@etsoo/react 1.2.32 → 1.2.36

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.
Files changed (44) hide show
  1. package/.github/workflows/main.yml +1 -1
  2. package/__tests__/tsconfig.json +1 -1
  3. package/lib/app/Labels.d.ts +4 -4
  4. package/lib/components/GridColumn.d.ts +2 -2
  5. package/lib/components/GridColumn.js +1 -1
  6. package/lib/components/GridLoader.d.ts +5 -4
  7. package/lib/components/GridLoader.js +17 -9
  8. package/lib/mu/pages/DataGridPage.d.ts +2 -1
  9. package/lib/mu/pages/DataGridPage.js +4 -4
  10. package/lib/mu/pages/DataGridPageProps.d.ts +2 -1
  11. package/lib/mu/pages/FixedListPage.d.ts +2 -1
  12. package/lib/mu/pages/FixedListPage.js +4 -4
  13. package/lib/mu/pages/ListPage.d.ts +2 -1
  14. package/lib/mu/pages/ListPage.js +4 -4
  15. package/lib/mu/pages/ListPageProps.d.ts +2 -1
  16. package/lib/mu/pages/ResponsivePage.d.ts +2 -1
  17. package/lib/mu/pages/ResponsivePage.js +4 -4
  18. package/lib/mu/pages/ResponsivePageProps.d.ts +2 -2
  19. package/lib/mu/pages/SearchPageProps.d.ts +8 -3
  20. package/lib/mu/pages/TablePage.d.ts +2 -1
  21. package/lib/mu/pages/TablePage.js +4 -4
  22. package/lib/mu/pages/TablePageProps.d.ts +2 -1
  23. package/lib/states/CultureState.d.ts +1 -1
  24. package/lib/states/RouterProps.d.ts +1 -1
  25. package/lib/uses/useCombinedRefs.d.ts +1 -1
  26. package/lib/uses/useCombinedRefs.js +1 -1
  27. package/package.json +11 -11
  28. package/src/app/Labels.ts +4 -4
  29. package/src/app/ReactApp.ts +0 -1
  30. package/src/components/GridColumn.ts +1 -1
  31. package/src/components/GridLoader.ts +26 -15
  32. package/src/mu/pages/DataGridPage.tsx +8 -4
  33. package/src/mu/pages/DataGridPageProps.ts +3 -2
  34. package/src/mu/pages/FixedListPage.tsx +7 -5
  35. package/src/mu/pages/ListPage.tsx +15 -5
  36. package/src/mu/pages/ListPageProps.ts +3 -2
  37. package/src/mu/pages/ResponsivePage.tsx +8 -4
  38. package/src/mu/pages/ResponsivePageProps.ts +6 -7
  39. package/src/mu/pages/SearchPageProps.ts +12 -3
  40. package/src/mu/pages/TablePage.tsx +8 -4
  41. package/src/mu/pages/TablePageProps.ts +3 -2
  42. package/src/states/CultureState.ts +2 -2
  43. package/src/states/RouterProps.ts +1 -1
  44. package/src/uses/useCombinedRefs.ts +3 -3
@@ -28,7 +28,7 @@ jobs:
28
28
  # Setup .npmrc file to publish to npm
29
29
  - uses: actions/setup-node@v1
30
30
  with:
31
- node-version: '14.8'
31
+ node-version: '14.18'
32
32
  registry-url: 'https://registry.npmjs.org'
33
33
 
34
34
  # Named after Continuous Integration, installs dependencies directly from package-lock.json
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2020",
3
+ "target": "ES2019",
4
4
  "module": "ESNext",
5
5
  "allowJs": true,
6
6
  "skipLibCheck": true,
@@ -50,14 +50,14 @@ export declare namespace Labels {
50
50
  * setLabelReference key reference
51
51
  */
52
52
  interface setLabelsReference {
53
- commonPage?: DataTypes.ReadonlyStringDictionary;
54
- notificationMU?: DataTypes.ReadonlyStringDictionary;
55
- userAvatarEditor?: DataTypes.ReadonlyStringDictionary;
53
+ commonPage?: DataTypes.StringDictionary;
54
+ notificationMU?: DataTypes.StringDictionary;
55
+ userAvatarEditor?: DataTypes.StringDictionary;
56
56
  }
57
57
  /**
58
58
  * Set components' labels
59
59
  * @param labels Labels
60
60
  * @param reference Key reference
61
61
  */
62
- const setLabels: (labels: DataTypes.ReadonlySimpleObject, reference?: setLabelsReference) => void;
62
+ const setLabels: (labels: {}, reference?: setLabelsReference) => void;
63
63
  }
@@ -4,7 +4,7 @@ import { GridLoaderStates } from './GridLoader';
4
4
  /**
5
5
  * Grid data type
6
6
  */
7
- import GridDataType = DataTypes.DataType;
7
+ import GridDataType = DataTypes.CombinedEnum;
8
8
  export { GridDataType };
9
9
  /**
10
10
  * Grid align
@@ -15,7 +15,7 @@ export declare type GridAlign = 'center' | 'inherit' | 'justify' | 'left' | 'rig
15
15
  * @param align Align
16
16
  * @param type Data type
17
17
  */
18
- export declare const GridAlignGet: (align?: GridAlign | undefined, type?: DataTypes.DataType | undefined) => GridAlign | undefined;
18
+ export declare const GridAlignGet: (align?: GridAlign | undefined, type?: DataTypes.CombinedEnum | undefined) => GridAlign | undefined;
19
19
  /**
20
20
  * Grid cell value type
21
21
  */
@@ -2,7 +2,7 @@ import { DataTypes } from '@etsoo/shared';
2
2
  /**
3
3
  * Grid data type
4
4
  */
5
- var GridDataType = DataTypes.DataType;
5
+ var GridDataType = DataTypes.CombinedEnum;
6
6
  export { GridDataType };
7
7
  /**
8
8
  * Data align get
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  /**
2
3
  * Grid size
3
4
  */
@@ -11,17 +12,17 @@ export declare const GridSizeGet: (size: GridSize, input: number) => number;
11
12
  /**
12
13
  * Grid data type
13
14
  */
14
- export declare type GridData = FormData | Record<string, any>;
15
+ export declare type GridData = FormData | DataTypes.StringRecord;
15
16
  /**
16
- * Grid data get as Json
17
+ * Grid data get with format
17
18
  * @param data Data
18
19
  * @returns Json data
19
20
  */
20
- export declare const GridDataGet: (data?: GridData | undefined) => Record<string, any> | undefined;
21
+ export declare function GridDataGet<F extends DataTypes.BasicTemplate>(props: GridLoadDataProps, template?: F): GridJsonData & DataTypes.BasicTemplateType<F>;
21
22
  /**
22
23
  * Grid Json data
23
24
  */
24
- export interface GridJsonData extends Omit<GridLoadDataProps, 'data'>, Record<string, any> {
25
+ export interface GridJsonData extends Omit<GridLoadDataProps, 'data'> {
25
26
  }
26
27
  /**
27
28
  * Grid data load props
@@ -10,16 +10,24 @@ export const GridSizeGet = (size, input) => {
10
10
  return size;
11
11
  };
12
12
  /**
13
- * Grid data get as Json
13
+ * Grid data get with format
14
14
  * @param data Data
15
15
  * @returns Json data
16
16
  */
17
- export const GridDataGet = (data) => {
18
- if (data instanceof FormData) {
19
- // Clear empty value
20
- DomUtils.clearFormData(data);
21
- // Transfer to Json
22
- return DomUtils.formDataToObject(data);
17
+ export function GridDataGet(props, template) {
18
+ // Destruct
19
+ const { data, ...rest } = props;
20
+ // Conditions
21
+ let conditions = {};
22
+ // Cast data
23
+ if (data != null && template != null) {
24
+ if (data instanceof FormData) {
25
+ // Clear empty value
26
+ DomUtils.clearFormData(data);
27
+ }
28
+ // Set keepSource to true to hold form data, even they are invisible from the conditions
29
+ conditions = DomUtils.dataAs(data, template, true);
23
30
  }
24
- return data;
25
- };
31
+ // DomUtils.dataAs(data, template);
32
+ return { ...conditions, ...rest };
33
+ }
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { DataGridPageProps } from './DataGridPageProps';
3
4
  /**
4
5
  * DataGrid page
5
6
  * @param props Props
6
7
  * @returns Component
7
8
  */
8
- export declare function DataGridPage<T>(props: DataGridPageProps<T>): JSX.Element;
9
+ export declare function DataGridPage<T, F extends DataTypes.BasicTemplate>(props: DataGridPageProps<T, F>): JSX.Element;
@@ -15,7 +15,7 @@ import { CommonPage } from './CommonPage';
15
15
  export function DataGridPage(props) {
16
16
  var _a, _b;
17
17
  // Destruct
18
- const { adjustHeight, fields, height, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
18
+ const { adjustHeight, fields, fieldTemplate, height, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
19
19
  (_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
20
20
  // States
21
21
  const [states, setStates] = React.useReducer((currentState, newState) => {
@@ -33,9 +33,9 @@ export function DataGridPage(props) {
33
33
  const onSubmit = (data, _reset) => {
34
34
  setStates({ data });
35
35
  };
36
- const localLoadData = ({ data, ...rest }) => {
37
- const json = GridDataGet(data);
38
- return loadData({ ...json, ...rest });
36
+ const localLoadData = (props) => {
37
+ const data = GridDataGet(props, fieldTemplate);
38
+ return loadData(data);
39
39
  };
40
40
  // Watch container
41
41
  const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
@@ -1,9 +1,10 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { DataGridExProps } from '../DataGridEx';
2
3
  import { SearchPageProps } from './SearchPageProps';
3
4
  /**
4
5
  * DataGrid page props
5
6
  */
6
- export interface DataGridPageProps<T> extends SearchPageProps<T>, Omit<DataGridExProps<T>, 'loadData' | 'height'> {
7
+ export interface DataGridPageProps<T, F extends DataTypes.BasicTemplate> extends SearchPageProps<T, F>, Omit<DataGridExProps<T>, 'loadData' | 'height'> {
7
8
  /**
8
9
  * Height will be deducted
9
10
  * @param height Current calcuated height
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { ListPageProps } from './ListPageProps';
3
4
  /**
4
5
  * Fixed height list page
5
6
  * @param props Props
6
7
  * @returns Component
7
8
  */
8
- export declare function FixedListPage<T>(props: ListPageProps<T> & {
9
+ export declare function FixedListPage<T, F extends DataTypes.BasicTemplate>(props: ListPageProps<T, F> & {
9
10
  /**
10
11
  * Height will be deducted
11
12
  * @param height Current calcuated height
@@ -15,7 +15,7 @@ import { CommonPage } from './CommonPage';
15
15
  export function FixedListPage(props) {
16
16
  var _a;
17
17
  // Destruct
18
- const { adjustHeight, fields, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
18
+ const { adjustHeight, fields, fieldTemplate, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
19
19
  (_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
20
20
  // States
21
21
  const [states] = React.useState({});
@@ -39,9 +39,9 @@ export function FixedListPage(props) {
39
39
  states.data = data;
40
40
  reset();
41
41
  };
42
- const localLoadData = ({ data, ...rest }) => {
43
- const json = GridDataGet(data);
44
- return loadData({ ...json, ...rest });
42
+ const localLoadData = (props) => {
43
+ const data = GridDataGet(props, fieldTemplate);
44
+ return loadData(data);
45
45
  };
46
46
  // Watch container
47
47
  const { dimensions } = useDimensions(1, undefined, sizeReadyMiliseconds);
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { ListPageProps } from './ListPageProps';
3
4
  /**
4
5
  * List page
5
6
  * @param props Props
6
7
  * @returns Component
7
8
  */
8
- export declare function ListPage<T>(props: ListPageProps<T>): JSX.Element;
9
+ export declare function ListPage<T, F extends DataTypes.BasicTemplate>(props: ListPageProps<T, F>): JSX.Element;
@@ -14,7 +14,7 @@ import { CommonPage, CommonPagePullContainer, CommonPageScrollContainer } from '
14
14
  export function ListPage(props) {
15
15
  var _a;
16
16
  // Destruct
17
- const { fields, loadData, mRef, pageProps = {}, ...rest } = props;
17
+ const { fields, fieldTemplate, loadData, mRef, pageProps = {}, ...rest } = props;
18
18
  (_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
19
19
  // States
20
20
  const [states] = React.useState({});
@@ -36,9 +36,9 @@ export function ListPage(props) {
36
36
  states.data = data;
37
37
  reset();
38
38
  };
39
- const localLoadData = ({ data, ...rest }) => {
40
- const json = GridDataGet(data);
41
- return loadData({ ...json, ...rest });
39
+ const localLoadData = (props) => {
40
+ const data = GridDataGet(props, fieldTemplate);
41
+ return loadData(data);
42
42
  };
43
43
  // Layout
44
44
  return (React.createElement(CommonPage, { ...pageProps, scrollContainer: CommonPageScrollContainer, pullContainer: CommonPagePullContainer },
@@ -1,7 +1,8 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { ScrollerListExProps } from '../ScrollerListEx';
2
3
  import { SearchPageProps } from './SearchPageProps';
3
4
  /**
4
5
  * List page props
5
6
  */
6
- export interface ListPageProps<T> extends SearchPageProps<T>, Omit<ScrollerListExProps<T>, 'loadData'> {
7
+ export interface ListPageProps<T, F extends DataTypes.BasicTemplate> extends SearchPageProps<T, F>, Omit<ScrollerListExProps<T>, 'loadData'> {
7
8
  }
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { ResponsePageProps } from './ResponsivePageProps';
3
4
  /**
4
5
  * Fixed height list page
5
6
  * @param props Props
6
7
  * @returns Component
7
8
  */
8
- export declare function ResponsivePage<T>(props: ResponsePageProps<T>): JSX.Element;
9
+ export declare function ResponsivePage<T, F extends DataTypes.BasicTemplate>(props: ResponsePageProps<T, F>): JSX.Element;
@@ -16,7 +16,7 @@ import { CommonPage } from './CommonPage';
16
16
  export function ResponsivePage(props) {
17
17
  var _a, _b;
18
18
  // Destruct
19
- const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, height, loadData, innerItemRenderer, itemSize, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
19
+ const { adjustHeight, columns, dataGridMinWidth = DataGridExCalColumns(columns).total, fields, fieldTemplate, height, loadData, innerItemRenderer, itemSize, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
20
20
  (_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
21
21
  // States
22
22
  const [states, setStates] = React.useReducer((currentState, newState) => {
@@ -24,9 +24,9 @@ export function ResponsivePage(props) {
24
24
  }, {
25
25
  height
26
26
  });
27
- const localLoadData = ({ data, ...rest }) => {
28
- const json = GridDataGet(data);
29
- return loadData({ ...json, ...rest });
27
+ const localLoadData = (props) => {
28
+ const data = GridDataGet(props, fieldTemplate);
29
+ return loadData(data);
30
30
  };
31
31
  const refs = useCombinedRefs(mRef, (ref) => {
32
32
  if (ref == null)
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { ListChildComponentProps } from 'react-window';
3
4
  import { GridMethodRef } from '../GridMethodRef';
4
5
  import { ScrollerListExInnerItemRendererProps } from '../ScrollerListEx';
5
6
  import { DataGridPageProps } from './DataGridPageProps';
6
- import { SearchPageProps } from './SearchPageProps';
7
7
  /**
8
8
  * Response page props
9
9
  */
10
- export interface ResponsePageProps<T> extends SearchPageProps<T>, Omit<DataGridPageProps<T>, 'mRef' | 'itemKey' | 'onScroll' | 'onItemsRendered'> {
10
+ export interface ResponsePageProps<T, F extends DataTypes.BasicTemplate> extends Omit<DataGridPageProps<T, F>, 'mRef' | 'itemKey' | 'onScroll' | 'onItemsRendered'> {
11
11
  /**
12
12
  * Min width to show Datagrid
13
13
  */
@@ -1,18 +1,23 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { GridJsonData, GridLoader } from '../../components/GridLoader';
3
4
  import { CommonPageProps } from './CommonPageProps';
4
5
  /**
5
6
  * Search page props
6
7
  */
7
- export interface SearchPageProps<T> extends Omit<GridLoader<T>, 'loadData'> {
8
+ export interface SearchPageProps<T, F extends DataTypes.BasicTemplate> extends Omit<GridLoader<T>, 'loadData'> {
8
9
  /**
9
- * Fields
10
+ * Search fields
10
11
  */
11
12
  fields: React.ReactElement[];
13
+ /**
14
+ * Search field template
15
+ */
16
+ fieldTemplate?: F;
12
17
  /**
13
18
  * Load data callback
14
19
  */
15
- loadData: (data: GridJsonData) => PromiseLike<T[] | null | undefined>;
20
+ loadData: (data: GridJsonData & DataTypes.BasicTemplateType<F>) => PromiseLike<T[] | null | undefined>;
16
21
  /**
17
22
  * Page props
18
23
  */
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
+ import { DataTypes } from '@etsoo/shared';
2
3
  import { TablePageProps } from './TablePageProps';
3
4
  /**
4
5
  * Table page
5
6
  * @param props Props
6
7
  * @returns Component
7
8
  */
8
- export declare function TablePage<T>(props: TablePageProps<T>): JSX.Element;
9
+ export declare function TablePage<T, F extends DataTypes.BasicTemplate>(props: TablePageProps<T, F>): JSX.Element;
@@ -15,7 +15,7 @@ import { CommonPage, CommonPagePullContainer, CommonPageScrollContainer } from '
15
15
  export function TablePage(props) {
16
16
  var _a;
17
17
  // Destruct
18
- const { columns, fields, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
18
+ const { columns, fields, fieldTemplate, loadData, mRef, sizeReadyMiliseconds = 100, pageProps = {}, ...rest } = props;
19
19
  (_a = pageProps.paddings) !== null && _a !== void 0 ? _a : (pageProps.paddings = MUGlobal.pagePaddings);
20
20
  // States
21
21
  const [states] = React.useState({});
@@ -37,9 +37,9 @@ export function TablePage(props) {
37
37
  states.data = data;
38
38
  reset();
39
39
  };
40
- const localLoadData = ({ data, ...rest }) => {
41
- const json = GridDataGet(data);
42
- return loadData({ ...json, ...rest });
40
+ const localLoadData = (props) => {
41
+ const data = GridDataGet(props, fieldTemplate);
42
+ return loadData(data);
43
43
  };
44
44
  // Total width
45
45
  const totalWidth = React.useMemo(() => columns.reduce((previousValue, { width, minWidth }) => {
@@ -1,7 +1,8 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { TableExProps } from '../TableEx';
2
3
  import { SearchPageProps } from './SearchPageProps';
3
4
  /**
4
5
  * Table page props
5
6
  */
6
- export interface TablePageProps<T> extends SearchPageProps<T>, Omit<TableExProps<T>, 'loadData'> {
7
+ export interface TablePageProps<T, F extends DataTypes.BasicTemplate> extends SearchPageProps<T, F>, Omit<TableExProps<T>, 'loadData'> {
7
8
  }
@@ -15,7 +15,7 @@ export interface CultureCalls extends IUpdate<ICulture, CultureAction> {
15
15
  * Key value
16
16
  * @param key Item key
17
17
  */
18
- get<T extends DataTypes.SimpleType = string>(key: string): T | undefined;
18
+ get<T = string>(key: string): T | undefined;
19
19
  }
20
20
  /**
21
21
  * Culture provider props
@@ -15,7 +15,7 @@ export declare type IdStateRouterProps<T extends DataTypes.IdType = number> = St
15
15
  /**
16
16
  * State router props, include data in location.state
17
17
  */
18
- export declare type StateRouterProps<T extends Readonly<Record<string, any>>> = RouteComponentProps<{
18
+ export declare type StateRouterProps<T extends Readonly<DataTypes.StringRecord>> = RouteComponentProps<{
19
19
  location: {
20
20
  state: T;
21
21
  };
@@ -4,4 +4,4 @@
4
4
  * @param refs Refs
5
5
  * @returns Callback
6
6
  */
7
- export default function useCombinedRefs(...refs: (React.Ref<any> | undefined)[]): (target: any) => void;
7
+ export default function useCombinedRefs(...refs: (React.Ref<unknown> | undefined)[]): (target: unknown) => void;
@@ -19,7 +19,7 @@ export default function useCombinedRefs(...refs) {
19
19
  }
20
20
  else {
21
21
  // as any to update readonly property
22
- ref.current = target;
22
+ Reflect.set(ref, 'current', target);
23
23
  }
24
24
  });
25
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.2.32",
3
+ "version": "1.2.36",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -44,16 +44,16 @@
44
44
  "@emotion/react": "^11.4.1",
45
45
  "@emotion/style": "^0.8.0",
46
46
  "@emotion/styled": "^11.3.0",
47
- "@etsoo/appscript": "^1.1.6",
48
- "@etsoo/notificationbase": "^1.0.79",
49
- "@etsoo/shared": "^1.0.46",
50
- "@mui/icons-material": "^5.0.3",
51
- "@mui/material": "^5.0.3",
47
+ "@etsoo/appscript": "^1.1.9",
48
+ "@etsoo/notificationbase": "^1.0.84",
49
+ "@etsoo/shared": "^1.0.51",
50
+ "@mui/icons-material": "^5.0.4",
51
+ "@mui/material": "^5.0.4",
52
52
  "@reach/router": "^1.3.4",
53
53
  "@types/pica": "^5.1.3",
54
54
  "@types/pulltorefreshjs": "^0.1.5",
55
55
  "@types/reach__router": "^1.3.9",
56
- "@types/react": "^17.0.27",
56
+ "@types/react": "^17.0.30",
57
57
  "@types/react-avatar-editor": "^10.3.6",
58
58
  "@types/react-dom": "^17.0.9",
59
59
  "@types/react-input-mask": "^3.0.1",
@@ -77,13 +77,13 @@
77
77
  "@types/react-test-renderer": "^17.0.1",
78
78
  "@typescript-eslint/eslint-plugin": "^5.0.0",
79
79
  "@typescript-eslint/parser": "^5.0.0",
80
- "eslint": "^8.0.0",
80
+ "eslint": "^8.0.1",
81
81
  "eslint-config-airbnb-base": "^14.2.1",
82
- "eslint-plugin-import": "^2.25.1",
82
+ "eslint-plugin-import": "^2.25.2",
83
83
  "eslint-plugin-react": "^7.26.1",
84
84
  "jest": "^27.2.5",
85
85
  "react-test-renderer": "^17.0.2",
86
- "ts-jest": "^27.0.5",
87
- "typescript": "^4.4.3"
86
+ "ts-jest": "^27.0.6",
87
+ "typescript": "^4.4.4"
88
88
  }
89
89
  }
package/src/app/Labels.ts CHANGED
@@ -54,9 +54,9 @@ export namespace Labels {
54
54
  * setLabelReference key reference
55
55
  */
56
56
  export interface setLabelsReference {
57
- commonPage?: DataTypes.ReadonlyStringDictionary;
58
- notificationMU?: DataTypes.ReadonlyStringDictionary;
59
- userAvatarEditor?: DataTypes.ReadonlyStringDictionary;
57
+ commonPage?: DataTypes.StringDictionary;
58
+ notificationMU?: DataTypes.StringDictionary;
59
+ userAvatarEditor?: DataTypes.StringDictionary;
60
60
  }
61
61
 
62
62
  /**
@@ -65,7 +65,7 @@ export namespace Labels {
65
65
  * @param reference Key reference
66
66
  */
67
67
  export const setLabels = (
68
- labels: DataTypes.ReadonlySimpleObject,
68
+ labels: {},
69
69
  reference: setLabelsReference = {}
70
70
  ) => {
71
71
  Utils.setLabels(CommonPage, labels, reference.commonPage);
@@ -7,7 +7,6 @@ import {
7
7
  } from '@etsoo/appscript';
8
8
  import { DataTypes } from '@etsoo/shared';
9
9
  import React from 'react';
10
- import { NotifierPromptProps } from '../mu/NotifierPromptProps';
11
10
  import { NotificationReactCallProps } from '../notifier/Notifier';
12
11
  import { CultureAction } from '../states/CultureState';
13
12
  import { IStateProps } from '../states/IState';
@@ -5,7 +5,7 @@ import { GridLoaderStates } from './GridLoader';
5
5
  /**
6
6
  * Grid data type
7
7
  */
8
- import GridDataType = DataTypes.DataType;
8
+ import GridDataType = DataTypes.CombinedEnum;
9
9
  export { GridDataType };
10
10
 
11
11
  /**
@@ -1,4 +1,4 @@
1
- import { DomUtils } from '@etsoo/shared';
1
+ import { DataTypes, DomUtils } from '@etsoo/shared';
2
2
 
3
3
  /**
4
4
  * Grid size
@@ -18,31 +18,42 @@ export const GridSizeGet = (size: GridSize, input: number) => {
18
18
  /**
19
19
  * Grid data type
20
20
  */
21
- export type GridData = FormData | Record<string, any>;
21
+ export type GridData = FormData | DataTypes.StringRecord;
22
22
 
23
23
  /**
24
- * Grid data get as Json
24
+ * Grid data get with format
25
25
  * @param data Data
26
26
  * @returns Json data
27
27
  */
28
- export const GridDataGet = (data?: GridData) => {
29
- if (data instanceof FormData) {
30
- // Clear empty value
31
- DomUtils.clearFormData(data);
32
-
33
- // Transfer to Json
34
- return DomUtils.formDataToObject(data);
28
+ export function GridDataGet<F extends DataTypes.BasicTemplate>(
29
+ props: GridLoadDataProps,
30
+ template?: F
31
+ ): GridJsonData & DataTypes.BasicTemplateType<F> {
32
+ // Destruct
33
+ const { data, ...rest } = props;
34
+
35
+ // Conditions
36
+ let conditions: DataTypes.BasicTemplateType<F> = {};
37
+
38
+ // Cast data
39
+ if (data != null && template != null) {
40
+ if (data instanceof FormData) {
41
+ // Clear empty value
42
+ DomUtils.clearFormData(data);
43
+ }
44
+
45
+ // Set keepSource to true to hold form data, even they are invisible from the conditions
46
+ conditions = DomUtils.dataAs(data, template, true);
35
47
  }
36
48
 
37
- return data;
38
- };
49
+ // DomUtils.dataAs(data, template);
50
+ return { ...conditions, ...rest };
51
+ }
39
52
 
40
53
  /**
41
54
  * Grid Json data
42
55
  */
43
- export interface GridJsonData
44
- extends Omit<GridLoadDataProps, 'data'>,
45
- Record<string, any> {}
56
+ export interface GridJsonData extends Omit<GridLoadDataProps, 'data'> {}
46
57
 
47
58
  /**
48
59
  * Grid data load props
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { Box, Stack } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
@@ -22,11 +23,14 @@ interface LocalStates {
22
23
  * @param props Props
23
24
  * @returns Component
24
25
  */
25
- export function DataGridPage<T>(props: DataGridPageProps<T>) {
26
+ export function DataGridPage<T, F extends DataTypes.BasicTemplate>(
27
+ props: DataGridPageProps<T, F>
28
+ ) {
26
29
  // Destruct
27
30
  const {
28
31
  adjustHeight,
29
32
  fields,
33
+ fieldTemplate,
30
34
  height,
31
35
  loadData,
32
36
  mRef,
@@ -58,9 +62,9 @@ export function DataGridPage<T>(props: DataGridPageProps<T>) {
58
62
  setStates({ data });
59
63
  };
60
64
 
61
- const localLoadData = ({ data, ...rest }: GridLoadDataProps) => {
62
- const json = GridDataGet(data);
63
- return loadData({ ...json, ...rest });
65
+ const localLoadData = (props: GridLoadDataProps) => {
66
+ const data = GridDataGet(props, fieldTemplate);
67
+ return loadData(data);
64
68
  };
65
69
 
66
70
  // Watch container
@@ -1,11 +1,12 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { DataGridExProps } from '../DataGridEx';
2
3
  import { SearchPageProps } from './SearchPageProps';
3
4
 
4
5
  /**
5
6
  * DataGrid page props
6
7
  */
7
- export interface DataGridPageProps<T>
8
- extends SearchPageProps<T>,
8
+ export interface DataGridPageProps<T, F extends DataTypes.BasicTemplate>
9
+ extends SearchPageProps<T, F>,
9
10
  Omit<DataGridExProps<T>, 'loadData' | 'height'> {
10
11
  /**
11
12
  * Height will be deducted
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { Box, Stack } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
@@ -15,8 +16,8 @@ import { ListPageProps } from './ListPageProps';
15
16
  * @param props Props
16
17
  * @returns Component
17
18
  */
18
- export function FixedListPage<T>(
19
- props: ListPageProps<T> & {
19
+ export function FixedListPage<T, F extends DataTypes.BasicTemplate>(
20
+ props: ListPageProps<T, F> & {
20
21
  /**
21
22
  * Height will be deducted
22
23
  * @param height Current calcuated height
@@ -28,6 +29,7 @@ export function FixedListPage<T>(
28
29
  const {
29
30
  adjustHeight,
30
31
  fields,
32
+ fieldTemplate,
31
33
  loadData,
32
34
  mRef,
33
35
  sizeReadyMiliseconds = 100,
@@ -69,9 +71,9 @@ export function FixedListPage<T>(
69
71
  reset();
70
72
  };
71
73
 
72
- const localLoadData = ({ data, ...rest }: GridLoadDataProps) => {
73
- const json = GridDataGet(data);
74
- return loadData({ ...json, ...rest });
74
+ const localLoadData = (props: GridLoadDataProps) => {
75
+ const data = GridDataGet(props, fieldTemplate);
76
+ return loadData(data);
75
77
  };
76
78
 
77
79
  // Watch container
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { Box, Stack } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
@@ -18,9 +19,18 @@ import { ListPageProps } from './ListPageProps';
18
19
  * @param props Props
19
20
  * @returns Component
20
21
  */
21
- export function ListPage<T>(props: ListPageProps<T>) {
22
+ export function ListPage<T, F extends DataTypes.BasicTemplate>(
23
+ props: ListPageProps<T, F>
24
+ ) {
22
25
  // Destruct
23
- const { fields, loadData, mRef, pageProps = {}, ...rest } = props;
26
+ const {
27
+ fields,
28
+ fieldTemplate,
29
+ loadData,
30
+ mRef,
31
+ pageProps = {},
32
+ ...rest
33
+ } = props;
24
34
 
25
35
  pageProps.paddings ??= MUGlobal.pagePaddings;
26
36
 
@@ -51,9 +61,9 @@ export function ListPage<T>(props: ListPageProps<T>) {
51
61
  reset();
52
62
  };
53
63
 
54
- const localLoadData = ({ data, ...rest }: GridLoadDataProps) => {
55
- const json = GridDataGet(data);
56
- return loadData({ ...json, ...rest });
64
+ const localLoadData = (props: GridLoadDataProps) => {
65
+ const data = GridDataGet(props, fieldTemplate);
66
+ return loadData(data);
57
67
  };
58
68
 
59
69
  // Layout
@@ -1,9 +1,10 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { ScrollerListExProps } from '../ScrollerListEx';
2
3
  import { SearchPageProps } from './SearchPageProps';
3
4
 
4
5
  /**
5
6
  * List page props
6
7
  */
7
- export interface ListPageProps<T>
8
- extends SearchPageProps<T>,
8
+ export interface ListPageProps<T, F extends DataTypes.BasicTemplate>
9
+ extends SearchPageProps<T, F>,
9
10
  Omit<ScrollerListExProps<T>, 'loadData'> {}
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { Box, Stack } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
@@ -23,13 +24,16 @@ interface LocalStates {
23
24
  * @param props Props
24
25
  * @returns Component
25
26
  */
26
- export function ResponsivePage<T>(props: ResponsePageProps<T>) {
27
+ export function ResponsivePage<T, F extends DataTypes.BasicTemplate>(
28
+ props: ResponsePageProps<T, F>
29
+ ) {
27
30
  // Destruct
28
31
  const {
29
32
  adjustHeight,
30
33
  columns,
31
34
  dataGridMinWidth = DataGridExCalColumns(columns).total,
32
35
  fields,
36
+ fieldTemplate,
33
37
  height,
34
38
  loadData,
35
39
  innerItemRenderer,
@@ -52,9 +56,9 @@ export function ResponsivePage<T>(props: ResponsePageProps<T>) {
52
56
  }
53
57
  );
54
58
 
55
- const localLoadData = ({ data, ...rest }: GridLoadDataProps) => {
56
- const json = GridDataGet(data);
57
- return loadData({ ...json, ...rest });
59
+ const localLoadData = (props: GridLoadDataProps) => {
60
+ const data = GridDataGet(props, fieldTemplate);
61
+ return loadData(data);
58
62
  };
59
63
 
60
64
  const refs = useCombinedRefs(mRef, (ref: GridMethodRef) => {
@@ -1,18 +1,17 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { ListChildComponentProps } from 'react-window';
2
3
  import { GridMethodRef } from '../GridMethodRef';
3
4
  import { ScrollerListExInnerItemRendererProps } from '../ScrollerListEx';
4
5
  import { DataGridPageProps } from './DataGridPageProps';
5
- import { SearchPageProps } from './SearchPageProps';
6
6
 
7
7
  /**
8
8
  * Response page props
9
9
  */
10
- export interface ResponsePageProps<T>
11
- extends SearchPageProps<T>,
12
- Omit<
13
- DataGridPageProps<T>,
14
- 'mRef' | 'itemKey' | 'onScroll' | 'onItemsRendered'
15
- > {
10
+ export interface ResponsePageProps<T, F extends DataTypes.BasicTemplate>
11
+ extends Omit<
12
+ DataGridPageProps<T, F>,
13
+ 'mRef' | 'itemKey' | 'onScroll' | 'onItemsRendered'
14
+ > {
16
15
  /**
17
16
  * Min width to show Datagrid
18
17
  */
@@ -1,19 +1,28 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { GridJsonData, GridLoader } from '../../components/GridLoader';
2
3
  import { CommonPageProps } from './CommonPageProps';
3
4
 
4
5
  /**
5
6
  * Search page props
6
7
  */
7
- export interface SearchPageProps<T> extends Omit<GridLoader<T>, 'loadData'> {
8
+ export interface SearchPageProps<T, F extends DataTypes.BasicTemplate>
9
+ extends Omit<GridLoader<T>, 'loadData'> {
8
10
  /**
9
- * Fields
11
+ * Search fields
10
12
  */
11
13
  fields: React.ReactElement[];
12
14
 
15
+ /**
16
+ * Search field template
17
+ */
18
+ fieldTemplate?: F;
19
+
13
20
  /**
14
21
  * Load data callback
15
22
  */
16
- loadData: (data: GridJsonData) => PromiseLike<T[] | null | undefined>;
23
+ loadData: (
24
+ data: GridJsonData & DataTypes.BasicTemplateType<F>
25
+ ) => PromiseLike<T[] | null | undefined>;
17
26
 
18
27
  /**
19
28
  * Page props
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { Box, Stack } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridDataGet, GridLoadDataProps } from '../../components/GridLoader';
@@ -18,11 +19,14 @@ import { TablePageProps } from './TablePageProps';
18
19
  * @param props Props
19
20
  * @returns Component
20
21
  */
21
- export function TablePage<T>(props: TablePageProps<T>) {
22
+ export function TablePage<T, F extends DataTypes.BasicTemplate>(
23
+ props: TablePageProps<T, F>
24
+ ) {
22
25
  // Destruct
23
26
  const {
24
27
  columns,
25
28
  fields,
29
+ fieldTemplate,
26
30
  loadData,
27
31
  mRef,
28
32
  sizeReadyMiliseconds = 100,
@@ -59,9 +63,9 @@ export function TablePage<T>(props: TablePageProps<T>) {
59
63
  reset();
60
64
  };
61
65
 
62
- const localLoadData = ({ data, ...rest }: GridLoadDataProps) => {
63
- const json = GridDataGet(data);
64
- return loadData({ ...json, ...rest });
66
+ const localLoadData = (props: GridLoadDataProps) => {
67
+ const data = GridDataGet(props, fieldTemplate);
68
+ return loadData(data);
65
69
  };
66
70
 
67
71
  // Total width
@@ -1,9 +1,10 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { TableExProps } from '../TableEx';
2
3
  import { SearchPageProps } from './SearchPageProps';
3
4
 
4
5
  /**
5
6
  * Table page props
6
7
  */
7
- export interface TablePageProps<T>
8
- extends SearchPageProps<T>,
8
+ export interface TablePageProps<T, F extends DataTypes.BasicTemplate>
9
+ extends SearchPageProps<T, F>,
9
10
  Omit<TableExProps<T>, 'loadData'> {}
@@ -16,7 +16,7 @@ export interface CultureCalls extends IUpdate<ICulture, CultureAction> {
16
16
  * Key value
17
17
  * @param key Item key
18
18
  */
19
- get<T extends DataTypes.SimpleType = string>(key: string): T | undefined;
19
+ get<T = string>(key: string): T | undefined;
20
20
  }
21
21
 
22
22
  /**
@@ -30,7 +30,7 @@ const calls = {
30
30
  * Key value
31
31
  * @param key Item key
32
32
  */
33
- get<T extends DataTypes.SimpleType = string>(key: string) {
33
+ get<T = string>(key: string) {
34
34
  const value = this.state.resources[key];
35
35
  if (value == null) return undefined;
36
36
  return value as T;
@@ -16,7 +16,7 @@ export type IdStateRouterProps<T extends DataTypes.IdType = number> =
16
16
  /**
17
17
  * State router props, include data in location.state
18
18
  */
19
- export type StateRouterProps<T extends Readonly<Record<string, any>>> =
19
+ export type StateRouterProps<T extends Readonly<DataTypes.StringRecord>> =
20
20
  RouteComponentProps<{
21
21
  location: { state: T };
22
22
  }>;
@@ -4,9 +4,9 @@
4
4
  * @returns Callback
5
5
  */
6
6
  export default function useCombinedRefs(
7
- ...refs: (React.Ref<any> | undefined)[]
7
+ ...refs: (React.Ref<unknown> | undefined)[]
8
8
  ) {
9
- return (target: any) => {
9
+ return (target: unknown) => {
10
10
  // Ignore null reference
11
11
  if (target == null) return;
12
12
 
@@ -20,7 +20,7 @@ export default function useCombinedRefs(
20
20
  ref(target);
21
21
  } else {
22
22
  // as any to update readonly property
23
- (ref as any).current = target;
23
+ Reflect.set(ref, 'current', target);
24
24
  }
25
25
  });
26
26
  };