es-grid-template 1.9.44 → 1.9.46
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/es/table-component/body/EditableCell.js +33 -5
- package/es/table-component/hook/useColumns.js +5 -2
- package/es/table-component/hook/utils.d.ts +3 -0
- package/es/table-component/hook/utils.js +61 -0
- package/lib/table-component/body/EditableCell.js +32 -4
- package/lib/table-component/hook/useColumns.js +4 -1
- package/lib/table-component/hook/utils.d.ts +3 -0
- package/lib/table-component/hook/utils.js +67 -4
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
3
|
import { DatePicker, TimePicker, ColorPicker, Input } from "rc-master-ui";
|
|
4
4
|
import { Divider, Row, Col, Button } from "antd";
|
|
5
|
-
import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs, convertLabelToTitle, getDatepickerFormat, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets, getFormat, removeVietnameseTones } from "../hook/utils";
|
|
5
|
+
import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs, convertLabelToTitle, getDatepickerFormat, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets, getFormat, removeVietnameseTones, getDateValueType } from "../hook/utils";
|
|
6
6
|
import classNames from "classnames";
|
|
7
7
|
import { NumericFormat } from "react-numeric-component";
|
|
8
8
|
import dayjs from "dayjs";
|
|
@@ -305,7 +305,17 @@ const EditableCell = props => {
|
|
|
305
305
|
});
|
|
306
306
|
case 'time':
|
|
307
307
|
const timeFormat = getDatepickerFormat(editType, cellFormat);
|
|
308
|
-
|
|
308
|
+
|
|
309
|
+
// chỉ nhận giá trị dạng HH:mm | mm:HH => convert
|
|
310
|
+
|
|
311
|
+
let time = value ?? null;
|
|
312
|
+
const typeTime = getDateValueType(value);
|
|
313
|
+
if (typeTime === 'time') {
|
|
314
|
+
time = value ? dayjs(value, timeFormat) : null;
|
|
315
|
+
} else {
|
|
316
|
+
const abc = moment(value).format(timeFormat);
|
|
317
|
+
time = abc ? dayjs(abc, timeFormat) : null;
|
|
318
|
+
}
|
|
309
319
|
const maxTimeValue = !isEmpty(column.maxTime) ? dayjs(column.maxTime).format(timeFormat) : null;
|
|
310
320
|
const minTimeValue = !isEmpty(column.minTime) ? dayjs(column.minTime).format(timeFormat) : null;
|
|
311
321
|
|
|
@@ -336,7 +346,16 @@ const EditableCell = props => {
|
|
|
336
346
|
autoFocus: column.field === startCell?.colId,
|
|
337
347
|
defaultOpen: column.field === startCell?.colId,
|
|
338
348
|
onChange: (newDate, dateString) => {
|
|
339
|
-
|
|
349
|
+
if (typeTime === 'time') {
|
|
350
|
+
onChange(dateString);
|
|
351
|
+
} else {
|
|
352
|
+
// const datetime = dayjs(dateString as string, timeFormat, true);
|
|
353
|
+
|
|
354
|
+
const newVal = moment(newDate.toDate()).format();
|
|
355
|
+
|
|
356
|
+
// const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
|
|
357
|
+
onChange(newVal);
|
|
358
|
+
}
|
|
340
359
|
onChange(dateString);
|
|
341
360
|
setTimeout(() => {
|
|
342
361
|
// @ts-ignore
|
|
@@ -349,14 +368,23 @@ const EditableCell = props => {
|
|
|
349
368
|
// @ts-ignore
|
|
350
369
|
const prevState = record[dataIndex];
|
|
351
370
|
const newState = itemState;
|
|
371
|
+
let newValue = newState;
|
|
372
|
+
if (typeTime === 'time') {
|
|
373
|
+
newValue = newState;
|
|
374
|
+
} else {
|
|
375
|
+
const datetime = dayjs(newState, timeFormat, true);
|
|
376
|
+
const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : '';
|
|
377
|
+
onChange(newVal);
|
|
378
|
+
newValue = newVal;
|
|
379
|
+
}
|
|
352
380
|
if (prevState !== newState) {
|
|
353
381
|
handleCellChange?.({
|
|
354
382
|
key: key,
|
|
355
383
|
field: column.field ?? column.field,
|
|
356
384
|
record: formState,
|
|
357
385
|
prevState,
|
|
358
|
-
newState,
|
|
359
|
-
option:
|
|
386
|
+
newState: newValue,
|
|
387
|
+
option: newValue,
|
|
360
388
|
indexCol,
|
|
361
389
|
indexRow,
|
|
362
390
|
type: 'blur'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { Fragment } from 'react';
|
|
2
2
|
import ControlCheckbox from "../components/ControlCheckbox";
|
|
3
|
-
import { checkDecimalSeparator, checkThousandSeparator, countUnselectedChildren, excludeItems, getAllChildren, getFormat, isColor, isEmpty, sortByType, toggleRowAndChildren } from "./utils";
|
|
3
|
+
import { checkDecimalSeparator, checkThousandSeparator, convertToDate, countUnselectedChildren, excludeItems, getAllChildren, getFormat, isColor, isEmpty, sortByType, toggleRowAndChildren } from "./utils";
|
|
4
4
|
import { numericFormatter } from 'react-numeric-component';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import moment from 'moment';
|
|
@@ -38,7 +38,10 @@ export const renderValueCell = (column, value, record, rowIndex, colIndex, forma
|
|
|
38
38
|
case 'date':
|
|
39
39
|
return value ? dayjs(value).format(format?.dateFormat ?? 'DD/MM/YYYY') : '';
|
|
40
40
|
case 'time':
|
|
41
|
-
|
|
41
|
+
const timeFormat = format?.timeFormat ?? 'HH:mm';
|
|
42
|
+
const abc = convertToDate(value, timeFormat);
|
|
43
|
+
const timeValue = value ? dayjs(abc).format(timeFormat) : '';
|
|
44
|
+
return timeValue ?? '';
|
|
42
45
|
case 'year':
|
|
43
46
|
const year = value ? moment(value).format('yyyy') : '';
|
|
44
47
|
return year;
|
|
@@ -37,6 +37,9 @@ export declare const getFormat: (colFormat?: IFormat, format?: IFormat) => {
|
|
|
37
37
|
export declare function convertFormat(formatStr: string): string;
|
|
38
38
|
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
39
39
|
export declare const getDateRangeFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
40
|
+
export type DateValueType = 'datetime' | 'time' | 'invalid';
|
|
41
|
+
export declare function getDateValueType(value: unknown): DateValueType;
|
|
42
|
+
export declare const convertToDate: (value?: string | Date | null, format?: string) => string;
|
|
40
43
|
export declare const getTypeFilter: (col: any) => TypeFilter;
|
|
41
44
|
export declare const addRowIdArray: (inputArray: any[]) => any[];
|
|
42
45
|
export declare function groupArrayByColumns(arr: any[], columns: string[] | undefined): any;
|
|
@@ -171,6 +171,67 @@ export const getDateRangeFormat = (type, format) => {
|
|
|
171
171
|
return 'dd/MM/yyyy';
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
|
+
export function getDateValueType(value) {
|
|
175
|
+
if (typeof value !== 'string') {
|
|
176
|
+
return 'invalid';
|
|
177
|
+
}
|
|
178
|
+
const datetimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
179
|
+
const timeRegex = /^\d{2}:\d{2}(:\d{2})?$/;
|
|
180
|
+
if (datetimeRegex.test(value)) {
|
|
181
|
+
return 'datetime';
|
|
182
|
+
}
|
|
183
|
+
if (timeRegex.test(value)) {
|
|
184
|
+
return 'time';
|
|
185
|
+
}
|
|
186
|
+
return 'invalid';
|
|
187
|
+
}
|
|
188
|
+
export const convertToDate = (value, format) => {
|
|
189
|
+
if (!value) {
|
|
190
|
+
return '';
|
|
191
|
+
}
|
|
192
|
+
const valueType = getDateValueType(value);
|
|
193
|
+
if (valueType === 'time') {
|
|
194
|
+
const date = dayjs(value, format, true);
|
|
195
|
+
return date.isValid() ? moment(date.toDate()).format() : '';
|
|
196
|
+
}
|
|
197
|
+
if (valueType === 'datetime') {
|
|
198
|
+
return moment(value).format() ?? '';
|
|
199
|
+
}
|
|
200
|
+
if (valueType === 'invalid') {
|
|
201
|
+
return '';
|
|
202
|
+
}
|
|
203
|
+
return '';
|
|
204
|
+
|
|
205
|
+
// if (value instanceof Date) {
|
|
206
|
+
// return moment(value).format();
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
// let date: dayjs.Dayjs;
|
|
210
|
+
|
|
211
|
+
// if (format) {
|
|
212
|
+
// const bbb = moment(value)
|
|
213
|
+
|
|
214
|
+
// if (!bbb.isValid()) {
|
|
215
|
+
|
|
216
|
+
// // value dạng HH:mm
|
|
217
|
+
// date = dayjs(value, format, true);
|
|
218
|
+
|
|
219
|
+
// } else {
|
|
220
|
+
// // value dạng datetime
|
|
221
|
+
|
|
222
|
+
// date = dayjs(bbb.format(format), format, true);
|
|
223
|
+
|
|
224
|
+
// }
|
|
225
|
+
|
|
226
|
+
// } else {
|
|
227
|
+
|
|
228
|
+
// // Tự nhận diện ISO, YYYY-MM-DD,...
|
|
229
|
+
// date = dayjs(value);
|
|
230
|
+
|
|
231
|
+
// }
|
|
232
|
+
|
|
233
|
+
// return date.isValid() ? moment(date.toDate()).format() : null;
|
|
234
|
+
};
|
|
174
235
|
export const getTypeFilter = col => {
|
|
175
236
|
if (col?.typeFilter) {
|
|
176
237
|
return col.typeFilter;
|
|
@@ -313,7 +313,17 @@ const EditableCell = props => {
|
|
|
313
313
|
});
|
|
314
314
|
case 'time':
|
|
315
315
|
const timeFormat = (0, _utils.getDatepickerFormat)(editType, cellFormat);
|
|
316
|
-
|
|
316
|
+
|
|
317
|
+
// chỉ nhận giá trị dạng HH:mm | mm:HH => convert
|
|
318
|
+
|
|
319
|
+
let time = value ?? null;
|
|
320
|
+
const typeTime = (0, _utils.getDateValueType)(value);
|
|
321
|
+
if (typeTime === 'time') {
|
|
322
|
+
time = value ? (0, _dayjs.default)(value, timeFormat) : null;
|
|
323
|
+
} else {
|
|
324
|
+
const abc = (0, _moment.default)(value).format(timeFormat);
|
|
325
|
+
time = abc ? (0, _dayjs.default)(abc, timeFormat) : null;
|
|
326
|
+
}
|
|
317
327
|
const maxTimeValue = !(0, _utils.isEmpty)(column.maxTime) ? (0, _dayjs.default)(column.maxTime).format(timeFormat) : null;
|
|
318
328
|
const minTimeValue = !(0, _utils.isEmpty)(column.minTime) ? (0, _dayjs.default)(column.minTime).format(timeFormat) : null;
|
|
319
329
|
|
|
@@ -344,7 +354,16 @@ const EditableCell = props => {
|
|
|
344
354
|
autoFocus: column.field === startCell?.colId,
|
|
345
355
|
defaultOpen: column.field === startCell?.colId,
|
|
346
356
|
onChange: (newDate, dateString) => {
|
|
347
|
-
|
|
357
|
+
if (typeTime === 'time') {
|
|
358
|
+
onChange(dateString);
|
|
359
|
+
} else {
|
|
360
|
+
// const datetime = dayjs(dateString as string, timeFormat, true);
|
|
361
|
+
|
|
362
|
+
const newVal = (0, _moment.default)(newDate.toDate()).format();
|
|
363
|
+
|
|
364
|
+
// const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
|
|
365
|
+
onChange(newVal);
|
|
366
|
+
}
|
|
348
367
|
onChange(dateString);
|
|
349
368
|
setTimeout(() => {
|
|
350
369
|
// @ts-ignore
|
|
@@ -357,14 +376,23 @@ const EditableCell = props => {
|
|
|
357
376
|
// @ts-ignore
|
|
358
377
|
const prevState = record[dataIndex];
|
|
359
378
|
const newState = itemState;
|
|
379
|
+
let newValue = newState;
|
|
380
|
+
if (typeTime === 'time') {
|
|
381
|
+
newValue = newState;
|
|
382
|
+
} else {
|
|
383
|
+
const datetime = (0, _dayjs.default)(newState, timeFormat, true);
|
|
384
|
+
const newVal = datetime.isValid() ? (0, _moment.default)(datetime.toDate()).format() : '';
|
|
385
|
+
onChange(newVal);
|
|
386
|
+
newValue = newVal;
|
|
387
|
+
}
|
|
360
388
|
if (prevState !== newState) {
|
|
361
389
|
handleCellChange?.({
|
|
362
390
|
key: key,
|
|
363
391
|
field: column.field ?? column.field,
|
|
364
392
|
record: formState,
|
|
365
393
|
prevState,
|
|
366
|
-
newState,
|
|
367
|
-
option:
|
|
394
|
+
newState: newValue,
|
|
395
|
+
option: newValue,
|
|
368
396
|
indexCol,
|
|
369
397
|
indexRow,
|
|
370
398
|
type: 'blur'
|
|
@@ -48,7 +48,10 @@ const renderValueCell = (column, value, record, rowIndex, colIndex, format, edit
|
|
|
48
48
|
case 'date':
|
|
49
49
|
return value ? (0, _dayjs.default)(value).format(format?.dateFormat ?? 'DD/MM/YYYY') : '';
|
|
50
50
|
case 'time':
|
|
51
|
-
|
|
51
|
+
const timeFormat = format?.timeFormat ?? 'HH:mm';
|
|
52
|
+
const abc = (0, _utils.convertToDate)(value, timeFormat);
|
|
53
|
+
const timeValue = value ? (0, _dayjs.default)(abc).format(timeFormat) : '';
|
|
54
|
+
return timeValue ?? '';
|
|
52
55
|
case 'year':
|
|
53
56
|
const year = value ? (0, _moment.default)(value).format('yyyy') : '';
|
|
54
57
|
return year;
|
|
@@ -37,6 +37,9 @@ export declare const getFormat: (colFormat?: IFormat, format?: IFormat) => {
|
|
|
37
37
|
export declare function convertFormat(formatStr: string): string;
|
|
38
38
|
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
39
39
|
export declare const getDateRangeFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
|
|
40
|
+
export type DateValueType = 'datetime' | 'time' | 'invalid';
|
|
41
|
+
export declare function getDateValueType(value: unknown): DateValueType;
|
|
42
|
+
export declare const convertToDate: (value?: string | Date | null, format?: string) => string;
|
|
40
43
|
export declare const getTypeFilter: (col: any) => TypeFilter;
|
|
41
44
|
export declare const addRowIdArray: (inputArray: any[]) => any[];
|
|
42
45
|
export declare function groupArrayByColumns(arr: any[], columns: string[] | undefined): any;
|
|
@@ -19,7 +19,7 @@ exports.convertArrayWithIndent = void 0;
|
|
|
19
19
|
exports.convertColumnsToTreeData = convertColumnsToTreeData;
|
|
20
20
|
exports.convertFomatedDateToDate = exports.convertFlatColumn1 = exports.convertFilters = exports.convertDayjsToDate = exports.convertDateToDayjs = void 0;
|
|
21
21
|
exports.convertFormat = convertFormat;
|
|
22
|
-
exports.convertToObjTrue = exports.convertToObj = exports.convertLabelToTitle = void 0;
|
|
22
|
+
exports.convertToObjTrue = exports.convertToObj = exports.convertToDate = exports.convertLabelToTitle = void 0;
|
|
23
23
|
exports.countUnselectedChildren = countUnselectedChildren;
|
|
24
24
|
exports.detectSeparators = exports.customWeekStartEndFormat = void 0;
|
|
25
25
|
exports.excludeItems = excludeItems;
|
|
@@ -33,7 +33,9 @@ exports.getAllChildren = getAllChildren;
|
|
|
33
33
|
exports.getAllVisibleKeys1 = exports.getAllVisibleKeys = exports.getAllRowKey = void 0;
|
|
34
34
|
exports.getCellsByPosition = getCellsByPosition;
|
|
35
35
|
exports.getColIdsBetween = getColIdsBetween;
|
|
36
|
-
exports.
|
|
36
|
+
exports.getDateRangeFormat = exports.getCommonPinningStyles2 = exports.getCommonPinningStyles = void 0;
|
|
37
|
+
exports.getDateValueType = getDateValueType;
|
|
38
|
+
exports.getFormat = exports.getFixedFields = exports.getEditType = exports.getDiffent2Array = exports.getDefaultValue = exports.getDefaultOperator = exports.getDatepickerFormat = void 0;
|
|
37
39
|
exports.getHiddenParentKeys = getHiddenParentKeys;
|
|
38
40
|
exports.getHiddenParentKeys1 = getHiddenParentKeys1;
|
|
39
41
|
exports.getInvisibleColumns = getInvisibleColumns;
|
|
@@ -61,8 +63,7 @@ exports.sumFields = sumFields;
|
|
|
61
63
|
exports.sumNumberFields = sumNumberFields;
|
|
62
64
|
exports.sumSize = void 0;
|
|
63
65
|
exports.toggleRowAndChildren = toggleRowAndChildren;
|
|
64
|
-
exports.unFlattenData = void 0;
|
|
65
|
-
exports.updateArrayByKey = void 0;
|
|
66
|
+
exports.updateArrayByKey = exports.unFlattenData = void 0;
|
|
66
67
|
exports.updateColumnWidthsRecursive = updateColumnWidthsRecursive;
|
|
67
68
|
exports.updateColumnsByGroup = exports.updateColumns1 = void 0;
|
|
68
69
|
exports.updateOrInsert = updateOrInsert;
|
|
@@ -253,6 +254,68 @@ const getDateRangeFormat = (type, format) => {
|
|
|
253
254
|
}
|
|
254
255
|
};
|
|
255
256
|
exports.getDateRangeFormat = getDateRangeFormat;
|
|
257
|
+
function getDateValueType(value) {
|
|
258
|
+
if (typeof value !== 'string') {
|
|
259
|
+
return 'invalid';
|
|
260
|
+
}
|
|
261
|
+
const datetimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
262
|
+
const timeRegex = /^\d{2}:\d{2}(:\d{2})?$/;
|
|
263
|
+
if (datetimeRegex.test(value)) {
|
|
264
|
+
return 'datetime';
|
|
265
|
+
}
|
|
266
|
+
if (timeRegex.test(value)) {
|
|
267
|
+
return 'time';
|
|
268
|
+
}
|
|
269
|
+
return 'invalid';
|
|
270
|
+
}
|
|
271
|
+
const convertToDate = (value, format) => {
|
|
272
|
+
if (!value) {
|
|
273
|
+
return '';
|
|
274
|
+
}
|
|
275
|
+
const valueType = getDateValueType(value);
|
|
276
|
+
if (valueType === 'time') {
|
|
277
|
+
const date = (0, _dayjs.default)(value, format, true);
|
|
278
|
+
return date.isValid() ? (0, _moment.default)(date.toDate()).format() : '';
|
|
279
|
+
}
|
|
280
|
+
if (valueType === 'datetime') {
|
|
281
|
+
return (0, _moment.default)(value).format() ?? '';
|
|
282
|
+
}
|
|
283
|
+
if (valueType === 'invalid') {
|
|
284
|
+
return '';
|
|
285
|
+
}
|
|
286
|
+
return '';
|
|
287
|
+
|
|
288
|
+
// if (value instanceof Date) {
|
|
289
|
+
// return moment(value).format();
|
|
290
|
+
// }
|
|
291
|
+
|
|
292
|
+
// let date: dayjs.Dayjs;
|
|
293
|
+
|
|
294
|
+
// if (format) {
|
|
295
|
+
// const bbb = moment(value)
|
|
296
|
+
|
|
297
|
+
// if (!bbb.isValid()) {
|
|
298
|
+
|
|
299
|
+
// // value dạng HH:mm
|
|
300
|
+
// date = dayjs(value, format, true);
|
|
301
|
+
|
|
302
|
+
// } else {
|
|
303
|
+
// // value dạng datetime
|
|
304
|
+
|
|
305
|
+
// date = dayjs(bbb.format(format), format, true);
|
|
306
|
+
|
|
307
|
+
// }
|
|
308
|
+
|
|
309
|
+
// } else {
|
|
310
|
+
|
|
311
|
+
// // Tự nhận diện ISO, YYYY-MM-DD,...
|
|
312
|
+
// date = dayjs(value);
|
|
313
|
+
|
|
314
|
+
// }
|
|
315
|
+
|
|
316
|
+
// return date.isValid() ? moment(date.toDate()).format() : null;
|
|
317
|
+
};
|
|
318
|
+
exports.convertToDate = convertToDate;
|
|
256
319
|
const getTypeFilter = col => {
|
|
257
320
|
if (col?.typeFilter) {
|
|
258
321
|
return col.typeFilter;
|