react-table-edit 0.7.2 → 0.7.3

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.js CHANGED
@@ -3076,7 +3076,7 @@ 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
  }
@@ -3085,64 +3085,86 @@ var TableEdit = (0, import_react16.forwardRef)((props, ref) => {
3085
3085
  };
3086
3086
  const pasteDataFromExcel = async (row, 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
3101
  if ((!column.disabledCondition || !column.disabledCondition(row)) && column.editEnable) {
3103
3102
  if (column.onPaste) {
3104
- const rs = await column.onPaste(stringData, indexRow, row);
3103
+ const rs = await column.onPaste(stringData.join(","), 0, row);
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;
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[row + 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
+ if ((!column.disabledCondition || !column.disabledCondition(row)) && column.editEnable) {
3125
+ if (column.onPaste && column.resultValidate) {
3126
+ const rs = column.resultValidate.find((item2) => item2[column.selectSettings?.fieldValue] === stringData);
3127
+ if (rs) {
3128
+ dataRow[column.field] = stringData;
3119
3129
  if (column.callback) {
3120
- column.callback(date, indexRow);
3130
+ column.callback(rs, row + indexRow);
3121
3131
  }
3122
3132
  } else {
3123
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3133
+ notificationError(t("PasteExcelNotExist", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3124
3134
  }
3125
- } else if (column.editType === "numeric") {
3126
- const number = Number(stringData);
3127
- if (!isNaN(number)) {
3128
- dataRow[column.field] = number;
3129
- if (column.callback) {
3130
- column.callback(number, indexRow);
3135
+ } else {
3136
+ if (column.editType === "date") {
3137
+ const date = new Date(stringData);
3138
+ if (!isNaN(date.getTime())) {
3139
+ dataRow[column.field] = date;
3140
+ if (column.callback) {
3141
+ column.callback(date, row + indexRow);
3142
+ }
3143
+ } else {
3144
+ notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3145
+ }
3146
+ } else if (column.editType === "numeric") {
3147
+ const number = Number(stringData);
3148
+ if (!isNaN(number)) {
3149
+ dataRow[column.field] = number;
3150
+ if (column.callback) {
3151
+ column.callback(number, row + indexRow);
3152
+ }
3153
+ } else {
3154
+ notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3131
3155
  }
3132
3156
  } else {
3133
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3134
- }
3135
- } else {
3136
- dataRow[column.field] = stringData;
3137
- if (column.callback) {
3138
- column.callback(stringData, indexRow);
3157
+ dataRow[column.field] = stringData;
3158
+ if (column.callback) {
3159
+ column.callback(stringData, row + indexRow);
3160
+ }
3139
3161
  }
3140
3162
  }
3141
3163
  }
3142
3164
  }
3143
3165
  }
3166
+ rowChange(dataRow, row + indexRow, "");
3144
3167
  }
3145
- rowChange(dataRow, row + indexRow, "");
3146
3168
  }
3147
3169
  changeDataSource(dataSource);
3148
3170
  };
package/dist/index.mjs CHANGED
@@ -3042,7 +3042,7 @@ 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
  }
@@ -3051,64 +3051,86 @@ var TableEdit = forwardRef3((props, ref) => {
3051
3051
  };
3052
3052
  const pasteDataFromExcel = async (row, 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
3067
  if ((!column.disabledCondition || !column.disabledCondition(row)) && column.editEnable) {
3069
3068
  if (column.onPaste) {
3070
- const rs = await column.onPaste(stringData, indexRow, row);
3069
+ const rs = await column.onPaste(stringData.join(","), 0, row);
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;
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[row + 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
+ if ((!column.disabledCondition || !column.disabledCondition(row)) && column.editEnable) {
3091
+ if (column.onPaste && column.resultValidate) {
3092
+ const rs = column.resultValidate.find((item2) => item2[column.selectSettings?.fieldValue] === stringData);
3093
+ if (rs) {
3094
+ dataRow[column.field] = stringData;
3085
3095
  if (column.callback) {
3086
- column.callback(date, indexRow);
3096
+ column.callback(rs, row + indexRow);
3087
3097
  }
3088
3098
  } else {
3089
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3099
+ notificationError(t("PasteExcelNotExist", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3090
3100
  }
3091
- } else if (column.editType === "numeric") {
3092
- const number = Number(stringData);
3093
- if (!isNaN(number)) {
3094
- dataRow[column.field] = number;
3095
- if (column.callback) {
3096
- column.callback(number, indexRow);
3101
+ } else {
3102
+ if (column.editType === "date") {
3103
+ const date = new Date(stringData);
3104
+ if (!isNaN(date.getTime())) {
3105
+ dataRow[column.field] = date;
3106
+ if (column.callback) {
3107
+ column.callback(date, row + indexRow);
3108
+ }
3109
+ } else {
3110
+ notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3111
+ }
3112
+ } else if (column.editType === "numeric") {
3113
+ const number = Number(stringData);
3114
+ if (!isNaN(number)) {
3115
+ dataRow[column.field] = number;
3116
+ if (column.callback) {
3117
+ column.callback(number, row + indexRow);
3118
+ }
3119
+ } else {
3120
+ notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3097
3121
  }
3098
3122
  } else {
3099
- notificationError(t("PasteExcelIncorrectFormat", { index: row + indexRow + 1, field: t(column.headerText ?? ""), value: stringData }));
3100
- }
3101
- } else {
3102
- dataRow[column.field] = stringData;
3103
- if (column.callback) {
3104
- column.callback(stringData, indexRow);
3123
+ dataRow[column.field] = stringData;
3124
+ if (column.callback) {
3125
+ column.callback(stringData, row + indexRow);
3126
+ }
3105
3127
  }
3106
3128
  }
3107
3129
  }
3108
3130
  }
3109
3131
  }
3132
+ rowChange(dataRow, row + indexRow, "");
3110
3133
  }
3111
- rowChange(dataRow, row + indexRow, "");
3112
3134
  }
3113
3135
  changeDataSource(dataSource);
3114
3136
  };
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.3",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",