@hh.ru/magritte-ui-select 13.0.23 → 13.0.25
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/ApplyChangesButton.d.ts +1 -1
- package/ApplyChangesButton.js +30 -29
- package/ApplyChangesButton.js.map +1 -1
- package/ClearButton.js +18 -21
- package/ClearButton.js.map +1 -1
- package/ClearCard.d.ts +1 -1
- package/ClearCard.js +2 -3
- package/ClearCard.js.map +1 -1
- package/Select.d.ts +14 -14
- package/Select.js +46 -8
- package/Select.js.map +1 -1
- package/SelectBottomSheet.js +56 -33
- package/SelectBottomSheet.js.map +1 -1
- package/SelectBottomSheetHeader.js +16 -9
- package/SelectBottomSheetHeader.js.map +1 -1
- package/SelectDrop.js +93 -57
- package/SelectDrop.js.map +1 -1
- package/SelectEmptyHint.js +22 -11
- package/SelectEmptyHint.js.map +1 -1
- package/SelectOptions.d.ts +4 -4
- package/SelectOptions.js +103 -67
- package/SelectOptions.js.map +1 -1
- package/SelectPickerCloseIcon.js +21 -11
- package/SelectPickerCloseIcon.js.map +1 -1
- package/SelectPickerContext.js +82 -82
- package/SelectPickerContext.js.map +1 -1
- package/SelectSearchInput.d.ts +1 -1
- package/SelectSearchInput.js +14 -4
- package/SelectSearchInput.js.map +1 -1
- package/SelectSearchTrigger.d.ts +1 -1
- package/SelectSearchTrigger.js +108 -37
- package/SelectSearchTrigger.js.map +1 -1
- package/SelectTrigger.d.ts +1 -1
- package/SelectTrigger.js +45 -17
- package/SelectTrigger.js.map +1 -1
- package/UncontrolledSelect.d.ts +5 -5
- package/UncontrolledSelect.js +43 -9
- package/UncontrolledSelect.js.map +1 -1
- package/index.css +50 -50
- package/index.d.ts +16 -16
- package/index.mock.d.ts +12 -12
- package/index.mock.js +33 -34
- package/index.mock.js.map +1 -1
- package/internal/ConfigContext.d.ts +1 -1
- package/internal/ConfigContext.js +52 -38
- package/internal/ConfigContext.js.map +1 -1
- package/internal/NavigationManagement.js +46 -44
- package/internal/NavigationManagement.js.map +1 -1
- package/internal/Option.d.ts +3 -3
- package/internal/Option.js +108 -43
- package/internal/Option.js.map +1 -1
- package/internal/OptionControl.d.ts +5 -5
- package/internal/OptionControl.js +37 -8
- package/internal/OptionControl.js.map +1 -1
- package/internal/SearchStateContext.js +19 -13
- package/internal/SearchStateContext.js.map +1 -1
- package/internal/SelectDataProvider.d.ts +2 -2
- package/internal/SelectDataProvider.js +17 -12
- package/internal/SelectDataProvider.js.map +1 -1
- package/internal/SelectError.js +21 -14
- package/internal/SelectError.js.map +1 -1
- package/internal/SelectReloadButton.js +12 -2
- package/internal/SelectReloadButton.js.map +1 -1
- package/internal/SelectStateContext.d.ts +2 -2
- package/internal/SelectStateContext.js +34 -43
- package/internal/SelectStateContext.js.map +1 -1
- package/internal/SelectStore.js +40 -45
- package/internal/SelectStore.js.map +1 -1
- package/internal/VisibilityContext.js +17 -8
- package/internal/VisibilityContext.js.map +1 -1
- package/internal/focusOrchestrator.d.ts +2 -2
- package/internal/focusOrchestrator.js +50 -50
- package/internal/focusOrchestrator.js.map +1 -1
- package/internal/slots.d.ts +1 -1
- package/internal/slots.js +5 -2
- package/internal/slots.js.map +1 -1
- package/internal/useDataProvider.d.ts +1 -1
- package/internal/useDataProvider.js +91 -95
- package/internal/useDataProvider.js.map +1 -1
- package/internal/useFocusWithin.js +32 -47
- package/internal/useFocusWithin.js.map +1 -1
- package/internal/utils.d.ts +1 -1
- package/internal/utils.js +39 -46
- package/internal/utils.js.map +1 -1
- package/legacy/SelectLegacy.d.ts +1 -1
- package/legacy/SelectLegacy.js +201 -61
- package/legacy/SelectLegacy.js.map +1 -1
- package/legacy/UncontrolledSelectLegacy.d.ts +5 -5
- package/legacy/UncontrolledSelectLegacy.js +24 -10
- package/legacy/UncontrolledSelectLegacy.js.map +1 -1
- package/legacy/internal/BottomSheetHeaderLegacy.d.ts +1 -1
- package/legacy/internal/BottomSheetHeaderLegacy.js +49 -33
- package/legacy/internal/BottomSheetHeaderLegacy.js.map +1 -1
- package/legacy/internal/ContentBeforeLegacy.d.ts +1 -1
- package/legacy/internal/ContentBeforeLegacy.js +21 -18
- package/legacy/internal/ContentBeforeLegacy.js.map +1 -1
- package/legacy/internal/FooterLegacy.d.ts +1 -1
- package/legacy/internal/FooterLegacy.js +58 -38
- package/legacy/internal/FooterLegacy.js.map +1 -1
- package/legacy/internal/OptionLayoutLegacy.d.ts +2 -2
- package/legacy/internal/OptionLayoutLegacy.js +28 -24
- package/legacy/internal/OptionLayoutLegacy.js.map +1 -1
- package/legacy/internal/TriggerLegacy.d.ts +1 -1
- package/legacy/internal/TriggerLegacy.js +36 -31
- package/legacy/internal/TriggerLegacy.js.map +1 -1
- package/legacy/internal/UnsavedChangesAlertLegacy.d.ts +1 -1
- package/legacy/internal/UnsavedChangesAlertLegacy.js +10 -9
- package/legacy/internal/UnsavedChangesAlertLegacy.js.map +1 -1
- package/legacy/types.d.ts +2 -2
- package/package.json +19 -19
- package/types.d.ts +1 -1
- package/useDataProvider.d.ts +1 -1
- package/useDataProvider.js +4 -2
- package/useDataProvider.js.map +1 -1
- package/usePickerRef.js +3 -4
- package/usePickerRef.js.map +1 -1
- package/useSearchState.d.ts +1 -1
- package/useSearchState.js +1 -2
- package/useSearchState.js.map +1 -1
- package/useSelectConfig.d.ts +1 -1
- package/useSelectConfig.js +1 -2
- package/useSelectConfig.js.map +1 -1
- package/useSelectContentState.js +25 -23
- package/useSelectContentState.js.map +1 -1
- package/useSelectError.d.ts +1 -1
- package/useSelectError.js +1 -2
- package/useSelectError.js.map +1 -1
- package/useSelectHint.d.ts +1 -1
- package/useSelectHint.js +1 -2
- package/useSelectHint.js.map +1 -1
- package/useSelectTrigger.d.ts +1 -1
- package/useSelectTrigger.js +99 -108
- package/useSelectTrigger.js.map +1 -1
- package/useVisibility.d.ts +1 -1
- package/useVisibility.js +1 -2
- package/useVisibility.js.map +1 -1
|
@@ -6,19 +6,25 @@ import './VisibilityContext.js';
|
|
|
6
6
|
import './utils.js';
|
|
7
7
|
|
|
8
8
|
const SearchContext = createContext(null);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const SearchStateProvider = ({
|
|
10
|
+
children,
|
|
11
|
+
searchValue,
|
|
12
|
+
setSearchValue
|
|
13
|
+
}) => {
|
|
14
|
+
const value = useMemo(
|
|
15
|
+
() => ({
|
|
16
|
+
searchValue,
|
|
17
|
+
setSearchValue
|
|
18
|
+
}),
|
|
19
|
+
[searchValue, setSearchValue]
|
|
20
|
+
);
|
|
21
|
+
const { showOptions } = useVisibility();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!showOptions) {
|
|
24
|
+
setSearchValue("");
|
|
25
|
+
}
|
|
26
|
+
}, [showOptions, setSearchValue]);
|
|
27
|
+
return /* @__PURE__ */ jsx(SearchContext.Provider, { value, children });
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
export { SearchContext, SearchStateProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchStateContext.js","sources":["src/internal/SearchStateContext.tsx"],"sourcesContent":["import { createContext, useMemo, type ReactNode, type ReactElement, SetStateAction, Dispatch, useEffect } from 'react';\n\nimport { useVisibility } from '@hh.ru/magritte-ui-select/useVisibility';\n\nexport interface SearchContextValue {\n searchValue: string;\n setSearchValue: Dispatch<SetStateAction<string>>;\n}\n\nexport const SearchContext = createContext<SearchContextValue | null>(null);\n\n// стейт поиска\nexport const SearchStateProvider = ({\n children,\n searchValue,\n setSearchValue,\n}: { children: ReactNode } & SearchContextValue): ReactElement => {\n const value = useMemo<SearchContextValue>(\n () => ({\n searchValue,\n setSearchValue,\n }),\n [searchValue, setSearchValue]\n );\n\n const { showOptions } = useVisibility();\n useEffect(() => {\n if (!showOptions) {\n setSearchValue('');\n }\n }, [showOptions, setSearchValue]);\n\n return <SearchContext.Provider value={value}>{children}</SearchContext.Provider>;\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"SearchStateContext.js","sources":["src/internal/SearchStateContext.tsx"],"sourcesContent":["import { createContext, useMemo, type ReactNode, type ReactElement, SetStateAction, Dispatch, useEffect } from 'react';\n\nimport { useVisibility } from '@hh.ru/magritte-ui-select/useVisibility';\n\nexport interface SearchContextValue {\n searchValue: string;\n setSearchValue: Dispatch<SetStateAction<string>>;\n}\n\nexport const SearchContext = createContext<SearchContextValue | null>(null);\n\n// стейт поиска\nexport const SearchStateProvider = ({\n children,\n searchValue,\n setSearchValue,\n}: { children: ReactNode } & SearchContextValue): ReactElement => {\n const value = useMemo<SearchContextValue>(\n () => ({\n searchValue,\n setSearchValue,\n }),\n [searchValue, setSearchValue]\n );\n\n const { showOptions } = useVisibility();\n useEffect(() => {\n if (!showOptions) {\n setSearchValue('');\n }\n }, [showOptions, setSearchValue]);\n\n return <SearchContext.Provider value={value}>{children}</SearchContext.Provider>;\n};\n"],"names":[],"mappings":";;;;;;AASa,MAAA,aAAA,GAAgB,cAAyC,IAAI,EAAA;AAGnE,MAAM,sBAAsB,CAAC;AAAA,EAChC,QAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AACJ,CAAkE,KAAA;AAC9D,EAAA,MAAM,KAAQ,GAAA,OAAA;AAAA,IACV,OAAO;AAAA,MACH,WAAA;AAAA,MACA,cAAA;AAAA,KACJ,CAAA;AAAA,IACA,CAAC,aAAa,cAAc,CAAA;AAAA,GAChC,CAAA;AAEA,EAAM,MAAA,EAAE,WAAY,EAAA,GAAI,aAAc,EAAA,CAAA;AACtC,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,IAAI,CAAC,WAAa,EAAA;AACd,MAAA,cAAA,CAAe,EAAE,CAAA,CAAA;AAAA,KACrB;AAAA,GACD,EAAA,CAAC,WAAa,EAAA,cAAc,CAAC,CAAA,CAAA;AAEhC,EAAA,uBAAQ,GAAA,CAAA,aAAA,CAAc,QAAd,EAAA,EAAuB,OAAe,QAAS,EAAA,CAAA,CAAA;AAC3D;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode, ReactElement } from 'react';
|
|
2
2
|
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
-
import { type UseDataProvider } from '
|
|
4
|
-
import { OnOptionsChangeCallback, UseDataProviderParams } from '
|
|
3
|
+
import { type UseDataProvider } from '../internal/useDataProvider';
|
|
4
|
+
import { OnOptionsChangeCallback, UseDataProviderParams } from '../types';
|
|
5
5
|
export declare const DataProviderContext: import("react").Context<UseDataProvider<StaticDataFetcherItem> | null>;
|
|
6
6
|
interface SelectDataProviderProps<DataType extends StaticDataFetcherItem> extends UseDataProviderParams<DataType> {
|
|
7
7
|
children: ReactNode;
|
|
@@ -10,18 +10,23 @@ import '../useVisibility.js';
|
|
|
10
10
|
import './VisibilityContext.js';
|
|
11
11
|
|
|
12
12
|
const DataProviderContext = createContext(null);
|
|
13
|
-
const SelectDataProvider = ({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
const SelectDataProvider = ({
|
|
14
|
+
children,
|
|
15
|
+
onOptionsChange,
|
|
16
|
+
options,
|
|
17
|
+
dataProvider: dataProviderExternal
|
|
18
|
+
}) => {
|
|
19
|
+
const dataProvider = useMemo(() => {
|
|
20
|
+
if (!options && !dataProviderExternal) {
|
|
21
|
+
throw new Error(`dataProvider or options must be used within <Select>`);
|
|
22
|
+
}
|
|
23
|
+
if (options) {
|
|
24
|
+
return createStaticDataProvider(options);
|
|
25
|
+
}
|
|
26
|
+
return dataProviderExternal;
|
|
27
|
+
}, [dataProviderExternal, options]);
|
|
28
|
+
const searchData = useDataProvider(dataProvider, onOptionsChange);
|
|
29
|
+
return /* @__PURE__ */ jsx(DataProviderContext.Provider, { value: searchData, children });
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
export { DataProviderContext, SelectDataProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectDataProvider.js","sources":["src/internal/SelectDataProvider.tsx"],"sourcesContent":["import { type ReactNode, useMemo, ReactElement, createContext } from 'react';\n\nimport {\n StaticDataFetcherItem,\n createStaticDataProvider,\n DataProvider as DataProviderType,\n} from '@hh.ru/magritte-common-data-provider';\nimport {\n useDataProvider as useDataProviderInternal,\n type UseDataProvider,\n} from '@hh.ru/magritte-ui-select/internal/useDataProvider';\nimport { OnOptionsChangeCallback, UseDataProviderParams } from '@hh.ru/magritte-ui-select/types';\n\nexport const DataProviderContext = createContext<UseDataProvider<StaticDataFetcherItem> | null>(null);\n\ninterface SelectDataProviderProps<DataType extends StaticDataFetcherItem> extends UseDataProviderParams<DataType> {\n children: ReactNode;\n onOptionsChange?: OnOptionsChangeCallback<DataType>;\n}\n\nconst SelectDataProvider = <DataType extends StaticDataFetcherItem>({\n children,\n onOptionsChange,\n options,\n dataProvider: dataProviderExternal,\n}: SelectDataProviderProps<DataType>): ReactElement => {\n const dataProvider = useMemo(() => {\n if (!options && !dataProviderExternal) {\n throw new Error(`dataProvider or options must be used within <Select>`);\n }\n if (options) {\n return createStaticDataProvider<DataType>(options);\n }\n return dataProviderExternal as DataProviderType<DataType>;\n }, [dataProviderExternal, options]);\n\n const searchData = useDataProviderInternal<DataType>(dataProvider, onOptionsChange);\n\n return <DataProviderContext.Provider value={searchData}>{children}</DataProviderContext.Provider>;\n};\n\nexport { SelectDataProvider };\n"],"names":["useDataProviderInternal"
|
|
1
|
+
{"version":3,"file":"SelectDataProvider.js","sources":["src/internal/SelectDataProvider.tsx"],"sourcesContent":["import { type ReactNode, useMemo, ReactElement, createContext } from 'react';\n\nimport {\n StaticDataFetcherItem,\n createStaticDataProvider,\n DataProvider as DataProviderType,\n} from '@hh.ru/magritte-common-data-provider';\nimport {\n useDataProvider as useDataProviderInternal,\n type UseDataProvider,\n} from '@hh.ru/magritte-ui-select/internal/useDataProvider';\nimport { OnOptionsChangeCallback, UseDataProviderParams } from '@hh.ru/magritte-ui-select/types';\n\nexport const DataProviderContext = createContext<UseDataProvider<StaticDataFetcherItem> | null>(null);\n\ninterface SelectDataProviderProps<DataType extends StaticDataFetcherItem> extends UseDataProviderParams<DataType> {\n children: ReactNode;\n onOptionsChange?: OnOptionsChangeCallback<DataType>;\n}\n\nconst SelectDataProvider = <DataType extends StaticDataFetcherItem>({\n children,\n onOptionsChange,\n options,\n dataProvider: dataProviderExternal,\n}: SelectDataProviderProps<DataType>): ReactElement => {\n const dataProvider = useMemo(() => {\n if (!options && !dataProviderExternal) {\n throw new Error(`dataProvider or options must be used within <Select>`);\n }\n if (options) {\n return createStaticDataProvider<DataType>(options);\n }\n return dataProviderExternal as DataProviderType<DataType>;\n }, [dataProviderExternal, options]);\n\n const searchData = useDataProviderInternal<DataType>(dataProvider, onOptionsChange);\n\n return <DataProviderContext.Provider value={searchData}>{children}</DataProviderContext.Provider>;\n};\n\nexport { SelectDataProvider };\n"],"names":["useDataProviderInternal"],"mappings":";;;;;;;;;;AAaa,MAAA,mBAAA,GAAsB,cAA6D,IAAI,EAAA;AAOpG,MAAM,qBAAqB,CAAyC;AAAA,EAChE,QAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAc,EAAA,oBAAA;AAClB,CAAuD,KAAA;AACnD,EAAM,MAAA,YAAA,GAAe,QAAQ,MAAM;AAC/B,IAAI,IAAA,CAAC,OAAW,IAAA,CAAC,oBAAsB,EAAA;AACnC,MAAM,MAAA,IAAI,MAAM,CAAsD,oDAAA,CAAA,CAAA,CAAA;AAAA,KAC1E;AACA,IAAA,IAAI,OAAS,EAAA;AACT,MAAA,OAAO,yBAAmC,OAAO,CAAA,CAAA;AAAA,KACrD;AACA,IAAO,OAAA,oBAAA,CAAA;AAAA,GACR,EAAA,CAAC,oBAAsB,EAAA,OAAO,CAAC,CAAA,CAAA;AAElC,EAAM,MAAA,UAAA,GAAaA,eAAkC,CAAA,YAAA,EAAc,eAAe,CAAA,CAAA;AAElF,EAAA,2BAAQ,mBAAoB,CAAA,QAAA,EAApB,EAA6B,KAAA,EAAO,YAAa,QAAS,EAAA,CAAA,CAAA;AACtE;;;;"}
|
package/internal/SelectError.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './../index.css';
|
|
2
|
-
import { jsxs, Fragment
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
4
4
|
import { SelectReloadButton } from './SelectReloadButton.js';
|
|
5
5
|
import { useSelectError } from '../useSelectError.js';
|
|
@@ -20,21 +20,28 @@ import '../useVisibility.js';
|
|
|
20
20
|
import './VisibilityContext.js';
|
|
21
21
|
import './ConfigContext.js';
|
|
22
22
|
|
|
23
|
-
var styles = {"error-container":"magritte-error-container___ICGpQ_13-0-
|
|
23
|
+
var styles = {"error-container":"magritte-error-container___ICGpQ_13-0-25","errorContainer":"magritte-error-container___ICGpQ_13-0-25"};
|
|
24
24
|
|
|
25
|
-
/** Ошибка дата-провайдера, показывать решает пикер */
|
|
26
25
|
const SelectError = () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
26
|
+
const { isMobile } = useBreakpoint();
|
|
27
|
+
const { providerError } = useSelectError();
|
|
28
|
+
if (!providerError) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const { title, description, reloadButton: reloadButtonExternal } = providerError;
|
|
32
|
+
const errorContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
+
/* @__PURE__ */ jsx(Title, { Element: "h3", size: "small", alignment: "center", children: title }),
|
|
34
|
+
/* @__PURE__ */ jsx(VSpacing, { default: 8 }),
|
|
35
|
+
/* @__PURE__ */ jsx(Text, { typography: "paragraph-2-regular", style: "secondary", children: description })
|
|
36
|
+
] });
|
|
37
|
+
if (isMobile) {
|
|
38
|
+
return /* @__PURE__ */ jsx("div", { className: styles.errorContainer, "data-qa": "magritte-select-error-xs", children: errorContent });
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.errorContainer, "data-qa": "magritte-select-error", children: [
|
|
41
|
+
errorContent,
|
|
42
|
+
/* @__PURE__ */ jsx(VSpacing, { default: 32 }),
|
|
43
|
+
/* @__PURE__ */ jsx(SelectReloadButton, { label: reloadButtonExternal })
|
|
44
|
+
] });
|
|
38
45
|
};
|
|
39
46
|
|
|
40
47
|
export { SelectError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectError.js","sources":["src/internal/SelectError.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { SelectReloadButton } from '@hh.ru/magritte-ui-select/internal/SelectReloadButton';\nimport { useSelectError } from '@hh.ru/magritte-ui-select/useSelectError';\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { Title } from '@hh.ru/magritte-ui-title';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './select-error.less';\n\n/** Ошибка дата-провайдера, показывать решает пикер */\nexport const SelectError: FC = () => {\n const { isMobile } = useBreakpoint();\n const { providerError } = useSelectError();\n\n if (!providerError) {\n return null;\n }\n\n const { title, description, reloadButton: reloadButtonExternal } = providerError;\n\n const errorContent = (\n <>\n <Title Element=\"h3\" size=\"small\" alignment=\"center\">\n {title}\n </Title>\n <VSpacing default={8} />\n <Text typography=\"paragraph-2-regular\" style=\"secondary\">\n {description}\n </Text>\n </>\n );\n\n if (isMobile) {\n return (\n <div className={styles.errorContainer} data-qa=\"magritte-select-error-xs\">\n {errorContent}\n </div>\n );\n }\n return (\n <div className={styles.errorContainer} data-qa=\"magritte-select-error\">\n {errorContent}\n <VSpacing default={32} />\n <SelectReloadButton label={reloadButtonExternal} />\n </div>\n );\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"SelectError.js","sources":["src/internal/SelectError.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { SelectReloadButton } from '@hh.ru/magritte-ui-select/internal/SelectReloadButton';\nimport { useSelectError } from '@hh.ru/magritte-ui-select/useSelectError';\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { Title } from '@hh.ru/magritte-ui-title';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './select-error.less';\n\n/** Ошибка дата-провайдера, показывать решает пикер */\nexport const SelectError: FC = () => {\n const { isMobile } = useBreakpoint();\n const { providerError } = useSelectError();\n\n if (!providerError) {\n return null;\n }\n\n const { title, description, reloadButton: reloadButtonExternal } = providerError;\n\n const errorContent = (\n <>\n <Title Element=\"h3\" size=\"small\" alignment=\"center\">\n {title}\n </Title>\n <VSpacing default={8} />\n <Text typography=\"paragraph-2-regular\" style=\"secondary\">\n {description}\n </Text>\n </>\n );\n\n if (isMobile) {\n return (\n <div className={styles.errorContainer} data-qa=\"magritte-select-error-xs\">\n {errorContent}\n </div>\n );\n }\n return (\n <div className={styles.errorContainer} data-qa=\"magritte-select-error\">\n {errorContent}\n <VSpacing default={32} />\n <SelectReloadButton label={reloadButtonExternal} />\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAYO,MAAM,cAAkB,MAAM;AACjC,EAAM,MAAA,EAAE,QAAS,EAAA,GAAI,aAAc,EAAA,CAAA;AACnC,EAAM,MAAA,EAAE,aAAc,EAAA,GAAI,cAAe,EAAA,CAAA;AAEzC,EAAA,IAAI,CAAC,aAAe,EAAA;AAChB,IAAO,OAAA,IAAA,CAAA;AAAA,GACX;AAEA,EAAA,MAAM,EAAE,KAAA,EAAO,WAAa,EAAA,YAAA,EAAc,sBAAyB,GAAA,aAAA,CAAA;AAEnE,EAAA,MAAM,+BAEE,IAAA,CAAA,QAAA,EAAA,EAAA,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,SAAM,OAAQ,EAAA,IAAA,EAAK,MAAK,OAAQ,EAAA,SAAA,EAAU,UACtC,QACL,EAAA,KAAA,EAAA,CAAA;AAAA,oBACA,GAAA,CAAC,QAAS,EAAA,EAAA,OAAA,EAAS,CAAG,EAAA,CAAA;AAAA,wBACrB,IAAK,EAAA,EAAA,UAAA,EAAW,qBAAsB,EAAA,KAAA,EAAM,aACxC,QACL,EAAA,WAAA,EAAA,CAAA;AAAA,GACJ,EAAA,CAAA,CAAA;AAGJ,EAAA,IAAI,QAAU,EAAA;AACV,IAAA,2BACK,KAAI,EAAA,EAAA,SAAA,EAAW,OAAO,cAAgB,EAAA,SAAA,EAAQ,4BAC1C,QACL,EAAA,YAAA,EAAA,CAAA,CAAA;AAAA,GAER;AACA,EAAA,4BACK,KAAI,EAAA,EAAA,SAAA,EAAW,MAAO,CAAA,cAAA,EAAgB,WAAQ,uBAC1C,EAAA,QAAA,EAAA;AAAA,IAAA,YAAA;AAAA,oBACD,GAAA,CAAC,QAAS,EAAA,EAAA,OAAA,EAAS,EAAI,EAAA,CAAA;AAAA,oBACvB,GAAA,CAAC,kBAAmB,EAAA,EAAA,KAAA,EAAO,oBAAsB,EAAA,CAAA;AAAA,GACrD,EAAA,CAAA,CAAA;AAER;;;;"}
|
|
@@ -14,8 +14,18 @@ import '../useVisibility.js';
|
|
|
14
14
|
import './VisibilityContext.js';
|
|
15
15
|
|
|
16
16
|
const SelectReloadButton = ({ label }) => {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const { reloadRequest } = useDataProvider();
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
Button,
|
|
20
|
+
{
|
|
21
|
+
mode: "primary",
|
|
22
|
+
style: "accent",
|
|
23
|
+
size: "medium",
|
|
24
|
+
onClick: reloadRequest,
|
|
25
|
+
icon: /* @__PURE__ */ jsx(ArrowPathClockwiseOutlinedSize24, {}),
|
|
26
|
+
children: label
|
|
27
|
+
}
|
|
28
|
+
);
|
|
19
29
|
};
|
|
20
30
|
|
|
21
31
|
export { SelectReloadButton };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectReloadButton.js","sources":["src/internal/SelectReloadButton.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { Button } from '@hh.ru/magritte-ui-button';\nimport { ArrowPathClockwiseOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { useDataProvider } from '@hh.ru/magritte-ui-select/useDataProvider';\n\nexport const SelectReloadButton: FC<{ label: string }> = ({ label }) => {\n const { reloadRequest } = useDataProvider();\n return (\n <Button\n mode=\"primary\"\n style=\"accent\"\n size=\"medium\"\n onClick={reloadRequest}\n icon={<ArrowPathClockwiseOutlinedSize24 />}\n >\n {label}\n </Button>\n );\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"SelectReloadButton.js","sources":["src/internal/SelectReloadButton.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { Button } from '@hh.ru/magritte-ui-button';\nimport { ArrowPathClockwiseOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { useDataProvider } from '@hh.ru/magritte-ui-select/useDataProvider';\n\nexport const SelectReloadButton: FC<{ label: string }> = ({ label }) => {\n const { reloadRequest } = useDataProvider();\n return (\n <Button\n mode=\"primary\"\n style=\"accent\"\n size=\"medium\"\n onClick={reloadRequest}\n icon={<ArrowPathClockwiseOutlinedSize24 />}\n >\n {label}\n </Button>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAMO,MAAM,kBAA4C,GAAA,CAAC,EAAE,KAAA,EAAY,KAAA;AACpE,EAAM,MAAA,EAAE,aAAc,EAAA,GAAI,eAAgB,EAAA,CAAA;AAC1C,EACI,uBAAA,GAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACG,IAAK,EAAA,SAAA;AAAA,MACL,KAAM,EAAA,QAAA;AAAA,MACN,IAAK,EAAA,QAAA;AAAA,MACL,OAAS,EAAA,aAAA;AAAA,MACT,IAAA,sBAAO,gCAAiC,EAAA,EAAA,CAAA;AAAA,MAEvC,QAAA,EAAA,KAAA;AAAA,KAAA;AAAA,GACL,CAAA;AAER;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode, type ReactElement } from 'react';
|
|
2
2
|
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
-
import { SelectStore } from '
|
|
4
|
-
import { ValueTypeHelper } from '
|
|
3
|
+
import { SelectStore } from '../internal/SelectStore';
|
|
4
|
+
import { ValueTypeHelper } from '../types';
|
|
5
5
|
export declare const SelectDraftStoreContext: import("react").Context<SelectStore<StaticDataFetcherItem> | null>;
|
|
6
6
|
/**
|
|
7
7
|
* Возвращает ссылку на драфт стор, если такой зарегистрирован.
|
|
@@ -8,53 +8,44 @@ import './ConfigContext.js';
|
|
|
8
8
|
|
|
9
9
|
const SelectStoreContext = createContext(null);
|
|
10
10
|
const SelectDraftStoreContext = createContext(null);
|
|
11
|
-
/**
|
|
12
|
-
* Возвращает ссылку на драфт стор, если такой зарегистрирован.
|
|
13
|
-
* Иначе даем работать с общим стором.
|
|
14
|
-
* Даем возможность получить доступ напрямую к CommittedStore (например, для Apply к Drop).
|
|
15
|
-
*/
|
|
16
11
|
const useSelectStore = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
const draftStore = useContext(SelectDraftStoreContext);
|
|
13
|
+
const committedStore = useContext(SelectStoreContext);
|
|
14
|
+
if (draftStore) {
|
|
15
|
+
return draftStore;
|
|
16
|
+
}
|
|
17
|
+
return assertSelectContext(committedStore, "useSelectStore");
|
|
23
18
|
};
|
|
24
|
-
// возвращает реактивное состояние стора
|
|
25
19
|
const useSelected = (store) => {
|
|
26
|
-
|
|
20
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
27
21
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}, [store, valueOrValuesExternal]);
|
|
57
|
-
return jsx(SelectStoreContext.Provider, { value: store, children: children });
|
|
22
|
+
const SelectStateProvider = ({
|
|
23
|
+
children,
|
|
24
|
+
onChange,
|
|
25
|
+
value: valueOrValuesExternal
|
|
26
|
+
}) => {
|
|
27
|
+
const [store] = useState(() => new SelectStore(value2Array(valueOrValuesExternal)));
|
|
28
|
+
const { multiple } = useSelectConfig();
|
|
29
|
+
const suppressOnChangeRef = useRef(false);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const storeUnsubscribe = store.subscribe(() => {
|
|
32
|
+
if (suppressOnChangeRef.current) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const selected = store.getSnapshot();
|
|
36
|
+
onChange?.(multiple ? [...selected] : selected[0]);
|
|
37
|
+
});
|
|
38
|
+
return storeUnsubscribe;
|
|
39
|
+
}, [store, multiple, onChange]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
suppressOnChangeRef.current = true;
|
|
42
|
+
try {
|
|
43
|
+
store.replace(value2Array(valueOrValuesExternal));
|
|
44
|
+
} finally {
|
|
45
|
+
suppressOnChangeRef.current = false;
|
|
46
|
+
}
|
|
47
|
+
}, [store, valueOrValuesExternal]);
|
|
48
|
+
return /* @__PURE__ */ jsx(SelectStoreContext.Provider, { value: store, children });
|
|
58
49
|
};
|
|
59
50
|
|
|
60
51
|
export { SelectDraftStoreContext, SelectStateProvider, useSelectStore, useSelected };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectStateContext.js","sources":["src/internal/SelectStateContext.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n type ReactNode,\n type ReactElement,\n useState,\n useSyncExternalStore,\n useEffect,\n useRef,\n} from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { SelectStore } from '@hh.ru/magritte-ui-select/internal/SelectStore';\nimport { assertSelectContext, value2Array } from '@hh.ru/magritte-ui-select/internal/utils';\nimport { ValueTypeHelper } from '@hh.ru/magritte-ui-select/types';\nimport { useSelectConfig } from '@hh.ru/magritte-ui-select/useSelectConfig';\n\nconst SelectStoreContext = createContext<SelectStore<StaticDataFetcherItem> | null>(null);\n\nexport const SelectDraftStoreContext = createContext<SelectStore<StaticDataFetcherItem> | null>(null);\n\n/**\n * Возвращает ссылку на драфт стор, если такой зарегистрирован.\n * Иначе даем работать с общим стором.\n * Даем возможность получить доступ напрямую к CommittedStore (например, для Apply к Drop).\n */\nexport const useSelectStore = <DataType extends StaticDataFetcherItem>(): SelectStore<DataType> => {\n const draftStore = useContext(SelectDraftStoreContext);\n const committedStore = useContext(SelectStoreContext);\n if (draftStore) {\n return draftStore as SelectStore<DataType>;\n }\n return assertSelectContext(committedStore, 'useSelectStore') as SelectStore<DataType>;\n};\n\n// возвращает реактивное состояние стора\nexport const useSelected = <DataType extends StaticDataFetcherItem>(\n store: SelectStore<DataType>\n): readonly DataType[] => {\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n};\n\ninterface SelectStateProviderNewProps<MultipleType extends boolean, DataType extends StaticDataFetcherItem> {\n children: ReactNode;\n onChange?: (value: ValueTypeHelper<MultipleType, DataType>) => void;\n value?: ValueTypeHelper<MultipleType, DataType>;\n}\n\n// выбранные значения, операции над ними и эмит внешнего onChange\nexport const SelectStateProvider = <MultipleType extends boolean, DataType extends StaticDataFetcherItem>({\n children,\n onChange,\n value: valueOrValuesExternal,\n}: SelectStateProviderNewProps<MultipleType, DataType>): ReactElement => {\n const [store] = useState(() => new SelectStore(value2Array<MultipleType, DataType>(valueOrValuesExternal)));\n const { multiple } = useSelectConfig();\n\n // во время реакции на внешнее обновление value\n // - эмитить внешний onChange НЕ нужно\n // - но обновить дерево селекта нужно\n const suppressOnChangeRef = useRef(false);\n\n // эмит внешнего onChange для потребителей\n useEffect(() => {\n const storeUnsubscribe = store.subscribe(() => {\n if (suppressOnChangeRef.current) {\n return;\n }\n const selected = store.getSnapshot();\n onChange?.((multiple ? [...selected] : selected[0]) as ValueTypeHelper<MultipleType, DataType>);\n });\n return storeUnsubscribe;\n }, [store, multiple, onChange]);\n\n // синк стора с внешним свойством\n useEffect(() => {\n suppressOnChangeRef.current = true;\n try {\n store.replace(value2Array<MultipleType, DataType>(valueOrValuesExternal));\n } finally {\n suppressOnChangeRef.current = false;\n }\n }, [store, valueOrValuesExternal]);\n\n return <SelectStoreContext.Provider value={store}>{children}</SelectStoreContext.Provider>;\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"SelectStateContext.js","sources":["src/internal/SelectStateContext.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n type ReactNode,\n type ReactElement,\n useState,\n useSyncExternalStore,\n useEffect,\n useRef,\n} from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { SelectStore } from '@hh.ru/magritte-ui-select/internal/SelectStore';\nimport { assertSelectContext, value2Array } from '@hh.ru/magritte-ui-select/internal/utils';\nimport { ValueTypeHelper } from '@hh.ru/magritte-ui-select/types';\nimport { useSelectConfig } from '@hh.ru/magritte-ui-select/useSelectConfig';\n\nconst SelectStoreContext = createContext<SelectStore<StaticDataFetcherItem> | null>(null);\n\nexport const SelectDraftStoreContext = createContext<SelectStore<StaticDataFetcherItem> | null>(null);\n\n/**\n * Возвращает ссылку на драфт стор, если такой зарегистрирован.\n * Иначе даем работать с общим стором.\n * Даем возможность получить доступ напрямую к CommittedStore (например, для Apply к Drop).\n */\nexport const useSelectStore = <DataType extends StaticDataFetcherItem>(): SelectStore<DataType> => {\n const draftStore = useContext(SelectDraftStoreContext);\n const committedStore = useContext(SelectStoreContext);\n if (draftStore) {\n return draftStore as SelectStore<DataType>;\n }\n return assertSelectContext(committedStore, 'useSelectStore') as SelectStore<DataType>;\n};\n\n// возвращает реактивное состояние стора\nexport const useSelected = <DataType extends StaticDataFetcherItem>(\n store: SelectStore<DataType>\n): readonly DataType[] => {\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n};\n\ninterface SelectStateProviderNewProps<MultipleType extends boolean, DataType extends StaticDataFetcherItem> {\n children: ReactNode;\n onChange?: (value: ValueTypeHelper<MultipleType, DataType>) => void;\n value?: ValueTypeHelper<MultipleType, DataType>;\n}\n\n// выбранные значения, операции над ними и эмит внешнего onChange\nexport const SelectStateProvider = <MultipleType extends boolean, DataType extends StaticDataFetcherItem>({\n children,\n onChange,\n value: valueOrValuesExternal,\n}: SelectStateProviderNewProps<MultipleType, DataType>): ReactElement => {\n const [store] = useState(() => new SelectStore(value2Array<MultipleType, DataType>(valueOrValuesExternal)));\n const { multiple } = useSelectConfig();\n\n // во время реакции на внешнее обновление value\n // - эмитить внешний onChange НЕ нужно\n // - но обновить дерево селекта нужно\n const suppressOnChangeRef = useRef(false);\n\n // эмит внешнего onChange для потребителей\n useEffect(() => {\n const storeUnsubscribe = store.subscribe(() => {\n if (suppressOnChangeRef.current) {\n return;\n }\n const selected = store.getSnapshot();\n onChange?.((multiple ? [...selected] : selected[0]) as ValueTypeHelper<MultipleType, DataType>);\n });\n return storeUnsubscribe;\n }, [store, multiple, onChange]);\n\n // синк стора с внешним свойством\n useEffect(() => {\n suppressOnChangeRef.current = true;\n try {\n store.replace(value2Array<MultipleType, DataType>(valueOrValuesExternal));\n } finally {\n suppressOnChangeRef.current = false;\n }\n }, [store, valueOrValuesExternal]);\n\n return <SelectStoreContext.Provider value={store}>{children}</SelectStoreContext.Provider>;\n};\n"],"names":[],"mappings":";;;;;;;AAiBA,MAAM,kBAAA,GAAqB,cAAyD,IAAI,CAAA,CAAA;AAE3E,MAAA,uBAAA,GAA0B,cAAyD,IAAI,EAAA;AAO7F,MAAM,iBAAiB,MAAqE;AAC/F,EAAM,MAAA,UAAA,GAAa,WAAW,uBAAuB,CAAA,CAAA;AACrD,EAAM,MAAA,cAAA,GAAiB,WAAW,kBAAkB,CAAA,CAAA;AACpD,EAAA,IAAI,UAAY,EAAA;AACZ,IAAO,OAAA,UAAA,CAAA;AAAA,GACX;AACA,EAAO,OAAA,mBAAA,CAAoB,gBAAgB,gBAAgB,CAAA,CAAA;AAC/D,EAAA;AAGa,MAAA,WAAA,GAAc,CACvB,KACsB,KAAA;AACtB,EAAA,OAAO,qBAAqB,KAAM,CAAA,SAAA,EAAW,KAAM,CAAA,WAAA,EAAa,MAAM,WAAW,CAAA,CAAA;AACrF,EAAA;AASO,MAAM,sBAAsB,CAAuE;AAAA,EACtG,QAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAO,EAAA,qBAAA;AACX,CAAyE,KAAA;AACrE,EAAM,MAAA,CAAC,KAAK,CAAA,GAAI,QAAS,CAAA,MAAM,IAAI,WAAY,CAAA,WAAA,CAAoC,qBAAqB,CAAC,CAAC,CAAA,CAAA;AAC1G,EAAM,MAAA,EAAE,QAAS,EAAA,GAAI,eAAgB,EAAA,CAAA;AAKrC,EAAM,MAAA,mBAAA,GAAsB,OAAO,KAAK,CAAA,CAAA;AAGxC,EAAA,SAAA,CAAU,MAAM;AACZ,IAAM,MAAA,gBAAA,GAAmB,KAAM,CAAA,SAAA,CAAU,MAAM;AAC3C,MAAA,IAAI,oBAAoB,OAAS,EAAA;AAC7B,QAAA,OAAA;AAAA,OACJ;AACA,MAAM,MAAA,QAAA,GAAW,MAAM,WAAY,EAAA,CAAA;AACnC,MAAA,QAAA,GAAY,WAAW,CAAC,GAAG,QAAQ,CAAI,GAAA,QAAA,CAAS,CAAC,CAA6C,CAAA,CAAA;AAAA,KACjG,CAAA,CAAA;AACD,IAAO,OAAA,gBAAA,CAAA;AAAA,GACR,EAAA,CAAC,KAAO,EAAA,QAAA,EAAU,QAAQ,CAAC,CAAA,CAAA;AAG9B,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,mBAAA,CAAoB,OAAU,GAAA,IAAA,CAAA;AAC9B,IAAI,IAAA;AACA,MAAM,KAAA,CAAA,OAAA,CAAQ,WAAoC,CAAA,qBAAqB,CAAC,CAAA,CAAA;AAAA,KAC1E,SAAA;AACE,MAAA,mBAAA,CAAoB,OAAU,GAAA,KAAA,CAAA;AAAA,KAClC;AAAA,GACD,EAAA,CAAC,KAAO,EAAA,qBAAqB,CAAC,CAAA,CAAA;AAEjC,EAAA,2BAAQ,kBAAmB,CAAA,QAAA,EAAnB,EAA4B,KAAA,EAAO,OAAQ,QAAS,EAAA,CAAA,CAAA;AAChE;;;;"}
|
package/internal/SelectStore.js
CHANGED
|
@@ -2,57 +2,52 @@ import './../index.css';
|
|
|
2
2
|
import { isArraysEquals, extractValues } from './utils.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
|
-
// стор хранит выбранные объекты, а не ids
|
|
6
|
-
// внешний onChange должен получать DataType | DataType[]
|
|
7
|
-
// массив опций меняется дата провайдером => нужно место, где хранить обьекты DataType
|
|
8
5
|
class SelectStore {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
6
|
+
values;
|
|
7
|
+
listeners = /* @__PURE__ */ new Set();
|
|
8
|
+
constructor(initial = []) {
|
|
9
|
+
this.values = [...initial];
|
|
10
|
+
}
|
|
11
|
+
getSnapshot = () => {
|
|
12
|
+
return this.values;
|
|
13
|
+
};
|
|
14
|
+
subscribe = (listener) => {
|
|
15
|
+
this.listeners.add(listener);
|
|
16
|
+
return () => {
|
|
17
|
+
this.listeners.delete(listener);
|
|
22
18
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
this.values = [...source];
|
|
30
|
-
this.emit();
|
|
31
|
-
}
|
|
32
|
-
add(value) {
|
|
33
|
-
if (this.values.some((item) => item.value === value.value)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.values = [...this.values, value];
|
|
37
|
-
this.emit();
|
|
19
|
+
};
|
|
20
|
+
replace(source) {
|
|
21
|
+
if (isArraysEquals(extractValues(this.values), extractValues(source))) {
|
|
22
|
+
return;
|
|
38
23
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
this.values = [...source];
|
|
25
|
+
this.emit();
|
|
26
|
+
}
|
|
27
|
+
add(value) {
|
|
28
|
+
if (this.values.some((item) => item.value === value.value)) {
|
|
29
|
+
return;
|
|
45
30
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
this.values = [...this.values, value];
|
|
32
|
+
this.emit();
|
|
33
|
+
}
|
|
34
|
+
remove(id) {
|
|
35
|
+
if (!this.values.some((item) => item.value === id)) {
|
|
36
|
+
return;
|
|
52
37
|
}
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
this.values = this.values.filter((item) => item.value !== id);
|
|
39
|
+
this.emit();
|
|
40
|
+
}
|
|
41
|
+
clear() {
|
|
42
|
+
if (this.values.length === 0) {
|
|
43
|
+
return;
|
|
55
44
|
}
|
|
45
|
+
this.values = [];
|
|
46
|
+
this.emit();
|
|
47
|
+
}
|
|
48
|
+
emit() {
|
|
49
|
+
this.listeners.forEach((listener) => listener());
|
|
50
|
+
}
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
export { SelectStore };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectStore.js","sources":["src/internal/SelectStore.ts"],"sourcesContent":["import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { extractValues, isArraysEquals } from '@hh.ru/magritte-ui-select/internal/utils';\n\ntype Listener = () => void;\ntype Value = StaticDataFetcherItem['value'];\n\n// стор хранит выбранные объекты, а не ids\n// внешний onChange должен получать DataType | DataType[]\n// массив опций меняется дата провайдером => нужно место, где хранить обьекты DataType\nexport class SelectStore<DataType extends StaticDataFetcherItem> {\n private values: readonly DataType[];\n private readonly listeners = new Set<Listener>();\n\n public constructor(initial: readonly DataType[] = []) {\n this.values = [...initial];\n }\n\n public getSnapshot = (): readonly DataType[] => {\n return this.values;\n };\n\n public subscribe = (listener: Listener): VoidFunction => {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n public replace(source: readonly DataType[]): void {\n // идентичность выбранных элементов определяется через поле value\n // так как value единственное поле которое StaticDataFetcherItem гарантирует\n if (isArraysEquals(extractValues<DataType>(this.values), extractValues<DataType>(source))) {\n return;\n }\n this.values = [...source];\n this.emit();\n }\n\n public add(value: DataType): void {\n if (this.values.some((item) => item.value === value.value)) {\n return;\n }\n this.values = [...this.values, value];\n this.emit();\n }\n\n public remove(id: Value): void {\n if (!this.values.some((item) => item.value === id)) {\n return;\n }\n this.values = this.values.filter((item) => item.value !== id);\n this.emit();\n }\n\n public clear(): void {\n if (this.values.length === 0) {\n return;\n }\n this.values = [];\n this.emit();\n }\n\n private emit(): void {\n this.listeners.forEach((listener) => listener());\n }\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SelectStore.js","sources":["src/internal/SelectStore.ts"],"sourcesContent":["import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { extractValues, isArraysEquals } from '@hh.ru/magritte-ui-select/internal/utils';\n\ntype Listener = () => void;\ntype Value = StaticDataFetcherItem['value'];\n\n// стор хранит выбранные объекты, а не ids\n// внешний onChange должен получать DataType | DataType[]\n// массив опций меняется дата провайдером => нужно место, где хранить обьекты DataType\nexport class SelectStore<DataType extends StaticDataFetcherItem> {\n private values: readonly DataType[];\n private readonly listeners = new Set<Listener>();\n\n public constructor(initial: readonly DataType[] = []) {\n this.values = [...initial];\n }\n\n public getSnapshot = (): readonly DataType[] => {\n return this.values;\n };\n\n public subscribe = (listener: Listener): VoidFunction => {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n };\n\n public replace(source: readonly DataType[]): void {\n // идентичность выбранных элементов определяется через поле value\n // так как value единственное поле которое StaticDataFetcherItem гарантирует\n if (isArraysEquals(extractValues<DataType>(this.values), extractValues<DataType>(source))) {\n return;\n }\n this.values = [...source];\n this.emit();\n }\n\n public add(value: DataType): void {\n if (this.values.some((item) => item.value === value.value)) {\n return;\n }\n this.values = [...this.values, value];\n this.emit();\n }\n\n public remove(id: Value): void {\n if (!this.values.some((item) => item.value === id)) {\n return;\n }\n this.values = this.values.filter((item) => item.value !== id);\n this.emit();\n }\n\n public clear(): void {\n if (this.values.length === 0) {\n return;\n }\n this.values = [];\n this.emit();\n }\n\n private emit(): void {\n this.listeners.forEach((listener) => listener());\n }\n}\n"],"names":[],"mappings":";;;AASO,MAAM,WAAoD,CAAA;AAAA,EACrD,MAAA,CAAA;AAAA,EACS,SAAA,uBAAgB,GAAc,EAAA,CAAA;AAAA,EAExC,WAAA,CAAY,OAA+B,GAAA,EAAI,EAAA;AAClD,IAAK,IAAA,CAAA,MAAA,GAAS,CAAC,GAAG,OAAO,CAAA,CAAA;AAAA,GAC7B;AAAA,EAEO,cAAc,MAA2B;AAC5C,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GAChB,CAAA;AAAA,EAEO,SAAA,GAAY,CAAC,QAAqC,KAAA;AACrD,IAAK,IAAA,CAAA,SAAA,CAAU,IAAI,QAAQ,CAAA,CAAA;AAC3B,IAAA,OAAO,MAAM;AACT,MAAK,IAAA,CAAA,SAAA,CAAU,OAAO,QAAQ,CAAA,CAAA;AAAA,KAClC,CAAA;AAAA,GACJ,CAAA;AAAA,EAEO,QAAQ,MAAmC,EAAA;AAG9C,IAAI,IAAA,cAAA,CAAe,cAAwB,IAAK,CAAA,MAAM,GAAG,aAAwB,CAAA,MAAM,CAAC,CAAG,EAAA;AACvF,MAAA,OAAA;AAAA,KACJ;AACA,IAAK,IAAA,CAAA,MAAA,GAAS,CAAC,GAAG,MAAM,CAAA,CAAA;AACxB,IAAA,IAAA,CAAK,IAAK,EAAA,CAAA;AAAA,GACd;AAAA,EAEO,IAAI,KAAuB,EAAA;AAC9B,IAAI,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA,CAAC,SAAS,IAAK,CAAA,KAAA,KAAU,KAAM,CAAA,KAAK,CAAG,EAAA;AACxD,MAAA,OAAA;AAAA,KACJ;AACA,IAAA,IAAA,CAAK,MAAS,GAAA,CAAC,GAAG,IAAA,CAAK,QAAQ,KAAK,CAAA,CAAA;AACpC,IAAA,IAAA,CAAK,IAAK,EAAA,CAAA;AAAA,GACd;AAAA,EAEO,OAAO,EAAiB,EAAA;AAC3B,IAAI,IAAA,CAAC,KAAK,MAAO,CAAA,IAAA,CAAK,CAAC,IAAS,KAAA,IAAA,CAAK,KAAU,KAAA,EAAE,CAAG,EAAA;AAChD,MAAA,OAAA;AAAA,KACJ;AACA,IAAK,IAAA,CAAA,MAAA,GAAS,KAAK,MAAO,CAAA,MAAA,CAAO,CAAC,IAAS,KAAA,IAAA,CAAK,UAAU,EAAE,CAAA,CAAA;AAC5D,IAAA,IAAA,CAAK,IAAK,EAAA,CAAA;AAAA,GACd;AAAA,EAEO,KAAc,GAAA;AACjB,IAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,KAAW,CAAG,EAAA;AAC1B,MAAA,OAAA;AAAA,KACJ;AACA,IAAA,IAAA,CAAK,SAAS,EAAC,CAAA;AACf,IAAA,IAAA,CAAK,IAAK,EAAA,CAAA;AAAA,GACd;AAAA,EAEQ,IAAa,GAAA;AACjB,IAAA,IAAA,CAAK,SAAU,CAAA,OAAA,CAAQ,CAAC,QAAA,KAAa,UAAU,CAAA,CAAA;AAAA,GACnD;AACJ;;;;"}
|
|
@@ -3,14 +3,23 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { createContext, useCallback, useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
const VisibilityContext = createContext(null);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const VisibilityProvider = ({
|
|
7
|
+
children,
|
|
8
|
+
showOptions,
|
|
9
|
+
setShowOptions
|
|
10
|
+
}) => {
|
|
11
|
+
const toggleListVisibility = useCallback(
|
|
12
|
+
(force) => setShowOptions((showOptions2) => force !== void 0 ? force : !showOptions2),
|
|
13
|
+
[setShowOptions]
|
|
14
|
+
);
|
|
15
|
+
const value = useMemo(
|
|
16
|
+
() => ({
|
|
17
|
+
showOptions,
|
|
18
|
+
toggleListVisibility
|
|
19
|
+
}),
|
|
20
|
+
[showOptions, toggleListVisibility]
|
|
21
|
+
);
|
|
22
|
+
return /* @__PURE__ */ jsx(VisibilityContext.Provider, { value, children });
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
export { VisibilityContext, VisibilityProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisibilityContext.js","sources":["src/internal/VisibilityContext.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type ReactElement,\n useMemo,\n useCallback,\n SetStateAction,\n Dispatch,\n} from 'react';\n\nexport interface VisibilityContextValue {\n showOptions: boolean;\n toggleListVisibility: (force?: boolean) => void;\n}\n\nexport const VisibilityContext = createContext<VisibilityContextValue | null>(null);\n\ninterface VisibilityProviderProps {\n children: ReactNode;\n showOptions: boolean;\n setShowOptions: Dispatch<SetStateAction<boolean>>;\n}\n\n// видимость пикера\nexport const VisibilityProvider = ({\n children,\n showOptions,\n setShowOptions,\n}: VisibilityProviderProps): ReactElement => {\n const toggleListVisibility = useCallback(\n (force?: boolean) => setShowOptions((showOptions) => (force !== undefined ? force : !showOptions)),\n [setShowOptions]\n );\n const value = useMemo(\n () => ({\n showOptions,\n toggleListVisibility,\n }),\n [showOptions, toggleListVisibility]\n );\n\n return <VisibilityContext.Provider value={value}>{children}</VisibilityContext.Provider>;\n};\n"],"names":["
|
|
1
|
+
{"version":3,"file":"VisibilityContext.js","sources":["src/internal/VisibilityContext.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type ReactElement,\n useMemo,\n useCallback,\n SetStateAction,\n Dispatch,\n} from 'react';\n\nexport interface VisibilityContextValue {\n showOptions: boolean;\n toggleListVisibility: (force?: boolean) => void;\n}\n\nexport const VisibilityContext = createContext<VisibilityContextValue | null>(null);\n\ninterface VisibilityProviderProps {\n children: ReactNode;\n showOptions: boolean;\n setShowOptions: Dispatch<SetStateAction<boolean>>;\n}\n\n// видимость пикера\nexport const VisibilityProvider = ({\n children,\n showOptions,\n setShowOptions,\n}: VisibilityProviderProps): ReactElement => {\n const toggleListVisibility = useCallback(\n (force?: boolean) => setShowOptions((showOptions) => (force !== undefined ? force : !showOptions)),\n [setShowOptions]\n );\n const value = useMemo(\n () => ({\n showOptions,\n toggleListVisibility,\n }),\n [showOptions, toggleListVisibility]\n );\n\n return <VisibilityContext.Provider value={value}>{children}</VisibilityContext.Provider>;\n};\n"],"names":["showOptions"],"mappings":";;;AAea,MAAA,iBAAA,GAAoB,cAA6C,IAAI,EAAA;AAS3E,MAAM,qBAAqB,CAAC;AAAA,EAC/B,QAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AACJ,CAA6C,KAAA;AACzC,EAAA,MAAM,oBAAuB,GAAA,WAAA;AAAA,IACzB,CAAC,UAAoB,cAAe,CAAA,CAACA,iBAAiB,KAAU,KAAA,KAAA,CAAA,GAAY,KAAQ,GAAA,CAACA,YAAY,CAAA;AAAA,IACjG,CAAC,cAAc,CAAA;AAAA,GACnB,CAAA;AACA,EAAA,MAAM,KAAQ,GAAA,OAAA;AAAA,IACV,OAAO;AAAA,MACH,WAAA;AAAA,MACA,oBAAA;AAAA,KACJ,CAAA;AAAA,IACA,CAAC,aAAa,oBAAoB,CAAA;AAAA,GACtC,CAAA;AAEA,EAAA,uBAAQ,GAAA,CAAA,iBAAA,CAAkB,QAAlB,EAAA,EAA2B,OAAe,QAAS,EAAA,CAAA,CAAA;AAC/D;;;;"}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { PropsWithChildren, FC } from 'react';
|
|
9
9
|
export declare const FocusTarget: {
|
|
10
|
-
readonly Trigger:
|
|
11
|
-
readonly OptionsList:
|
|
10
|
+
readonly Trigger: 'trigger';
|
|
11
|
+
readonly OptionsList: 'options-list';
|
|
12
12
|
};
|
|
13
13
|
export type FocusTarget = (typeof FocusTarget)[keyof typeof FocusTarget];
|
|
14
14
|
/**
|