es-grid-template 0.0.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/LICENSE +19 -0
- package/README.md +1 -6
- package/{dist/components/GridTable → es}/CheckboxFilter.d.ts +1 -1
- package/es/CheckboxFilter.js +249 -0
- package/{dist/components/GridTable → es}/ColumnsChoose.d.ts +3 -2
- package/es/ColumnsChoose.js +213 -0
- package/{dist/components/GridTable → es}/ContextMenu.d.ts +1 -1
- package/es/ContextMenu.js +126 -0
- package/{dist/components/GridTable → es}/FilterSearch.d.ts +3 -3
- package/es/FilterSearch.js +33 -0
- package/es/GridTable.d.ts +7 -0
- package/es/GridTable.js +927 -0
- package/es/hooks/constant.js +214 -0
- package/es/hooks/index.js +5 -0
- package/{dist → es}/hooks/useColumns/index.d.ts +1 -1
- package/es/hooks/useColumns/index.js +25 -0
- package/{dist → es}/hooks/useIsOverflow.d.ts +1 -1
- package/es/hooks/useIsOverflow.js +17 -0
- package/es/hooks/useOnClickOutside.js +28 -0
- package/{dist → es}/hooks/utils.d.ts +7 -3
- package/es/hooks/utils.js +192 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/styles.scss +30 -0
- package/es/type.d.ts +88 -0
- package/es/type.js +1 -0
- package/lib/CheckboxFilter.d.ts +19 -0
- package/lib/CheckboxFilter.js +257 -0
- package/lib/ColumnsChoose.d.ts +10 -0
- package/lib/ColumnsChoose.js +223 -0
- package/lib/ContextMenu.d.ts +20 -0
- package/lib/ContextMenu.js +135 -0
- package/lib/FilterSearch.d.ts +12 -0
- package/lib/FilterSearch.js +42 -0
- package/lib/GridTable.d.ts +7 -0
- package/lib/GridTable.js +936 -0
- package/lib/hooks/constant.d.ts +48 -0
- package/lib/hooks/constant.js +221 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.js +49 -0
- package/lib/hooks/useColumns/index.d.ts +2 -0
- package/lib/hooks/useColumns/index.js +31 -0
- package/lib/hooks/useIsOverflow.d.ts +1 -0
- package/lib/hooks/useIsOverflow.js +26 -0
- package/lib/hooks/useOnClickOutside.d.ts +1 -0
- package/lib/hooks/useOnClickOutside.js +36 -0
- package/lib/hooks/utils.d.ts +18 -0
- package/lib/hooks/utils.js +215 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +9 -0
- package/lib/styles.scss +30 -0
- package/lib/type.d.ts +88 -0
- package/lib/type.js +5 -0
- package/package.json +75 -94
- package/dist/components/GridTable/GridTable.d.ts +0 -6
- package/dist/components/GridTable/index.d.ts +0 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -53
- package/dist/type.d.ts +0 -45
- /package/{dist → es}/hooks/constant.d.ts +0 -0
- /package/{dist → es}/hooks/index.d.ts +0 -0
- /package/{dist → es}/hooks/useOnClickOutside.d.ts +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
export const defaultWidth = 100;
|
|
2
|
+
export const defaultRowHeight = 35;
|
|
3
|
+
export const numberOperator = [{
|
|
4
|
+
value: 'equal',
|
|
5
|
+
label: 'Equal',
|
|
6
|
+
key: '=='
|
|
7
|
+
}, {
|
|
8
|
+
value: 'greaterthan',
|
|
9
|
+
label: 'Greater than',
|
|
10
|
+
key: '>'
|
|
11
|
+
}, {
|
|
12
|
+
value: 'greaterthan',
|
|
13
|
+
label: 'Greater Than or Equal',
|
|
14
|
+
key: '>='
|
|
15
|
+
}, {
|
|
16
|
+
value: 'lessthan',
|
|
17
|
+
label: 'Less Than',
|
|
18
|
+
key: '<'
|
|
19
|
+
}, {
|
|
20
|
+
value: 'lessthanorequal',
|
|
21
|
+
label: 'Less Than Or Equal',
|
|
22
|
+
key: '<='
|
|
23
|
+
}, {
|
|
24
|
+
value: 'notequal',
|
|
25
|
+
label: 'Not Equal',
|
|
26
|
+
key: '!='
|
|
27
|
+
}];
|
|
28
|
+
export const stringOperator = [{
|
|
29
|
+
value: 'startswith',
|
|
30
|
+
key: '_=',
|
|
31
|
+
label: 'Starts With'
|
|
32
|
+
}, {
|
|
33
|
+
value: 'endswith',
|
|
34
|
+
key: '|=',
|
|
35
|
+
label: 'Ends With'
|
|
36
|
+
}, {
|
|
37
|
+
value: 'contains',
|
|
38
|
+
key: '~=',
|
|
39
|
+
label: 'Contains'
|
|
40
|
+
}, {
|
|
41
|
+
value: 'equal',
|
|
42
|
+
key: '==',
|
|
43
|
+
label: 'Equal'
|
|
44
|
+
}, {
|
|
45
|
+
value: 'notequal',
|
|
46
|
+
key: '!=',
|
|
47
|
+
label: 'Not Equal'
|
|
48
|
+
}];
|
|
49
|
+
export const dateOperator = [{
|
|
50
|
+
value: 'equal',
|
|
51
|
+
key: '==',
|
|
52
|
+
label: 'Equal'
|
|
53
|
+
}, {
|
|
54
|
+
value: 'notequal',
|
|
55
|
+
key: '!=',
|
|
56
|
+
label: 'Not Equal'
|
|
57
|
+
}, {
|
|
58
|
+
value: 'greaterthan',
|
|
59
|
+
key: '>',
|
|
60
|
+
label: 'Greater Than'
|
|
61
|
+
}, {
|
|
62
|
+
value: 'lessthan',
|
|
63
|
+
key: '<',
|
|
64
|
+
label: 'Less Than'
|
|
65
|
+
}];
|
|
66
|
+
export const dateTimeOperator = [{
|
|
67
|
+
value: 'equal',
|
|
68
|
+
key: '==',
|
|
69
|
+
label: 'Equal'
|
|
70
|
+
}, {
|
|
71
|
+
value: 'notequal',
|
|
72
|
+
key: '!=',
|
|
73
|
+
label: 'Not Equal'
|
|
74
|
+
}, {
|
|
75
|
+
value: 'greaterthan',
|
|
76
|
+
key: '>',
|
|
77
|
+
label: 'Greater Than'
|
|
78
|
+
}, {
|
|
79
|
+
value: 'lessthan',
|
|
80
|
+
key: '<',
|
|
81
|
+
label: 'Less Than'
|
|
82
|
+
}];
|
|
83
|
+
export const booleanOperator = [{
|
|
84
|
+
value: 'equal',
|
|
85
|
+
key: '==',
|
|
86
|
+
label: 'Equal'
|
|
87
|
+
}, {
|
|
88
|
+
value: 'notequal',
|
|
89
|
+
key: '!=',
|
|
90
|
+
label: 'Not Equal'
|
|
91
|
+
}];
|
|
92
|
+
export const translateOption = (options, t) => {
|
|
93
|
+
if (!t) {
|
|
94
|
+
return options;
|
|
95
|
+
}
|
|
96
|
+
return options.map(it => ({
|
|
97
|
+
...it,
|
|
98
|
+
label: t(it.label)
|
|
99
|
+
}));
|
|
100
|
+
};
|
|
101
|
+
export const transferFontSize = {
|
|
102
|
+
6: 8,
|
|
103
|
+
7: 9,
|
|
104
|
+
8: 11,
|
|
105
|
+
9: 12,
|
|
106
|
+
10: 13,
|
|
107
|
+
11: 15,
|
|
108
|
+
12: 16,
|
|
109
|
+
13: 17,
|
|
110
|
+
14: 19,
|
|
111
|
+
15: 20,
|
|
112
|
+
16: 21,
|
|
113
|
+
17: 23,
|
|
114
|
+
18: 24,
|
|
115
|
+
19: 25,
|
|
116
|
+
20: 27,
|
|
117
|
+
21: 28,
|
|
118
|
+
22: 29,
|
|
119
|
+
24: 32,
|
|
120
|
+
26: 35,
|
|
121
|
+
27: 36,
|
|
122
|
+
28: 37
|
|
123
|
+
};
|
|
124
|
+
export const defaultDateFormat = 'd/m/Y';
|
|
125
|
+
export const defaultDateTimeFormat = 'd/m/Y H:i';
|
|
126
|
+
export const defaultTimeFormat = 'H:i';
|
|
127
|
+
export const defaultPageSizes = [20, 30, 50, 100];
|
|
128
|
+
export const alignToFlex = {
|
|
129
|
+
center: 'center',
|
|
130
|
+
left: 'start',
|
|
131
|
+
right: 'end'
|
|
132
|
+
};
|
|
133
|
+
export const optionsSize = [{
|
|
134
|
+
label: 'letter',
|
|
135
|
+
value: 'letter',
|
|
136
|
+
width: 21.59,
|
|
137
|
+
height: 27.94
|
|
138
|
+
}, {
|
|
139
|
+
label: 'A3',
|
|
140
|
+
value: 'a3',
|
|
141
|
+
width: 27.94,
|
|
142
|
+
height: 42
|
|
143
|
+
}, {
|
|
144
|
+
label: 'A4',
|
|
145
|
+
value: 'a4',
|
|
146
|
+
width: 21,
|
|
147
|
+
height: 29.7
|
|
148
|
+
}];
|
|
149
|
+
export const paperSize = {
|
|
150
|
+
a4: {
|
|
151
|
+
width: 21,
|
|
152
|
+
height: 29.7
|
|
153
|
+
},
|
|
154
|
+
a3: {
|
|
155
|
+
width: 27.94,
|
|
156
|
+
height: 42
|
|
157
|
+
},
|
|
158
|
+
letter: {
|
|
159
|
+
width: 21.59,
|
|
160
|
+
height: 27.94
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
export const optionFont = [{
|
|
164
|
+
value: 'Times New Roman',
|
|
165
|
+
label: 'Times New Roman'
|
|
166
|
+
}, {
|
|
167
|
+
value: 'Calibri',
|
|
168
|
+
label: 'Calibri (Body)'
|
|
169
|
+
}];
|
|
170
|
+
// portrait' | 'landscape'
|
|
171
|
+
export const optionsPaperOrientation = [{
|
|
172
|
+
value: 'portrait',
|
|
173
|
+
label: 'portrait'
|
|
174
|
+
}, {
|
|
175
|
+
value: 'landscape',
|
|
176
|
+
label: 'landscape'
|
|
177
|
+
}];
|
|
178
|
+
export const optionFontSize = [{
|
|
179
|
+
value: 8,
|
|
180
|
+
label: '8'
|
|
181
|
+
}, {
|
|
182
|
+
value: 9,
|
|
183
|
+
label: '9'
|
|
184
|
+
}, {
|
|
185
|
+
value: 10,
|
|
186
|
+
label: '10'
|
|
187
|
+
}, {
|
|
188
|
+
value: 11,
|
|
189
|
+
label: '11'
|
|
190
|
+
}, {
|
|
191
|
+
value: 12,
|
|
192
|
+
label: '12'
|
|
193
|
+
}, {
|
|
194
|
+
value: 13,
|
|
195
|
+
label: '13'
|
|
196
|
+
}, {
|
|
197
|
+
value: 14,
|
|
198
|
+
label: '14'
|
|
199
|
+
}, {
|
|
200
|
+
value: 16,
|
|
201
|
+
label: '16'
|
|
202
|
+
}, {
|
|
203
|
+
value: 18,
|
|
204
|
+
label: '18'
|
|
205
|
+
}, {
|
|
206
|
+
value: 24,
|
|
207
|
+
label: '24'
|
|
208
|
+
}, {
|
|
209
|
+
value: 36,
|
|
210
|
+
label: '36'
|
|
211
|
+
}, {
|
|
212
|
+
value: 48,
|
|
213
|
+
label: '48'
|
|
214
|
+
}];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ColumnsType, ColumnType } from "../../type";
|
|
1
|
+
import type { ColumnsType, ColumnType } from "../../type";
|
|
2
2
|
export declare function flatColumns<RecordType>(columns: ColumnsType<RecordType>, parentKey?: string): ColumnType<RecordType>[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
export function flatColumns(columns, parentKey = 'key') {
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
return columns.filter(column => column && typeof column === 'object').reduce((list, column, index) => {
|
|
6
|
+
const {
|
|
7
|
+
fixed
|
|
8
|
+
} = column;
|
|
9
|
+
// Convert `fixed='true'` to `fixed='left'` instead
|
|
10
|
+
const parsedFixed = fixed === true ? 'left' : fixed;
|
|
11
|
+
const mergedKey = `${parentKey}-${index}`;
|
|
12
|
+
const subColumns = column.children;
|
|
13
|
+
if (subColumns && subColumns.length > 0) {
|
|
14
|
+
return [...list, ...flatColumns(subColumns, mergedKey).map(subColum => ({
|
|
15
|
+
fixed: parsedFixed,
|
|
16
|
+
...subColum
|
|
17
|
+
}))];
|
|
18
|
+
}
|
|
19
|
+
return [...list, {
|
|
20
|
+
key: mergedKey,
|
|
21
|
+
...column,
|
|
22
|
+
fixed: parsedFixed
|
|
23
|
+
}];
|
|
24
|
+
}, []);
|
|
25
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useIsOverflow: (ref: any, callback?: any) => boolean
|
|
1
|
+
export declare const useIsOverflow: (ref: any, callback?: any) => boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export const useIsOverflow = (ref, callback) => {
|
|
3
|
+
const [isOverflow, setIsOverflow] = React.useState(false);
|
|
4
|
+
React.useLayoutEffect(() => {
|
|
5
|
+
const trigger = () => {
|
|
6
|
+
const hasOverflow = ref?.current?.scrollWidth > ref?.current?.clientWidth;
|
|
7
|
+
setIsOverflow(hasOverflow);
|
|
8
|
+
if (callback) {
|
|
9
|
+
callback(hasOverflow);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
if (ref) {
|
|
13
|
+
trigger();
|
|
14
|
+
}
|
|
15
|
+
}, [callback, ref]);
|
|
16
|
+
return isOverflow;
|
|
17
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//** React Imports
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export const useOnClickOutside = (ref, handler) => {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const listener = event => {
|
|
6
|
+
// ** Do nothing if clicking ref's element or descendent elements
|
|
7
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// ** Call passed function on click outside
|
|
12
|
+
handler(event);
|
|
13
|
+
};
|
|
14
|
+
document.addEventListener('mousedown', listener);
|
|
15
|
+
document.addEventListener('touchstart', listener);
|
|
16
|
+
return () => {
|
|
17
|
+
document.removeEventListener('mousedown', listener);
|
|
18
|
+
document.removeEventListener('touchstart', listener);
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
// ** Add ref and handler to effect dependencies
|
|
22
|
+
// ** It's worth noting that because passed in handler is a new ...
|
|
23
|
+
// ** ... function on every render that will cause this effect ...
|
|
24
|
+
// ** ... callback/cleanup to run every render. It's not a big deal ...
|
|
25
|
+
// ** ... but to optimize you can wrap handler in useCallback before ...
|
|
26
|
+
// ** ... passing it into this hook.
|
|
27
|
+
[ref, handler]);
|
|
28
|
+
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
+
import type { EditType, IColumnType, TypeFilter } from "ui-rc";
|
|
3
|
+
import type { ColumnType } from "../type";
|
|
2
4
|
export declare const sumDataByField: (data: any[], field: string) => any;
|
|
3
|
-
export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string
|
|
5
|
+
export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
4
6
|
export declare const checkDecimalSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
5
7
|
export declare const isEmpty: (d: any) => boolean;
|
|
6
8
|
export declare const isNullOrUndefined: (d: any) => boolean;
|
|
7
9
|
export declare const convertDayjsToDate: (dateString: string, format: string) => Date;
|
|
8
|
-
export declare const convertDateToDayjs: (date: Date | undefined, format: string) => dayjs.Dayjs
|
|
10
|
+
export declare const convertDateToDayjs: (date: Date | undefined, format: string) => dayjs.Dayjs;
|
|
9
11
|
export declare const isNameColor: (strColor: string) => boolean;
|
|
10
12
|
export declare const isColor: (value: string) => boolean;
|
|
11
|
-
export declare const getVisibleColumnKeys: (columns: any[]) => string[];
|
|
12
13
|
export declare const getAllVisibleKeys: (columns: any[]) => any[];
|
|
14
|
+
export declare const getVisibleColumnKeys: (columns: any[]) => string[];
|
|
13
15
|
export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
|
|
14
16
|
export declare const updateColumns: (columns: any[], includes: string[]) => any[];
|
|
17
|
+
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, col: ColumnType<any>) => string;
|
|
18
|
+
export declare const getTypeFilter: (col: ColumnType<any>) => TypeFilter;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
export const sumDataByField = (data, field) => {
|
|
3
|
+
if (data && data.length > 0) {
|
|
4
|
+
return data.reduce((accumulator, currentValue) => {
|
|
5
|
+
const val = typeof currentValue[field] === 'number' || !isNaN(currentValue[field]) ? Number(currentValue[field]) : 0;
|
|
6
|
+
return accumulator + val;
|
|
7
|
+
}, 0);
|
|
8
|
+
} else {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const checkThousandSeparator = (thousandSeparator, decimalSeparator) => {
|
|
13
|
+
if (thousandSeparator) {
|
|
14
|
+
if (decimalSeparator) {
|
|
15
|
+
if (thousandSeparator === decimalSeparator) {
|
|
16
|
+
return ',';
|
|
17
|
+
} else {
|
|
18
|
+
return thousandSeparator;
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
return thousandSeparator;
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
|
|
28
|
+
if (decimalSeparator) {
|
|
29
|
+
if (thousandSeparator) {
|
|
30
|
+
if (thousandSeparator === decimalSeparator) {
|
|
31
|
+
return '.';
|
|
32
|
+
} else {
|
|
33
|
+
return decimalSeparator;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
return decimalSeparator;
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if (thousandSeparator && thousandSeparator === '.') {
|
|
40
|
+
return ',';
|
|
41
|
+
}
|
|
42
|
+
return '.';
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export const isEmpty = d => {
|
|
46
|
+
if (d === null || d === undefined || d === '') {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
export const isNullOrUndefined = d => {
|
|
52
|
+
if (d === null || d === undefined) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
export const convertDayjsToDate = (dateString, format) => {
|
|
58
|
+
const dayjsDate = dayjs(dateString, format); // Parse using the provided format
|
|
59
|
+
if (!dayjsDate.isValid()) {
|
|
60
|
+
throw new Error('Invalid date or format');
|
|
61
|
+
}
|
|
62
|
+
// return moment(dayjsDate.toDate()).format() // Convert to JavaScript Date
|
|
63
|
+
return dayjsDate.toDate(); // Convert to JavaScript Date
|
|
64
|
+
};
|
|
65
|
+
export const convertDateToDayjs = (date, format) => {
|
|
66
|
+
const dateValue = date ? dayjs(date).format(format) : null;
|
|
67
|
+
return dateValue ? dayjs(dateValue, format) : null;
|
|
68
|
+
};
|
|
69
|
+
export const isNameColor = strColor => {
|
|
70
|
+
const s = new Option().style;
|
|
71
|
+
s.color = strColor;
|
|
72
|
+
return s.color === strColor;
|
|
73
|
+
};
|
|
74
|
+
export const isColor = value => {
|
|
75
|
+
const hexRegex = /^#([0-9A-F]{3}){1,2}$/i;
|
|
76
|
+
const rgbRegex = /^rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)$/;
|
|
77
|
+
const rgbaRegex = /^rgba\((\d{1,3}), (\d{1,3}), (\d{1,3}), (0|1|0?\.\d+)\)$/;
|
|
78
|
+
const hslRegex = /^hsl\(\d{1,3}, \d{1,3}%, \d{1,3}%\)$/;
|
|
79
|
+
const hslaRegex = /^hsla\(\d{1,3}, \d{1,3}%, \d{1,3}%, (0|1|0?\.\d+)\)$/;
|
|
80
|
+
const namedColors = /^(?:aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow)$/i;
|
|
81
|
+
return hexRegex.test(value) || rgbRegex.test(value) || rgbaRegex.test(value) || hslRegex.test(value) || hslaRegex.test(value) || namedColors.test(value) || isNameColor(value);
|
|
82
|
+
};
|
|
83
|
+
export const getAllVisibleKeys = columns => {
|
|
84
|
+
const keys = [];
|
|
85
|
+
const traverse = (cols, parentHidden = false) => {
|
|
86
|
+
for (const col of cols) {
|
|
87
|
+
if (col.hidden || parentHidden) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (col.key) {
|
|
91
|
+
keys.push(col.key);
|
|
92
|
+
}
|
|
93
|
+
if (col.children) {
|
|
94
|
+
traverse(col.children, col.hidden);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
traverse(columns);
|
|
99
|
+
return keys;
|
|
100
|
+
};
|
|
101
|
+
export const getVisibleColumnKeys = columns => {
|
|
102
|
+
const allKeys = getAllVisibleKeys(columns);
|
|
103
|
+
const allParentKeys = getHiddenParentKeys(columns);
|
|
104
|
+
const rs = allKeys.filter(item => !allParentKeys.includes(item));
|
|
105
|
+
return rs;
|
|
106
|
+
};
|
|
107
|
+
export function getHiddenParentKeys(columns, parentKeys = []) {
|
|
108
|
+
const hiddenParents = new Set();
|
|
109
|
+
for (const column of columns) {
|
|
110
|
+
if (column.children) {
|
|
111
|
+
const currentPath = column.key ? [...parentKeys, column.key] : [...parentKeys];
|
|
112
|
+
const childHiddenParents = getHiddenParentKeys(column.children, currentPath);
|
|
113
|
+
if (childHiddenParents.length > 0) {
|
|
114
|
+
childHiddenParents.forEach(key => hiddenParents.add(key));
|
|
115
|
+
currentPath.forEach(key => hiddenParents.add(key));
|
|
116
|
+
}
|
|
117
|
+
} else if (column.hidden) {
|
|
118
|
+
parentKeys.forEach(key => hiddenParents.add(key));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return Array.from(hiddenParents);
|
|
122
|
+
}
|
|
123
|
+
export const updateColumns = (columns, includes) => {
|
|
124
|
+
return columns.map(column => {
|
|
125
|
+
const newColumn = {
|
|
126
|
+
...column
|
|
127
|
+
};
|
|
128
|
+
let hasVisibleChild = false;
|
|
129
|
+
if (newColumn.children) {
|
|
130
|
+
newColumn.children = updateColumns(newColumn.children, includes);
|
|
131
|
+
hasVisibleChild = newColumn.children.some(child => !child.hidden);
|
|
132
|
+
}
|
|
133
|
+
if (newColumn.key && !includes.includes(newColumn.key)) {
|
|
134
|
+
newColumn.hidden = true;
|
|
135
|
+
} else {
|
|
136
|
+
newColumn.hidden = false;
|
|
137
|
+
}
|
|
138
|
+
if (newColumn.children && newColumn.children.length > 0) {
|
|
139
|
+
newColumn.hidden = !hasVisibleChild;
|
|
140
|
+
}
|
|
141
|
+
return newColumn;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
export const getDatepickerFormat = (type, col) => {
|
|
145
|
+
const typeFormat = type ? type.toLowerCase() : '';
|
|
146
|
+
switch (typeFormat) {
|
|
147
|
+
case "date":
|
|
148
|
+
case "daterange":
|
|
149
|
+
return col.format?.dateFormat ? col.format?.dateFormat : 'DD/MM/YYYY';
|
|
150
|
+
case "datetime":
|
|
151
|
+
return col.format?.datetimeFormat ? col.format?.datetimeFormat : 'DD/MM/YYYY HH:mm';
|
|
152
|
+
case "week":
|
|
153
|
+
return col.format?.weekFormat ? col.format?.weekFormat : 'DD/MM';
|
|
154
|
+
case "month":
|
|
155
|
+
return col.format?.monthFormat ? col.format?.monthFormat : 'MM/YYYY';
|
|
156
|
+
case "quarter":
|
|
157
|
+
return col.format?.dateFormat ? col.format?.dateFormat : 'DD/MM/YYYY';
|
|
158
|
+
case "year":
|
|
159
|
+
return col.format?.yearFormat ? col.format?.yearFormat : 'YYYY';
|
|
160
|
+
case "time":
|
|
161
|
+
return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm';
|
|
162
|
+
default:
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
export const getTypeFilter = col => {
|
|
167
|
+
if (col.typeFilter) {
|
|
168
|
+
return col.typeFilter;
|
|
169
|
+
}
|
|
170
|
+
const type = col.type ?? '';
|
|
171
|
+
switch (type) {
|
|
172
|
+
case "number":
|
|
173
|
+
return 'Number';
|
|
174
|
+
case "date":
|
|
175
|
+
return 'Date';
|
|
176
|
+
case "datetime":
|
|
177
|
+
return 'Datetime';
|
|
178
|
+
case "boolean":
|
|
179
|
+
return 'Checkbox';
|
|
180
|
+
case "checkbox":
|
|
181
|
+
return 'Checkbox';
|
|
182
|
+
|
|
183
|
+
// case "week": return ''
|
|
184
|
+
// case "month": return col.format?.monthFormat ? col.format?.monthFormat : 'MM/YYYY'
|
|
185
|
+
// case "quarter": return col.format?.dateFormat ? col.format?.dateFormat : 'DD/MM/YYYY'
|
|
186
|
+
// case "year": return col.format?.yearFormat ? col.format?.yearFormat : 'YYYY'
|
|
187
|
+
// case "time": return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm'
|
|
188
|
+
case "string":
|
|
189
|
+
default:
|
|
190
|
+
return 'Text';
|
|
191
|
+
}
|
|
192
|
+
};
|
package/es/index.d.ts
ADDED
package/es/index.js
ADDED
package/es/styles.scss
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
$prefix : 'ui-rc'!default;
|
|
2
|
+
.popup-context-menu {
|
|
3
|
+
min-width: 200px;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.ui-rc-table-wrapper{
|
|
7
|
+
&.table-none-column-select {
|
|
8
|
+
.#{$prefix}-table-cell {
|
|
9
|
+
&.#{$prefix}-table-selection-column {
|
|
10
|
+
padding: 0!important;
|
|
11
|
+
overflow: hidden !important;
|
|
12
|
+
border-inline-end: 0 !important;
|
|
13
|
+
//flex: 0 0 0 !important;
|
|
14
|
+
//width: 0 !important;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//
|
|
21
|
+
//.ui-rc-table-wrapper {
|
|
22
|
+
// &.table-none-column-select {
|
|
23
|
+
// .ui-rc-table-cell {
|
|
24
|
+
// &.ui-rc-table-selection-column {
|
|
25
|
+
// padding: 0!important;
|
|
26
|
+
// overflow: hidden !important;
|
|
27
|
+
// }
|
|
28
|
+
// }
|
|
29
|
+
// }
|
|
30
|
+
//}
|
package/es/type.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { TableProps, TableColumnType as RcColumnType } from "ui-rc";
|
|
2
|
+
import type { Key, ReactElement, ReactNode } from "react";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import type { IOperator } from "./hooks";
|
|
5
|
+
import type { FilterOperator, TableRowSelection } from "ui-rc/dist/table/interface";
|
|
6
|
+
import type { ToolbarItem } from "ui-rc/dist/toolbar";
|
|
7
|
+
import type { ItemType } from "ui-rc/dist/menu/interface";
|
|
8
|
+
export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
|
|
9
|
+
export type AnyObject = Record<PropertyKey, any>;
|
|
10
|
+
export interface ColumnGroupType<RecordType = AnyObject> extends Omit<ColumnType<RecordType>, 'dataIndex'> {
|
|
11
|
+
children: ColumnsType<RecordType>;
|
|
12
|
+
}
|
|
13
|
+
export type ColumnType<RecordType> = RcColumnType<RecordType> & {
|
|
14
|
+
type?: IColumnType;
|
|
15
|
+
isSummary?: boolean;
|
|
16
|
+
summaryTemplate?: (data: number, key: string) => ReactElement | ReactNode;
|
|
17
|
+
maxWidth?: string | number;
|
|
18
|
+
format?: IFormat;
|
|
19
|
+
allowFiltering?: boolean;
|
|
20
|
+
operator?: FilterOperator;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
showInColumnChoose?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type ColumnsType<RecordType = AnyObject> = (ColumnGroupType<RecordType> | ColumnType<RecordType>)[];
|
|
25
|
+
export interface GridTableProps<RecordType> extends Omit<TableProps<RecordType>, 'columns' | 'rowSelection'> {
|
|
26
|
+
columns?: ColumnsType<RecordType>;
|
|
27
|
+
format?: IFormat;
|
|
28
|
+
t?: any;
|
|
29
|
+
lang?: string;
|
|
30
|
+
contextMenuItems?: any[];
|
|
31
|
+
contextMenuHidden?: string[] | ((args?: Omit<ContextInfo<RecordType>, 'item' | 'event'>) => string[]);
|
|
32
|
+
contextMenuOpen?: (args: Omit<ContextInfo<RecordType>, 'item'>) => void;
|
|
33
|
+
contextMenuClick?: (args: ContextInfo<RecordType>) => void;
|
|
34
|
+
recordDoubleClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
|
|
35
|
+
toolbarItems?: ToolbarItem[];
|
|
36
|
+
showColumnChoose?: boolean;
|
|
37
|
+
onFilter?: (query: {
|
|
38
|
+
field: string;
|
|
39
|
+
key: string;
|
|
40
|
+
operator: IOperator;
|
|
41
|
+
predicate: 'and' | 'or';
|
|
42
|
+
value: any;
|
|
43
|
+
}[]) => void;
|
|
44
|
+
selectionSettings?: SelectionSettings;
|
|
45
|
+
rowKey?: string;
|
|
46
|
+
rowSelection?: RowSelection<RecordType>;
|
|
47
|
+
rowSelected?: (args: {
|
|
48
|
+
type: string;
|
|
49
|
+
rowData: RecordType;
|
|
50
|
+
selected: RecordType | RecordType[];
|
|
51
|
+
}) => void;
|
|
52
|
+
}
|
|
53
|
+
export type RowSelection<RecordType> = Omit<TableRowSelection<RecordType>, 'type' | 'columnWidth' | 'hideSelectAll' | 'defaultSelectedRowKeys'>;
|
|
54
|
+
export type SelectionSettings = {
|
|
55
|
+
mode?: 'checkbox' | 'radio';
|
|
56
|
+
type?: 'single' | 'multiple';
|
|
57
|
+
checkboxOnly?: boolean;
|
|
58
|
+
hideSelectAll?: boolean;
|
|
59
|
+
columnWidth?: number | string;
|
|
60
|
+
defaultSelectedRowKeys?: Key[];
|
|
61
|
+
};
|
|
62
|
+
export type RecordDoubleClickEventArgs<RecordType> = {
|
|
63
|
+
rowData: RecordType;
|
|
64
|
+
rowIndex: number | undefined;
|
|
65
|
+
e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
|
|
66
|
+
};
|
|
67
|
+
export type ContextInfo<RecordType> = {
|
|
68
|
+
rowInfo: {
|
|
69
|
+
rowData: RecordType | null;
|
|
70
|
+
};
|
|
71
|
+
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
|
|
72
|
+
item: ItemType;
|
|
73
|
+
};
|
|
74
|
+
export type IFormat = {
|
|
75
|
+
thousandSeparator?: string;
|
|
76
|
+
decimalSeparator?: string;
|
|
77
|
+
decimalScale?: number | undefined;
|
|
78
|
+
allowNegative?: boolean;
|
|
79
|
+
prefix?: string | undefined;
|
|
80
|
+
suffix?: string | undefined;
|
|
81
|
+
fixedDecimalScale?: boolean;
|
|
82
|
+
dateFormat?: string;
|
|
83
|
+
datetimeFormat?: string;
|
|
84
|
+
timeFormat?: string;
|
|
85
|
+
weekFormat?: string;
|
|
86
|
+
monthFormat?: string;
|
|
87
|
+
yearFormat?: string;
|
|
88
|
+
};
|
package/es/type.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TableLocale } from "ui-rc/dist/table/interface";
|
|
3
|
+
type Props = {
|
|
4
|
+
options: any[];
|
|
5
|
+
filterSearch?: boolean;
|
|
6
|
+
open?: boolean;
|
|
7
|
+
tablePrefixCls?: string;
|
|
8
|
+
prefixCls?: string;
|
|
9
|
+
dropdownPrefixCls?: string;
|
|
10
|
+
filterMultiple: boolean;
|
|
11
|
+
onSelect?: (value: any) => void;
|
|
12
|
+
selectedKeys: string[];
|
|
13
|
+
locale: TableLocale;
|
|
14
|
+
filterMode?: 'menu' | 'tree';
|
|
15
|
+
searchValue: string;
|
|
16
|
+
setSearchValue: (value: any) => void;
|
|
17
|
+
};
|
|
18
|
+
declare const CheckboxFilter: (props: Props) => React.JSX.Element;
|
|
19
|
+
export default CheckboxFilter;
|