@etsoo/react 1.8.10 → 1.8.12

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.
@@ -0,0 +1,55 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import {
3
+ GridDataGetData,
4
+ GridTemplateType
5
+ } from "../src/components/GridLoader";
6
+
7
+ const template = {
8
+ keyword: "string",
9
+ deviceId: "number",
10
+ creationStart: "date",
11
+ creationEnd: "date"
12
+ } as const satisfies DataTypes.BasicTemplate;
13
+
14
+ test("Tests for GridTemplateType", () => {
15
+ const data: GridTemplateType<typeof template> = {
16
+ keyword: "test",
17
+ deviceId: 1,
18
+ creationStart: new Date()
19
+ };
20
+
21
+ expect(data.keyword).toBe("test");
22
+ expect(data.deviceId).toBe(1);
23
+ });
24
+
25
+ test("Tests for GridDataGetData with keeping source", () => {
26
+ const data = {
27
+ keyword: "test",
28
+ deviceId: 1,
29
+ creationStart: "2024/12/06",
30
+ other: false
31
+ };
32
+
33
+ const result = GridDataGetData(data, template, true);
34
+
35
+ expect(result.keyword).toBe("test");
36
+ expect(result.deviceId).toBe(1);
37
+ expect(result.creationStart).toBeInstanceOf(Date);
38
+ expect((result as any).other).toBe(false);
39
+ });
40
+
41
+ test("Tests for GridDataGetData without keeping source", () => {
42
+ const data = {
43
+ keyword: "test",
44
+ deviceId: 1,
45
+ creationStart: "2024/12/06",
46
+ other: false
47
+ };
48
+
49
+ const result = GridDataGetData(data, template, false);
50
+
51
+ expect(result.keyword).toBe("test");
52
+ expect(result.deviceId).toBe(1);
53
+ expect(result.creationStart).toBeInstanceOf(Date);
54
+ expect((result as any).other).toBeUndefined();
55
+ });
@@ -17,8 +17,8 @@ export type GridData = FormData | DataTypes.StringRecord;
17
17
  /**
18
18
  * Grid template type
19
19
  */
20
- export type GridTemplateType<o extends object> = DataTypes.BasicTemplateType<{
21
- [k in keyof o]: k extends "date" ? "date" | "string" : k extends DataTypes.BasicNames ? DataTypes.BasicNames : never;
20
+ export type GridTemplateType<T> = DataTypes.BasicTemplateType<{
21
+ [k in keyof T]: T[k] extends "date" ? "date" | "string" : T[k] extends DataTypes.BasicNames ? T[k] : never;
22
22
  }>;
23
23
  /**
24
24
  * Grid data get with format
@@ -27,7 +27,7 @@ export type GridTemplateType<o extends object> = DataTypes.BasicTemplateType<{
27
27
  * @param keepSource Keep source data
28
28
  * @returns Json data
29
29
  */
30
- export declare function GridDataGet(props: GridLoadDataProps, template?: object, keepSource?: boolean): GridJsonData & GridTemplateType<typeof template>;
30
+ export declare function GridDataGet<const T>(props: GridLoadDataProps, template?: T, keepSource?: boolean): GridJsonData & GridTemplateType<T>;
31
31
  /**
32
32
  * Grid data get with format
33
33
  * @param data Data
@@ -35,7 +35,7 @@ export declare function GridDataGet(props: GridLoadDataProps, template?: object,
35
35
  * @param keepSource Keep source data
36
36
  * @returns Json data
37
37
  */
38
- export declare function GridDataGetData(data?: GridData, template?: object, keepSource?: boolean): GridTemplateType<typeof template>;
38
+ export declare function GridDataGetData<const T>(data?: GridData, template?: T, keepSource?: boolean): GridTemplateType<T>;
39
39
  /**
40
40
  * Grid Json data
41
41
  */
@@ -69,7 +69,7 @@ export type GridLoadDataPartialProps = {
69
69
  /**
70
70
  * Grid data loader
71
71
  */
72
- export interface GridLoader<T extends object> {
72
+ export type GridLoader<T extends object> = {
73
73
  /**
74
74
  * Auto load data, otherwise call reset
75
75
  * @default true
@@ -103,7 +103,7 @@ export interface GridLoader<T extends object> {
103
103
  * Threshold at which to pre-fetch data; default is half of loadBatchSize
104
104
  */
105
105
  threshold?: number | undefined;
106
- }
106
+ };
107
107
  type GridLoaderProps<T> = {
108
108
  /**
109
109
  * Auto load data, otherwise call reset
@@ -16,7 +16,7 @@ export const GridSizeGet = (size, input) => {
16
16
  * @param keepSource Keep source data
17
17
  * @returns Json data
18
18
  */
19
- export function GridDataGet(props, template = {}, keepSource = true) {
19
+ export function GridDataGet(props, template, keepSource) {
20
20
  // Destruct
21
21
  const { data, ...rest } = props;
22
22
  // DomUtils.dataAs(data, template);
@@ -29,7 +29,7 @@ export function GridDataGet(props, template = {}, keepSource = true) {
29
29
  * @param keepSource Keep source data
30
30
  * @returns Json data
31
31
  */
32
- export function GridDataGetData(data, template = {}, keepSource = true) {
32
+ export function GridDataGetData(data, template, keepSource) {
33
33
  // Clear form empty value
34
34
  if (data instanceof FormData) {
35
35
  DomUtils.clearFormData(data);
@@ -21,7 +21,7 @@ export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>,
21
21
  /**
22
22
  * Scroller vertical grid props
23
23
  */
24
- export interface ScrollerGridProps<T extends object> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> {
24
+ export type ScrollerGridProps<T extends object> = GridLoader<T> & Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> & {
25
25
  /**
26
26
  * Footer renderer
27
27
  */
@@ -50,7 +50,7 @@ export interface ScrollerGridProps<T extends object> extends GridLoader<T>, Omit
50
50
  * Returns the height of the specified row.
51
51
  */
52
52
  rowHeight?: ((index: number) => number) | number;
53
- }
53
+ };
54
54
  /**
55
55
  * Scroller grid forward ref
56
56
  */
@@ -6,7 +6,7 @@ import { GridMethodRef } from "./GridMethodRef";
6
6
  /**
7
7
  * Scroller vertical list props
8
8
  */
9
- export interface ScrollerListProps<T extends object> extends GridLoader<T>, Omit<ListProps<T>, "outerRef" | "height" | "width" | "children" | "itemCount"> {
9
+ export type ScrollerListProps<T extends object> = GridLoader<T> & Omit<ListProps<T>, "outerRef" | "height" | "width" | "children" | "itemCount"> & {
10
10
  /**
11
11
  * Methods ref
12
12
  */
@@ -35,7 +35,7 @@ export interface ScrollerListProps<T extends object> extends GridLoader<T>, Omit
35
35
  * Item size, a function indicates its a variable size list
36
36
  */
37
37
  itemSize: ((index: number) => number) | number;
38
- }
38
+ };
39
39
  /**
40
40
  * Scroller list ref
41
41
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.8.10",
3
+ "version": "1.8.12",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,11 +24,11 @@ export type GridData = FormData | DataTypes.StringRecord;
24
24
  /**
25
25
  * Grid template type
26
26
  */
27
- export type GridTemplateType<o extends object> = DataTypes.BasicTemplateType<{
28
- [k in keyof o]: k extends "date"
27
+ export type GridTemplateType<T> = DataTypes.BasicTemplateType<{
28
+ [k in keyof T]: T[k] extends "date"
29
29
  ? "date" | "string"
30
- : k extends DataTypes.BasicNames
31
- ? DataTypes.BasicNames
30
+ : T[k] extends DataTypes.BasicNames
31
+ ? T[k]
32
32
  : never;
33
33
  }>;
34
34
 
@@ -39,16 +39,16 @@ export type GridTemplateType<o extends object> = DataTypes.BasicTemplateType<{
39
39
  * @param keepSource Keep source data
40
40
  * @returns Json data
41
41
  */
42
- export function GridDataGet(
42
+ export function GridDataGet<const T>(
43
43
  props: GridLoadDataProps,
44
- template: object = {} satisfies DataTypes.BasicTemplate,
45
- keepSource: boolean = true
46
- ): GridJsonData & GridTemplateType<typeof template> {
44
+ template?: T,
45
+ keepSource?: boolean
46
+ ): GridJsonData & GridTemplateType<T> {
47
47
  // Destruct
48
48
  const { data, ...rest } = props;
49
49
 
50
50
  // DomUtils.dataAs(data, template);
51
- return { ...GridDataGetData(data, template, keepSource), ...rest };
51
+ return { ...GridDataGetData<T>(data, template, keepSource), ...rest };
52
52
  }
53
53
 
54
54
  /**
@@ -58,11 +58,11 @@ export function GridDataGet(
58
58
  * @param keepSource Keep source data
59
59
  * @returns Json data
60
60
  */
61
- export function GridDataGetData(
61
+ export function GridDataGetData<const T>(
62
62
  data?: GridData,
63
- template: object = {} satisfies DataTypes.BasicTemplate,
64
- keepSource: boolean = true
65
- ): GridTemplateType<typeof template> {
63
+ template?: T,
64
+ keepSource?: boolean
65
+ ): GridTemplateType<T> {
66
66
  // Clear form empty value
67
67
  if (data instanceof FormData) {
68
68
  DomUtils.clearFormData(data);
@@ -70,12 +70,12 @@ export function GridDataGetData(
70
70
 
71
71
  // Conditions
72
72
  // Set keepSource to true to hold form data, even they are invisible from the conditions
73
- const conditions: GridTemplateType<typeof template> =
73
+ const conditions =
74
74
  data == null
75
75
  ? {}
76
76
  : DomUtils.dataAs(data, template as DataTypes.BasicTemplate, keepSource);
77
77
 
78
- return conditions;
78
+ return conditions as any;
79
79
  }
80
80
 
81
81
  /**
@@ -116,7 +116,7 @@ export type GridLoadDataPartialProps = {
116
116
  /**
117
117
  * Grid data loader
118
118
  */
119
- export interface GridLoader<T extends object> {
119
+ export type GridLoader<T extends object> = {
120
120
  /**
121
121
  * Auto load data, otherwise call reset
122
122
  * @default true
@@ -161,7 +161,7 @@ export interface GridLoader<T extends object> {
161
161
  * Threshold at which to pre-fetch data; default is half of loadBatchSize
162
162
  */
163
163
  threshold?: number | undefined;
164
- }
164
+ };
165
165
 
166
166
  type GridLoaderProps<T> = {
167
167
  /**
@@ -44,44 +44,48 @@ export type ScrollerGridItemRendererProps<T> = Omit<
44
44
  /**
45
45
  * Scroller vertical grid props
46
46
  */
47
- export interface ScrollerGridProps<T extends object>
48
- extends GridLoader<T>,
49
- Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> {
50
- /**
51
- * Footer renderer
52
- */
53
- footerRenderer?: (rows: T[], states: GridLoaderStates<T>) => React.ReactNode;
54
-
55
- /**
56
- * Header renderer
57
- */
58
- headerRenderer?: (states: GridLoaderStates<T>) => React.ReactNode;
59
-
60
- /**
61
- * Id field
62
- */
63
- idField?: DataTypes.Keys<T>;
64
-
65
- /**
66
- * Item renderer
67
- */
68
- itemRenderer: (props: ScrollerGridItemRendererProps<T>) => React.ReactElement;
69
-
70
- /**
71
- * Methods
72
- */
73
- mRef?: React.Ref<ScrollerGridForwardRef<T>>;
74
-
75
- /**
76
- * On items select change
77
- */
78
- onSelectChange?: (selectedItems: T[]) => void;
79
-
80
- /**
81
- * Returns the height of the specified row.
82
- */
83
- rowHeight?: ((index: number) => number) | number;
84
- }
47
+ export type ScrollerGridProps<T extends object> = GridLoader<T> &
48
+ Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> & {
49
+ /**
50
+ * Footer renderer
51
+ */
52
+ footerRenderer?: (
53
+ rows: T[],
54
+ states: GridLoaderStates<T>
55
+ ) => React.ReactNode;
56
+
57
+ /**
58
+ * Header renderer
59
+ */
60
+ headerRenderer?: (states: GridLoaderStates<T>) => React.ReactNode;
61
+
62
+ /**
63
+ * Id field
64
+ */
65
+ idField?: DataTypes.Keys<T>;
66
+
67
+ /**
68
+ * Item renderer
69
+ */
70
+ itemRenderer: (
71
+ props: ScrollerGridItemRendererProps<T>
72
+ ) => React.ReactElement;
73
+
74
+ /**
75
+ * Methods
76
+ */
77
+ mRef?: React.Ref<ScrollerGridForwardRef<T>>;
78
+
79
+ /**
80
+ * On items select change
81
+ */
82
+ onSelectChange?: (selectedItems: T[]) => void;
83
+
84
+ /**
85
+ * Returns the height of the specified row.
86
+ */
87
+ rowHeight?: ((index: number) => number) | number;
88
+ };
85
89
 
86
90
  /**
87
91
  * Scroller grid forward ref
@@ -21,47 +21,46 @@ import { GridMethodRef } from "./GridMethodRef";
21
21
  /**
22
22
  * Scroller vertical list props
23
23
  */
24
- export interface ScrollerListProps<T extends object>
25
- extends GridLoader<T>,
26
- Omit<
27
- ListProps<T>,
28
- "outerRef" | "height" | "width" | "children" | "itemCount" // Exclude these props, shoud be exisited otherwise will be failed
29
- > {
30
- /**
31
- * Methods ref
32
- */
33
- mRef?: React.Ref<ScrollerListForwardRef<T>>;
34
-
35
- /**
36
- * Outer div ref
37
- */
38
- oRef?: React.Ref<HTMLDivElement>;
39
-
40
- /**
41
- * Height of the list
42
- */
43
- height?: number;
44
-
45
- /**
46
- * Width of the list
47
- */
48
- width?: number | string;
49
-
50
- /**
51
- * Id field
52
- */
53
- idField?: DataTypes.Keys<T>;
54
-
55
- /**
56
- * Item renderer
57
- */
58
- itemRenderer: (props: ListChildComponentProps<T>) => React.ReactElement;
59
-
60
- /**
61
- * Item size, a function indicates its a variable size list
62
- */
63
- itemSize: ((index: number) => number) | number;
64
- }
24
+ export type ScrollerListProps<T extends object> = GridLoader<T> &
25
+ Omit<
26
+ ListProps<T>,
27
+ "outerRef" | "height" | "width" | "children" | "itemCount" // Exclude these props, shoud be exisited otherwise will be failed
28
+ > & {
29
+ /**
30
+ * Methods ref
31
+ */
32
+ mRef?: React.Ref<ScrollerListForwardRef<T>>;
33
+
34
+ /**
35
+ * Outer div ref
36
+ */
37
+ oRef?: React.Ref<HTMLDivElement>;
38
+
39
+ /**
40
+ * Height of the list
41
+ */
42
+ height?: number;
43
+
44
+ /**
45
+ * Width of the list
46
+ */
47
+ width?: number | string;
48
+
49
+ /**
50
+ * Id field
51
+ */
52
+ idField?: DataTypes.Keys<T>;
53
+
54
+ /**
55
+ * Item renderer
56
+ */
57
+ itemRenderer: (props: ListChildComponentProps<T>) => React.ReactElement;
58
+
59
+ /**
60
+ * Item size, a function indicates its a variable size list
61
+ */
62
+ itemSize: ((index: number) => number) | number;
63
+ };
65
64
 
66
65
  /**
67
66
  * Scroller list ref