diff --git a/component/package-lock.json b/component/package-lock.json index d7c5a953..c8eceafa 100644 --- a/component/package-lock.json +++ b/component/package-lock.json @@ -1,12 +1,12 @@ { "name": "active-table", - "version": "1.1.2", + "version": "1.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "active-table", - "version": "1.1.2", + "version": "1.1.3", "license": "MIT", "dependencies": { "lit": "^3.0.2" diff --git a/component/package.json b/component/package.json index 34a13d2c..d483a501 100644 --- a/component/package.json +++ b/component/package.json @@ -1,6 +1,6 @@ { "name": "active-table", - "version": "1.1.2", + "version": "1.1.3", "description": "Framework agnostic table component for editable data experience", "main": "./dist/activeTable.js", "module": "./dist/activeTable.js", diff --git a/component/src/utils/outerTableComponents/files/CSV/CSVImport.ts b/component/src/utils/outerTableComponents/files/CSV/CSVImport.ts index 525b9a56..ffc1625c 100644 --- a/component/src/utils/outerTableComponents/files/CSV/CSVImport.ts +++ b/component/src/utils/outerTableComponents/files/CSV/CSVImport.ts @@ -7,11 +7,24 @@ export class CSVImport { return rowsOfData.map((row) => row.concat(Array(largestRowLength).fill('')).slice(0, largestRowLength)); } - private static parseDataFromRow(row: string, rowsOfData: string[][], largestRowLength: number) { - const data = row.split(','); - if (data.length > 0) { - rowsOfData.push(data); - if (data.length > largestRowLength) largestRowLength = data.length; + private static splitRow(row: string) { + // Matches commas outside of double-quotes + const regex = /("[^"]*"|[^,]+)(,|$)/g; + const rowCells: string[] = []; + row.replace(regex, (_, value) => { + rowCells.push(value); + // Return an empty string to continue the iteration + return ''; + }); + + return rowCells; + } + + private static parseDataFromRow(row: string, cells: string[][], largestRowLength: number) { + const rowCells = CSVImport.splitRow(row); + if (rowCells.length > 0) { + cells.push(rowCells); + if (rowCells.length > largestRowLength) largestRowLength = rowCells.length; } return largestRowLength; } @@ -20,12 +33,12 @@ export class CSVImport { private static parseCSV(csvText: string) { try { const rows = csvText.split(/\r\n|\n/) as string[]; - const rowsOfData: string[][] = []; + const cells: string[][] = []; let largestRowLength = 0; rows.forEach((row) => { - largestRowLength = CSVImport.parseDataFromRow(row, rowsOfData, largestRowLength); + largestRowLength = CSVImport.parseDataFromRow(row, cells, largestRowLength); }); - return CSVImport.getPaddedArray(rowsOfData, largestRowLength); + return CSVImport.getPaddedArray(cells, largestRowLength); } catch (errorMessage) { console.error('Incorrect format'); return null; diff --git a/component/src/utils/paste/CSV/overwriteCellsViaCSVOnPaste.ts b/component/src/utils/paste/CSV/overwriteCellsViaCSVOnPaste.ts index 2ce4d988..f6ec28df 100644 --- a/component/src/utils/paste/CSV/overwriteCellsViaCSVOnPaste.ts +++ b/component/src/utils/paste/CSV/overwriteCellsViaCSVOnPaste.ts @@ -13,7 +13,7 @@ export class OverwriteCellsViaCSVOnPaste { // prettier-ignore public static overwrite(at: ActiveTable, - clipboardText: string, event: ClipboardEvent, rowIndex: number, columnIndex: number,) { + clipboardText: string, event: ClipboardEvent, rowIndex: number, columnIndex: number) { event.preventDefault(); const CSV = ParseCSVClipboardText.parse(clipboardText); OverwriteCellsViaCSVOnPaste.focusOriginalCellAfterProcess(at, diff --git a/component/src/utils/paste/CSV/parseCSVClipboardText.ts b/component/src/utils/paste/CSV/parseCSVClipboardText.ts index e7f32971..273b4f51 100644 --- a/component/src/utils/paste/CSV/parseCSVClipboardText.ts +++ b/component/src/utils/paste/CSV/parseCSVClipboardText.ts @@ -35,7 +35,9 @@ export class ParseCSVClipboardText { const linesOfText: string[] = processedText.split(newLine); return linesOfText.map((lineOfText: string) => { // row indexes in worksheets end with \\t\\t\\t\\t\\t - return lineOfText.split(tab); + const cells = lineOfText.split(tab); + // when pasting data with ", it is parsed as \\" + return cells.map((cell) => cell.replace(/\\"/g, '')); }); } } diff --git a/other-packages/react/package-lock.json b/other-packages/react/package-lock.json index 8b6c23fc..b114fcaf 100644 --- a/other-packages/react/package-lock.json +++ b/other-packages/react/package-lock.json @@ -1,12 +1,12 @@ { "name": "active-table-react", - "version": "1.1.2", + "version": "1.1.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "active-table-react", - "version": "1.1.2", + "version": "1.1.3", "license": "MIT", "dependencies": { "@lit-labs/react": "^1.1.1", diff --git a/other-packages/react/package.json b/other-packages/react/package.json index a1217dcf..4c554af9 100644 --- a/other-packages/react/package.json +++ b/other-packages/react/package.json @@ -1,6 +1,6 @@ { "name": "active-table-react", - "version": "1.1.2", + "version": "1.1.3", "description": "Active Table wrapper for React", "main": "./dist/activeTable.js", "module": "./dist/activeTable.js", diff --git a/website/docs/docs/installation.mdx b/website/docs/docs/installation.mdx index 7cba49f4..20745678 100644 --- a/website/docs/docs/installation.mdx +++ b/website/docs/docs/installation.mdx @@ -19,5 +19,5 @@ npm install active-table-react Access the component via CDN: ``` -https://unpkg.com/active-table@1.1.2/dist/activeTable.bundle.js +https://unpkg.com/active-table@1.1.3/dist/activeTable.bundle.js ``` diff --git a/website/package-lock.json b/website/package-lock.json index 26278652..95e15dc7 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -12,7 +12,7 @@ "@docusaurus/preset-classic": "^2.3.0", "@docusaurus/theme-search-algolia": "^2.3.1", "@mdx-js/react": "^1.6.22", - "active-table-react": "^1.1.2", + "active-table-react": "^1.1.3", "clsx": "^1.2.1", "prism-react-renderer": "^1.3.5", "react": "^17.0.2", @@ -3785,9 +3785,9 @@ } }, "node_modules/active-table-react": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/active-table-react/-/active-table-react-1.1.2.tgz", - "integrity": "sha512-Cu81mRyk6/vli70zPMoXxT6DUYCjVD4nPBmYbKI64+w/LWfc8eV2xPbxdqbcu68EfXYi3K2+KqJWscKkoKL1yQ==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/active-table-react/-/active-table-react-1.1.3.tgz", + "integrity": "sha512-RYEv84dXKpXoDgHpba4Rjo7O5+xdPo0hAegS2EvRhhXdwNvoKTH/piv4HY4km6CVXQYqu3swZmpznCq8EwwjSw==", "dependencies": { "@lit-labs/react": "^1.1.1", "active-table": "1.1.2" @@ -15572,9 +15572,9 @@ } }, "active-table-react": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/active-table-react/-/active-table-react-1.1.2.tgz", - "integrity": "sha512-Cu81mRyk6/vli70zPMoXxT6DUYCjVD4nPBmYbKI64+w/LWfc8eV2xPbxdqbcu68EfXYi3K2+KqJWscKkoKL1yQ==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/active-table-react/-/active-table-react-1.1.3.tgz", + "integrity": "sha512-RYEv84dXKpXoDgHpba4Rjo7O5+xdPo0hAegS2EvRhhXdwNvoKTH/piv4HY4km6CVXQYqu3swZmpznCq8EwwjSw==", "requires": { "@lit-labs/react": "^1.1.1", "active-table": "1.1.2" diff --git a/website/package.json b/website/package.json index 833795d4..8f9a1eaf 100644 --- a/website/package.json +++ b/website/package.json @@ -18,7 +18,7 @@ "@docusaurus/preset-classic": "^2.3.0", "@docusaurus/theme-search-algolia": "^2.3.1", "@mdx-js/react": "^1.6.22", - "active-table-react": "^1.1.2", + "active-table-react": "^1.1.3", "clsx": "^1.2.1", "prism-react-renderer": "^1.3.5", "react": "^17.0.2",