@cloud-ru/ds-toolbar 1.0.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/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +301 -0
- package/dist/cjs/components/Toolbar/Toolbar.d.ts +3 -0
- package/dist/cjs/components/Toolbar/Toolbar.js +51 -0
- package/dist/cjs/components/Toolbar/helpers.d.ts +12 -0
- package/dist/cjs/components/Toolbar/helpers.js +27 -0
- package/dist/cjs/components/Toolbar/hooks/index.d.ts +2 -0
- package/dist/cjs/components/Toolbar/hooks/index.js +18 -0
- package/dist/cjs/components/Toolbar/hooks/useFilters.d.ts +12 -0
- package/dist/cjs/components/Toolbar/hooks/useFilters.js +55 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/index.d.ts +1 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/index.js +17 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/usePersistState.d.ts +9 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/usePersistState.js +72 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/index.d.ts +3 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/index.js +19 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/isDateString.d.ts +9 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/isDateString.js +45 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/parser.d.ts +4 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/parser.js +46 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/serializer.d.ts +11 -0
- package/dist/cjs/components/Toolbar/hooks/usePersistState/utils/serializer.js +41 -0
- package/dist/cjs/components/Toolbar/index.d.ts +3 -0
- package/dist/cjs/components/Toolbar/index.js +19 -0
- package/dist/cjs/components/Toolbar/styles.module.css +297 -0
- package/dist/cjs/components/Toolbar/types.d.ts +80 -0
- package/dist/cjs/components/Toolbar/types.js +2 -0
- package/dist/cjs/components/Toolbar/typesUtils.d.ts +12 -0
- package/dist/cjs/components/Toolbar/typesUtils.js +2 -0
- package/dist/cjs/components/Toolbar/utils/buildMobileOverflowActions.d.ts +10 -0
- package/dist/cjs/components/Toolbar/utils/buildMobileOverflowActions.js +84 -0
- package/dist/cjs/components/Toolbar/utils/toolbarAfterOverflow.d.ts +2 -0
- package/dist/cjs/components/Toolbar/utils/toolbarAfterOverflow.js +5 -0
- package/dist/cjs/components/index.d.ts +4 -0
- package/dist/cjs/components/index.js +23 -0
- package/dist/cjs/helperComponents/BulkActions/BulkActions.d.ts +2 -0
- package/dist/cjs/helperComponents/BulkActions/BulkActions.js +20 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsCheckbox/BulkActionsCheckbox.d.ts +8 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsCheckbox/BulkActionsCheckbox.js +20 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsCheckbox/index.d.ts +1 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsCheckbox/index.js +17 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsCheckbox/styles.module.css +3 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsControls/BulkActionsControls.d.ts +17 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsControls/BulkActionsControls.js +39 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsControls/index.d.ts +1 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsControls/index.js +17 -0
- package/dist/cjs/helperComponents/BulkActions/components/BulkActionsControls/styles.module.css +39 -0
- package/dist/cjs/helperComponents/BulkActions/components/MobileBulkActionsSheet/MobileBulkActionsSheet.d.ts +14 -0
- package/dist/cjs/helperComponents/BulkActions/components/MobileBulkActionsSheet/MobileBulkActionsSheet.js +27 -0
- package/dist/cjs/helperComponents/BulkActions/components/MobileBulkActionsSheet/index.d.ts +1 -0
- package/dist/cjs/helperComponents/BulkActions/components/MobileBulkActionsSheet/index.js +17 -0
- package/dist/cjs/helperComponents/BulkActions/components/SelectionLabel/SelectionLabel.d.ts +9 -0
- package/dist/cjs/helperComponents/BulkActions/components/SelectionLabel/SelectionLabel.js +21 -0
- package/dist/cjs/helperComponents/BulkActions/components/SelectionLabel/index.d.ts +1 -0
- package/dist/cjs/helperComponents/BulkActions/components/SelectionLabel/index.js +17 -0
- package/dist/cjs/helperComponents/BulkActions/components/SelectionLabel/styles.module.css +40 -0
- package/dist/cjs/helperComponents/BulkActions/components/index.d.ts +4 -0
- package/dist/cjs/helperComponents/BulkActions/components/index.js +20 -0
- package/dist/cjs/helperComponents/BulkActions/index.d.ts +2 -0
- package/dist/cjs/helperComponents/BulkActions/index.js +18 -0
- package/dist/cjs/helperComponents/BulkActions/styles.module.css +9 -0
- package/dist/cjs/helperComponents/BulkActions/types.d.ts +31 -0
- package/dist/cjs/helperComponents/BulkActions/types.js +2 -0
- package/dist/cjs/helperComponents/BulkActions/utils.d.ts +15 -0
- package/dist/cjs/helperComponents/BulkActions/utils.js +26 -0
- package/dist/cjs/helperComponents/DataView/DataView.d.ts +2 -0
- package/dist/cjs/helperComponents/DataView/DataView.js +9 -0
- package/dist/cjs/helperComponents/DataView/constants.d.ts +9 -0
- package/dist/cjs/helperComponents/DataView/constants.js +13 -0
- package/dist/cjs/helperComponents/DataView/index.d.ts +3 -0
- package/dist/cjs/helperComponents/DataView/index.js +19 -0
- package/dist/cjs/helperComponents/DataView/types.d.ts +12 -0
- package/dist/cjs/helperComponents/DataView/types.js +2 -0
- package/dist/cjs/helperComponents/FilterButton/FilterButton.d.ts +12 -0
- package/dist/cjs/helperComponents/FilterButton/FilterButton.js +17 -0
- package/dist/cjs/helperComponents/FilterButton/index.d.ts +1 -0
- package/dist/cjs/helperComponents/FilterButton/index.js +17 -0
- package/dist/cjs/helperComponents/FilterButton/styles.module.css +5 -0
- package/dist/cjs/helperComponents/MoreActions/MoreActions.d.ts +13 -0
- package/dist/cjs/helperComponents/MoreActions/MoreActions.js +35 -0
- package/dist/cjs/helperComponents/MoreActions/index.d.ts +1 -0
- package/dist/cjs/helperComponents/MoreActions/index.js +17 -0
- package/dist/cjs/helperComponents/MoreActions/styles.module.css +5 -0
- package/dist/cjs/helperComponents/Search/ToolbarSearch.d.ts +9 -0
- package/dist/cjs/helperComponents/Search/ToolbarSearch.js +19 -0
- package/dist/cjs/helperComponents/Search/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Search/index.js +17 -0
- package/dist/cjs/helperComponents/Search/styles.module.css +25 -0
- package/dist/cjs/helperComponents/Separator/Separator.d.ts +1 -0
- package/dist/cjs/helperComponents/Separator/Separator.js +11 -0
- package/dist/cjs/helperComponents/Separator/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Separator/index.js +17 -0
- package/dist/cjs/helperComponents/Separator/styles.module.css +14 -0
- package/dist/cjs/helperComponents/index.d.ts +6 -0
- package/dist/cjs/helperComponents/index.js +22 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/locale/index.d.ts +55 -0
- package/dist/cjs/locale/index.js +32 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +437 -0
- package/dist/cjs/testIds.d.ts +24 -0
- package/dist/cjs/testIds.js +27 -0
- package/dist/esm/components/Toolbar/Toolbar.d.ts +3 -0
- package/dist/esm/components/Toolbar/Toolbar.js +45 -0
- package/dist/esm/components/Toolbar/helpers.d.ts +12 -0
- package/dist/esm/components/Toolbar/helpers.js +23 -0
- package/dist/esm/components/Toolbar/hooks/index.d.ts +2 -0
- package/dist/esm/components/Toolbar/hooks/index.js +2 -0
- package/dist/esm/components/Toolbar/hooks/useFilters.d.ts +12 -0
- package/dist/esm/components/Toolbar/hooks/useFilters.js +49 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/index.d.ts +1 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/index.js +1 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/usePersistState.d.ts +9 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/usePersistState.js +69 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/index.d.ts +3 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/index.js +3 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/isDateString.d.ts +9 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/isDateString.js +42 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/parser.d.ts +4 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/parser.js +42 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/serializer.d.ts +11 -0
- package/dist/esm/components/Toolbar/hooks/usePersistState/utils/serializer.js +37 -0
- package/dist/esm/components/Toolbar/index.d.ts +3 -0
- package/dist/esm/components/Toolbar/index.js +3 -0
- package/dist/esm/components/Toolbar/styles.module.css +297 -0
- package/dist/esm/components/Toolbar/types.d.ts +80 -0
- package/dist/esm/components/Toolbar/types.js +1 -0
- package/dist/esm/components/Toolbar/typesUtils.d.ts +12 -0
- package/dist/esm/components/Toolbar/typesUtils.js +1 -0
- package/dist/esm/components/Toolbar/utils/buildMobileOverflowActions.d.ts +10 -0
- package/dist/esm/components/Toolbar/utils/buildMobileOverflowActions.js +81 -0
- package/dist/esm/components/Toolbar/utils/toolbarAfterOverflow.d.ts +2 -0
- package/dist/esm/components/Toolbar/utils/toolbarAfterOverflow.js +2 -0
- package/dist/esm/components/index.d.ts +4 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/helperComponents/BulkActions/BulkActions.d.ts +2 -0
- package/dist/esm/helperComponents/BulkActions/BulkActions.js +14 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsCheckbox/BulkActionsCheckbox.d.ts +8 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsCheckbox/BulkActionsCheckbox.js +14 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsCheckbox/index.d.ts +1 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsCheckbox/index.js +1 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsCheckbox/styles.module.css +3 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsControls/BulkActionsControls.d.ts +17 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsControls/BulkActionsControls.js +33 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsControls/index.d.ts +1 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsControls/index.js +1 -0
- package/dist/esm/helperComponents/BulkActions/components/BulkActionsControls/styles.module.css +39 -0
- package/dist/esm/helperComponents/BulkActions/components/MobileBulkActionsSheet/MobileBulkActionsSheet.d.ts +14 -0
- package/dist/esm/helperComponents/BulkActions/components/MobileBulkActionsSheet/MobileBulkActionsSheet.js +24 -0
- package/dist/esm/helperComponents/BulkActions/components/MobileBulkActionsSheet/index.d.ts +1 -0
- package/dist/esm/helperComponents/BulkActions/components/MobileBulkActionsSheet/index.js +1 -0
- package/dist/esm/helperComponents/BulkActions/components/SelectionLabel/SelectionLabel.d.ts +9 -0
- package/dist/esm/helperComponents/BulkActions/components/SelectionLabel/SelectionLabel.js +15 -0
- package/dist/esm/helperComponents/BulkActions/components/SelectionLabel/index.d.ts +1 -0
- package/dist/esm/helperComponents/BulkActions/components/SelectionLabel/index.js +1 -0
- package/dist/esm/helperComponents/BulkActions/components/SelectionLabel/styles.module.css +40 -0
- package/dist/esm/helperComponents/BulkActions/components/index.d.ts +4 -0
- package/dist/esm/helperComponents/BulkActions/components/index.js +4 -0
- package/dist/esm/helperComponents/BulkActions/index.d.ts +2 -0
- package/dist/esm/helperComponents/BulkActions/index.js +2 -0
- package/dist/esm/helperComponents/BulkActions/styles.module.css +9 -0
- package/dist/esm/helperComponents/BulkActions/types.d.ts +31 -0
- package/dist/esm/helperComponents/BulkActions/types.js +1 -0
- package/dist/esm/helperComponents/BulkActions/utils.d.ts +15 -0
- package/dist/esm/helperComponents/BulkActions/utils.js +21 -0
- package/dist/esm/helperComponents/DataView/DataView.d.ts +2 -0
- package/dist/esm/helperComponents/DataView/DataView.js +6 -0
- package/dist/esm/helperComponents/DataView/constants.d.ts +9 -0
- package/dist/esm/helperComponents/DataView/constants.js +10 -0
- package/dist/esm/helperComponents/DataView/index.d.ts +3 -0
- package/dist/esm/helperComponents/DataView/index.js +3 -0
- package/dist/esm/helperComponents/DataView/types.d.ts +12 -0
- package/dist/esm/helperComponents/DataView/types.js +1 -0
- package/dist/esm/helperComponents/FilterButton/FilterButton.d.ts +12 -0
- package/dist/esm/helperComponents/FilterButton/FilterButton.js +11 -0
- package/dist/esm/helperComponents/FilterButton/index.d.ts +1 -0
- package/dist/esm/helperComponents/FilterButton/index.js +1 -0
- package/dist/esm/helperComponents/FilterButton/styles.module.css +5 -0
- package/dist/esm/helperComponents/MoreActions/MoreActions.d.ts +13 -0
- package/dist/esm/helperComponents/MoreActions/MoreActions.js +29 -0
- package/dist/esm/helperComponents/MoreActions/index.d.ts +1 -0
- package/dist/esm/helperComponents/MoreActions/index.js +1 -0
- package/dist/esm/helperComponents/MoreActions/styles.module.css +5 -0
- package/dist/esm/helperComponents/Search/ToolbarSearch.d.ts +9 -0
- package/dist/esm/helperComponents/Search/ToolbarSearch.js +13 -0
- package/dist/esm/helperComponents/Search/index.d.ts +1 -0
- package/dist/esm/helperComponents/Search/index.js +1 -0
- package/dist/esm/helperComponents/Search/styles.module.css +25 -0
- package/dist/esm/helperComponents/Separator/Separator.d.ts +1 -0
- package/dist/esm/helperComponents/Separator/Separator.js +5 -0
- package/dist/esm/helperComponents/Separator/index.d.ts +1 -0
- package/dist/esm/helperComponents/Separator/index.js +1 -0
- package/dist/esm/helperComponents/Separator/styles.module.css +14 -0
- package/dist/esm/helperComponents/index.d.ts +6 -0
- package/dist/esm/helperComponents/index.js +6 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/locale/index.d.ts +55 -0
- package/dist/esm/locale/index.js +29 -0
- package/dist/esm/style.css +437 -0
- package/dist/esm/testIds.d.ts +24 -0
- package/dist/esm/testIds.js +24 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +65 -0
- package/src/components/Toolbar/Toolbar.tsx +145 -0
- package/src/components/Toolbar/helpers.ts +39 -0
- package/src/components/Toolbar/hooks/index.ts +2 -0
- package/src/components/Toolbar/hooks/useFilters.ts +87 -0
- package/src/components/Toolbar/hooks/usePersistState/index.ts +1 -0
- package/src/components/Toolbar/hooks/usePersistState/usePersistState.ts +107 -0
- package/src/components/Toolbar/hooks/usePersistState/utils/index.ts +3 -0
- package/src/components/Toolbar/hooks/usePersistState/utils/isDateString.ts +49 -0
- package/src/components/Toolbar/hooks/usePersistState/utils/parser.ts +62 -0
- package/src/components/Toolbar/hooks/usePersistState/utils/serializer.ts +51 -0
- package/src/components/Toolbar/index.ts +3 -0
- package/src/components/Toolbar/styles.module.scss +116 -0
- package/src/components/Toolbar/types.ts +99 -0
- package/src/components/Toolbar/typesUtils.ts +17 -0
- package/src/components/Toolbar/utils/buildMobileOverflowActions.tsx +142 -0
- package/src/components/Toolbar/utils/toolbarAfterOverflow.ts +2 -0
- package/src/components/index.ts +4 -0
- package/src/helperComponents/BulkActions/BulkActions.tsx +54 -0
- package/src/helperComponents/BulkActions/components/BulkActionsCheckbox/BulkActionsCheckbox.tsx +35 -0
- package/src/helperComponents/BulkActions/components/BulkActionsCheckbox/index.ts +1 -0
- package/src/helperComponents/BulkActions/components/BulkActionsCheckbox/styles.module.scss +3 -0
- package/src/helperComponents/BulkActions/components/BulkActionsControls/BulkActionsControls.tsx +135 -0
- package/src/helperComponents/BulkActions/components/BulkActionsControls/index.ts +1 -0
- package/src/helperComponents/BulkActions/components/BulkActionsControls/styles.module.scss +49 -0
- package/src/helperComponents/BulkActions/components/MobileBulkActionsSheet/MobileBulkActionsSheet.tsx +88 -0
- package/src/helperComponents/BulkActions/components/MobileBulkActionsSheet/index.ts +1 -0
- package/src/helperComponents/BulkActions/components/SelectionLabel/SelectionLabel.tsx +40 -0
- package/src/helperComponents/BulkActions/components/SelectionLabel/index.ts +1 -0
- package/src/helperComponents/BulkActions/components/SelectionLabel/styles.module.scss +38 -0
- package/src/helperComponents/BulkActions/components/index.ts +4 -0
- package/src/helperComponents/BulkActions/index.ts +2 -0
- package/src/helperComponents/BulkActions/styles.module.scss +13 -0
- package/src/helperComponents/BulkActions/types.ts +32 -0
- package/src/helperComponents/BulkActions/utils.tsx +32 -0
- package/src/helperComponents/DataView/DataView.tsx +22 -0
- package/src/helperComponents/DataView/constants.tsx +15 -0
- package/src/helperComponents/DataView/index.ts +3 -0
- package/src/helperComponents/DataView/types.ts +15 -0
- package/src/helperComponents/FilterButton/FilterButton.tsx +40 -0
- package/src/helperComponents/FilterButton/index.ts +1 -0
- package/src/helperComponents/FilterButton/styles.module.scss +5 -0
- package/src/helperComponents/MoreActions/MoreActions.tsx +69 -0
- package/src/helperComponents/MoreActions/index.ts +1 -0
- package/src/helperComponents/MoreActions/styles.module.scss +5 -0
- package/src/helperComponents/Search/ToolbarSearch.tsx +48 -0
- package/src/helperComponents/Search/index.ts +1 -0
- package/src/helperComponents/Search/styles.module.scss +35 -0
- package/src/helperComponents/Separator/Separator.tsx +9 -0
- package/src/helperComponents/Separator/index.ts +1 -0
- package/src/helperComponents/Separator/styles.module.scss +18 -0
- package/src/helperComponents/index.ts +6 -0
- package/src/index.ts +5 -0
- package/src/locale/index.ts +33 -0
- package/src/testIds.ts +24 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useFilters = useFilters;
|
|
7
|
+
const adaptive_1 = require("@cloud-ru/ds-adaptive");
|
|
8
|
+
const chips_1 = require("@cloud-ru/ds-chips");
|
|
9
|
+
const utils_1 = require("@cloud-ru/ds-utils");
|
|
10
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const styles_module_scss_1 = __importDefault(require('../styles.module.css'));
|
|
13
|
+
function useFilters({ filterRow, }) {
|
|
14
|
+
const { layoutType } = (0, adaptive_1.useAdaptiveLayout)();
|
|
15
|
+
const isMobile = (0, adaptive_1.isMobileLayout)(layoutType);
|
|
16
|
+
const defaultOpen = isMobile ? (filterRow?.initialOpen ?? false) : false;
|
|
17
|
+
const [filtersOpen, setFiltersOpen] = (0, utils_1.useUncontrolledProp)(filterRow?.open, defaultOpen, newValue => {
|
|
18
|
+
const result = typeof newValue === 'function' ? newValue(filtersOpen) : newValue;
|
|
19
|
+
filterRow?.onOpenChange?.(result);
|
|
20
|
+
});
|
|
21
|
+
const [value, setValue] = (0, utils_1.useUncontrolledProp)(filterRow?.value, (filterRow?.defaultValue ?? {}), newValue => {
|
|
22
|
+
const result = typeof newValue === 'function' ? newValue(value) : newValue;
|
|
23
|
+
filterRow?.onChange?.(result);
|
|
24
|
+
});
|
|
25
|
+
const [visibleFilters, setVisibleFilters] = (0, utils_1.useUncontrolledProp)(filterRow?.visibleFilters, Object.keys(value), newState => {
|
|
26
|
+
const result = typeof newState === 'function' ? newState(visibleFilters) : newState;
|
|
27
|
+
filterRow?.onVisibleFiltersChange?.(result);
|
|
28
|
+
});
|
|
29
|
+
const patchedFilters = (0, react_1.useMemo)(() => (filterRow?.filters ?? []).map(filter => {
|
|
30
|
+
if (!isMobile && ['single', 'multiple'].includes(filter.type)) {
|
|
31
|
+
return {
|
|
32
|
+
...filter,
|
|
33
|
+
dropDownClassName: (0, classnames_1.default)(filter.dropDownClassName, styles_module_scss_1.default.list),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return filter;
|
|
37
|
+
}), [filterRow?.filters, isMobile]);
|
|
38
|
+
const numberOfFilters = (0, react_1.useMemo)(() => Object.keys(value).reduce((result, filterKey) => result + Number((0, chips_1.hasFilterBeenApplied)(value[filterKey])), 0), [value]);
|
|
39
|
+
return {
|
|
40
|
+
filterButton: filterRow ? { open: filtersOpen, onOpenChange: setFiltersOpen, numberOfFilters } : undefined,
|
|
41
|
+
filterRow: filtersOpen && filterRow
|
|
42
|
+
? {
|
|
43
|
+
...filterRow,
|
|
44
|
+
open: undefined,
|
|
45
|
+
onOpenChange: undefined,
|
|
46
|
+
initialOpen: undefined,
|
|
47
|
+
filters: patchedFilters,
|
|
48
|
+
value,
|
|
49
|
+
onChange: setValue,
|
|
50
|
+
visibleFilters,
|
|
51
|
+
onVisibleFiltersChange: setVisibleFilters,
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './usePersistState';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./usePersistState"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FiltersState } from '@cloud-ru/ds-chips';
|
|
2
|
+
import { ToolbarPersistConfig } from '../../types';
|
|
3
|
+
type UsePersistStateProps<TState extends FiltersState = Record<string, unknown>> = {
|
|
4
|
+
persist?: ToolbarPersistConfig<TState>;
|
|
5
|
+
filter?: TState;
|
|
6
|
+
search?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function usePersistState<TState extends FiltersState = Record<string, unknown>>({ persist, filter, search, }: UsePersistStateProps<TState>): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePersistState = usePersistState;
|
|
4
|
+
const utils_1 = require("@cloud-ru/ds-utils");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const utils_2 = require("./utils");
|
|
7
|
+
function runPersistStateHydrationOnce({ hasHydratedRef, defaultState, onLoad, }) {
|
|
8
|
+
if (hasHydratedRef.current) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (defaultState) {
|
|
12
|
+
onLoad?.({
|
|
13
|
+
...defaultState,
|
|
14
|
+
filter: (0, utils_2.prepareDataForFilter)(defaultState.filter ?? {}),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
hasHydratedRef.current = true;
|
|
18
|
+
}
|
|
19
|
+
function usePersistState({ persist, filter, search, }) {
|
|
20
|
+
const hasHydratedRef = (0, react_1.useRef)(false);
|
|
21
|
+
const skipInitialPersistRef = (0, react_1.useRef)(true);
|
|
22
|
+
const onLoadRef = (0, react_1.useRef)(persist?.onLoad);
|
|
23
|
+
onLoadRef.current = persist?.onLoad;
|
|
24
|
+
const dataPersistOptions = (0, react_1.useMemo)(() => {
|
|
25
|
+
if (!persist?.filterQueryKey || !persist?.id)
|
|
26
|
+
return undefined;
|
|
27
|
+
const defaultValidate = (value) => {
|
|
28
|
+
const filterOk = value?.filter === undefined || (typeof value.filter === 'object' && value.filter !== null);
|
|
29
|
+
const searchOk = value?.search === undefined || typeof value.search === 'string';
|
|
30
|
+
return Boolean(filterOk && searchOk);
|
|
31
|
+
};
|
|
32
|
+
const combinedValidate = (value) => {
|
|
33
|
+
const baseValid = defaultValidate(value);
|
|
34
|
+
return persist?.validateData ? baseValid && persist.validateData(value) : baseValid;
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
queryKey: persist.filterQueryKey,
|
|
38
|
+
localStorageKey: `${persist.id}_filter`,
|
|
39
|
+
validateData: combinedValidate,
|
|
40
|
+
};
|
|
41
|
+
}, [persist]);
|
|
42
|
+
const { getDefaultData, setDataToStorages } = (0, utils_1.useDataPersist)({
|
|
43
|
+
options: dataPersistOptions,
|
|
44
|
+
serializer: value => (persist?.serializer ? persist.serializer(value) : (0, utils_2.defaultSerializer)(value)),
|
|
45
|
+
parser: (value) => (persist?.parser ? persist.parser(value) : (0, utils_2.defaultParser)(value)),
|
|
46
|
+
});
|
|
47
|
+
const defaultState = (0, react_1.useMemo)(getDefaultData, [getDefaultData]);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
runPersistStateHydrationOnce({
|
|
50
|
+
hasHydratedRef,
|
|
51
|
+
defaultState,
|
|
52
|
+
onLoad: onLoadRef.current,
|
|
53
|
+
});
|
|
54
|
+
}, [defaultState]);
|
|
55
|
+
(0, react_1.useEffect)(() => {
|
|
56
|
+
if (!persist?.id || !persist?.filterQueryKey || !hasHydratedRef.current) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (skipInitialPersistRef.current) {
|
|
60
|
+
skipInitialPersistRef.current = false;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const snapshot = {
|
|
64
|
+
...(persist.state ?? getDefaultData() ?? {}),
|
|
65
|
+
...(filter ? { filter } : {}),
|
|
66
|
+
...(search !== undefined ? { search } : {}),
|
|
67
|
+
};
|
|
68
|
+
if (Object.keys(snapshot).length === 0)
|
|
69
|
+
return;
|
|
70
|
+
setDataToStorages(snapshot);
|
|
71
|
+
}, [persist?.id, persist?.filterQueryKey, persist?.state, filter, search, setDataToStorages, getDefaultData]);
|
|
72
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./parser"), exports);
|
|
18
|
+
__exportStar(require("./serializer"), exports);
|
|
19
|
+
__exportStar(require("./isDateString"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Утилита для проверки значения на соответствие дате.
|
|
2
|
+
* Поддерживает:
|
|
3
|
+
* - ISO форматы: '2021-01-01T00:00:00Z', '2021-01-01T15:55:42.000Z'
|
|
4
|
+
* - Форматы с точками: '12.03.2025', '12.03.2025 12:00'
|
|
5
|
+
* - Частичные даты: '2026', '2026-01'
|
|
6
|
+
* - Timestamps: '1768492519666', '-62167219200000'
|
|
7
|
+
* - Временные зоны: '+03:00', '-05:00'
|
|
8
|
+
*/
|
|
9
|
+
export declare function isDateString(value: unknown): value is string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDateString = isDateString;
|
|
4
|
+
const DATE_SYMBOLS_REGEXP = /[\d\-:.TZ+\s]/g;
|
|
5
|
+
/** Утилита для проверки значения на соответствие дате.
|
|
6
|
+
* Поддерживает:
|
|
7
|
+
* - ISO форматы: '2021-01-01T00:00:00Z', '2021-01-01T15:55:42.000Z'
|
|
8
|
+
* - Форматы с точками: '12.03.2025', '12.03.2025 12:00'
|
|
9
|
+
* - Частичные даты: '2026', '2026-01'
|
|
10
|
+
* - Timestamps: '1768492519666', '-62167219200000'
|
|
11
|
+
* - Временные зоны: '+03:00', '-05:00'
|
|
12
|
+
*/
|
|
13
|
+
function isDateString(value) {
|
|
14
|
+
if (typeof value !== 'string')
|
|
15
|
+
return false;
|
|
16
|
+
const trimmed = value.trim();
|
|
17
|
+
if (trimmed.length === 0)
|
|
18
|
+
return false;
|
|
19
|
+
const nonDateSymbols = trimmed.replaceAll(DATE_SYMBOLS_REGEXP, '');
|
|
20
|
+
if (nonDateSymbols.length > 0)
|
|
21
|
+
return false;
|
|
22
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
23
|
+
if (trimmed.length <= 2)
|
|
24
|
+
return false;
|
|
25
|
+
const num = Number(trimmed);
|
|
26
|
+
const date = new Date(num);
|
|
27
|
+
if (isNaN(date.getTime()))
|
|
28
|
+
return false;
|
|
29
|
+
return date.getTime() === num;
|
|
30
|
+
}
|
|
31
|
+
if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(trimmed)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const date = new Date(trimmed);
|
|
35
|
+
if (isNaN(date.getTime()))
|
|
36
|
+
return false;
|
|
37
|
+
const hasDateLikeStructure = /^\d{4}/.test(trimmed) ||
|
|
38
|
+
/^\d{1,2}[.-]\d{1,2}[.-]\d{4}/.test(trimmed) ||
|
|
39
|
+
/^\d{4}[.-]\d{1,2}[.-]\d{1,2}/.test(trimmed) ||
|
|
40
|
+
/T/.test(trimmed);
|
|
41
|
+
if (!hasDateLikeStructure && !trimmed.includes(':')) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return date.toString() !== 'Invalid Date';
|
|
45
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FiltersState } from '@cloud-ru/ds-chips';
|
|
2
|
+
import { PersistedFilterState } from '../../../types';
|
|
3
|
+
export declare function defaultParser<T extends FiltersState>(value: string): PersistedFilterState<T>;
|
|
4
|
+
export declare function prepareDataForFilter<T>(filter: Record<string, unknown>): T;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultParser = defaultParser;
|
|
4
|
+
exports.prepareDataForFilter = prepareDataForFilter;
|
|
5
|
+
const ft_request_payload_transform_1 = require("@cloud-ru/ft-request-payload-transform");
|
|
6
|
+
const isDateString_1 = require("./isDateString");
|
|
7
|
+
function parseValue(value) {
|
|
8
|
+
if ((0, isDateString_1.isDateString)(value)) {
|
|
9
|
+
return new Date(value);
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'boolean') {
|
|
12
|
+
return String(value);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function mapFilterFromPayload(value) {
|
|
17
|
+
if (!value) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return Object.fromEntries(value.map(filter => {
|
|
21
|
+
if (Array.isArray(filter.value)) {
|
|
22
|
+
return [filter.field, filter.value.map(parseValue)];
|
|
23
|
+
}
|
|
24
|
+
return [filter.field, parseValue(filter.value)];
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
function defaultParser(value) {
|
|
28
|
+
const parsed = (0, ft_request_payload_transform_1.parseQueryParamsString)(value);
|
|
29
|
+
return {
|
|
30
|
+
pagination: parsed?.pagination,
|
|
31
|
+
ordering: parsed?.ordering,
|
|
32
|
+
search: parsed?.search?.toString() || '',
|
|
33
|
+
filter: mapFilterFromPayload(parsed?.filter) ?? {},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function prepareDataForFilter(filter) {
|
|
37
|
+
return Object.entries(filter).reduce((acc, [key, value]) => {
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
acc[key] = value.map(parseValue);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
acc[key] = parseValue(value);
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
}, { ...filter });
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FiltersState } from '@cloud-ru/ds-chips';
|
|
2
|
+
import { RequestPayloadParams } from '@cloud-ru/ft-request-payload-transform';
|
|
3
|
+
import { PersistedFilterState } from '../../../types';
|
|
4
|
+
/** Вспомогательная функция для преобразования состояния тулбара к формату RequestPayloadParams */
|
|
5
|
+
export declare function formatFilterStateToRequestPayload<T extends FiltersState>(value?: PersistedFilterState<T> | null): {
|
|
6
|
+
toObject(): Partial<RequestPayloadParams>;
|
|
7
|
+
toString(params?: {
|
|
8
|
+
encode?: boolean;
|
|
9
|
+
}): string;
|
|
10
|
+
};
|
|
11
|
+
export declare function defaultSerializer<T extends FiltersState>(value: PersistedFilterState<T>): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatFilterStateToRequestPayload = formatFilterStateToRequestPayload;
|
|
4
|
+
exports.defaultSerializer = defaultSerializer;
|
|
5
|
+
const ft_request_payload_transform_1 = require("@cloud-ru/ft-request-payload-transform");
|
|
6
|
+
function mapValueToString(filter) {
|
|
7
|
+
if (filter instanceof Date) {
|
|
8
|
+
return filter.toISOString();
|
|
9
|
+
}
|
|
10
|
+
return filter;
|
|
11
|
+
}
|
|
12
|
+
function mapFilterToPayload(value) {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return Object.entries(value)
|
|
17
|
+
.filter(([, v]) => v !== undefined)
|
|
18
|
+
.map(([key, v]) => Array.isArray(v)
|
|
19
|
+
? {
|
|
20
|
+
value: v.map(mapValueToString),
|
|
21
|
+
condition: 'in',
|
|
22
|
+
field: key,
|
|
23
|
+
}
|
|
24
|
+
: {
|
|
25
|
+
value: mapValueToString(v),
|
|
26
|
+
condition: 'eq',
|
|
27
|
+
field: key,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** Вспомогательная функция для преобразования состояния тулбара к формату RequestPayloadParams */
|
|
31
|
+
function formatFilterStateToRequestPayload(value) {
|
|
32
|
+
return (0, ft_request_payload_transform_1.createRequestPayload)({
|
|
33
|
+
pagination: value?.pagination,
|
|
34
|
+
search: value?.search ?? '',
|
|
35
|
+
ordering: value?.ordering,
|
|
36
|
+
filter: mapFilterToPayload(value?.filter),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function defaultSerializer(value) {
|
|
40
|
+
return formatFilterStateToRequestPayload(value).toString();
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Toolbar"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./hooks"), exports);
|