react-table-edit 0.7.2 → 0.7.4

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/index.d.mts CHANGED
@@ -110,6 +110,7 @@ type IColumnTable = {
110
110
  commandItems?: ICommandItem[];
111
111
  editTypeCondition?: any;
112
112
  onPaste?: any;
113
+ onPasteValidate?: any;
113
114
  placeholder?: string;
114
115
  numericSettings?: ISettingNumericElement;
115
116
  selectSettings?: ISettingSelectElement;
package/dist/index.d.ts CHANGED
@@ -110,6 +110,7 @@ type IColumnTable = {
110
110
  commandItems?: ICommandItem[];
111
111
  editTypeCondition?: any;
112
112
  onPaste?: any;
113
+ onPasteValidate?: any;
113
114
  placeholder?: string;
114
115
  numericSettings?: ISettingNumericElement;
115
116
  selectSettings?: ISettingSelectElement;
package/dist/index.js CHANGED
@@ -3076,73 +3076,112 @@ var TableEdit = (0, import_react16.forwardRef)((props, ref) => {
3076
3076
  const column = contentColumns[col + index];
3077
3077
  if (column) {
3078
3078
  if (column.visible !== false) {
3079
- return column;
3079
+ return { ...column };
3080
3080
  } else {
3081
3081
  return getColumn(col, index + 1);
3082
3082
  }
3083
3083
  }
3084
3084
  return void 0;
3085
3085
  };
3086
- const pasteDataFromExcel = async (row, col, e) => {
3086
+ const pasteDataFromExcel = async (currenRowIndex, col, e) => {
3087
3087
  const clipboard = (e.clipboardData || window.Clipboard).getData("text");
3088
- const arrayRow = clipboard.trimEnd().split("\n");
3088
+ const rowsClipboard = clipboard.trimEnd().split("\n");
3089
3089
  setIndexFocus(void 0);
3090
- for (let indexRow = 0; indexRow < arrayRow.length; indexRow++) {
3091
- const item = arrayRow[indexRow];
3092
- const arrayCol = item.trimEnd().split(" ");
3093
- let dataRow = dataSource[row + indexRow];
3094
- if (!dataRow) {
3095
- dataRow = { ...defaultValue };
3096
- dataSource.push(dataRow);
3097
- }
3098
- for (let index = 0; index < arrayCol.length; index++) {
3099
- const stringData = arrayCol[index].toString().trim();
3090
+ if (rowsClipboard.length > 0) {
3091
+ const columnsDataChange = [];
3092
+ for (let index = 0; index < rowsClipboard[0].trimEnd().split(" ").length; index++) {
3093
+ const stringData = [];
3094
+ rowsClipboard.forEach((element) => {
3095
+ if (element.trimEnd().split(" ")[index]) {
3096
+ stringData.push(element.trimEnd().split(" ")[index].toString().trim());
3097
+ }
3098
+ });
3100
3099
  const column = getColumn(col, index);
3101
3100
  if (column) {
3102
- if ((!column.disabledCondition || !column.disabledCondition(row)) && column.editEnable) {
3103
- if (column.onPaste) {
3104
- const rs = await column.onPaste(stringData, indexRow, row);
3101
+ if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable) {
3102
+ if (column.onPasteValidate) {
3103
+ const rs = await column.onPasteValidate(stringData.join(","), 0, dataSource[currenRowIndex + 0]);
3105
3104
  if (rs) {
3106
- dataRow = rs.dataRow;
3107
- dataRow[column.field] = stringData;
3108
- if (column.callback) {
3109
- column.callback(rs.value, indexRow);
3110
- }
3111
- } else {
3112
- notificationError(t("PasteExcelNotExist", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3105
+ column.resultValidate = rs;
3113
3106
  }
3114
- } else {
3115
- if (column.editType === "date") {
3116
- const date = new Date(stringData);
3117
- if (!isNaN(date.getTime())) {
3118
- dataRow[column.field] = date;
3119
- if (column.callback) {
3120
- column.callback(date, indexRow);
3107
+ }
3108
+ }
3109
+ }
3110
+ columnsDataChange.push(column);
3111
+ }
3112
+ for (let indexRow = 0; indexRow < rowsClipboard.length; indexRow++) {
3113
+ const item = rowsClipboard[indexRow];
3114
+ const colsClipboard = item.trimEnd().split(" ");
3115
+ let dataRow = dataSource[currenRowIndex + indexRow];
3116
+ if (!dataRow) {
3117
+ dataRow = { ...defaultValue };
3118
+ dataSource.push(dataRow);
3119
+ }
3120
+ for (let index = 0; index < colsClipboard.length; index++) {
3121
+ const stringData = colsClipboard[index].toString().trim();
3122
+ const column = columnsDataChange[index];
3123
+ if (column) {
3124
+ console.log(!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow]));
3125
+ if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow])) && column.editEnable) {
3126
+ if (column.onPasteValidate && column.resultValidate) {
3127
+ const rs = column.resultValidate.find((item2) => item2[column.selectSettings?.fieldValue] === stringData);
3128
+ if (rs) {
3129
+ if (column.onPaste) {
3130
+ dataRow[column.field] = column.onPaste(dataRow, stringData);
3131
+ } else {
3132
+ dataRow[column.field] = stringData;
3121
3133
  }
3122
- } else {
3123
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3124
- }
3125
- } else if (column.editType === "numeric") {
3126
- const number = Number(stringData);
3127
- if (!isNaN(number)) {
3128
- dataRow[column.field] = number;
3129
3134
  if (column.callback) {
3130
- column.callback(number, indexRow);
3135
+ column.callback(rs, currenRowIndex + indexRow);
3131
3136
  }
3132
3137
  } else {
3133
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3138
+ notificationError(t("PasteExcelNotExist", { index: currenRowIndex + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3134
3139
  }
3135
3140
  } else {
3136
- dataRow[column.field] = stringData;
3137
- if (column.callback) {
3138
- column.callback(stringData, indexRow);
3141
+ if (column.editType === "date") {
3142
+ const date = new Date(stringData);
3143
+ if (!isNaN(date.getTime())) {
3144
+ if (column.onPaste) {
3145
+ dataRow[column.field] = column.onPaste(dataRow, date);
3146
+ } else {
3147
+ dataRow[column.field] = date;
3148
+ }
3149
+ if (column.callback) {
3150
+ column.callback(date, currenRowIndex + indexRow);
3151
+ }
3152
+ } else {
3153
+ notificationError(t("PasteExcelIncorrectFormat", { index: currenRowIndex + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3154
+ }
3155
+ } else if (column.editType === "numeric") {
3156
+ const number = Number(stringData);
3157
+ if (!isNaN(number)) {
3158
+ if (column.onPaste) {
3159
+ dataRow[column.field] = column.onPaste(dataRow, number);
3160
+ } else {
3161
+ dataRow[column.field] = number;
3162
+ }
3163
+ if (column.callback) {
3164
+ column.callback(number, currenRowIndex + indexRow);
3165
+ }
3166
+ } else {
3167
+ notificationError(t("PasteExcelIncorrectFormat", { index: currenRowIndex + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3168
+ }
3169
+ } else {
3170
+ if (column.onPaste) {
3171
+ column.onPaste(dataRow, stringData);
3172
+ } else {
3173
+ dataRow[column.field] = stringData;
3174
+ }
3175
+ if (column.callback) {
3176
+ column.callback(stringData, currenRowIndex + indexRow);
3177
+ }
3139
3178
  }
3140
3179
  }
3141
3180
  }
3142
3181
  }
3143
3182
  }
3183
+ rowChange(dataRow, currenRowIndex + indexRow, "");
3144
3184
  }
3145
- rowChange(dataRow, row + indexRow, "");
3146
3185
  }
3147
3186
  changeDataSource(dataSource);
3148
3187
  };
package/dist/index.mjs CHANGED
@@ -3042,73 +3042,112 @@ var TableEdit = forwardRef3((props, ref) => {
3042
3042
  const column = contentColumns[col + index];
3043
3043
  if (column) {
3044
3044
  if (column.visible !== false) {
3045
- return column;
3045
+ return { ...column };
3046
3046
  } else {
3047
3047
  return getColumn(col, index + 1);
3048
3048
  }
3049
3049
  }
3050
3050
  return void 0;
3051
3051
  };
3052
- const pasteDataFromExcel = async (row, col, e) => {
3052
+ const pasteDataFromExcel = async (currenRowIndex, col, e) => {
3053
3053
  const clipboard = (e.clipboardData || window.Clipboard).getData("text");
3054
- const arrayRow = clipboard.trimEnd().split("\n");
3054
+ const rowsClipboard = clipboard.trimEnd().split("\n");
3055
3055
  setIndexFocus(void 0);
3056
- for (let indexRow = 0; indexRow < arrayRow.length; indexRow++) {
3057
- const item = arrayRow[indexRow];
3058
- const arrayCol = item.trimEnd().split(" ");
3059
- let dataRow = dataSource[row + indexRow];
3060
- if (!dataRow) {
3061
- dataRow = { ...defaultValue };
3062
- dataSource.push(dataRow);
3063
- }
3064
- for (let index = 0; index < arrayCol.length; index++) {
3065
- const stringData = arrayCol[index].toString().trim();
3056
+ if (rowsClipboard.length > 0) {
3057
+ const columnsDataChange = [];
3058
+ for (let index = 0; index < rowsClipboard[0].trimEnd().split(" ").length; index++) {
3059
+ const stringData = [];
3060
+ rowsClipboard.forEach((element) => {
3061
+ if (element.trimEnd().split(" ")[index]) {
3062
+ stringData.push(element.trimEnd().split(" ")[index].toString().trim());
3063
+ }
3064
+ });
3066
3065
  const column = getColumn(col, index);
3067
3066
  if (column) {
3068
- if ((!column.disabledCondition || !column.disabledCondition(row)) && column.editEnable) {
3069
- if (column.onPaste) {
3070
- const rs = await column.onPaste(stringData, indexRow, row);
3067
+ if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + 0])) && column.editEnable) {
3068
+ if (column.onPasteValidate) {
3069
+ const rs = await column.onPasteValidate(stringData.join(","), 0, dataSource[currenRowIndex + 0]);
3071
3070
  if (rs) {
3072
- dataRow = rs.dataRow;
3073
- dataRow[column.field] = stringData;
3074
- if (column.callback) {
3075
- column.callback(rs.value, indexRow);
3076
- }
3077
- } else {
3078
- notificationError(t("PasteExcelNotExist", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3071
+ column.resultValidate = rs;
3079
3072
  }
3080
- } else {
3081
- if (column.editType === "date") {
3082
- const date = new Date(stringData);
3083
- if (!isNaN(date.getTime())) {
3084
- dataRow[column.field] = date;
3085
- if (column.callback) {
3086
- column.callback(date, indexRow);
3073
+ }
3074
+ }
3075
+ }
3076
+ columnsDataChange.push(column);
3077
+ }
3078
+ for (let indexRow = 0; indexRow < rowsClipboard.length; indexRow++) {
3079
+ const item = rowsClipboard[indexRow];
3080
+ const colsClipboard = item.trimEnd().split(" ");
3081
+ let dataRow = dataSource[currenRowIndex + indexRow];
3082
+ if (!dataRow) {
3083
+ dataRow = { ...defaultValue };
3084
+ dataSource.push(dataRow);
3085
+ }
3086
+ for (let index = 0; index < colsClipboard.length; index++) {
3087
+ const stringData = colsClipboard[index].toString().trim();
3088
+ const column = columnsDataChange[index];
3089
+ if (column) {
3090
+ console.log(!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow]));
3091
+ if ((!column.disabledCondition || !column.disabledCondition(dataSource[currenRowIndex + indexRow])) && column.editEnable) {
3092
+ if (column.onPasteValidate && column.resultValidate) {
3093
+ const rs = column.resultValidate.find((item2) => item2[column.selectSettings?.fieldValue] === stringData);
3094
+ if (rs) {
3095
+ if (column.onPaste) {
3096
+ dataRow[column.field] = column.onPaste(dataRow, stringData);
3097
+ } else {
3098
+ dataRow[column.field] = stringData;
3087
3099
  }
3088
- } else {
3089
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3090
- }
3091
- } else if (column.editType === "numeric") {
3092
- const number = Number(stringData);
3093
- if (!isNaN(number)) {
3094
- dataRow[column.field] = number;
3095
3100
  if (column.callback) {
3096
- column.callback(number, indexRow);
3101
+ column.callback(rs, currenRowIndex + indexRow);
3097
3102
  }
3098
3103
  } else {
3099
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3104
+ notificationError(t("PasteExcelNotExist", { index: currenRowIndex + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3100
3105
  }
3101
3106
  } else {
3102
- dataRow[column.field] = stringData;
3103
- if (column.callback) {
3104
- column.callback(stringData, indexRow);
3107
+ if (column.editType === "date") {
3108
+ const date = new Date(stringData);
3109
+ if (!isNaN(date.getTime())) {
3110
+ if (column.onPaste) {
3111
+ dataRow[column.field] = column.onPaste(dataRow, date);
3112
+ } else {
3113
+ dataRow[column.field] = date;
3114
+ }
3115
+ if (column.callback) {
3116
+ column.callback(date, currenRowIndex + indexRow);
3117
+ }
3118
+ } else {
3119
+ notificationError(t("PasteExcelIncorrectFormat", { index: currenRowIndex + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3120
+ }
3121
+ } else if (column.editType === "numeric") {
3122
+ const number = Number(stringData);
3123
+ if (!isNaN(number)) {
3124
+ if (column.onPaste) {
3125
+ dataRow[column.field] = column.onPaste(dataRow, number);
3126
+ } else {
3127
+ dataRow[column.field] = number;
3128
+ }
3129
+ if (column.callback) {
3130
+ column.callback(number, currenRowIndex + indexRow);
3131
+ }
3132
+ } else {
3133
+ notificationError(t("PasteExcelIncorrectFormat", { index: currenRowIndex + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3134
+ }
3135
+ } else {
3136
+ if (column.onPaste) {
3137
+ column.onPaste(dataRow, stringData);
3138
+ } else {
3139
+ dataRow[column.field] = stringData;
3140
+ }
3141
+ if (column.callback) {
3142
+ column.callback(stringData, currenRowIndex + indexRow);
3143
+ }
3105
3144
  }
3106
3145
  }
3107
3146
  }
3108
3147
  }
3109
3148
  }
3149
+ rowChange(dataRow, currenRowIndex + indexRow, "");
3110
3150
  }
3111
- rowChange(dataRow, row + indexRow, "");
3112
3151
  }
3113
3152
  changeDataSource(dataSource);
3114
3153
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-table-edit",
3
3
  "license": "MIT",
4
- "version": "0.7.2",
4
+ "version": "0.7.4",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",