es-grid-template 1.9.50 → 1.9.51
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/group-component/hook/utils.d.ts +3 -3
- package/es/table-component/TableContainerEdit.js +12 -5
- package/es/table-component/body/EditableCell.d.ts +3 -0
- package/es/table-component/body/EditableCell.js +122 -36
- package/es/table-component/body/TableBodyCellEdit.js +70 -9
- package/es/table-component/hook/useColumns.js +2 -2
- package/es/table-component/hook/utils.d.ts +3 -0
- package/es/table-component/hook/utils.js +32 -1
- package/es/table-component/style.scss +6 -0
- package/lib/table-component/TableContainerEdit.js +12 -5
- package/lib/table-component/body/EditableCell.d.ts +3 -0
- package/lib/table-component/body/EditableCell.js +122 -36
- package/lib/table-component/body/TableBodyCellEdit.js +69 -8
- package/lib/table-component/hook/useColumns.js +2 -2
- package/lib/table-component/hook/utils.d.ts +3 -0
- package/lib/table-component/hook/utils.js +37 -4
- package/lib/table-component/style.scss +6 -0
- package/package.json +1 -1
|
@@ -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, "left" | "right" | "
|
|
198
|
-
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
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, "left" | "right" | "
|
|
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;
|
|
@@ -416,11 +416,14 @@ const TableContainerEdit = props => {
|
|
|
416
416
|
}
|
|
417
417
|
} else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
|
|
418
418
|
const isDate = isDateValue(cellValue.trim());
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
const
|
|
419
|
+
|
|
420
|
+
// const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format
|
|
421
|
+
// const cellFormat = getFormat(colFormat, format)
|
|
422
|
+
// const editType = getEditType(columnOri as any)
|
|
423
|
+
// const dateFormat = getDatepickerFormat(editType, cellFormat)
|
|
424
|
+
// const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim(), dateFormat, true).format() : null
|
|
425
|
+
|
|
426
|
+
const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim()).format() : null;
|
|
424
427
|
newData[targetRow] = {
|
|
425
428
|
...newData[targetRow],
|
|
426
429
|
[columnKey]: date
|
|
@@ -600,6 +603,8 @@ const TableContainerEdit = props => {
|
|
|
600
603
|
handlePasted(rowsPasted);
|
|
601
604
|
}
|
|
602
605
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
606
|
+
|
|
607
|
+
// Copy
|
|
603
608
|
React.useEffect(() => {
|
|
604
609
|
const handleKeyDown = e => {
|
|
605
610
|
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
@@ -610,6 +615,8 @@ const TableContainerEdit = props => {
|
|
|
610
615
|
document.addEventListener('keydown', handleKeyDown);
|
|
611
616
|
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
612
617
|
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
618
|
+
|
|
619
|
+
// Paste
|
|
613
620
|
React.useEffect(() => {
|
|
614
621
|
const handlePaste = e => {
|
|
615
622
|
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;
|
|
@@ -43,7 +43,9 @@ const EditableCell = props => {
|
|
|
43
43
|
// children,
|
|
44
44
|
column,
|
|
45
45
|
indexRow,
|
|
46
|
-
indexCol
|
|
46
|
+
indexCol,
|
|
47
|
+
// visibleColumns,
|
|
48
|
+
handleNextCell
|
|
47
49
|
// cellEditing,
|
|
48
50
|
// ...restProps
|
|
49
51
|
} = props;
|
|
@@ -61,8 +63,7 @@ const EditableCell = props => {
|
|
|
61
63
|
} = useContext(TableContext);
|
|
62
64
|
const datePickerRef = React.useRef(null);
|
|
63
65
|
const dateTimePickerRef = React.useRef(null);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const timePickerRef = React.useRef(null);
|
|
66
67
|
const colFormat = typeof column?.format === 'function' ? column?.format(record) : column?.format;
|
|
67
68
|
const cellFormat = getFormat(colFormat, format);
|
|
68
69
|
const inputNode = (value, onChange) => {
|
|
@@ -99,7 +100,24 @@ const EditableCell = props => {
|
|
|
99
100
|
const options = validateOption ? validateOption(record, column.field) : selectOptions ?? [];
|
|
100
101
|
const optionsTree = validateOption ? convertArrayWithIndent(validateOption(record, column.field)) : selectOptions ? convertArrayWithIndent(selectOptions) : [];
|
|
101
102
|
|
|
102
|
-
// const
|
|
103
|
+
// const focusToken = (token: FormatToken, fmt: string) => {
|
|
104
|
+
// const input: HTMLInputElement | null =
|
|
105
|
+
// timePickerRef.current?.nativeElement?.querySelector('input') ??
|
|
106
|
+
// timePickerRef.current?.input;
|
|
107
|
+
|
|
108
|
+
// if (!input) return;
|
|
109
|
+
|
|
110
|
+
// const start = fmt.indexOf(token);
|
|
111
|
+
// if (start === -1) return;
|
|
112
|
+
|
|
113
|
+
// input.focus();
|
|
114
|
+
|
|
115
|
+
// input.setSelectionRange(start, start + token.length - 1);
|
|
116
|
+
|
|
117
|
+
// requestAnimationFrame(() => {
|
|
118
|
+
// input.setSelectionRange(start, start + token.length);
|
|
119
|
+
// });
|
|
120
|
+
// };
|
|
103
121
|
|
|
104
122
|
switch (editType) {
|
|
105
123
|
case 'date':
|
|
@@ -324,6 +342,7 @@ const EditableCell = props => {
|
|
|
324
342
|
const maxTime = maxTimeValue ? dayjs(maxTimeValue, timeFormat) : undefined;
|
|
325
343
|
const minTime = minTimeValue ? dayjs(minTimeValue, timeFormat) : undefined;
|
|
326
344
|
return /*#__PURE__*/React.createElement(TimePicker, {
|
|
345
|
+
ref: timePickerRef,
|
|
327
346
|
format: {
|
|
328
347
|
format: timeFormat,
|
|
329
348
|
type: 'mask'
|
|
@@ -344,8 +363,79 @@ const EditableCell = props => {
|
|
|
344
363
|
"data-tooltip-content": message,
|
|
345
364
|
"data-tooltip-id": `${id}-tooltip-error`,
|
|
346
365
|
autoFocus: column.field === startCell?.colId,
|
|
347
|
-
defaultOpen: column.field === startCell?.colId
|
|
348
|
-
|
|
366
|
+
defaultOpen: column.field === startCell?.colId
|
|
367
|
+
|
|
368
|
+
// onChange={(newDate, dateString) => {
|
|
369
|
+
|
|
370
|
+
// if (typeTime === 'time') {
|
|
371
|
+
|
|
372
|
+
// onChange(dateString)
|
|
373
|
+
|
|
374
|
+
// } else {
|
|
375
|
+
|
|
376
|
+
// // const datetime = dayjs(dateString as string, timeFormat, true);
|
|
377
|
+
|
|
378
|
+
// const newVal = newDate ? moment(newDate.toDate()).format() : undefined
|
|
379
|
+
|
|
380
|
+
// // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
|
|
381
|
+
// onChange(newVal)
|
|
382
|
+
|
|
383
|
+
// }
|
|
384
|
+
|
|
385
|
+
// setTimeout(() => {
|
|
386
|
+
// // @ts-ignore
|
|
387
|
+
// dateTimePickerRef.current?.focus()
|
|
388
|
+
// }, 0)
|
|
389
|
+
|
|
390
|
+
// }}
|
|
391
|
+
|
|
392
|
+
// onBlur={() => {
|
|
393
|
+
// const formState = getValues()
|
|
394
|
+
// const itemState = getValues(dataIndex)
|
|
395
|
+
// // @ts-ignore
|
|
396
|
+
// const prevState = record[dataIndex]
|
|
397
|
+
// const newState = itemState
|
|
398
|
+
|
|
399
|
+
// let newValue = newState
|
|
400
|
+
|
|
401
|
+
// if (typeTime === 'time') {
|
|
402
|
+
|
|
403
|
+
// newValue = newState
|
|
404
|
+
|
|
405
|
+
// } else {
|
|
406
|
+
|
|
407
|
+
// const datetime = dayjs(newState as string, timeFormat, true);
|
|
408
|
+
|
|
409
|
+
// const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : undefined
|
|
410
|
+
// onChange(newVal)
|
|
411
|
+
|
|
412
|
+
// newValue = newVal
|
|
413
|
+
|
|
414
|
+
// }
|
|
415
|
+
|
|
416
|
+
// if (prevState !== newState) {
|
|
417
|
+
// handleCellChange?.({
|
|
418
|
+
// key: key as any,
|
|
419
|
+
// field: column.field ?? column.field as any,
|
|
420
|
+
// record: formState,
|
|
421
|
+
// prevState,
|
|
422
|
+
// newState: newValue,
|
|
423
|
+
// option: newValue,
|
|
424
|
+
// indexCol,
|
|
425
|
+
// indexRow,
|
|
426
|
+
// type: 'blur'
|
|
427
|
+
// })
|
|
428
|
+
// }
|
|
429
|
+
// }}
|
|
430
|
+
|
|
431
|
+
// needConfirm={false}
|
|
432
|
+
,
|
|
433
|
+
|
|
434
|
+
onCalendarChange: (newDate, dateString) => {
|
|
435
|
+
// const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
|
|
436
|
+
|
|
437
|
+
// onChange(newDateValue)
|
|
438
|
+
|
|
349
439
|
if (typeTime === 'time') {
|
|
350
440
|
onChange(dateString);
|
|
351
441
|
} else {
|
|
@@ -358,38 +448,34 @@ const EditableCell = props => {
|
|
|
358
448
|
}
|
|
359
449
|
setTimeout(() => {
|
|
360
450
|
// @ts-ignore
|
|
361
|
-
|
|
362
|
-
}
|
|
451
|
+
timePickerRef.current?.focus();
|
|
452
|
+
});
|
|
363
453
|
},
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
454
|
+
onOpenChange: open => {
|
|
455
|
+
if (!open) {
|
|
456
|
+
const formState = getValues();
|
|
457
|
+
const itemState = getValues(dataIndex);
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
const prevState = record[dataIndex];
|
|
460
|
+
const newState = itemState;
|
|
461
|
+
if (prevState !== newState) {
|
|
462
|
+
handleCellChange?.({
|
|
463
|
+
key: key,
|
|
464
|
+
field: column.field ?? column.field,
|
|
465
|
+
record: formState,
|
|
466
|
+
prevState,
|
|
467
|
+
newState,
|
|
468
|
+
option: newState,
|
|
469
|
+
indexCol,
|
|
470
|
+
indexRow,
|
|
471
|
+
type: 'blur'
|
|
472
|
+
});
|
|
473
|
+
}
|
|
379
474
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
field: column.field ?? column.field,
|
|
385
|
-
record: formState,
|
|
386
|
-
prevState,
|
|
387
|
-
newState: newValue,
|
|
388
|
-
option: newValue,
|
|
389
|
-
indexCol,
|
|
390
|
-
indexRow,
|
|
391
|
-
type: 'blur'
|
|
392
|
-
});
|
|
475
|
+
},
|
|
476
|
+
onKeyDown: e => {
|
|
477
|
+
if (e?.code === "Tab") {
|
|
478
|
+
handleNextCell?.();
|
|
393
479
|
}
|
|
394
480
|
}
|
|
395
481
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Space from "rc-master-ui/es/space";
|
|
2
2
|
import Command from "../components/command/Command";
|
|
3
|
-
import { addRowsDown, addRowsDownWithCtrl, addRowsUp, addRowsUpWithCtrl, findFirst, flattenArray, flattenData, getColIdsBetween, getCommonPinningStyles, getEditType, getFormat, getRowIdsBetween, getSelectedCellMatrix, isEditable, isObjEmpty, isObjEqual, newGuid, unFlattenData, updateOrInsert } from "../hook/utils";
|
|
3
|
+
import { addRowsDown, addRowsDownWithCtrl, addRowsUp, addRowsUpWithCtrl, findFirst, flattenArray, flattenData, getColIdsBetween, getCommonPinningStyles, getEditType, getFormat, getNextEditableColumn, getRowIdsBetween, getSelectedCellMatrix, isEditable, isObjEmpty, isObjEqual, newGuid, unFlattenData, updateOrInsert } from "../hook/utils";
|
|
4
4
|
import Checkbox from "rc-master-ui/es/checkbox/Checkbox";
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import React from "react";
|
|
@@ -232,6 +232,7 @@ const TableBodyCellEdit = props => {
|
|
|
232
232
|
format
|
|
233
233
|
} = React.useContext(TableContext);
|
|
234
234
|
const expandIconColumnIndex = expandable?.expandIconColumnIndex;
|
|
235
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
235
236
|
const record = cell.row.original;
|
|
236
237
|
const columnMeta = cell.column.columnDef.meta ?? {};
|
|
237
238
|
const [isOpenTooltip, setIsOpenTooltip] = React.useState(false);
|
|
@@ -309,7 +310,9 @@ const TableBodyCellEdit = props => {
|
|
|
309
310
|
}
|
|
310
311
|
}, [cell, columnMeta, isOpenTooltip, record, valueCellString]);
|
|
311
312
|
const triggerDragPaste = (pasteState, ctrlKey) => {
|
|
312
|
-
const tmpCols =
|
|
313
|
+
const tmpCols = {
|
|
314
|
+
...visibleColumns
|
|
315
|
+
};
|
|
313
316
|
const rowPasteIds = getRowIdsBetween(table, startPasteCell?.rowId ?? '', endPasteCell?.rowId ?? '');
|
|
314
317
|
const colPasteds = getColIdsBetween(table, startPasteCell?.colId ?? '', endPasteCell?.colId ?? '');
|
|
315
318
|
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
@@ -383,7 +386,9 @@ const TableBodyCellEdit = props => {
|
|
|
383
386
|
setRangePasteState?.(undefined);
|
|
384
387
|
};
|
|
385
388
|
const triggerPointPaste = (pasteState, cellStart, cellEnd, ctrlKey) => {
|
|
386
|
-
const tmpCols =
|
|
389
|
+
const tmpCols = {
|
|
390
|
+
...visibleColumns
|
|
391
|
+
};
|
|
387
392
|
const rowPasteIds = getRowIdsBetween(table, cellStart?.rowId ?? '', cellEnd?.rowId ?? '');
|
|
388
393
|
const colPasteds = getColIdsBetween(table, cellStart?.colId ?? '', cellEnd?.colId ?? '');
|
|
389
394
|
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
@@ -584,7 +589,9 @@ const TableBodyCellEdit = props => {
|
|
|
584
589
|
function handleKeyDown(e, rowId, colId) {
|
|
585
590
|
if (e.key === 'Tab') {
|
|
586
591
|
e.preventDefault();
|
|
587
|
-
const allCols =
|
|
592
|
+
const allCols = {
|
|
593
|
+
...visibleColumns
|
|
594
|
+
};
|
|
588
595
|
const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
589
596
|
const nextCol = allCols[currentColIndex + 1];
|
|
590
597
|
if (nextCol) {
|
|
@@ -648,7 +655,7 @@ const TableBodyCellEdit = props => {
|
|
|
648
655
|
if (e.key === 'ArrowRight') {
|
|
649
656
|
e.preventDefault();
|
|
650
657
|
e.stopPropagation();
|
|
651
|
-
const allCols =
|
|
658
|
+
const allCols = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
652
659
|
const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
|
|
653
660
|
const nextCol = allCols[currentColIndex + 1];
|
|
654
661
|
if (nextCol) {
|
|
@@ -679,7 +686,7 @@ const TableBodyCellEdit = props => {
|
|
|
679
686
|
}
|
|
680
687
|
if (e.key === 'ArrowLeft') {
|
|
681
688
|
e.preventDefault();
|
|
682
|
-
const allCols =
|
|
689
|
+
const allCols = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
683
690
|
|
|
684
691
|
// const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
685
692
|
const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
|
|
@@ -827,7 +834,7 @@ const TableBodyCellEdit = props => {
|
|
|
827
834
|
}
|
|
828
835
|
const handleMouseDownIndex = rowId => {
|
|
829
836
|
setIsSelecting?.(true);
|
|
830
|
-
const allColumns =
|
|
837
|
+
const allColumns = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
831
838
|
const firstCOlSpin = findFirst(allColumns);
|
|
832
839
|
const startCol = allColumns[0].id;
|
|
833
840
|
const endCol = allColumns[allColumns.length - 1].id;
|
|
@@ -861,7 +868,7 @@ const TableBodyCellEdit = props => {
|
|
|
861
868
|
};
|
|
862
869
|
const handleMouseEnterIndex = rowId => {
|
|
863
870
|
if (isSelecting) {
|
|
864
|
-
const allColumns =
|
|
871
|
+
const allColumns = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
865
872
|
|
|
866
873
|
// const firstCOl = findFirst(allColumns)
|
|
867
874
|
|
|
@@ -1111,6 +1118,58 @@ const TableBodyCellEdit = props => {
|
|
|
1111
1118
|
}, 100);
|
|
1112
1119
|
}
|
|
1113
1120
|
};
|
|
1121
|
+
const handleNextCell = () => {
|
|
1122
|
+
const allCols = visibleColumns;
|
|
1123
|
+
|
|
1124
|
+
// const colId = cell.column.id
|
|
1125
|
+
const rowId = cell.row.id;
|
|
1126
|
+
|
|
1127
|
+
// const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
1128
|
+
// const currentColIndex = indexCol;
|
|
1129
|
+
|
|
1130
|
+
const isNextCol = allCols[colIndex + 1];
|
|
1131
|
+
const nextCol = getNextEditableColumn(visibleColumns, colIndex, record);
|
|
1132
|
+
if (isNextCol && nextCol) {
|
|
1133
|
+
setFocusedCell?.({
|
|
1134
|
+
rowId,
|
|
1135
|
+
colId: nextCol.id
|
|
1136
|
+
});
|
|
1137
|
+
setStartCell?.({
|
|
1138
|
+
rowId,
|
|
1139
|
+
colId: nextCol.id
|
|
1140
|
+
});
|
|
1141
|
+
setEndCell?.({
|
|
1142
|
+
rowId,
|
|
1143
|
+
colId: nextCol.id
|
|
1144
|
+
});
|
|
1145
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1146
|
+
rowId,
|
|
1147
|
+
colId: nextCol.id
|
|
1148
|
+
}, {
|
|
1149
|
+
rowId,
|
|
1150
|
+
colId: nextCol.id
|
|
1151
|
+
}));
|
|
1152
|
+
columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
|
|
1153
|
+
align: 'center'
|
|
1154
|
+
});
|
|
1155
|
+
const nextItem = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${rowId}"].cell-editing[data-col-key="${nextCol.id}"] input`);
|
|
1156
|
+
|
|
1157
|
+
// 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
|
|
1158
|
+
// 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
|
|
1159
|
+
|
|
1160
|
+
const textarea = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${rowId}"].cell-editing[data-col-key="${nextCol.id}"] textarea`);
|
|
1161
|
+
setTimeout(() => {
|
|
1162
|
+
if (textarea) {
|
|
1163
|
+
textarea.focus();
|
|
1164
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
if (nextItem) {
|
|
1168
|
+
nextItem.focus();
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1114
1173
|
const cellValue = cell.getValue();
|
|
1115
1174
|
const rowIndex = cell.row.index;
|
|
1116
1175
|
const colFormat = typeof columnMeta?.format === 'function' ? columnMeta?.format(record) : columnMeta?.format;
|
|
@@ -1246,7 +1305,9 @@ const TableBodyCellEdit = props => {
|
|
|
1246
1305
|
editType: getEditType(cell.column.columnDef.meta, record),
|
|
1247
1306
|
indexCol: cell.column.getIndex(),
|
|
1248
1307
|
indexRow: cell.row.index,
|
|
1249
|
-
record: record
|
|
1308
|
+
record: record,
|
|
1309
|
+
visibleColumns: visibleColumns,
|
|
1310
|
+
handleNextCell: handleNextCell
|
|
1250
1311
|
// rowKey={rowKey}
|
|
1251
1312
|
}) : /*#__PURE__*/React.createElement("div", {
|
|
1252
1313
|
className: classNames('ui-rc_cell-content', {
|
|
@@ -38,9 +38,9 @@ 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
|
-
const timeFormat = format?.timeFormat
|
|
41
|
+
const timeFormat = format?.timeFormat;
|
|
42
42
|
const abc = convertToDate(value, timeFormat);
|
|
43
|
-
const timeValue = value ? dayjs(abc).format(timeFormat) : '';
|
|
43
|
+
const timeValue = value ? dayjs(abc).format(timeFormat ?? 'HH:mm') : '';
|
|
44
44
|
return timeValue ?? '';
|
|
45
45
|
case 'year':
|
|
46
46
|
const year = value ? moment(value).format('yyyy') : '';
|
|
@@ -81,6 +81,7 @@ export declare function sortData(data: any[], sorter: Sorter[]): any[];
|
|
|
81
81
|
export declare function filterDataByColumns(data: any[], queries: FilterItem[] | undefined, sorter: Sorter[] | undefined, keysFilter: string[] | undefined, ignoreAccents?: boolean): any[];
|
|
82
82
|
export declare const getAllRowKey: (data: any[]) => any[];
|
|
83
83
|
export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
84
|
+
export declare const getNextEditableColumn: (columns: any[], currentIndex: number, rowData: any) => any;
|
|
84
85
|
export declare const checkFieldKey: (key: string | undefined) => string;
|
|
85
86
|
export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
|
|
86
87
|
export declare const convertLabelToTitle: (data: any[]) => any[];
|
|
@@ -167,3 +168,5 @@ export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType
|
|
|
167
168
|
export declare function sumFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
|
|
168
169
|
export declare function sumNumberFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
|
|
169
170
|
export declare const getTreeDepth: (rows: any[]) => number;
|
|
171
|
+
export type FormatToken = 'YYYY' | 'MM' | 'DD' | 'HH' | 'mm' | 'ss';
|
|
172
|
+
export declare const isDateChanged: (oldDate: string | Date, newDate: string | Date, format: string) => FormatToken | null;
|
|
@@ -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,7 @@ 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 ?? ['HH:mm:ss', 'HH:mm'], true);
|
|
195
198
|
return date.isValid() ? moment(date.toDate()).format() : '';
|
|
196
199
|
}
|
|
197
200
|
if (valueType === 'datetime') {
|
|
@@ -1230,6 +1233,14 @@ export const isEditable = (column, rowData) => {
|
|
|
1230
1233
|
}
|
|
1231
1234
|
return column?.editEnable;
|
|
1232
1235
|
};
|
|
1236
|
+
export const getNextEditableColumn = (columns, currentIndex, rowData) => {
|
|
1237
|
+
for (let i = currentIndex + 1; i < columns.length; i++) {
|
|
1238
|
+
if (isEditable(columns[i].columnDef.meta, rowData)) {
|
|
1239
|
+
return columns[i];
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return undefined;
|
|
1243
|
+
};
|
|
1233
1244
|
export const checkFieldKey = key => {
|
|
1234
1245
|
if (key) {
|
|
1235
1246
|
return key;
|
|
@@ -2718,4 +2729,24 @@ export function sumNumberFields(columns, data, childrenKey = 'children') {
|
|
|
2718
2729
|
export const getTreeDepth = rows => {
|
|
2719
2730
|
if (!rows?.length) return 0;
|
|
2720
2731
|
return 1 + Math.max(0, ...rows.map(r => getTreeDepth(r.children)));
|
|
2732
|
+
};
|
|
2733
|
+
const TOKEN_MAP = {
|
|
2734
|
+
YYYY: 'year',
|
|
2735
|
+
MM: 'month',
|
|
2736
|
+
DD: 'day',
|
|
2737
|
+
HH: 'hour',
|
|
2738
|
+
mm: 'minute',
|
|
2739
|
+
ss: 'second'
|
|
2740
|
+
};
|
|
2741
|
+
export const isDateChanged = (oldDate, newDate, format) => {
|
|
2742
|
+
const prev = dayjs(oldDate, format, true);
|
|
2743
|
+
const next = dayjs(newDate, format, true);
|
|
2744
|
+
const tokens = ['YYYY', 'MM', 'DD', 'HH', 'mm', 'ss'];
|
|
2745
|
+
for (const token of tokens) {
|
|
2746
|
+
if (!format.includes(token)) continue;
|
|
2747
|
+
if (!prev.isSame(next, TOKEN_MAP[token])) {
|
|
2748
|
+
return token;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
return null;
|
|
2721
2752
|
};
|
|
@@ -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
|
}
|
|
@@ -417,11 +417,14 @@ const TableContainerEdit = props => {
|
|
|
417
417
|
}
|
|
418
418
|
} else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
|
|
419
419
|
const isDate = (0, _utils.isDateValue)(cellValue.trim());
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
const
|
|
424
|
-
const
|
|
420
|
+
|
|
421
|
+
// const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format
|
|
422
|
+
// const cellFormat = getFormat(colFormat, format)
|
|
423
|
+
// const editType = getEditType(columnOri as any)
|
|
424
|
+
// const dateFormat = getDatepickerFormat(editType, cellFormat)
|
|
425
|
+
// const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim(), dateFormat, true).format() : null
|
|
426
|
+
|
|
427
|
+
const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim()).format() : null;
|
|
425
428
|
newData[targetRow] = {
|
|
426
429
|
...newData[targetRow],
|
|
427
430
|
[columnKey]: date
|
|
@@ -601,6 +604,8 @@ const TableContainerEdit = props => {
|
|
|
601
604
|
handlePasted(rowsPasted);
|
|
602
605
|
}
|
|
603
606
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
607
|
+
|
|
608
|
+
// Copy
|
|
604
609
|
_react.default.useEffect(() => {
|
|
605
610
|
const handleKeyDown = e => {
|
|
606
611
|
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
@@ -611,6 +616,8 @@ const TableContainerEdit = props => {
|
|
|
611
616
|
document.addEventListener('keydown', handleKeyDown);
|
|
612
617
|
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
613
618
|
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
619
|
+
|
|
620
|
+
// Paste
|
|
614
621
|
_react.default.useEffect(() => {
|
|
615
622
|
const handlePaste = e => {
|
|
616
623
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
370
|
-
}
|
|
459
|
+
timePickerRef.current?.focus();
|
|
460
|
+
});
|
|
371
461
|
},
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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,9 @@ 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
|
|
51
|
+
const timeFormat = format?.timeFormat;
|
|
52
52
|
const abc = (0, _utils.convertToDate)(value, timeFormat);
|
|
53
|
-
const timeValue = value ? (0, _dayjs.default)(abc).format(timeFormat) : '';
|
|
53
|
+
const timeValue = value ? (0, _dayjs.default)(abc).format(timeFormat ?? 'HH:mm') : '';
|
|
54
54
|
return timeValue ?? '';
|
|
55
55
|
case 'year':
|
|
56
56
|
const year = value ? (0, _moment.default)(value).format('yyyy') : '';
|
|
@@ -81,6 +81,7 @@ export declare function sortData(data: any[], sorter: Sorter[]): any[];
|
|
|
81
81
|
export declare function filterDataByColumns(data: any[], queries: FilterItem[] | undefined, sorter: Sorter[] | undefined, keysFilter: string[] | undefined, ignoreAccents?: boolean): any[];
|
|
82
82
|
export declare const getAllRowKey: (data: any[]) => any[];
|
|
83
83
|
export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
84
|
+
export declare const getNextEditableColumn: (columns: any[], currentIndex: number, rowData: any) => any;
|
|
84
85
|
export declare const checkFieldKey: (key: string | undefined) => string;
|
|
85
86
|
export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
|
|
86
87
|
export declare const convertLabelToTitle: (data: any[]) => any[];
|
|
@@ -167,3 +168,5 @@ export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType
|
|
|
167
168
|
export declare function sumFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
|
|
168
169
|
export declare function sumNumberFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
|
|
169
170
|
export declare const getTreeDepth: (rows: any[]) => number;
|
|
171
|
+
export type FormatToken = 'YYYY' | 'MM' | 'DD' | 'HH' | 'mm' | 'ss';
|
|
172
|
+
export declare const isDateChanged: (oldDate: string | Date, newDate: string | Date, format: string) => FormatToken | null;
|
|
@@ -39,12 +39,12 @@ exports.getFormat = exports.getFixedFields = exports.getEditType = exports.getDi
|
|
|
39
39
|
exports.getHiddenParentKeys = getHiddenParentKeys;
|
|
40
40
|
exports.getHiddenParentKeys1 = getHiddenParentKeys1;
|
|
41
41
|
exports.getInvisibleColumns = getInvisibleColumns;
|
|
42
|
-
exports.getNewItemsOnly = exports.getLastSelectCell = void 0;
|
|
42
|
+
exports.getNextEditableColumn = exports.getNewItemsOnly = exports.getLastSelectCell = void 0;
|
|
43
43
|
exports.getRowIdsBetween = getRowIdsBetween;
|
|
44
44
|
exports.getVisibleColumnKeys1 = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTreeDepth = exports.getTableHeight = exports.getSelectedCellMatrix = void 0;
|
|
45
45
|
exports.getVisibleFields = getVisibleFields;
|
|
46
46
|
exports.groupArrayByColumns = groupArrayByColumns;
|
|
47
|
-
exports.isColor = void 0;
|
|
47
|
+
exports.isDateChanged = exports.isColor = void 0;
|
|
48
48
|
exports.isDateString = isDateString;
|
|
49
49
|
exports.isEmpty = exports.isEditable = exports.isDisable = exports.isDateValue = void 0;
|
|
50
50
|
exports.isEqualSet = isEqualSet;
|
|
@@ -260,6 +260,9 @@ function getDateValueType(value) {
|
|
|
260
260
|
}
|
|
261
261
|
const datetimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
262
262
|
const timeRegex = /^\d{2}:\d{2}(:\d{2})?$/;
|
|
263
|
+
|
|
264
|
+
// const timeRegex = /^(?:[01]\d|2[0-3])\s*:\s*[0-5]\d(?:\s*:\s*[0-5]\d)?$/;
|
|
265
|
+
|
|
263
266
|
if (datetimeRegex.test(value)) {
|
|
264
267
|
return 'datetime';
|
|
265
268
|
}
|
|
@@ -274,7 +277,7 @@ const convertToDate = (value, format) => {
|
|
|
274
277
|
}
|
|
275
278
|
const valueType = getDateValueType(value);
|
|
276
279
|
if (valueType === 'time') {
|
|
277
|
-
const date = (0, _dayjs.default)(value, format, true);
|
|
280
|
+
const date = (0, _dayjs.default)(value, format ?? ['HH:mm:ss', 'HH:mm'], true);
|
|
278
281
|
return date.isValid() ? (0, _moment.default)(date.toDate()).format() : '';
|
|
279
282
|
}
|
|
280
283
|
if (valueType === 'datetime') {
|
|
@@ -1336,6 +1339,15 @@ const isEditable = (column, rowData) => {
|
|
|
1336
1339
|
return column?.editEnable;
|
|
1337
1340
|
};
|
|
1338
1341
|
exports.isEditable = isEditable;
|
|
1342
|
+
const getNextEditableColumn = (columns, currentIndex, rowData) => {
|
|
1343
|
+
for (let i = currentIndex + 1; i < columns.length; i++) {
|
|
1344
|
+
if (isEditable(columns[i].columnDef.meta, rowData)) {
|
|
1345
|
+
return columns[i];
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
return undefined;
|
|
1349
|
+
};
|
|
1350
|
+
exports.getNextEditableColumn = getNextEditableColumn;
|
|
1339
1351
|
const checkFieldKey = key => {
|
|
1340
1352
|
if (key) {
|
|
1341
1353
|
return key;
|
|
@@ -2853,4 +2865,25 @@ const getTreeDepth = rows => {
|
|
|
2853
2865
|
if (!rows?.length) return 0;
|
|
2854
2866
|
return 1 + Math.max(0, ...rows.map(r => getTreeDepth(r.children)));
|
|
2855
2867
|
};
|
|
2856
|
-
exports.getTreeDepth = getTreeDepth;
|
|
2868
|
+
exports.getTreeDepth = getTreeDepth;
|
|
2869
|
+
const TOKEN_MAP = {
|
|
2870
|
+
YYYY: 'year',
|
|
2871
|
+
MM: 'month',
|
|
2872
|
+
DD: 'day',
|
|
2873
|
+
HH: 'hour',
|
|
2874
|
+
mm: 'minute',
|
|
2875
|
+
ss: 'second'
|
|
2876
|
+
};
|
|
2877
|
+
const isDateChanged = (oldDate, newDate, format) => {
|
|
2878
|
+
const prev = (0, _dayjs.default)(oldDate, format, true);
|
|
2879
|
+
const next = (0, _dayjs.default)(newDate, format, true);
|
|
2880
|
+
const tokens = ['YYYY', 'MM', 'DD', 'HH', 'mm', 'ss'];
|
|
2881
|
+
for (const token of tokens) {
|
|
2882
|
+
if (!format.includes(token)) continue;
|
|
2883
|
+
if (!prev.isSame(next, TOKEN_MAP[token])) {
|
|
2884
|
+
return token;
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
return null;
|
|
2888
|
+
};
|
|
2889
|
+
exports.isDateChanged = isDateChanged;
|
|
@@ -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
|
}
|