react-table-edit 1.4.54 → 1.4.55
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/dist/component/table/key-handlers.d.ts +4 -2
- package/dist/index.js +100 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KeyboardEvent } from "react";
|
|
2
|
+
import { TFunction } from "react-i18next";
|
|
2
3
|
import { ICellInfo, IColumnTable, IFTableEditPaging } from "../type";
|
|
3
4
|
export interface KeyHandlerParams {
|
|
4
5
|
row: any;
|
|
@@ -10,6 +11,7 @@ export interface KeyHandlerParams {
|
|
|
10
11
|
indexLastEdit: number;
|
|
11
12
|
editDisable?: boolean;
|
|
12
13
|
addDisable?: boolean;
|
|
14
|
+
t: TFunction<"translation", undefined>;
|
|
13
15
|
pagingSetting?: IFTableEditPaging;
|
|
14
16
|
changeDataSource: (data: any[], numberOfRows?: number) => void;
|
|
15
17
|
rowChange?: (row: any, indexRow: number, field: string) => void;
|
|
@@ -20,8 +22,8 @@ export interface KeyHandlerParams {
|
|
|
20
22
|
}
|
|
21
23
|
export declare const handleArrowRight: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void;
|
|
22
24
|
export declare const handleArrowLeft: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void;
|
|
23
|
-
export declare const handleArrowUp: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void
|
|
24
|
-
export declare const handleArrowDown: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void
|
|
25
|
+
export declare const handleArrowUp: (e: KeyboardEvent<any>, params: KeyHandlerParams) => Promise<void>;
|
|
26
|
+
export declare const handleArrowDown: (e: KeyboardEvent<any>, params: KeyHandlerParams) => Promise<void>;
|
|
25
27
|
export declare const handleTab: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void;
|
|
26
28
|
export declare const handleEnter: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void;
|
|
27
29
|
export declare const handleCtrlD: (e: KeyboardEvent<any>, params: KeyHandlerParams) => void;
|
package/dist/index.js
CHANGED
|
@@ -42787,7 +42787,7 @@ const PasteData = async (props) => {
|
|
|
42787
42787
|
const rs = column.resultValidate.find((item) => item[column.selectSettings?.fieldValue ?? "value"] === stringData);
|
|
42788
42788
|
if (rs) {
|
|
42789
42789
|
if (column.onPaste) {
|
|
42790
|
-
|
|
42790
|
+
column.onPaste(dataRow, stringData);
|
|
42791
42791
|
}
|
|
42792
42792
|
else {
|
|
42793
42793
|
dataRow[column.field] = stringData;
|
|
@@ -42859,7 +42859,7 @@ const PasteData = async (props) => {
|
|
|
42859
42859
|
else if (column.type === "select") {
|
|
42860
42860
|
if (column.selectSettings?.allowCreate) {
|
|
42861
42861
|
if (column.onPaste) {
|
|
42862
|
-
|
|
42862
|
+
column.onPaste(dataRow, stringData);
|
|
42863
42863
|
}
|
|
42864
42864
|
else {
|
|
42865
42865
|
dataRow[column.field] = stringData;
|
|
@@ -42872,7 +42872,7 @@ const PasteData = async (props) => {
|
|
|
42872
42872
|
const rs = ((column.selectSettings?.optionsField ? item[column.selectSettings?.optionsField] : column.selectSettings?.options) ?? []).find((item) => item[column.selectSettings?.fieldValue ?? "value"] === stringData);
|
|
42873
42873
|
if (rs) {
|
|
42874
42874
|
if (column.onPaste) {
|
|
42875
|
-
|
|
42875
|
+
column.onPaste(dataRow, stringData);
|
|
42876
42876
|
}
|
|
42877
42877
|
else {
|
|
42878
42878
|
dataRow[column.field] = stringData;
|
|
@@ -43097,7 +43097,7 @@ const CellComponent = React__default["default"].memo((props) => {
|
|
|
43097
43097
|
setSelectedCell({ minRow, maxRow, minCol, maxCol });
|
|
43098
43098
|
}
|
|
43099
43099
|
};
|
|
43100
|
-
const handleMouseUp = () => {
|
|
43100
|
+
const handleMouseUp = async () => {
|
|
43101
43101
|
if (!typeDragging.current) {
|
|
43102
43102
|
return;
|
|
43103
43103
|
}
|
|
@@ -43105,13 +43105,40 @@ const CellComponent = React__default["default"].memo((props) => {
|
|
|
43105
43105
|
const column = contentColumns[startCell.col];
|
|
43106
43106
|
const dataCopyRow = dataSource[startCell.row];
|
|
43107
43107
|
if (!(column.editEnable !== true || col.disabledCondition?.(dataCopyRow))) {
|
|
43108
|
+
let objCallback;
|
|
43109
|
+
if (column.onPasteValidate) {
|
|
43110
|
+
const rs = await column.onPasteValidate(dataCopyRow[column.field ?? ''], dataCopyRow, startCell?.row);
|
|
43111
|
+
if (rs && rs.length > 0) {
|
|
43112
|
+
objCallback = rs[0];
|
|
43113
|
+
}
|
|
43114
|
+
else {
|
|
43115
|
+
notificationError(t("PasteExcelNotExist", { index: startCell.row + 1, field: t(column.headerText ?? ""), value: dataCopyRow[column.field ?? ''] }));
|
|
43116
|
+
typeDragging.current = 0;
|
|
43117
|
+
isCopying.current = false;
|
|
43118
|
+
return;
|
|
43119
|
+
}
|
|
43120
|
+
}
|
|
43108
43121
|
const startIndex = startCell.row > indexRow ? startCell.row - 1 : startCell.row + 1;
|
|
43109
43122
|
const condition = (idx) => (startCell.row > indexRow ? idx >= indexRow : idx <= indexRow);
|
|
43110
43123
|
for (let index = startIndex; condition(index); (startCell.row > indexRow ? index-- : index++)) {
|
|
43111
|
-
|
|
43112
|
-
if (column.
|
|
43113
|
-
|
|
43114
|
-
|
|
43124
|
+
//copy dữ liệu
|
|
43125
|
+
if (column.onPaste) {
|
|
43126
|
+
column.onPaste(dataSource[index], dataCopyRow[column.field ?? '']);
|
|
43127
|
+
}
|
|
43128
|
+
else {
|
|
43129
|
+
dataSource[index][column.field ?? ''] = dataCopyRow[column.field ?? ''];
|
|
43130
|
+
}
|
|
43131
|
+
//callback
|
|
43132
|
+
if (column.callback) {
|
|
43133
|
+
//Xác thực dữ liệu được paste
|
|
43134
|
+
if (objCallback) {
|
|
43135
|
+
column.callback(objCallback, index, dataSource[index]);
|
|
43136
|
+
//Giá trị trường callback khi copy
|
|
43137
|
+
}
|
|
43138
|
+
else if (column.callbackValue) {
|
|
43139
|
+
objCallback = column.callbackValue(dataCopyRow);
|
|
43140
|
+
column.callback(objCallback, index, dataSource[index]);
|
|
43141
|
+
}
|
|
43115
43142
|
}
|
|
43116
43143
|
if (rowChange) {
|
|
43117
43144
|
rowChange(dataSource[index], index, column.field);
|
|
@@ -43152,7 +43179,7 @@ const CellComponent = React__default["default"].memo((props) => {
|
|
|
43152
43179
|
const content = typeDis === 'template' ? col.template?.(row, indexRow) ?? '' : value;
|
|
43153
43180
|
const isNegativeNumeric = col.type === 'numeric' && Number(row[col.field]) < 0;
|
|
43154
43181
|
const displayValue = isNegativeNumeric ? jsxRuntime.jsx("span", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: `${formatSetting?.prefixNegative ?? '-'}${content}${formatSetting?.suffixNegative ?? ''}` }) : content;
|
|
43155
|
-
return (jsxRuntime.jsx("td", { ...commonTdProps, children: jsxRuntime.jsx("div", { className: "r-rowcell-div", children: jsxRuntime.jsxs("div", { className: classNames$2("r-rowcell-content", { "r-active-cell": (isSelected && editDisable) || isActiveCell }, { "r-cell-disable": col.editEnable !== true || col.disabledCondition?.(row) }, { "r-cell-selected-top": indexRow === selectedCell?.minRow && isActiveCell }, { "r-cell-selected-bottom": indexRow === selectedCell?.maxRow && isActiveCell }, { "r-cell-selected-left": indexCol === selectedCell?.minCol && isActiveCell }, { "r-cell-selected-right": indexCol === selectedCell?.maxCol && isActiveCell }, { "r-cell-selected-single": isSingleCellSelected }), style: { textAlign: col.textAlign ?? "left" }, children: [typeDis === 'edit' ? jsxRuntime.jsx(RenderEditCellComponent, { idTable: idTable, col: col, handleKeyDown: handleKeyDown, handleDataChange: handleDataChange, indexCol: indexCol, indexRow: indexRow, row: row, editDisable: editDisable, formatSetting: formatSetting, gridRef: gridRef }) : jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}-col${indexCol}`, tabIndex: Number(`${indexRow + 1}${indexCol + 1}`), onKeyDown: (e) => handleKeyDown(e, row), onMouseDown: (e) => handleMouseDown(e, 1), onDoubleClick: (e) => { focusEditElementCell(e, indexRow, indexCol); }, style: { justifyContent: col.textAlign === "center" ? "center" : col.textAlign === "right" ? "flex-end" : "flex-start" }, className: "r-cell-text", children: displayValue }), content && (jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}-col${indexCol}`, children: displayValue }))] }), errorMessage && jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { id: `error-row${indexRow}-col${indexCol}`, className: classNames$2("cursor-pointer r-icon-invalid"), children: jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", children: [jsxRuntime.jsx("g", { "clip-path": "url(#clip0_537_2)", children: jsxRuntime.jsx("path", { d: "M18.0301 -0.0416304L17.9871 17.5138L0.474868 0.0404105L18.0301 -0.0416304Z", fill: "#da2626ff" }) }), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", { id: "clip0_537_2", children: jsxRuntime.jsx("rect", { width: "18", height: "18", fill: "white" }) }) })] }) }), jsxRuntime.jsx(UncontrolledTooltip, { target: `error-row${indexRow}-col${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? "" })] }), jsxRuntime.jsx("div", { className: "drag-handler", onMouseDown: (e) => handleMouseDown(e, 1, true) }), typeDis !== 'edit' && col.type === 'select' && jsxRuntime.jsx("div", { className: "drop-icon", children: jsxRuntime.jsx("svg", { height: "20", width: "20", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { d: "M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z" }) }) })] }) }) }));
|
|
43182
|
+
return (jsxRuntime.jsx("td", { ...commonTdProps, children: jsxRuntime.jsx("div", { className: "r-rowcell-div", children: jsxRuntime.jsxs("div", { className: classNames$2("r-rowcell-content", { "r-active-cell": (isSelected && editDisable) || isActiveCell }, { "r-cell-disable": col.editEnable !== true || col.disabledCondition?.(row) }, { "r-cell-selected-top": indexRow === selectedCell?.minRow && isActiveCell }, { "r-cell-selected-bottom": indexRow === selectedCell?.maxRow && isActiveCell }, { "r-cell-selected-left": indexCol === selectedCell?.minCol && isActiveCell }, { "r-cell-selected-right": indexCol === selectedCell?.maxCol && isActiveCell }, { "r-cell-selected-single": isSingleCellSelected }), style: { textAlign: col.textAlign ?? "left" }, children: [typeDis === 'edit' ? jsxRuntime.jsx(RenderEditCellComponent, { idTable: idTable, col: col, handleKeyDown: handleKeyDown, handleDataChange: handleDataChange, indexCol: indexCol, indexRow: indexRow, row: row, editDisable: editDisable, formatSetting: formatSetting, gridRef: gridRef }) : jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { id: `content-${idTable}-row${indexRow}-col${indexCol}`, tabIndex: Number(`${indexRow + 1}${indexCol + 1}`), onKeyDown: (e) => handleKeyDown(e, row), onMouseDown: (e) => handleMouseDown(e, 1), onDoubleClick: (e) => { focusEditElementCell(e, indexRow, indexCol); }, style: { justifyContent: col.textAlign === "center" ? "center" : col.textAlign === "right" ? "flex-end" : "flex-start" }, className: "r-cell-text", children: displayValue }), !!content && (jsxRuntime.jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}-col${indexCol}`, children: displayValue }))] }), errorMessage && jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { id: `error-row${indexRow}-col${indexCol}`, className: classNames$2("cursor-pointer r-icon-invalid"), children: jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "10", height: "10", viewBox: "0 0 10 10", fill: "none", children: [jsxRuntime.jsx("g", { "clip-path": "url(#clip0_537_2)", children: jsxRuntime.jsx("path", { d: "M18.0301 -0.0416304L17.9871 17.5138L0.474868 0.0404105L18.0301 -0.0416304Z", fill: "#da2626ff" }) }), jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("clipPath", { id: "clip0_537_2", children: jsxRuntime.jsx("rect", { width: "18", height: "18", fill: "white" }) }) })] }) }), jsxRuntime.jsx(UncontrolledTooltip, { target: `error-row${indexRow}-col${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? "" })] }), jsxRuntime.jsx("div", { className: "drag-handler", onMouseDown: (e) => handleMouseDown(e, 1, true) }), typeDis !== 'edit' && col.type === 'select' && jsxRuntime.jsx("div", { className: "drop-icon", children: jsxRuntime.jsx("svg", { height: "20", width: "20", viewBox: "0 0 20 20", children: jsxRuntime.jsx("path", { d: "M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z" }) }) })] }) }) }));
|
|
43156
43183
|
});
|
|
43157
43184
|
|
|
43158
43185
|
const handleArrowRight = (e, params) => {
|
|
@@ -43183,20 +43210,44 @@ const handleArrowLeft = (e, params) => {
|
|
|
43183
43210
|
e.preventDefault();
|
|
43184
43211
|
}
|
|
43185
43212
|
};
|
|
43186
|
-
const handleArrowUp = (e, params) => {
|
|
43187
|
-
const { startCell, pagingClient, pagingSetting, handleFocusCell, rowChange, changeDataSource, contentColumns, dataSource, row } = params;
|
|
43213
|
+
const handleArrowUp = async (e, params) => {
|
|
43214
|
+
const { startCell, pagingClient, pagingSetting, handleFocusCell, t, rowChange, changeDataSource, contentColumns, dataSource, row } = params;
|
|
43188
43215
|
if (startCell.row > 0) {
|
|
43189
43216
|
if ((e.ctrlKey || e.metaKey || e.altKey) && e.shiftKey) {
|
|
43190
43217
|
const column = contentColumns[startCell.col];
|
|
43218
|
+
let objCallback;
|
|
43219
|
+
if (column.onPasteValidate) {
|
|
43220
|
+
const rs = await column.onPasteValidate(row[column.field ?? ''], row, startCell?.row);
|
|
43221
|
+
if (rs && rs.length > 0) {
|
|
43222
|
+
objCallback = rs[0];
|
|
43223
|
+
}
|
|
43224
|
+
else {
|
|
43225
|
+
notificationError(t("PasteExcelNotExist", { index: startCell.row + 1, field: t(column.headerText ?? ""), value: row[column.field ?? ''] }));
|
|
43226
|
+
return;
|
|
43227
|
+
}
|
|
43228
|
+
}
|
|
43191
43229
|
for (let index = startCell.row; index >= 0; index--) {
|
|
43192
|
-
|
|
43193
|
-
|
|
43194
|
-
|
|
43195
|
-
|
|
43196
|
-
|
|
43230
|
+
//copy dữ liệu
|
|
43231
|
+
if (column.onPaste) {
|
|
43232
|
+
column.onPaste(dataSource[index], row[column.field ?? '']);
|
|
43233
|
+
}
|
|
43234
|
+
else {
|
|
43235
|
+
dataSource[index][column.field ?? ''] = row[column.field ?? ''];
|
|
43236
|
+
}
|
|
43237
|
+
//callback
|
|
43238
|
+
if (column.callback) {
|
|
43239
|
+
//Xác thực dữ liệu được paste
|
|
43240
|
+
if (objCallback) {
|
|
43241
|
+
column.callback(objCallback, index, dataSource[index]);
|
|
43242
|
+
//Giá trị trường callback khi copy
|
|
43243
|
+
}
|
|
43244
|
+
else if (column.callbackValue) {
|
|
43245
|
+
objCallback = column.callbackValue(row);
|
|
43246
|
+
column.callback(objCallback, index, dataSource[index]);
|
|
43247
|
+
}
|
|
43197
43248
|
}
|
|
43198
43249
|
if (rowChange) {
|
|
43199
|
-
rowChange(
|
|
43250
|
+
rowChange(dataSource[index], index, column.field);
|
|
43200
43251
|
}
|
|
43201
43252
|
}
|
|
43202
43253
|
changeDataSource(dataSource);
|
|
@@ -43210,20 +43261,44 @@ const handleArrowUp = (e, params) => {
|
|
|
43210
43261
|
e.preventDefault();
|
|
43211
43262
|
}
|
|
43212
43263
|
};
|
|
43213
|
-
const handleArrowDown = (e, params) => {
|
|
43214
|
-
const { startCell, totalCount, pagingClient, pagingSetting, handleFocusCell, rowChange, changeDataSource, dataSource, contentColumns, row } = params;
|
|
43264
|
+
const handleArrowDown = async (e, params) => {
|
|
43265
|
+
const { t, startCell, totalCount, pagingClient, pagingSetting, handleFocusCell, rowChange, changeDataSource, dataSource, contentColumns, row } = params;
|
|
43215
43266
|
if (startCell.row < totalCount - 1) {
|
|
43216
43267
|
if ((e.ctrlKey || e.metaKey || e.altKey) && e.shiftKey) {
|
|
43217
43268
|
const column = contentColumns[startCell.col];
|
|
43269
|
+
let objCallback;
|
|
43270
|
+
if (column.onPasteValidate) {
|
|
43271
|
+
const rs = await column.onPasteValidate(row[column.field ?? ''], row, startCell?.row);
|
|
43272
|
+
if (rs && rs.length > 0) {
|
|
43273
|
+
objCallback = rs[0];
|
|
43274
|
+
}
|
|
43275
|
+
else {
|
|
43276
|
+
notificationError(t("PasteExcelNotExist", { index: startCell.row + 1, field: t(column.headerText ?? ""), value: row[column.field ?? ''] }));
|
|
43277
|
+
return;
|
|
43278
|
+
}
|
|
43279
|
+
}
|
|
43218
43280
|
for (let index = startCell.row + 1; index < totalCount; index++) {
|
|
43219
|
-
|
|
43220
|
-
|
|
43221
|
-
|
|
43222
|
-
|
|
43223
|
-
|
|
43281
|
+
//copy dữ liệu
|
|
43282
|
+
if (column.onPaste) {
|
|
43283
|
+
column.onPaste(dataSource[index], row[column.field ?? '']);
|
|
43284
|
+
}
|
|
43285
|
+
else {
|
|
43286
|
+
dataSource[index][column.field ?? ''] = row[column.field ?? ''];
|
|
43287
|
+
}
|
|
43288
|
+
//callback
|
|
43289
|
+
if (column.callback) {
|
|
43290
|
+
//Xác thực dữ liệu được paste
|
|
43291
|
+
if (objCallback) {
|
|
43292
|
+
column.callback(objCallback, index, dataSource[index]);
|
|
43293
|
+
//Giá trị trường callback khi copy
|
|
43294
|
+
}
|
|
43295
|
+
else if (column.callbackValue) {
|
|
43296
|
+
objCallback = column.callbackValue(row);
|
|
43297
|
+
column.callback(objCallback, index, dataSource[index]);
|
|
43298
|
+
}
|
|
43224
43299
|
}
|
|
43225
43300
|
if (rowChange) {
|
|
43226
|
-
rowChange(
|
|
43301
|
+
rowChange(dataSource[index], index, column.field);
|
|
43227
43302
|
}
|
|
43228
43303
|
}
|
|
43229
43304
|
changeDataSource(dataSource);
|