es-grid-template 1.9.50 → 1.9.52

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.
@@ -177,6 +177,9 @@ export function getDateValueType(value) {
177
177
  }
178
178
  const datetimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;
179
179
  const timeRegex = /^\d{2}:\d{2}(:\d{2})?$/;
180
+
181
+ // const timeRegex = /^(?:[01]\d|2[0-3])\s*:\s*[0-5]\d(?:\s*:\s*[0-5]\d)?$/;
182
+
180
183
  if (datetimeRegex.test(value)) {
181
184
  return 'datetime';
182
185
  }
@@ -191,7 +194,8 @@ export const convertToDate = (value, format) => {
191
194
  }
192
195
  const valueType = getDateValueType(value);
193
196
  if (valueType === 'time') {
194
- const date = dayjs(value, format, true);
197
+ // const date = dayjs(value, format ? [format, 'HH:mm:ss', 'HH:mm' ] : ['HH:mm:ss', 'HH:mm'], true);
198
+ const date = dayjs(value, format ?? ['HH:mm:ss', 'HH:mm'], true);
195
199
  return date.isValid() ? moment(date.toDate()).format() : '';
196
200
  }
197
201
  if (valueType === 'datetime') {
@@ -1230,6 +1234,14 @@ export const isEditable = (column, rowData) => {
1230
1234
  }
1231
1235
  return column?.editEnable;
1232
1236
  };
1237
+ export const getNextEditableColumn = (columns, currentIndex, rowData) => {
1238
+ for (let i = currentIndex + 1; i < columns.length; i++) {
1239
+ if (isEditable(columns[i].columnDef.meta, rowData)) {
1240
+ return columns[i];
1241
+ }
1242
+ }
1243
+ return undefined;
1244
+ };
1233
1245
  export const checkFieldKey = key => {
1234
1246
  if (key) {
1235
1247
  return key;
@@ -2718,4 +2730,24 @@ export function sumNumberFields(columns, data, childrenKey = 'children') {
2718
2730
  export const getTreeDepth = rows => {
2719
2731
  if (!rows?.length) return 0;
2720
2732
  return 1 + Math.max(0, ...rows.map(r => getTreeDepth(r.children)));
2733
+ };
2734
+ const TOKEN_MAP = {
2735
+ YYYY: 'year',
2736
+ MM: 'month',
2737
+ DD: 'day',
2738
+ HH: 'hour',
2739
+ mm: 'minute',
2740
+ ss: 'second'
2741
+ };
2742
+ export const isDateChanged = (oldDate, newDate, format) => {
2743
+ const prev = dayjs(oldDate, format, true);
2744
+ const next = dayjs(newDate, format, true);
2745
+ const tokens = ['YYYY', 'MM', 'DD', 'HH', 'mm', 'ss'];
2746
+ for (const token of tokens) {
2747
+ if (!format.includes(token)) continue;
2748
+ if (!prev.isSame(next, TOKEN_MAP[token])) {
2749
+ return token;
2750
+ }
2751
+ }
2752
+ return null;
2721
2753
  };
@@ -48,4 +48,4 @@ const colorDark = '#e6e4f3e6 ';
48
48
  export const GridStyle = styled.div.withConfig({
49
49
  displayName: "GridStyle",
50
50
  componentId: "es-grid-template__sc-hdqm5k-0"
51
- })(["&.", "-grid{color:", ";font-size:", ";background-color:", ";font-family:", ";&.", "-grid-editable{.", "-grid-container{.", "-grid-tbody{.", "-grid-row{background-color:", ";color:", ";&.", "-grid-row-parent{background-color:#ffffff;font-weight:500;}}}}}table{table-layout:fixed;border-collapse:separate;border-spacing:0;}.", "-grid-container{border:1px solid ", ";border-right:0;&::after{position:absolute;top:0px;right:0;z-index:1;height:100%;border-right:1px solid ", ";content:'';pointer-events:none;}.", "-grid-cell{padding:5px 8px;&.", "-grid-cell-text-center{text-align:center;justify-content:center;}&.", "-grid-cell-text-right{justify-content:flex-end;text-align:right;}&.", "-grid-cell-ellipsis{.ui-rc_cell-content{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;word-break:keep-all;&.select-cell{padding-right:18px;position:relative;}.caret-down{float:right;position:absolute;right:0;&::before{content:'';display:inline-block;margin-left:4px;vertical-align:middle;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:5px solid #6f7777;}}}}&.", "-grid-cell-wrap{white-space:normal;text-overflow:ellipsis;word-break:break-word;}.", "-grid-header-text-wrap{white-space:normal;overflow:hidden;text-overflow:ellipsis;word-break:break-word;}}.", "-grid-thead{background-color:", ";font-weight:", ";.", "-grid-cell{font-weight:inherit;color:", ";background-color:inherit;border-inline-end:1px solid ", ";border-bottom:1px solid ", ";&.ui-rc-grid-cell-ellipsis{.ui-rc-table-column-title,.", "-grid-cell-ellipsis{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;word-break:keep-all;}}&.ui-rc-grid-cell-wrap{.ui-rc-table-column-title,.", "-grid-cell-text-wrap{white-space:normal;word-break:break-word;overflow:hidden;}}&:hover{.ui-rc-header-trigger{.ui-rc-table-column-sorter-cancel{opacity:1;}}}.", "-grid-filter-column{display:flex;justify-content:space-between;width:100%;align-items:center;position:relative;z-index:3;}.ui-rc-header-trigger{padding-left:6px;display:flex;align-items:center;.ui-rc-table-column-sorter-cancel{opacity:0;}}.resizer{cursor:col-resize;height:100%;position:absolute;right:0;top:0;z-index:3;touch-action:none;user-select:none;width:5px;}.resizer.isResizing{opacity:1;}}}.", "-grid-tbody{.", "-grid-row{font-weight:", ";background-color:", ";color:", ";&.", "-grid-row-odd{background-color:#f9f8fd;}&.", "-grid-row-even{}&.", "-grid-row-parent{background-color:#f5f5f5;font-weight:500;}}}.", "-grid-tfoot{.", "-grid-footer-row{border-bottom-width:1px;border-bottom-color:", ";border-bottom-style:solid;border-top-width:1px;border-top-color:", ";border-top-style:solid;background-color:#fafafa;}.", "-grid-cell{background-color:inherit;border-inline-end:1px solid ", ";}}}&.", "-grid-dark{background-color:", ";color:", ";.", "-grid-container{border-color:", ";&::after{border-right-color:", ";}}}.ui-rc-toolbar-bottom{border-right:1px solid #e0e0e0;border-left:1px solid #e0e0e0;.be-toolbar-item{.ui-rc-btn{font-size:12px;}.toolbar-dropdown-button{font-size:12px;.ui-rc-btn.ui-rc-btn-default.ui-rc-btn-variant-outlined.ui-rc-btn-compact-item.ui-rc-btn-compact-first-item{border-color:#28c76f;}.ui-rc-btn.ui-rc-btn-default.ui-rc-btn-variant-outlined.ui-rc-btn-compact-item.ui-rc-btn-compact-last-item{border-color:#28c76f;.ui-rc-btn-icon{color:#28c76f;}}}}}.ui-rc-toolbar-bottom_border-bottom{border-bottom:1px solid #e0e0e0;}.ui-rc-toolbar-bottom{position:relative;padding:.15rem 0.5rem;background-color:#ffffff;.toolbar-button{border-radius:3px;}.ui-rc-btn{border-radius:3px;height:28px;&.ui-rc-btn-compact-item.ui-rc-btn-compact-last-item{border-start-start-radius:0;border-end-start-radius:0;}&.ui-rc-btn-compact-item.ui-rc-btn-compact-first-item{border-start-end-radius:0;border-end-end-radius:0;}}}}"], props => props.$prefix, color, fontSize, BgColor, fontFamily, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => `${props.$theme.backgroundColor ? props.$theme.backgroundColor : BgColor}`, props => `${props.$theme.color ? props.$theme.color : color}`, props => props.$prefix, props => props.$prefix, tableBorderColor, tableBorderColor, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => `${props.$theme.backgroundColor ? props.$theme.backgroundColor : BgColor}`, fwHeader, props => props.$prefix, props => `${props.$theme.color ? props.$theme.color : color}`, tableBorderColor, tableBorderColor, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, fwBody, props => `${props.$theme.backgroundColor ? props.$theme.backgroundColor : BgColor}`, props => `${props.$theme.color ? props.$theme.color : color}`, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, tableBorderColor, tableBorderColor, props => props.$prefix, tableBorderColor, props => props.$prefix, BgColorDark, colorDark, props => props.$prefix, tableBorderColorDark, tableBorderColorDark);
51
+ })(["&.", "-grid{color:", ";font-size:", ";background-color:", ";font-family:", ";&.", "-grid-editable{.", "-grid-container{.", "-grid-tbody{.", "-grid-row{background-color:", ";color:", ";&.", "-grid-row-parent{background-color:#ffffff;font-weight:500;}}}}}table{table-layout:fixed;border-collapse:separate;border-spacing:0;}.", "-grid-container{border:1px solid ", ";border-right:0;&::after{position:absolute;top:0px;right:0;z-index:1;height:100%;border-right:1px solid ", ";content:'';pointer-events:none;}.", "-grid-cell{padding:5px 8px;&.", "-grid-cell-text-center{text-align:center;justify-content:center;}&.", "-grid-cell-text-right{justify-content:flex-end;text-align:right;}&.", "-grid-cell-ellipsis{.ui-rc_cell-content{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;word-break:keep-all;&.select-cell{padding-right:18px;position:relative;}.caret-down{float:right;position:absolute;right:0;&::before{content:'';display:inline-block;margin-left:4px;vertical-align:middle;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:5px solid #6f7777;}}}}&.", "-grid-cell-wrap{white-space:normal;text-overflow:ellipsis;word-break:break-word;}.", "-grid-header-text-wrap{white-space:normal;overflow:hidden;text-overflow:ellipsis;word-break:break-word;}}.", "-grid-thead{background-color:", ";font-weight:", ";.", "-grid-cell{font-weight:inherit;color:", ";background-color:inherit;border-inline-end:1px solid ", ";border-bottom:1px solid ", ";&.ui-rc-grid-cell-ellipsis{.ui-rc-table-column-title,.", "-grid-cell-ellipsis{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;word-break:keep-all;}}&.ui-rc-grid-cell-wrap{.ui-rc-table-column-title,.", "-grid-cell-text-wrap{white-space:normal;word-break:break-word;overflow:hidden;}}&:hover{.ui-rc-header-trigger{.ui-rc-table-column-sorter-cancel{opacity:1;}}}.", "-grid-filter-column{display:flex;justify-content:space-between;width:100%;align-items:center;position:relative;z-index:3;}.ui-rc-header-trigger{padding-left:6px;display:flex;align-items:center;.ui-rc-table-column-sorter-cancel{opacity:0;}}.resizer{cursor:col-resize;height:100%;position:absolute;right:0;top:0;z-index:3;touch-action:none;user-select:none;width:5px;}.resizer.isResizing{opacity:1;}}}.", "-grid-tbody{.", "-grid-row{font-weight:", ";background-color:", ";color:", ";&.", "-grid-row-odd{background-color:#f9f8fd;}&.", "-grid-row-even{}&.", "-grid-row-parent{background-color:#f5f5f5;font-weight:500;}}}.", "-grid-tfoot{.", "-grid-footer-row{border-bottom-width:1px;border-bottom-color:", ";border-bottom-style:solid;border-top-width:1px;border-top-color:", ";border-top-style:solid;background-color:#fafafa;}.", "-grid-cell{background-color:inherit;border-inline-end:1px solid ", ";}}}&.", "-grid-dark{background-color:", ";color:", ";.", "-grid-container{border-color:", ";&::after{border-right-color:", ";}}}.ui-rc-toolbar-bottom{border-right:1px solid #e0e0e0;border-left:1px solid #e0e0e0;.be-toolbar-item{.ui-rc-btn{font-size:12px;line-height:1.5}.toolbar-dropdown-button{font-size:12px;.ui-rc-btn.ui-rc-btn-default.ui-rc-btn-variant-outlined.ui-rc-btn-compact-item.ui-rc-btn-compact-first-item{border-color:#28c76f;}.ui-rc-btn.ui-rc-btn-default.ui-rc-btn-variant-outlined.ui-rc-btn-compact-item.ui-rc-btn-compact-last-item{border-color:#28c76f;.ui-rc-btn-icon{color:#28c76f;}}}}}.ui-rc-toolbar-bottom_border-bottom{border-bottom:1px solid #e0e0e0;}.ui-rc-toolbar-bottom{position:relative;padding:.15rem 0.5rem;background-color:#ffffff;.toolbar-button{border-radius:3px;}.ui-rc-btn{border-radius:3px;height:28px;&.ui-rc-btn-compact-item.ui-rc-btn-compact-last-item{border-start-start-radius:0;border-end-start-radius:0;}&.ui-rc-btn-compact-item.ui-rc-btn-compact-first-item{border-start-end-radius:0;border-end-end-radius:0;}}}}"], props => props.$prefix, color, fontSize, BgColor, fontFamily, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => `${props.$theme.backgroundColor ? props.$theme.backgroundColor : BgColor}`, props => `${props.$theme.color ? props.$theme.color : color}`, props => props.$prefix, props => props.$prefix, tableBorderColor, tableBorderColor, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => `${props.$theme.backgroundColor ? props.$theme.backgroundColor : BgColor}`, fwHeader, props => props.$prefix, props => `${props.$theme.color ? props.$theme.color : color}`, tableBorderColor, tableBorderColor, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, fwBody, props => `${props.$theme.backgroundColor ? props.$theme.backgroundColor : BgColor}`, props => `${props.$theme.color ? props.$theme.color : color}`, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, props => props.$prefix, tableBorderColor, tableBorderColor, props => props.$prefix, tableBorderColor, props => props.$prefix, BgColorDark, colorDark, props => props.$prefix, tableBorderColorDark, tableBorderColorDark);
@@ -1195,4 +1195,10 @@ $cell-index-focus-bg-Dark: #E6EFFD !default;
1195
1195
  .ui-rc-toolbar-bottom_border-bottom {
1196
1196
  border-bottom-color: $tableBorderColorDark;
1197
1197
  }
1198
+ }
1199
+
1200
+ .ui-rc-checkbox {
1201
+ &:has(input:focus) span {
1202
+ border-color: red;
1203
+ }
1198
1204
  }
@@ -1,5 +1,5 @@
1
- import { TreeDataNode } from "antd";
2
- import { ColumnTable } from "../../grid-component";
1
+ import type { TreeDataNode } from "antd";
2
+ import type { ColumnTable } from "../../grid-component";
3
3
  export declare function convertColumnsToTreeData(columns: ColumnTable[], groupColumns?: string[], t?: any): TreeDataNode[];
4
4
  export declare function filterColumnsByField(columns: ColumnTable[], fieldList: string[]): ColumnTable[];
5
5
  export declare function filterVisibleColumns(columns: ColumnTable[]): ColumnTable[];
@@ -257,39 +257,6 @@ const TableContainerEdit = props => {
257
257
  const rowsFocus = _react.default.useMemo(() => {
258
258
  return startCell && endCell ? (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId) : [];
259
259
  }, [endCell, startCell, table]);
260
- const copySelectionToClipboard = _react.default.useCallback(() => {
261
- if (!startCell || !endCell) {
262
- return;
263
- }
264
-
265
- // const allRows = table.getRowModel().rows;
266
- const allRows = table.getRowModel().flatRows;
267
- // const allColumns = table.getAllLeafColumns();
268
-
269
- const rowIds = (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId);
270
- const colIds = (0, _utils.getColIdsBetween)(table, startCell.colId, endCell.colId);
271
- const dataToCopy = [];
272
- rowIds.forEach(rowId => {
273
- const row = allRows.find(r => r.id === rowId);
274
- if (!row) return;
275
- const rowData = [];
276
- colIds.forEach(colId => {
277
- const cellll = row.getVisibleCells().find(c => c.column.id === colId);
278
- const value = cellll?.getValue();
279
- rowData.push(value !== undefined ? String(value) : '');
280
- });
281
- dataToCopy.push(rowData);
282
- });
283
-
284
- // Convert to TSV string
285
- const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
286
-
287
- // Copy to clipboard
288
- // navigator.clipboard.writeText(tsv).then(() => {
289
- // });
290
-
291
- copy(tsv).then(() => {}).catch(() => {});
292
- }, [startCell, endCell, table]);
293
260
  const triggerChangeData = _react.default.useCallback((newData, args) => {
294
261
  onDataChange?.(newData, args);
295
262
  }, [onDataChange, dataSource]);
@@ -330,6 +297,55 @@ const TableContainerEdit = props => {
330
297
  });
331
298
  }
332
299
  }, [onCellPaste, originData, triggerChangeData]);
300
+
301
+ // Copy
302
+
303
+ const copySelectionToClipboard = _react.default.useCallback(() => {
304
+ if (!startCell || !endCell) {
305
+ return;
306
+ }
307
+
308
+ // const allRows = table.getRowModel().rows;
309
+ const allRows = table.getRowModel().flatRows;
310
+ // const allColumns = table.getAllLeafColumns();
311
+
312
+ const rowIds = (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId);
313
+ const colIds = (0, _utils.getColIdsBetween)(table, startCell.colId, endCell.colId);
314
+ const dataToCopy = [];
315
+ rowIds.forEach(rowId => {
316
+ const row = allRows.find(r => r.id === rowId);
317
+ if (!row) return;
318
+ const rowData = [];
319
+ colIds.forEach(colId => {
320
+ const cellll = row.getVisibleCells().find(c => c.column.id === colId);
321
+ const value = cellll?.getValue();
322
+ rowData.push(value !== undefined ? String(value) : '');
323
+ });
324
+ dataToCopy.push(rowData);
325
+ });
326
+
327
+ // Convert to TSV string
328
+ const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
329
+
330
+ // Copy to clipboard
331
+ // navigator.clipboard.writeText(tsv).then(() => {
332
+ // });
333
+
334
+ copy(tsv).then(() => {}).catch(() => {});
335
+ }, [startCell, endCell, table]);
336
+ _react.default.useEffect(() => {
337
+ const handleKeyDown = e => {
338
+ if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
339
+ e.preventDefault();
340
+ copySelectionToClipboard();
341
+ }
342
+ };
343
+ document.addEventListener('keydown', handleKeyDown);
344
+ return () => document.removeEventListener('keydown', handleKeyDown);
345
+ }, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
346
+
347
+ // Paste
348
+
333
349
  const handlePasted = _react.default.useCallback(pasteData => {
334
350
  if (!startCell) {
335
351
  return;
@@ -337,7 +353,8 @@ const TableContainerEdit = props => {
337
353
  const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
338
354
 
339
355
  // const allRows = table.getRowModel().rows;
340
- const allRows = table.getRowModel().flatRows;
356
+ const flatRows = table.getRowModel().flatRows;
357
+ const allRows = flatRows.filter((item, index, self) => index === self.findIndex(x => x.id === item.id));
341
358
  const allCols = table.getVisibleLeafColumns();
342
359
  const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
343
360
  const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
@@ -361,7 +378,7 @@ const TableContainerEdit = props => {
361
378
  const targetRow = startRow + rowIndex;
362
379
 
363
380
  // Nếu vượt quá số dòng hiện có, thêm dòng mới
364
- if (targetRow >= newData.length) {
381
+ if (targetRow > newData.length) {
365
382
  const newID = (0, _utils.newGuid)();
366
383
  const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
367
384
  newData.push(defaultValue ? {
@@ -417,11 +434,14 @@ const TableContainerEdit = props => {
417
434
  }
418
435
  } else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
419
436
  const isDate = (0, _utils.isDateValue)(cellValue.trim());
420
- const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format;
421
- const cellFormat = (0, _utils.getFormat)(colFormat, format);
422
- const editType = (0, _utils.getEditType)(columnOri);
423
- const dateFormat = (0, _utils.getDatepickerFormat)(editType, cellFormat);
424
- const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim(), dateFormat).format("YYYY-MM-DDTHH:mm:ssZ") : null;
437
+
438
+ // const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format
439
+ // const cellFormat = getFormat(colFormat, format)
440
+ // const editType = getEditType(columnOri as any)
441
+ // const dateFormat = getDatepickerFormat(editType, cellFormat)
442
+ // const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim(), dateFormat, true).format() : null
443
+
444
+ const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim()).format() : null;
425
445
  newData[targetRow] = {
426
446
  ...newData[targetRow],
427
447
  [columnKey]: date
@@ -522,11 +542,17 @@ const TableContainerEdit = props => {
522
542
  }
523
543
  } else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
524
544
  const isDate = (0, _utils.isDateValue)(cellValue.trim());
525
- const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format;
526
- const cellFormat = (0, _utils.getFormat)(colFormat, format);
527
- const editType = (0, _utils.getEditType)(columnOri);
528
- const dateFormat = (0, _utils.getDatepickerFormat)(editType, cellFormat);
529
- const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim(), dateFormat).format("YYYY-MM-DDTHH:mm:ssZ") : null;
545
+
546
+ // const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format
547
+ // const cellFormat = getFormat(colFormat, format)
548
+
549
+ // const editType = getEditType(columnOri as any)
550
+
551
+ // const dateFormat = getDatepickerFormat(editType, cellFormat)
552
+
553
+ // const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim(), dateFormat).format("YYYY-MM-DDTHH:mm:ssZ") : null
554
+
555
+ const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim()).format() : null;
530
556
  childData[targetRow] = {
531
557
  ...childData[targetRow],
532
558
  [columnKey]: date
@@ -601,16 +627,6 @@ const TableContainerEdit = props => {
601
627
  handlePasted(rowsPasted);
602
628
  }
603
629
  }, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
604
- _react.default.useEffect(() => {
605
- const handleKeyDown = e => {
606
- if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
607
- e.preventDefault();
608
- copySelectionToClipboard();
609
- }
610
- };
611
- document.addEventListener('keydown', handleKeyDown);
612
- return () => document.removeEventListener('keydown', handleKeyDown);
613
- }, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
614
630
  _react.default.useEffect(() => {
615
631
  const handlePaste = e => {
616
632
  if (startCell && !editingKey) {
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import type { EditType } from "rc-master-ui";
3
3
  import type { ColumnTable, IFormat } from "../../grid-component/type";
4
+ import type { Column } from "@tanstack/react-table";
4
5
  interface EditableCellProps<DataType> extends React.HTMLAttributes<HTMLElement> {
5
6
  t?: any;
6
7
  dataIndex: string;
@@ -11,6 +12,8 @@ interface EditableCellProps<DataType> extends React.HTMLAttributes<HTMLElement>
11
12
  indexRow: number;
12
13
  indexCol: number;
13
14
  cellEditing?: any;
15
+ visibleColumns?: Column<DataType>[];
16
+ handleNextCell?: () => void;
14
17
  }
15
18
  declare const EditableCell: <T>(props: EditableCellProps<T>) => JSX.Element;
16
19
  export default EditableCell;
@@ -51,7 +51,9 @@ const EditableCell = props => {
51
51
  // children,
52
52
  column,
53
53
  indexRow,
54
- indexCol
54
+ indexCol,
55
+ // visibleColumns,
56
+ handleNextCell
55
57
  // cellEditing,
56
58
  // ...restProps
57
59
  } = props;
@@ -69,8 +71,7 @@ const EditableCell = props => {
69
71
  } = (0, _react.useContext)(_useContext.TableContext);
70
72
  const datePickerRef = _react.default.useRef(null);
71
73
  const dateTimePickerRef = _react.default.useRef(null);
72
- // const timePickerRef = React.useRef(null);
73
-
74
+ const timePickerRef = _react.default.useRef(null);
74
75
  const colFormat = typeof column?.format === 'function' ? column?.format(record) : column?.format;
75
76
  const cellFormat = (0, _utils.getFormat)(colFormat, format);
76
77
  const inputNode = (value, onChange) => {
@@ -107,7 +108,24 @@ const EditableCell = props => {
107
108
  const options = validateOption ? validateOption(record, column.field) : selectOptions ?? [];
108
109
  const optionsTree = validateOption ? (0, _utils.convertArrayWithIndent)(validateOption(record, column.field)) : selectOptions ? (0, _utils.convertArrayWithIndent)(selectOptions) : [];
109
110
 
110
- // const currt = flatColumns2()
111
+ // const focusToken = (token: FormatToken, fmt: string) => {
112
+ // const input: HTMLInputElement | null =
113
+ // timePickerRef.current?.nativeElement?.querySelector('input') ??
114
+ // timePickerRef.current?.input;
115
+
116
+ // if (!input) return;
117
+
118
+ // const start = fmt.indexOf(token);
119
+ // if (start === -1) return;
120
+
121
+ // input.focus();
122
+
123
+ // input.setSelectionRange(start, start + token.length - 1);
124
+
125
+ // requestAnimationFrame(() => {
126
+ // input.setSelectionRange(start, start + token.length);
127
+ // });
128
+ // };
111
129
 
112
130
  switch (editType) {
113
131
  case 'date':
@@ -332,6 +350,7 @@ const EditableCell = props => {
332
350
  const maxTime = maxTimeValue ? (0, _dayjs.default)(maxTimeValue, timeFormat) : undefined;
333
351
  const minTime = minTimeValue ? (0, _dayjs.default)(minTimeValue, timeFormat) : undefined;
334
352
  return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TimePicker, {
353
+ ref: timePickerRef,
335
354
  format: {
336
355
  format: timeFormat,
337
356
  type: 'mask'
@@ -352,8 +371,79 @@ const EditableCell = props => {
352
371
  "data-tooltip-content": message,
353
372
  "data-tooltip-id": `${id}-tooltip-error`,
354
373
  autoFocus: column.field === startCell?.colId,
355
- defaultOpen: column.field === startCell?.colId,
356
- onChange: (newDate, dateString) => {
374
+ defaultOpen: column.field === startCell?.colId
375
+
376
+ // onChange={(newDate, dateString) => {
377
+
378
+ // if (typeTime === 'time') {
379
+
380
+ // onChange(dateString)
381
+
382
+ // } else {
383
+
384
+ // // const datetime = dayjs(dateString as string, timeFormat, true);
385
+
386
+ // const newVal = newDate ? moment(newDate.toDate()).format() : undefined
387
+
388
+ // // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
389
+ // onChange(newVal)
390
+
391
+ // }
392
+
393
+ // setTimeout(() => {
394
+ // // @ts-ignore
395
+ // dateTimePickerRef.current?.focus()
396
+ // }, 0)
397
+
398
+ // }}
399
+
400
+ // onBlur={() => {
401
+ // const formState = getValues()
402
+ // const itemState = getValues(dataIndex)
403
+ // // @ts-ignore
404
+ // const prevState = record[dataIndex]
405
+ // const newState = itemState
406
+
407
+ // let newValue = newState
408
+
409
+ // if (typeTime === 'time') {
410
+
411
+ // newValue = newState
412
+
413
+ // } else {
414
+
415
+ // const datetime = dayjs(newState as string, timeFormat, true);
416
+
417
+ // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : undefined
418
+ // onChange(newVal)
419
+
420
+ // newValue = newVal
421
+
422
+ // }
423
+
424
+ // if (prevState !== newState) {
425
+ // handleCellChange?.({
426
+ // key: key as any,
427
+ // field: column.field ?? column.field as any,
428
+ // record: formState,
429
+ // prevState,
430
+ // newState: newValue,
431
+ // option: newValue,
432
+ // indexCol,
433
+ // indexRow,
434
+ // type: 'blur'
435
+ // })
436
+ // }
437
+ // }}
438
+
439
+ // needConfirm={false}
440
+ ,
441
+
442
+ onCalendarChange: (newDate, dateString) => {
443
+ // const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
444
+
445
+ // onChange(newDateValue)
446
+
357
447
  if (typeTime === 'time') {
358
448
  onChange(dateString);
359
449
  } else {
@@ -366,38 +456,34 @@ const EditableCell = props => {
366
456
  }
367
457
  setTimeout(() => {
368
458
  // @ts-ignore
369
- dateTimePickerRef.current?.focus();
370
- }, 0);
459
+ timePickerRef.current?.focus();
460
+ });
371
461
  },
372
- onBlur: () => {
373
- console.log('22222222222');
374
- const formState = getValues();
375
- const itemState = getValues(dataIndex);
376
- // @ts-ignore
377
- const prevState = record[dataIndex];
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() : undefined;
385
- onChange(newVal);
386
- newValue = newVal;
462
+ onOpenChange: open => {
463
+ if (!open) {
464
+ const formState = getValues();
465
+ const itemState = getValues(dataIndex);
466
+ // @ts-ignore
467
+ const prevState = record[dataIndex];
468
+ const newState = itemState;
469
+ if (prevState !== newState) {
470
+ handleCellChange?.({
471
+ key: key,
472
+ field: column.field ?? column.field,
473
+ record: formState,
474
+ prevState,
475
+ newState,
476
+ option: newState,
477
+ indexCol,
478
+ indexRow,
479
+ type: 'blur'
480
+ });
481
+ }
387
482
  }
388
- console.log('newValue', newValue);
389
- if (prevState !== newState) {
390
- handleCellChange?.({
391
- key: key,
392
- field: column.field ?? column.field,
393
- record: formState,
394
- prevState,
395
- newState: newValue,
396
- option: newValue,
397
- indexCol,
398
- indexRow,
399
- type: 'blur'
400
- });
483
+ },
484
+ onKeyDown: e => {
485
+ if (e?.code === "Tab") {
486
+ handleNextCell?.();
401
487
  }
402
488
  }
403
489
  });
@@ -239,6 +239,7 @@ const TableBodyCellEdit = props => {
239
239
  format
240
240
  } = _react.default.useContext(_useContext.TableContext);
241
241
  const expandIconColumnIndex = expandable?.expandIconColumnIndex;
242
+ const visibleColumns = table.getVisibleLeafColumns();
242
243
  const record = cell.row.original;
243
244
  const columnMeta = cell.column.columnDef.meta ?? {};
244
245
  const [isOpenTooltip, setIsOpenTooltip] = _react.default.useState(false);
@@ -316,7 +317,9 @@ const TableBodyCellEdit = props => {
316
317
  }
317
318
  }, [cell, columnMeta, isOpenTooltip, record, valueCellString]);
318
319
  const triggerDragPaste = (pasteState, ctrlKey) => {
319
- const tmpCols = table.getVisibleLeafColumns();
320
+ const tmpCols = {
321
+ ...visibleColumns
322
+ };
320
323
  const rowPasteIds = (0, _utils.getRowIdsBetween)(table, startPasteCell?.rowId ?? '', endPasteCell?.rowId ?? '');
321
324
  const colPasteds = (0, _utils.getColIdsBetween)(table, startPasteCell?.colId ?? '', endPasteCell?.colId ?? '');
322
325
  const rowSelectIds = (0, _utils.getRowIdsBetween)(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
@@ -390,7 +393,9 @@ const TableBodyCellEdit = props => {
390
393
  setRangePasteState?.(undefined);
391
394
  };
392
395
  const triggerPointPaste = (pasteState, cellStart, cellEnd, ctrlKey) => {
393
- const tmpCols = table.getVisibleLeafColumns();
396
+ const tmpCols = {
397
+ ...visibleColumns
398
+ };
394
399
  const rowPasteIds = (0, _utils.getRowIdsBetween)(table, cellStart?.rowId ?? '', cellEnd?.rowId ?? '');
395
400
  const colPasteds = (0, _utils.getColIdsBetween)(table, cellStart?.colId ?? '', cellEnd?.colId ?? '');
396
401
  const rowSelectIds = (0, _utils.getRowIdsBetween)(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
@@ -591,7 +596,9 @@ const TableBodyCellEdit = props => {
591
596
  function handleKeyDown(e, rowId, colId) {
592
597
  if (e.key === 'Tab') {
593
598
  e.preventDefault();
594
- const allCols = table.getVisibleLeafColumns();
599
+ const allCols = {
600
+ ...visibleColumns
601
+ };
595
602
  const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
596
603
  const nextCol = allCols[currentColIndex + 1];
597
604
  if (nextCol) {
@@ -655,7 +662,7 @@ const TableBodyCellEdit = props => {
655
662
  if (e.key === 'ArrowRight') {
656
663
  e.preventDefault();
657
664
  e.stopPropagation();
658
- const allCols = table.getVisibleLeafColumns().filter(it => !_hooks.nonActionColumn.includes(it.id));
665
+ const allCols = visibleColumns.filter(it => !_hooks.nonActionColumn.includes(it.id));
659
666
  const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
660
667
  const nextCol = allCols[currentColIndex + 1];
661
668
  if (nextCol) {
@@ -686,7 +693,7 @@ const TableBodyCellEdit = props => {
686
693
  }
687
694
  if (e.key === 'ArrowLeft') {
688
695
  e.preventDefault();
689
- const allCols = table.getVisibleLeafColumns().filter(it => !_hooks.nonActionColumn.includes(it.id));
696
+ const allCols = visibleColumns.filter(it => !_hooks.nonActionColumn.includes(it.id));
690
697
 
691
698
  // const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
692
699
  const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
@@ -834,7 +841,7 @@ const TableBodyCellEdit = props => {
834
841
  }
835
842
  const handleMouseDownIndex = rowId => {
836
843
  setIsSelecting?.(true);
837
- const allColumns = table.getVisibleLeafColumns().filter(it => !_hooks.nonActionColumn.includes(it.id));
844
+ const allColumns = visibleColumns.filter(it => !_hooks.nonActionColumn.includes(it.id));
838
845
  const firstCOlSpin = (0, _utils.findFirst)(allColumns);
839
846
  const startCol = allColumns[0].id;
840
847
  const endCol = allColumns[allColumns.length - 1].id;
@@ -868,7 +875,7 @@ const TableBodyCellEdit = props => {
868
875
  };
869
876
  const handleMouseEnterIndex = rowId => {
870
877
  if (isSelecting) {
871
- const allColumns = table.getVisibleLeafColumns().filter(it => !_hooks.nonActionColumn.includes(it.id));
878
+ const allColumns = visibleColumns.filter(it => !_hooks.nonActionColumn.includes(it.id));
872
879
 
873
880
  // const firstCOl = findFirst(allColumns)
874
881
 
@@ -1118,6 +1125,58 @@ const TableBodyCellEdit = props => {
1118
1125
  }, 100);
1119
1126
  }
1120
1127
  };
1128
+ const handleNextCell = () => {
1129
+ const allCols = visibleColumns;
1130
+
1131
+ // const colId = cell.column.id
1132
+ const rowId = cell.row.id;
1133
+
1134
+ // const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
1135
+ // const currentColIndex = indexCol;
1136
+
1137
+ const isNextCol = allCols[colIndex + 1];
1138
+ const nextCol = (0, _utils.getNextEditableColumn)(visibleColumns, colIndex, record);
1139
+ if (isNextCol && nextCol) {
1140
+ setFocusedCell?.({
1141
+ rowId,
1142
+ colId: nextCol.id
1143
+ });
1144
+ setStartCell?.({
1145
+ rowId,
1146
+ colId: nextCol.id
1147
+ });
1148
+ setEndCell?.({
1149
+ rowId,
1150
+ colId: nextCol.id
1151
+ });
1152
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
1153
+ rowId,
1154
+ colId: nextCol.id
1155
+ }, {
1156
+ rowId,
1157
+ colId: nextCol.id
1158
+ }));
1159
+ columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
1160
+ align: 'center'
1161
+ });
1162
+ const nextItem = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${rowId}"].cell-editing[data-col-key="${nextCol.id}"] input`);
1163
+
1164
+ // const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] input`) as HTMLInputElement
1165
+ // const textarea = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowNumber}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] textarea`) as any
1166
+
1167
+ const textarea = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${rowId}"].cell-editing[data-col-key="${nextCol.id}"] textarea`);
1168
+ setTimeout(() => {
1169
+ if (textarea) {
1170
+ textarea.focus();
1171
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
1172
+ return;
1173
+ }
1174
+ if (nextItem) {
1175
+ nextItem.focus();
1176
+ }
1177
+ });
1178
+ }
1179
+ };
1121
1180
  const cellValue = cell.getValue();
1122
1181
  const rowIndex = cell.row.index;
1123
1182
  const colFormat = typeof columnMeta?.format === 'function' ? columnMeta?.format(record) : columnMeta?.format;
@@ -1253,7 +1312,9 @@ const TableBodyCellEdit = props => {
1253
1312
  editType: (0, _utils.getEditType)(cell.column.columnDef.meta, record),
1254
1313
  indexCol: cell.column.getIndex(),
1255
1314
  indexRow: cell.row.index,
1256
- record: record
1315
+ record: record,
1316
+ visibleColumns: visibleColumns,
1317
+ handleNextCell: handleNextCell
1257
1318
  // rowKey={rowKey}
1258
1319
  }) : /*#__PURE__*/_react.default.createElement("div", {
1259
1320
  className: (0, _classnames.default)('ui-rc_cell-content', {
@@ -48,9 +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
- const timeFormat = format?.timeFormat ?? 'HH:mm';
51
+ const timeFormat = format?.timeFormat;
52
+ console.log('timeFormat', timeFormat);
52
53
  const abc = (0, _utils.convertToDate)(value, timeFormat);
53
- const timeValue = value ? (0, _dayjs.default)(abc).format(timeFormat) : '';
54
+ const timeValue = value ? (0, _dayjs.default)(abc).format(timeFormat ?? 'HH:mm') : '';
54
55
  return timeValue ?? '';
55
56
  case 'year':
56
57
  const year = value ? (0, _moment.default)(value).format('yyyy') : '';