From 408898e48722ff39bb253a1dde17afa94ddcbe61 Mon Sep 17 00:00:00 2001 From: alomoa Date: Mon, 24 Jul 2023 12:22:15 +0100 Subject: [PATCH] feat: adds option to save empty rows --- README.md | 3 ++- src/table.js | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 49984ab..390a4c0 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,8 @@ var editor = EditorJS({ | ------------------ | -------- | ---------------------------------------- | | `rows` | `number` | initial number of rows. `2` by default | | `cols` | `number` | initial number of columns. `2` by default | -| `withHeadings` | `boolean` | toggle table headings. `false` by default | +| `withHeadings` | `boolean`| toggle table headings. `false` by default | +| `allowEmptyRows` | `boolean`| toggle saving empty rows. `false` by default | ## Output data diff --git a/src/table.js b/src/table.js index 28d10ad..971ddbb 100644 --- a/src/table.js +++ b/src/table.js @@ -43,6 +43,11 @@ export default class Table { this.data = data; this.config = config; + /** + * Config default + */ + this.config.allowEmptyRows = config.allowEmptyRows ?? false; + /** * DOM nodes */ @@ -934,8 +939,8 @@ export default class Table { const cells = Array.from(row.querySelectorAll(`.${CSS.cell}`)); const isEmptyRow = cells.every(cell => !cell.textContent.trim()); - if (isEmptyRow) { - continue; + if(!this.config.allowEmptyRows && isEmptyRow){ + continue; } data.push(cells.map(cell => cell.innerHTML));