es-grid-template 1.8.83 → 1.8.84

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.
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { Fragment } from "react";
3
3
  import { useCopyToClipboard } from 'usehooks-ts';
4
- import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, getTableHeight, isEditable, isFormattedNumber, newGuid, parseExcelClipboardText, sumSize,
4
+ import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, getTableHeight, isEditable, isFormattedNumber, newGuid, sumSize,
5
5
  // sumSize,
6
6
  unFlattenData, updateArrayByKey, updateColumnWidthsRecursive, updateOrInsert } from "./hook/utils";
7
7
  import { useVirtualizer } from "@tanstack/react-virtual";
@@ -18,7 +18,7 @@ import { Collapse2, Expand2, Maximize, Minimize } from "becoxy-icons";
18
18
  import TableWrapper from "./table/TableWrapper";
19
19
  import withReactContent from "sweetalert2-react-content";
20
20
  import Swal from "sweetalert2";
21
- import { convertToObjTrue, findAllChildrenKeys2, flatColumns2, isObjEmpty } from "../table-component/hook/utils";
21
+ import { convertToObjTrue, findAllChildrenKeys2, flatColumns2, isObjEmpty, parseExcelClipboardText } from "../table-component/hook/utils";
22
22
  import { ColumnsGroup } from "./ColumnsGroup";
23
23
  import { unGroupData } from "../table-virtuoso/hook/utils";
24
24
  import { useLocale } from "rc-master-ui/es/locale";
@@ -141,10 +141,6 @@ export declare function isTreeArray(arr: any[]): boolean;
141
141
  export declare function updateColumnWidthsRecursive(columns: any[], sizing: Record<string, number>): any[];
142
142
  export declare function updateWidthsByOther(source: any[], target: any[]): any[];
143
143
  export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
144
- export declare function parseExcelText(text: string): string[][];
145
- export declare function parseExcelClipboard(e: React.ClipboardEvent): string[][];
146
- export declare function parseExcelClipboardText(text: string): string[][];
147
- export declare function parseClipboardEvent(e: ClipboardEvent | React.ClipboardEvent): string[][];
148
144
  export declare function arraysEqualIgnoreOrderFast(a: any[], b: any[]): boolean;
149
145
  export declare function filterByIds(a: any[], b: any[]): any[];
150
146
  export declare function excludeItems(arrayA: any[], arrayB: any[]): any[];
@@ -212,9 +208,9 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
212
208
  ellipsis?: boolean;
213
209
  allowResizing?: boolean;
214
210
  allowSelection?: boolean | ((rowData: RecordType) => boolean);
215
- onCellStyles?: Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position">);
216
- onCellHeaderStyles?: Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position">);
217
- onCellFooterStyles?: Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "left" | "right" | "display" | "minWidth" | "position">);
211
+ 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">);
212
+ 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">);
213
+ 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">);
218
214
  sumGroup?: boolean;
219
215
  onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
220
216
  }[];
@@ -2059,114 +2059,6 @@ export function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
2059
2059
  dig(data);
2060
2060
  return keys;
2061
2061
  }
2062
- export function parseExcelText(text) {
2063
- // const text = e.clipboardData?.getData('text/plain') ?? '';
2064
- if (!text) return [];
2065
-
2066
- // Excel thường dùng \r\n giữa dòng, \t giữa cột
2067
- const rows = text.split(/\r?\n/) // tách theo dòng
2068
- .filter(r => r.trim() !== '') // bỏ dòng trống
2069
- .map(row => row.split('\t') // tách theo cột
2070
- .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2071
- );
2072
- return rows;
2073
- }
2074
- export function parseExcelClipboard(e) {
2075
- const text = e.clipboardData?.getData('text/plain') ?? '';
2076
- if (!text) return [];
2077
-
2078
- // Excel thường dùng \r\n giữa dòng, \t giữa cột
2079
- const rows = text.split(/\r?\n/) // tách theo dòng
2080
- .filter(r => r.trim() !== '') // bỏ dòng trống
2081
- .map(row => row.split('\t') // tách theo cột
2082
- .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2083
- );
2084
- return rows;
2085
- }
2086
- export function parseExcelClipboardText(text) {
2087
- const rows = [];
2088
- let curRow = [];
2089
- let curCell = '';
2090
- let inQuotes = false;
2091
- for (let i = 0; i < text.length; i++) {
2092
- const ch = text[i];
2093
- if (ch === '"') {
2094
- // "" -> an escaped quote inside quoted field
2095
- if (inQuotes && text[i + 1] === '"') {
2096
- curCell += '"';
2097
- i++; // skip next
2098
- } else {
2099
- inQuotes = !inQuotes; // open/close quote
2100
- }
2101
- continue;
2102
- }
2103
-
2104
- // tab as column separator (only if not inside quotes)
2105
- if (ch === '\t' && !inQuotes) {
2106
- curRow.push(curCell);
2107
- curCell = '';
2108
- continue;
2109
- }
2110
-
2111
- // newline as row separator (handle \r\n and lone \r or \n), only outside quotes
2112
- if ((ch === '\r' || ch === '\n') && !inQuotes) {
2113
- // handle CRLF
2114
- if (ch === '\r' && text[i + 1] === '\n') i++;
2115
- curRow.push(curCell);
2116
- curCell = '';
2117
- rows.push(curRow);
2118
- curRow = [];
2119
- continue;
2120
- }
2121
-
2122
- // normal character
2123
- curCell += ch;
2124
- }
2125
-
2126
- // push last cell/row (if any)
2127
- // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2128
- if (curCell !== '' || curRow.length > 0) {
2129
- curRow.push(curCell);
2130
- rows.push(curRow);
2131
- }
2132
-
2133
- // if the whole input was empty, return []
2134
- if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2135
- return [];
2136
- }
2137
- return rows;
2138
- }
2139
- export function parseClipboardEvent(e) {
2140
- const dataTransfer = e.clipboardData ?? e.nativeEvent?.clipboardData;
2141
- if (!dataTransfer) return [];
2142
-
2143
- // 1) try HTML (better fidelity for Excel)
2144
- const html = dataTransfer.getData?.('text/html');
2145
- if (html) {
2146
- try {
2147
- const doc = new DOMParser().parseFromString(html, 'text/html');
2148
- const table = doc.querySelector('table');
2149
- if (table) {
2150
- const result = [];
2151
- for (const tr of Array.from(table.rows)) {
2152
- const row = [];
2153
- for (const cell of Array.from(tr.cells)) {
2154
- // innerText preserves newlines from <br>
2155
- row.push(cell.innerText ?? '');
2156
- }
2157
- result.push(row);
2158
- }
2159
- if (result.length) return result;
2160
- }
2161
- } catch {
2162
- // fallback to text parsing
2163
- }
2164
- }
2165
-
2166
- // 2) fallback: parse plain text (TSV with quoted fields)
2167
- const text = dataTransfer.getData?.('text/plain') ?? '';
2168
- return parseExcelClipboardText(text);
2169
- }
2170
2062
  export function arraysEqualIgnoreOrderFast(a, b) {
2171
2063
  if (a.length !== b.length) return false;
2172
2064
  const count = Object.create(null);
@@ -142,10 +142,8 @@ export declare function isTreeArray2(arr: any[]): boolean;
142
142
  export declare function updateColumnWidthsRecursive(columns: any[], sizing: Record<string, number>): any[];
143
143
  export declare function updateWidthsByOther(source: any[], target: any[]): any[];
144
144
  export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
145
- export declare function parseExcelText(text: string): string[][];
146
- export declare function parseExcelClipboard(e: React.ClipboardEvent): string[][];
147
145
  export declare function parseExcelClipboardText(text: string): string[][];
148
- export declare function parseClipboardEvent(e: ClipboardEvent | React.ClipboardEvent): string[][];
146
+ export declare function parseExcelClipboard(e: React.ClipboardEvent): string[][];
149
147
  export declare function arraysEqualIgnoreOrderFast(a: any[], b: any[]): boolean;
150
148
  export declare function filterByIds(a: any[], b: any[]): any[];
151
149
  export declare function excludeItems(arrayA: any[], arrayB: any[]): any[];
@@ -2076,17 +2076,31 @@ export function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
2076
2076
  dig(data);
2077
2077
  return keys;
2078
2078
  }
2079
- export function parseExcelText(text) {
2080
- // const text = e.clipboardData?.getData('text/plain') ?? '';
2081
- if (!text) return [];
2082
-
2083
- // Excel thường dùng \r\n giữa dòng, \t giữa cột
2084
- const rows = text.split(/\r?\n/) // tách theo dòng
2085
- .filter(r => r.trim() !== '') // bỏ dòng trống
2086
- .map(row => row.split('\t') // tách theo cột
2087
- .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2088
- );
2089
- return rows;
2079
+ export function parseExcelClipboardText(text) {
2080
+ const lines = text.split(/\r?\n/);
2081
+ const result = [];
2082
+ let buffer = '';
2083
+ let inQuotedCell = false;
2084
+ for (const line of lines) {
2085
+ if (!inQuotedCell && line.startsWith('"') && !line.endsWith('"')) {
2086
+ inQuotedCell = true;
2087
+ buffer = line.slice(1); // bỏ "
2088
+ continue;
2089
+ }
2090
+ if (inQuotedCell) {
2091
+ if (line.endsWith('"')) {
2092
+ buffer += '\n' + line.slice(0, -1); // bỏ "
2093
+ result.push([buffer]);
2094
+ buffer = '';
2095
+ inQuotedCell = false;
2096
+ } else {
2097
+ buffer += '\n' + line;
2098
+ }
2099
+ continue;
2100
+ }
2101
+ result.push([line]);
2102
+ }
2103
+ return result;
2090
2104
  }
2091
2105
  export function parseExcelClipboard(e) {
2092
2106
  const text = e.clipboardData?.getData('text/plain') ?? '';
@@ -2100,90 +2114,61 @@ export function parseExcelClipboard(e) {
2100
2114
  );
2101
2115
  return rows;
2102
2116
  }
2103
- export function parseExcelClipboardText(text) {
2104
- const rows = [];
2105
- let curRow = [];
2106
- let curCell = '';
2107
- let inQuotes = false;
2108
- for (let i = 0; i < text.length; i++) {
2109
- const ch = text[i];
2110
- if (ch === '"') {
2111
- // "" -> an escaped quote inside quoted field
2112
- if (inQuotes && text[i + 1] === '"') {
2113
- curCell += '"';
2114
- i++; // skip next
2115
- } else {
2116
- inQuotes = !inQuotes; // open/close quote
2117
- }
2118
- continue;
2119
- }
2120
2117
 
2121
- // tab as column separator (only if not inside quotes)
2122
- if (ch === '\t' && !inQuotes) {
2123
- curRow.push(curCell);
2124
- curCell = '';
2125
- continue;
2126
- }
2118
+ // export function parseExcelText(text: string): string[][] {
2119
+ // const rows: string[][] = [];
2120
+ // let curRow: string[] = [];
2121
+ // let curCell = '';
2122
+ // let inQuotes = false;
2123
+
2124
+ // for (let i = 0; i < text.length; i++) {
2125
+ // const ch = text[i];
2126
+
2127
+ // if (ch === '"') {
2128
+ // if (inQuotes && text[i + 1] === '"') {
2129
+ // curCell += '"';
2130
+ // i++; // skip next
2131
+ // } else {
2132
+ // inQuotes = !inQuotes; // open/close quote
2133
+ // }
2134
+ // continue;
2135
+ // }
2127
2136
 
2128
- // newline as row separator (handle \r\n and lone \r or \n), only outside quotes
2129
- if ((ch === '\r' || ch === '\n') && !inQuotes) {
2130
- // handle CRLF
2131
- if (ch === '\r' && text[i + 1] === '\n') i++;
2132
- curRow.push(curCell);
2133
- curCell = '';
2134
- rows.push(curRow);
2135
- curRow = [];
2136
- continue;
2137
- }
2137
+ // if (ch === '\t' && !inQuotes) {
2138
+ // curRow.push(curCell);
2139
+ // curCell = '';
2140
+ // continue;
2141
+ // }
2138
2142
 
2139
- // normal character
2140
- curCell += ch;
2141
- }
2143
+ // if ((ch === '\r' || ch === '\n') && !inQuotes) {
2144
+ // // handle CRLF
2145
+ // if (ch === '\r' && text[i + 1] === '\n') i++;
2146
+ // curRow.push(curCell);
2147
+ // curCell = '';
2148
+ // rows.push(curRow);
2149
+ // curRow = [];
2150
+ // continue;
2151
+ // }
2142
2152
 
2143
- // push last cell/row (if any)
2144
- // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2145
- if (curCell !== '' || curRow.length > 0) {
2146
- curRow.push(curCell);
2147
- rows.push(curRow);
2148
- }
2153
+ // // normal character
2154
+ // curCell += ch;
2155
+ // }
2149
2156
 
2150
- // if the whole input was empty, return []
2151
- if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2152
- return [];
2153
- }
2154
- return rows;
2155
- }
2156
- export function parseClipboardEvent(e) {
2157
- const dataTransfer = e.clipboardData ?? e.nativeEvent?.clipboardData;
2158
- if (!dataTransfer) return [];
2159
-
2160
- // 1) try HTML (better fidelity for Excel)
2161
- const html = dataTransfer.getData?.('text/html');
2162
- if (html) {
2163
- try {
2164
- const doc = new DOMParser().parseFromString(html, 'text/html');
2165
- const table = doc.querySelector('table');
2166
- if (table) {
2167
- const result = [];
2168
- for (const tr of Array.from(table.rows)) {
2169
- const row = [];
2170
- for (const cell of Array.from(tr.cells)) {
2171
- // innerText preserves newlines from <br>
2172
- row.push(cell.innerText ?? '');
2173
- }
2174
- result.push(row);
2175
- }
2176
- if (result.length) return result;
2177
- }
2178
- } catch {
2179
- // fallback to text parsing
2180
- }
2181
- }
2157
+ // // push last cell/row (if any)
2158
+ // // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2159
+ // if (curCell !== '' || curRow.length > 0) {
2160
+ // curRow.push(curCell);
2161
+ // rows.push(curRow);
2162
+ // }
2163
+
2164
+ // // if the whole input was empty, return []
2165
+ // if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2166
+ // return [];
2167
+ // }
2168
+
2169
+ // return rows;
2170
+ // }
2182
2171
 
2183
- // 2) fallback: parse plain text (TSV with quoted fields)
2184
- const text = dataTransfer.getData?.('text/plain') ?? '';
2185
- return parseExcelClipboardText(text);
2186
- }
2187
2172
  export function arraysEqualIgnoreOrderFast(a, b) {
2188
2173
  if (a.length !== b.length) return false;
2189
2174
  const count = Object.create(null);
@@ -759,7 +759,7 @@ const TableContainerEdit = props => {
759
759
  // )
760
760
 
761
761
  // const rowsPasted = parseExcelText(pasteData)
762
- const rowsPasted = (0, _utils.parseExcelClipboardText)(pasteData);
762
+ const rowsPasted = (0, _utils2.parseExcelClipboardText)(pasteData);
763
763
  if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
764
764
  // bật popup thông báo
765
765
 
@@ -141,10 +141,6 @@ export declare function isTreeArray(arr: any[]): boolean;
141
141
  export declare function updateColumnWidthsRecursive(columns: any[], sizing: Record<string, number>): any[];
142
142
  export declare function updateWidthsByOther(source: any[], target: any[]): any[];
143
143
  export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
144
- export declare function parseExcelText(text: string): string[][];
145
- export declare function parseExcelClipboard(e: React.ClipboardEvent): string[][];
146
- export declare function parseExcelClipboardText(text: string): string[][];
147
- export declare function parseClipboardEvent(e: ClipboardEvent | React.ClipboardEvent): string[][];
148
144
  export declare function arraysEqualIgnoreOrderFast(a: any[], b: any[]): boolean;
149
145
  export declare function filterByIds(a: any[], b: any[]): any[];
150
146
  export declare function excludeItems(arrayA: any[], arrayB: any[]): any[];
@@ -48,12 +48,7 @@ exports.isEqualSet = isEqualSet;
48
48
  exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isFormattedNumber = void 0;
49
49
  exports.isObjEqual = isObjEqual;
50
50
  exports.isTreeArray = isTreeArray;
51
- exports.parseBooleanToValue = exports.onRemoveBgSelectedCell = exports.onAddBgSelectedCell = exports.newGuid = void 0;
52
- exports.parseClipboardEvent = parseClipboardEvent;
53
- exports.parseExcelClipboard = parseExcelClipboard;
54
- exports.parseExcelClipboardText = parseExcelClipboardText;
55
- exports.parseExcelText = parseExcelText;
56
- exports.removeColumns = void 0;
51
+ exports.removeColumns = exports.parseBooleanToValue = exports.onRemoveBgSelectedCell = exports.onAddBgSelectedCell = exports.newGuid = void 0;
57
52
  exports.removeDuplicatesByKey = removeDuplicatesByKey;
58
53
  exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = void 0;
59
54
  exports.sortColumnsByField = sortColumnsByField;
@@ -2182,114 +2177,6 @@ function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
2182
2177
  dig(data);
2183
2178
  return keys;
2184
2179
  }
2185
- function parseExcelText(text) {
2186
- // const text = e.clipboardData?.getData('text/plain') ?? '';
2187
- if (!text) return [];
2188
-
2189
- // Excel thường dùng \r\n giữa dòng, \t giữa cột
2190
- const rows = text.split(/\r?\n/) // tách theo dòng
2191
- .filter(r => r.trim() !== '') // bỏ dòng trống
2192
- .map(row => row.split('\t') // tách theo cột
2193
- .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2194
- );
2195
- return rows;
2196
- }
2197
- function parseExcelClipboard(e) {
2198
- const text = e.clipboardData?.getData('text/plain') ?? '';
2199
- if (!text) return [];
2200
-
2201
- // Excel thường dùng \r\n giữa dòng, \t giữa cột
2202
- const rows = text.split(/\r?\n/) // tách theo dòng
2203
- .filter(r => r.trim() !== '') // bỏ dòng trống
2204
- .map(row => row.split('\t') // tách theo cột
2205
- .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2206
- );
2207
- return rows;
2208
- }
2209
- function parseExcelClipboardText(text) {
2210
- const rows = [];
2211
- let curRow = [];
2212
- let curCell = '';
2213
- let inQuotes = false;
2214
- for (let i = 0; i < text.length; i++) {
2215
- const ch = text[i];
2216
- if (ch === '"') {
2217
- // "" -> an escaped quote inside quoted field
2218
- if (inQuotes && text[i + 1] === '"') {
2219
- curCell += '"';
2220
- i++; // skip next
2221
- } else {
2222
- inQuotes = !inQuotes; // open/close quote
2223
- }
2224
- continue;
2225
- }
2226
-
2227
- // tab as column separator (only if not inside quotes)
2228
- if (ch === '\t' && !inQuotes) {
2229
- curRow.push(curCell);
2230
- curCell = '';
2231
- continue;
2232
- }
2233
-
2234
- // newline as row separator (handle \r\n and lone \r or \n), only outside quotes
2235
- if ((ch === '\r' || ch === '\n') && !inQuotes) {
2236
- // handle CRLF
2237
- if (ch === '\r' && text[i + 1] === '\n') i++;
2238
- curRow.push(curCell);
2239
- curCell = '';
2240
- rows.push(curRow);
2241
- curRow = [];
2242
- continue;
2243
- }
2244
-
2245
- // normal character
2246
- curCell += ch;
2247
- }
2248
-
2249
- // push last cell/row (if any)
2250
- // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2251
- if (curCell !== '' || curRow.length > 0) {
2252
- curRow.push(curCell);
2253
- rows.push(curRow);
2254
- }
2255
-
2256
- // if the whole input was empty, return []
2257
- if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2258
- return [];
2259
- }
2260
- return rows;
2261
- }
2262
- function parseClipboardEvent(e) {
2263
- const dataTransfer = e.clipboardData ?? e.nativeEvent?.clipboardData;
2264
- if (!dataTransfer) return [];
2265
-
2266
- // 1) try HTML (better fidelity for Excel)
2267
- const html = dataTransfer.getData?.('text/html');
2268
- if (html) {
2269
- try {
2270
- const doc = new DOMParser().parseFromString(html, 'text/html');
2271
- const table = doc.querySelector('table');
2272
- if (table) {
2273
- const result = [];
2274
- for (const tr of Array.from(table.rows)) {
2275
- const row = [];
2276
- for (const cell of Array.from(tr.cells)) {
2277
- // innerText preserves newlines from <br>
2278
- row.push(cell.innerText ?? '');
2279
- }
2280
- result.push(row);
2281
- }
2282
- if (result.length) return result;
2283
- }
2284
- } catch {
2285
- // fallback to text parsing
2286
- }
2287
- }
2288
-
2289
- // 2) fallback: parse plain text (TSV with quoted fields)
2290
- const text = dataTransfer.getData?.('text/plain') ?? '';
2291
- return parseExcelClipboardText(text);
2292
- }
2293
2180
  function arraysEqualIgnoreOrderFast(a, b) {
2294
2181
  if (a.length !== b.length) return false;
2295
2182
  const count = Object.create(null);
@@ -142,10 +142,8 @@ export declare function isTreeArray2(arr: any[]): boolean;
142
142
  export declare function updateColumnWidthsRecursive(columns: any[], sizing: Record<string, number>): any[];
143
143
  export declare function updateWidthsByOther(source: any[], target: any[]): any[];
144
144
  export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
145
- export declare function parseExcelText(text: string): string[][];
146
- export declare function parseExcelClipboard(e: React.ClipboardEvent): string[][];
147
145
  export declare function parseExcelClipboardText(text: string): string[][];
148
- export declare function parseClipboardEvent(e: ClipboardEvent | React.ClipboardEvent): string[][];
146
+ export declare function parseExcelClipboard(e: React.ClipboardEvent): string[][];
149
147
  export declare function arraysEqualIgnoreOrderFast(a: any[], b: any[]): boolean;
150
148
  export declare function filterByIds(a: any[], b: any[]): any[];
151
149
  export declare function excludeItems(arrayA: any[], arrayB: any[]): any[];
@@ -50,10 +50,8 @@ exports.isObjEqual = isObjEqual;
50
50
  exports.isTreeArray = isTreeArray;
51
51
  exports.isTreeArray2 = isTreeArray2;
52
52
  exports.parseBooleanToValue = exports.onRemoveBgSelectedCell = exports.onAddBgSelectedCell = exports.newGuid = void 0;
53
- exports.parseClipboardEvent = parseClipboardEvent;
54
53
  exports.parseExcelClipboard = parseExcelClipboard;
55
54
  exports.parseExcelClipboardText = parseExcelClipboardText;
56
- exports.parseExcelText = parseExcelText;
57
55
  exports.removeColumns = void 0;
58
56
  exports.removeDuplicatesByKey = removeDuplicatesByKey;
59
57
  exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = void 0;
@@ -2199,17 +2197,31 @@ function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
2199
2197
  dig(data);
2200
2198
  return keys;
2201
2199
  }
2202
- function parseExcelText(text) {
2203
- // const text = e.clipboardData?.getData('text/plain') ?? '';
2204
- if (!text) return [];
2205
-
2206
- // Excel thường dùng \r\n giữa dòng, \t giữa cột
2207
- const rows = text.split(/\r?\n/) // tách theo dòng
2208
- .filter(r => r.trim() !== '') // bỏ dòng trống
2209
- .map(row => row.split('\t') // tách theo cột
2210
- .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2211
- );
2212
- return rows;
2200
+ function parseExcelClipboardText(text) {
2201
+ const lines = text.split(/\r?\n/);
2202
+ const result = [];
2203
+ let buffer = '';
2204
+ let inQuotedCell = false;
2205
+ for (const line of lines) {
2206
+ if (!inQuotedCell && line.startsWith('"') && !line.endsWith('"')) {
2207
+ inQuotedCell = true;
2208
+ buffer = line.slice(1); // bỏ "
2209
+ continue;
2210
+ }
2211
+ if (inQuotedCell) {
2212
+ if (line.endsWith('"')) {
2213
+ buffer += '\n' + line.slice(0, -1); // bỏ "
2214
+ result.push([buffer]);
2215
+ buffer = '';
2216
+ inQuotedCell = false;
2217
+ } else {
2218
+ buffer += '\n' + line;
2219
+ }
2220
+ continue;
2221
+ }
2222
+ result.push([line]);
2223
+ }
2224
+ return result;
2213
2225
  }
2214
2226
  function parseExcelClipboard(e) {
2215
2227
  const text = e.clipboardData?.getData('text/plain') ?? '';
@@ -2223,90 +2235,61 @@ function parseExcelClipboard(e) {
2223
2235
  );
2224
2236
  return rows;
2225
2237
  }
2226
- function parseExcelClipboardText(text) {
2227
- const rows = [];
2228
- let curRow = [];
2229
- let curCell = '';
2230
- let inQuotes = false;
2231
- for (let i = 0; i < text.length; i++) {
2232
- const ch = text[i];
2233
- if (ch === '"') {
2234
- // "" -> an escaped quote inside quoted field
2235
- if (inQuotes && text[i + 1] === '"') {
2236
- curCell += '"';
2237
- i++; // skip next
2238
- } else {
2239
- inQuotes = !inQuotes; // open/close quote
2240
- }
2241
- continue;
2242
- }
2243
2238
 
2244
- // tab as column separator (only if not inside quotes)
2245
- if (ch === '\t' && !inQuotes) {
2246
- curRow.push(curCell);
2247
- curCell = '';
2248
- continue;
2249
- }
2239
+ // export function parseExcelText(text: string): string[][] {
2240
+ // const rows: string[][] = [];
2241
+ // let curRow: string[] = [];
2242
+ // let curCell = '';
2243
+ // let inQuotes = false;
2244
+
2245
+ // for (let i = 0; i < text.length; i++) {
2246
+ // const ch = text[i];
2247
+
2248
+ // if (ch === '"') {
2249
+ // if (inQuotes && text[i + 1] === '"') {
2250
+ // curCell += '"';
2251
+ // i++; // skip next
2252
+ // } else {
2253
+ // inQuotes = !inQuotes; // open/close quote
2254
+ // }
2255
+ // continue;
2256
+ // }
2250
2257
 
2251
- // newline as row separator (handle \r\n and lone \r or \n), only outside quotes
2252
- if ((ch === '\r' || ch === '\n') && !inQuotes) {
2253
- // handle CRLF
2254
- if (ch === '\r' && text[i + 1] === '\n') i++;
2255
- curRow.push(curCell);
2256
- curCell = '';
2257
- rows.push(curRow);
2258
- curRow = [];
2259
- continue;
2260
- }
2258
+ // if (ch === '\t' && !inQuotes) {
2259
+ // curRow.push(curCell);
2260
+ // curCell = '';
2261
+ // continue;
2262
+ // }
2261
2263
 
2262
- // normal character
2263
- curCell += ch;
2264
- }
2264
+ // if ((ch === '\r' || ch === '\n') && !inQuotes) {
2265
+ // // handle CRLF
2266
+ // if (ch === '\r' && text[i + 1] === '\n') i++;
2267
+ // curRow.push(curCell);
2268
+ // curCell = '';
2269
+ // rows.push(curRow);
2270
+ // curRow = [];
2271
+ // continue;
2272
+ // }
2265
2273
 
2266
- // push last cell/row (if any)
2267
- // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2268
- if (curCell !== '' || curRow.length > 0) {
2269
- curRow.push(curCell);
2270
- rows.push(curRow);
2271
- }
2274
+ // // normal character
2275
+ // curCell += ch;
2276
+ // }
2272
2277
 
2273
- // if the whole input was empty, return []
2274
- if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2275
- return [];
2276
- }
2277
- return rows;
2278
- }
2279
- function parseClipboardEvent(e) {
2280
- const dataTransfer = e.clipboardData ?? e.nativeEvent?.clipboardData;
2281
- if (!dataTransfer) return [];
2282
-
2283
- // 1) try HTML (better fidelity for Excel)
2284
- const html = dataTransfer.getData?.('text/html');
2285
- if (html) {
2286
- try {
2287
- const doc = new DOMParser().parseFromString(html, 'text/html');
2288
- const table = doc.querySelector('table');
2289
- if (table) {
2290
- const result = [];
2291
- for (const tr of Array.from(table.rows)) {
2292
- const row = [];
2293
- for (const cell of Array.from(tr.cells)) {
2294
- // innerText preserves newlines from <br>
2295
- row.push(cell.innerText ?? '');
2296
- }
2297
- result.push(row);
2298
- }
2299
- if (result.length) return result;
2300
- }
2301
- } catch {
2302
- // fallback to text parsing
2303
- }
2304
- }
2278
+ // // push last cell/row (if any)
2279
+ // // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2280
+ // if (curCell !== '' || curRow.length > 0) {
2281
+ // curRow.push(curCell);
2282
+ // rows.push(curRow);
2283
+ // }
2284
+
2285
+ // // if the whole input was empty, return []
2286
+ // if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2287
+ // return [];
2288
+ // }
2289
+
2290
+ // return rows;
2291
+ // }
2305
2292
 
2306
- // 2) fallback: parse plain text (TSV with quoted fields)
2307
- const text = dataTransfer.getData?.('text/plain') ?? '';
2308
- return parseExcelClipboardText(text);
2309
- }
2310
2293
  function arraysEqualIgnoreOrderFast(a, b) {
2311
2294
  if (a.length !== b.length) return false;
2312
2295
  const count = Object.create(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.8.83",
3
+ "version": "1.8.84",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",