es-grid-template 1.9.44 → 1.9.45

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.
@@ -194,10 +194,10 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
194
194
  value: any;
195
195
  rowData: RecordType;
196
196
  }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
197
- onCellStyles?: Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position">);
198
- onCellHeaderStyles?: Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position">);
197
+ onCellStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
198
+ onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
199
199
  onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
200
- onCellFooterStyles?: Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position">);
200
+ onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
201
201
  getValue?: (row: any, rowIndex: number) => any;
202
202
  getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
203
203
  headerCellProps?: import("./../../grid-component/type").CellProps;
@@ -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,20 @@ const EditableCell = props => {
305
305
  });
306
306
  case 'time':
307
307
  const timeFormat = getDatepickerFormat(editType, cellFormat);
308
- const time = value ? dayjs(value, timeFormat) : null;
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
+ }
319
+
320
+ // time = value ? dayjs(value, timeFormat) : null
321
+
309
322
  const maxTimeValue = !isEmpty(column.maxTime) ? dayjs(column.maxTime).format(timeFormat) : null;
310
323
  const minTimeValue = !isEmpty(column.minTime) ? dayjs(column.minTime).format(timeFormat) : null;
311
324
 
@@ -336,7 +349,20 @@ const EditableCell = props => {
336
349
  autoFocus: column.field === startCell?.colId,
337
350
  defaultOpen: column.field === startCell?.colId,
338
351
  onChange: (newDate, dateString) => {
352
+ if (typeTime === 'time') {
353
+ onChange(dateString);
354
+ } else {
355
+ // const datetime = dayjs(dateString as string, timeFormat, true);
356
+
357
+ const newVal = moment(newDate.toDate()).format();
358
+
359
+ // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
360
+
361
+ onChange(newVal);
362
+ }
363
+
339
364
  // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
365
+
340
366
  onChange(dateString);
341
367
  setTimeout(() => {
342
368
  // @ts-ignore
@@ -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
- return value ? value : '';
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,20 @@ const EditableCell = props => {
313
313
  });
314
314
  case 'time':
315
315
  const timeFormat = (0, _utils.getDatepickerFormat)(editType, cellFormat);
316
- const time = value ? (0, _dayjs.default)(value, timeFormat) : null;
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
+ }
327
+
328
+ // time = value ? dayjs(value, timeFormat) : null
329
+
317
330
  const maxTimeValue = !(0, _utils.isEmpty)(column.maxTime) ? (0, _dayjs.default)(column.maxTime).format(timeFormat) : null;
318
331
  const minTimeValue = !(0, _utils.isEmpty)(column.minTime) ? (0, _dayjs.default)(column.minTime).format(timeFormat) : null;
319
332
 
@@ -344,7 +357,20 @@ const EditableCell = props => {
344
357
  autoFocus: column.field === startCell?.colId,
345
358
  defaultOpen: column.field === startCell?.colId,
346
359
  onChange: (newDate, dateString) => {
360
+ if (typeTime === 'time') {
361
+ onChange(dateString);
362
+ } else {
363
+ // const datetime = dayjs(dateString as string, timeFormat, true);
364
+
365
+ const newVal = (0, _moment.default)(newDate.toDate()).format();
366
+
367
+ // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
368
+
369
+ onChange(newVal);
370
+ }
371
+
347
372
  // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
373
+
348
374
  onChange(dateString);
349
375
  setTimeout(() => {
350
376
  // @ts-ignore
@@ -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
- return value ? value : '';
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.getFormat = exports.getFixedFields = exports.getEditType = exports.getDiffent2Array = exports.getDefaultValue = exports.getDefaultOperator = exports.getDatepickerFormat = exports.getDateRangeFormat = exports.getCommonPinningStyles2 = exports.getCommonPinningStyles = void 0;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.44",
3
+ "version": "1.9.45",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",