@wix/auto-patterns 1.42.0 → 1.44.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/dist/cjs/components/AutoPatternsApp/AutoPatternsApp.js +19 -5
- package/dist/cjs/components/AutoPatternsApp/AutoPatternsApp.js.map +1 -1
- package/dist/cjs/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js +29 -74
- package/dist/cjs/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map +1 -1
- package/dist/cjs/components/AutoPatternsGrid/AutoPatternsGrid.js +147 -25
- package/dist/cjs/components/AutoPatternsGrid/AutoPatternsGrid.js.map +1 -1
- package/dist/cjs/components/AutoPatternsRoute/AutoPatternsPage.js +10 -27
- package/dist/cjs/components/AutoPatternsRoute/AutoPatternsPage.js.map +1 -1
- package/dist/cjs/components/AutoPatternsTable/AutoPatternsTable.js +141 -40
- package/dist/cjs/components/AutoPatternsTable/AutoPatternsTable.js.map +1 -1
- package/dist/cjs/components/AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch.js +169 -9
- package/dist/cjs/components/AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch.js.map +1 -1
- package/dist/cjs/hooks/getCommonCollectionFeaturesAsync.js +11 -0
- package/dist/cjs/hooks/getCommonCollectionFeaturesAsync.js.map +1 -0
- package/dist/cjs/hooks/getFilterComponent.js +52 -0
- package/dist/cjs/hooks/getFilterComponent.js.map +1 -0
- package/dist/cjs/hooks/index.js +4 -11
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/pluginsDynamicImports.js +25 -0
- package/dist/cjs/hooks/pluginsDynamicImports.js.map +1 -0
- package/dist/cjs/hooks/useAsyncFeaturesPromiseState.js +30 -0
- package/dist/cjs/hooks/useAsyncFeaturesPromiseState.js.map +1 -0
- package/dist/cjs/hooks/useBaseCollectionComponentReadyFeatures.js +62 -0
- package/dist/cjs/hooks/useBaseCollectionComponentReadyFeatures.js.map +1 -0
- package/dist/cjs/hooks/useBasePatternsStateParams.js +36 -0
- package/dist/cjs/hooks/useBasePatternsStateParams.js.map +1 -0
- package/dist/cjs/hooks/useCollectionInitAsyncDeps.js +15 -0
- package/dist/cjs/hooks/useCollectionInitAsyncDeps.js.map +1 -0
- package/dist/cjs/hooks/useCommonCollectionFeatures.js +14 -4
- package/dist/cjs/hooks/useCommonCollectionFeatures.js.map +1 -1
- package/dist/cjs/hooks/useFilters.js +17 -103
- package/dist/cjs/hooks/useFilters.js.map +1 -1
- package/dist/cjs/hooks/useFiltersState.js +112 -0
- package/dist/cjs/hooks/useFiltersState.js.map +1 -0
- package/dist/cjs/hooks/useGridFeaturesAsync.js +42 -0
- package/dist/cjs/hooks/useGridFeaturesAsync.js.map +1 -0
- package/dist/cjs/hooks/useGridVisibleFieldIds.js +17 -0
- package/dist/cjs/hooks/useGridVisibleFieldIds.js.map +1 -0
- package/dist/cjs/hooks/useSyncCollectionStateToAppContext.js +22 -0
- package/dist/cjs/hooks/useSyncCollectionStateToAppContext.js.map +1 -0
- package/dist/cjs/hooks/useTableFeaturesAsync.js +51 -0
- package/dist/cjs/hooks/useTableFeaturesAsync.js.map +1 -0
- package/dist/cjs/hooks/useTableGridSwitchFeaturesAsync.js +52 -0
- package/dist/cjs/hooks/useTableGridSwitchFeaturesAsync.js.map +1 -0
- package/dist/cjs/hooks/useTableSections.js +18 -0
- package/dist/cjs/hooks/useTableSections.js.map +1 -0
- package/dist/cjs/utils/filterCreators.js +16 -31
- package/dist/cjs/utils/filterCreators.js.map +1 -1
- package/dist/cjs/utils/minimalRequiredPatternsRuntimeCheck.js +18 -0
- package/dist/cjs/utils/minimalRequiredPatternsRuntimeCheck.js.map +1 -0
- package/dist/cjs/utils/minimalRequiredRuntimeCheck.js +21 -0
- package/dist/cjs/utils/minimalRequiredRuntimeCheck.js.map +1 -0
- package/dist/esm/components/AutoPatternsApp/AutoPatternsApp.js +14 -1
- package/dist/esm/components/AutoPatternsApp/AutoPatternsApp.js.map +1 -1
- package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js +23 -31
- package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map +1 -1
- package/dist/esm/components/AutoPatternsGrid/AutoPatternsGrid.js +134 -28
- package/dist/esm/components/AutoPatternsGrid/AutoPatternsGrid.js.map +1 -1
- package/dist/esm/components/AutoPatternsRoute/AutoPatternsPage.js +3 -7
- package/dist/esm/components/AutoPatternsRoute/AutoPatternsPage.js.map +1 -1
- package/dist/esm/components/AutoPatternsTable/AutoPatternsTable.js +126 -41
- package/dist/esm/components/AutoPatternsTable/AutoPatternsTable.js.map +1 -1
- package/dist/esm/components/AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch.js +155 -10
- package/dist/esm/components/AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch.js.map +1 -1
- package/dist/esm/hooks/getCommonCollectionFeaturesAsync.js +7 -0
- package/dist/esm/hooks/getCommonCollectionFeaturesAsync.js.map +1 -0
- package/dist/esm/hooks/getFilterComponent.js +48 -0
- package/dist/esm/hooks/getFilterComponent.js.map +1 -0
- package/dist/esm/hooks/index.js +1 -2
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/pluginsDynamicImports.js +13 -0
- package/dist/esm/hooks/pluginsDynamicImports.js.map +1 -0
- package/dist/esm/hooks/useAsyncFeaturesPromiseState.js +28 -0
- package/dist/esm/hooks/useAsyncFeaturesPromiseState.js.map +1 -0
- package/dist/esm/hooks/useBaseCollectionComponentReadyFeatures.js +58 -0
- package/dist/esm/hooks/useBaseCollectionComponentReadyFeatures.js.map +1 -0
- package/dist/esm/hooks/useBasePatternsStateParams.js +32 -0
- package/dist/esm/hooks/useBasePatternsStateParams.js.map +1 -0
- package/dist/esm/hooks/useCollectionInitAsyncDeps.js +11 -0
- package/dist/esm/hooks/useCollectionInitAsyncDeps.js.map +1 -0
- package/dist/esm/hooks/useCommonCollectionFeatures.js +1 -0
- package/dist/esm/hooks/useCommonCollectionFeatures.js.map +1 -1
- package/dist/esm/hooks/useFilters.js +14 -100
- package/dist/esm/hooks/useFilters.js.map +1 -1
- package/dist/esm/hooks/useFiltersState.js +107 -0
- package/dist/esm/hooks/useFiltersState.js.map +1 -0
- package/dist/esm/hooks/useGridFeaturesAsync.js +37 -0
- package/dist/esm/hooks/useGridFeaturesAsync.js.map +1 -0
- package/dist/esm/hooks/useGridVisibleFieldIds.js +13 -0
- package/dist/esm/hooks/useGridVisibleFieldIds.js.map +1 -0
- package/dist/esm/hooks/useSyncCollectionStateToAppContext.js +18 -0
- package/dist/esm/hooks/useSyncCollectionStateToAppContext.js.map +1 -0
- package/dist/esm/hooks/useTableFeaturesAsync.js +46 -0
- package/dist/esm/hooks/useTableFeaturesAsync.js.map +1 -0
- package/dist/esm/hooks/useTableGridSwitchFeaturesAsync.js +47 -0
- package/dist/esm/hooks/useTableGridSwitchFeaturesAsync.js.map +1 -0
- package/dist/esm/hooks/useTableSections.js +14 -0
- package/dist/esm/hooks/useTableSections.js.map +1 -0
- package/dist/esm/utils/filterCreators.js +17 -32
- package/dist/esm/utils/filterCreators.js.map +1 -1
- package/dist/esm/utils/minimalRequiredPatternsRuntimeCheck.js +14 -0
- package/dist/esm/utils/minimalRequiredPatternsRuntimeCheck.js.map +1 -0
- package/dist/esm/utils/minimalRequiredRuntimeCheck.js +17 -0
- package/dist/esm/utils/minimalRequiredRuntimeCheck.js.map +1 -0
- package/dist/types/components/AutoPatternsApp/AutoPatternsApp.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.d.ts +6 -0
- package/dist/types/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsGrid/AutoPatternsGrid.d.ts +17 -2
- package/dist/types/components/AutoPatternsGrid/AutoPatternsGrid.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsRoute/AutoPatternsPage.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsTable/AutoPatternsTable.d.ts +17 -2
- package/dist/types/components/AutoPatternsTable/AutoPatternsTable.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch.d.ts +18 -2
- package/dist/types/components/AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch.d.ts.map +1 -1
- package/dist/types/hooks/getCommonCollectionFeaturesAsync.d.ts +4 -0
- package/dist/types/hooks/getCommonCollectionFeaturesAsync.d.ts.map +1 -0
- package/dist/types/hooks/getFilterComponent.d.ts +4 -0
- package/dist/types/hooks/getFilterComponent.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +1 -2
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/pluginsDynamicImports.d.ts +7 -0
- package/dist/types/hooks/pluginsDynamicImports.d.ts.map +1 -0
- package/dist/types/hooks/useAsyncFeaturesPromiseState.d.ts +6 -0
- package/dist/types/hooks/useAsyncFeaturesPromiseState.d.ts.map +1 -0
- package/dist/types/hooks/useBaseCollectionComponentReadyFeatures.d.ts +36 -0
- package/dist/types/hooks/useBaseCollectionComponentReadyFeatures.d.ts.map +1 -0
- package/dist/types/hooks/useBasePatternsStateParams.d.ts +31 -0
- package/dist/types/hooks/useBasePatternsStateParams.d.ts.map +1 -0
- package/dist/types/hooks/useCollectionInitAsyncDeps.d.ts +4 -0
- package/dist/types/hooks/useCollectionInitAsyncDeps.d.ts.map +1 -0
- package/dist/types/hooks/useCommonCollectionFeatures.d.ts +1 -0
- package/dist/types/hooks/useCommonCollectionFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useFilters.d.ts +9 -21
- package/dist/types/hooks/useFilters.d.ts.map +1 -1
- package/dist/types/hooks/useFiltersState.d.ts +26 -0
- package/dist/types/hooks/useFiltersState.d.ts.map +1 -0
- package/dist/types/hooks/useGridDragAndDrop.d.ts +1 -1
- package/dist/types/hooks/useGridFeaturesAsync.d.ts +26 -0
- package/dist/types/hooks/useGridFeaturesAsync.d.ts.map +1 -0
- package/dist/types/hooks/useGridVisibleFieldIds.d.ts +3 -0
- package/dist/types/hooks/useGridVisibleFieldIds.d.ts.map +1 -0
- package/dist/types/hooks/useSyncCollectionStateToAppContext.d.ts +6 -0
- package/dist/types/hooks/useSyncCollectionStateToAppContext.d.ts.map +1 -0
- package/dist/types/hooks/useTableFeaturesAsync.d.ts +29 -0
- package/dist/types/hooks/useTableFeaturesAsync.d.ts.map +1 -0
- package/dist/types/hooks/useTableGridSwitchDragAndDrop.d.ts +1 -1
- package/dist/types/hooks/useTableGridSwitchFeaturesAsync.d.ts +29 -0
- package/dist/types/hooks/useTableGridSwitchFeaturesAsync.d.ts.map +1 -0
- package/dist/types/hooks/useTableSections.d.ts +8 -0
- package/dist/types/hooks/useTableSections.d.ts.map +1 -0
- package/dist/types/utils/filterCreators.d.ts +10 -19
- package/dist/types/utils/filterCreators.d.ts.map +1 -1
- package/dist/types/utils/minimalRequiredPatternsRuntimeCheck.d.ts +5 -0
- package/dist/types/utils/minimalRequiredPatternsRuntimeCheck.d.ts.map +1 -0
- package/dist/types/utils/minimalRequiredRuntimeCheck.d.ts +9 -0
- package/dist/types/utils/minimalRequiredRuntimeCheck.d.ts.map +1 -0
- package/package.json +18 -17
- package/dist/cjs/hooks/useGridFeatures.js +0 -63
- package/dist/cjs/hooks/useGridFeatures.js.map +0 -1
- package/dist/cjs/hooks/useTableFeatures.js +0 -79
- package/dist/cjs/hooks/useTableFeatures.js.map +0 -1
- package/dist/cjs/hooks/useTableGridSwitchFeatures.js +0 -83
- package/dist/cjs/hooks/useTableGridSwitchFeatures.js.map +0 -1
- package/dist/esm/hooks/useGridFeatures.js +0 -58
- package/dist/esm/hooks/useGridFeatures.js.map +0 -1
- package/dist/esm/hooks/useTableFeatures.js +0 -74
- package/dist/esm/hooks/useTableFeatures.js.map +0 -1
- package/dist/esm/hooks/useTableGridSwitchFeatures.js +0 -78
- package/dist/esm/hooks/useTableGridSwitchFeatures.js.map +0 -1
- package/dist/types/hooks/useGridFeatures.d.ts +0 -43
- package/dist/types/hooks/useGridFeatures.d.ts.map +0 -1
- package/dist/types/hooks/useTableFeatures.d.ts +0 -27
- package/dist/types/hooks/useTableFeatures.d.ts.map +0 -1
- package/dist/types/hooks/useTableGridSwitchFeatures.d.ts +0 -52
- package/dist/types/hooks/useTableGridSwitchFeatures.d.ts.map +0 -1
|
@@ -1,108 +1,23 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { CollectionToolbarFilters } from '@wix/patterns';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const currFilters = [];
|
|
13
|
-
configuration == null || configuration.items.forEach(filter => {
|
|
14
|
-
const {
|
|
15
|
-
id,
|
|
16
|
-
fieldId
|
|
17
|
-
} = filter;
|
|
18
|
-
const fieldDefinition = schema.fields[fieldId];
|
|
19
|
-
if (!fieldDefinition) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const label = filter.displayName || fieldDefinition.displayName;
|
|
23
|
-
const {
|
|
24
|
-
openByDefault,
|
|
25
|
-
tagLabel,
|
|
26
|
-
sectionTitle
|
|
27
|
-
} = filter;
|
|
28
|
-
const baseParams = {
|
|
29
|
-
id,
|
|
30
|
-
fieldId,
|
|
31
|
-
commonFilterProps: {
|
|
32
|
-
sectionTitle,
|
|
33
|
-
initiallyOpen: openByDefault,
|
|
34
|
-
accordionItemProps: {
|
|
35
|
-
label
|
|
36
|
-
},
|
|
37
|
-
toolbarItemProps: {
|
|
38
|
-
label
|
|
39
|
-
},
|
|
40
|
-
toolbarTagProps: {
|
|
41
|
-
label: tagLabel
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
switch (fieldDefinition.type) {
|
|
46
|
-
case 'DATE':
|
|
47
|
-
case 'DATETIME':
|
|
48
|
-
currFilters.push(createDateTimeFilter({
|
|
49
|
-
...baseParams,
|
|
50
|
-
config: filter.dateConfig
|
|
51
|
-
}));
|
|
52
|
-
break;
|
|
53
|
-
case 'BOOLEAN':
|
|
54
|
-
currFilters.push(createBooleanFilter({
|
|
55
|
-
...baseParams,
|
|
56
|
-
config: filter.booleanConfig
|
|
57
|
-
}));
|
|
58
|
-
break;
|
|
59
|
-
case 'NUMBER':
|
|
60
|
-
currFilters.push(createNumberFilter({
|
|
61
|
-
...baseParams,
|
|
62
|
-
config: filter.numberConfig
|
|
63
|
-
}));
|
|
64
|
-
break;
|
|
65
|
-
case 'REFERENCE':
|
|
66
|
-
{
|
|
67
|
-
const {
|
|
68
|
-
referencedCollectionId
|
|
69
|
-
} = fieldDefinition.referenceMetadata;
|
|
70
|
-
const referencedSchema = schemaRegistry.getSchema(referencedCollectionId);
|
|
71
|
-
if (referencedSchema) {
|
|
72
|
-
currFilters.push(createReferenceFilter({
|
|
73
|
-
...baseParams,
|
|
74
|
-
config: filter.dynamicOptionsConfig,
|
|
75
|
-
additionalParams: {
|
|
76
|
-
referencedSchema
|
|
77
|
-
}
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
default:
|
|
83
|
-
if (filter != null && filter.enumConfig) {
|
|
84
|
-
currFilters.push(createEnumFilter({
|
|
85
|
-
...baseParams,
|
|
86
|
-
config: filter.enumConfig
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return currFilters;
|
|
93
|
-
});
|
|
94
|
-
const filterFieldMapping = React.useMemo(() => {
|
|
95
|
-
return configuration == null ? void 0 : configuration.items.reduce((acc, filter) => {
|
|
96
|
-
acc[filter.id] = filter;
|
|
97
|
-
return acc;
|
|
98
|
-
}, {});
|
|
99
|
-
}, [configuration == null ? void 0 : configuration.items]);
|
|
4
|
+
import { DynamicCollectionFilter, StaticCollectionFilter } from '../components/filters';
|
|
5
|
+
import { getFilterComponent } from './getFilterComponent';
|
|
6
|
+
export const useFilters = (configuration, filtersState) => {
|
|
7
|
+
const {
|
|
8
|
+
filters,
|
|
9
|
+
filterFieldMapping,
|
|
10
|
+
filtersObject
|
|
11
|
+
} = filtersState;
|
|
100
12
|
const collectionToolbarFiltersProps = React.useMemo(() => ({
|
|
101
13
|
inline: (configuration == null ? void 0 : configuration.maxInlineFilters) || 0,
|
|
102
14
|
panelTitle: configuration == null ? void 0 : configuration.panelTitle
|
|
103
15
|
}), [configuration]);
|
|
104
|
-
const
|
|
105
|
-
|
|
16
|
+
const filtersWithComponents = filters.map(filter => ({
|
|
17
|
+
...filter,
|
|
18
|
+
component: getFilterComponent(filter)
|
|
19
|
+
})).filter(filter => filter.component !== null);
|
|
20
|
+
const filtersData = filtersWithComponents.reduce((acc, filter) => {
|
|
106
21
|
acc.components.push(filter.collectionData ? /*#__PURE__*/React.createElement(StaticCollectionFilter, _extends({
|
|
107
22
|
filter: filter.filter,
|
|
108
23
|
key: filter.key,
|
|
@@ -120,13 +35,12 @@ export const useFilters = configuration => {
|
|
|
120
35
|
}, filter.props)));
|
|
121
36
|
return acc;
|
|
122
37
|
}, {
|
|
123
|
-
filters: {},
|
|
124
38
|
components: [],
|
|
125
39
|
collectionToolbarFiltersProps
|
|
126
40
|
});
|
|
127
41
|
return {
|
|
128
42
|
filterFieldMapping,
|
|
129
|
-
filtersObject
|
|
43
|
+
filtersObject,
|
|
130
44
|
filterComponent: filtersData.components.length > 0 ? /*#__PURE__*/React.createElement(CollectionToolbarFilters, collectionToolbarFiltersProps, filtersData.components) : undefined
|
|
131
45
|
};
|
|
132
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","CollectionToolbarFilters","useSchema","useSchemaRegistry","StaticCollectionFilter","DynamicCollectionFilter","createDateTimeFilter","createBooleanFilter","createNumberFilter","createEnumFilter","createReferenceFilter","useFilters","configuration","schema","schemaRegistry","filters","useState","currFilters","items","forEach","filter","id","fieldId","fieldDefinition","fields","label","displayName","openByDefault","tagLabel","sectionTitle","baseParams","commonFilterProps","initiallyOpen","accordionItemProps","toolbarItemProps","toolbarTagProps","type","push","config","dateConfig","booleanConfig","numberConfig","referencedCollectionId","referenceMetadata","referencedSchema","getSchema","dynamicOptionsConfig","additionalParams","enumConfig","filterFieldMapping","useMemo","reduce","acc","collectionToolbarFiltersProps","inline","maxInlineFilters","panelTitle","filtersData","key","components","collectionData","createElement","_extends","component","props","collectionId","componentName","filtersObject","filterComponent","length","undefined"],"sources":["../../../src/hooks/useFilters.tsx"],"sourcesContent":["import React from 'react';\nimport {\n CollectionToolbarFilters,\n CollectionToolbarFiltersProps,\n Filter,\n} from '@wix/patterns';\nimport { Filter as SchemaFilterType, FiltersConfig } from '../types';\nimport { useSchema } from '../providers/SchemaContext';\nimport { useSchemaRegistry } from '../providers';\nimport {\n StaticCollectionFilter,\n DynamicCollectionFilter,\n} from '../components/filters';\nimport {\n createDateTimeFilter,\n createBooleanFilter,\n createNumberFilter,\n createEnumFilter,\n createReferenceFilter,\n} from '../utils/filterCreators';\n\nexport interface FilterOptions {\n key: string;\n fieldId: string;\n filter: Filter<any>;\n component: React.ElementType;\n collectionData?: { id: string; name: string }[];\n collectionId?: string;\n componentName?: string;\n props: Record<string, any>;\n}\n\nexport interface ReturnValue {\n filters: { [key: string]: Filter<any> };\n components: React.JSX.Element[];\n collectionToolbarFiltersProps: Pick<\n CollectionToolbarFiltersProps,\n 'inline' | 'panelTitle' | 'useNewFilters'\n >;\n}\n\nexport const useFilters = (configuration?: FiltersConfig) => {\n const schema = useSchema();\n const schemaRegistry = useSchemaRegistry();\n const [filters] = React.useState(() => {\n const currFilters: FilterOptions[] = [];\n configuration?.items.forEach((filter) => {\n const { id, fieldId } = filter;\n const fieldDefinition = schema.fields[fieldId];\n if (!fieldDefinition) {\n return;\n }\n\n const label = filter.displayName || fieldDefinition.displayName;\n const { openByDefault, tagLabel, sectionTitle } = filter;\n\n const baseParams = {\n id,\n fieldId,\n commonFilterProps: {\n sectionTitle,\n initiallyOpen: openByDefault,\n accordionItemProps: { label },\n toolbarItemProps: { label },\n toolbarTagProps: { label: tagLabel },\n },\n };\n\n switch (fieldDefinition.type) {\n case 'DATE':\n case 'DATETIME':\n currFilters.push(\n createDateTimeFilter({\n ...baseParams,\n config: filter.dateConfig,\n }),\n );\n break;\n\n case 'BOOLEAN':\n currFilters.push(\n createBooleanFilter({\n ...baseParams,\n config: filter.booleanConfig,\n }),\n );\n break;\n\n case 'NUMBER':\n currFilters.push(\n createNumberFilter({\n ...baseParams,\n config: filter.numberConfig,\n }),\n );\n break;\n\n case 'REFERENCE': {\n const { referencedCollectionId } = fieldDefinition.referenceMetadata;\n const referencedSchema = schemaRegistry.getSchema(\n referencedCollectionId,\n );\n\n if (referencedSchema) {\n currFilters.push(\n createReferenceFilter({\n ...baseParams,\n config: filter.dynamicOptionsConfig,\n additionalParams: {\n referencedSchema,\n },\n }),\n );\n }\n break;\n }\n\n default:\n if (filter?.enumConfig) {\n currFilters.push(\n createEnumFilter({\n ...baseParams,\n config: filter.enumConfig,\n }),\n );\n }\n break;\n }\n });\n return currFilters;\n });\n\n const filterFieldMapping = React.useMemo(() => {\n return configuration?.items.reduce((acc, filter) => {\n acc[filter.id] = filter;\n return acc;\n }, {} as Record<string, SchemaFilterType>);\n }, [configuration?.items]);\n\n const collectionToolbarFiltersProps = React.useMemo<\n Pick<CollectionToolbarFiltersProps, 'inline' | 'panelTitle'>\n >(\n () => ({\n inline: configuration?.maxInlineFilters || 0,\n panelTitle: configuration?.panelTitle,\n }),\n [configuration],\n );\n\n const filtersData = filters.reduce<ReturnValue>(\n (acc, filter) => {\n acc.filters[filter.key] = filter.filter;\n acc.components.push(\n filter.collectionData ? (\n <StaticCollectionFilter\n filter={filter.filter}\n key={filter.key}\n component={filter.component}\n collectionData={filter.collectionData}\n {...filter.props}\n />\n ) : filter.collectionId ? (\n <DynamicCollectionFilter\n filter={filter.filter}\n key={filter.key}\n component={filter.component}\n collectionId={filter.collectionId}\n componentName={filter.props.componentName}\n {...filter.props}\n />\n ) : (\n <filter.component\n key={filter.key}\n filter={filter.filter}\n {...filter.props}\n />\n ),\n );\n\n return acc;\n },\n { filters: {}, components: [], collectionToolbarFiltersProps },\n );\n\n return {\n filterFieldMapping,\n filtersObject: filtersData.filters,\n filterComponent:\n filtersData.components.length > 0 ? (\n <CollectionToolbarFilters {...collectionToolbarFiltersProps}>\n {filtersData.components}\n </CollectionToolbarFilters>\n ) : undefined,\n };\n};\n"],"mappings":"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","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","CollectionToolbarFilters","DynamicCollectionFilter","StaticCollectionFilter","getFilterComponent","useFilters","configuration","filtersState","filters","filterFieldMapping","filtersObject","collectionToolbarFiltersProps","useMemo","inline","maxInlineFilters","panelTitle","filtersWithComponents","map","filter","component","filtersData","reduce","acc","components","push","collectionData","createElement","_extends","key","props","collectionId","componentName","filterComponent","length","undefined"],"sources":["../../../src/hooks/useFilters.tsx"],"sourcesContent":["import React, { ElementType } from 'react';\nimport {\n CollectionToolbarFilters,\n CollectionToolbarFiltersProps,\n} from '@wix/patterns';\nimport { FiltersConfig } from '../types';\nimport {\n DynamicCollectionFilter,\n StaticCollectionFilter,\n} from '../components/filters';\nimport { FilterOptions, useFiltersState } from './useFiltersState';\nimport { getFilterComponent } from './getFilterComponent';\n\nexport interface FilterOptionsWithComponent extends FilterOptions {\n component: ElementType;\n}\n\nexport interface ReturnValue {\n components: React.JSX.Element[];\n collectionToolbarFiltersProps: Pick<\n CollectionToolbarFiltersProps,\n 'inline' | 'panelTitle' | 'useNewFilters'\n >;\n}\n\nexport const useFilters = (\n configuration: FiltersConfig | undefined,\n filtersState: ReturnType<typeof useFiltersState>,\n) => {\n const { filters, filterFieldMapping, filtersObject } = filtersState;\n\n const collectionToolbarFiltersProps = React.useMemo<\n Pick<CollectionToolbarFiltersProps, 'inline' | 'panelTitle'>\n >(\n () => ({\n inline: configuration?.maxInlineFilters || 0,\n panelTitle: configuration?.panelTitle,\n }),\n [configuration],\n );\n\n const filtersWithComponents = filters\n .map((filter) => ({\n ...filter,\n component: getFilterComponent(filter),\n }))\n .filter(\n (filter): filter is FilterOptionsWithComponent =>\n filter.component !== null,\n );\n\n const filtersData = filtersWithComponents.reduce<ReturnValue>(\n (acc, filter) => {\n acc.components.push(\n filter.collectionData ? (\n <StaticCollectionFilter\n filter={filter.filter}\n key={filter.key}\n component={filter.component}\n collectionData={filter.collectionData}\n {...filter.props}\n />\n ) : filter.collectionId ? (\n <DynamicCollectionFilter\n filter={filter.filter}\n key={filter.key}\n component={filter.component}\n collectionId={filter.collectionId}\n componentName={filter.props.componentName}\n {...filter.props}\n />\n ) : (\n <filter.component\n key={filter.key}\n filter={filter.filter}\n {...filter.props}\n />\n ),\n );\n\n return acc;\n },\n { components: [], collectionToolbarFiltersProps },\n );\n\n return {\n filterFieldMapping,\n filtersObject,\n filterComponent:\n filtersData.components.length > 0 ? (\n <CollectionToolbarFilters {...collectionToolbarFiltersProps}>\n {filtersData.components}\n </CollectionToolbarFilters>\n ) : undefined,\n };\n};\n"],"mappings":";AAAA,OAAOA,KAAK,MAAuB,OAAO;AAC1C,SACEC,wBAAwB,QAEnB,eAAe;AAEtB,SACEC,uBAAuB,EACvBC,sBAAsB,QACjB,uBAAuB;AAE9B,SAASC,kBAAkB,QAAQ,sBAAsB;AAczD,OAAO,MAAMC,UAAU,GAAGA,CACxBC,aAAwC,EACxCC,YAAgD,KAC7C;EACH,MAAM;IAAEC,OAAO;IAAEC,kBAAkB;IAAEC;EAAc,CAAC,GAAGH,YAAY;EAEnE,MAAMI,6BAA6B,GAAGX,KAAK,CAACY,OAAO,CAGjD,OAAO;IACLC,MAAM,EAAE,CAAAP,aAAa,oBAAbA,aAAa,CAAEQ,gBAAgB,KAAI,CAAC;IAC5CC,UAAU,EAAET,aAAa,oBAAbA,aAAa,CAAES;EAC7B,CAAC,CAAC,EACF,CAACT,aAAa,CAChB,CAAC;EAED,MAAMU,qBAAqB,GAAGR,OAAO,CAClCS,GAAG,CAAEC,MAAM,KAAM;IAChB,GAAGA,MAAM;IACTC,SAAS,EAAEf,kBAAkB,CAACc,MAAM;EACtC,CAAC,CAAC,CAAC,CACFA,MAAM,CACJA,MAAM,IACLA,MAAM,CAACC,SAAS,KAAK,IACzB,CAAC;EAEH,MAAMC,WAAW,GAAGJ,qBAAqB,CAACK,MAAM,CAC9C,CAACC,GAAG,EAAEJ,MAAM,KAAK;IACfI,GAAG,CAACC,UAAU,CAACC,IAAI,CACjBN,MAAM,CAACO,cAAc,gBACnBzB,KAAA,CAAA0B,aAAA,CAACvB,sBAAsB,EAAAwB,QAAA;MACrBT,MAAM,EAAEA,MAAM,CAACA,MAAO;MACtBU,GAAG,EAAEV,MAAM,CAACU,GAAI;MAChBT,SAAS,EAAED,MAAM,CAACC,SAAU;MAC5BM,cAAc,EAAEP,MAAM,CAACO;IAAe,GAClCP,MAAM,CAACW,KAAK,CACjB,CAAC,GACAX,MAAM,CAACY,YAAY,gBACrB9B,KAAA,CAAA0B,aAAA,CAACxB,uBAAuB,EAAAyB,QAAA;MACtBT,MAAM,EAAEA,MAAM,CAACA,MAAO;MACtBU,GAAG,EAAEV,MAAM,CAACU,GAAI;MAChBT,SAAS,EAAED,MAAM,CAACC,SAAU;MAC5BW,YAAY,EAAEZ,MAAM,CAACY,YAAa;MAClCC,aAAa,EAAEb,MAAM,CAACW,KAAK,CAACE;IAAc,GACtCb,MAAM,CAACW,KAAK,CACjB,CAAC,gBAEF7B,KAAA,CAAA0B,aAAA,CAACR,MAAM,CAACC,SAAS,EAAAQ,QAAA;MACfC,GAAG,EAAEV,MAAM,CAACU,GAAI;MAChBV,MAAM,EAAEA,MAAM,CAACA;IAAO,GAClBA,MAAM,CAACW,KAAK,CACjB,CAEL,CAAC;IAED,OAAOP,GAAG;EACZ,CAAC,EACD;IAAEC,UAAU,EAAE,EAAE;IAAEZ;EAA8B,CAClD,CAAC;EAED,OAAO;IACLF,kBAAkB;IAClBC,aAAa;IACbsB,eAAe,EACbZ,WAAW,CAACG,UAAU,CAACU,MAAM,GAAG,CAAC,gBAC/BjC,KAAA,CAAA0B,aAAA,CAACzB,wBAAwB,EAAKU,6BAA6B,EACxDS,WAAW,CAACG,UACW,CAAC,GACzBW;EACR,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useSchema, useSchemaRegistry } from '../providers';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { createBooleanFilter, createDateTimeFilter, createEnumFilter, createNumberFilter, createReferenceFilter } from '../utils/filterCreators';
|
|
4
|
+
export function useFiltersState(config) {
|
|
5
|
+
const schema = useSchema();
|
|
6
|
+
const schemaRegistry = useSchemaRegistry();
|
|
7
|
+
const [filters] = React.useState(() => {
|
|
8
|
+
const currFilters = [];
|
|
9
|
+
config == null || config.items.forEach(filter => {
|
|
10
|
+
const {
|
|
11
|
+
id,
|
|
12
|
+
fieldId
|
|
13
|
+
} = filter;
|
|
14
|
+
const fieldDefinition = schema.fields[fieldId];
|
|
15
|
+
if (!fieldDefinition) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const label = filter.displayName || fieldDefinition.displayName;
|
|
19
|
+
const {
|
|
20
|
+
openByDefault,
|
|
21
|
+
tagLabel,
|
|
22
|
+
sectionTitle
|
|
23
|
+
} = filter;
|
|
24
|
+
const baseParams = {
|
|
25
|
+
id,
|
|
26
|
+
fieldId,
|
|
27
|
+
fieldDefinition,
|
|
28
|
+
commonFilterProps: {
|
|
29
|
+
sectionTitle,
|
|
30
|
+
initiallyOpen: openByDefault,
|
|
31
|
+
accordionItemProps: {
|
|
32
|
+
label
|
|
33
|
+
},
|
|
34
|
+
toolbarItemProps: {
|
|
35
|
+
label
|
|
36
|
+
},
|
|
37
|
+
toolbarTagProps: {
|
|
38
|
+
label: tagLabel
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
switch (fieldDefinition.type) {
|
|
43
|
+
case 'DATE':
|
|
44
|
+
case 'DATETIME':
|
|
45
|
+
currFilters.push(createDateTimeFilter({
|
|
46
|
+
...baseParams,
|
|
47
|
+
config: filter.dateConfig
|
|
48
|
+
}));
|
|
49
|
+
break;
|
|
50
|
+
case 'BOOLEAN':
|
|
51
|
+
currFilters.push(createBooleanFilter({
|
|
52
|
+
...baseParams,
|
|
53
|
+
config: filter.booleanConfig
|
|
54
|
+
}));
|
|
55
|
+
break;
|
|
56
|
+
case 'NUMBER':
|
|
57
|
+
currFilters.push(createNumberFilter({
|
|
58
|
+
...baseParams,
|
|
59
|
+
config: filter.numberConfig
|
|
60
|
+
}));
|
|
61
|
+
break;
|
|
62
|
+
case 'REFERENCE':
|
|
63
|
+
{
|
|
64
|
+
const {
|
|
65
|
+
referencedCollectionId
|
|
66
|
+
} = fieldDefinition.referenceMetadata;
|
|
67
|
+
const referencedSchema = schemaRegistry.getSchema(referencedCollectionId);
|
|
68
|
+
if (referencedSchema) {
|
|
69
|
+
currFilters.push(createReferenceFilter({
|
|
70
|
+
...baseParams,
|
|
71
|
+
config: filter.dynamicOptionsConfig,
|
|
72
|
+
additionalParams: {
|
|
73
|
+
referencedSchema
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default:
|
|
80
|
+
if (filter != null && filter.enumConfig) {
|
|
81
|
+
currFilters.push(createEnumFilter({
|
|
82
|
+
...baseParams,
|
|
83
|
+
config: filter.enumConfig
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return currFilters;
|
|
90
|
+
});
|
|
91
|
+
const filterFieldMapping = React.useMemo(() => {
|
|
92
|
+
return config == null ? void 0 : config.items.reduce((acc, filter) => {
|
|
93
|
+
acc[filter.id] = filter;
|
|
94
|
+
return acc;
|
|
95
|
+
}, {});
|
|
96
|
+
}, [config == null ? void 0 : config.items]);
|
|
97
|
+
const filtersObject = filters.reduce((acc, filter) => {
|
|
98
|
+
acc[filter.key] = filter.filter;
|
|
99
|
+
return acc;
|
|
100
|
+
}, {});
|
|
101
|
+
return {
|
|
102
|
+
filters,
|
|
103
|
+
filterFieldMapping,
|
|
104
|
+
filtersObject
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=useFiltersState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSchema","useSchemaRegistry","React","createBooleanFilter","createDateTimeFilter","createEnumFilter","createNumberFilter","createReferenceFilter","useFiltersState","config","schema","schemaRegistry","filters","useState","currFilters","items","forEach","filter","id","fieldId","fieldDefinition","fields","label","displayName","openByDefault","tagLabel","sectionTitle","baseParams","commonFilterProps","initiallyOpen","accordionItemProps","toolbarItemProps","toolbarTagProps","type","push","dateConfig","booleanConfig","numberConfig","referencedCollectionId","referenceMetadata","referencedSchema","getSchema","dynamicOptionsConfig","additionalParams","enumConfig","filterFieldMapping","useMemo","reduce","acc","filtersObject","key"],"sources":["../../../src/hooks/useFiltersState.ts"],"sourcesContent":["import { useSchema, useSchemaRegistry } from '../providers';\nimport React from 'react';\nimport {\n createBooleanFilter,\n createDateTimeFilter,\n createEnumFilter,\n createNumberFilter,\n createReferenceFilter,\n} from '../utils/filterCreators';\nimport {\n DateFilterConfig,\n DynamicOptionsFilterConfig,\n EnumFilterConfig,\n Field,\n Filter as SchemaFilterType,\n FiltersConfig,\n} from '../types';\nimport { Filter } from '@wix/patterns';\n\nexport interface FilterOptions {\n key: string;\n fieldId: string;\n fieldDefinition: Field;\n filter: Filter<any>;\n collectionData?: { id: string; name: string }[];\n collectionId?: string;\n componentName?: string;\n props: Record<string, any>;\n dateConfig?: DateFilterConfig;\n enumConfig?: EnumFilterConfig;\n dynamicOptionsFilterConfig?: DynamicOptionsFilterConfig;\n}\n\nexport function useFiltersState(config?: FiltersConfig) {\n const schema = useSchema();\n const schemaRegistry = useSchemaRegistry();\n const [filters] = React.useState(() => {\n const currFilters: FilterOptions[] = [];\n config?.items.forEach((filter) => {\n const { id, fieldId } = filter;\n const fieldDefinition = schema.fields[fieldId];\n if (!fieldDefinition) {\n return;\n }\n\n const label = filter.displayName || fieldDefinition.displayName;\n const { openByDefault, tagLabel, sectionTitle } = filter;\n\n const baseParams = {\n id,\n fieldId,\n fieldDefinition,\n commonFilterProps: {\n sectionTitle,\n initiallyOpen: openByDefault,\n accordionItemProps: { label },\n toolbarItemProps: { label },\n toolbarTagProps: { label: tagLabel },\n },\n };\n\n switch (fieldDefinition.type) {\n case 'DATE':\n case 'DATETIME':\n currFilters.push(\n createDateTimeFilter({\n ...baseParams,\n config: filter.dateConfig,\n }),\n );\n break;\n\n case 'BOOLEAN':\n currFilters.push(\n createBooleanFilter({\n ...baseParams,\n config: filter.booleanConfig,\n }),\n );\n break;\n\n case 'NUMBER':\n currFilters.push(\n createNumberFilter({\n ...baseParams,\n config: filter.numberConfig,\n }),\n );\n break;\n\n case 'REFERENCE': {\n const { referencedCollectionId } = fieldDefinition.referenceMetadata;\n const referencedSchema = schemaRegistry.getSchema(\n referencedCollectionId,\n );\n\n if (referencedSchema) {\n currFilters.push(\n createReferenceFilter({\n ...baseParams,\n config: filter.dynamicOptionsConfig,\n additionalParams: {\n referencedSchema,\n },\n }),\n );\n }\n break;\n }\n\n default:\n if (filter?.enumConfig) {\n currFilters.push(\n createEnumFilter({\n ...baseParams,\n config: filter.enumConfig,\n }),\n );\n }\n break;\n }\n });\n return currFilters;\n });\n\n const filterFieldMapping = React.useMemo(() => {\n return config?.items.reduce((acc, filter) => {\n acc[filter.id] = filter;\n return acc;\n }, {} as Record<string, SchemaFilterType>);\n }, [config?.items]);\n\n const filtersObject = filters.reduce((acc, filter) => {\n acc[filter.key] = filter.filter;\n return acc;\n }, {} as { [key: string]: Filter<any> });\n\n return { filters, filterFieldMapping, filtersObject };\n}\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useAsyncFeaturesPromiseState } from './useAsyncFeaturesPromiseState';
|
|
2
|
+
import { importGridDragAndDrop } from './pluginsDynamicImports';
|
|
3
|
+
import { getCommonCollectionFeaturesAsync } from './getCommonCollectionFeaturesAsync';
|
|
4
|
+
/**
|
|
5
|
+
* useGridFeaturesAsync - Step 3 in Grid Flow
|
|
6
|
+
*
|
|
7
|
+
* FLOW 2: AutoPatternsCollectionComponent → AutoPatternsGrid → [useGridFeaturesAsync] → AutoPatternsGridLoaded → useBaseCollectionComponentReadyFeatures → Grid
|
|
8
|
+
*
|
|
9
|
+
* This hook is responsible for loading all grid-specific async features and plugins.
|
|
10
|
+
* It dynamically imports features based on configuration to optimize bundle size.
|
|
11
|
+
* Grid flow is simpler than table flow since grids have fewer optional features.
|
|
12
|
+
*
|
|
13
|
+
* Key Responsibilities:
|
|
14
|
+
* - Loads common collection features (shared across all flows)
|
|
15
|
+
* - Conditionally loads grid-specific dragAndDrop if enabled
|
|
16
|
+
* - Returns promise state that tracks loading status of all features
|
|
17
|
+
* - Enables AutoPatternsGrid to know when all features are ready
|
|
18
|
+
*/
|
|
19
|
+
export const useGridFeaturesAsync = props => {
|
|
20
|
+
const {
|
|
21
|
+
config
|
|
22
|
+
} = props;
|
|
23
|
+
const asyncFeaturesState = useAsyncFeaturesPromiseState({
|
|
24
|
+
// Load common features shared by all collection components (filters, common actions, etc.)
|
|
25
|
+
...getCommonCollectionFeaturesAsync(),
|
|
26
|
+
// Grid-specific drag and drop functionality - only load if enabled in config
|
|
27
|
+
// Note: Grid has fewer async features compared to Table (no sections, no baseTableFeatures)
|
|
28
|
+
dragAndDrop: () => {
|
|
29
|
+
var _config$dragAndDrop;
|
|
30
|
+
return (_config$dragAndDrop = config.dragAndDrop) != null && _config$dragAndDrop.enabled ? importGridDragAndDrop() : null;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
asyncFeaturesState
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=useGridFeaturesAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useAsyncFeaturesPromiseState","importGridDragAndDrop","getCommonCollectionFeaturesAsync","useGridFeaturesAsync","props","config","asyncFeaturesState","dragAndDrop","_config$dragAndDrop","enabled"],"sources":["../../../src/hooks/useGridFeaturesAsync.tsx"],"sourcesContent":["import { GridConfig } from '../types';\nimport { useAsyncFeaturesPromiseState } from './useAsyncFeaturesPromiseState';\nimport { importGridDragAndDrop } from './pluginsDynamicImports';\nimport { getCommonCollectionFeaturesAsync } from './getCommonCollectionFeaturesAsync';\n\nexport interface UseGridFeaturesAsyncProps {\n config: GridConfig;\n}\n\n/**\n * useGridFeaturesAsync - Step 3 in Grid Flow\n *\n * FLOW 2: AutoPatternsCollectionComponent → AutoPatternsGrid → [useGridFeaturesAsync] → AutoPatternsGridLoaded → useBaseCollectionComponentReadyFeatures → Grid\n *\n * This hook is responsible for loading all grid-specific async features and plugins.\n * It dynamically imports features based on configuration to optimize bundle size.\n * Grid flow is simpler than table flow since grids have fewer optional features.\n *\n * Key Responsibilities:\n * - Loads common collection features (shared across all flows)\n * - Conditionally loads grid-specific dragAndDrop if enabled\n * - Returns promise state that tracks loading status of all features\n * - Enables AutoPatternsGrid to know when all features are ready\n */\nexport const useGridFeaturesAsync = (props: UseGridFeaturesAsyncProps) => {\n const { config } = props;\n\n const asyncFeaturesState = useAsyncFeaturesPromiseState({\n // Load common features shared by all collection components (filters, common actions, etc.)\n ...getCommonCollectionFeaturesAsync(),\n\n // Grid-specific drag and drop functionality - only load if enabled in config\n // Note: Grid has fewer async features compared to Table (no sections, no baseTableFeatures)\n dragAndDrop: () =>\n config.dragAndDrop?.enabled ? importGridDragAndDrop() : null,\n });\n\n return {\n asyncFeaturesState,\n };\n};\n"],"mappings":"AACA,SAASA,4BAA4B,QAAQ,gCAAgC;AAC7E,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,gCAAgC,QAAQ,oCAAoC;AAMrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,KAAgC,IAAK;EACxE,MAAM;IAAEC;EAAO,CAAC,GAAGD,KAAK;EAExB,MAAME,kBAAkB,GAAGN,4BAA4B,CAAC;IACtD;IACA,GAAGE,gCAAgC,CAAC,CAAC;IAErC;IACA;IACAK,WAAW,EAAEA,CAAA;MAAA,IAAAC,mBAAA;MAAA,OACX,CAAAA,mBAAA,GAAAH,MAAM,CAACE,WAAW,aAAlBC,mBAAA,CAAoBC,OAAO,GAAGR,qBAAqB,CAAC,CAAC,GAAG,IAAI;IAAA;EAChE,CAAC,CAAC;EAEF,OAAO;IACLK;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
export function useGridVisibleFieldIds(config) {
|
|
3
|
+
const {
|
|
4
|
+
item
|
|
5
|
+
} = config;
|
|
6
|
+
const {
|
|
7
|
+
titleFieldId,
|
|
8
|
+
subtitleFieldId,
|
|
9
|
+
imageFieldId
|
|
10
|
+
} = item;
|
|
11
|
+
return useMemo(() => [titleFieldId, subtitleFieldId, imageFieldId].filter(Boolean), [titleFieldId, subtitleFieldId, imageFieldId]);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=useGridVisibleFieldIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useMemo","useGridVisibleFieldIds","config","item","titleFieldId","subtitleFieldId","imageFieldId","filter","Boolean"],"sources":["../../../src/hooks/useGridVisibleFieldIds.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { GridSpecificConfig } from '../types';\n\nexport function useGridVisibleFieldIds(config: GridSpecificConfig) {\n const { item } = config;\n\n const { titleFieldId, subtitleFieldId, imageFieldId } = item;\n return useMemo(\n () =>\n [titleFieldId, subtitleFieldId, imageFieldId].filter(Boolean) as string[],\n [titleFieldId, subtitleFieldId, imageFieldId],\n );\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAG/B,OAAO,SAASC,sBAAsBA,CAACC,MAA0B,EAAE;EACjE,MAAM;IAAEC;EAAK,CAAC,GAAGD,MAAM;EAEvB,MAAM;IAAEE,YAAY;IAAEC,eAAe;IAAEC;EAAa,CAAC,GAAGH,IAAI;EAC5D,OAAOH,OAAO,CACZ,MACE,CAACI,YAAY,EAAEC,eAAe,EAAEC,YAAY,CAAC,CAACC,MAAM,CAACC,OAAO,CAAa,EAC3E,CAACJ,YAAY,EAAEC,eAAe,EAAEC,YAAY,CAC9C,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useSelector } from '@wix/patterns';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useAppContextSync } from './useAppContextSync';
|
|
4
|
+
export function useSyncCollectionStateToAppContext(props) {
|
|
5
|
+
const {
|
|
6
|
+
collection
|
|
7
|
+
} = props;
|
|
8
|
+
const items = useSelector(() => collection.result.items);
|
|
9
|
+
const refreshCollection = useCallback(() => {
|
|
10
|
+
return () => {
|
|
11
|
+
return collection.clearResultAndMoveToStart({
|
|
12
|
+
force: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}, [collection]);
|
|
16
|
+
useAppContextSync(items, refreshCollection);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=useSyncCollectionStateToAppContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSelector","useCallback","useAppContextSync","useSyncCollectionStateToAppContext","props","collection","items","result","refreshCollection","clearResultAndMoveToStart","force"],"sources":["../../../src/hooks/useSyncCollectionStateToAppContext.ts"],"sourcesContent":["import { CollectionState, useSelector } from '@wix/patterns';\nimport { useCallback } from 'react';\nimport { useAppContextSync } from './useAppContextSync';\n\nexport interface UseSyncCollectionStateToAppContextProps {\n collection: CollectionState<any, {}>;\n}\n\nexport function useSyncCollectionStateToAppContext(\n props: UseSyncCollectionStateToAppContextProps,\n) {\n const { collection } = props;\n const items = useSelector(() => collection.result.items);\n\n const refreshCollection = useCallback(() => {\n return () => {\n return collection.clearResultAndMoveToStart({ force: true });\n };\n }, [collection]);\n\n useAppContextSync(items, refreshCollection);\n}\n"],"mappings":"AAAA,SAA0BA,WAAW,QAAQ,eAAe;AAC5D,SAASC,WAAW,QAAQ,OAAO;AACnC,SAASC,iBAAiB,QAAQ,qBAAqB;AAMvD,OAAO,SAASC,kCAAkCA,CAChDC,KAA8C,EAC9C;EACA,MAAM;IAAEC;EAAW,CAAC,GAAGD,KAAK;EAC5B,MAAME,KAAK,GAAGN,WAAW,CAAC,MAAMK,UAAU,CAACE,MAAM,CAACD,KAAK,CAAC;EAExD,MAAME,iBAAiB,GAAGP,WAAW,CAAC,MAAM;IAC1C,OAAO,MAAM;MACX,OAAOI,UAAU,CAACI,yBAAyB,CAAC;QAAEC,KAAK,EAAE;MAAK,CAAC,CAAC;IAC9D,CAAC;EACH,CAAC,EAAE,CAACL,UAAU,CAAC,CAAC;EAEhBH,iBAAiB,CAACI,KAAK,EAAEE,iBAAiB,CAAC;AAC7C","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useAutoPatternsOverridesContext } from '../providers/AutoPatternsOverridesContext';
|
|
2
|
+
import { importBaseTableFeatures, importTableDragAndDrop, importTableSections } from './pluginsDynamicImports';
|
|
3
|
+
import { useAsyncFeaturesPromiseState } from './useAsyncFeaturesPromiseState';
|
|
4
|
+
import { getCommonCollectionFeaturesAsync } from './getCommonCollectionFeaturesAsync';
|
|
5
|
+
/**
|
|
6
|
+
* useTableFeaturesAsync - Step 3 in Table Flow
|
|
7
|
+
*
|
|
8
|
+
* FLOW 1: AutoPatternsCollectionComponent → AutoPatternsTable → [useTableFeaturesAsync] → AutoPatternsTableLoaded → useBaseCollectionComponentReadyFeatures → Table
|
|
9
|
+
*
|
|
10
|
+
* This hook is responsible for loading all table-specific async features and plugins.
|
|
11
|
+
* It dynamically imports features based on configuration to optimize bundle size.
|
|
12
|
+
*
|
|
13
|
+
* Key Responsibilities:
|
|
14
|
+
* - Loads common collection features (shared across all flows)
|
|
15
|
+
* - Conditionally loads table-specific dragAndDrop if enabled
|
|
16
|
+
* - Always loads baseTableFeatures for core table functionality
|
|
17
|
+
* - Conditionally loads table sections if configured with overrides
|
|
18
|
+
* - Returns promise state that tracks loading status of all features
|
|
19
|
+
* - Enables AutoPatternsTable to know when all features are ready
|
|
20
|
+
*/
|
|
21
|
+
export const useTableFeaturesAsync = props => {
|
|
22
|
+
const {
|
|
23
|
+
config
|
|
24
|
+
} = props;
|
|
25
|
+
const overrides = useAutoPatternsOverridesContext();
|
|
26
|
+
const asyncFeaturesState = useAsyncFeaturesPromiseState({
|
|
27
|
+
// Load common features shared by all collection components (filters, common actions, etc.)
|
|
28
|
+
...getCommonCollectionFeaturesAsync(),
|
|
29
|
+
// Table-specific drag and drop functionality - only load if enabled in config
|
|
30
|
+
dragAndDrop: () => {
|
|
31
|
+
var _config$dragAndDrop;
|
|
32
|
+
return (_config$dragAndDrop = config.dragAndDrop) != null && _config$dragAndDrop.enabled ? importTableDragAndDrop() : null;
|
|
33
|
+
},
|
|
34
|
+
// Core table features (columns, custom columns, row clicks, etc.) - always required
|
|
35
|
+
baseTableFeatures: () => importBaseTableFeatures(),
|
|
36
|
+
// Table sections feature - only load if sections are configured AND overrides exist
|
|
37
|
+
sections: () => {
|
|
38
|
+
var _config$sections, _overrides$sections;
|
|
39
|
+
return !!((_config$sections = config.sections) != null && _config$sections.id) && (overrides == null || (_overrides$sections = overrides.sections) == null ? void 0 : _overrides$sections[config.sections.id]) != null ? importTableSections() : null;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
asyncFeaturesState
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=useTableFeaturesAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useAutoPatternsOverridesContext","importBaseTableFeatures","importTableDragAndDrop","importTableSections","useAsyncFeaturesPromiseState","getCommonCollectionFeaturesAsync","useTableFeaturesAsync","props","config","overrides","asyncFeaturesState","dragAndDrop","_config$dragAndDrop","enabled","baseTableFeatures","sections","_config$sections","_overrides$sections","id"],"sources":["../../../src/hooks/useTableFeaturesAsync.tsx"],"sourcesContent":["import { TableConfig } from '../types';\nimport { useAutoPatternsOverridesContext } from '../providers/AutoPatternsOverridesContext';\nimport {\n importBaseTableFeatures,\n importTableDragAndDrop,\n importTableSections,\n} from './pluginsDynamicImports';\nimport { useAsyncFeaturesPromiseState } from './useAsyncFeaturesPromiseState';\nimport { getCommonCollectionFeaturesAsync } from './getCommonCollectionFeaturesAsync';\n\nexport interface UseTableFeaturesAsyncProps {\n config: TableConfig;\n}\n\n/**\n * useTableFeaturesAsync - Step 3 in Table Flow\n *\n * FLOW 1: AutoPatternsCollectionComponent → AutoPatternsTable → [useTableFeaturesAsync] → AutoPatternsTableLoaded → useBaseCollectionComponentReadyFeatures → Table\n *\n * This hook is responsible for loading all table-specific async features and plugins.\n * It dynamically imports features based on configuration to optimize bundle size.\n *\n * Key Responsibilities:\n * - Loads common collection features (shared across all flows)\n * - Conditionally loads table-specific dragAndDrop if enabled\n * - Always loads baseTableFeatures for core table functionality\n * - Conditionally loads table sections if configured with overrides\n * - Returns promise state that tracks loading status of all features\n * - Enables AutoPatternsTable to know when all features are ready\n */\nexport const useTableFeaturesAsync = (props: UseTableFeaturesAsyncProps) => {\n const { config } = props;\n\n const overrides = useAutoPatternsOverridesContext();\n\n const asyncFeaturesState = useAsyncFeaturesPromiseState({\n // Load common features shared by all collection components (filters, common actions, etc.)\n ...getCommonCollectionFeaturesAsync(),\n\n // Table-specific drag and drop functionality - only load if enabled in config\n dragAndDrop: () =>\n config.dragAndDrop?.enabled ? importTableDragAndDrop() : null,\n\n // Core table features (columns, custom columns, row clicks, etc.) - always required\n baseTableFeatures: () => importBaseTableFeatures(),\n\n // Table sections feature - only load if sections are configured AND overrides exist\n sections: () =>\n !!config.sections?.id && overrides?.sections?.[config.sections.id] != null\n ? importTableSections()\n : null,\n });\n\n return { asyncFeaturesState };\n};\n"],"mappings":"AACA,SAASA,+BAA+B,QAAQ,2CAA2C;AAC3F,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,mBAAmB,QACd,yBAAyB;AAChC,SAASC,4BAA4B,QAAQ,gCAAgC;AAC7E,SAASC,gCAAgC,QAAQ,oCAAoC;AAMrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,GAAIC,KAAiC,IAAK;EAC1E,MAAM;IAAEC;EAAO,CAAC,GAAGD,KAAK;EAExB,MAAME,SAAS,GAAGT,+BAA+B,CAAC,CAAC;EAEnD,MAAMU,kBAAkB,GAAGN,4BAA4B,CAAC;IACtD;IACA,GAAGC,gCAAgC,CAAC,CAAC;IAErC;IACAM,WAAW,EAAEA,CAAA;MAAA,IAAAC,mBAAA;MAAA,OACX,CAAAA,mBAAA,GAAAJ,MAAM,CAACG,WAAW,aAAlBC,mBAAA,CAAoBC,OAAO,GAAGX,sBAAsB,CAAC,CAAC,GAAG,IAAI;IAAA;IAE/D;IACAY,iBAAiB,EAAEA,CAAA,KAAMb,uBAAuB,CAAC,CAAC;IAElD;IACAc,QAAQ,EAAEA,CAAA;MAAA,IAAAC,gBAAA,EAAAC,mBAAA;MAAA,OACR,CAAC,GAAAD,gBAAA,GAACR,MAAM,CAACO,QAAQ,aAAfC,gBAAA,CAAiBE,EAAE,KAAI,CAAAT,SAAS,aAAAQ,mBAAA,GAATR,SAAS,CAAEM,QAAQ,qBAAnBE,mBAAA,CAAsBT,MAAM,CAACO,QAAQ,CAACG,EAAE,CAAC,KAAI,IAAI,GACtEf,mBAAmB,CAAC,CAAC,GACrB,IAAI;IAAA;EACZ,CAAC,CAAC;EAEF,OAAO;IAAEO;EAAmB,CAAC;AAC/B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useAutoPatternsOverridesContext } from '../providers';
|
|
2
|
+
import { useAsyncFeaturesPromiseState } from './useAsyncFeaturesPromiseState';
|
|
3
|
+
import { importBaseTableFeatures, importTableGridSwitchDragAndDrop, importTableSections } from './pluginsDynamicImports';
|
|
4
|
+
import { getCommonCollectionFeaturesAsync } from './getCommonCollectionFeaturesAsync';
|
|
5
|
+
/**
|
|
6
|
+
* useTableGridSwitchFeaturesAsync - Step 3 in TableGridSwitch Flow
|
|
7
|
+
*
|
|
8
|
+
* FLOW 3: AutoPatternsCollectionComponent → AutoPatternsTableGridSwitch → [useTableGridSwitchFeaturesAsync] → AutoPatternsTableGridSwitchLoaded → useBaseCollectionComponentReadyFeatures → TableGridSwitch
|
|
9
|
+
*
|
|
10
|
+
* This hook is responsible for loading all table-grid-switch specific async features and plugins.
|
|
11
|
+
* It combines features from both table and grid flows to support runtime switching between views.
|
|
12
|
+
*
|
|
13
|
+
* Key Responsibilities:
|
|
14
|
+
* - Loads common collection features (shared across all flows)
|
|
15
|
+
* - Conditionally loads table-grid-switch specific dragAndDrop if enabled
|
|
16
|
+
* - Always loads baseTableFeatures for core table functionality (needed for table mode)
|
|
17
|
+
* - Conditionally loads table sections if configured with overrides (table mode feature)
|
|
18
|
+
* - Note: Grid-specific features are handled synchronously via useBaseGridFeatures
|
|
19
|
+
* - Returns promise state that tracks loading status of all features
|
|
20
|
+
*/
|
|
21
|
+
export const useTableGridSwitchFeaturesAsync = props => {
|
|
22
|
+
const {
|
|
23
|
+
config
|
|
24
|
+
} = props;
|
|
25
|
+
const overrides = useAutoPatternsOverridesContext();
|
|
26
|
+
const asyncFeaturesState = useAsyncFeaturesPromiseState({
|
|
27
|
+
// Load common features shared by all collection components (filters, common actions, etc.)
|
|
28
|
+
...getCommonCollectionFeaturesAsync(),
|
|
29
|
+
// Table-grid-switch specific drag and drop functionality - handles both table AND grid drag&drop
|
|
30
|
+
dragAndDrop: () => {
|
|
31
|
+
var _config$dragAndDrop;
|
|
32
|
+
return (_config$dragAndDrop = config.dragAndDrop) != null && _config$dragAndDrop.enabled ? importTableGridSwitchDragAndDrop() : null;
|
|
33
|
+
},
|
|
34
|
+
// Core table features (columns, custom columns, row clicks, etc.) - required for table mode
|
|
35
|
+
baseTableFeatures: () => importBaseTableFeatures(),
|
|
36
|
+
// Table sections feature - only load if sections are configured AND overrides exist
|
|
37
|
+
// This is table-specific functionality not used in grid mode
|
|
38
|
+
sections: () => {
|
|
39
|
+
var _config$sections, _overrides$sections;
|
|
40
|
+
return !!((_config$sections = config.sections) != null && _config$sections.id) && (overrides == null || (_overrides$sections = overrides.sections) == null ? void 0 : _overrides$sections[config.sections.id]) != null ? importTableSections() : null;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
asyncFeaturesState
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=useTableGridSwitchFeaturesAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useAutoPatternsOverridesContext","useAsyncFeaturesPromiseState","importBaseTableFeatures","importTableGridSwitchDragAndDrop","importTableSections","getCommonCollectionFeaturesAsync","useTableGridSwitchFeaturesAsync","props","config","overrides","asyncFeaturesState","dragAndDrop","_config$dragAndDrop","enabled","baseTableFeatures","sections","_config$sections","_overrides$sections","id"],"sources":["../../../src/hooks/useTableGridSwitchFeaturesAsync.tsx"],"sourcesContent":["import { TableGridSwitchConfig } from '../types';\nimport { useAutoPatternsOverridesContext } from '../providers';\nimport { useAsyncFeaturesPromiseState } from './useAsyncFeaturesPromiseState';\nimport {\n importBaseTableFeatures,\n importTableGridSwitchDragAndDrop,\n importTableSections,\n} from './pluginsDynamicImports';\nimport { getCommonCollectionFeaturesAsync } from './getCommonCollectionFeaturesAsync';\n\nexport interface UseTableGridSwitchFeaturesAsyncProps {\n config: TableGridSwitchConfig;\n}\n\n/**\n * useTableGridSwitchFeaturesAsync - Step 3 in TableGridSwitch Flow\n *\n * FLOW 3: AutoPatternsCollectionComponent → AutoPatternsTableGridSwitch → [useTableGridSwitchFeaturesAsync] → AutoPatternsTableGridSwitchLoaded → useBaseCollectionComponentReadyFeatures → TableGridSwitch\n *\n * This hook is responsible for loading all table-grid-switch specific async features and plugins.\n * It combines features from both table and grid flows to support runtime switching between views.\n *\n * Key Responsibilities:\n * - Loads common collection features (shared across all flows)\n * - Conditionally loads table-grid-switch specific dragAndDrop if enabled\n * - Always loads baseTableFeatures for core table functionality (needed for table mode)\n * - Conditionally loads table sections if configured with overrides (table mode feature)\n * - Note: Grid-specific features are handled synchronously via useBaseGridFeatures\n * - Returns promise state that tracks loading status of all features\n */\nexport const useTableGridSwitchFeaturesAsync = (\n props: UseTableGridSwitchFeaturesAsyncProps,\n) => {\n const { config } = props;\n\n const overrides = useAutoPatternsOverridesContext();\n\n const asyncFeaturesState = useAsyncFeaturesPromiseState({\n // Load common features shared by all collection components (filters, common actions, etc.)\n ...getCommonCollectionFeaturesAsync(),\n\n // Table-grid-switch specific drag and drop functionality - handles both table AND grid drag&drop\n dragAndDrop: () =>\n config.dragAndDrop?.enabled ? importTableGridSwitchDragAndDrop() : null,\n\n // Core table features (columns, custom columns, row clicks, etc.) - required for table mode\n baseTableFeatures: () => importBaseTableFeatures(),\n\n // Table sections feature - only load if sections are configured AND overrides exist\n // This is table-specific functionality not used in grid mode\n sections: () =>\n !!config.sections?.id && overrides?.sections?.[config.sections.id] != null\n ? importTableSections()\n : null,\n });\n\n return { asyncFeaturesState };\n};\n"],"mappings":"AACA,SAASA,+BAA+B,QAAQ,cAAc;AAC9D,SAASC,4BAA4B,QAAQ,gCAAgC;AAC7E,SACEC,uBAAuB,EACvBC,gCAAgC,EAChCC,mBAAmB,QACd,yBAAyB;AAChC,SAASC,gCAAgC,QAAQ,oCAAoC;AAMrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,+BAA+B,GAC1CC,KAA2C,IACxC;EACH,MAAM;IAAEC;EAAO,CAAC,GAAGD,KAAK;EAExB,MAAME,SAAS,GAAGT,+BAA+B,CAAC,CAAC;EAEnD,MAAMU,kBAAkB,GAAGT,4BAA4B,CAAC;IACtD;IACA,GAAGI,gCAAgC,CAAC,CAAC;IAErC;IACAM,WAAW,EAAEA,CAAA;MAAA,IAAAC,mBAAA;MAAA,OACX,CAAAA,mBAAA,GAAAJ,MAAM,CAACG,WAAW,aAAlBC,mBAAA,CAAoBC,OAAO,GAAGV,gCAAgC,CAAC,CAAC,GAAG,IAAI;IAAA;IAEzE;IACAW,iBAAiB,EAAEA,CAAA,KAAMZ,uBAAuB,CAAC,CAAC;IAElD;IACA;IACAa,QAAQ,EAAEA,CAAA;MAAA,IAAAC,gBAAA,EAAAC,mBAAA;MAAA,OACR,CAAC,GAAAD,gBAAA,GAACR,MAAM,CAACO,QAAQ,aAAfC,gBAAA,CAAiBE,EAAE,KAAI,CAAAT,SAAS,aAAAQ,mBAAA,GAATR,SAAS,CAAEM,QAAQ,qBAAnBE,mBAAA,CAAsBT,MAAM,CAACO,QAAQ,CAACG,EAAE,CAAC,KAAI,IAAI,GACtEd,mBAAmB,CAAC,CAAC,GACrB,IAAI;IAAA;EACZ,CAAC,CAAC;EAEF,OAAO;IAAEM;EAAmB,CAAC;AAC/B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TableSections } from '@wix/patterns';
|
|
2
|
+
import { useAutoPatternsOverridesContext } from '../providers';
|
|
3
|
+
export function useTableSections(config) {
|
|
4
|
+
var _config$sections, _overrides$sections, _overrides$sections2;
|
|
5
|
+
const overrides = useAutoPatternsOverridesContext();
|
|
6
|
+
if (!((_config$sections = config.sections) != null && _config$sections.id) || !(overrides != null && (_overrides$sections = overrides.sections) != null && _overrides$sections[config.sections.id])) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
renderSection: (_overrides$sections2 = overrides.sections) == null ? void 0 : _overrides$sections2[config.sections.id],
|
|
11
|
+
TableSections
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=useTableSections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TableSections","useAutoPatternsOverridesContext","useTableSections","config","_config$sections","_overrides$sections","_overrides$sections2","overrides","sections","id","undefined","renderSection"],"sources":["../../../src/hooks/useTableSections.ts"],"sourcesContent":["import { TableSections } from '@wix/patterns';\nimport { useAutoPatternsOverridesContext } from '../providers';\nimport { TableConfig } from '../types';\n\nexport function useTableSections(config: TableConfig) {\n const overrides = useAutoPatternsOverridesContext();\n\n if (!config.sections?.id || !overrides?.sections?.[config.sections.id]) {\n return undefined;\n }\n\n return {\n renderSection: overrides.sections?.[config.sections.id],\n TableSections,\n };\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SAASC,+BAA+B,QAAQ,cAAc;AAG9D,OAAO,SAASC,gBAAgBA,CAACC,MAAmB,EAAE;EAAA,IAAAC,gBAAA,EAAAC,mBAAA,EAAAC,oBAAA;EACpD,MAAMC,SAAS,GAAGN,+BAA+B,CAAC,CAAC;EAEnD,IAAI,GAAAG,gBAAA,GAACD,MAAM,CAACK,QAAQ,aAAfJ,gBAAA,CAAiBK,EAAE,KAAI,EAACF,SAAS,aAAAF,mBAAA,GAATE,SAAS,CAAEC,QAAQ,aAAnBH,mBAAA,CAAsBF,MAAM,CAACK,QAAQ,CAACC,EAAE,CAAC,GAAE;IACtE,OAAOC,SAAS;EAClB;EAEA,OAAO;IACLC,aAAa,GAAAL,oBAAA,GAAEC,SAAS,CAACC,QAAQ,qBAAlBF,oBAAA,CAAqBH,MAAM,CAACK,QAAQ,CAACC,EAAE,CAAC;IACvDT;EACF,CAAC;AACH","ignoreList":[]}
|