From d35962a6eb89133010c0a2350ba787572a175bc7 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Thu, 24 Jun 2021 23:14:30 -0400 Subject: [PATCH 01/19] Adding cell-border as an attribute --- src/formats/table.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/formats/table.js b/src/formats/table.js index 4c2b657..175020a 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -122,6 +122,7 @@ class TableCell extends Container { } static create(value) { + console.log('create tablecell with value', value); const node = super.create(value) node.setAttribute("data-row", value.row) @@ -136,6 +137,10 @@ class TableCell extends Container { node.style.backgroundColor = value['cell-bg'] } + if(value['cell-border']){ + node.setAttribute('data-cell-border', value['cell-border']) + } + return node } From a5835efa28ec2eee5f8efaf12203a536cde2f402 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Wed, 30 Jun 2021 20:33:11 -0400 Subject: [PATCH 02/19] make cell border just like cell bg, pass value into cell line to persist --- src/formats/table.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/formats/table.js b/src/formats/table.js index 175020a..6ba62ae 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -35,6 +35,10 @@ class TableCellLine extends Block { if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']) } + + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']) + } return node } @@ -42,7 +46,7 @@ class TableCellLine extends Block { static formats(domNode) { const formats = {} - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg']).reduce((formats, attribute) => { + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined } @@ -63,6 +67,12 @@ class TableCellLine extends Block { } else { this.domNode.removeAttribute('data-cell-bg') } + } else if (name === 'cell-border') { + if (value) { + this.domNode.setAttribute('data-cell-border', value) + } else { + this.domNode.removeAttribute('data-cell-border') + } } else if (name === 'header') { if (!value) return; const { row, cell, rowspan, colspan } = TableCellLine.formats(this.domNode) @@ -85,13 +95,15 @@ class TableCellLine extends Block { const rowspan = this.domNode.getAttribute('data-rowspan') const colspan = this.domNode.getAttribute('data-colspan') const cellBg = this.domNode.getAttribute('data-cell-bg') + const cellBorder = this.domNode.getAttribute('data-cell-border') if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId, colspan, rowspan, - 'cell-bg': cellBg + 'cell-bg': cellBg, + 'cell-border': cellBorder }) } super.optimize(context) @@ -137,7 +149,7 @@ class TableCell extends Container { node.style.backgroundColor = value['cell-bg'] } - if(value['cell-border']){ + if (value['cell-border']) { node.setAttribute('data-cell-border', value['cell-border']) } @@ -155,6 +167,10 @@ class TableCell extends Container { formats["cell-bg"] = domNode.getAttribute("data-cell-bg") } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border") + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute) @@ -182,6 +198,10 @@ class TableCell extends Container { formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg") } + if (this.domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = this.domNode.getAttribute("data-cell-border") + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (this.domNode.hasAttribute(attribute)) { formats[attribute] = this.domNode.getAttribute(attribute) @@ -221,6 +241,9 @@ class TableCell extends Container { } else { this.domNode.style.backgroundColor = 'initial' } + } else if (name === 'cell-border'){ + this.toggleAttribute('data-cell-border', value) + this.formatChildren(name, value) } else { super.format(name, value) } From c3eb3035abf5ad4363dcd9ff6b8ccf463bc09d0d Mon Sep 17 00:00:00 2001 From: alex zhang Date: Wed, 30 Jun 2021 21:51:31 -0400 Subject: [PATCH 03/19] generate build artifacts --- dist/demo/demo1.js | 243 ++++++++++++++++++++++----------- dist/demo/demo1.js.css | 117 +--------------- dist/quill-better-table.css | 117 +--------------- dist/quill-better-table.js | 243 ++++++++++++++++++++++----------- dist/quill-better-table.min.js | 2 +- 5 files changed, 331 insertions(+), 391 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index bb44a32..51257ce 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "ced44c7892a78034ffe4"; +/******/ var hotCurrentHash = "81ae6e0616c1987a997e"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -166,6 +166,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ _declinedDependencies: {}, /******/ _selfAccepted: false, /******/ _selfDeclined: false, +/******/ _selfInvalidated: false, /******/ _disposeHandlers: [], /******/ _main: hotCurrentChildModule !== moduleId, /******/ @@ -196,6 +197,29 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var idx = hot._disposeHandlers.indexOf(callback); /******/ if (idx >= 0) hot._disposeHandlers.splice(idx, 1); /******/ }, +/******/ invalidate: function() { +/******/ this._selfInvalidated = true; +/******/ switch (hotStatus) { +/******/ case "idle": +/******/ hotUpdate = {}; +/******/ hotUpdate[moduleId] = modules[moduleId]; +/******/ hotSetStatus("ready"); +/******/ break; +/******/ case "ready": +/******/ hotApplyInvalidatedModule(moduleId); +/******/ break; +/******/ case "prepare": +/******/ case "check": +/******/ case "dispose": +/******/ case "apply": +/******/ (hotQueuedInvalidatedModules = +/******/ hotQueuedInvalidatedModules || []).push(moduleId); +/******/ break; +/******/ default: +/******/ // ignore requests in error states +/******/ break; +/******/ } +/******/ }, /******/ /******/ // Management API /******/ check: hotCheck, @@ -237,7 +261,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var hotDeferred; /******/ /******/ // The update info -/******/ var hotUpdate, hotUpdateNewHash; +/******/ var hotUpdate, hotUpdateNewHash, hotQueuedInvalidatedModules; /******/ /******/ function toModuleId(id) { /******/ var isNumber = +id + "" === id; @@ -252,7 +276,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ hotSetStatus("check"); /******/ return hotDownloadManifest(hotRequestTimeout).then(function(update) { /******/ if (!update) { -/******/ hotSetStatus("idle"); +/******/ hotSetStatus(hotApplyInvalidatedModules() ? "ready" : "idle"); /******/ return null; /******/ } /******/ hotRequestedFilesMap = {}; @@ -271,7 +295,6 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var chunkId = 0; /******/ // eslint-disable-next-line no-lone-blocks /******/ { -/******/ /*globals chunkId */ /******/ hotEnsureUpdateChunk(chunkId); /******/ } /******/ if ( @@ -346,6 +369,11 @@ return /******/ (function(modules) { // webpackBootstrap /******/ if (hotStatus !== "ready") /******/ throw new Error("apply() is only allowed in ready status"); /******/ options = options || {}; +/******/ return hotApplyInternal(options); +/******/ } +/******/ +/******/ function hotApplyInternal(options) { +/******/ hotApplyInvalidatedModules(); /******/ /******/ var cb; /******/ var i; @@ -368,7 +396,11 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var moduleId = queueItem.id; /******/ var chain = queueItem.chain; /******/ module = installedModules[moduleId]; -/******/ if (!module || module.hot._selfAccepted) continue; +/******/ if ( +/******/ !module || +/******/ (module.hot._selfAccepted && !module.hot._selfInvalidated) +/******/ ) +/******/ continue; /******/ if (module.hot._selfDeclined) { /******/ return { /******/ type: "self-declined", @@ -536,10 +568,13 @@ return /******/ (function(modules) { // webpackBootstrap /******/ installedModules[moduleId] && /******/ installedModules[moduleId].hot._selfAccepted && /******/ // removed self-accepted modules should not be required -/******/ appliedUpdate[moduleId] !== warnUnexpectedRequire +/******/ appliedUpdate[moduleId] !== warnUnexpectedRequire && +/******/ // when called invalidate self-accepting is not possible +/******/ !installedModules[moduleId].hot._selfInvalidated /******/ ) { /******/ outdatedSelfAcceptedModules.push({ /******/ module: moduleId, +/******/ parents: installedModules[moduleId].parents.slice(), /******/ errorHandler: installedModules[moduleId].hot._selfAccepted /******/ }); /******/ } @@ -612,7 +647,11 @@ return /******/ (function(modules) { // webpackBootstrap /******/ // Now in "apply" phase /******/ hotSetStatus("apply"); /******/ -/******/ hotCurrentHash = hotUpdateNewHash; +/******/ if (hotUpdateNewHash !== undefined) { +/******/ hotCurrentHash = hotUpdateNewHash; +/******/ hotUpdateNewHash = undefined; +/******/ } +/******/ hotUpdate = undefined; /******/ /******/ // insert new code /******/ for (moduleId in appliedUpdate) { @@ -665,7 +704,8 @@ return /******/ (function(modules) { // webpackBootstrap /******/ for (i = 0; i < outdatedSelfAcceptedModules.length; i++) { /******/ var item = outdatedSelfAcceptedModules[i]; /******/ moduleId = item.module; -/******/ hotCurrentParents = [moduleId]; +/******/ hotCurrentParents = item.parents; +/******/ hotCurrentChildModule = moduleId; /******/ try { /******/ __webpack_require__(moduleId); /******/ } catch (err) { @@ -707,12 +747,35 @@ return /******/ (function(modules) { // webpackBootstrap /******/ return Promise.reject(error); /******/ } /******/ +/******/ if (hotQueuedInvalidatedModules) { +/******/ return hotApplyInternal(options).then(function(list) { +/******/ outdatedModules.forEach(function(moduleId) { +/******/ if (list.indexOf(moduleId) < 0) list.push(moduleId); +/******/ }); +/******/ return list; +/******/ }); +/******/ } +/******/ /******/ hotSetStatus("idle"); /******/ return new Promise(function(resolve) { /******/ resolve(outdatedModules); /******/ }); /******/ } /******/ +/******/ function hotApplyInvalidatedModules() { +/******/ if (hotQueuedInvalidatedModules) { +/******/ if (!hotUpdate) hotUpdate = {}; +/******/ hotQueuedInvalidatedModules.forEach(hotApplyInvalidatedModule); +/******/ hotQueuedInvalidatedModules = undefined; +/******/ return true; +/******/ } +/******/ } +/******/ +/******/ function hotApplyInvalidatedModule(moduleId) { +/******/ if (!Object.prototype.hasOwnProperty.call(hotUpdate, moduleId)) +/******/ hotUpdate[moduleId] = modules[moduleId]; +/******/ } +/******/ /******/ // The module cache /******/ var installedModules = {}; /******/ @@ -869,6 +932,7 @@ module.exports = "= cellsNumber) { existCells[index].remove(); @@ -1047,7 +1111,7 @@ class table_column_tool_TableColumnTool { toolCell = existCells[index]; // set tool cell min-width css(toolCell, { - 'min-width': "".concat(colWidth, "px") + 'min-width': `${colWidth}px` }); } } @@ -1084,7 +1148,7 @@ class table_column_tool_TableColumnTool { } css($helpLine, { - 'left': "".concat(cellRect.left + cellRect.width - 1 + delta, "px") + 'left': `${cellRect.left + cellRect.width - 1 + delta}px` }); } }; @@ -1098,7 +1162,7 @@ class table_column_tool_TableColumnTool { if (dragging) { colBlot.format('width', width0 + delta); css(cell, { - 'min-width': "".concat(width0 + delta, "px") + 'min-width': `${width0 + delta}px` }); x0 = 0; x = 0; @@ -1127,10 +1191,10 @@ class table_column_tool_TableColumnTool { $helpLine = document.createElement('div'); css($helpLine, { position: 'fixed', - top: "".concat(cellRect.top, "px"), - left: "".concat(cellRect.left + cellRect.width - 1, "px"), + top: `${cellRect.top}px`, + left: `${cellRect.left + cellRect.width - 1}px`, zIndex: '100', - height: "".concat(tableRect.height + COL_TOOL_HEIGHT + 4, "px"), + height: `${tableRect.height + COL_TOOL_HEIGHT + 4}px`, width: '1px', backgroundColor: PRIMARY_COLOR }); @@ -1172,10 +1236,10 @@ class header_Header extends Block { const node = super.create(value.value); CELL_IDENTITY_KEYS.forEach(key => { - if (value[key]) node.setAttribute("data-".concat(key), value[key]); + if (value[key]) node.setAttribute(`data-${key}`, value[key]); }); CELL_ATTRIBUTES.forEach(key => { - if (value[key]) node.setAttribute("data-".concat(key), value[key]); + if (value[key]) node.setAttribute(`data-${key}`, value[key]); }); return node; } @@ -1184,8 +1248,8 @@ class header_Header extends Block { const formats = {}; formats.value = this.tagName.indexOf(domNode.tagName) + 1; return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).reduce((formats, attribute) => { - if (domNode.hasAttribute("data-".concat(attribute))) { - formats[attribute] = domNode.getAttribute("data-".concat(attribute)) || undefined; + if (domNode.hasAttribute(`data-${attribute}`)) { + formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; @@ -1291,24 +1355,28 @@ class TableCellLine extends table_Block { const node = super.create(value); CELL_IDENTITY_KEYS.forEach(key => { let identityMaker = key === 'row' ? table_rowId : table_cellId; - node.setAttribute("data-".concat(key), value[key] || identityMaker()); + node.setAttribute(`data-${key}`, value[key] || identityMaker()); }); CELL_ATTRIBUTES.forEach(attrName => { - node.setAttribute("data-".concat(attrName), value[attrName] || CELL_DEFAULT[attrName]); + node.setAttribute(`data-${attrName}`, value[attrName] || CELL_DEFAULT[attrName]); }); if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']); } + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']); + } + return node; } static formats(domNode) { const formats = {}; - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg']).reduce((formats, attribute) => { - if (domNode.hasAttribute("data-".concat(attribute))) { - formats[attribute] = domNode.getAttribute("data-".concat(attribute)) || undefined; + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + if (domNode.hasAttribute(`data-${attribute}`)) { + formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; @@ -1318,9 +1386,9 @@ class TableCellLine extends table_Block { format(name, value) { if (CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).indexOf(name) > -1) { if (value) { - this.domNode.setAttribute("data-".concat(name), value); + this.domNode.setAttribute(`data-${name}`, value); } else { - this.domNode.removeAttribute("data-".concat(name)); + this.domNode.removeAttribute(`data-${name}`); } } else if (name === 'cell-bg') { if (value) { @@ -1328,6 +1396,12 @@ class TableCellLine extends table_Block { } else { this.domNode.removeAttribute('data-cell-bg'); } + } else if (name === 'cell-border') { + if (value) { + this.domNode.setAttribute('data-cell-border', value); + } else { + this.domNode.removeAttribute('data-cell-border'); + } } else if (name === 'header') { if (!value) return; const { @@ -1355,13 +1429,15 @@ class TableCellLine extends table_Block { const rowspan = this.domNode.getAttribute('data-rowspan'); const colspan = this.domNode.getAttribute('data-colspan'); const cellBg = this.domNode.getAttribute('data-cell-bg'); + const cellBorder = this.domNode.getAttribute('data-cell-border'); if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId, colspan, rowspan, - 'cell-bg': cellBg + 'cell-bg': cellBg, + 'cell-border': cellBorder }); } @@ -1392,6 +1468,7 @@ class TableCell extends Container { } static create(value) { + console.log('create tablecell with value', value); const node = super.create(value); node.setAttribute("data-row", value.row); CELL_ATTRIBUTES.forEach(attrName => { @@ -1405,6 +1482,10 @@ class TableCell extends Container { node.style.backgroundColor = value['cell-bg']; } + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']); + } + return node; } @@ -1419,6 +1500,10 @@ class TableCell extends Container { formats["cell-bg"] = domNode.getAttribute("data-cell-bg"); } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border"); + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute); @@ -1447,6 +1532,10 @@ class TableCell extends Container { formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg"); } + if (this.domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (this.domNode.hasAttribute(attribute)) { formats[attribute] = this.domNode.getAttribute(attribute); @@ -1475,7 +1564,7 @@ class TableCell extends Container { this.toggleAttribute(name, value); this.formatChildren(name, value); } else if (['row'].indexOf(name) > -1) { - this.toggleAttribute("data-".concat(name), value); + this.toggleAttribute(`data-${name}`, value); this.formatChildren(name, value); } else if (name === 'cell-bg') { this.toggleAttribute('data-cell-bg', value); @@ -1486,6 +1575,9 @@ class TableCell extends Container { } else { this.domNode.style.backgroundColor = 'initial'; } + } else if (name === 'cell-border') { + this.toggleAttribute('data-cell-border', value); + this.formatChildren(name, value); } else { super.format(name, value); } @@ -1545,8 +1637,8 @@ class TableRow extends Container { formats() { return ["row"].reduce((formats, attrName) => { - if (this.domNode.hasAttribute("data-".concat(attrName))) { - formats[attrName] = this.domNode.getAttribute("data-".concat(attrName)); + if (this.domNode.hasAttribute(`data-${attrName}`)) { + formats[attrName] = this.domNode.getAttribute(`data-${attrName}`); } return formats; @@ -1601,15 +1693,15 @@ class TableCol extends table_Block { static create(value) { let node = super.create(value); COL_ATTRIBUTES.forEach(attrName => { - node.setAttribute("".concat(attrName), value[attrName] || COL_DEFAULT[attrName]); + node.setAttribute(`${attrName}`, value[attrName] || COL_DEFAULT[attrName]); }); return node; } static formats(domNode) { return COL_ATTRIBUTES.reduce((formats, attribute) => { - if (domNode.hasAttribute("".concat(attribute))) { - formats[attribute] = domNode.getAttribute("".concat(attribute)) || undefined; + if (domNode.hasAttribute(`${attribute}`)) { + formats[attribute] = domNode.getAttribute(`${attribute}`) || undefined; } return formats; @@ -1618,7 +1710,7 @@ class TableCol extends table_Block { format(name, value) { if (COL_ATTRIBUTES.indexOf(name) > -1) { - this.domNode.setAttribute("".concat(name), value || COL_DEFAULT[name]); + this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]); } else { super.format(name, value); } @@ -1657,7 +1749,7 @@ class table_TableContainer extends Container { sumWidth = sumWidth + parseInt(col.formats()[TableCol.blotName].width, 10); return sumWidth; }, 0); - this.domNode.style.width = "".concat(tableWidth, "px"); + this.domNode.style.width = `${tableWidth}px`; }, 0); } @@ -1669,9 +1761,7 @@ class table_TableContainer extends Container { return this.children.head; } - deleteColumns(compareRect) { - let delIndexes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - let editorWrapper = arguments.length > 2 ? arguments[2] : undefined; + deleteColumns(compareRect, delIndexes = [], editorWrapper) { const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; const tableCells = this.descendants(TableCell); @@ -1808,9 +1898,7 @@ class table_TableContainer extends Container { } } - insertColumn(compareRect, colIndex) { - let isRight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; - let editorWrapper = arguments.length > 3 ? arguments[3] : undefined; + insertColumn(compareRect, colIndex, isRight = true, editorWrapper) { const [body] = this.descendants(TableBody); const [tableColGroup] = this.descendants(TableColGroup); const tableCols = this.descendants(TableCol); @@ -2094,12 +2182,12 @@ TableCol.requiredContainer = TableColGroup; function table_rowId() { const id = Math.random().toString(36).slice(2, 6); - return "row-".concat(id); + return `row-${id}`; } function table_cellId() { const id = Math.random().toString(36).slice(2, 6); - return "cell-".concat(id); + return `cell-${id}`; } @@ -2224,30 +2312,30 @@ class table_selection_TableSelection { const tableViewScrollLeft = this.table.parentNode.scrollLeft; css(this.left, { display: 'block', - left: "".concat(this.boundary.x - tableViewScrollLeft - 1, "px"), - top: "".concat(this.boundary.y, "px"), - height: "".concat(this.boundary.height + 1, "px"), + left: `${this.boundary.x - tableViewScrollLeft - 1}px`, + top: `${this.boundary.y}px`, + height: `${this.boundary.height + 1}px`, width: '1px' }); css(this.right, { display: 'block', - left: "".concat(this.boundary.x1 - tableViewScrollLeft, "px"), - top: "".concat(this.boundary.y, "px"), - height: "".concat(this.boundary.height + 1, "px"), + left: `${this.boundary.x1 - tableViewScrollLeft}px`, + top: `${this.boundary.y}px`, + height: `${this.boundary.height + 1}px`, width: '1px' }); css(this.top, { display: 'block', - left: "".concat(this.boundary.x - 1 - tableViewScrollLeft, "px"), - top: "".concat(this.boundary.y, "px"), - width: "".concat(this.boundary.width + 1, "px"), + left: `${this.boundary.x - 1 - tableViewScrollLeft}px`, + top: `${this.boundary.y}px`, + width: `${this.boundary.width + 1}px`, height: '1px' }); css(this.bottom, { display: 'block', - left: "".concat(this.boundary.x - 1 - tableViewScrollLeft, "px"), - top: "".concat(this.boundary.y1 + 1, "px"), - width: "".concat(this.boundary.width + 1, "px"), + left: `${this.boundary.x - 1 - tableViewScrollLeft}px`, + top: `${this.boundary.y1 + 1}px`, + width: `${this.boundary.width + 1}px`, height: '1px' }); } // based on selectedTds compute positions of help lines @@ -2540,20 +2628,19 @@ class table_operation_menu_TableOperationMenu { return null; } - menuInitial(_ref) { - let { - table, - left, - top - } = _ref; + menuInitial({ + table, + left, + top + }) { this.domNode = document.createElement('div'); this.domNode.classList.add('qlbt-operation-menu'); css(this.domNode, { position: 'absolute', - left: "".concat(left, "px"), - top: "".concat(top, "px"), - 'min-height': "".concat(MENU_MIN_HEIHGT, "px"), - width: "".concat(MENU_WIDTH, "px") + left: `${left}px`, + top: `${top}px`, + 'min-height': `${MENU_MIN_HEIHGT}px`, + width: `${MENU_WIDTH}px` }); for (let name in this.menuItems) { @@ -2618,12 +2705,11 @@ class table_operation_menu_TableOperationMenu { return node; } - menuItemCreator(_ref2) { - let { - text, - iconSrc, - handler - } = _ref2; + menuItemCreator({ + text, + iconSrc, + handler + }) { const node = document.createElement('div'); node.classList.add('qlbt-operation-menu-item'); const iconSpan = document.createElement('span'); @@ -2990,8 +3076,7 @@ class quill_better_table_BetterTable extends Module { }); } - getTable() { - let range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.quill.getSelection(); + getTable(range = this.quill.getSelection()) { if (range == null) return [null, null, null, -1]; const [cellLine, offset] = this.quill.getLine(range.index); @@ -3012,7 +3097,7 @@ class quill_better_table_BetterTable extends Module { let delta = new quill_better_table_Delta().retain(range.index); if (isInTableCell(currentBlot)) { - console.warn("Can not insert table into a table cell."); + console.warn(`Can not insert table into a table cell.`); return; } diff --git a/dist/demo/demo1.js.css b/dist/demo/demo1.js.css index cec18b9..72d9433 100644 --- a/dist/demo/demo1.js.css +++ b/dist/demo/demo1.js.css @@ -1,117 +1,2 @@ -.ql-container .qlbt-selection-line.qlbt-selection-line-left::before { - position: absolute; - left: -2px; - top: -2px; - content: ''; - width: 5px; - height: 5px; - background-color: #0589f3; - border-radius: 5px; } - -.ql-container .qlbt-selection-line.qlbt-selection-line-right::before { - position: absolute; - right: -2px; - bottom: -3px; - content: ''; - width: 5px; - height: 5px; - background-color: #0589f3; - border-radius: 5px; } - -.quill-better-table-wrapper { - overflow-x: auto; } - -table.quill-better-table { - table-layout: fixed; - border-collapse: collapse; } - table.quill-better-table td { - border: 1px solid #000; - padding: 2px 5px; } - -.qlbt-operation-menu { - background-color: #fff; - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); - font-size: 14px; - z-index: 100; - overflow: hidden; } - .qlbt-operation-menu .qlbt-operation-menu-dividing { - height: 1px; - background-color: #efefef; } - .qlbt-operation-menu .qlbt-operation-menu-subtitle { - color: #999; - font-size: 14px; - padding: 5px 16px; } - .qlbt-operation-menu .qlbt-operation-color-picker { - display: flex; - align-items: center; - flex-wrap: wrap; - padding: 0 16px 10px; - background-color: #fff; - overflow: hidden; } - .qlbt-operation-menu .qlbt-operation-color-picker .qlbt-operation-color-picker-item { - width: 20px; - height: 20px; - border: 1px solid #595959; - margin-right: 5px; - margin-bottom: 5px; - cursor: pointer; } - .qlbt-operation-menu .qlbt-operation-menu-item { - display: flex; - align-items: center; - padding: 10px 16px; - background-color: #fff; - cursor: pointer; - color: #595959; - overflow: hidden; - text-overflow: ellipsis; } - .qlbt-operation-menu .qlbt-operation-menu-item:hover { - background-color: #efefef; } - .qlbt-operation-menu .qlbt-operation-menu-item .qlbt-operation-menu-icon { - margin-right: 8px; - height: 20px; - width: 20px; - font-size: 0; } - -.qlbt-col-tool { - position: absolute; - display: flex; - align-items: flex-end; - overflow: hidden; - z-index: 99; - height: 16px; } - .qlbt-col-tool .qlbt-col-tool-cell { - position: relative; - background-color: #fff; - border-top: 1px solid #000; - border-right: 1px solid #000; - border-bottom: 1px solid #000; } - .qlbt-col-tool .qlbt-col-tool-cell:first-child { - border-left: 1px solid #000; } - .qlbt-col-tool .qlbt-col-tool-cell-holder { - position: absolute; - right: -1px; - top: 0; - bottom: 0; - z-index: 3; - width: 1px; - background-color: transparent; - cursor: ew-resize; } - .qlbt-col-tool .qlbt-col-tool-cell-holder:hover { - background-color: #0589f3; } - .qlbt-col-tool .qlbt-col-tool-cell-holder::before { - content: ""; - position: absolute; - top: 0; - left: -6px; - display: block; - width: 8px; - height: 100%; } - .qlbt-col-tool .qlbt-col-tool-cell-holder::after { - content: ""; - position: absolute; - top: 0; - right: -6px; - display: block; - width: 8px; - height: 100%; } +.ql-container .qlbt-selection-line.qlbt-selection-line-left::before{position:absolute;left:-2px;top:-2px;content:'';width:5px;height:5px;background-color:#0589f3;border-radius:5px}.ql-container .qlbt-selection-line.qlbt-selection-line-right::before{position:absolute;right:-2px;bottom:-3px;content:'';width:5px;height:5px;background-color:#0589f3;border-radius:5px}.quill-better-table-wrapper{overflow-x:auto}table.quill-better-table{table-layout:fixed;border-collapse:collapse}table.quill-better-table td{border:1px solid #000;padding:2px 5px}.qlbt-operation-menu{background-color:#fff;box-shadow:0 2px 8px rgba(0,0,0,0.15);font-size:14px;z-index:100;overflow:hidden}.qlbt-operation-menu .qlbt-operation-menu-dividing{height:1px;background-color:#efefef}.qlbt-operation-menu .qlbt-operation-menu-subtitle{color:#999;font-size:14px;padding:5px 16px}.qlbt-operation-menu .qlbt-operation-color-picker{display:flex;align-items:center;flex-wrap:wrap;padding:0 16px 10px;background-color:#fff;overflow:hidden}.qlbt-operation-menu .qlbt-operation-color-picker .qlbt-operation-color-picker-item{width:20px;height:20px;border:1px solid #595959;margin-right:5px;margin-bottom:5px;cursor:pointer}.qlbt-operation-menu .qlbt-operation-menu-item{display:flex;align-items:center;padding:10px 16px;background-color:#fff;cursor:pointer;color:#595959;overflow:hidden;text-overflow:ellipsis}.qlbt-operation-menu .qlbt-operation-menu-item:hover{background-color:#efefef}.qlbt-operation-menu .qlbt-operation-menu-item .qlbt-operation-menu-icon{margin-right:8px;height:20px;width:20px;font-size:0}.qlbt-col-tool{position:absolute;display:flex;align-items:flex-end;overflow:hidden;z-index:99;height:16px}.qlbt-col-tool .qlbt-col-tool-cell{position:relative;background-color:#fff;border-top:1px solid #000;border-right:1px solid #000;border-bottom:1px solid #000}.qlbt-col-tool .qlbt-col-tool-cell:first-child{border-left:1px solid #000}.qlbt-col-tool .qlbt-col-tool-cell-holder{position:absolute;right:-1px;top:0;bottom:0;z-index:3;width:1px;background-color:transparent;cursor:ew-resize}.qlbt-col-tool .qlbt-col-tool-cell-holder:hover{background-color:#0589f3}.qlbt-col-tool .qlbt-col-tool-cell-holder::before{content:"";position:absolute;top:0;left:-6px;display:block;width:8px;height:100%}.qlbt-col-tool .qlbt-col-tool-cell-holder::after{content:"";position:absolute;top:0;right:-6px;display:block;width:8px;height:100%} diff --git a/dist/quill-better-table.css b/dist/quill-better-table.css index cec18b9..72d9433 100644 --- a/dist/quill-better-table.css +++ b/dist/quill-better-table.css @@ -1,117 +1,2 @@ -.ql-container .qlbt-selection-line.qlbt-selection-line-left::before { - position: absolute; - left: -2px; - top: -2px; - content: ''; - width: 5px; - height: 5px; - background-color: #0589f3; - border-radius: 5px; } - -.ql-container .qlbt-selection-line.qlbt-selection-line-right::before { - position: absolute; - right: -2px; - bottom: -3px; - content: ''; - width: 5px; - height: 5px; - background-color: #0589f3; - border-radius: 5px; } - -.quill-better-table-wrapper { - overflow-x: auto; } - -table.quill-better-table { - table-layout: fixed; - border-collapse: collapse; } - table.quill-better-table td { - border: 1px solid #000; - padding: 2px 5px; } - -.qlbt-operation-menu { - background-color: #fff; - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); - font-size: 14px; - z-index: 100; - overflow: hidden; } - .qlbt-operation-menu .qlbt-operation-menu-dividing { - height: 1px; - background-color: #efefef; } - .qlbt-operation-menu .qlbt-operation-menu-subtitle { - color: #999; - font-size: 14px; - padding: 5px 16px; } - .qlbt-operation-menu .qlbt-operation-color-picker { - display: flex; - align-items: center; - flex-wrap: wrap; - padding: 0 16px 10px; - background-color: #fff; - overflow: hidden; } - .qlbt-operation-menu .qlbt-operation-color-picker .qlbt-operation-color-picker-item { - width: 20px; - height: 20px; - border: 1px solid #595959; - margin-right: 5px; - margin-bottom: 5px; - cursor: pointer; } - .qlbt-operation-menu .qlbt-operation-menu-item { - display: flex; - align-items: center; - padding: 10px 16px; - background-color: #fff; - cursor: pointer; - color: #595959; - overflow: hidden; - text-overflow: ellipsis; } - .qlbt-operation-menu .qlbt-operation-menu-item:hover { - background-color: #efefef; } - .qlbt-operation-menu .qlbt-operation-menu-item .qlbt-operation-menu-icon { - margin-right: 8px; - height: 20px; - width: 20px; - font-size: 0; } - -.qlbt-col-tool { - position: absolute; - display: flex; - align-items: flex-end; - overflow: hidden; - z-index: 99; - height: 16px; } - .qlbt-col-tool .qlbt-col-tool-cell { - position: relative; - background-color: #fff; - border-top: 1px solid #000; - border-right: 1px solid #000; - border-bottom: 1px solid #000; } - .qlbt-col-tool .qlbt-col-tool-cell:first-child { - border-left: 1px solid #000; } - .qlbt-col-tool .qlbt-col-tool-cell-holder { - position: absolute; - right: -1px; - top: 0; - bottom: 0; - z-index: 3; - width: 1px; - background-color: transparent; - cursor: ew-resize; } - .qlbt-col-tool .qlbt-col-tool-cell-holder:hover { - background-color: #0589f3; } - .qlbt-col-tool .qlbt-col-tool-cell-holder::before { - content: ""; - position: absolute; - top: 0; - left: -6px; - display: block; - width: 8px; - height: 100%; } - .qlbt-col-tool .qlbt-col-tool-cell-holder::after { - content: ""; - position: absolute; - top: 0; - right: -6px; - display: block; - width: 8px; - height: 100%; } +.ql-container .qlbt-selection-line.qlbt-selection-line-left::before{position:absolute;left:-2px;top:-2px;content:'';width:5px;height:5px;background-color:#0589f3;border-radius:5px}.ql-container .qlbt-selection-line.qlbt-selection-line-right::before{position:absolute;right:-2px;bottom:-3px;content:'';width:5px;height:5px;background-color:#0589f3;border-radius:5px}.quill-better-table-wrapper{overflow-x:auto}table.quill-better-table{table-layout:fixed;border-collapse:collapse}table.quill-better-table td{border:1px solid #000;padding:2px 5px}.qlbt-operation-menu{background-color:#fff;box-shadow:0 2px 8px rgba(0,0,0,0.15);font-size:14px;z-index:100;overflow:hidden}.qlbt-operation-menu .qlbt-operation-menu-dividing{height:1px;background-color:#efefef}.qlbt-operation-menu .qlbt-operation-menu-subtitle{color:#999;font-size:14px;padding:5px 16px}.qlbt-operation-menu .qlbt-operation-color-picker{display:flex;align-items:center;flex-wrap:wrap;padding:0 16px 10px;background-color:#fff;overflow:hidden}.qlbt-operation-menu .qlbt-operation-color-picker .qlbt-operation-color-picker-item{width:20px;height:20px;border:1px solid #595959;margin-right:5px;margin-bottom:5px;cursor:pointer}.qlbt-operation-menu .qlbt-operation-menu-item{display:flex;align-items:center;padding:10px 16px;background-color:#fff;cursor:pointer;color:#595959;overflow:hidden;text-overflow:ellipsis}.qlbt-operation-menu .qlbt-operation-menu-item:hover{background-color:#efefef}.qlbt-operation-menu .qlbt-operation-menu-item .qlbt-operation-menu-icon{margin-right:8px;height:20px;width:20px;font-size:0}.qlbt-col-tool{position:absolute;display:flex;align-items:flex-end;overflow:hidden;z-index:99;height:16px}.qlbt-col-tool .qlbt-col-tool-cell{position:relative;background-color:#fff;border-top:1px solid #000;border-right:1px solid #000;border-bottom:1px solid #000}.qlbt-col-tool .qlbt-col-tool-cell:first-child{border-left:1px solid #000}.qlbt-col-tool .qlbt-col-tool-cell-holder{position:absolute;right:-1px;top:0;bottom:0;z-index:3;width:1px;background-color:transparent;cursor:ew-resize}.qlbt-col-tool .qlbt-col-tool-cell-holder:hover{background-color:#0589f3}.qlbt-col-tool .qlbt-col-tool-cell-holder::before{content:"";position:absolute;top:0;left:-6px;display:block;width:8px;height:100%}.qlbt-col-tool .qlbt-col-tool-cell-holder::after{content:"";position:absolute;top:0;right:-6px;display:block;width:8px;height:100%} diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 7e44cf0..681fba5 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "ced44c7892a78034ffe4"; +/******/ var hotCurrentHash = "81ae6e0616c1987a997e"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -166,6 +166,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ _declinedDependencies: {}, /******/ _selfAccepted: false, /******/ _selfDeclined: false, +/******/ _selfInvalidated: false, /******/ _disposeHandlers: [], /******/ _main: hotCurrentChildModule !== moduleId, /******/ @@ -196,6 +197,29 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var idx = hot._disposeHandlers.indexOf(callback); /******/ if (idx >= 0) hot._disposeHandlers.splice(idx, 1); /******/ }, +/******/ invalidate: function() { +/******/ this._selfInvalidated = true; +/******/ switch (hotStatus) { +/******/ case "idle": +/******/ hotUpdate = {}; +/******/ hotUpdate[moduleId] = modules[moduleId]; +/******/ hotSetStatus("ready"); +/******/ break; +/******/ case "ready": +/******/ hotApplyInvalidatedModule(moduleId); +/******/ break; +/******/ case "prepare": +/******/ case "check": +/******/ case "dispose": +/******/ case "apply": +/******/ (hotQueuedInvalidatedModules = +/******/ hotQueuedInvalidatedModules || []).push(moduleId); +/******/ break; +/******/ default: +/******/ // ignore requests in error states +/******/ break; +/******/ } +/******/ }, /******/ /******/ // Management API /******/ check: hotCheck, @@ -237,7 +261,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var hotDeferred; /******/ /******/ // The update info -/******/ var hotUpdate, hotUpdateNewHash; +/******/ var hotUpdate, hotUpdateNewHash, hotQueuedInvalidatedModules; /******/ /******/ function toModuleId(id) { /******/ var isNumber = +id + "" === id; @@ -252,7 +276,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ hotSetStatus("check"); /******/ return hotDownloadManifest(hotRequestTimeout).then(function(update) { /******/ if (!update) { -/******/ hotSetStatus("idle"); +/******/ hotSetStatus(hotApplyInvalidatedModules() ? "ready" : "idle"); /******/ return null; /******/ } /******/ hotRequestedFilesMap = {}; @@ -271,7 +295,6 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var chunkId = 2; /******/ // eslint-disable-next-line no-lone-blocks /******/ { -/******/ /*globals chunkId */ /******/ hotEnsureUpdateChunk(chunkId); /******/ } /******/ if ( @@ -346,6 +369,11 @@ return /******/ (function(modules) { // webpackBootstrap /******/ if (hotStatus !== "ready") /******/ throw new Error("apply() is only allowed in ready status"); /******/ options = options || {}; +/******/ return hotApplyInternal(options); +/******/ } +/******/ +/******/ function hotApplyInternal(options) { +/******/ hotApplyInvalidatedModules(); /******/ /******/ var cb; /******/ var i; @@ -368,7 +396,11 @@ return /******/ (function(modules) { // webpackBootstrap /******/ var moduleId = queueItem.id; /******/ var chain = queueItem.chain; /******/ module = installedModules[moduleId]; -/******/ if (!module || module.hot._selfAccepted) continue; +/******/ if ( +/******/ !module || +/******/ (module.hot._selfAccepted && !module.hot._selfInvalidated) +/******/ ) +/******/ continue; /******/ if (module.hot._selfDeclined) { /******/ return { /******/ type: "self-declined", @@ -536,10 +568,13 @@ return /******/ (function(modules) { // webpackBootstrap /******/ installedModules[moduleId] && /******/ installedModules[moduleId].hot._selfAccepted && /******/ // removed self-accepted modules should not be required -/******/ appliedUpdate[moduleId] !== warnUnexpectedRequire +/******/ appliedUpdate[moduleId] !== warnUnexpectedRequire && +/******/ // when called invalidate self-accepting is not possible +/******/ !installedModules[moduleId].hot._selfInvalidated /******/ ) { /******/ outdatedSelfAcceptedModules.push({ /******/ module: moduleId, +/******/ parents: installedModules[moduleId].parents.slice(), /******/ errorHandler: installedModules[moduleId].hot._selfAccepted /******/ }); /******/ } @@ -612,7 +647,11 @@ return /******/ (function(modules) { // webpackBootstrap /******/ // Now in "apply" phase /******/ hotSetStatus("apply"); /******/ -/******/ hotCurrentHash = hotUpdateNewHash; +/******/ if (hotUpdateNewHash !== undefined) { +/******/ hotCurrentHash = hotUpdateNewHash; +/******/ hotUpdateNewHash = undefined; +/******/ } +/******/ hotUpdate = undefined; /******/ /******/ // insert new code /******/ for (moduleId in appliedUpdate) { @@ -665,7 +704,8 @@ return /******/ (function(modules) { // webpackBootstrap /******/ for (i = 0; i < outdatedSelfAcceptedModules.length; i++) { /******/ var item = outdatedSelfAcceptedModules[i]; /******/ moduleId = item.module; -/******/ hotCurrentParents = [moduleId]; +/******/ hotCurrentParents = item.parents; +/******/ hotCurrentChildModule = moduleId; /******/ try { /******/ __webpack_require__(moduleId); /******/ } catch (err) { @@ -707,12 +747,35 @@ return /******/ (function(modules) { // webpackBootstrap /******/ return Promise.reject(error); /******/ } /******/ +/******/ if (hotQueuedInvalidatedModules) { +/******/ return hotApplyInternal(options).then(function(list) { +/******/ outdatedModules.forEach(function(moduleId) { +/******/ if (list.indexOf(moduleId) < 0) list.push(moduleId); +/******/ }); +/******/ return list; +/******/ }); +/******/ } +/******/ /******/ hotSetStatus("idle"); /******/ return new Promise(function(resolve) { /******/ resolve(outdatedModules); /******/ }); /******/ } /******/ +/******/ function hotApplyInvalidatedModules() { +/******/ if (hotQueuedInvalidatedModules) { +/******/ if (!hotUpdate) hotUpdate = {}; +/******/ hotQueuedInvalidatedModules.forEach(hotApplyInvalidatedModule); +/******/ hotQueuedInvalidatedModules = undefined; +/******/ return true; +/******/ } +/******/ } +/******/ +/******/ function hotApplyInvalidatedModule(moduleId) { +/******/ if (!Object.prototype.hasOwnProperty.call(hotUpdate, moduleId)) +/******/ hotUpdate[moduleId] = modules[moduleId]; +/******/ } +/******/ /******/ // The module cache /******/ var installedModules = {}; /******/ @@ -869,6 +932,7 @@ module.exports = "= cellsNumber) { existCells[index].remove(); @@ -1047,7 +1111,7 @@ class table_column_tool_TableColumnTool { toolCell = existCells[index]; // set tool cell min-width css(toolCell, { - 'min-width': "".concat(colWidth, "px") + 'min-width': `${colWidth}px` }); } } @@ -1084,7 +1148,7 @@ class table_column_tool_TableColumnTool { } css($helpLine, { - 'left': "".concat(cellRect.left + cellRect.width - 1 + delta, "px") + 'left': `${cellRect.left + cellRect.width - 1 + delta}px` }); } }; @@ -1098,7 +1162,7 @@ class table_column_tool_TableColumnTool { if (dragging) { colBlot.format('width', width0 + delta); css(cell, { - 'min-width': "".concat(width0 + delta, "px") + 'min-width': `${width0 + delta}px` }); x0 = 0; x = 0; @@ -1127,10 +1191,10 @@ class table_column_tool_TableColumnTool { $helpLine = document.createElement('div'); css($helpLine, { position: 'fixed', - top: "".concat(cellRect.top, "px"), - left: "".concat(cellRect.left + cellRect.width - 1, "px"), + top: `${cellRect.top}px`, + left: `${cellRect.left + cellRect.width - 1}px`, zIndex: '100', - height: "".concat(tableRect.height + COL_TOOL_HEIGHT + 4, "px"), + height: `${tableRect.height + COL_TOOL_HEIGHT + 4}px`, width: '1px', backgroundColor: PRIMARY_COLOR }); @@ -1172,10 +1236,10 @@ class header_Header extends Block { const node = super.create(value.value); CELL_IDENTITY_KEYS.forEach(key => { - if (value[key]) node.setAttribute("data-".concat(key), value[key]); + if (value[key]) node.setAttribute(`data-${key}`, value[key]); }); CELL_ATTRIBUTES.forEach(key => { - if (value[key]) node.setAttribute("data-".concat(key), value[key]); + if (value[key]) node.setAttribute(`data-${key}`, value[key]); }); return node; } @@ -1184,8 +1248,8 @@ class header_Header extends Block { const formats = {}; formats.value = this.tagName.indexOf(domNode.tagName) + 1; return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).reduce((formats, attribute) => { - if (domNode.hasAttribute("data-".concat(attribute))) { - formats[attribute] = domNode.getAttribute("data-".concat(attribute)) || undefined; + if (domNode.hasAttribute(`data-${attribute}`)) { + formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; @@ -1291,24 +1355,28 @@ class TableCellLine extends table_Block { const node = super.create(value); CELL_IDENTITY_KEYS.forEach(key => { let identityMaker = key === 'row' ? table_rowId : table_cellId; - node.setAttribute("data-".concat(key), value[key] || identityMaker()); + node.setAttribute(`data-${key}`, value[key] || identityMaker()); }); CELL_ATTRIBUTES.forEach(attrName => { - node.setAttribute("data-".concat(attrName), value[attrName] || CELL_DEFAULT[attrName]); + node.setAttribute(`data-${attrName}`, value[attrName] || CELL_DEFAULT[attrName]); }); if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']); } + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']); + } + return node; } static formats(domNode) { const formats = {}; - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg']).reduce((formats, attribute) => { - if (domNode.hasAttribute("data-".concat(attribute))) { - formats[attribute] = domNode.getAttribute("data-".concat(attribute)) || undefined; + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + if (domNode.hasAttribute(`data-${attribute}`)) { + formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; @@ -1318,9 +1386,9 @@ class TableCellLine extends table_Block { format(name, value) { if (CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).indexOf(name) > -1) { if (value) { - this.domNode.setAttribute("data-".concat(name), value); + this.domNode.setAttribute(`data-${name}`, value); } else { - this.domNode.removeAttribute("data-".concat(name)); + this.domNode.removeAttribute(`data-${name}`); } } else if (name === 'cell-bg') { if (value) { @@ -1328,6 +1396,12 @@ class TableCellLine extends table_Block { } else { this.domNode.removeAttribute('data-cell-bg'); } + } else if (name === 'cell-border') { + if (value) { + this.domNode.setAttribute('data-cell-border', value); + } else { + this.domNode.removeAttribute('data-cell-border'); + } } else if (name === 'header') { if (!value) return; const { @@ -1355,13 +1429,15 @@ class TableCellLine extends table_Block { const rowspan = this.domNode.getAttribute('data-rowspan'); const colspan = this.domNode.getAttribute('data-colspan'); const cellBg = this.domNode.getAttribute('data-cell-bg'); + const cellBorder = this.domNode.getAttribute('data-cell-border'); if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId, colspan, rowspan, - 'cell-bg': cellBg + 'cell-bg': cellBg, + 'cell-border': cellBorder }); } @@ -1392,6 +1468,7 @@ class TableCell extends Container { } static create(value) { + console.log('create tablecell with value', value); const node = super.create(value); node.setAttribute("data-row", value.row); CELL_ATTRIBUTES.forEach(attrName => { @@ -1405,6 +1482,10 @@ class TableCell extends Container { node.style.backgroundColor = value['cell-bg']; } + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']); + } + return node; } @@ -1419,6 +1500,10 @@ class TableCell extends Container { formats["cell-bg"] = domNode.getAttribute("data-cell-bg"); } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border"); + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute); @@ -1447,6 +1532,10 @@ class TableCell extends Container { formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg"); } + if (this.domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (this.domNode.hasAttribute(attribute)) { formats[attribute] = this.domNode.getAttribute(attribute); @@ -1475,7 +1564,7 @@ class TableCell extends Container { this.toggleAttribute(name, value); this.formatChildren(name, value); } else if (['row'].indexOf(name) > -1) { - this.toggleAttribute("data-".concat(name), value); + this.toggleAttribute(`data-${name}`, value); this.formatChildren(name, value); } else if (name === 'cell-bg') { this.toggleAttribute('data-cell-bg', value); @@ -1486,6 +1575,9 @@ class TableCell extends Container { } else { this.domNode.style.backgroundColor = 'initial'; } + } else if (name === 'cell-border') { + this.toggleAttribute('data-cell-border', value); + this.formatChildren(name, value); } else { super.format(name, value); } @@ -1545,8 +1637,8 @@ class TableRow extends Container { formats() { return ["row"].reduce((formats, attrName) => { - if (this.domNode.hasAttribute("data-".concat(attrName))) { - formats[attrName] = this.domNode.getAttribute("data-".concat(attrName)); + if (this.domNode.hasAttribute(`data-${attrName}`)) { + formats[attrName] = this.domNode.getAttribute(`data-${attrName}`); } return formats; @@ -1601,15 +1693,15 @@ class TableCol extends table_Block { static create(value) { let node = super.create(value); COL_ATTRIBUTES.forEach(attrName => { - node.setAttribute("".concat(attrName), value[attrName] || COL_DEFAULT[attrName]); + node.setAttribute(`${attrName}`, value[attrName] || COL_DEFAULT[attrName]); }); return node; } static formats(domNode) { return COL_ATTRIBUTES.reduce((formats, attribute) => { - if (domNode.hasAttribute("".concat(attribute))) { - formats[attribute] = domNode.getAttribute("".concat(attribute)) || undefined; + if (domNode.hasAttribute(`${attribute}`)) { + formats[attribute] = domNode.getAttribute(`${attribute}`) || undefined; } return formats; @@ -1618,7 +1710,7 @@ class TableCol extends table_Block { format(name, value) { if (COL_ATTRIBUTES.indexOf(name) > -1) { - this.domNode.setAttribute("".concat(name), value || COL_DEFAULT[name]); + this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]); } else { super.format(name, value); } @@ -1657,7 +1749,7 @@ class table_TableContainer extends Container { sumWidth = sumWidth + parseInt(col.formats()[TableCol.blotName].width, 10); return sumWidth; }, 0); - this.domNode.style.width = "".concat(tableWidth, "px"); + this.domNode.style.width = `${tableWidth}px`; }, 0); } @@ -1669,9 +1761,7 @@ class table_TableContainer extends Container { return this.children.head; } - deleteColumns(compareRect) { - let delIndexes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - let editorWrapper = arguments.length > 2 ? arguments[2] : undefined; + deleteColumns(compareRect, delIndexes = [], editorWrapper) { const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; const tableCells = this.descendants(TableCell); @@ -1808,9 +1898,7 @@ class table_TableContainer extends Container { } } - insertColumn(compareRect, colIndex) { - let isRight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; - let editorWrapper = arguments.length > 3 ? arguments[3] : undefined; + insertColumn(compareRect, colIndex, isRight = true, editorWrapper) { const [body] = this.descendants(TableBody); const [tableColGroup] = this.descendants(TableColGroup); const tableCols = this.descendants(TableCol); @@ -2094,12 +2182,12 @@ TableCol.requiredContainer = TableColGroup; function table_rowId() { const id = Math.random().toString(36).slice(2, 6); - return "row-".concat(id); + return `row-${id}`; } function table_cellId() { const id = Math.random().toString(36).slice(2, 6); - return "cell-".concat(id); + return `cell-${id}`; } @@ -2224,30 +2312,30 @@ class table_selection_TableSelection { const tableViewScrollLeft = this.table.parentNode.scrollLeft; css(this.left, { display: 'block', - left: "".concat(this.boundary.x - tableViewScrollLeft - 1, "px"), - top: "".concat(this.boundary.y, "px"), - height: "".concat(this.boundary.height + 1, "px"), + left: `${this.boundary.x - tableViewScrollLeft - 1}px`, + top: `${this.boundary.y}px`, + height: `${this.boundary.height + 1}px`, width: '1px' }); css(this.right, { display: 'block', - left: "".concat(this.boundary.x1 - tableViewScrollLeft, "px"), - top: "".concat(this.boundary.y, "px"), - height: "".concat(this.boundary.height + 1, "px"), + left: `${this.boundary.x1 - tableViewScrollLeft}px`, + top: `${this.boundary.y}px`, + height: `${this.boundary.height + 1}px`, width: '1px' }); css(this.top, { display: 'block', - left: "".concat(this.boundary.x - 1 - tableViewScrollLeft, "px"), - top: "".concat(this.boundary.y, "px"), - width: "".concat(this.boundary.width + 1, "px"), + left: `${this.boundary.x - 1 - tableViewScrollLeft}px`, + top: `${this.boundary.y}px`, + width: `${this.boundary.width + 1}px`, height: '1px' }); css(this.bottom, { display: 'block', - left: "".concat(this.boundary.x - 1 - tableViewScrollLeft, "px"), - top: "".concat(this.boundary.y1 + 1, "px"), - width: "".concat(this.boundary.width + 1, "px"), + left: `${this.boundary.x - 1 - tableViewScrollLeft}px`, + top: `${this.boundary.y1 + 1}px`, + width: `${this.boundary.width + 1}px`, height: '1px' }); } // based on selectedTds compute positions of help lines @@ -2540,20 +2628,19 @@ class table_operation_menu_TableOperationMenu { return null; } - menuInitial(_ref) { - let { - table, - left, - top - } = _ref; + menuInitial({ + table, + left, + top + }) { this.domNode = document.createElement('div'); this.domNode.classList.add('qlbt-operation-menu'); css(this.domNode, { position: 'absolute', - left: "".concat(left, "px"), - top: "".concat(top, "px"), - 'min-height': "".concat(MENU_MIN_HEIHGT, "px"), - width: "".concat(MENU_WIDTH, "px") + left: `${left}px`, + top: `${top}px`, + 'min-height': `${MENU_MIN_HEIHGT}px`, + width: `${MENU_WIDTH}px` }); for (let name in this.menuItems) { @@ -2618,12 +2705,11 @@ class table_operation_menu_TableOperationMenu { return node; } - menuItemCreator(_ref2) { - let { - text, - iconSrc, - handler - } = _ref2; + menuItemCreator({ + text, + iconSrc, + handler + }) { const node = document.createElement('div'); node.classList.add('qlbt-operation-menu-item'); const iconSpan = document.createElement('span'); @@ -2990,8 +3076,7 @@ class quill_better_table_BetterTable extends Module { }); } - getTable() { - let range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.quill.getSelection(); + getTable(range = this.quill.getSelection()) { if (range == null) return [null, null, null, -1]; const [cellLine, offset] = this.quill.getLine(range.index); @@ -3012,7 +3097,7 @@ class quill_better_table_BetterTable extends Module { let delta = new quill_better_table_Delta().retain(range.index); if (isInTableCell(currentBlot)) { - console.warn("Can not insert table into a table cell."); + console.warn(`Can not insert table into a table cell.`); return; } diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 5f39509..c480c90 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(m[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,n=!0,r="4e3f8499cfb63ceb338e",l=1e4,i={},s=[],a=[];function c(e){var t=E[e];if(!t)return T;var n=function(n){return t.hot.active?(E[n]?-1===E[n].parents.indexOf(e)&&E[n].parents.push(e):(s=[e],o=n),-1===t.children.indexOf(n)&&t.children.push(n)):(console.warn("[HMR] unexpected require("+n+") from disposed module "+e),s=[]),T(n)},r=function(e){return{configurable:!0,enumerable:!0,get:function(){return T[e]},set:function(t){T[e]=t}}};for(var l in T)Object.prototype.hasOwnProperty.call(T,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(n,l,r(l));return n.e=function(e){return"ready"===u&&p("prepare"),w++,T.e(e).then(t,function(e){throw t(),e});function t(){w--,"prepare"===u&&(v[e]||q(e),0===w&&0===g&&A())}},n.t=function(e,t){return 1&t&&(e=n(e)),T.t(e,-2&t)},n}function d(e){var t={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_disposeHandlers:[],_main:o!==e,active:!0,accept:function(e,o){if(void 0===e)t._selfAccepted=!0;else if("function"==typeof e)t._selfAccepted=e;else if("object"==typeof e)for(var n=0;n=0&&t._disposeHandlers.splice(o,1)},check:C,apply:S,status:function(e){if(!e)return u;h.push(e)},addStatusHandler:function(e){h.push(e)},removeStatusHandler:function(e){var t=h.indexOf(e);t>=0&&h.splice(t,1)},data:i[e]};return o=void 0,t}var h=[],u="idle";function p(e){u=e;for(var t=0;t0;){var r=n.pop(),l=r.id,i=r.chain;if((a=E[l])&&!a.hot._selfAccepted){if(a.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(a.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),C.type){case"self-declined":t.onDeclined&&t.onDeclined(C),t.ignoreDeclined||(q=new Error("Aborted because of self decline: "+C.moduleId+H));break;case"declined":t.onDeclined&&t.onDeclined(C),t.ignoreDeclined||(q=new Error("Aborted because of declined dependency: "+C.moduleId+" in "+C.parentId+H));break;case"unaccepted":t.onUnaccepted&&t.onUnaccepted(C),t.ignoreUnaccepted||(q=new Error("Aborted because "+c+" is not accepted"+H));break;case"accepted":t.onAccepted&&t.onAccepted(C),A=!0;break;case"disposed":t.onDisposed&&t.onDisposed(C),S=!0;break;default:throw new Error("Unexception type "+C.type)}if(q)return p("abort"),Promise.reject(q);if(A)for(c in w[c]=m[c],h(g,C.outdatedModules),C.outdatedDependencies)Object.prototype.hasOwnProperty.call(C.outdatedDependencies,c)&&(f[c]||(f[c]=[]),h(f[c],C.outdatedDependencies[c]));S&&(h(g,[C.moduleId]),w[c]=v)}var M,B=[];for(n=0;n0;)if(c=L.pop(),a=E[c]){var z={},k=a.hot._disposeHandlers;for(l=0;l=0&&I.parents.splice(M,1))}}for(c in f)if(Object.prototype.hasOwnProperty.call(f,c)&&(a=E[c]))for(R=f[c],l=0;l=0&&a.children.splice(M,1);for(c in p("apply"),r=b,w)Object.prototype.hasOwnProperty.call(w,c)&&(e[c]=w[c]);var D=null;for(c in f)if(Object.prototype.hasOwnProperty.call(f,c)&&(a=E[c])){R=f[c];var j=[];for(n=0;n'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var n=o(0),r=o.n(n);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,n)=>t.includes(n)?o:Object.assign({},o,{[n]:e[n]}),{})}function a(e){let t;if(null==(t=e.path||e.composedPath&&e.composedPath())&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}const c=12,d=12,h=50,u="#35A7ED";class p{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:"".concat(o.width,"px"),height:"".concat(c,"px"),left:"".concat(o.left-t.left+e.scrollLeft,"px"),top:"".concat(o.top-t.top+e.scrollTop-c-5,"px")})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"".concat(d,"px")}),e.appendChild(t),e}updateToolCells(){const e=r.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,n=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=n?i[e].remove():l(s=i[e],{"min-width":"".concat(r,"px")}):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":"".concat(r,"px")}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=r.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let n=!1,i=0,s=0,a=0,d=0,p={},f={},m=null;const b=e=>{e.preventDefault(),n&&(s=e.clientX,a=d+s-i>=h?s-i:h-d,l(m,{left:"".concat(f.left+f.width-1+a,"px")}))},g=r=>{r.preventDefault();const c=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),h=t.colGroup().children.at(c);n&&(h.format("width",d+a),l(e,{"min-width":"".concat(d+a,"px")}),i=0,s=0,a=0,d=0,n=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",b,!1),document.removeEventListener("mouseup",g,!1),p={},f={},m.remove(),m=null,t.updateTableWidth();const u=this.quill.getModule("better-table").tableSelection;u&&u.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",b,!1),document.addEventListener("mouseup",g,!1),p=this.table.getBoundingClientRect(),f=e.getBoundingClientRect(),l(m=document.createElement("div"),{position:"fixed",top:"".concat(f.top,"px"),left:"".concat(f.left+f.width-1,"px"),zIndex:"100",height:"".concat(p.height+c+4,"px"),width:"1px",backgroundColor:u}),document.body.appendChild(m),n=!0,i=t.clientX,d=f.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const f=r.a.import("blots/block");class m extends f{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return N.forEach(o=>{e[o]&&t.setAttribute("data-".concat(o),e[o])}),C.forEach(o=>{e[o]&&t.setAttribute("data-".concat(o),e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,C.concat(N).reduce((t,o)=>(e.hasAttribute("data-".concat(o))&&(t[o]=e.getAttribute("data-".concat(o))||void 0),t),t)}format(e,t){const{row:o,cell:n,rowspan:r,colspan:l}=m.formats(this.domNode);e===m.blotName?t?super.format(e,{value:t,row:o,cell:n,rowspan:r,colspan:l}):o?this.replaceWith(S.blotName,{row:o,cell:n,rowspan:r,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:n}=m.formats(this.domNode);if(!t||this.parent instanceof E||this.wrap(E.blotName,{row:t,colspan:n,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}m.blotName="header",m.tagName=["H1","H2","H3","H4","H5","H6"];var b=m;const g=r.a.import("blots/break"),w=r.a.import("blots/block"),v=r.a.import("blots/container"),y=["width"],x={width:100},N=["row","cell"],C=["rowspan","colspan"],q={rowspan:1,colspan:1},A=5;class S extends w{static create(e){const t=super.create(e);return N.forEach(o=>{let n="row"===o?L:z;t.setAttribute("data-".concat(o),e[o]||n())}),C.forEach(o=>{t.setAttribute("data-".concat(o),e[o]||q[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),t}static formats(e){return C.concat(N).concat(["cell-bg"]).reduce((t,o)=>(e.hasAttribute("data-".concat(o))&&(t[o]=e.getAttribute("data-".concat(o))||void 0),t),{})}format(e,t){if(C.concat(N).indexOf(e)>-1)t?this.domNode.setAttribute("data-".concat(e),t):this.domNode.removeAttribute("data-".concat(e));else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("header"===e){if(!t)return;const{row:o,cell:n,rowspan:r,colspan:l}=S.formats(this.domNode);super.format(e,{value:t,row:o,cell:n,rowspan:r,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),n=this.domNode.getAttribute("data-colspan"),r=this.domNode.getAttribute("data-cell-bg");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:n,rowspan:o,"cell-bg":r}),super.optimize(e)}tableCell(){return this.parent}}S.blotName="table-cell-line",S.className="qlbt-cell-line",S.tagName="P";class E extends v{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],n=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===n.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),C.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),C.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),C.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){C.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-".concat(e),t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}E.blotName="table",E.tagName="TD";class T extends v{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),n=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===n.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-".concat(t))&&(e[t]=this.domNode.getAttribute("data-".concat(t))),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}T.blotName="table-row",T.tagName="TR";class H extends v{}H.blotName="table-body",H.tagName="TBODY";class M extends w{static create(e){let t=super.create(e);return y.forEach(o=>{t.setAttribute("".concat(o),e[o]||x[o])}),t}static formats(e){return y.reduce((t,o)=>(e.hasAttribute("".concat(o))&&(t[o]=e.getAttribute("".concat(o))||void 0),t),{})}format(e,t){y.indexOf(e)>-1?this.domNode.setAttribute("".concat(e),t||x[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}M.blotName="table-col",M.tagName="col";class B extends v{}B.blotName="table-col-group",B.tagName="colgroup";class O extends v{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[M.blotName].width,10),0);this.domNode.style.width="".concat(t,"px")},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o=arguments.length>2?arguments[2]:void 0;const[n]=this.descendants(H);if(null==n||null==n.children.head)return;const r=this.descendants(E),l=[],s=[];if(r.forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),o);n.x+A>e.x&&n.x1-Ae.x1-A&&s.push(t)}),l.length===r.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(H);if(null==o||null==o.children.head)return;const n=this.descendants(E),r=this.descendants(T),l=[],s=[],a=[],c=r.filter(o=>{const n=i(o.domNode.getBoundingClientRect(),t);return n.y>e.y-A&&n.y1{const n=i(o.domNode.getBoundingClientRect(),t);n.y>e.y-A&&n.y1e.y1-A&&(s.push(o),Math.abs(n.y-e.y){let r=i(n.domNode.getBoundingClientRect(),t);return r.y>e.y-A&&r.y1{const o=i(e.domNode.getBoundingClientRect(),t),n=e.parent.next,r=n.children.reduce((e,n)=>{const r=i(n.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-r.x){e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-d)}),c.forEach(e=>e.remove())}tableDestroy(){const e=r.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(r.a.sources.USER)}insertCell(e,t){const o=z(),n=e.formats().row,r=this.scroll.create(E.blotName,Object.assign({},q,{row:n})),l=this.scroll.create(S.blotName,{row:n,cell:o});r.appendChild(l),t?e.insertBefore(r,t):e.appendChild(r)}insertColumn(e,t){let o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=arguments.length>3?arguments[3]:void 0;const[r]=this.descendants(H),[l]=this.descendants(B),s=this.descendants(M);let a=[],c=[],d=[];if(null==r||null==r.children.head)return;this.descendants(E).forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),n);o?Math.abs(r.x1-e.x1)A&&e.x1-r.x1<-A&&c.push(t):Math.abs(r.x-e.x)A&&e.x-r.x1<-A&&c.push(t)}),a.forEach(e=>{const t=o?e.next:e,n=z(),r=e.parent,l=r.formats().row,i=e.formats(),s=this.scroll.create(E.blotName,Object.assign({},q,{row:l,rowspan:i.rowspan})),a=this.scroll.create(S.blotName,{row:l,cell:n,rowspan:i.rowspan});s.appendChild(a),t?r.insertBefore(s,t):r.appendChild(s),d.push(s)});const h=this.scroll.create(M.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),c.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),d.push(e)}),d.sort((e,t)=>{return e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y}),this.updateTableWidth(),d}insertRow(e,t,o){const[n]=this.descendants(H);if(null==n||null==n.children.head)return;const r=this.descendants(E),l=L(),s=this.scroll.create(T.blotName,{row:l});let a=[],c=[],d=[];r.forEach(n=>{const r=i(n.domNode.getBoundingClientRect(),o);t?Math.abs(r.y1-e.y1)A&&e.y1-r.y1<-A&&c.push(n):Math.abs(r.y-e.y)A&&e.y-r.y1<-A&&c.push(n)});const h=(e,t)=>{return e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x};a.sort(h),a.forEach(e=>{const t=z(),o=e.formats(),n=this.scroll.create(E.blotName,Object.assign({},q,{row:l,colspan:o.colspan})),r=this.scroll.create(S.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(g.blotName);r.appendChild(i),n.appendChild(r),s.appendChild(n),d.push(n)}),c.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),d.push(e)});const u=this.rows().find(n=>{let r=i(n.domNode.getBoundingClientRect(),o);return t?Math.abs(r.y-e.y-e.height)(0!==r?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",n),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",n),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},n=1,r=1;e.forEach(e=>{if(o=e.formats(),n=o.rowspan,(r=o.colspan)>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=r;e>1;e--)this.insertCell(o,t)}if(n>1){let o=n,l=e.row().next;for(;o>1;){let n=l.children.reduce((o,n)=>{let r=i(e.domNode.getBoundingClientRect(),t),l=i(n.domNode.getBoundingClientRect(),t);return Math.abs(r.x1-l.x)0;e--)this.insertCell(l,n);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}O.blotName="table-container",O.className="quill-better-table",O.tagName="TABLE";class R extends v{constructor(e,t){super(e,t);const o=r.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function L(){const e=Math.random().toString(36).slice(2,6);return"row-".concat(e)}function z(){const e=Math.random().toString(36).slice(2,6);return"cell-".concat(e)}R.blotName="table-view",R.className="quill-better-table-wrapper",R.tagName="DIV",R.allowedChildren=[O],O.requiredContainer=R,O.allowedChildren=[H,B],H.requiredContainer=O,H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[E],E.requiredContainer=T,E.allowedChildren=[S,b],S.requiredContainer=E,B.allowedChildren=[M],B.requiredContainer=O,M.requiredContainer=B;const k="#0589f3",I=["left","right","top","bottom"],D=2;class j{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;I.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":k}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",r,!1),this.quill.root.addEventListener("mouseup",function e(o){t.quill.root.removeEventListener("mousemove",r,!1);t.quill.root.removeEventListener("mouseup",e,!1);t.dragging=!1},!1);const t=this,o=e.target.closest("td[data-row]"),n=i(o.getBoundingClientRect(),this.quill.root.parentNode);function r(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const r=e.target.closest("td[data-row]"),l=i(r.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=V(n,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==r&&t.quill.blur()}this.dragging=!0,this.boundary=V(n,n),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){r.a.find(this.table).descendants(E).forEach(e=>{let{x:t,y:o,width:n,height:r}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+D>=this.boundary.x&&t+D<=this.boundary.x1||t-D+n>=this.boundary.x&&t-D+n<=this.boundary.x1)&&(o+D>=this.boundary.y&&o+D<=this.boundary.y1||o-D+r>=this.boundary.y&&o-D+r<=this.boundary.y1)&&(this.boundary=V(this.boundary,{x:t,y:o,width:n,height:r}))})}computeSelectedTds(){return r.a.find(this.table).descendants(E).reduce((e,t)=>{let{x:o,y:n,width:r,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+D>=this.boundary.x&&o-D+r<=this.boundary.x1&&n+D>=this.boundary.y&&n-D+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:"".concat(this.boundary.x-e-1,"px"),top:"".concat(this.boundary.y,"px"),height:"".concat(this.boundary.height+1,"px"),width:"1px"}),l(this.right,{display:"block",left:"".concat(this.boundary.x1-e,"px"),top:"".concat(this.boundary.y,"px"),height:"".concat(this.boundary.height+1,"px"),width:"1px"}),l(this.top,{display:"block",left:"".concat(this.boundary.x-1-e,"px"),top:"".concat(this.boundary.y,"px"),width:"".concat(this.boundary.width+1,"px"),height:"1px"}),l(this.bottom,{display:"block",left:"".concat(this.boundary.x-1-e,"px"),top:"".concat(this.boundary.y1+1,"px"),width:"".concat(this.boundary.width+1,"px"),height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=V(e,t),this.repositionHelpLines()}destroy(){return I.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=V(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],I.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function V(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:n,y:r,y1:l,width:n-o,height:l-r}}var U=o(1),_=o.n(U),P=o(2),W=o.n(P),G=o(3),X=o.n(G),K=o(4),Y=o.n(K),$=o(5),J=o.n($),Q=o(6),F=o.n(Q),Z=o(7),ee=o.n(Z),te=o(8),oe=o.n(te),ne=o(9),re=o.n(ne);const le=150,ie=200,se=["white","red","yellow","blue"],ae="Background Colors",ce={insertColumnRight:{text:"Insert column right",iconSrc:_.a,handler(){const e=r.a.find(this.table);let t=he(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:W.a,handler(){const e=r.a.find(this.table);let t=he(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:X.a,handler(){const e=r.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:Y.a,handler(){const e=r.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:J.a,handler(){const e=r.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),n);return o(s,t)&&r.push(e.indexOf(l)),r},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let n=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})},!1),o}(e);o.appendChild(n)}),o}menuItemCreator(e){let{text:t,iconSrc:o,handler:n}=e;const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const l=document.createElement("span");l.classList.add("qlbt-operation-menu-icon"),l.innerHTML=o;const i=document.createElement("span");return i.classList.add("qlbt-operation-menu-text"),i.innerText=t,r.appendChild(l),r.appendChild(i),r.addEventListener("click",n.bind(this),!1),r}}function he(e,t,o,n){return e.reduce((r,l)=>{let s=i(l.getBoundingClientRect(),n);return o(s,t)&&(r=e.indexOf(l)),r},!1)}const ue=r.a.import("delta");function pe(e,t,o){const n=e.parentNode,r="TABLE"===n.parentNode.tagName?n.parentNode:n.parentNode.parentNode,l=Array.from(r.querySelectorAll("tr")),i=Array.from(n.querySelectorAll("td")),a=l.indexOf(n)+1,c=i.indexOf(e)+1,d=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new ue).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:h,colspan:d}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let n=t.insert,r=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new ue)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:h,colspan:d,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",n=0;n<3;n++)o+=("0"+Number(t[n]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var r=e.replace(/#/,"").split("");if(6===r.length)return e;if(3===r.length){var l="#";for(n=0;n{if(t.insert&&"string"==typeof t.insert){const o=[];let n=t.insert,r=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:h,colspan:d}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new ue)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:c,rowspan:h,colspan:d}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new ue)}function me(e,t,o){let n=new ue;const r=e.querySelector("tr");if(null===r)return n;const l=Array.from(r.querySelectorAll("td")).concat(Array.from(r.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length)===i&&(t=t.concat(n)),t),new ue)}}const be=r.a.import("core/module"),ge=r.a.import("delta");class we extends be{static register(){r.a.register(M,!0),r.a.register(B,!0),r.a.register(S,!0),r.a.register(E,!0),r.a.register(T,!0),r.a.register(H,!0),r.a.register(O,!0),r.a.register(R,!0),r.a.register(R,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const n=a(o);if(!n||n.length<=0)return;const r=n.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(r){if(this.table===r)return;this.table&&this.hideTableTools(),this.showTableTools(r,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const n=a(o);if(!n||n.length<=0)return;const r=n.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=n.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=n.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),r&&(this.tableOperationMenu=new de({table:r,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0});let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",pe),e.clipboard.addMatcher("th",fe),e.clipboard.addMatcher("table",me),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.quill.getSelection();if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==S.blotName)return[null,null,null,-1];const n=t.tableCell(),r=n.row();return[r.table(),r,n,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let n=this.quill.getLeaf(o.index)[0],l=(new ge).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===E.blotName||e(t.parent));var o}(n)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=L();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:z()}}),e),e)},l),this.quill.updateContents(l,r.a.sources.USER),this.quill.setSelection(o.index+t+1,r.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new p(e,t,o),this.tableSelection=new j(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ve(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const n=e?"prev":"next";if(null!=o.line[n])return!0;const l=o.line.parent,i=l.parent[n];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,n=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,n+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const n=Object.keys(t.format).reduce((e,n)=>(this.quill.scroll.query(n,o.BLOCK)&&!Array.isArray(t.format[n])&&(e[n]=t.format[n]),e),{});this.quill.insertText(e.index,"\n",n["table-cell-line"],r.a.sources.USER),this.quill.setSelection(e.index+1,r.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==n[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],r.a.sources.USER))})}},"table-cell-line up":ve(!0),"table-cell-line down":ve(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,r.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,r.a.sources.USER),!1}return!0}}};t.default=we}]).default}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,n=!0,r="0b8281906d61e728b981",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var n=function(n){return t.hot.active?(H[n]?-1===H[n].parents.indexOf(e)&&H[n].parents.push(e):(i=[e],o=n),-1===t.children.indexOf(n)&&t.children.push(n)):(console.warn("[HMR] unexpected require("+n+") from disposed module "+e),i=[]),M(n)},r=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(n,l,r(l));return n.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},n.t=function(e,t){return 1&t&&(e=n(e)),M.t(e,-2&t)},n}function d(t){var n={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)n._selfAccepted=!0;else if("function"==typeof e)n._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&n._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,n}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var r=n.pop(),l=r.id,i=r.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":n.onDeclined&&n.onDeclined(A),n.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":n.onDeclined&&n.onDeclined(A),n.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":n.onUnaccepted&&n.onUnaccepted(A),n.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":n.onAccepted&&n.onAccepted(A),T=!0;break;case"disposed":n.onDisposed&&n.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(r=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var n=o(0),r=o.n(n);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,n)=>t.includes(n)?o:Object.assign({},o,{[n]:e[n]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=r.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,n=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=n?i[e].remove():(s=i[e],l(s,{"min-width":r+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":r+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=r.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let n=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),n&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=r=>{r.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);n&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,n=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),n=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=r.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:n,rowspan:r,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:n,rowspan:r,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:n,rowspan:r,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:n}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:n,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=r.a.import("blots/break"),f=r.a.import("blots/block"),b=r.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let n="row"===o?H:M;t.setAttribute("data-"+o,e[o]||n())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:n,rowspan:r,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:n,rowspan:r,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),n=this.domNode.getAttribute("data-colspan"),r=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:n,rowspan:o,"cell-bg":r,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],n=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===n.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),n=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===n.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[n]=this.descendants(q);if(null==n||null==n.children.head)return;const r=this.descendants(N),l=[],s=[];if(r.forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),o);n.x+5>e.x&&n.x1-5e.x1-5&&s.push(t)}),l.length===r.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const n=this.descendants(N),r=this.descendants(C),l=[],s=[],a=[],d=r.filter(o=>{const n=i(o.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const n=i(o.domNode.getBoundingClientRect(),t);n.y>e.y-5&&n.y1e.y1-5&&(s.push(o),Math.abs(n.y-e.y)<5&&a.push(o))}),l.length===n.length)return void this.tableDestroy();const c=this.rows().reduce((o,n)=>{let r=i(n.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const o=i(e.domNode.getBoundingClientRect(),t),n=e.parent.next,r=n.children.reduce((e,n)=>{const r=i(n.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-r.x)<5&&(e=n),e},null);n.insertBefore(e,r),e.format("row",n.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=r.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(r.a.sources.USER)}insertCell(e,t){const o=M(),n=e.formats().row,r=this.scroll.create(N.blotName,Object.assign({},y,{row:n})),l=this.scroll.create(x.blotName,{row:n,cell:o});r.appendChild(l),t?e.insertBefore(r,t):e.appendChild(r)}insertColumn(e,t,o=!0,n){const[r]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==r||null==r.children.head)return;this.descendants(N).forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),n);o?Math.abs(r.x1-e.x1)<5?a.push(t):e.x1-r.x>5&&e.x1-r.x1<-5&&d.push(t):Math.abs(r.x-e.x)<5?a.push(t):e.x-r.x>5&&e.x-r.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,n=M(),r=e.parent,l=r.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:n,rowspan:i.rowspan});s.appendChild(a),t?r.insertBefore(s,t):r.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[n]=this.descendants(q);if(null==n||null==n.children.head)return;const r=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];r.forEach(n=>{const r=i(n.domNode.getBoundingClientRect(),o);t?Math.abs(r.y1-e.y1)<5?a.push(n):e.y1-r.y>5&&e.y1-r.y1<-5&&d.push(n):Math.abs(r.y-e.y)<5?a.push(n):e.y-r.y>5&&e.y-r.y1<-5&&d.push(n)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),n=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),r=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);r.appendChild(i),n.appendChild(r),s.appendChild(n),c.push(n)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(n=>{let r=i(n.domNode.getBoundingClientRect(),o);return t?Math.abs(r.y-e.y-e.height)<5:Math.abs(r.y-e.y)<5});return n.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,n,r){const l=t.reduce((e,t,r)=>(0!==r?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",n),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",n),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},n=1,r=1;e.forEach(e=>{if(o=e.formats(),n=o.rowspan,r=o.colspan,r>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=r;e>1;e--)this.insertCell(o,t)}if(n>1){let o=n,l=e.row().next;for(;o>1;){let n=l.children.reduce((o,n)=>{let r=i(e.domNode.getBoundingClientRect(),t),l=i(n.domNode.getBoundingClientRect(),t);return Math.abs(r.x1-l.x)<5&&(o=n),o},null);for(let e=r;e>0;e--)this.insertCell(l,n);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=r.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const B=["left","right","top","bottom"];class O{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",r,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",r,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),n=i(o.getBoundingClientRect(),this.quill.root.parentNode);function r(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const r=e.target.closest("td[data-row]"),l=i(r.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(n,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==r&&t.quill.blur()}this.dragging=!0,this.boundary=R(n,n),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){r.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:n,height:r}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+n>=this.boundary.x&&t-2+n<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+r>=this.boundary.y&&o-2+r<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:n,height:r}))})}computeSelectedTds(){return r.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:n,width:r,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+r<=this.boundary.x1&&n+2>=this.boundary.y&&n-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:n,y:r,y1:l,width:n-o,height:l-r}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=r.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=r.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=r.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=r.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=r.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),n);return o(s,t)&&r.push(e.indexOf(l)),r},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(n()));function n(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(n()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let n=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(n)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const n=document.createElement("div");n.classList.add("qlbt-operation-menu-item");const r=document.createElement("span");r.classList.add("qlbt-operation-menu-icon"),r.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,n.appendChild(r),n.appendChild(l),n.addEventListener("click",o.bind(this),!1),n}}function te(e,t,o,n){return e.reduce((r,l)=>{let s=i(l.getBoundingClientRect(),n);return o(s,t)&&(r=e.indexOf(l)),r},!1)}const oe=r.a.import("delta");function ne(e,t,o){const n=e.parentNode,r="TABLE"===n.parentNode.tagName?n.parentNode:n.parentNode.parentNode,l=Array.from(r.querySelectorAll("tr")),i=Array.from(n.querySelectorAll("td")),a=l.indexOf(n)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let n=t.insert,r=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",n=0;n<3;n++)o+=("0"+Number(t[n]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var r=e.replace(/#/,"").split("");if(6===r.length)return e;if(3===r.length){var l="#";for(n=0;n{if(t.insert&&"string"==typeof t.insert){const o=[];let n=t.insert,r=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let n=new oe;const r=e.querySelector("tr");if(null===r)return n;const l=Array.from(r.querySelectorAll("td")).concat(Array.from(r.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(n))),t),new oe)}}const ie=r.a.import("core/module"),se=r.a.import("delta");class ae extends ie{static register(){r.a.register(A,!0),r.a.register(E,!0),r.a.register(x,!0),r.a.register(N,!0),r.a.register(C,!0),r.a.register(q,!0),r.a.register(S,!0),r.a.register(T,!0),r.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const n=a(o);if(!n||n.length<=0)return;const r=n.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(r){if(this.table===r)return;this.table&&this.hideTableTools(),this.showTableTools(r,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const n=a(o);if(!n||n.length<=0)return;const r=n.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=n.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=n.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),r&&(this.tableOperationMenu=new ee({table:r,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",re),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const n=t.tableCell(),r=n.row();return[r.table(),r,n,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let n=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(n)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,r.a.sources.USER),this.quill.setSelection(o.index+t+1,r.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new O(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const n=e?"prev":"next";if(null!=o.line[n])return!0;const l=o.line.parent,i=l.parent[n];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,n=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,n+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const n=Object.keys(t.format).reduce((e,n)=>(this.quill.scroll.query(n,o.BLOCK)&&!Array.isArray(t.format[n])&&(e[n]=t.format[n]),e),{});this.quill.insertText(e.index,"\n",n["table-cell-line"],r.a.sources.USER),this.quill.setSelection(e.index+1,r.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==n[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],r.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,r.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,r.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file From e908bc5e1d797a158650b5306412976e0ebc86e1 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Fri, 2 Jul 2021 21:59:57 -0400 Subject: [PATCH 04/19] Trying to use a special border color to encode no border cells --- dist/demo/demo1.js | 10 +++++++++- dist/quill-better-table.js | 10 +++++++++- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 8 ++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 51257ce..967f7a8 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "81ae6e0616c1987a997e"; +/******/ var hotCurrentHash = "2048db6adee61e3e681f"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1504,6 +1504,12 @@ class TableCell extends Container { formats["cell-border"] = domNode.getAttribute("data-cell-border"); } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border"); + } else if (domNode.style && domNode.style.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute); @@ -1534,6 +1540,8 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); + } else if (this.domNode.style && this.domNode.style.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 681fba5..0cc115a 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "81ae6e0616c1987a997e"; +/******/ var hotCurrentHash = "2048db6adee61e3e681f"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1504,6 +1504,12 @@ class TableCell extends Container { formats["cell-border"] = domNode.getAttribute("data-cell-border"); } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border"); + } else if (domNode.style && domNode.style.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute); @@ -1534,6 +1540,8 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); + } else if (this.domNode.style && this.domNode.style.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index c480c90..2b88716 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,n=!0,r="0b8281906d61e728b981",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var n=function(n){return t.hot.active?(H[n]?-1===H[n].parents.indexOf(e)&&H[n].parents.push(e):(i=[e],o=n),-1===t.children.indexOf(n)&&t.children.push(n)):(console.warn("[HMR] unexpected require("+n+") from disposed module "+e),i=[]),M(n)},r=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(n,l,r(l));return n.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},n.t=function(e,t){return 1&t&&(e=n(e)),M.t(e,-2&t)},n}function d(t){var n={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)n._selfAccepted=!0;else if("function"==typeof e)n._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&n._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,n}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var r=n.pop(),l=r.id,i=r.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":n.onDeclined&&n.onDeclined(A),n.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":n.onDeclined&&n.onDeclined(A),n.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":n.onUnaccepted&&n.onUnaccepted(A),n.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":n.onAccepted&&n.onAccepted(A),T=!0;break;case"disposed":n.onDisposed&&n.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(r=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var n=o(0),r=o.n(n);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,n)=>t.includes(n)?o:Object.assign({},o,{[n]:e[n]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=r.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,n=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=n?i[e].remove():(s=i[e],l(s,{"min-width":r+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":r+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=r.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let n=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),n&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=r=>{r.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);n&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,n=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),n=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=r.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:n,rowspan:r,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:n,rowspan:r,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:n,rowspan:r,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:n}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:n,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=r.a.import("blots/break"),f=r.a.import("blots/block"),b=r.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let n="row"===o?H:M;t.setAttribute("data-"+o,e[o]||n())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:n,rowspan:r,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:n,rowspan:r,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),n=this.domNode.getAttribute("data-colspan"),r=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:n,rowspan:o,"cell-bg":r,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],n=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===n.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),n=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===n.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[n]=this.descendants(q);if(null==n||null==n.children.head)return;const r=this.descendants(N),l=[],s=[];if(r.forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),o);n.x+5>e.x&&n.x1-5e.x1-5&&s.push(t)}),l.length===r.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const n=this.descendants(N),r=this.descendants(C),l=[],s=[],a=[],d=r.filter(o=>{const n=i(o.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const n=i(o.domNode.getBoundingClientRect(),t);n.y>e.y-5&&n.y1e.y1-5&&(s.push(o),Math.abs(n.y-e.y)<5&&a.push(o))}),l.length===n.length)return void this.tableDestroy();const c=this.rows().reduce((o,n)=>{let r=i(n.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const o=i(e.domNode.getBoundingClientRect(),t),n=e.parent.next,r=n.children.reduce((e,n)=>{const r=i(n.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-r.x)<5&&(e=n),e},null);n.insertBefore(e,r),e.format("row",n.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=r.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(r.a.sources.USER)}insertCell(e,t){const o=M(),n=e.formats().row,r=this.scroll.create(N.blotName,Object.assign({},y,{row:n})),l=this.scroll.create(x.blotName,{row:n,cell:o});r.appendChild(l),t?e.insertBefore(r,t):e.appendChild(r)}insertColumn(e,t,o=!0,n){const[r]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==r||null==r.children.head)return;this.descendants(N).forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),n);o?Math.abs(r.x1-e.x1)<5?a.push(t):e.x1-r.x>5&&e.x1-r.x1<-5&&d.push(t):Math.abs(r.x-e.x)<5?a.push(t):e.x-r.x>5&&e.x-r.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,n=M(),r=e.parent,l=r.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:n,rowspan:i.rowspan});s.appendChild(a),t?r.insertBefore(s,t):r.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[n]=this.descendants(q);if(null==n||null==n.children.head)return;const r=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];r.forEach(n=>{const r=i(n.domNode.getBoundingClientRect(),o);t?Math.abs(r.y1-e.y1)<5?a.push(n):e.y1-r.y>5&&e.y1-r.y1<-5&&d.push(n):Math.abs(r.y-e.y)<5?a.push(n):e.y-r.y>5&&e.y-r.y1<-5&&d.push(n)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),n=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),r=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);r.appendChild(i),n.appendChild(r),s.appendChild(n),c.push(n)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(n=>{let r=i(n.domNode.getBoundingClientRect(),o);return t?Math.abs(r.y-e.y-e.height)<5:Math.abs(r.y-e.y)<5});return n.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,n,r){const l=t.reduce((e,t,r)=>(0!==r?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",n),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",n),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},n=1,r=1;e.forEach(e=>{if(o=e.formats(),n=o.rowspan,r=o.colspan,r>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=r;e>1;e--)this.insertCell(o,t)}if(n>1){let o=n,l=e.row().next;for(;o>1;){let n=l.children.reduce((o,n)=>{let r=i(e.domNode.getBoundingClientRect(),t),l=i(n.domNode.getBoundingClientRect(),t);return Math.abs(r.x1-l.x)<5&&(o=n),o},null);for(let e=r;e>0;e--)this.insertCell(l,n);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=r.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const B=["left","right","top","bottom"];class O{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",r,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",r,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),n=i(o.getBoundingClientRect(),this.quill.root.parentNode);function r(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const r=e.target.closest("td[data-row]"),l=i(r.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(n,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==r&&t.quill.blur()}this.dragging=!0,this.boundary=R(n,n),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){r.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:n,height:r}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+n>=this.boundary.x&&t-2+n<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+r>=this.boundary.y&&o-2+r<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:n,height:r}))})}computeSelectedTds(){return r.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:n,width:r,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+r<=this.boundary.x1&&n+2>=this.boundary.y&&n-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:n,y:r,y1:l,width:n-o,height:l-r}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=r.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=r.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=r.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=r.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(r.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=r.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),n);return o(s,t)&&r.push(e.indexOf(l)),r},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(n()));function n(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(n()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let n=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(n)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const n=document.createElement("div");n.classList.add("qlbt-operation-menu-item");const r=document.createElement("span");r.classList.add("qlbt-operation-menu-icon"),r.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,n.appendChild(r),n.appendChild(l),n.addEventListener("click",o.bind(this),!1),n}}function te(e,t,o,n){return e.reduce((r,l)=>{let s=i(l.getBoundingClientRect(),n);return o(s,t)&&(r=e.indexOf(l)),r},!1)}const oe=r.a.import("delta");function ne(e,t,o){const n=e.parentNode,r="TABLE"===n.parentNode.tagName?n.parentNode:n.parentNode.parentNode,l=Array.from(r.querySelectorAll("tr")),i=Array.from(n.querySelectorAll("td")),a=l.indexOf(n)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let n=t.insert,r=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",n=0;n<3;n++)o+=("0"+Number(t[n]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var r=e.replace(/#/,"").split("");if(6===r.length)return e;if(3===r.length){var l="#";for(n=0;n{if(t.insert&&"string"==typeof t.insert){const o=[];let n=t.insert,r=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let n=new oe;const r=e.querySelector("tr");if(null===r)return n;const l=Array.from(r.querySelectorAll("td")).concat(Array.from(r.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(n))),t),new oe)}}const ie=r.a.import("core/module"),se=r.a.import("delta");class ae extends ie{static register(){r.a.register(A,!0),r.a.register(E,!0),r.a.register(x,!0),r.a.register(N,!0),r.a.register(C,!0),r.a.register(q,!0),r.a.register(S,!0),r.a.register(T,!0),r.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const n=a(o);if(!n||n.length<=0)return;const r=n.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(r){if(this.table===r)return;this.table&&this.hideTableTools(),this.showTableTools(r,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const n=a(o);if(!n||n.length<=0)return;const r=n.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=n.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=n.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),r&&(this.tableOperationMenu=new ee({table:r,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",re),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const n=t.tableCell(),r=n.row();return[r.table(),r,n,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let n=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(n)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,r.a.sources.USER),this.quill.setSelection(o.index+t+1,r.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new O(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const n=e?"prev":"next";if(null!=o.line[n])return!0;const l=o.line.parent,i=l.parent[n];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,n=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,n+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const n=Object.keys(t.format).reduce((e,n)=>(this.quill.scroll.query(n,o.BLOCK)&&!Array.isArray(t.format[n])&&(e[n]=t.format[n]),e),{});this.quill.insertText(e.index,"\n",n["table-cell-line"],r.a.sources.USER),this.quill.setSelection(e.index+1,r.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==n[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],r.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,r.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,r.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="1db9110444cb03b65fe7",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 6ba62ae..6fe0345 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -171,6 +171,12 @@ class TableCell extends Container { formats["cell-border"] = domNode.getAttribute("data-cell-border") } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border") + }else if (domNode.style && domNode.style.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page + } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute) @@ -200,6 +206,8 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border") + }else if (this.domNode.style && this.domNode.style.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { From f5e21f6b6249f97e92f949cdc776e1d3948ccb82 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Fri, 2 Jul 2021 22:10:12 -0400 Subject: [PATCH 05/19] corrected the way to get border style --- dist/demo/demo1.js | 6 +++--- dist/quill-better-table.js | 6 +++--- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 967f7a8..e070f90 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "2048db6adee61e3e681f"; +/******/ var hotCurrentHash = "d2691e653a3428f55941"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1506,7 +1506,7 @@ class TableCell extends Container { if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border"); - } else if (domNode.style && domNode.style.indexOf('fefefe') >= 0) { + } else if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { formats["cell-border"] = 'none'; //this is customized for review and comment page } @@ -1540,7 +1540,7 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); - } else if (this.domNode.style && this.domNode.style.indexOf('fefefe') >= 0) { + } else if (this.domNode.style && this.domNode.style.border && this.domNode.style.border.indexOf('fefefe') >= 0) { formats["cell-border"] = 'none'; //this is customized for review and comment page } diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 0cc115a..81a69ad 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "2048db6adee61e3e681f"; +/******/ var hotCurrentHash = "d2691e653a3428f55941"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1506,7 +1506,7 @@ class TableCell extends Container { if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border"); - } else if (domNode.style && domNode.style.indexOf('fefefe') >= 0) { + } else if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { formats["cell-border"] = 'none'; //this is customized for review and comment page } @@ -1540,7 +1540,7 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); - } else if (this.domNode.style && this.domNode.style.indexOf('fefefe') >= 0) { + } else if (this.domNode.style && this.domNode.style.border && this.domNode.style.border.indexOf('fefefe') >= 0) { formats["cell-border"] = 'none'; //this is customized for review and comment page } diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 2b88716..e9f1832 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="1db9110444cb03b65fe7",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="18bbbd04052085c0ef8d",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 6fe0345..8b0b3d1 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -173,7 +173,7 @@ class TableCell extends Container { if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border") - }else if (domNode.style && domNode.style.indexOf('fefefe') >= 0) { + }else if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { formats["cell-border"] = 'none'; //this is customized for review and comment page } @@ -206,7 +206,7 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border") - }else if (this.domNode.style && this.domNode.style.indexOf('fefefe') >= 0) { + }else if (this.domNode.style && this.domNode.style.border && this.domNode.style.border.indexOf('fefefe') >= 0) { formats["cell-border"] = 'none'; //this is customized for review and comment page } From 795df6a78c90d2f847e8c82e38b519f3d0663c64 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Fri, 2 Jul 2021 22:37:17 -0400 Subject: [PATCH 06/19] adding more logging about blot creation --- dist/demo/demo1.js | 7 ++++++- dist/quill-better-table.js | 7 ++++++- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index e070f90..8fc1f9f 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "d2691e653a3428f55941"; +/******/ var hotCurrentHash = "e817703ea7dd92e498fe"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1489,6 +1489,11 @@ class TableCell extends Container { return node; } + constructor(scroll, domNode, value) { + super(scroll, domNode); + console.log('table cell constructor ', domNode, value); + } + static formats(domNode) { const formats = {}; diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 81a69ad..4521593 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "d2691e653a3428f55941"; +/******/ var hotCurrentHash = "e817703ea7dd92e498fe"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1489,6 +1489,11 @@ class TableCell extends Container { return node; } + constructor(scroll, domNode, value) { + super(scroll, domNode); + console.log('table cell constructor ', domNode, value); + } + static formats(domNode) { const formats = {}; diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index e9f1832..b73a9f6 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="18bbbd04052085c0ef8d",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="cc47a2dc89556e0597a1",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}constructor(e,t,o){super(e,t),console.log("table cell constructor ",t,o)}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 8b0b3d1..f01c3d8 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -156,6 +156,11 @@ class TableCell extends Container { return node } + constructor(scroll, domNode, value){ + super(scroll, domNode); + console.log('table cell constructor ', domNode, value); + } + static formats(domNode) { const formats = {} From bb8c793f5300cc8701cce1a6e5657dec2de366bd Mon Sep 17 00:00:00 2001 From: alex zhang Date: Fri, 2 Jul 2021 22:46:13 -0400 Subject: [PATCH 07/19] log value function --- dist/demo/demo1.js | 14 +++++++++++++- dist/quill-better-table.js | 14 +++++++++++++- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 9 +++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 8fc1f9f..b2c7886 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "e817703ea7dd92e498fe"; +/******/ var hotCurrentHash = "cd73ef7e34c0761945a3"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1489,6 +1489,18 @@ class TableCell extends Container { return node; } + static value(domNode) { + console.log('make value from ', domNode); + const value = { ...domNode.dataset + }; + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + value["cell-border"] = 'none'; //this is customized for review and comment page + } + + return value; + } + constructor(scroll, domNode, value) { super(scroll, domNode); console.log('table cell constructor ', domNode, value); diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 4521593..1b2f22e 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "e817703ea7dd92e498fe"; +/******/ var hotCurrentHash = "cd73ef7e34c0761945a3"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1489,6 +1489,18 @@ class TableCell extends Container { return node; } + static value(domNode) { + console.log('make value from ', domNode); + const value = { ...domNode.dataset + }; + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + value["cell-border"] = 'none'; //this is customized for review and comment page + } + + return value; + } + constructor(scroll, domNode, value) { super(scroll, domNode); console.log('table cell constructor ', domNode, value); diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index b73a9f6..1055f2b 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="cc47a2dc89556e0597a1",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}constructor(e,t,o){super(e,t),console.log("table cell constructor ",t,o)}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="cde6432541ddd6632e7c",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static value(e){console.log("make value from ",e);const t={...e.dataset};return e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}constructor(e,t,o){super(e,t),console.log("table cell constructor ",t,o)}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index f01c3d8..9569a49 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -156,6 +156,15 @@ class TableCell extends Container { return node } + static value(domNode) { + console.log('make value from ', domNode); + const value = {...domNode.dataset}; + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + value["cell-border"] = 'none'; //this is customized for review and comment page + } + return value; + } + constructor(scroll, domNode, value){ super(scroll, domNode); console.log('table cell constructor ', domNode, value); From 210d0175bf62b5e1fdde4c8a287e5bb201adeaf7 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 00:08:05 -0400 Subject: [PATCH 08/19] trying to add border hints onto table cell line --- dist/demo/demo1.js | 42 ++++++++++++++++++---------------- dist/quill-better-table.js | 42 ++++++++++++++++++---------------- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 39 +++++++++++++++++-------------- 4 files changed, 67 insertions(+), 58 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index b2c7886..a3e526d 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "cd73ef7e34c0761945a3"; +/******/ var hotCurrentHash = "ea2e88dbe064133451e8"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1352,6 +1352,7 @@ const ERROR_LIMIT = 5; class TableCellLine extends table_Block { static create(value) { + console.log('create tablecellline with value', value); const node = super.create(value); CELL_IDENTITY_KEYS.forEach(key => { let identityMaker = key === 'row' ? table_rowId : table_cellId; @@ -1372,15 +1373,34 @@ class TableCellLine extends table_Block { return node; } + static value(domNode) { + console.log('make value from ', domNode); + const value = { ...domNode.dataset + }; + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + value["cell-border"] = 'none'; //this is customized for review and comment page + } + + return value; + } + static formats(domNode) { + console.log('static formats', domNode); const formats = {}; - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + formats = CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; }, formats); + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page + } + + return formats; } format(name, value) { @@ -1468,7 +1488,6 @@ class TableCell extends Container { } static create(value) { - console.log('create tablecell with value', value); const node = super.create(value); node.setAttribute("data-row", value.row); CELL_ATTRIBUTES.forEach(attrName => { @@ -1489,23 +1508,6 @@ class TableCell extends Container { return node; } - static value(domNode) { - console.log('make value from ', domNode); - const value = { ...domNode.dataset - }; - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - value["cell-border"] = 'none'; //this is customized for review and comment page - } - - return value; - } - - constructor(scroll, domNode, value) { - super(scroll, domNode); - console.log('table cell constructor ', domNode, value); - } - static formats(domNode) { const formats = {}; diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 1b2f22e..ff5a7df 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "cd73ef7e34c0761945a3"; +/******/ var hotCurrentHash = "ea2e88dbe064133451e8"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1352,6 +1352,7 @@ const ERROR_LIMIT = 5; class TableCellLine extends table_Block { static create(value) { + console.log('create tablecellline with value', value); const node = super.create(value); CELL_IDENTITY_KEYS.forEach(key => { let identityMaker = key === 'row' ? table_rowId : table_cellId; @@ -1372,15 +1373,34 @@ class TableCellLine extends table_Block { return node; } + static value(domNode) { + console.log('make value from ', domNode); + const value = { ...domNode.dataset + }; + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + value["cell-border"] = 'none'; //this is customized for review and comment page + } + + return value; + } + static formats(domNode) { + console.log('static formats', domNode); const formats = {}; - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + formats = CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; }, formats); + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page + } + + return formats; } format(name, value) { @@ -1468,7 +1488,6 @@ class TableCell extends Container { } static create(value) { - console.log('create tablecell with value', value); const node = super.create(value); node.setAttribute("data-row", value.row); CELL_ATTRIBUTES.forEach(attrName => { @@ -1489,23 +1508,6 @@ class TableCell extends Container { return node; } - static value(domNode) { - console.log('make value from ', domNode); - const value = { ...domNode.dataset - }; - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - value["cell-border"] = 'none'; //this is customized for review and comment page - } - - return value; - } - - constructor(scroll, domNode, value) { - super(scroll, domNode); - console.log('table cell constructor ', domNode, value); - } - static formats(domNode) { const formats = {}; diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 1055f2b..3c49dfa 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="cde6432541ddd6632e7c",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){console.log("create tablecell with value",e);const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static value(e){console.log("make value from ",e);const t={...e.dataset};return e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}constructor(e,t,o){super(e,t),console.log("table cell constructor ",t,o)}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="13402efc66eb15126525",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return O;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),O(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return O[e]},set:function(t){O[e]=t}}};for(var l in O)Object.prototype.hasOwnProperty.call(O,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,O.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),O.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),M=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=f[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));M&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],y=["rowspan","colspan"],v={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||v[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static value(e){console.log("make value from ",e);const t={...e.dataset};return e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}static formats(e){console.log("static formats",e);const t={};return t=y.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t),e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}format(e,t){if(y.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},v,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},v,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},v,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const M=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;M.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return M.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],M.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 9569a49..7c48403 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -20,6 +20,8 @@ const ERROR_LIMIT = 5 class TableCellLine extends Block { static create(value) { + console.log('create tablecellline with value', value); + const node = super.create(value) CELL_IDENTITY_KEYS.forEach(key => { @@ -43,15 +45,33 @@ class TableCellLine extends Block { return node } + + static value(domNode) { + console.log('make value from ', domNode); + const value = {...domNode.dataset}; + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + value["cell-border"] = 'none'; //this is customized for review and comment page + } + return value; + } + static formats(domNode) { + console.log('static formats', domNode); + const formats = {} - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + formats = CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined } return formats - }, formats) + }, formats); + + if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { + formats["cell-border"] = 'none'; //this is customized for review and comment page + } + + return formats; } format(name, value) { @@ -134,7 +154,6 @@ class TableCell extends Container { } static create(value) { - console.log('create tablecell with value', value); const node = super.create(value) node.setAttribute("data-row", value.row) @@ -156,20 +175,6 @@ class TableCell extends Container { return node } - static value(domNode) { - console.log('make value from ', domNode); - const value = {...domNode.dataset}; - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - value["cell-border"] = 'none'; //this is customized for review and comment page - } - return value; - } - - constructor(scroll, domNode, value){ - super(scroll, domNode); - console.log('table cell constructor ', domNode, value); - } - static formats(domNode) { const formats = {} From d651d55c8bf1f3d1a1a4150c03d9a13ee8a1bc8b Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 00:35:40 -0400 Subject: [PATCH 09/19] get border hint fro node matchers --- src/utils/node-matchers.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index d6407bf..72992c2 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -16,6 +16,8 @@ export function matchTableCell (node, delta, scroll) { const colspan = node.getAttribute('colspan') || false const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' + const cellBorder = node.getAttribute('data-cell-border') || + (node.style && node.style.border && node.style.border.indexOf('fefefe') >= 0 ? 'none': undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { @@ -63,7 +65,7 @@ export function matchTableCell (node, delta, scroll) { newDelta.insert(op.insert, Object.assign( {}, Object.assign({}, { row: rowId }, op.attributes.table), - { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-bg': cellBg } }, + { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-bg': cellBg , 'cell-border': cellBorder} }, _omit(op.attributes, ['table']) )) } else { From c9c2372cfdde9f6e7743c506c7c3bad3a3c90b9b Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 00:36:25 -0400 Subject: [PATCH 10/19] get border hint from matchers --- dist/demo/demo1.js | 8 +++++--- dist/quill-better-table.js | 8 +++++--- dist/quill-better-table.min.js | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index a3e526d..db3898f 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "ea2e88dbe064133451e8"; +/******/ var hotCurrentHash = "7078847d86847c28bc06"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2791,7 +2791,8 @@ function matchTableCell(node, delta, scroll) { const colspan = node.getAttribute('colspan') || false; const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - // bugfix: empty table cells copied from other place will be removed unexpectedly + + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.border && node.style.border.indexOf('fefefe') >= 0 ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { @@ -2845,7 +2846,8 @@ function matchTableCell(node, delta, scroll) { cell: cellId, rowspan, colspan, - 'cell-bg': cellBg + 'cell-bg': cellBg, + 'cell-border': cellBorder } }, _omit(op.attributes, ['table']))); } else { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index ff5a7df..ba1cc74 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "ea2e88dbe064133451e8"; +/******/ var hotCurrentHash = "7078847d86847c28bc06"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2791,7 +2791,8 @@ function matchTableCell(node, delta, scroll) { const colspan = node.getAttribute('colspan') || false; const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - // bugfix: empty table cells copied from other place will be removed unexpectedly + + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.border && node.style.border.indexOf('fefefe') >= 0 ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { @@ -2845,7 +2846,8 @@ function matchTableCell(node, delta, scroll) { cell: cellId, rowspan, colspan, - 'cell-bg': cellBg + 'cell-bg': cellBg, + 'cell-border': cellBorder } }, _omit(op.attributes, ['table']))); } else { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 3c49dfa..1a9862c 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="13402efc66eb15126525",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return O;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),O(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return O[e]},set:function(t){O[e]=t}}};for(var l in O)Object.prototype.hasOwnProperty.call(O,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,O.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),O.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),M=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=f[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));M&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],y=["rowspan","colspan"],v={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||v[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static value(e){console.log("make value from ",e);const t={...e.dataset};return e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}static formats(e){console.log("static formats",e);const t={};return t=y.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t),e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}format(e,t){if(y.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},v,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},v,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},v,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const M=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;M.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return M.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],M.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor;return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="0807c0131719fa3fced6",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return O;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),O(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return O[e]},set:function(t){O[e]=t}}};for(var l in O)Object.prototype.hasOwnProperty.call(O,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,O.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),O.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),M=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=f[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));M&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],y=["rowspan","colspan"],v={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||v[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static value(e){console.log("make value from ",e);const t={...e.dataset};return e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}static formats(e){console.log("static formats",e);const t={};return t=y.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t),e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}format(e,t){if(y.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},v,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},v,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},v,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const M=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;M.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return M.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],M.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor,p=e.getAttribute("data-cell-border")||(e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0?"none":void 0);return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u,"cell-border":p}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file From 216bad6ee4dcdd7605208f9f4d559a03deb6067b Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 00:41:33 -0400 Subject: [PATCH 11/19] backing out some crazy changes --- dist/demo/demo1.js | 23 ++--------------------- dist/quill-better-table.js | 23 ++--------------------- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 20 +------------------- 4 files changed, 6 insertions(+), 62 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index db3898f..94dd4d0 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "7078847d86847c28bc06"; +/******/ var hotCurrentHash = "a9de8eb281d1acd67a59"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1373,34 +1373,15 @@ class TableCellLine extends table_Block { return node; } - static value(domNode) { - console.log('make value from ', domNode); - const value = { ...domNode.dataset - }; - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - value["cell-border"] = 'none'; //this is customized for review and comment page - } - - return value; - } - static formats(domNode) { - console.log('static formats', domNode); const formats = {}; - formats = CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; }, formats); - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page - } - - return formats; } format(name, value) { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index ba1cc74..4ec9da5 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "7078847d86847c28bc06"; +/******/ var hotCurrentHash = "a9de8eb281d1acd67a59"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1373,34 +1373,15 @@ class TableCellLine extends table_Block { return node; } - static value(domNode) { - console.log('make value from ', domNode); - const value = { ...domNode.dataset - }; - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - value["cell-border"] = 'none'; //this is customized for review and comment page - } - - return value; - } - static formats(domNode) { - console.log('static formats', domNode); const formats = {}; - formats = CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } return formats; }, formats); - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page - } - - return formats; } format(name, value) { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 1a9862c..642b17e 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="0807c0131719fa3fced6",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return O;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),O(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return O[e]},set:function(t){O[e]=t}}};for(var l in O)Object.prototype.hasOwnProperty.call(O,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,O.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),O.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),M=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=f[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));M&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],y=["rowspan","colspan"],v={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||v[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static value(e){console.log("make value from ",e);const t={...e.dataset};return e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}static formats(e){console.log("static formats",e);const t={};return t=y.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t),e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),t}format(e,t){if(y.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},v,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},v,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},v,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const M=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;M.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return M.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],M.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor,p=e.getAttribute("data-cell-border")||(e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0?"none":void 0);return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u,"cell-border":p}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="957be4b6bc4221caeeb9",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor,p=e.getAttribute("data-cell-border")||(e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0?"none":void 0);return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u,"cell-border":p}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 7c48403..3a62ac5 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -45,33 +45,15 @@ class TableCellLine extends Block { return node } - - static value(domNode) { - console.log('make value from ', domNode); - const value = {...domNode.dataset}; - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - value["cell-border"] = 'none'; //this is customized for review and comment page - } - return value; - } - static formats(domNode) { - console.log('static formats', domNode); - const formats = {} - formats = CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined } return formats }, formats); - - if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page - } - - return formats; } format(name, value) { From 62b7b59b1604e62331e4a3cb6a8364c182162025 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 00:48:27 -0400 Subject: [PATCH 12/19] log node matchers --- dist/demo/demo1.js | 3 ++- dist/quill-better-table.js | 3 ++- dist/quill-better-table.min.js | 2 +- src/utils/node-matchers.js | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 94dd4d0..8bcd094 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "a9de8eb281d1acd67a59"; +/******/ var hotCurrentHash = "76db839a5b3abaf48c4a"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2763,6 +2763,7 @@ function getColToolCellIndexesByBoundary(cells, boundary, conditionFn, container const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); // rebuild delta function matchTableCell(node, delta, scroll) { + console.log('matching node ', node); const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; const rows = Array.from(table.querySelectorAll('tr')); diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 4ec9da5..ebbb67c 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "a9de8eb281d1acd67a59"; +/******/ var hotCurrentHash = "76db839a5b3abaf48c4a"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2763,6 +2763,7 @@ function getColToolCellIndexesByBoundary(cells, boundary, conditionFn, container const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); // rebuild delta function matchTableCell(node, delta, scroll) { + console.log('matching node ', node); const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; const rows = Array.from(table.querySelectorAll('tr')); diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 642b17e..a852f3c 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="957be4b6bc4221caeeb9",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor,p=e.getAttribute("data-cell-border")||(e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0?"none":void 0);return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u,"cell-border":p}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="feba7fc13657f78c3469",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor,p=e.getAttribute("data-cell-border")||(e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0?"none":void 0);return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u,"cell-border":p}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index 72992c2..ef9dd10 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -5,6 +5,7 @@ const Delta = Quill.import('delta') // rebuild delta export function matchTableCell (node, delta, scroll) { + console.log('matching node ', node); const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode From fa550aea0368f64e0f2822f26d985729742346e9 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 01:05:32 -0400 Subject: [PATCH 13/19] compare border color by hex value --- dist/demo/demo1.js | 8 +++++--- dist/quill-better-table.js | 8 +++++--- dist/quill-better-table.min.js | 2 +- src/utils/node-matchers.js | 5 +++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 8bcd094..0cb54ae 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "76db839a5b3abaf48c4a"; +/******/ var hotCurrentHash = "a130b5c1eec08b285f20"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2774,7 +2774,8 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.border && node.style.border.indexOf('fefefe') >= 0 ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined); + console.log('calculated cellBorder', cellBorder); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { @@ -2782,7 +2783,8 @@ function matchTableCell(node, delta, scroll) { row: rowId, cell: cellId, rowspan, - colspan + colspan, + 'cell-border': cellBorder } }); return delta; diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index ebbb67c..602206a 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "76db839a5b3abaf48c4a"; +/******/ var hotCurrentHash = "a130b5c1eec08b285f20"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2774,7 +2774,8 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.border && node.style.border.indexOf('fefefe') >= 0 ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined); + console.log('calculated cellBorder', cellBorder); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { @@ -2782,7 +2783,8 @@ function matchTableCell(node, delta, scroll) { row: rowId, cell: cellId, rowspan, - colspan + colspan, + 'cell-border': cellBorder } }); return delta; diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index a852f3c..fcda9f6 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="feba7fc13657f78c3469",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}class d{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),o=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),l(this.domNode,{width:o.width+"px",height:"12px",left:o.left-t.left+e.scrollLeft+"px",top:o.top-t.top+e.scrollTop-12-5+"px"})}createToolCell(){const e=document.createElement("div");e.classList.add("qlbt-col-tool-cell");const t=document.createElement("div");return t.classList.add("qlbt-col-tool-cell-holder"),l(e,{height:"12px"}),e.appendChild(t),e}updateToolCells(){const e=n.a.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,r=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const c=n.a.import("blots/block");class h extends c{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=h.formats(this.domNode);e===h.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(x.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=h.formats(this.domNode);if(!t||this.parent instanceof N||this.wrap(N.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}h.blotName="header",h.tagName=["H1","H2","H3","H4","H5","H6"];var u=h;const p=n.a.import("blots/break"),f=n.a.import("blots/block"),b=n.a.import("blots/container"),m=["width"],g={width:100},w=["row","cell"],v=["rowspan","colspan"],y={rowspan:1,colspan:1};class x extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return w.forEach(o=>{let r="row"===o?H:M;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||y[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(w).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=x.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}x.blotName="table-cell-line",x.className="qlbt-cell-line",x.tagName="P";class N extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}N.blotName="table",N.tagName="TD";class C extends b{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}C.blotName="table-row",C.tagName="TR";class q extends b{}q.blotName="table-body",q.tagName="TBODY";class A extends f{static create(e){let t=super.create(e);return m.forEach(o=>{t.setAttribute(""+o,e[o]||g[o])}),t}static formats(e){return m.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){m.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||g[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}A.blotName="table-col",A.tagName="col";class E extends b{}E.blotName="table-col-group",E.tagName="colgroup";class S extends b{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[A.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(q);if(null==o||null==o.children.head)return;const r=this.descendants(N),n=this.descendants(C),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=M(),r=e.formats().row,n=this.scroll.create(N.blotName,Object.assign({},y,{row:r})),l=this.scroll.create(x.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(q),[l]=this.descendants(E),s=this.descendants(A);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(N).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=M(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(N.blotName,Object.assign({},y,{row:l,rowspan:i.rowspan})),a=this.scroll.create(x.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(A.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(q);if(null==r||null==r.children.head)return;const n=this.descendants(N),l=H(),s=this.scroll.create(C.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=M(),o=e.formats(),r=this.scroll.create(N.blotName,Object.assign({},y,{row:l,colspan:o.colspan})),n=this.scroll.create(x.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(p.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}S.blotName="table-container",S.className="quill-better-table",S.tagName="TABLE";class T extends b{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function H(){return"row-"+Math.random().toString(36).slice(2,6)}function M(){return"cell-"+Math.random().toString(36).slice(2,6)}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[S],S.requiredContainer=T,S.allowedChildren=[q,E],q.requiredContainer=S,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N],N.requiredContainer=C,N.allowedChildren=[x,u],x.requiredContainer=N,E.allowedChildren=[A],E.requiredContainer=S,A.requiredContainer=E;const O=["left","right","top","bottom"];class B{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=R(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=R(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(N).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=R(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(N).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=R(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=R(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function R(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var L=o(1),k=o.n(L),z=o(2),I=o.n(z),D=o(3),j=o.n(D),V=o(4),_=o.n(V),U=o(5),P=o.n(U),W=o(6),G=o.n(W),X=o(7),K=o.n(X),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const F=["white","red","yellow","blue"],Z={insertColumnRight:{text:"Insert column right",iconSrc:k.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:I.a,handler(){const e=n.a.find(this.table);let t=te(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:j.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:_.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:P.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function te(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const oe=n.a.import("delta");function re(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1,u=e.getAttribute("data-cell-bg")||e.style.backgroundColor,p=e.getAttribute("data-cell-border")||(e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0?"none":void 0);return 0===t.length()?t=(new oe).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c,"cell-bg":u,"cell-border":p}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===function(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new oe)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new oe)}function le(e,t,o){let r=new oe;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new oe)}}const ie=n.a.import("core/module"),se=n.a.import("delta");class ae extends ie{static register(){n.a.register(A,!0),n.a.register(E,!0),n.a.register(x,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(S,!0),n.a.register(T,!0),n.a.register(T,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new ee({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",re),e.clipboard.addMatcher("th",ne),e.clipboard.addMatcher("table",le),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==x.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new se).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===N.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=H();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:M()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new d(e,t,o),this.tableSelection=new B(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function de(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":de(!0),"table-cell-line down":de(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=ae}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="c4ba3fe8b9bd02167337",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const B=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),F=o(7),K=o.n(F),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#FEFEFE"===d(e.style.borderColor)?"none":void 0);return console.log("calculated cellBorder",f),0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index ef9dd10..6b181fb 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -18,12 +18,13 @@ export function matchTableCell (node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' const cellBorder = node.getAttribute('data-cell-border') || - (node.style && node.style.border && node.style.border.indexOf('fefefe') >= 0 ? 'none': undefined); + (node.style && node.style.borderColor && convertToHex(node.style.borderColor) ==='#FEFEFE' ? 'none': undefined); + console.log('calculated cellBorder', cellBorder); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { - 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } + 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-border':cellBorder } }) return delta } From 57322991cfba26011f9cfd39c4c54bf07d221dfd Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 01:15:29 -0400 Subject: [PATCH 14/19] more logging --- dist/demo/demo1.js | 11 ++++++++--- dist/quill-better-table.js | 11 ++++++++--- dist/quill-better-table.min.js | 2 +- src/utils/node-matchers.js | 7 +++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 0cb54ae..a58e862 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "a130b5c1eec08b285f20"; +/******/ var hotCurrentHash = "7b174f08c21f884d4c9d"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2774,8 +2774,13 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined); - console.log('calculated cellBorder', cellBorder); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined) || 'none'; + + if (node.style && node.style.borderColor) { + console.log('borderColor', node.style.borderColor); + console.log('converted', convertToHex(node.style.borderColor)); + } // bugfix: empty table cells copied from other place will be removed unexpectedly + if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 602206a..eecbcfe 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "a130b5c1eec08b285f20"; +/******/ var hotCurrentHash = "7b174f08c21f884d4c9d"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2774,8 +2774,13 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined); - console.log('calculated cellBorder', cellBorder); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined) || 'none'; + + if (node.style && node.style.borderColor) { + console.log('borderColor', node.style.borderColor); + console.log('converted', convertToHex(node.style.borderColor)); + } // bugfix: empty table cells copied from other place will be removed unexpectedly + if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index fcda9f6..d4da2f5 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="c4ba3fe8b9bd02167337",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const B=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),F=o(7),K=o.n(F),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#FEFEFE"===d(e.style.borderColor)?"none":void 0);return console.log("calculated cellBorder",f),0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(b[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="a33f15bbb2c4a78585ac",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(b={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=b[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==f&&(n=f,f=void 0);for(h in b=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},b=n=>{n.preventDefault();const f=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(f);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",b,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",b,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(y).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const b=n.a.import("blots/break"),f=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},y=["row","cell"],v=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return y.forEach(o=>{let r="row"===o?M:O;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(y).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(y).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends f{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(b.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const B=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),F=o(7),K=o.n(F),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,b=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#FEFEFE"===d(e.style.borderColor)?"none":void 0)||"none";return e.style&&e.style.borderColor&&(console.log("borderColor",e.style.borderColor),console.log("converted",d(e.style.borderColor))),0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":b}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":b}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index 6b181fb..65d27eb 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -18,9 +18,12 @@ export function matchTableCell (node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' const cellBorder = node.getAttribute('data-cell-border') || - (node.style && node.style.borderColor && convertToHex(node.style.borderColor) ==='#FEFEFE' ? 'none': undefined); + (node.style && node.style.borderColor && convertToHex(node.style.borderColor) ==='#FEFEFE' ? 'none': undefined) || 'none'; + if(node.style && node.style.borderColor){ - console.log('calculated cellBorder', cellBorder); + console.log('borderColor', node.style.borderColor); + console.log('converted', convertToHex(node.style.borderColor)); + } // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { From 4514db146415d13aeb54f4c341bd8becefd42fe9 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Sat, 3 Jul 2021 01:22:08 -0400 Subject: [PATCH 15/19] done logging --- dist/demo/demo1.js | 10 ++-------- dist/quill-better-table.js | 10 ++-------- dist/quill-better-table.min.js | 2 +- src/utils/node-matchers.js | 8 ++------ 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index a58e862..8831d4d 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "7b174f08c21f884d4c9d"; +/******/ var hotCurrentHash = "36b0f0cac5deaaf3ad7c"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2774,13 +2774,7 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined) || 'none'; - - if (node.style && node.style.borderColor) { - console.log('borderColor', node.style.borderColor); - console.log('converted', convertToHex(node.style.borderColor)); - } // bugfix: empty table cells copied from other place will be removed unexpectedly - + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index eecbcfe..8b1c399 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "7b174f08c21f884d4c9d"; +/******/ var hotCurrentHash = "36b0f0cac5deaaf3ad7c"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2774,13 +2774,7 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#FEFEFE' ? 'none' : undefined) || 'none'; - - if (node.style && node.style.borderColor) { - console.log('borderColor', node.style.borderColor); - console.log('converted', convertToHex(node.style.borderColor)); - } // bugfix: empty table cells copied from other place will be removed unexpectedly - + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index d4da2f5..ff6d795 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(b[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="a33f15bbb2c4a78585ac",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(b={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=b[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==f&&(n=f,f=void 0);for(h in b=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},b=n=>{n.preventDefault();const f=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(f);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",b,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",b,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(y).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const b=n.a.import("blots/break"),f=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},y=["row","cell"],v=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends f{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return y.forEach(o=>{let r="row"===o?M:O;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(y).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(y).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends f{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(b.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const B=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),F=o(7),K=o.n(F),Y=o(8),$=o.n(Y),J=o(9),Q=o.n(J);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,b=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#FEFEFE"===d(e.style.borderColor)?"none":void 0)||"none";return e.style&&e.style.borderColor&&(console.log("borderColor",e.style.borderColor),console.log("converted",d(e.style.borderColor))),0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":b}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":b}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="420b39cbc152af5a1f03",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const B=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#fefefe"===d(e.style.borderColor)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index 65d27eb..b7c5e61 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -18,12 +18,8 @@ export function matchTableCell (node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' const cellBorder = node.getAttribute('data-cell-border') || - (node.style && node.style.borderColor && convertToHex(node.style.borderColor) ==='#FEFEFE' ? 'none': undefined) || 'none'; - if(node.style && node.style.borderColor){ - - console.log('borderColor', node.style.borderColor); - console.log('converted', convertToHex(node.style.borderColor)); - } + (node.style && node.style.borderColor && convertToHex(node.style.borderColor) ==='#fefefe' ? 'none': undefined); + // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { From 9e059c2eda71c9861c04df7be32c48ee96fe3c3c Mon Sep 17 00:00:00 2001 From: alex zhang Date: Mon, 5 Jul 2021 15:01:34 -0400 Subject: [PATCH 16/19] removed logging and unneeded code --- dist/demo/demo1.js | 8 +------- dist/quill-better-table.js | 8 +------- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 8 +------- src/utils/node-matchers.js | 3 +-- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 8831d4d..4f0403c 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "36b0f0cac5deaaf3ad7c"; +/******/ var hotCurrentHash = "be97bea329b1f39220c0"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1352,7 +1352,6 @@ const ERROR_LIMIT = 5; class TableCellLine extends table_Block { static create(value) { - console.log('create tablecellline with value', value); const node = super.create(value); CELL_IDENTITY_KEYS.forEach(key => { let identityMaker = key === 'row' ? table_rowId : table_cellId; @@ -1506,8 +1505,6 @@ class TableCell extends Container { if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border"); - } else if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { @@ -1540,8 +1537,6 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); - } else if (this.domNode.style && this.domNode.style.border && this.domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { @@ -2763,7 +2758,6 @@ function getColToolCellIndexesByBoundary(cells, boundary, conditionFn, container const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); // rebuild delta function matchTableCell(node, delta, scroll) { - console.log('matching node ', node); const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; const rows = Array.from(table.querySelectorAll('tr')); diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 8b1c399..9d10d89 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "36b0f0cac5deaaf3ad7c"; +/******/ var hotCurrentHash = "be97bea329b1f39220c0"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -1352,7 +1352,6 @@ const ERROR_LIMIT = 5; class TableCellLine extends table_Block { static create(value) { - console.log('create tablecellline with value', value); const node = super.create(value); CELL_IDENTITY_KEYS.forEach(key => { let identityMaker = key === 'row' ? table_rowId : table_cellId; @@ -1506,8 +1505,6 @@ class TableCell extends Container { if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border"); - } else if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { @@ -1540,8 +1537,6 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); - } else if (this.domNode.style && this.domNode.style.border && this.domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { @@ -2763,7 +2758,6 @@ function getColToolCellIndexesByBoundary(cells, boundary, conditionFn, container const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); // rebuild delta function matchTableCell(node, delta, scroll) { - console.log('matching node ', node); const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; const rows = Array.from(table.querySelectorAll('tr')); diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index ff6d795..bdc9907 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="420b39cbc152af5a1f03",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+B));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+B));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+B));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),O=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));O&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){console.log("create tablecellline with value",e);const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:O;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")?t["cell-border"]=e.getAttribute("data-cell-border"):e.style&&e.style.border&&e.style.border.indexOf("fefefe")>=0&&(t["cell-border"]="none"),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")?e["cell-border"]=this.domNode.getAttribute("data-cell-border"):this.domNode.style&&this.domNode.style.border&&this.domNode.style.border.indexOf("fefefe")>=0&&(e["cell-border"]="none"),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=O(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=O(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=O(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function O(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const B=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;B.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return B.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],B.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){console.log("matching node ",e);const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#fefefe"===d(e.style.borderColor)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:O()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="1cb926572c3789b6e60b",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#fefefe"===d(e.style.borderColor)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 3a62ac5..7e9ea8e 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -20,8 +20,6 @@ const ERROR_LIMIT = 5 class TableCellLine extends Block { static create(value) { - console.log('create tablecellline with value', value); - const node = super.create(value) CELL_IDENTITY_KEYS.forEach(key => { @@ -174,8 +172,6 @@ class TableCell extends Container { if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border") - }else if (domNode.style && domNode.style.border && domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page } return CELL_ATTRIBUTES.reduce((formats, attribute) => { @@ -207,10 +203,8 @@ class TableCell extends Container { if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border") - }else if (this.domNode.style && this.domNode.style.border && this.domNode.style.border.indexOf('fefefe') >= 0) { - formats["cell-border"] = 'none'; //this is customized for review and comment page } - + return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (this.domNode.hasAttribute(attribute)) { formats[attribute] = this.domNode.getAttribute(attribute) diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index b7c5e61..424271f 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -5,7 +5,6 @@ const Delta = Quill.import('delta') // rebuild delta export function matchTableCell (node, delta, scroll) { - console.log('matching node ', node); const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode @@ -18,7 +17,7 @@ export function matchTableCell (node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' const cellBorder = node.getAttribute('data-cell-border') || - (node.style && node.style.borderColor && convertToHex(node.style.borderColor) ==='#fefefe' ? 'none': undefined); + (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none': undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { From 4166cfd5a52da8cc7f5d629c527fd4088f499930 Mon Sep 17 00:00:00 2001 From: alex zhang Date: Wed, 7 Jul 2021 20:54:38 -0400 Subject: [PATCH 17/19] mark border none if any of the 4 borders has color FEFEFE --- dist/demo/demo1.js | 4 ++-- dist/quill-better-table.js | 4 ++-- dist/quill-better-table.min.js | 2 +- src/utils/node-matchers.js | 6 +++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 4f0403c..762ad72 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "be97bea329b1f39220c0"; +/******/ var hotCurrentHash = "e1712f28e02eec8e7da4"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2768,7 +2768,7 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderTopColor && convertToHex(node.style.borderTopColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderRightColor && convertToHex(node.style.borderRightColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderBottomColor && convertToHex(node.style.borderBottomColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderLeftColor && convertToHex(node.style.borderLeftColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index 9d10d89..d4a6904 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "be97bea329b1f39220c0"; +/******/ var hotCurrentHash = "e1712f28e02eec8e7da4"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2768,7 +2768,7 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderTopColor && convertToHex(node.style.borderTopColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderRightColor && convertToHex(node.style.borderRightColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderBottomColor && convertToHex(node.style.borderBottomColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderLeftColor && convertToHex(node.style.borderLeftColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index bdc9907..7d4edf3 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="1cb926572c3789b6e60b",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#fefefe"===d(e.style.borderColor)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="576a83de5c4dca17c615",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=f[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(y).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},y=["row","cell"],v=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return y.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(y).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(y).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#fefefe"===d(e.style.borderColor)?"none":void 0)||(e.style&&e.style.borderTopColor&&"#fefefe"===d(e.style.borderTopColor)?"none":void 0)||(e.style&&e.style.borderRightColor&&"#fefefe"===d(e.style.borderRightColor)?"none":void 0)||(e.style&&e.style.borderBottomColor&&"#fefefe"===d(e.style.borderBottomColor)?"none":void 0)||(e.style&&e.style.borderLeftColor&&"#fefefe"===d(e.style.borderLeftColor)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index 424271f..d6af0e0 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -17,7 +17,11 @@ export function matchTableCell (node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' const cellBorder = node.getAttribute('data-cell-border') || - (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none': undefined); + (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none': undefined) || + (node.style && node.style.borderTopColor && convertToHex(node.style.borderTopColor) === '#fefefe' ? 'none': undefined) || + (node.style && node.style.borderRightColor && convertToHex(node.style.borderRightColor) === '#fefefe' ? 'none': undefined) || + (node.style && node.style.borderBottomColor && convertToHex(node.style.borderBottomColor) === '#fefefe' ? 'none': undefined) || + (node.style && node.style.borderLeftColor && convertToHex(node.style.borderLeftColor) === '#fefefe' ? 'none': undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { From e409b6fc4296eb303c138841ff690737bddbc5dd Mon Sep 17 00:00:00 2001 From: alex zhang Date: Wed, 7 Jul 2021 21:20:53 -0400 Subject: [PATCH 18/19] corrected the way of getting border color --- dist/demo/demo1.js | 5 +++-- dist/quill-better-table.js | 5 +++-- dist/quill-better-table.min.js | 2 +- src/utils/node-matchers.js | 7 ++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 762ad72..226d229 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "e1712f28e02eec8e7da4"; +/******/ var hotCurrentHash = "dc685a62a82fa8e825a4"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2768,7 +2768,8 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderTopColor && convertToHex(node.style.borderTopColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderRightColor && convertToHex(node.style.borderRightColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderBottomColor && convertToHex(node.style.borderBottomColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderLeftColor && convertToHex(node.style.borderLeftColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); + const cellBorder = node.getAttribute('data-cell-border') || (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index d4a6904..d54c1be 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "e1712f28e02eec8e7da4"; +/******/ var hotCurrentHash = "dc685a62a82fa8e825a4"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -2768,7 +2768,8 @@ function matchTableCell(node, delta, scroll) { const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const cellBorder = node.getAttribute('data-cell-border') || (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderTopColor && convertToHex(node.style.borderTopColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderRightColor && convertToHex(node.style.borderRightColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderBottomColor && convertToHex(node.style.borderBottomColor) === '#fefefe' ? 'none' : undefined) || (node.style && node.style.borderLeftColor && convertToHex(node.style.borderLeftColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); + const cellBorder = node.getAttribute('data-cell-border') || (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 7d4edf3..3befa86 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!v[e])return;for(var o in v[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="576a83de5c4dca17c615",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(y[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in v[h]=f[h],g(y,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(y,[A.moduleId]),v[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,v)Object.prototype.hasOwnProperty.call(v,h)&&(e[h]=v[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,v.concat(y).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},y=["row","cell"],v=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return y.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),v.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return v.concat(y).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(v.concat(y).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),v.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),v.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),v.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){v.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.getAttribute("data-cell-border")||(e.style&&e.style.borderColor&&"#fefefe"===d(e.style.borderColor)?"none":void 0)||(e.style&&e.style.borderTopColor&&"#fefefe"===d(e.style.borderTopColor)?"none":void 0)||(e.style&&e.style.borderRightColor&&"#fefefe"===d(e.style.borderRightColor)?"none":void 0)||(e.style&&e.style.borderBottomColor&&"#fefefe"===d(e.style.borderBottomColor)?"none":void 0)||(e.style&&e.style.borderLeftColor&&"#fefefe"===d(e.style.borderLeftColor)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":f}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":f}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="8c47f450cf52c31f39d1",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.style&&(e.style.borderColor||e.style.borderTopColor||e.style.borderRightColor||e.style.borderBottomColor||e.style.borderLeftColor),b=e.getAttribute("data-cell-border")||(f&&"#fefefe"===d(f)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":b}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":b}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index d6af0e0..57adbc6 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -16,12 +16,9 @@ export function matchTableCell (node, delta, scroll) { const colspan = node.getAttribute('colspan') || false const rowspan = node.getAttribute('rowspan') || false const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' + const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); const cellBorder = node.getAttribute('data-cell-border') || - (node.style && node.style.borderColor && convertToHex(node.style.borderColor) === '#fefefe' ? 'none': undefined) || - (node.style && node.style.borderTopColor && convertToHex(node.style.borderTopColor) === '#fefefe' ? 'none': undefined) || - (node.style && node.style.borderRightColor && convertToHex(node.style.borderRightColor) === '#fefefe' ? 'none': undefined) || - (node.style && node.style.borderBottomColor && convertToHex(node.style.borderBottomColor) === '#fefefe' ? 'none': undefined) || - (node.style && node.style.borderLeftColor && convertToHex(node.style.borderLeftColor) === '#fefefe' ? 'none': undefined); + (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none': undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { From ac9eaa00cb37685ed4d33ce16c7aceb8caade8f0 Mon Sep 17 00:00:00 2001 From: Alex Zhang Date: Thu, 1 Jun 2023 18:47:17 -0400 Subject: [PATCH 19/19] support table cell vertical align --- dist/demo/demo1.js | 558 ++++------- dist/quill-better-table.js | 552 ++++------- dist/quill-better-table.min.js | 2 +- src/formats/table.js | 1645 ++++++++++++++++---------------- src/utils/node-matchers.js | 374 ++++---- 5 files changed, 1346 insertions(+), 1785 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 226d229..1a586c9 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "dc685a62a82fa8e825a4"; +/******/ var hotCurrentHash = "c8ddfda8765e39518b2a"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -947,13 +947,13 @@ function css(domNode, rules) { } } } + /** * getRelativeRect * @param {Object} targetRect rect data for target element * @param {Element} container container element * @return {Object} an object with rect data */ - function getRelativeRect(targetRect, container) { let containerRect = container.getBoundingClientRect(); return { @@ -965,13 +965,13 @@ function getRelativeRect(targetRect, container) { height: targetRect.height }; } + /** * _omit * @param {Object} obj target Object * @param {Array} uselessKeys keys of removed properties * @return {Object} new Object without useless properties */ - function _omit(obj, uselessKeys) { return obj && Object.keys(obj).reduce((acc, key) => { return uselessKeys.includes(key) ? acc : Object.assign({}, acc, { @@ -979,6 +979,7 @@ function _omit(obj, uselessKeys) { }); }, {}); } + /** * getEventComposedPath * compatibility fixed for Event.path/Event.composedPath @@ -988,53 +989,45 @@ function _omit(obj, uselessKeys) { * @param {Event} evt * @return {Array} an array of event.path */ - function getEventComposedPath(evt) { - let path; // chrome, opera, safari, firefox - - path = evt.path || evt.composedPath && evt.composedPath(); // other: edge + let path; + // chrome, opera, safari, firefox + path = evt.path || evt.composedPath && evt.composedPath(); + // other: edge if (path == undefined && evt.target) { path = []; let target = evt.target; path.push(target); - while (target && target.parentNode) { target = target.parentNode; path.push(target); } } - return path; } function convertToHex(rgb) { - var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; // if rgb - + var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; + // if rgb if (/^(rgb|RGB)/.test(rgb)) { var color = rgb.toString().match(/\d+/g); var hex = "#"; - for (var i = 0; i < 3; i++) { hex += ("0" + Number(color[i]).toString(16)).slice(-2); } - return hex; } else if (reg.test(rgb)) { var aNum = rgb.replace(/#/, "").split(""); - if (aNum.length === 6) { return rgb; } else if (aNum.length === 3) { var numHex = "#"; - for (var i = 0; i < aNum.length; i += 1) { numHex += aNum[i] + aNum[i]; } - return numHex; } } - return rgb; } // CONCATENATED MODULE: ./src/modules/table-column-tool.js @@ -1054,7 +1047,6 @@ class table_column_tool_TableColumnTool { this.domNode = null; this.initColTool(); } - initColTool() { const parent = this.quill.root.parentNode; const tableRect = this.table.getBoundingClientRect(); @@ -1071,7 +1063,6 @@ class table_column_tool_TableColumnTool { top: `${tableViewRect.top - containerRect.top + parent.scrollTop - COL_TOOL_HEIGHT - 5}px` }); } - createToolCell() { const toolCell = document.createElement('div'); toolCell.classList.add('qlbt-col-tool-cell'); @@ -1083,45 +1074,40 @@ class table_column_tool_TableColumnTool { toolCell.appendChild(resizeHolder); return toolCell; } - updateToolCells() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const CellsInFirstRow = tableContainer.children.tail.children.head.children; const tableCols = tableContainer.colGroup().children; const cellsNumber = computeCellsNumber(CellsInFirstRow); let existCells = Array.from(this.domNode.querySelectorAll('.qlbt-col-tool-cell')); - for (let index = 0; index < Math.max(cellsNumber, existCells.length); index++) { let col = tableCols.at(index); - let colWidth = col && parseInt(col.formats()[col.statics.blotName].width, 10); // if cell already exist - + let colWidth = col && parseInt(col.formats()[col.statics.blotName].width, 10); + // if cell already exist let toolCell = null; - if (!existCells[index]) { toolCell = this.createToolCell(); this.domNode.appendChild(toolCell); - this.addColCellHolderHandler(toolCell); // set tool cell min-width - + this.addColCellHolderHandler(toolCell); + // set tool cell min-width css(toolCell, { 'min-width': `${colWidth}px` }); } else if (existCells[index] && index >= cellsNumber) { existCells[index].remove(); } else { - toolCell = existCells[index]; // set tool cell min-width - + toolCell = existCells[index]; + // set tool cell min-width css(toolCell, { 'min-width': `${colWidth}px` }); } } } - destroy() { this.domNode.remove(); return null; } - addColCellHolderHandler(cell) { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const $holder = cell.querySelector(".qlbt-col-tool-cell-holder"); @@ -1129,36 +1115,30 @@ class table_column_tool_TableColumnTool { let x0 = 0; let x = 0; let delta = 0; - let width0 = 0; // helpLine relation varrible - + let width0 = 0; + // helpLine relation varrible let tableRect = {}; let cellRect = {}; let $helpLine = null; - const handleDrag = e => { e.preventDefault(); - if (dragging) { x = e.clientX; - if (width0 + x - x0 >= CELL_MIN_WIDTH) { delta = x - x0; } else { delta = CELL_MIN_WIDTH - width0; } - css($helpLine, { 'left': `${cellRect.left + cellRect.width - 1 + delta}px` }); } }; - const handleMouseup = e => { e.preventDefault(); const existCells = Array.from(this.domNode.querySelectorAll('.qlbt-col-tool-cell')); const colIndex = existCells.indexOf(cell); const colBlot = tableContainer.colGroup().children.at(colIndex); - if (dragging) { colBlot.format('width', width0 + delta); css(cell, { @@ -1171,7 +1151,6 @@ class table_column_tool_TableColumnTool { dragging = false; $holder.classList.remove('dragging'); } - document.removeEventListener('mousemove', handleDrag, false); document.removeEventListener('mouseup', handleMouseup, false); tableRect = {}; @@ -1182,7 +1161,6 @@ class table_column_tool_TableColumnTool { const tableSelection = this.quill.getModule('better-table').tableSelection; tableSelection && tableSelection.clearSelection(); }; - const handleMousedown = e => { document.addEventListener('mousemove', handleDrag, false); document.addEventListener('mouseup', handleMouseup, false); @@ -1204,16 +1182,12 @@ class table_column_tool_TableColumnTool { width0 = cellRect.width; $holder.classList.add('dragging'); }; - $holder.addEventListener('mousedown', handleMousedown, false); } - colToolCells() { return Array.from(this.domNode.querySelectorAll('.qlbt-col-tool-cell')); } - } - function computeCellsNumber(CellsInFirstRow) { return CellsInFirstRow.reduce((sum, cell) => { const cellColspan = cell.formats().colspan; @@ -1225,7 +1199,6 @@ function computeCellsNumber(CellsInFirstRow) { const Block = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import("blots/block"); - class header_Header extends Block { static create(value) { if (typeof value === 'string') { @@ -1233,7 +1206,6 @@ class header_Header extends Block { value }; } - const node = super.create(value.value); CELL_IDENTITY_KEYS.forEach(key => { if (value[key]) node.setAttribute(`data-${key}`, value[key]); @@ -1243,7 +1215,6 @@ class header_Header extends Block { }); return node; } - static formats(domNode) { const formats = {}; formats.value = this.tagName.indexOf(domNode.tagName) + 1; @@ -1251,11 +1222,9 @@ class header_Header extends Block { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } - return formats; }, formats); } - format(name, value) { const { row, @@ -1263,7 +1232,6 @@ class header_Header extends Block { rowspan, colspan } = header_Header.formats(this.domNode); - if (name === header_Header.blotName) { if (value) { super.format(name, { @@ -1289,45 +1257,39 @@ class header_Header extends Block { super.format(name, value); } } - optimize(context) { const { row, rowspan, colspan } = header_Header.formats(this.domNode); - if (row && !(this.parent instanceof TableCell)) { this.wrap(TableCell.blotName, { row, colspan, rowspan }); - } // ShadowBlot optimize - + } + // ShadowBlot optimize this.enforceAllowedChildren(); - if (this.uiNode != null && this.uiNode !== this.domNode.firstChild) { this.domNode.insertBefore(this.uiNode, this.domNode.firstChild); } - if (this.children.length === 0) { if (this.statics.defaultChild != null) { const child = this.scroll.create(this.statics.defaultChild.blotName); - this.appendChild(child); // TODO double check if necessary + this.appendChild(child); + // TODO double check if necessary // child.optimize(context); } else { this.remove(); } - } // Block optimize - - + } + // Block optimize this.cache = {}; } - } - header_Header.blotName = 'header'; header_Header.tagName = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; /* harmony default export */ var header = (header_Header); @@ -1349,7 +1311,6 @@ const CELL_DEFAULT = { colspan: 1 }; const ERROR_LIMIT = 5; - class TableCellLine extends table_Block { static create(value) { const node = super.create(value); @@ -1360,29 +1321,26 @@ class TableCellLine extends table_Block { CELL_ATTRIBUTES.forEach(attrName => { node.setAttribute(`data-${attrName}`, value[attrName] || CELL_DEFAULT[attrName]); }); - if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']); } - if (value['cell-border']) { node.setAttribute('data-cell-border', value['cell-border']); } - + if (value['cell-valign']) { + node.setAttribute('data-cell-valign', value['cell-valign']); + } return node; } - static formats(domNode) { const formats = {}; - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border', 'cell-valign']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } - return formats; }, formats); } - format(name, value) { if (CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).indexOf(name) > -1) { if (value) { @@ -1402,6 +1360,12 @@ class TableCellLine extends table_Block { } else { this.domNode.removeAttribute('data-cell-border'); } + } else if (name === 'cell-valign') { + if (value) { + this.domNode.setAttribute(`data-${name}`, value); + } else { + this.domNode.removeAttribute(`data-${name}`); + } } else if (name === 'header') { if (!value) return; const { @@ -1421,7 +1385,6 @@ class TableCellLine extends table_Block { super.format(name, value); } } - optimize(context) { // cover shadowBlot's wrap call, pass params parentBlot initialize // needed @@ -1430,30 +1393,26 @@ class TableCellLine extends table_Block { const colspan = this.domNode.getAttribute('data-colspan'); const cellBg = this.domNode.getAttribute('data-cell-bg'); const cellBorder = this.domNode.getAttribute('data-cell-border'); - + const cellValign = this.domNode.getAttribute('data-cell-valign'); if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId, colspan, rowspan, 'cell-bg': cellBg, - 'cell-border': cellBorder + 'cell-border': cellBorder, + 'cell-valign': cellValign }); } - super.optimize(context); } - tableCell() { return this.parent; } - } - TableCellLine.blotName = "table-cell-line"; TableCellLine.className = "qlbt-cell-line"; TableCellLine.tagName = "P"; - class TableCell extends Container { checkMerge() { if (super.checkMerge() && this.next.children.head != null) { @@ -1463,10 +1422,8 @@ class TableCell extends Container { const nextTail = this.next.children.tail.formats()[this.next.children.tail.statics.blotName]; return thisHead.cell === thisTail.cell && thisHead.cell === nextHead.cell && thisHead.cell === nextTail.cell; } - return false; } - static create(value) { const node = super.create(value); node.setAttribute("data-row", value.row); @@ -1475,79 +1432,66 @@ class TableCell extends Container { node.setAttribute(attrName, value[attrName]); } }); - if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']); node.style.backgroundColor = value['cell-bg']; } - if (value['cell-border']) { node.setAttribute('data-cell-border', value['cell-border']); } - + if (value['cell-valign']) { + node.setAttribute('data-cell-valign', value['cell-valign']); + } return node; } - static formats(domNode) { const formats = {}; - if (domNode.hasAttribute("data-row")) { formats["row"] = domNode.getAttribute("data-row"); } - if (domNode.hasAttribute("data-cell-bg")) { formats["cell-bg"] = domNode.getAttribute("data-cell-bg"); } - if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border"); } - - if (domNode.hasAttribute("data-cell-border")) { - formats["cell-border"] = domNode.getAttribute("data-cell-border"); + if (domNode.hasAttribute("data-cell-valign")) { + formats["cell-valign"] = domNode.getAttribute("data-cell-valign"); } - return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute); } - return formats; }, formats); } - cellOffset() { if (this.parent) { return this.parent.children.indexOf(this); } - return -1; } - formats() { const formats = {}; - if (this.domNode.hasAttribute("data-row")) { formats["row"] = this.domNode.getAttribute("data-row"); } - if (this.domNode.hasAttribute("data-cell-bg")) { formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg"); } - if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); } - + if (this.domNode.hasAttribute("data-cell-valign")) { + formats["cell-valign"] = this.domNode.getAttribute("data-cell-valign"); + } return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (this.domNode.hasAttribute(attribute)) { formats[attribute] = this.domNode.getAttribute(attribute); } - return formats; }, formats); } - toggleAttribute(name, value) { if (value) { this.domNode.setAttribute(name, value); @@ -1555,13 +1499,11 @@ class TableCell extends Container { this.domNode.removeAttribute(name); } } - formatChildren(name, value) { this.children.forEach(child => { child.format(name, value); }); } - format(name, value) { if (CELL_ATTRIBUTES.indexOf(name) > -1) { this.toggleAttribute(name, value); @@ -1572,7 +1514,6 @@ class TableCell extends Container { } else if (name === 'cell-bg') { this.toggleAttribute('data-cell-bg', value); this.formatChildren(name, value); - if (value) { this.domNode.style.backgroundColor = value; } else { @@ -1581,44 +1522,37 @@ class TableCell extends Container { } else if (name === 'cell-border') { this.toggleAttribute('data-cell-border', value); this.formatChildren(name, value); + } else if (name === 'cell-valign') { + this.toggleAttribute('data-cell-valign', value); + this.formatChildren(name, value); } else { super.format(name, value); } } - optimize(context) { const rowId = this.domNode.getAttribute("data-row"); - if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId }); } - super.optimize(context); } - row() { return this.parent; } - rowOffset() { if (this.row()) { return this.row().rowOffset(); } - return -1; } - table() { return this.row() && this.row().table(); } - } - TableCell.blotName = "table"; TableCell.tagName = "TD"; - class TableRow extends Container { checkMerge() { if (super.checkMerge() && this.next.children.head != null) { @@ -1628,70 +1562,56 @@ class TableRow extends Container { const nextTail = this.next.children.tail.formats(); return thisHead.row === thisTail.row && thisHead.row === nextHead.row && thisHead.row === nextTail.row; } - return false; } - static create(value) { const node = super.create(value); node.setAttribute("data-row", value.row); return node; } - formats() { return ["row"].reduce((formats, attrName) => { if (this.domNode.hasAttribute(`data-${attrName}`)) { formats[attrName] = this.domNode.getAttribute(`data-${attrName}`); } - return formats; }, {}); } - optimize(context) { // optimize function of ShadowBlot if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName); - } // optimize function of ParentBlot + } + + // optimize function of ParentBlot // note: modified this optimize function because // TableRow should not be removed when the length of its children was 0 - - this.enforceAllowedChildren(); - if (this.uiNode != null && this.uiNode !== this.domNode.firstChild) { this.domNode.insertBefore(this.uiNode, this.domNode.firstChild); - } // optimize function of ContainerBlot - + } + // optimize function of ContainerBlot if (this.children.length > 0 && this.next != null && this.checkMerge()) { this.next.moveChildren(this); this.next.remove(); } } - rowOffset() { if (this.parent) { return this.parent.children.indexOf(this); } - return -1; } - table() { return this.parent && this.parent.parent; } - } - TableRow.blotName = "table-row"; TableRow.tagName = "TR"; - class TableBody extends Container {} - TableBody.blotName = "table-body"; TableBody.tagName = "TBODY"; - class TableCol extends table_Block { static create(value) { let node = super.create(value); @@ -1700,17 +1620,14 @@ class TableCol extends table_Block { }); return node; } - static formats(domNode) { return COL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(`${attribute}`)) { formats[attribute] = domNode.getAttribute(`${attribute}`) || undefined; } - return formats; }, {}); } - format(name, value) { if (COL_ATTRIBUTES.indexOf(name) > -1) { this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]); @@ -1718,32 +1635,24 @@ class TableCol extends table_Block { super.format(name, value); } } - html() { return this.domNode.outerHTML; } - } - TableCol.blotName = "table-col"; TableCol.tagName = "col"; - class TableColGroup extends Container {} - TableColGroup.blotName = "table-col-group"; TableColGroup.tagName = "colgroup"; - class table_TableContainer extends Container { static create() { let node = super.create(); return node; } - constructor(scroll, domNode) { super(scroll, domNode); this.updateTableWidth(); } - updateTableWidth() { setTimeout(() => { const colGroup = this.colGroup(); @@ -1755,16 +1664,15 @@ class table_TableContainer extends Container { this.domNode.style.width = `${tableWidth}px`; }, 0); } - cells(column) { return this.rows().map(row => row.children.at(column)); } - colGroup() { return this.children.head; } - - deleteColumns(compareRect, delIndexes = [], editorWrapper) { + deleteColumns(compareRect) { + let delIndexes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + let editorWrapper = arguments.length > 2 ? arguments[2] : undefined; const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; const tableCells = this.descendants(TableCell); @@ -1772,20 +1680,18 @@ class table_TableContainer extends Container { const modifiedCells = []; tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (cellRect.x + ERROR_LIMIT > compareRect.x && cellRect.x1 - ERROR_LIMIT < compareRect.x1) { removedCells.push(cell); } else if (cellRect.x < compareRect.x + ERROR_LIMIT && cellRect.x1 > compareRect.x1 - ERROR_LIMIT) { modifiedCells.push(cell); } }); - if (removedCells.length === tableCells.length) { this.tableDestroy(); return true; - } // remove the matches column tool cell - + } + // remove the matches column tool cell delIndexes.forEach(delIndex => { this.colGroup().children.at(delIndexes[0]).remove(); }); @@ -1799,65 +1705,56 @@ class table_TableContainer extends Container { }); this.updateTableWidth(); } - deleteRow(compareRect, editorWrapper) { const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; const tableCells = this.descendants(TableCell); const tableRows = this.descendants(TableRow); const removedCells = []; // cells to be removed - const modifiedCells = []; // cells to be modified - const fallCells = []; // cells to fall into next row + // compute rows to remove // bugfix: #21 There will be a empty tr left if delete the last row of a table - const removedRows = tableRows.filter(row => { const rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper); return rowRect.y > compareRect.y - ERROR_LIMIT && rowRect.y1 < compareRect.y1 + ERROR_LIMIT; }); tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (cellRect.y > compareRect.y - ERROR_LIMIT && cellRect.y1 < compareRect.y1 + ERROR_LIMIT) { removedCells.push(cell); } else if (cellRect.y < compareRect.y + ERROR_LIMIT && cellRect.y1 > compareRect.y1 - ERROR_LIMIT) { modifiedCells.push(cell); - if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) { fallCells.push(cell); } } }); - if (removedCells.length === tableCells.length) { this.tableDestroy(); return; - } // compute length of removed rows - + } + // compute length of removed rows const removedRowsLength = this.rows().reduce((sum, row) => { let rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper); - if (rowRect.y > compareRect.y - ERROR_LIMIT && rowRect.y1 < compareRect.y1 + ERROR_LIMIT) { sum += 1; } - return sum; - }, 0); // it must excute before the table layout changed with other operation + }, 0); + // it must excute before the table layout changed with other operation fallCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); const nextRow = cell.parent.next; const cellsInNextRow = nextRow.children; const refCell = cellsInNextRow.reduce((ref, compareCell) => { const compareRect = getRelativeRect(compareCell.domNode.getBoundingClientRect(), editorWrapper); - if (Math.abs(cellRect.x1 - compareRect.x) < ERROR_LIMIT) { ref = compareCell; } - return ref; }, null); nextRow.insertBefore(cell, refCell); @@ -1869,11 +1766,11 @@ class table_TableContainer extends Container { modifiedCells.forEach(cell => { const cellRowspan = parseInt(cell.formats().rowspan, 10); cell.format("rowspan", cellRowspan - removedRowsLength); - }); // remove selected rows + }); + // remove selected rows removedRows.forEach(row => row.remove()); } - tableDestroy() { const quill = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.scroll.domNode.parentNode); const tableModule = quill.getModule("better-table"); @@ -1881,7 +1778,6 @@ class table_TableContainer extends Container { tableModule.hideTableTools(); quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); } - insertCell(tableRow, ref) { const id = table_cellId(); const rId = tableRow.formats().row; @@ -1893,15 +1789,15 @@ class table_TableContainer extends Container { cell: id }); tableCell.appendChild(cellLine); - if (ref) { tableRow.insertBefore(tableCell, ref); } else { tableRow.appendChild(tableCell); } } - - insertColumn(compareRect, colIndex, isRight = true, editorWrapper) { + insertColumn(compareRect, colIndex) { + let isRight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + let editorWrapper = arguments.length > 3 ? arguments[3] : undefined; const [body] = this.descendants(TableBody); const [tableColGroup] = this.descendants(TableColGroup); const tableCols = this.descendants(TableCol); @@ -1912,7 +1808,6 @@ class table_TableContainer extends Container { const tableCells = this.descendants(TableCell); tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (isRight) { if (Math.abs(cellRect.x1 - compareRect.x1) < ERROR_LIMIT) { // the right of selected boundary equal to the right of table cell, @@ -1951,25 +1846,22 @@ class table_TableContainer extends Container { rowspan: cellFormats.rowspan }); tableCell.appendChild(cellLine); - if (ref) { tableRow.insertBefore(tableCell, ref); } else { tableRow.appendChild(tableCell); } - affectedCells.push(tableCell); - }); // insert new tableCol + }); + // insert new tableCol const tableCol = this.scroll.create(TableCol.blotName, true); let colRef = isRight ? tableCols[colIndex].next : tableCols[colIndex]; - if (colRef) { tableColGroup.insertBefore(tableCol, colRef); } else { tableColGroup.appendChild(tableCol); } - modifiedCells.forEach(cell => { const cellColspan = cell.formats().colspan; cell.format('colspan', parseInt(cellColspan, 10) + 1); @@ -1983,7 +1875,6 @@ class table_TableContainer extends Container { this.updateTableWidth(); return affectedCells; } - insertRow(compareRect, isDown, editorWrapper) { const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; @@ -1997,7 +1888,6 @@ class table_TableContainer extends Container { let affectedCells = []; tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (isDown) { if (Math.abs(cellRect.y1 - compareRect.y1) < ERROR_LIMIT) { addBelowCells.push(cell); @@ -2011,15 +1901,15 @@ class table_TableContainer extends Container { modifiedCells.push(cell); } } - }); // ordered table cells with rect.x, fix error for inserting - // new table cell in complicated table with wrong order. + }); + // ordered table cells with rect.x, fix error for inserting + // new table cell in complicated table with wrong order. const sortFunc = (cellA, cellB) => { let x1 = cellA.domNode.getBoundingClientRect().x; let x2 = cellB.domNode.getBoundingClientRect().x; return x1 - x2; }; - addBelowCells.sort(sortFunc); addBelowCells.forEach(cell => { const cId = table_cellId(); @@ -2046,19 +1936,18 @@ class table_TableContainer extends Container { }); const refRow = this.rows().find(row => { let rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper); - if (isDown) { return Math.abs(rowRect.y - compareRect.y - compareRect.height) < ERROR_LIMIT; } else { return Math.abs(rowRect.y - compareRect.y) < ERROR_LIMIT; } }); - body.insertBefore(newRow, refRow); // reordering affectedCells + body.insertBefore(newRow, refRow); + // reordering affectedCells affectedCells.sort(sortFunc); return affectedCells; } - mergeCells(compareRect, mergingCells, rowspan, colspan, editorWrapper) { const mergedCell = mergingCells.reduce((result, tableCell, index) => { if (index !== 0) { @@ -2069,7 +1958,6 @@ class table_TableContainer extends Container { tableCell.format('rowspan', rowspan); result = tableCell; } - return result; }, null); let rowId = mergedCell.domNode.getAttribute('data-row'); @@ -2082,7 +1970,6 @@ class table_TableContainer extends Container { }); return mergedCell; } - unmergeCells(unmergingCells, editorWrapper) { let cellFormats = {}; let cellRowspan = 1; @@ -2091,81 +1978,63 @@ class table_TableContainer extends Container { cellFormats = tableCell.formats(); cellRowspan = cellFormats.rowspan; cellColspan = cellFormats.colspan; - if (cellColspan > 1) { let ref = tableCell.next; let row = tableCell.row(); tableCell.format('colspan', 1); - for (let i = cellColspan; i > 1; i--) { this.insertCell(row, ref); } } - if (cellRowspan > 1) { let i = cellRowspan; let nextRow = tableCell.row().next; - while (i > 1) { let refInNextRow = nextRow.children.reduce((result, cell) => { let compareRect = getRelativeRect(tableCell.domNode.getBoundingClientRect(), editorWrapper); let cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (Math.abs(compareRect.x1 - cellRect.x) < ERROR_LIMIT) { result = cell; } - return result; }, null); - for (let i = cellColspan; i > 0; i--) { this.insertCell(nextRow, refInNextRow); } - i -= 1; nextRow = nextRow.next; } - tableCell.format('rowspan', 1); } }); } - rows() { const body = this.children.tail; if (body == null) return []; return body.children.map(row => row); } - } - table_TableContainer.blotName = "table-container"; table_TableContainer.className = "quill-better-table"; table_TableContainer.tagName = "TABLE"; - class table_TableViewWrapper extends Container { constructor(scroll, domNode) { super(scroll, domNode); const quill = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(scroll.domNode.parentNode); domNode.addEventListener('scroll', e => { const tableModule = quill.getModule('better-table'); - if (tableModule.columnTool) { tableModule.columnTool.domNode.scrollLeft = e.target.scrollLeft; } - if (tableModule.tableSelection && tableModule.tableSelection.selectedTds.length > 0) { tableModule.tableSelection.repositionHelpLines(); } }, false); } - table() { return this.children.head; } - } - table_TableViewWrapper.blotName = "table-view"; table_TableViewWrapper.className = "quill-better-table-wrapper"; table_TableViewWrapper.tagName = "DIV"; @@ -2182,18 +2051,15 @@ TableCellLine.requiredContainer = TableCell; TableColGroup.allowedChildren = [TableCol]; TableColGroup.requiredContainer = table_TableContainer; TableCol.requiredContainer = TableColGroup; - function table_rowId() { const id = Math.random().toString(36).slice(2, 6); return `row-${id}`; } - function table_cellId() { const id = Math.random().toString(36).slice(2, 6); return `cell-${id}`; } - // CONCATENATED MODULE: ./src/modules/table-selection.js @@ -2208,9 +2074,7 @@ class table_selection_TableSelection { this.quill = quill; this.options = options; this.boundary = {}; // params for selected square - this.selectedTds = []; // array for selected table-cells - this.dragging = false; this.selectingHandler = this.mouseDownHandler.bind(this); this.clearSelectionHandler = this.clearSelection.bind(this); @@ -2218,7 +2082,6 @@ class table_selection_TableSelection { this.quill.root.addEventListener('mousedown', this.selectingHandler, false); this.quill.on('text-change', this.clearSelectionHandler); } - helpLinesInitial() { let parent = this.quill.root.parentNode; LINE_POSITIONS.forEach(direction => { @@ -2233,7 +2096,6 @@ class table_selection_TableSelection { parent.appendChild(this[direction]); }); } - mouseDownHandler(e) { if (e.button !== 0 || !e.target.closest(".quill-better-table")) return; this.quill.root.addEventListener('mousemove', mouseMoveHandler, false); @@ -2246,7 +2108,6 @@ class table_selection_TableSelection { this.correctBoundary(); this.selectedTds = this.computeSelectedTds(); this.repositionHelpLines(); - function mouseMoveHandler(e) { if (e.button !== 0 || !e.target.closest(".quill-better-table")) return; const endTd = e.target.closest('td[data-row]'); @@ -2254,20 +2115,19 @@ class table_selection_TableSelection { self.boundary = computeBoundaryFromRects(startTdRect, endTdRect); self.correctBoundary(); self.selectedTds = self.computeSelectedTds(); - self.repositionHelpLines(); // avoid select text in multiple table-cell + self.repositionHelpLines(); + // avoid select text in multiple table-cell if (startTd !== endTd) { self.quill.blur(); } } - function mouseUpHandler(e) { self.quill.root.removeEventListener('mousemove', mouseMoveHandler, false); self.quill.root.removeEventListener('mouseup', mouseUpHandler, false); self.dragging = false; } } - correctBoundary() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const tableCells = tableContainer.descendants(TableCell); @@ -2279,7 +2139,6 @@ class table_selection_TableSelection { height } = getRelativeRect(tableCell.domNode.getBoundingClientRect(), this.quill.root.parentNode); let isCellIntersected = (x + table_selection_ERROR_LIMIT >= this.boundary.x && x + table_selection_ERROR_LIMIT <= this.boundary.x1 || x - table_selection_ERROR_LIMIT + width >= this.boundary.x && x - table_selection_ERROR_LIMIT + width <= this.boundary.x1) && (y + table_selection_ERROR_LIMIT >= this.boundary.y && y + table_selection_ERROR_LIMIT <= this.boundary.y1 || y - table_selection_ERROR_LIMIT + height >= this.boundary.y && y - table_selection_ERROR_LIMIT + height <= this.boundary.y1); - if (isCellIntersected) { this.boundary = computeBoundaryFromRects(this.boundary, { x, @@ -2290,7 +2149,6 @@ class table_selection_TableSelection { } }); } - computeSelectedTds() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const tableCells = tableContainer.descendants(TableCell); @@ -2302,15 +2160,12 @@ class table_selection_TableSelection { height } = getRelativeRect(tableCell.domNode.getBoundingClientRect(), this.quill.root.parentNode); let isCellIncluded = x + table_selection_ERROR_LIMIT >= this.boundary.x && x - table_selection_ERROR_LIMIT + width <= this.boundary.x1 && y + table_selection_ERROR_LIMIT >= this.boundary.y && y - table_selection_ERROR_LIMIT + height <= this.boundary.y1; - if (isCellIncluded) { selectedCells.push(tableCell); } - return selectedCells; }, []); } - repositionHelpLines() { const tableViewScrollLeft = this.table.parentNode.scrollLeft; css(this.left, { @@ -2341,17 +2196,16 @@ class table_selection_TableSelection { width: `${this.boundary.width + 1}px`, height: '1px' }); - } // based on selectedTds compute positions of help lines - // It is useful when selectedTds are not changed - + } + // based on selectedTds compute positions of help lines + // It is useful when selectedTds are not changed refreshHelpLinesPosition() { const startRect = getRelativeRect(this.selectedTds[0].domNode.getBoundingClientRect(), this.quill.root.parentNode); const endRect = getRelativeRect(this.selectedTds[this.selectedTds.length - 1].domNode.getBoundingClientRect(), this.quill.root.parentNode); this.boundary = computeBoundaryFromRects(startRect, endRect); this.repositionHelpLines(); } - destroy() { LINE_POSITIONS.forEach(direction => { this[direction].remove(); @@ -2361,14 +2215,12 @@ class table_selection_TableSelection { this.quill.off('text-change', this.clearSelectionHandler); return null; } - setSelection(startRect, endRect) { this.boundary = computeBoundaryFromRects(getRelativeRect(startRect, this.quill.root.parentNode), getRelativeRect(endRect, this.quill.root.parentNode)); this.correctBoundary(); this.selectedTds = this.computeSelectedTds(); this.repositionHelpLines(); } - clearSelection() { this.boundary = {}; this.selectedTds = []; @@ -2378,9 +2230,7 @@ class table_selection_TableSelection { }); }); } - } - function computeBoundaryFromRects(startRect, endRect) { let x = Math.min(startRect.x, endRect.x, startRect.x + startRect.width - 1, endRect.x + endRect.width - 1); let x1 = Math.max(startRect.x, endRect.x, startRect.x + startRect.width - 1, endRect.x + endRect.width - 1); @@ -2435,9 +2285,10 @@ var icon_operation_9_default = /*#__PURE__*/__webpack_require__.n(icon_operation // CONCATENATED MODULE: ./src/modules/table-operation-menu.js - // svg icons +// svg icons + @@ -2455,7 +2306,6 @@ const MENU_ITEMS_DEFAULT = { insertColumnRight: { text: 'Insert column right', iconSrc: icon_operation_1_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); let colIndex = getColToolCellIndexByBoundary(this.columnToolCells, this.boundary, (cellRect, boundary) => { @@ -2467,12 +2317,10 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(newColumn[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(newColumn[0].domNode.getBoundingClientRect(), newColumn[0].domNode.getBoundingClientRect()); } - }, insertColumnLeft: { text: 'Insert column left', iconSrc: icon_operation_2_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); let colIndex = getColToolCellIndexByBoundary(this.columnToolCells, this.boundary, (cellRect, boundary) => { @@ -2484,12 +2332,10 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(newColumn[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(newColumn[0].domNode.getBoundingClientRect(), newColumn[0].domNode.getBoundingClientRect()); } - }, insertRowUp: { text: 'Insert row up', iconSrc: icon_operation_3_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const affectedCells = tableContainer.insertRow(this.boundary, false, this.quill.root.parentNode); @@ -2497,12 +2343,10 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(affectedCells[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(affectedCells[0].domNode.getBoundingClientRect(), affectedCells[0].domNode.getBoundingClientRect()); } - }, insertRowDown: { text: 'Insert row down', iconSrc: icon_operation_4_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const affectedCells = tableContainer.insertRow(this.boundary, true, this.quill.root.parentNode); @@ -2510,87 +2354,73 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(affectedCells[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(affectedCells[0].domNode.getBoundingClientRect(), affectedCells[0].domNode.getBoundingClientRect()); } - }, mergeCells: { text: 'Merge selected cells', iconSrc: icon_operation_5_default.a, - handler() { - const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); // compute merged Cell rowspan, equal to length of selected rows - + const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); + // compute merged Cell rowspan, equal to length of selected rows const rowspan = tableContainer.rows().reduce((sum, row) => { let rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), this.quill.root.parentNode); - if (rowRect.y > this.boundary.y - table_operation_menu_ERROR_LIMIT && rowRect.y + rowRect.height < this.boundary.y + this.boundary.height + table_operation_menu_ERROR_LIMIT) { sum += 1; } - return sum; - }, 0); // compute merged cell colspan, equal to length of selected cols + }, 0); + // compute merged cell colspan, equal to length of selected cols const colspan = this.columnToolCells.reduce((sum, cell) => { let cellRect = getRelativeRect(cell.getBoundingClientRect(), this.quill.root.parentNode); - if (cellRect.x > this.boundary.x - table_operation_menu_ERROR_LIMIT && cellRect.x + cellRect.width < this.boundary.x + this.boundary.width + table_operation_menu_ERROR_LIMIT) { sum += 1; } - return sum; }, 0); const mergedCell = tableContainer.mergeCells(this.boundary, this.selectedTds, rowspan, colspan, this.quill.root.parentNode); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.setSelection(mergedCell.domNode.getBoundingClientRect(), mergedCell.domNode.getBoundingClientRect()); } - }, unmergeCells: { text: 'Unmerge cells', iconSrc: icon_operation_6_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); tableContainer.unmergeCells(this.selectedTds, this.quill.root.parentNode); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.clearSelection(); } - }, deleteColumn: { text: 'Delete selected columns', iconSrc: icon_operation_7_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); let colIndexes = getColToolCellIndexesByBoundary(this.columnToolCells, this.boundary, (cellRect, boundary) => { return cellRect.x + table_operation_menu_ERROR_LIMIT > boundary.x && cellRect.x + cellRect.width - table_operation_menu_ERROR_LIMIT < boundary.x1; }, this.quill.root.parentNode); let isDeleteTable = tableContainer.deleteColumns(this.boundary, colIndexes, this.quill.root.parentNode); - if (!isDeleteTable) { this.tableColumnTool.updateToolCells(); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.clearSelection(); } } - }, deleteRow: { text: 'Delete selected rows', iconSrc: icon_operation_8_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); tableContainer.deleteRow(this.boundary, this.quill.root.parentNode); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.clearSelection(); } - }, deleteTable: { text: 'Delete table', iconSrc: icon_operation_9_default.a, - handler() { const betterTableModule = this.quill.getModule('better-table'); const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); @@ -2598,7 +2428,6 @@ const MENU_ITEMS_DEFAULT = { tableContainer.remove(); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); } - } }; class table_operation_menu_TableOperationMenu { @@ -2620,22 +2449,20 @@ class table_operation_menu_TableOperationMenu { this.mount(); document.addEventListener("click", this.destroyHandler, false); } - mount() { document.body.appendChild(this.domNode); } - destroy() { this.domNode.remove(); document.removeEventListener("click", this.destroyHandler, false); return null; } - - menuInitial({ - table, - left, - top - }) { + menuInitial(_ref) { + let { + table, + left, + top + } = _ref; this.domNode = document.createElement('div'); this.domNode.classList.add('qlbt-operation-menu'); css(this.domNode, { @@ -2645,32 +2472,30 @@ class table_operation_menu_TableOperationMenu { 'min-height': `${MENU_MIN_HEIHGT}px`, width: `${MENU_WIDTH}px` }); - for (let name in this.menuItems) { if (this.menuItems[name]) { this.domNode.appendChild(this.menuItemCreator(Object.assign({}, MENU_ITEMS_DEFAULT[name], this.menuItems[name]))); - if (['insertRowDown', 'unmergeCells'].indexOf(name) > -1) { this.domNode.appendChild(dividingCreator()); } } - } // if colors option is false, disabled bg color - + } + // if colors option is false, disabled bg color if (this.options.color && this.options.color !== false) { this.domNode.appendChild(dividingCreator()); this.domNode.appendChild(subTitleCreator(this.colorSubTitle)); this.domNode.appendChild(this.colorsItemCreator(this.cellColors)); - } // create dividing line - + } + // create dividing line function dividingCreator() { const dividing = document.createElement('div'); dividing.classList.add('qlbt-operation-menu-dividing'); return dividing; - } // create subtitle for menu - + } + // create subtitle for menu function subTitleCreator(title) { const subTitle = document.createElement('div'); subTitle.classList.add('qlbt-operation-menu-subtitle'); @@ -2678,7 +2503,6 @@ class table_operation_menu_TableOperationMenu { return subTitle; } } - colorsItemCreator(colors) { const self = this; const node = document.createElement('div'); @@ -2687,7 +2511,6 @@ class table_operation_menu_TableOperationMenu { let colorBox = colorBoxCreator(color); node.appendChild(colorBox); }); - function colorBoxCreator(color) { const box = document.createElement('div'); box.classList.add('qlbt-operation-color-picker-item'); @@ -2695,7 +2518,6 @@ class table_operation_menu_TableOperationMenu { box.style.backgroundColor = color; box.addEventListener('click', function () { const selectedTds = self.tableSelection.selectedTds; - if (selectedTds && selectedTds.length > 0) { selectedTds.forEach(tableCell => { tableCell.format('cell-bg', color); @@ -2704,15 +2526,14 @@ class table_operation_menu_TableOperationMenu { }, false); return box; } - return node; } - - menuItemCreator({ - text, - iconSrc, - handler - }) { + menuItemCreator(_ref2) { + let { + text, + iconSrc, + handler + } = _ref2; const node = document.createElement('div'); node.classList.add('qlbt-operation-menu-item'); const iconSpan = document.createElement('span'); @@ -2726,37 +2547,31 @@ class table_operation_menu_TableOperationMenu { node.addEventListener('click', handler.bind(this), false); return node; } - } - function getColToolCellIndexByBoundary(cells, boundary, conditionFn, container) { return cells.reduce((findIndex, cell) => { let cellRect = getRelativeRect(cell.getBoundingClientRect(), container); - if (conditionFn(cellRect, boundary)) { findIndex = cells.indexOf(cell); } - return findIndex; }, false); } - function getColToolCellIndexesByBoundary(cells, boundary, conditionFn, container) { return cells.reduce((findIndexes, cell) => { let cellRect = getRelativeRect(cell.getBoundingClientRect(), container); - if (conditionFn(cellRect, boundary)) { findIndexes.push(cells.indexOf(cell)); } - return findIndexes; }, []); } // CONCATENATED MODULE: ./src/utils/node-matchers.js -const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); // rebuild delta +const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); +// rebuild delta function matchTableCell(node, delta, scroll) { const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; @@ -2767,10 +2582,11 @@ function matchTableCell(node, delta, scroll) { const colspan = node.getAttribute('colspan') || false; const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); - const cellBorder = node.getAttribute('data-cell-border') || (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none' : undefined); + const cellValign = node.getAttribute('data-cell-valign'); + // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { 'table-cell-line': { @@ -2778,18 +2594,17 @@ function matchTableCell(node, delta, scroll) { cell: cellId, rowspan, colspan, - 'cell-border': cellBorder + 'cell-border': cellBorder, + 'cell-valign': cellValign } }); return delta; } - delta = delta.reduce((newDelta, op) => { if (op.insert && typeof op.insert === 'string') { const lines = []; let insertStr = op.insert; let start = 0; - for (let i = 0; i < op.insert.length; i++) { if (insertStr.charAt(i) === '\n') { if (i === 0) { @@ -2798,11 +2613,9 @@ function matchTableCell(node, delta, scroll) { lines.push(insertStr.substring(start, i)); lines.push('\n'); } - start = i + 1; } } - const tailStr = insertStr.substring(start); if (tailStr) lines.push(tailStr); lines.forEach(text => { @@ -2811,7 +2624,6 @@ function matchTableCell(node, delta, scroll) { } else { newDelta.insert(op.insert, op.attributes); } - return newDelta; }, new Delta()); return delta.reduce((newDelta, op) => { @@ -2825,7 +2637,8 @@ function matchTableCell(node, delta, scroll) { rowspan, colspan, 'cell-bg': cellBg, - 'cell-border': cellBorder + 'cell-border': cellBorder, + 'cell-valign': cellValign } }, _omit(op.attributes, ['table']))); } else { @@ -2837,11 +2650,11 @@ function matchTableCell(node, delta, scroll) { newDelta.insert(op.insert, Object.assign({}, _omit(op.attributes, ['table', 'table-cell-line']))); } } - return newDelta; }, new Delta()); -} // replace th tag with td tag +} +// replace th tag with td tag function matchTableHeader(node, delta, scroll) { const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; @@ -2850,8 +2663,9 @@ function matchTableHeader(node, delta, scroll) { const rowId = rows.indexOf(row) + 1; const cellId = cells.indexOf(node) + 1; const colspan = node.getAttribute('colspan') || false; - const rowspan = node.getAttribute('rowspan') || false; // bugfix: empty table cells copied from other place will be removed unexpectedly + const rowspan = node.getAttribute('rowspan') || false; + // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { 'table-cell-line': { @@ -2863,13 +2677,11 @@ function matchTableHeader(node, delta, scroll) { }); return delta; } - delta = delta.reduce((newDelta, op) => { if (op.insert && typeof op.insert === 'string') { const lines = []; let insertStr = op.insert; let start = 0; - for (let i = 0; i < op.insert.length; i++) { if (insertStr.charAt(i) === '\n') { if (i === 0) { @@ -2878,18 +2690,16 @@ function matchTableHeader(node, delta, scroll) { lines.push(insertStr.substring(start, i)); lines.push('\n'); } - start = i + 1; } } - const tailStr = insertStr.substring(start); - if (tailStr) lines.push(tailStr); // bugfix: no '\n' in op.insert, push a '\n' to lines + if (tailStr) lines.push(tailStr); + // bugfix: no '\n' in op.insert, push a '\n' to lines if (lines.indexOf('\n') < 0) { lines.push('\n'); } - lines.forEach(text => { text === '\n' ? newDelta.insert('\n', { 'table-cell-line': { @@ -2903,7 +2713,6 @@ function matchTableHeader(node, delta, scroll) { } else { newDelta.insert(op.insert, op.attributes); } - return newDelta; }, new Delta()); return delta.reduce((newDelta, op) => { @@ -2919,15 +2728,16 @@ function matchTableHeader(node, delta, scroll) { } else { newDelta.insert(op.insert, Object.assign({}, _omit(op.attributes, ['table', 'table-cell-line']))); } - return newDelta; }, new Delta()); -} // supplement colgroup and col +} +// supplement colgroup and col function matchTable(node, delta, scroll) { let newColDelta = new Delta(); - const topRow = node.querySelector('tr'); // bugfix: empty table will return empty delta + const topRow = node.querySelector('tr'); + // bugfix: empty table will return empty delta if (topRow === null) return newColDelta; const cellsInTopRow = Array.from(topRow.querySelectorAll('td')).concat(Array.from(topRow.querySelectorAll('th'))); const maxCellsNumber = cellsInTopRow.reduce((sum, cell) => { @@ -2935,10 +2745,11 @@ function matchTable(node, delta, scroll) { sum = sum + parseInt(cellColspan, 10); return sum; }, 0); - const colsNumber = node.querySelectorAll('col').length; // issue #2 + const colsNumber = node.querySelectorAll('col').length; + + // issue #2 // bugfix: the table copied from Excel had some default col tags missing // add missing col tags - if (colsNumber === maxCellsNumber) { return delta; } else { @@ -2947,20 +2758,16 @@ function matchTable(node, delta, scroll) { 'table-col': true }); } - if (colsNumber === 0) return newColDelta.concat(delta); let lastNumber = 0; return delta.reduce((finalDelta, op) => { finalDelta.insert(op.insert, op.attributes); - if (op.attributes && op.attributes['table-col']) { lastNumber += op.insert.length; - if (lastNumber === colsNumber) { finalDelta = finalDelta.concat(newColDelta); } } - return finalDelta; }, new Delta()); } @@ -2969,14 +2776,14 @@ function matchTable(node, delta, scroll) { - // import table node matchers +// import table node matchers + const Module = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('core/module'); const quill_better_table_Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); - class quill_better_table_BetterTable extends Module { static register() { external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(TableCol, true); @@ -2987,13 +2794,15 @@ class quill_better_table_BetterTable extends Module { external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(TableBody, true); external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableContainer, true); external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableViewWrapper, true); - external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableViewWrapper, true); // register customized Header,overwriting quill built-in Header + external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableViewWrapper, true); + // register customized Header,overwriting quill built-in Header // Quill.register('formats/header', Header, true); } constructor(quill, options) { - super(quill, options); // handle click on quill-better-table + super(quill, options); + // handle click on quill-better-table this.quill.root.addEventListener('click', evt => { // bugfix: evt.path is undefined in Safari, FF, Micro Edge const path = getEventComposedPath(evt); @@ -3001,23 +2810,24 @@ class quill_better_table_BetterTable extends Module { const tableNode = path.filter(node => { return node.tagName && node.tagName.toUpperCase() === 'TABLE' && node.classList.contains('quill-better-table'); })[0]; - if (tableNode) { // current table clicked - if (this.table === tableNode) return; // other table clicked - + if (this.table === tableNode) return; + // other table clicked if (this.table) this.hideTableTools(); this.showTableTools(tableNode, quill, options); } else if (this.table) { // other clicked this.hideTableTools(); } - }, false); // handle right click on quill-better-table + }, false); + // handle right click on quill-better-table this.quill.root.addEventListener('contextmenu', evt => { if (!this.table) return true; - evt.preventDefault(); // bugfix: evt.path is undefined in Safari, FF, Micro Edge + evt.preventDefault(); + // bugfix: evt.path is undefined in Safari, FF, Micro Edge const path = getEventComposedPath(evt); if (!path || path.length <= 0) return; const tableNode = path.filter(node => { @@ -3030,13 +2840,10 @@ class quill_better_table_BetterTable extends Module { return node.tagName && node.tagName.toUpperCase() === 'TD' && node.getAttribute('data-row'); })[0]; let isTargetCellSelected = this.tableSelection.selectedTds.map(tableCell => tableCell.domNode).includes(cellNode); - if (this.tableSelection.selectedTds.length <= 0 || !isTargetCellSelected) { this.tableSelection.setSelection(cellNode.getBoundingClientRect(), cellNode.getBoundingClientRect()); } - if (this.tableOperationMenu) this.tableOperationMenu = this.tableOperationMenu.destroy(); - if (tableNode) { this.tableOperationMenu = new table_operation_menu_TableOperationMenu({ table: tableNode, @@ -3046,77 +2853,72 @@ class quill_better_table_BetterTable extends Module { top: evt.pageY }, quill, options.operationMenu); } - }, false); // add keyboard binding:Backspace - // prevent user hits backspace to delete table cell + }, false); + // add keyboard binding:Backspace + // prevent user hits backspace to delete table cell const KeyBoard = quill.getModule('keyboard'); quill.keyboard.addBinding({ key: 'Backspace' }, {}, function (range, context) { if (range.index === 0 || this.quill.getLength() <= 1) return true; const [line] = this.quill.getLine(range.index); - if (context.offset === 0) { const [prev] = this.quill.getLine(range.index - 1); - if (prev != null) { if (prev.statics.blotName === 'table-cell-line' && line.statics.blotName !== 'table-cell-line') return false; } } - return true; - }); // since only one matched bindings callback will excute. + }); + // since only one matched bindings callback will excute. // expected my binding callback excute first // I changed the order of binding callbacks - let thisBinding = quill.keyboard.bindings['Backspace'].pop(); - quill.keyboard.bindings['Backspace'].splice(0, 1, thisBinding); // add Matchers to match and render quill-better-table for initialization - // or pasting + quill.keyboard.bindings['Backspace'].splice(0, 1, thisBinding); + // add Matchers to match and render quill-better-table for initialization + // or pasting quill.clipboard.addMatcher('td', matchTableCell); quill.clipboard.addMatcher('th', matchTableHeader); - quill.clipboard.addMatcher('table', matchTable); // quill.clipboard.addMatcher('h1, h2, h3, h4, h5, h6', matchHeader) - // remove matcher for tr tag + quill.clipboard.addMatcher('table', matchTable); + // quill.clipboard.addMatcher('h1, h2, h3, h4, h5, h6', matchHeader) + // remove matcher for tr tag quill.clipboard.matchers = quill.clipboard.matchers.filter(matcher => { return matcher[0] !== 'tr'; }); } - - getTable(range = this.quill.getSelection()) { + getTable() { + let range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.quill.getSelection(); if (range == null) return [null, null, null, -1]; const [cellLine, offset] = this.quill.getLine(range.index); - if (cellLine == null || cellLine.statics.blotName !== TableCellLine.blotName) { return [null, null, null, -1]; } - const cell = cellLine.tableCell(); const row = cell.row(); const table = row.table(); return [table, row, cell, offset]; } - insertTable(rows, columns) { const range = this.quill.getSelection(true); if (range == null) return; let currentBlot = this.quill.getLeaf(range.index)[0]; let delta = new quill_better_table_Delta().retain(range.index); - if (isInTableCell(currentBlot)) { console.warn(`Can not insert table into a table cell.`); return; } - - delta.insert('\n'); // insert table column - + delta.insert('\n'); + // insert table column delta = new Array(columns).fill('\n').reduce((memo, text) => { memo.insert(text, { 'table-col': true }); return memo; - }, delta); // insert table cell line with empty line - + }, delta); + // insert table cell line with empty line delta = new Array(rows).fill(0).reduce(memo => { let tableRowId = table_rowId(); return new Array(columns).fill('\n').reduce((memo, text) => { @@ -3132,13 +2934,11 @@ class quill_better_table_BetterTable extends Module { this.quill.updateContents(delta, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.quill.setSelection(range.index + columns + 1, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.API); } - showTableTools(table, quill, options) { this.table = table; this.columnTool = new table_column_tool_TableColumnTool(table, quill, options); this.tableSelection = new table_selection_TableSelection(table, quill, options); } - hideTableTools() { this.columnTool && this.columnTool.destroy(); this.tableSelection && this.tableSelection.destroy(); @@ -3148,46 +2948,36 @@ class quill_better_table_BetterTable extends Module { this.tableOperationMenu = null; this.table = null; } - } - quill_better_table_BetterTable.keyboardBindings = { 'table-cell-line backspace': { key: 'Backspace', format: ['table-cell-line'], collapsed: true, offset: 0, - handler(range, context) { const [line, offset] = this.quill.getLine(range.index); - if (!line.prev || line.prev.statics.blotName !== 'table-cell-line') { return false; } - return true; } - }, 'table-cell-line delete': { key: 'Delete', format: ['table-cell-line'], collapsed: true, suffix: /^$/, - handler() {} - }, 'table-cell-line enter': { key: 'Enter', shiftKey: null, format: ['table-cell-line'], - handler(range, context) { // bugfix: a unexpected new line inserted when user compositionend with hitting Enter if (this.quill.selection && this.quill.selection.composing) return; const Scope = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.imports.parchment.Scope; - if (range.length > 0) { this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change } @@ -3196,13 +2986,12 @@ quill_better_table_BetterTable.keyboardBindings = { if (this.quill.scroll.query(format, Scope.BLOCK) && !Array.isArray(context.format[format])) { formats[format] = context.format[format]; } - return formats; - }, {}); // insert new cellLine with lineFormats - - this.quill.insertText(range.index, '\n', lineFormats['table-cell-line'], external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); // Earlier scroll.deleteAt might have messed up our selection, + }, {}); + // insert new cellLine with lineFormats + this.quill.insertText(range.index, '\n', lineFormats['table-cell-line'], external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); + // Earlier scroll.deleteAt might have messed up our selection, // so insertText's built in selection preservation is not reliable - this.quill.setSelection(range.index + 1, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.quill.focus(); Object.keys(context.format).forEach(name => { @@ -3212,35 +3001,28 @@ quill_better_table_BetterTable.keyboardBindings = { this.quill.format(name, context.format[name], external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); }); } - }, 'table-cell-line up': makeTableArrowHandler(true), 'table-cell-line down': makeTableArrowHandler(false), 'down-to-table': { key: 'ArrowDown', collapsed: true, - handler(range, context) { const target = context.line.next; - if (target && target.statics.blotName === 'table-view') { const targetCell = target.table().rows()[0].children.head; const targetLine = targetCell.children.head; this.quill.setSelection(targetLine.offset(this.quill.scroll), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); return false; } - return true; } - }, 'up-to-table': { key: 'ArrowUp', collapsed: true, - handler(range, context) { const target = context.line.prev; - if (target && target.statics.blotName === 'table-view') { const rows = target.table().rows(); const targetCell = rows[rows.length - 1].children.head; @@ -3248,19 +3030,15 @@ quill_better_table_BetterTable.keyboardBindings = { this.quill.setSelection(targetLine.offset(this.quill.scroll), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); return false; } - return true; } - } }; - function makeTableArrowHandler(up) { return { key: up ? 'ArrowUp' : 'ArrowDown', collapsed: true, format: ['table-cell-line'], - handler(range, context) { // TODO move to table module const key = up ? 'prev' : 'next'; @@ -3268,28 +3046,25 @@ function makeTableArrowHandler(up) { if (targetLine != null) return true; const cell = context.line.parent; const targetRow = cell.parent[key]; - if (targetRow != null && targetRow.statics.blotName === 'table-row') { let targetCell = targetRow.children.head; let totalColspanOfTargetCell = parseInt(targetCell.formats()['colspan'], 10); let cur = cell; - let totalColspanOfCur = parseInt(cur.formats()['colspan'], 10); // get targetCell above current cell depends on colspan + let totalColspanOfCur = parseInt(cur.formats()['colspan'], 10); + // get targetCell above current cell depends on colspan while (cur.prev != null) { cur = cur.prev; totalColspanOfCur += parseInt(cur.formats()['colspan'], 10); } - while (targetCell.next != null && totalColspanOfTargetCell < totalColspanOfCur) { targetCell = targetCell.next; totalColspanOfTargetCell += parseInt(targetCell.formats()['colspan'], 10); } - const index = targetCell.offset(this.quill.scroll); this.quill.setSelection(index, 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); } else { const targetLine = cell.table().parent[key]; - if (targetLine != null) { if (up) { this.quill.setSelection(targetLine.offset(this.quill.scroll) + targetLine.length() - 1, 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); @@ -3298,21 +3073,16 @@ function makeTableArrowHandler(up) { } } } - return false; } - }; } - function isTableCell(blot) { return blot.statics.blotName === TableCell.blotName; } - function isInTableCell(current) { return current && current.parent ? isTableCell(current.parent) ? true : isInTableCell(current.parent) : false; } - /* harmony default export */ var quill_better_table = __webpack_exports__["default"] = (quill_better_table_BetterTable); /***/ }), @@ -3331,13 +3101,12 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var src_quill_better_table_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10); /* harmony import */ var src_assets_quill_better_table_scss__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(11); /* harmony import */ var src_assets_quill_better_table_scss__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(src_assets_quill_better_table_scss__WEBPACK_IMPORTED_MODULE_1__); - // import better-table styles file +// import better-table styles file Quill.register({ 'modules/better-table': src_quill_better_table_js__WEBPACK_IMPORTED_MODULE_0__["default"] }, true); - window.onload = () => { const quill = new Quill('#editor-wrapper', { theme: 'snow', @@ -3361,15 +3130,12 @@ window.onload = () => { } }); let tableModule = quill.getModule('better-table'); - document.body.querySelector('#insert-table').onclick = () => { tableModule.insertTable(3, 3); }; - document.body.querySelector('#get-table').onclick = () => { console.log(tableModule.getTable()); }; - document.body.querySelector('#get-contents').onclick = () => { console.log(quill.getContents()); }; diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index d54c1be..4a8a4c7 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.js @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "dc685a62a82fa8e825a4"; +/******/ var hotCurrentHash = "c8ddfda8765e39518b2a"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -947,13 +947,13 @@ function css(domNode, rules) { } } } + /** * getRelativeRect * @param {Object} targetRect rect data for target element * @param {Element} container container element * @return {Object} an object with rect data */ - function getRelativeRect(targetRect, container) { let containerRect = container.getBoundingClientRect(); return { @@ -965,13 +965,13 @@ function getRelativeRect(targetRect, container) { height: targetRect.height }; } + /** * _omit * @param {Object} obj target Object * @param {Array} uselessKeys keys of removed properties * @return {Object} new Object without useless properties */ - function _omit(obj, uselessKeys) { return obj && Object.keys(obj).reduce((acc, key) => { return uselessKeys.includes(key) ? acc : Object.assign({}, acc, { @@ -979,6 +979,7 @@ function _omit(obj, uselessKeys) { }); }, {}); } + /** * getEventComposedPath * compatibility fixed for Event.path/Event.composedPath @@ -988,53 +989,45 @@ function _omit(obj, uselessKeys) { * @param {Event} evt * @return {Array} an array of event.path */ - function getEventComposedPath(evt) { - let path; // chrome, opera, safari, firefox - - path = evt.path || evt.composedPath && evt.composedPath(); // other: edge + let path; + // chrome, opera, safari, firefox + path = evt.path || evt.composedPath && evt.composedPath(); + // other: edge if (path == undefined && evt.target) { path = []; let target = evt.target; path.push(target); - while (target && target.parentNode) { target = target.parentNode; path.push(target); } } - return path; } function convertToHex(rgb) { - var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; // if rgb - + var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; + // if rgb if (/^(rgb|RGB)/.test(rgb)) { var color = rgb.toString().match(/\d+/g); var hex = "#"; - for (var i = 0; i < 3; i++) { hex += ("0" + Number(color[i]).toString(16)).slice(-2); } - return hex; } else if (reg.test(rgb)) { var aNum = rgb.replace(/#/, "").split(""); - if (aNum.length === 6) { return rgb; } else if (aNum.length === 3) { var numHex = "#"; - for (var i = 0; i < aNum.length; i += 1) { numHex += aNum[i] + aNum[i]; } - return numHex; } } - return rgb; } // CONCATENATED MODULE: ./src/modules/table-column-tool.js @@ -1054,7 +1047,6 @@ class table_column_tool_TableColumnTool { this.domNode = null; this.initColTool(); } - initColTool() { const parent = this.quill.root.parentNode; const tableRect = this.table.getBoundingClientRect(); @@ -1071,7 +1063,6 @@ class table_column_tool_TableColumnTool { top: `${tableViewRect.top - containerRect.top + parent.scrollTop - COL_TOOL_HEIGHT - 5}px` }); } - createToolCell() { const toolCell = document.createElement('div'); toolCell.classList.add('qlbt-col-tool-cell'); @@ -1083,45 +1074,40 @@ class table_column_tool_TableColumnTool { toolCell.appendChild(resizeHolder); return toolCell; } - updateToolCells() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const CellsInFirstRow = tableContainer.children.tail.children.head.children; const tableCols = tableContainer.colGroup().children; const cellsNumber = computeCellsNumber(CellsInFirstRow); let existCells = Array.from(this.domNode.querySelectorAll('.qlbt-col-tool-cell')); - for (let index = 0; index < Math.max(cellsNumber, existCells.length); index++) { let col = tableCols.at(index); - let colWidth = col && parseInt(col.formats()[col.statics.blotName].width, 10); // if cell already exist - + let colWidth = col && parseInt(col.formats()[col.statics.blotName].width, 10); + // if cell already exist let toolCell = null; - if (!existCells[index]) { toolCell = this.createToolCell(); this.domNode.appendChild(toolCell); - this.addColCellHolderHandler(toolCell); // set tool cell min-width - + this.addColCellHolderHandler(toolCell); + // set tool cell min-width css(toolCell, { 'min-width': `${colWidth}px` }); } else if (existCells[index] && index >= cellsNumber) { existCells[index].remove(); } else { - toolCell = existCells[index]; // set tool cell min-width - + toolCell = existCells[index]; + // set tool cell min-width css(toolCell, { 'min-width': `${colWidth}px` }); } } } - destroy() { this.domNode.remove(); return null; } - addColCellHolderHandler(cell) { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const $holder = cell.querySelector(".qlbt-col-tool-cell-holder"); @@ -1129,36 +1115,30 @@ class table_column_tool_TableColumnTool { let x0 = 0; let x = 0; let delta = 0; - let width0 = 0; // helpLine relation varrible - + let width0 = 0; + // helpLine relation varrible let tableRect = {}; let cellRect = {}; let $helpLine = null; - const handleDrag = e => { e.preventDefault(); - if (dragging) { x = e.clientX; - if (width0 + x - x0 >= CELL_MIN_WIDTH) { delta = x - x0; } else { delta = CELL_MIN_WIDTH - width0; } - css($helpLine, { 'left': `${cellRect.left + cellRect.width - 1 + delta}px` }); } }; - const handleMouseup = e => { e.preventDefault(); const existCells = Array.from(this.domNode.querySelectorAll('.qlbt-col-tool-cell')); const colIndex = existCells.indexOf(cell); const colBlot = tableContainer.colGroup().children.at(colIndex); - if (dragging) { colBlot.format('width', width0 + delta); css(cell, { @@ -1171,7 +1151,6 @@ class table_column_tool_TableColumnTool { dragging = false; $holder.classList.remove('dragging'); } - document.removeEventListener('mousemove', handleDrag, false); document.removeEventListener('mouseup', handleMouseup, false); tableRect = {}; @@ -1182,7 +1161,6 @@ class table_column_tool_TableColumnTool { const tableSelection = this.quill.getModule('better-table').tableSelection; tableSelection && tableSelection.clearSelection(); }; - const handleMousedown = e => { document.addEventListener('mousemove', handleDrag, false); document.addEventListener('mouseup', handleMouseup, false); @@ -1204,16 +1182,12 @@ class table_column_tool_TableColumnTool { width0 = cellRect.width; $holder.classList.add('dragging'); }; - $holder.addEventListener('mousedown', handleMousedown, false); } - colToolCells() { return Array.from(this.domNode.querySelectorAll('.qlbt-col-tool-cell')); } - } - function computeCellsNumber(CellsInFirstRow) { return CellsInFirstRow.reduce((sum, cell) => { const cellColspan = cell.formats().colspan; @@ -1225,7 +1199,6 @@ function computeCellsNumber(CellsInFirstRow) { const Block = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import("blots/block"); - class header_Header extends Block { static create(value) { if (typeof value === 'string') { @@ -1233,7 +1206,6 @@ class header_Header extends Block { value }; } - const node = super.create(value.value); CELL_IDENTITY_KEYS.forEach(key => { if (value[key]) node.setAttribute(`data-${key}`, value[key]); @@ -1243,7 +1215,6 @@ class header_Header extends Block { }); return node; } - static formats(domNode) { const formats = {}; formats.value = this.tagName.indexOf(domNode.tagName) + 1; @@ -1251,11 +1222,9 @@ class header_Header extends Block { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } - return formats; }, formats); } - format(name, value) { const { row, @@ -1263,7 +1232,6 @@ class header_Header extends Block { rowspan, colspan } = header_Header.formats(this.domNode); - if (name === header_Header.blotName) { if (value) { super.format(name, { @@ -1289,45 +1257,39 @@ class header_Header extends Block { super.format(name, value); } } - optimize(context) { const { row, rowspan, colspan } = header_Header.formats(this.domNode); - if (row && !(this.parent instanceof TableCell)) { this.wrap(TableCell.blotName, { row, colspan, rowspan }); - } // ShadowBlot optimize - + } + // ShadowBlot optimize this.enforceAllowedChildren(); - if (this.uiNode != null && this.uiNode !== this.domNode.firstChild) { this.domNode.insertBefore(this.uiNode, this.domNode.firstChild); } - if (this.children.length === 0) { if (this.statics.defaultChild != null) { const child = this.scroll.create(this.statics.defaultChild.blotName); - this.appendChild(child); // TODO double check if necessary + this.appendChild(child); + // TODO double check if necessary // child.optimize(context); } else { this.remove(); } - } // Block optimize - - + } + // Block optimize this.cache = {}; } - } - header_Header.blotName = 'header'; header_Header.tagName = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; /* harmony default export */ var header = (header_Header); @@ -1349,7 +1311,6 @@ const CELL_DEFAULT = { colspan: 1 }; const ERROR_LIMIT = 5; - class TableCellLine extends table_Block { static create(value) { const node = super.create(value); @@ -1360,29 +1321,26 @@ class TableCellLine extends table_Block { CELL_ATTRIBUTES.forEach(attrName => { node.setAttribute(`data-${attrName}`, value[attrName] || CELL_DEFAULT[attrName]); }); - if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']); } - if (value['cell-border']) { node.setAttribute('data-cell-border', value['cell-border']); } - + if (value['cell-valign']) { + node.setAttribute('data-cell-valign', value['cell-valign']); + } return node; } - static formats(domNode) { const formats = {}; - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border', 'cell-valign']).reduce((formats, attribute) => { if (domNode.hasAttribute(`data-${attribute}`)) { formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined; } - return formats; }, formats); } - format(name, value) { if (CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).indexOf(name) > -1) { if (value) { @@ -1402,6 +1360,12 @@ class TableCellLine extends table_Block { } else { this.domNode.removeAttribute('data-cell-border'); } + } else if (name === 'cell-valign') { + if (value) { + this.domNode.setAttribute(`data-${name}`, value); + } else { + this.domNode.removeAttribute(`data-${name}`); + } } else if (name === 'header') { if (!value) return; const { @@ -1421,7 +1385,6 @@ class TableCellLine extends table_Block { super.format(name, value); } } - optimize(context) { // cover shadowBlot's wrap call, pass params parentBlot initialize // needed @@ -1430,30 +1393,26 @@ class TableCellLine extends table_Block { const colspan = this.domNode.getAttribute('data-colspan'); const cellBg = this.domNode.getAttribute('data-cell-bg'); const cellBorder = this.domNode.getAttribute('data-cell-border'); - + const cellValign = this.domNode.getAttribute('data-cell-valign'); if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId, colspan, rowspan, 'cell-bg': cellBg, - 'cell-border': cellBorder + 'cell-border': cellBorder, + 'cell-valign': cellValign }); } - super.optimize(context); } - tableCell() { return this.parent; } - } - TableCellLine.blotName = "table-cell-line"; TableCellLine.className = "qlbt-cell-line"; TableCellLine.tagName = "P"; - class TableCell extends Container { checkMerge() { if (super.checkMerge() && this.next.children.head != null) { @@ -1463,10 +1422,8 @@ class TableCell extends Container { const nextTail = this.next.children.tail.formats()[this.next.children.tail.statics.blotName]; return thisHead.cell === thisTail.cell && thisHead.cell === nextHead.cell && thisHead.cell === nextTail.cell; } - return false; } - static create(value) { const node = super.create(value); node.setAttribute("data-row", value.row); @@ -1475,79 +1432,66 @@ class TableCell extends Container { node.setAttribute(attrName, value[attrName]); } }); - if (value['cell-bg']) { node.setAttribute('data-cell-bg', value['cell-bg']); node.style.backgroundColor = value['cell-bg']; } - if (value['cell-border']) { node.setAttribute('data-cell-border', value['cell-border']); } - + if (value['cell-valign']) { + node.setAttribute('data-cell-valign', value['cell-valign']); + } return node; } - static formats(domNode) { const formats = {}; - if (domNode.hasAttribute("data-row")) { formats["row"] = domNode.getAttribute("data-row"); } - if (domNode.hasAttribute("data-cell-bg")) { formats["cell-bg"] = domNode.getAttribute("data-cell-bg"); } - if (domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = domNode.getAttribute("data-cell-border"); } - - if (domNode.hasAttribute("data-cell-border")) { - formats["cell-border"] = domNode.getAttribute("data-cell-border"); + if (domNode.hasAttribute("data-cell-valign")) { + formats["cell-valign"] = domNode.getAttribute("data-cell-valign"); } - return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(attribute)) { formats[attribute] = domNode.getAttribute(attribute); } - return formats; }, formats); } - cellOffset() { if (this.parent) { return this.parent.children.indexOf(this); } - return -1; } - formats() { const formats = {}; - if (this.domNode.hasAttribute("data-row")) { formats["row"] = this.domNode.getAttribute("data-row"); } - if (this.domNode.hasAttribute("data-cell-bg")) { formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg"); } - if (this.domNode.hasAttribute("data-cell-border")) { formats["cell-border"] = this.domNode.getAttribute("data-cell-border"); } - + if (this.domNode.hasAttribute("data-cell-valign")) { + formats["cell-valign"] = this.domNode.getAttribute("data-cell-valign"); + } return CELL_ATTRIBUTES.reduce((formats, attribute) => { if (this.domNode.hasAttribute(attribute)) { formats[attribute] = this.domNode.getAttribute(attribute); } - return formats; }, formats); } - toggleAttribute(name, value) { if (value) { this.domNode.setAttribute(name, value); @@ -1555,13 +1499,11 @@ class TableCell extends Container { this.domNode.removeAttribute(name); } } - formatChildren(name, value) { this.children.forEach(child => { child.format(name, value); }); } - format(name, value) { if (CELL_ATTRIBUTES.indexOf(name) > -1) { this.toggleAttribute(name, value); @@ -1572,7 +1514,6 @@ class TableCell extends Container { } else if (name === 'cell-bg') { this.toggleAttribute('data-cell-bg', value); this.formatChildren(name, value); - if (value) { this.domNode.style.backgroundColor = value; } else { @@ -1581,44 +1522,37 @@ class TableCell extends Container { } else if (name === 'cell-border') { this.toggleAttribute('data-cell-border', value); this.formatChildren(name, value); + } else if (name === 'cell-valign') { + this.toggleAttribute('data-cell-valign', value); + this.formatChildren(name, value); } else { super.format(name, value); } } - optimize(context) { const rowId = this.domNode.getAttribute("data-row"); - if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName, { row: rowId }); } - super.optimize(context); } - row() { return this.parent; } - rowOffset() { if (this.row()) { return this.row().rowOffset(); } - return -1; } - table() { return this.row() && this.row().table(); } - } - TableCell.blotName = "table"; TableCell.tagName = "TD"; - class TableRow extends Container { checkMerge() { if (super.checkMerge() && this.next.children.head != null) { @@ -1628,70 +1562,56 @@ class TableRow extends Container { const nextTail = this.next.children.tail.formats(); return thisHead.row === thisTail.row && thisHead.row === nextHead.row && thisHead.row === nextTail.row; } - return false; } - static create(value) { const node = super.create(value); node.setAttribute("data-row", value.row); return node; } - formats() { return ["row"].reduce((formats, attrName) => { if (this.domNode.hasAttribute(`data-${attrName}`)) { formats[attrName] = this.domNode.getAttribute(`data-${attrName}`); } - return formats; }, {}); } - optimize(context) { // optimize function of ShadowBlot if (this.statics.requiredContainer && !(this.parent instanceof this.statics.requiredContainer)) { this.wrap(this.statics.requiredContainer.blotName); - } // optimize function of ParentBlot + } + + // optimize function of ParentBlot // note: modified this optimize function because // TableRow should not be removed when the length of its children was 0 - - this.enforceAllowedChildren(); - if (this.uiNode != null && this.uiNode !== this.domNode.firstChild) { this.domNode.insertBefore(this.uiNode, this.domNode.firstChild); - } // optimize function of ContainerBlot - + } + // optimize function of ContainerBlot if (this.children.length > 0 && this.next != null && this.checkMerge()) { this.next.moveChildren(this); this.next.remove(); } } - rowOffset() { if (this.parent) { return this.parent.children.indexOf(this); } - return -1; } - table() { return this.parent && this.parent.parent; } - } - TableRow.blotName = "table-row"; TableRow.tagName = "TR"; - class TableBody extends Container {} - TableBody.blotName = "table-body"; TableBody.tagName = "TBODY"; - class TableCol extends table_Block { static create(value) { let node = super.create(value); @@ -1700,17 +1620,14 @@ class TableCol extends table_Block { }); return node; } - static formats(domNode) { return COL_ATTRIBUTES.reduce((formats, attribute) => { if (domNode.hasAttribute(`${attribute}`)) { formats[attribute] = domNode.getAttribute(`${attribute}`) || undefined; } - return formats; }, {}); } - format(name, value) { if (COL_ATTRIBUTES.indexOf(name) > -1) { this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]); @@ -1718,32 +1635,24 @@ class TableCol extends table_Block { super.format(name, value); } } - html() { return this.domNode.outerHTML; } - } - TableCol.blotName = "table-col"; TableCol.tagName = "col"; - class TableColGroup extends Container {} - TableColGroup.blotName = "table-col-group"; TableColGroup.tagName = "colgroup"; - class table_TableContainer extends Container { static create() { let node = super.create(); return node; } - constructor(scroll, domNode) { super(scroll, domNode); this.updateTableWidth(); } - updateTableWidth() { setTimeout(() => { const colGroup = this.colGroup(); @@ -1755,16 +1664,15 @@ class table_TableContainer extends Container { this.domNode.style.width = `${tableWidth}px`; }, 0); } - cells(column) { return this.rows().map(row => row.children.at(column)); } - colGroup() { return this.children.head; } - - deleteColumns(compareRect, delIndexes = [], editorWrapper) { + deleteColumns(compareRect) { + let delIndexes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; + let editorWrapper = arguments.length > 2 ? arguments[2] : undefined; const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; const tableCells = this.descendants(TableCell); @@ -1772,20 +1680,18 @@ class table_TableContainer extends Container { const modifiedCells = []; tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (cellRect.x + ERROR_LIMIT > compareRect.x && cellRect.x1 - ERROR_LIMIT < compareRect.x1) { removedCells.push(cell); } else if (cellRect.x < compareRect.x + ERROR_LIMIT && cellRect.x1 > compareRect.x1 - ERROR_LIMIT) { modifiedCells.push(cell); } }); - if (removedCells.length === tableCells.length) { this.tableDestroy(); return true; - } // remove the matches column tool cell - + } + // remove the matches column tool cell delIndexes.forEach(delIndex => { this.colGroup().children.at(delIndexes[0]).remove(); }); @@ -1799,65 +1705,56 @@ class table_TableContainer extends Container { }); this.updateTableWidth(); } - deleteRow(compareRect, editorWrapper) { const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; const tableCells = this.descendants(TableCell); const tableRows = this.descendants(TableRow); const removedCells = []; // cells to be removed - const modifiedCells = []; // cells to be modified - const fallCells = []; // cells to fall into next row + // compute rows to remove // bugfix: #21 There will be a empty tr left if delete the last row of a table - const removedRows = tableRows.filter(row => { const rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper); return rowRect.y > compareRect.y - ERROR_LIMIT && rowRect.y1 < compareRect.y1 + ERROR_LIMIT; }); tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (cellRect.y > compareRect.y - ERROR_LIMIT && cellRect.y1 < compareRect.y1 + ERROR_LIMIT) { removedCells.push(cell); } else if (cellRect.y < compareRect.y + ERROR_LIMIT && cellRect.y1 > compareRect.y1 - ERROR_LIMIT) { modifiedCells.push(cell); - if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) { fallCells.push(cell); } } }); - if (removedCells.length === tableCells.length) { this.tableDestroy(); return; - } // compute length of removed rows - + } + // compute length of removed rows const removedRowsLength = this.rows().reduce((sum, row) => { let rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper); - if (rowRect.y > compareRect.y - ERROR_LIMIT && rowRect.y1 < compareRect.y1 + ERROR_LIMIT) { sum += 1; } - return sum; - }, 0); // it must excute before the table layout changed with other operation + }, 0); + // it must excute before the table layout changed with other operation fallCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); const nextRow = cell.parent.next; const cellsInNextRow = nextRow.children; const refCell = cellsInNextRow.reduce((ref, compareCell) => { const compareRect = getRelativeRect(compareCell.domNode.getBoundingClientRect(), editorWrapper); - if (Math.abs(cellRect.x1 - compareRect.x) < ERROR_LIMIT) { ref = compareCell; } - return ref; }, null); nextRow.insertBefore(cell, refCell); @@ -1869,11 +1766,11 @@ class table_TableContainer extends Container { modifiedCells.forEach(cell => { const cellRowspan = parseInt(cell.formats().rowspan, 10); cell.format("rowspan", cellRowspan - removedRowsLength); - }); // remove selected rows + }); + // remove selected rows removedRows.forEach(row => row.remove()); } - tableDestroy() { const quill = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.scroll.domNode.parentNode); const tableModule = quill.getModule("better-table"); @@ -1881,7 +1778,6 @@ class table_TableContainer extends Container { tableModule.hideTableTools(); quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); } - insertCell(tableRow, ref) { const id = table_cellId(); const rId = tableRow.formats().row; @@ -1893,15 +1789,15 @@ class table_TableContainer extends Container { cell: id }); tableCell.appendChild(cellLine); - if (ref) { tableRow.insertBefore(tableCell, ref); } else { tableRow.appendChild(tableCell); } } - - insertColumn(compareRect, colIndex, isRight = true, editorWrapper) { + insertColumn(compareRect, colIndex) { + let isRight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + let editorWrapper = arguments.length > 3 ? arguments[3] : undefined; const [body] = this.descendants(TableBody); const [tableColGroup] = this.descendants(TableColGroup); const tableCols = this.descendants(TableCol); @@ -1912,7 +1808,6 @@ class table_TableContainer extends Container { const tableCells = this.descendants(TableCell); tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (isRight) { if (Math.abs(cellRect.x1 - compareRect.x1) < ERROR_LIMIT) { // the right of selected boundary equal to the right of table cell, @@ -1951,25 +1846,22 @@ class table_TableContainer extends Container { rowspan: cellFormats.rowspan }); tableCell.appendChild(cellLine); - if (ref) { tableRow.insertBefore(tableCell, ref); } else { tableRow.appendChild(tableCell); } - affectedCells.push(tableCell); - }); // insert new tableCol + }); + // insert new tableCol const tableCol = this.scroll.create(TableCol.blotName, true); let colRef = isRight ? tableCols[colIndex].next : tableCols[colIndex]; - if (colRef) { tableColGroup.insertBefore(tableCol, colRef); } else { tableColGroup.appendChild(tableCol); } - modifiedCells.forEach(cell => { const cellColspan = cell.formats().colspan; cell.format('colspan', parseInt(cellColspan, 10) + 1); @@ -1983,7 +1875,6 @@ class table_TableContainer extends Container { this.updateTableWidth(); return affectedCells; } - insertRow(compareRect, isDown, editorWrapper) { const [body] = this.descendants(TableBody); if (body == null || body.children.head == null) return; @@ -1997,7 +1888,6 @@ class table_TableContainer extends Container { let affectedCells = []; tableCells.forEach(cell => { const cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (isDown) { if (Math.abs(cellRect.y1 - compareRect.y1) < ERROR_LIMIT) { addBelowCells.push(cell); @@ -2011,15 +1901,15 @@ class table_TableContainer extends Container { modifiedCells.push(cell); } } - }); // ordered table cells with rect.x, fix error for inserting - // new table cell in complicated table with wrong order. + }); + // ordered table cells with rect.x, fix error for inserting + // new table cell in complicated table with wrong order. const sortFunc = (cellA, cellB) => { let x1 = cellA.domNode.getBoundingClientRect().x; let x2 = cellB.domNode.getBoundingClientRect().x; return x1 - x2; }; - addBelowCells.sort(sortFunc); addBelowCells.forEach(cell => { const cId = table_cellId(); @@ -2046,19 +1936,18 @@ class table_TableContainer extends Container { }); const refRow = this.rows().find(row => { let rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), editorWrapper); - if (isDown) { return Math.abs(rowRect.y - compareRect.y - compareRect.height) < ERROR_LIMIT; } else { return Math.abs(rowRect.y - compareRect.y) < ERROR_LIMIT; } }); - body.insertBefore(newRow, refRow); // reordering affectedCells + body.insertBefore(newRow, refRow); + // reordering affectedCells affectedCells.sort(sortFunc); return affectedCells; } - mergeCells(compareRect, mergingCells, rowspan, colspan, editorWrapper) { const mergedCell = mergingCells.reduce((result, tableCell, index) => { if (index !== 0) { @@ -2069,7 +1958,6 @@ class table_TableContainer extends Container { tableCell.format('rowspan', rowspan); result = tableCell; } - return result; }, null); let rowId = mergedCell.domNode.getAttribute('data-row'); @@ -2082,7 +1970,6 @@ class table_TableContainer extends Container { }); return mergedCell; } - unmergeCells(unmergingCells, editorWrapper) { let cellFormats = {}; let cellRowspan = 1; @@ -2091,81 +1978,63 @@ class table_TableContainer extends Container { cellFormats = tableCell.formats(); cellRowspan = cellFormats.rowspan; cellColspan = cellFormats.colspan; - if (cellColspan > 1) { let ref = tableCell.next; let row = tableCell.row(); tableCell.format('colspan', 1); - for (let i = cellColspan; i > 1; i--) { this.insertCell(row, ref); } } - if (cellRowspan > 1) { let i = cellRowspan; let nextRow = tableCell.row().next; - while (i > 1) { let refInNextRow = nextRow.children.reduce((result, cell) => { let compareRect = getRelativeRect(tableCell.domNode.getBoundingClientRect(), editorWrapper); let cellRect = getRelativeRect(cell.domNode.getBoundingClientRect(), editorWrapper); - if (Math.abs(compareRect.x1 - cellRect.x) < ERROR_LIMIT) { result = cell; } - return result; }, null); - for (let i = cellColspan; i > 0; i--) { this.insertCell(nextRow, refInNextRow); } - i -= 1; nextRow = nextRow.next; } - tableCell.format('rowspan', 1); } }); } - rows() { const body = this.children.tail; if (body == null) return []; return body.children.map(row => row); } - } - table_TableContainer.blotName = "table-container"; table_TableContainer.className = "quill-better-table"; table_TableContainer.tagName = "TABLE"; - class table_TableViewWrapper extends Container { constructor(scroll, domNode) { super(scroll, domNode); const quill = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(scroll.domNode.parentNode); domNode.addEventListener('scroll', e => { const tableModule = quill.getModule('better-table'); - if (tableModule.columnTool) { tableModule.columnTool.domNode.scrollLeft = e.target.scrollLeft; } - if (tableModule.tableSelection && tableModule.tableSelection.selectedTds.length > 0) { tableModule.tableSelection.repositionHelpLines(); } }, false); } - table() { return this.children.head; } - } - table_TableViewWrapper.blotName = "table-view"; table_TableViewWrapper.className = "quill-better-table-wrapper"; table_TableViewWrapper.tagName = "DIV"; @@ -2182,18 +2051,15 @@ TableCellLine.requiredContainer = TableCell; TableColGroup.allowedChildren = [TableCol]; TableColGroup.requiredContainer = table_TableContainer; TableCol.requiredContainer = TableColGroup; - function table_rowId() { const id = Math.random().toString(36).slice(2, 6); return `row-${id}`; } - function table_cellId() { const id = Math.random().toString(36).slice(2, 6); return `cell-${id}`; } - // CONCATENATED MODULE: ./src/modules/table-selection.js @@ -2208,9 +2074,7 @@ class table_selection_TableSelection { this.quill = quill; this.options = options; this.boundary = {}; // params for selected square - this.selectedTds = []; // array for selected table-cells - this.dragging = false; this.selectingHandler = this.mouseDownHandler.bind(this); this.clearSelectionHandler = this.clearSelection.bind(this); @@ -2218,7 +2082,6 @@ class table_selection_TableSelection { this.quill.root.addEventListener('mousedown', this.selectingHandler, false); this.quill.on('text-change', this.clearSelectionHandler); } - helpLinesInitial() { let parent = this.quill.root.parentNode; LINE_POSITIONS.forEach(direction => { @@ -2233,7 +2096,6 @@ class table_selection_TableSelection { parent.appendChild(this[direction]); }); } - mouseDownHandler(e) { if (e.button !== 0 || !e.target.closest(".quill-better-table")) return; this.quill.root.addEventListener('mousemove', mouseMoveHandler, false); @@ -2246,7 +2108,6 @@ class table_selection_TableSelection { this.correctBoundary(); this.selectedTds = this.computeSelectedTds(); this.repositionHelpLines(); - function mouseMoveHandler(e) { if (e.button !== 0 || !e.target.closest(".quill-better-table")) return; const endTd = e.target.closest('td[data-row]'); @@ -2254,20 +2115,19 @@ class table_selection_TableSelection { self.boundary = computeBoundaryFromRects(startTdRect, endTdRect); self.correctBoundary(); self.selectedTds = self.computeSelectedTds(); - self.repositionHelpLines(); // avoid select text in multiple table-cell + self.repositionHelpLines(); + // avoid select text in multiple table-cell if (startTd !== endTd) { self.quill.blur(); } } - function mouseUpHandler(e) { self.quill.root.removeEventListener('mousemove', mouseMoveHandler, false); self.quill.root.removeEventListener('mouseup', mouseUpHandler, false); self.dragging = false; } } - correctBoundary() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const tableCells = tableContainer.descendants(TableCell); @@ -2279,7 +2139,6 @@ class table_selection_TableSelection { height } = getRelativeRect(tableCell.domNode.getBoundingClientRect(), this.quill.root.parentNode); let isCellIntersected = (x + table_selection_ERROR_LIMIT >= this.boundary.x && x + table_selection_ERROR_LIMIT <= this.boundary.x1 || x - table_selection_ERROR_LIMIT + width >= this.boundary.x && x - table_selection_ERROR_LIMIT + width <= this.boundary.x1) && (y + table_selection_ERROR_LIMIT >= this.boundary.y && y + table_selection_ERROR_LIMIT <= this.boundary.y1 || y - table_selection_ERROR_LIMIT + height >= this.boundary.y && y - table_selection_ERROR_LIMIT + height <= this.boundary.y1); - if (isCellIntersected) { this.boundary = computeBoundaryFromRects(this.boundary, { x, @@ -2290,7 +2149,6 @@ class table_selection_TableSelection { } }); } - computeSelectedTds() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const tableCells = tableContainer.descendants(TableCell); @@ -2302,15 +2160,12 @@ class table_selection_TableSelection { height } = getRelativeRect(tableCell.domNode.getBoundingClientRect(), this.quill.root.parentNode); let isCellIncluded = x + table_selection_ERROR_LIMIT >= this.boundary.x && x - table_selection_ERROR_LIMIT + width <= this.boundary.x1 && y + table_selection_ERROR_LIMIT >= this.boundary.y && y - table_selection_ERROR_LIMIT + height <= this.boundary.y1; - if (isCellIncluded) { selectedCells.push(tableCell); } - return selectedCells; }, []); } - repositionHelpLines() { const tableViewScrollLeft = this.table.parentNode.scrollLeft; css(this.left, { @@ -2341,17 +2196,16 @@ class table_selection_TableSelection { width: `${this.boundary.width + 1}px`, height: '1px' }); - } // based on selectedTds compute positions of help lines - // It is useful when selectedTds are not changed - + } + // based on selectedTds compute positions of help lines + // It is useful when selectedTds are not changed refreshHelpLinesPosition() { const startRect = getRelativeRect(this.selectedTds[0].domNode.getBoundingClientRect(), this.quill.root.parentNode); const endRect = getRelativeRect(this.selectedTds[this.selectedTds.length - 1].domNode.getBoundingClientRect(), this.quill.root.parentNode); this.boundary = computeBoundaryFromRects(startRect, endRect); this.repositionHelpLines(); } - destroy() { LINE_POSITIONS.forEach(direction => { this[direction].remove(); @@ -2361,14 +2215,12 @@ class table_selection_TableSelection { this.quill.off('text-change', this.clearSelectionHandler); return null; } - setSelection(startRect, endRect) { this.boundary = computeBoundaryFromRects(getRelativeRect(startRect, this.quill.root.parentNode), getRelativeRect(endRect, this.quill.root.parentNode)); this.correctBoundary(); this.selectedTds = this.computeSelectedTds(); this.repositionHelpLines(); } - clearSelection() { this.boundary = {}; this.selectedTds = []; @@ -2378,9 +2230,7 @@ class table_selection_TableSelection { }); }); } - } - function computeBoundaryFromRects(startRect, endRect) { let x = Math.min(startRect.x, endRect.x, startRect.x + startRect.width - 1, endRect.x + endRect.width - 1); let x1 = Math.max(startRect.x, endRect.x, startRect.x + startRect.width - 1, endRect.x + endRect.width - 1); @@ -2435,9 +2285,10 @@ var icon_operation_9_default = /*#__PURE__*/__webpack_require__.n(icon_operation // CONCATENATED MODULE: ./src/modules/table-operation-menu.js - // svg icons +// svg icons + @@ -2455,7 +2306,6 @@ const MENU_ITEMS_DEFAULT = { insertColumnRight: { text: 'Insert column right', iconSrc: icon_operation_1_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); let colIndex = getColToolCellIndexByBoundary(this.columnToolCells, this.boundary, (cellRect, boundary) => { @@ -2467,12 +2317,10 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(newColumn[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(newColumn[0].domNode.getBoundingClientRect(), newColumn[0].domNode.getBoundingClientRect()); } - }, insertColumnLeft: { text: 'Insert column left', iconSrc: icon_operation_2_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); let colIndex = getColToolCellIndexByBoundary(this.columnToolCells, this.boundary, (cellRect, boundary) => { @@ -2484,12 +2332,10 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(newColumn[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(newColumn[0].domNode.getBoundingClientRect(), newColumn[0].domNode.getBoundingClientRect()); } - }, insertRowUp: { text: 'Insert row up', iconSrc: icon_operation_3_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const affectedCells = tableContainer.insertRow(this.boundary, false, this.quill.root.parentNode); @@ -2497,12 +2343,10 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(affectedCells[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(affectedCells[0].domNode.getBoundingClientRect(), affectedCells[0].domNode.getBoundingClientRect()); } - }, insertRowDown: { text: 'Insert row down', iconSrc: icon_operation_4_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); const affectedCells = tableContainer.insertRow(this.boundary, true, this.quill.root.parentNode); @@ -2510,87 +2354,73 @@ const MENU_ITEMS_DEFAULT = { this.quill.setSelection(this.quill.getIndex(affectedCells[0]), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.tableSelection.setSelection(affectedCells[0].domNode.getBoundingClientRect(), affectedCells[0].domNode.getBoundingClientRect()); } - }, mergeCells: { text: 'Merge selected cells', iconSrc: icon_operation_5_default.a, - handler() { - const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); // compute merged Cell rowspan, equal to length of selected rows - + const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); + // compute merged Cell rowspan, equal to length of selected rows const rowspan = tableContainer.rows().reduce((sum, row) => { let rowRect = getRelativeRect(row.domNode.getBoundingClientRect(), this.quill.root.parentNode); - if (rowRect.y > this.boundary.y - table_operation_menu_ERROR_LIMIT && rowRect.y + rowRect.height < this.boundary.y + this.boundary.height + table_operation_menu_ERROR_LIMIT) { sum += 1; } - return sum; - }, 0); // compute merged cell colspan, equal to length of selected cols + }, 0); + // compute merged cell colspan, equal to length of selected cols const colspan = this.columnToolCells.reduce((sum, cell) => { let cellRect = getRelativeRect(cell.getBoundingClientRect(), this.quill.root.parentNode); - if (cellRect.x > this.boundary.x - table_operation_menu_ERROR_LIMIT && cellRect.x + cellRect.width < this.boundary.x + this.boundary.width + table_operation_menu_ERROR_LIMIT) { sum += 1; } - return sum; }, 0); const mergedCell = tableContainer.mergeCells(this.boundary, this.selectedTds, rowspan, colspan, this.quill.root.parentNode); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.setSelection(mergedCell.domNode.getBoundingClientRect(), mergedCell.domNode.getBoundingClientRect()); } - }, unmergeCells: { text: 'Unmerge cells', iconSrc: icon_operation_6_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); tableContainer.unmergeCells(this.selectedTds, this.quill.root.parentNode); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.clearSelection(); } - }, deleteColumn: { text: 'Delete selected columns', iconSrc: icon_operation_7_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); let colIndexes = getColToolCellIndexesByBoundary(this.columnToolCells, this.boundary, (cellRect, boundary) => { return cellRect.x + table_operation_menu_ERROR_LIMIT > boundary.x && cellRect.x + cellRect.width - table_operation_menu_ERROR_LIMIT < boundary.x1; }, this.quill.root.parentNode); let isDeleteTable = tableContainer.deleteColumns(this.boundary, colIndexes, this.quill.root.parentNode); - if (!isDeleteTable) { this.tableColumnTool.updateToolCells(); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.clearSelection(); } } - }, deleteRow: { text: 'Delete selected rows', iconSrc: icon_operation_8_default.a, - handler() { const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); tableContainer.deleteRow(this.boundary, this.quill.root.parentNode); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.tableSelection.clearSelection(); } - }, deleteTable: { text: 'Delete table', iconSrc: icon_operation_9_default.a, - handler() { const betterTableModule = this.quill.getModule('better-table'); const tableContainer = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.find(this.table); @@ -2598,7 +2428,6 @@ const MENU_ITEMS_DEFAULT = { tableContainer.remove(); this.quill.update(external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); } - } }; class table_operation_menu_TableOperationMenu { @@ -2620,22 +2449,20 @@ class table_operation_menu_TableOperationMenu { this.mount(); document.addEventListener("click", this.destroyHandler, false); } - mount() { document.body.appendChild(this.domNode); } - destroy() { this.domNode.remove(); document.removeEventListener("click", this.destroyHandler, false); return null; } - - menuInitial({ - table, - left, - top - }) { + menuInitial(_ref) { + let { + table, + left, + top + } = _ref; this.domNode = document.createElement('div'); this.domNode.classList.add('qlbt-operation-menu'); css(this.domNode, { @@ -2645,32 +2472,30 @@ class table_operation_menu_TableOperationMenu { 'min-height': `${MENU_MIN_HEIHGT}px`, width: `${MENU_WIDTH}px` }); - for (let name in this.menuItems) { if (this.menuItems[name]) { this.domNode.appendChild(this.menuItemCreator(Object.assign({}, MENU_ITEMS_DEFAULT[name], this.menuItems[name]))); - if (['insertRowDown', 'unmergeCells'].indexOf(name) > -1) { this.domNode.appendChild(dividingCreator()); } } - } // if colors option is false, disabled bg color - + } + // if colors option is false, disabled bg color if (this.options.color && this.options.color !== false) { this.domNode.appendChild(dividingCreator()); this.domNode.appendChild(subTitleCreator(this.colorSubTitle)); this.domNode.appendChild(this.colorsItemCreator(this.cellColors)); - } // create dividing line - + } + // create dividing line function dividingCreator() { const dividing = document.createElement('div'); dividing.classList.add('qlbt-operation-menu-dividing'); return dividing; - } // create subtitle for menu - + } + // create subtitle for menu function subTitleCreator(title) { const subTitle = document.createElement('div'); subTitle.classList.add('qlbt-operation-menu-subtitle'); @@ -2678,7 +2503,6 @@ class table_operation_menu_TableOperationMenu { return subTitle; } } - colorsItemCreator(colors) { const self = this; const node = document.createElement('div'); @@ -2687,7 +2511,6 @@ class table_operation_menu_TableOperationMenu { let colorBox = colorBoxCreator(color); node.appendChild(colorBox); }); - function colorBoxCreator(color) { const box = document.createElement('div'); box.classList.add('qlbt-operation-color-picker-item'); @@ -2695,7 +2518,6 @@ class table_operation_menu_TableOperationMenu { box.style.backgroundColor = color; box.addEventListener('click', function () { const selectedTds = self.tableSelection.selectedTds; - if (selectedTds && selectedTds.length > 0) { selectedTds.forEach(tableCell => { tableCell.format('cell-bg', color); @@ -2704,15 +2526,14 @@ class table_operation_menu_TableOperationMenu { }, false); return box; } - return node; } - - menuItemCreator({ - text, - iconSrc, - handler - }) { + menuItemCreator(_ref2) { + let { + text, + iconSrc, + handler + } = _ref2; const node = document.createElement('div'); node.classList.add('qlbt-operation-menu-item'); const iconSpan = document.createElement('span'); @@ -2726,37 +2547,31 @@ class table_operation_menu_TableOperationMenu { node.addEventListener('click', handler.bind(this), false); return node; } - } - function getColToolCellIndexByBoundary(cells, boundary, conditionFn, container) { return cells.reduce((findIndex, cell) => { let cellRect = getRelativeRect(cell.getBoundingClientRect(), container); - if (conditionFn(cellRect, boundary)) { findIndex = cells.indexOf(cell); } - return findIndex; }, false); } - function getColToolCellIndexesByBoundary(cells, boundary, conditionFn, container) { return cells.reduce((findIndexes, cell) => { let cellRect = getRelativeRect(cell.getBoundingClientRect(), container); - if (conditionFn(cellRect, boundary)) { findIndexes.push(cells.indexOf(cell)); } - return findIndexes; }, []); } // CONCATENATED MODULE: ./src/utils/node-matchers.js -const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); // rebuild delta +const Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); +// rebuild delta function matchTableCell(node, delta, scroll) { const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; @@ -2767,10 +2582,11 @@ function matchTableCell(node, delta, scroll) { const colspan = node.getAttribute('colspan') || false; const rowspan = node.getAttribute('rowspan') || false; const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor; // The td from external table has no 'data-cell-bg' - const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); - const cellBorder = node.getAttribute('data-cell-border') || (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none' : undefined); // bugfix: empty table cells copied from other place will be removed unexpectedly + const cellBorder = node.getAttribute('data-cell-border') || (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none' : undefined); + const cellValign = node.getAttribute('data-cell-valign'); + // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { 'table-cell-line': { @@ -2778,18 +2594,17 @@ function matchTableCell(node, delta, scroll) { cell: cellId, rowspan, colspan, - 'cell-border': cellBorder + 'cell-border': cellBorder, + 'cell-valign': cellValign } }); return delta; } - delta = delta.reduce((newDelta, op) => { if (op.insert && typeof op.insert === 'string') { const lines = []; let insertStr = op.insert; let start = 0; - for (let i = 0; i < op.insert.length; i++) { if (insertStr.charAt(i) === '\n') { if (i === 0) { @@ -2798,11 +2613,9 @@ function matchTableCell(node, delta, scroll) { lines.push(insertStr.substring(start, i)); lines.push('\n'); } - start = i + 1; } } - const tailStr = insertStr.substring(start); if (tailStr) lines.push(tailStr); lines.forEach(text => { @@ -2811,7 +2624,6 @@ function matchTableCell(node, delta, scroll) { } else { newDelta.insert(op.insert, op.attributes); } - return newDelta; }, new Delta()); return delta.reduce((newDelta, op) => { @@ -2825,7 +2637,8 @@ function matchTableCell(node, delta, scroll) { rowspan, colspan, 'cell-bg': cellBg, - 'cell-border': cellBorder + 'cell-border': cellBorder, + 'cell-valign': cellValign } }, _omit(op.attributes, ['table']))); } else { @@ -2837,11 +2650,11 @@ function matchTableCell(node, delta, scroll) { newDelta.insert(op.insert, Object.assign({}, _omit(op.attributes, ['table', 'table-cell-line']))); } } - return newDelta; }, new Delta()); -} // replace th tag with td tag +} +// replace th tag with td tag function matchTableHeader(node, delta, scroll) { const row = node.parentNode; const table = row.parentNode.tagName === 'TABLE' ? row.parentNode : row.parentNode.parentNode; @@ -2850,8 +2663,9 @@ function matchTableHeader(node, delta, scroll) { const rowId = rows.indexOf(row) + 1; const cellId = cells.indexOf(node) + 1; const colspan = node.getAttribute('colspan') || false; - const rowspan = node.getAttribute('rowspan') || false; // bugfix: empty table cells copied from other place will be removed unexpectedly + const rowspan = node.getAttribute('rowspan') || false; + // bugfix: empty table cells copied from other place will be removed unexpectedly if (delta.length() === 0) { delta = new Delta().insert('\n', { 'table-cell-line': { @@ -2863,13 +2677,11 @@ function matchTableHeader(node, delta, scroll) { }); return delta; } - delta = delta.reduce((newDelta, op) => { if (op.insert && typeof op.insert === 'string') { const lines = []; let insertStr = op.insert; let start = 0; - for (let i = 0; i < op.insert.length; i++) { if (insertStr.charAt(i) === '\n') { if (i === 0) { @@ -2878,18 +2690,16 @@ function matchTableHeader(node, delta, scroll) { lines.push(insertStr.substring(start, i)); lines.push('\n'); } - start = i + 1; } } - const tailStr = insertStr.substring(start); - if (tailStr) lines.push(tailStr); // bugfix: no '\n' in op.insert, push a '\n' to lines + if (tailStr) lines.push(tailStr); + // bugfix: no '\n' in op.insert, push a '\n' to lines if (lines.indexOf('\n') < 0) { lines.push('\n'); } - lines.forEach(text => { text === '\n' ? newDelta.insert('\n', { 'table-cell-line': { @@ -2903,7 +2713,6 @@ function matchTableHeader(node, delta, scroll) { } else { newDelta.insert(op.insert, op.attributes); } - return newDelta; }, new Delta()); return delta.reduce((newDelta, op) => { @@ -2919,15 +2728,16 @@ function matchTableHeader(node, delta, scroll) { } else { newDelta.insert(op.insert, Object.assign({}, _omit(op.attributes, ['table', 'table-cell-line']))); } - return newDelta; }, new Delta()); -} // supplement colgroup and col +} +// supplement colgroup and col function matchTable(node, delta, scroll) { let newColDelta = new Delta(); - const topRow = node.querySelector('tr'); // bugfix: empty table will return empty delta + const topRow = node.querySelector('tr'); + // bugfix: empty table will return empty delta if (topRow === null) return newColDelta; const cellsInTopRow = Array.from(topRow.querySelectorAll('td')).concat(Array.from(topRow.querySelectorAll('th'))); const maxCellsNumber = cellsInTopRow.reduce((sum, cell) => { @@ -2935,10 +2745,11 @@ function matchTable(node, delta, scroll) { sum = sum + parseInt(cellColspan, 10); return sum; }, 0); - const colsNumber = node.querySelectorAll('col').length; // issue #2 + const colsNumber = node.querySelectorAll('col').length; + + // issue #2 // bugfix: the table copied from Excel had some default col tags missing // add missing col tags - if (colsNumber === maxCellsNumber) { return delta; } else { @@ -2947,20 +2758,16 @@ function matchTable(node, delta, scroll) { 'table-col': true }); } - if (colsNumber === 0) return newColDelta.concat(delta); let lastNumber = 0; return delta.reduce((finalDelta, op) => { finalDelta.insert(op.insert, op.attributes); - if (op.attributes && op.attributes['table-col']) { lastNumber += op.insert.length; - if (lastNumber === colsNumber) { finalDelta = finalDelta.concat(newColDelta); } } - return finalDelta; }, new Delta()); } @@ -2969,14 +2776,14 @@ function matchTable(node, delta, scroll) { - // import table node matchers +// import table node matchers + const Module = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('core/module'); const quill_better_table_Delta = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.import('delta'); - class quill_better_table_BetterTable extends Module { static register() { external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(TableCol, true); @@ -2987,13 +2794,15 @@ class quill_better_table_BetterTable extends Module { external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(TableBody, true); external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableContainer, true); external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableViewWrapper, true); - external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableViewWrapper, true); // register customized Header,overwriting quill built-in Header + external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.register(table_TableViewWrapper, true); + // register customized Header,overwriting quill built-in Header // Quill.register('formats/header', Header, true); } constructor(quill, options) { - super(quill, options); // handle click on quill-better-table + super(quill, options); + // handle click on quill-better-table this.quill.root.addEventListener('click', evt => { // bugfix: evt.path is undefined in Safari, FF, Micro Edge const path = getEventComposedPath(evt); @@ -3001,23 +2810,24 @@ class quill_better_table_BetterTable extends Module { const tableNode = path.filter(node => { return node.tagName && node.tagName.toUpperCase() === 'TABLE' && node.classList.contains('quill-better-table'); })[0]; - if (tableNode) { // current table clicked - if (this.table === tableNode) return; // other table clicked - + if (this.table === tableNode) return; + // other table clicked if (this.table) this.hideTableTools(); this.showTableTools(tableNode, quill, options); } else if (this.table) { // other clicked this.hideTableTools(); } - }, false); // handle right click on quill-better-table + }, false); + // handle right click on quill-better-table this.quill.root.addEventListener('contextmenu', evt => { if (!this.table) return true; - evt.preventDefault(); // bugfix: evt.path is undefined in Safari, FF, Micro Edge + evt.preventDefault(); + // bugfix: evt.path is undefined in Safari, FF, Micro Edge const path = getEventComposedPath(evt); if (!path || path.length <= 0) return; const tableNode = path.filter(node => { @@ -3030,13 +2840,10 @@ class quill_better_table_BetterTable extends Module { return node.tagName && node.tagName.toUpperCase() === 'TD' && node.getAttribute('data-row'); })[0]; let isTargetCellSelected = this.tableSelection.selectedTds.map(tableCell => tableCell.domNode).includes(cellNode); - if (this.tableSelection.selectedTds.length <= 0 || !isTargetCellSelected) { this.tableSelection.setSelection(cellNode.getBoundingClientRect(), cellNode.getBoundingClientRect()); } - if (this.tableOperationMenu) this.tableOperationMenu = this.tableOperationMenu.destroy(); - if (tableNode) { this.tableOperationMenu = new table_operation_menu_TableOperationMenu({ table: tableNode, @@ -3046,77 +2853,72 @@ class quill_better_table_BetterTable extends Module { top: evt.pageY }, quill, options.operationMenu); } - }, false); // add keyboard binding:Backspace - // prevent user hits backspace to delete table cell + }, false); + // add keyboard binding:Backspace + // prevent user hits backspace to delete table cell const KeyBoard = quill.getModule('keyboard'); quill.keyboard.addBinding({ key: 'Backspace' }, {}, function (range, context) { if (range.index === 0 || this.quill.getLength() <= 1) return true; const [line] = this.quill.getLine(range.index); - if (context.offset === 0) { const [prev] = this.quill.getLine(range.index - 1); - if (prev != null) { if (prev.statics.blotName === 'table-cell-line' && line.statics.blotName !== 'table-cell-line') return false; } } - return true; - }); // since only one matched bindings callback will excute. + }); + // since only one matched bindings callback will excute. // expected my binding callback excute first // I changed the order of binding callbacks - let thisBinding = quill.keyboard.bindings['Backspace'].pop(); - quill.keyboard.bindings['Backspace'].splice(0, 1, thisBinding); // add Matchers to match and render quill-better-table for initialization - // or pasting + quill.keyboard.bindings['Backspace'].splice(0, 1, thisBinding); + // add Matchers to match and render quill-better-table for initialization + // or pasting quill.clipboard.addMatcher('td', matchTableCell); quill.clipboard.addMatcher('th', matchTableHeader); - quill.clipboard.addMatcher('table', matchTable); // quill.clipboard.addMatcher('h1, h2, h3, h4, h5, h6', matchHeader) - // remove matcher for tr tag + quill.clipboard.addMatcher('table', matchTable); + // quill.clipboard.addMatcher('h1, h2, h3, h4, h5, h6', matchHeader) + // remove matcher for tr tag quill.clipboard.matchers = quill.clipboard.matchers.filter(matcher => { return matcher[0] !== 'tr'; }); } - - getTable(range = this.quill.getSelection()) { + getTable() { + let range = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.quill.getSelection(); if (range == null) return [null, null, null, -1]; const [cellLine, offset] = this.quill.getLine(range.index); - if (cellLine == null || cellLine.statics.blotName !== TableCellLine.blotName) { return [null, null, null, -1]; } - const cell = cellLine.tableCell(); const row = cell.row(); const table = row.table(); return [table, row, cell, offset]; } - insertTable(rows, columns) { const range = this.quill.getSelection(true); if (range == null) return; let currentBlot = this.quill.getLeaf(range.index)[0]; let delta = new quill_better_table_Delta().retain(range.index); - if (isInTableCell(currentBlot)) { console.warn(`Can not insert table into a table cell.`); return; } - - delta.insert('\n'); // insert table column - + delta.insert('\n'); + // insert table column delta = new Array(columns).fill('\n').reduce((memo, text) => { memo.insert(text, { 'table-col': true }); return memo; - }, delta); // insert table cell line with empty line - + }, delta); + // insert table cell line with empty line delta = new Array(rows).fill(0).reduce(memo => { let tableRowId = table_rowId(); return new Array(columns).fill('\n').reduce((memo, text) => { @@ -3132,13 +2934,11 @@ class quill_better_table_BetterTable extends Module { this.quill.updateContents(delta, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); this.quill.setSelection(range.index + columns + 1, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.API); } - showTableTools(table, quill, options) { this.table = table; this.columnTool = new table_column_tool_TableColumnTool(table, quill, options); this.tableSelection = new table_selection_TableSelection(table, quill, options); } - hideTableTools() { this.columnTool && this.columnTool.destroy(); this.tableSelection && this.tableSelection.destroy(); @@ -3148,46 +2948,36 @@ class quill_better_table_BetterTable extends Module { this.tableOperationMenu = null; this.table = null; } - } - quill_better_table_BetterTable.keyboardBindings = { 'table-cell-line backspace': { key: 'Backspace', format: ['table-cell-line'], collapsed: true, offset: 0, - handler(range, context) { const [line, offset] = this.quill.getLine(range.index); - if (!line.prev || line.prev.statics.blotName !== 'table-cell-line') { return false; } - return true; } - }, 'table-cell-line delete': { key: 'Delete', format: ['table-cell-line'], collapsed: true, suffix: /^$/, - handler() {} - }, 'table-cell-line enter': { key: 'Enter', shiftKey: null, format: ['table-cell-line'], - handler(range, context) { // bugfix: a unexpected new line inserted when user compositionend with hitting Enter if (this.quill.selection && this.quill.selection.composing) return; const Scope = external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.imports.parchment.Scope; - if (range.length > 0) { this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change } @@ -3196,13 +2986,12 @@ quill_better_table_BetterTable.keyboardBindings = { if (this.quill.scroll.query(format, Scope.BLOCK) && !Array.isArray(context.format[format])) { formats[format] = context.format[format]; } - return formats; - }, {}); // insert new cellLine with lineFormats - - this.quill.insertText(range.index, '\n', lineFormats['table-cell-line'], external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); // Earlier scroll.deleteAt might have messed up our selection, + }, {}); + // insert new cellLine with lineFormats + this.quill.insertText(range.index, '\n', lineFormats['table-cell-line'], external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); + // Earlier scroll.deleteAt might have messed up our selection, // so insertText's built in selection preservation is not reliable - this.quill.setSelection(range.index + 1, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.SILENT); this.quill.focus(); Object.keys(context.format).forEach(name => { @@ -3212,35 +3001,28 @@ quill_better_table_BetterTable.keyboardBindings = { this.quill.format(name, context.format[name], external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); }); } - }, 'table-cell-line up': makeTableArrowHandler(true), 'table-cell-line down': makeTableArrowHandler(false), 'down-to-table': { key: 'ArrowDown', collapsed: true, - handler(range, context) { const target = context.line.next; - if (target && target.statics.blotName === 'table-view') { const targetCell = target.table().rows()[0].children.head; const targetLine = targetCell.children.head; this.quill.setSelection(targetLine.offset(this.quill.scroll), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); return false; } - return true; } - }, 'up-to-table': { key: 'ArrowUp', collapsed: true, - handler(range, context) { const target = context.line.prev; - if (target && target.statics.blotName === 'table-view') { const rows = target.table().rows(); const targetCell = rows[rows.length - 1].children.head; @@ -3248,19 +3030,15 @@ quill_better_table_BetterTable.keyboardBindings = { this.quill.setSelection(targetLine.offset(this.quill.scroll), 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); return false; } - return true; } - } }; - function makeTableArrowHandler(up) { return { key: up ? 'ArrowUp' : 'ArrowDown', collapsed: true, format: ['table-cell-line'], - handler(range, context) { // TODO move to table module const key = up ? 'prev' : 'next'; @@ -3268,28 +3046,25 @@ function makeTableArrowHandler(up) { if (targetLine != null) return true; const cell = context.line.parent; const targetRow = cell.parent[key]; - if (targetRow != null && targetRow.statics.blotName === 'table-row') { let targetCell = targetRow.children.head; let totalColspanOfTargetCell = parseInt(targetCell.formats()['colspan'], 10); let cur = cell; - let totalColspanOfCur = parseInt(cur.formats()['colspan'], 10); // get targetCell above current cell depends on colspan + let totalColspanOfCur = parseInt(cur.formats()['colspan'], 10); + // get targetCell above current cell depends on colspan while (cur.prev != null) { cur = cur.prev; totalColspanOfCur += parseInt(cur.formats()['colspan'], 10); } - while (targetCell.next != null && totalColspanOfTargetCell < totalColspanOfCur) { targetCell = targetCell.next; totalColspanOfTargetCell += parseInt(targetCell.formats()['colspan'], 10); } - const index = targetCell.offset(this.quill.scroll); this.quill.setSelection(index, 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); } else { const targetLine = cell.table().parent[key]; - if (targetLine != null) { if (up) { this.quill.setSelection(targetLine.offset(this.quill.scroll) + targetLine.length() - 1, 0, external_commonjs_quill_commonjs2_quill_amd_quill_root_Quill_default.a.sources.USER); @@ -3298,21 +3073,16 @@ function makeTableArrowHandler(up) { } } } - return false; } - }; } - function isTableCell(blot) { return blot.statics.blotName === TableCell.blotName; } - function isInTableCell(current) { return current && current.parent ? isTableCell(current.parent) ? true : isInTableCell(current.parent) : false; } - /* harmony default export */ var quill_better_table = __webpack_exports__["default"] = (quill_better_table_BetterTable); /***/ }), diff --git a/dist/quill-better-table.min.js b/dist/quill-better-table.min.js index 3befa86..8c845c0 100644 --- a/dist/quill-better-table.min.js +++ b/dist/quill-better-table.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===w&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="8c47f450cf52c31f39d1",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),w++,M.e(e).then(t,(function(e){throw t(),e}));function t(){w--,"prepare"===h&&(v[e]||q(e),0===w&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(v,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(w[h]||(w[h]=[]),g(w[h],A.outdatedDependencies[h]));B&&(g(v,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h]))for(z=w[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in w)if(Object.prototype.hasOwnProperty.call(w,h)&&(c=H[h])){z=w[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return v.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(v).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],w={width:100},v=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return v.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){return y.concat(v).concat(["cell-bg","cell-border"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(v).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||w[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||w[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,t=[],o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,r){const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(r()));function r(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(r()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator({text:e,iconSrc:t,handler:o}){const r=document.createElement("div");r.classList.add("qlbt-operation-menu-item");const n=document.createElement("span");n.classList.add("qlbt-operation-menu-icon"),n.innerHTML=t;const l=document.createElement("span");return l.classList.add("qlbt-operation-menu-text"),l.innerText=e,r.appendChild(n),r.appendChild(l),r.addEventListener("click",o.bind(this),!1),r}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.style&&(e.style.borderColor||e.style.borderTopColor||e.style.borderRightColor||e.style.borderBottomColor||e.style.borderLeftColor),b=e.getAttribute("data-cell-border")||(f&&"#fefefe"===d(f)?"none":void 0);return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":b}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":b}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill")):"function"==typeof define&&define.amd?define(["quill"],t):"object"==typeof exports?exports.quillBetterTable=t(require("quill")):e.quillBetterTable=t(e.Quill)}(window,(function(e){return function(e){var t=window.webpackHotUpdatequillBetterTable;window.webpackHotUpdatequillBetterTable=function(e,o){!function(e,t){if(!x[e]||!y[e])return;for(var o in y[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(f[o]=t[o]);0==--g&&0===v&&A()}(e,o),t&&t(e,o)};var o,r=!0,n="7658a6d19ca9dd6d5afe",l={},i=[],s=[];function a(e){var t=H[e];if(!t)return M;var r=function(r){return t.hot.active?(H[r]?-1===H[r].parents.indexOf(e)&&H[r].parents.push(e):(i=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),i=[]),M(r)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return M[e]},set:function(t){M[e]=t}}};for(var l in M)Object.prototype.hasOwnProperty.call(M,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(r,l,n(l));return r.e=function(e){return"ready"===h&&u("prepare"),v++,M.e(e).then(t,(function(e){throw t(),e}));function t(){v--,"prepare"===h&&(w[e]||q(e),0===v&&0===g&&A())}},r.t=function(e,t){return 1&t&&(e=r(e)),M.t(e,-2&t)},r}function d(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:o!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,h){case"idle":(f={})[t]=e[t],u("ready");break;case"ready":T(t);break;case"prepare":case"check":case"dispose":case"apply":(m=m||[]).push(t)}},check:C,apply:E,status:function(e){if(!e)return h;c.push(e)},addStatusHandler:function(e){c.push(e)},removeStatusHandler:function(e){var t=c.indexOf(e);t>=0&&c.splice(t,1)},data:l[t]};return o=void 0,r}var c=[],h="idle";function u(e){h=e;for(var t=0;t0;){var n=r.pop(),l=n.id,i=n.chain;if((c=H[l])&&(!c.hot._selfAccepted||c.hot._selfInvalidated)){if(c.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:l};if(c.hot._main)return{type:"unaccepted",chain:i,moduleId:l};for(var s=0;s ")),A.type){case"self-declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of self decline: "+A.moduleId+O));break;case"declined":r.onDeclined&&r.onDeclined(A),r.ignoreDeclined||(E=new Error("Aborted because of declined dependency: "+A.moduleId+" in "+A.parentId+O));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(A),r.ignoreUnaccepted||(E=new Error("Aborted because "+h+" is not accepted"+O));break;case"accepted":r.onAccepted&&r.onAccepted(A),T=!0;break;case"disposed":r.onDisposed&&r.onDisposed(A),B=!0;break;default:throw new Error("Unexception type "+A.type)}if(E)return u("abort"),Promise.reject(E);if(T)for(h in y[h]=f[h],g(w,A.outdatedModules),A.outdatedDependencies)Object.prototype.hasOwnProperty.call(A.outdatedDependencies,h)&&(v[h]||(v[h]=[]),g(v[h],A.outdatedDependencies[h]));B&&(g(w,[A.moduleId]),y[h]=C)}var R,L=[];for(a=0;a0;)if(h=I.pop(),c=H[h]){var D={},j=c.hot._disposeHandlers;for(d=0;d=0&&V.parents.splice(R,1))}}for(h in v)if(Object.prototype.hasOwnProperty.call(v,h)&&(c=H[h]))for(z=v[h],d=0;d=0&&c.children.splice(R,1);u("apply"),void 0!==b&&(n=b,b=void 0);for(h in f=void 0,y)Object.prototype.hasOwnProperty.call(y,h)&&(e[h]=y[h]);var _=null;for(h in v)if(Object.prototype.hasOwnProperty.call(v,h)&&(c=H[h])){z=v[h];var U=[];for(a=0;a'},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t){e.exports=''},function(e,t,o){e.exports=o(11)},function(e,t,o){"use strict";o.r(t);var r=o(0),n=o.n(r);function l(e,t){if("object"==typeof t)for(let o in t)e.style[o]=t[o]}function i(e,t){let o=t.getBoundingClientRect();return{x:e.x-o.x-t.scrollLeft,y:e.y-o.y-t.scrollTop,x1:e.x-o.x-t.scrollLeft+e.width,y1:e.y-o.y-t.scrollTop+e.height,width:e.width,height:e.height}}function s(e,t){return e&&Object.keys(e).reduce((o,r)=>t.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}function a(e){let t;if(t=e.path||e.composedPath&&e.composedPath(),null==t&&e.target){t=[];let o=e.target;for(t.push(o);o&&o.parentNode;)o=o.parentNode,t.push(o)}return t}function d(e){if(/^(rgb|RGB)/.test(e)){for(var t=e.toString().match(/\d+/g),o="#",r=0;r<3;r++)o+=("0"+Number(t[r]).toString(16)).slice(-2);return o}if(/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(e)){var n=e.replace(/#/,"").split("");if(6===n.length)return e;if(3===n.length){var l="#";for(r=0;r{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let i=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?i[e].remove():(s=i[e],l(s,{"min-width":n+"px"})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),l(s,{"min-width":n+"px"}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.a.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,i=0,s=0,a=0,d=0,c={},h={},u=null;const p=e=>{e.preventDefault(),r&&(s=e.clientX,a=d+s-i>=50?s-i:50-d,l(u,{left:h.left+h.width-1+a+"px"}))},f=n=>{n.preventDefault();const b=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),m=t.colGroup().children.at(b);r&&(m.format("width",d+a),l(e,{"min-width":d+a+"px"}),i=0,s=0,a=0,d=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",f,!1),c={},h={},u.remove(),u=null,t.updateTableWidth();const g=this.quill.getModule("better-table").tableSelection;g&&g.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",f,!1),c=this.table.getBoundingClientRect(),h=e.getBoundingClientRect(),u=document.createElement("div"),l(u,{position:"fixed",top:h.top+"px",left:h.left+h.width-1+"px",zIndex:"100",height:c.height+12+4+"px",width:"1px",backgroundColor:"#35A7ED"}),document.body.appendChild(u),r=!0,i=t.clientX,d=h.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const h=n.a.import("blots/block");class u extends h{static create(e){"string"==typeof e&&(e={value:e});const t=super.create(e.value);return w.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),y.forEach(o=>{e[o]&&t.setAttribute("data-"+o,e[o])}),t}static formats(e){const t={};return t.value=this.tagName.indexOf(e.tagName)+1,y.concat(w).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),t)}format(e,t){const{row:o,cell:r,rowspan:n,colspan:l}=u.formats(this.domNode);e===u.blotName?t?super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l}):o?this.replaceWith(N.blotName,{row:o,cell:r,rowspan:n,colspan:l}):super.format(e,t):super.format(e,t)}optimize(e){const{row:t,rowspan:o,colspan:r}=u.formats(this.domNode);if(!t||this.parent instanceof C||this.wrap(C.blotName,{row:t,colspan:r,rowspan:o}),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length)if(null!=this.statics.defaultChild){const e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.cache={}}}u.blotName="header",u.tagName=["H1","H2","H3","H4","H5","H6"];var p=u;const f=n.a.import("blots/break"),b=n.a.import("blots/block"),m=n.a.import("blots/container"),g=["width"],v={width:100},w=["row","cell"],y=["rowspan","colspan"],x={rowspan:1,colspan:1};class N extends b{static create(e){const t=super.create(e);return w.forEach(o=>{let r="row"===o?M:B;t.setAttribute("data-"+o,e[o]||r())}),y.forEach(o=>{t.setAttribute("data-"+o,e[o]||x[o])}),e["cell-bg"]&&t.setAttribute("data-cell-bg",e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),e["cell-valign"]&&t.setAttribute("data-cell-valign",e["cell-valign"]),t}static formats(e){return y.concat(w).concat(["cell-bg","cell-border","cell-valign"]).reduce((t,o)=>(e.hasAttribute("data-"+o)&&(t[o]=e.getAttribute("data-"+o)||void 0),t),{})}format(e,t){if(y.concat(w).indexOf(e)>-1)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("cell-bg"===e)t?this.domNode.setAttribute("data-cell-bg",t):this.domNode.removeAttribute("data-cell-bg");else if("cell-border"===e)t?this.domNode.setAttribute("data-cell-border",t):this.domNode.removeAttribute("data-cell-border");else if("cell-valign"===e)t?this.domNode.setAttribute("data-"+e,t):this.domNode.removeAttribute("data-"+e);else if("header"===e){if(!t)return;const{row:o,cell:r,rowspan:n,colspan:l}=N.formats(this.domNode);super.format(e,{value:t,row:o,cell:r,rowspan:n,colspan:l})}else super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=this.domNode.getAttribute("data-colspan"),n=this.domNode.getAttribute("data-cell-bg"),l=this.domNode.getAttribute("data-cell-border"),i=this.domNode.getAttribute("data-cell-valign");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o,"cell-bg":n,"cell-border":l,"cell-valign":i}),super.optimize(e)}tableCell(){return this.parent}}N.blotName="table-cell-line",N.className="qlbt-cell-line",N.tagName="P";class C extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()[this.children.head.statics.blotName],t=this.children.tail.formats()[this.children.tail.statics.blotName],o=this.next.children.head.formats()[this.next.children.head.statics.blotName],r=this.next.children.tail.formats()[this.next.children.tail.statics.blotName];return e.cell===t.cell&&e.cell===o.cell&&e.cell===r.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),y.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),e["cell-bg"]&&(t.setAttribute("data-cell-bg",e["cell-bg"]),t.style.backgroundColor=e["cell-bg"]),e["cell-border"]&&t.setAttribute("data-cell-border",e["cell-border"]),e["cell-valign"]&&t.setAttribute("data-cell-valign",e["cell-valign"]),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(t["cell-bg"]=e.getAttribute("data-cell-bg")),e.hasAttribute("data-cell-border")&&(t["cell-border"]=e.getAttribute("data-cell-border")),e.hasAttribute("data-cell-valign")&&(t["cell-valign"]=e.getAttribute("data-cell-valign")),y.reduce((t,o)=>(e.hasAttribute(o)&&(t[o]=e.getAttribute(o)),t),t)}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell-bg")&&(e["cell-bg"]=this.domNode.getAttribute("data-cell-bg")),this.domNode.hasAttribute("data-cell-border")&&(e["cell-border"]=this.domNode.getAttribute("data-cell-border")),this.domNode.hasAttribute("data-cell-valign")&&(e["cell-valign"]=this.domNode.getAttribute("data-cell-valign")),y.reduce((e,t)=>(this.domNode.hasAttribute(t)&&(e[t]=this.domNode.getAttribute(t)),e),e)}toggleAttribute(e,t){t?this.domNode.setAttribute(e,t):this.domNode.removeAttribute(e)}formatChildren(e,t){this.children.forEach(o=>{o.format(e,t)})}format(e,t){y.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute("data-"+e,t),this.formatChildren(e,t)):"cell-bg"===e?(this.toggleAttribute("data-cell-bg",t),this.formatChildren(e,t),this.domNode.style.backgroundColor=t||"initial"):"cell-border"===e?(this.toggleAttribute("data-cell-border",t),this.formatChildren(e,t)):"cell-valign"===e?(this.toggleAttribute("data-cell-valign",t),this.formatChildren(e,t)):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row");!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t}),super.optimize(e)}row(){return this.parent}rowOffset(){return this.row()?this.row().rowOffset():-1}table(){return this.row()&&this.row().table()}}C.blotName="table",C.tagName="TD";class q extends m{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),o=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===r.row}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),t}formats(){return["row"].reduce((e,t)=>(this.domNode.hasAttribute("data-"+t)&&(e[t]=this.domNode.getAttribute("data-"+t)),e),{})}optimize(e){!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName),this.enforceAllowedChildren(),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}q.blotName="table-row",q.tagName="TR";class A extends m{}A.blotName="table-body",A.tagName="TBODY";class E extends b{static create(e){let t=super.create(e);return g.forEach(o=>{t.setAttribute(""+o,e[o]||v[o])}),t}static formats(e){return g.reduce((t,o)=>(e.hasAttribute(""+o)&&(t[o]=e.getAttribute(""+o)||void 0),t),{})}format(e,t){g.indexOf(e)>-1?this.domNode.setAttribute(""+e,t||v[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}E.blotName="table-col",E.tagName="col";class S extends m{}S.blotName="table-col-group",S.tagName="colgroup";class T extends m{static create(){return super.create()}constructor(e,t){super(e,t),this.updateTableWidth()}updateTableWidth(){setTimeout(()=>{const e=this.colGroup();if(!e)return;const t=e.children.reduce((e,t)=>e+=parseInt(t.formats()[E.blotName].width,10),0);this.domNode.style.width=t+"px"},0)}cells(e){return this.rows().map(t=>t.children.at(e))}colGroup(){return this.children.head}deleteColumns(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o=arguments.length>2?arguments[2]:void 0;const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=[],s=[];if(n.forEach(t=>{const r=i(t.domNode.getBoundingClientRect(),o);r.x+5>e.x&&r.x1-5e.x1-5&&s.push(t)}),l.length===n.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const o=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",o-t.length)}),this.updateTableWidth()}deleteRow(e,t){const[o]=this.descendants(A);if(null==o||null==o.children.head)return;const r=this.descendants(C),n=this.descendants(q),l=[],s=[],a=[],d=n.filter(o=>{const r=i(o.domNode.getBoundingClientRect(),t);return r.y>e.y-5&&r.y1{const r=i(o.domNode.getBoundingClientRect(),t);r.y>e.y-5&&r.y1e.y1-5&&(s.push(o),Math.abs(r.y-e.y)<5&&a.push(o))}),l.length===r.length)return void this.tableDestroy();const c=this.rows().reduce((o,r)=>{let n=i(r.domNode.getBoundingClientRect(),t);return n.y>e.y-5&&n.y1{const o=i(e.domNode.getBoundingClientRect(),t),r=e.parent.next,n=r.children.reduce((e,r)=>{const n=i(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x)<5&&(e=r),e},null);r.insertBefore(e,n),e.format("row",r.formats().row)}),l.forEach(e=>{e.remove()}),s.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)}),d.forEach(e=>e.remove())}tableDestroy(){const e=n.a.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(n.a.sources.USER)}insertCell(e,t){const o=B(),r=e.formats().row,n=this.scroll.create(C.blotName,Object.assign({},x,{row:r})),l=this.scroll.create(N.blotName,{row:r,cell:o});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t){let o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=arguments.length>3?arguments[3]:void 0;const[n]=this.descendants(A),[l]=this.descendants(S),s=this.descendants(E);let a=[],d=[],c=[];if(null==n||null==n.children.head)return;this.descendants(C).forEach(t=>{const n=i(t.domNode.getBoundingClientRect(),r);o?Math.abs(n.x1-e.x1)<5?a.push(t):e.x1-n.x>5&&e.x1-n.x1<-5&&d.push(t):Math.abs(n.x-e.x)<5?a.push(t):e.x-n.x>5&&e.x-n.x1<-5&&d.push(t)}),a.forEach(e=>{const t=o?e.next:e,r=B(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(C.blotName,Object.assign({},x,{row:l,rowspan:i.rowspan})),a=this.scroll.create(N.blotName,{row:l,cell:r,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),c.push(s)});const h=this.scroll.create(E.blotName,!0);let u=o?s[t].next:s[t];return u?l.insertBefore(h,u):l.appendChild(h),d.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),c.push(e)}),c.sort((e,t)=>e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y),this.updateTableWidth(),c}insertRow(e,t,o){const[r]=this.descendants(A);if(null==r||null==r.children.head)return;const n=this.descendants(C),l=M(),s=this.scroll.create(q.blotName,{row:l});let a=[],d=[],c=[];n.forEach(r=>{const n=i(r.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)<5?a.push(r):e.y1-n.y>5&&e.y1-n.y1<-5&&d.push(r):Math.abs(n.y-e.y)<5?a.push(r):e.y-n.y>5&&e.y-n.y1<-5&&d.push(r)});const h=(e,t)=>e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x;a.sort(h),a.forEach(e=>{const t=B(),o=e.formats(),r=this.scroll.create(C.blotName,Object.assign({},x,{row:l,colspan:o.colspan})),n=this.scroll.create(N.blotName,{row:l,cell:t,colspan:o.colspan}),i=this.scroll.create(f.blotName);n.appendChild(i),r.appendChild(n),s.appendChild(r),c.push(r)}),d.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),c.push(e)});const u=this.rows().find(r=>{let n=i(r.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)<5:Math.abs(n.y-e.y)<5});return r.insertBefore(s,u),c.sort(h),c}mergeCells(e,t,o,r,n){const l=t.reduce((e,t,n)=>(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=l.domNode.getAttribute("data-row"),s=l.children.head.domNode.getAttribute("data-cell");return l.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),l}unmergeCells(e,t){let o={},r=1,n=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,n=o.colspan,n>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,l=e.row().next;for(;o>1;){let r=l.children.reduce((o,r)=>{let n=i(e.domNode.getBoundingClientRect(),t),l=i(r.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)<5&&(o=r),o},null);for(let e=n;e>0;e--)this.insertCell(l,r);o-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}T.blotName="table-container",T.className="quill-better-table",T.tagName="TABLE";class H extends m{constructor(e,t){super(e,t);const o=n.a.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=o.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}table(){return this.children.head}}function M(){return"row-"+Math.random().toString(36).slice(2,6)}function B(){return"cell-"+Math.random().toString(36).slice(2,6)}H.blotName="table-view",H.className="quill-better-table-wrapper",H.tagName="DIV",H.allowedChildren=[T],T.requiredContainer=H,T.allowedChildren=[A,S],A.requiredContainer=T,A.allowedChildren=[q],q.requiredContainer=A,q.allowedChildren=[C],C.requiredContainer=q,C.allowedChildren=[N,p],N.requiredContainer=C,S.allowedChildren=[E],S.requiredContainer=T,E.requiredContainer=S;const O=["left","right","top","bottom"];class R{constructor(e,t,o){if(!e)return null;this.table=e,this.quill=t,this.options=o,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHandler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHandler)}helpLinesInitial(){let e=this.quill.root.parentNode;O.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),this[t].classList.add("qlbt-selection-line-"+t),l(this[t],{position:"absolute",display:"none","background-color":"#0589f3"}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",n,!1),this.quill.root.addEventListener("mouseup",(function e(o){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1}),!1);const t=this,o=e.target.closest("td[data-row]"),r=i(o.getBoundingClientRect(),this.quill.root.parentNode);function n(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const n=e.target.closest("td[data-row]"),l=i(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=L(r,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=L(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.a.find(this.table).descendants(C).forEach(e=>{let{x:t,y:o,width:r,height:n}=i(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);(t+2>=this.boundary.x&&t+2<=this.boundary.x1||t-2+r>=this.boundary.x&&t-2+r<=this.boundary.x1)&&(o+2>=this.boundary.y&&o+2<=this.boundary.y1||o-2+n>=this.boundary.y&&o-2+n<=this.boundary.y1)&&(this.boundary=L(this.boundary,{x:t,y:o,width:r,height:n}))})}computeSelectedTds(){return n.a.find(this.table).descendants(C).reduce((e,t)=>{let{x:o,y:r,width:n,height:l}=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o+2>=this.boundary.x&&o-2+n<=this.boundary.x1&&r+2>=this.boundary.y&&r-2+l<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;l(this.left,{display:"block",left:this.boundary.x-e-1+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.right,{display:"block",left:this.boundary.x1-e+"px",top:this.boundary.y+"px",height:this.boundary.height+1+"px",width:"1px"}),l(this.top,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y+"px",width:this.boundary.width+1+"px",height:"1px"}),l(this.bottom,{display:"block",left:this.boundary.x-1-e+"px",top:this.boundary.y1+1+"px",width:this.boundary.width+1+"px",height:"1px"})}refreshHelpLinesPosition(){const e=i(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=i(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=L(e,t),this.repositionHelpLines()}destroy(){return O.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHandler),null}setSelection(e,t){this.boundary=L(i(e,this.quill.root.parentNode),i(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],O.forEach(e=>{this[e]&&l(this[e],{display:"none"})})}}function L(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),r=Math.max(e.x,t.x,e.x+e.width-1,t.x+t.width-1),n=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),l=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:n,y1:l,width:r-o,height:l-n}}var k=o(1),z=o.n(k),I=o(2),D=o.n(I),j=o(3),V=o.n(j),_=o(4),U=o.n(_),P=o(5),W=o.n(P),G=o(6),X=o.n(G),K=o(7),Y=o.n(K),$=o(8),J=o.n($),Q=o(9),F=o.n(Q);const Z=["white","red","yellow","blue"],ee={insertColumnRight:{text:"Insert column right",iconSrc:z.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",iconSrc:D.a,handler(){const e=n.a.find(this.table);let t=oe(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const o=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",iconSrc:V.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",iconSrc:U.a,handler(){const e=n.a.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.a.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.a.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",iconSrc:W.a,handler(){const e=n.a.find(this.table),t=e.rows().reduce((e,t)=>{let o=i(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=i(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.width{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&n.push(e.indexOf(l)),n},[])}(this.columnToolCells,this.boundary,(e,t)=>e.x+5>t.x&&e.x+e.width-5-1&&this.domNode.appendChild(n()));function n(){const e=document.createElement("div");return e.classList.add("qlbt-operation-menu-dividing"),e}this.options.color&&!1!==this.options.color&&(this.domNode.appendChild(n()),this.domNode.appendChild(function(e){const t=document.createElement("div");return t.classList.add("qlbt-operation-menu-subtitle"),t.innerText=e,t}(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)))}colorsItemCreator(e){const t=this,o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker"),e.forEach(e=>{let r=function(e){const o=document.createElement("div");return o.classList.add("qlbt-operation-color-picker-item"),o.setAttribute("data-color",e),o.style.backgroundColor=e,o.addEventListener("click",(function(){const o=t.tableSelection.selectedTds;o&&o.length>0&&o.forEach(t=>{t.format("cell-bg",e)})}),!1),o}(e);o.appendChild(r)}),o}menuItemCreator(e){let{text:t,iconSrc:o,handler:r}=e;const n=document.createElement("div");n.classList.add("qlbt-operation-menu-item");const l=document.createElement("span");l.classList.add("qlbt-operation-menu-icon"),l.innerHTML=o;const i=document.createElement("span");return i.classList.add("qlbt-operation-menu-text"),i.innerText=t,n.appendChild(l),n.appendChild(i),n.addEventListener("click",r.bind(this),!1),n}}function oe(e,t,o,r){return e.reduce((n,l)=>{let s=i(l.getBoundingClientRect(),r);return o(s,t)&&(n=e.indexOf(l)),n},!1)}const re=n.a.import("delta");function ne(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("td")),a=l.indexOf(r)+1,c=i.indexOf(e)+1,h=e.getAttribute("colspan")||!1,u=e.getAttribute("rowspan")||!1,p=e.getAttribute("data-cell-bg")||e.style.backgroundColor,f=e.style&&(e.style.borderColor||e.style.borderTopColor||e.style.borderRightColor||e.style.borderBottomColor||e.style.borderLeftColor),b=e.getAttribute("data-cell-border")||(f&&"#fefefe"===d(f)?"none":void 0),m=e.getAttribute("data-cell-valign");return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-border":b,"cell-valign":m}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,s(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},Object.assign({},{row:a},t.attributes.table),{"table-cell-line":{row:a,cell:c,rowspan:u,colspan:h,"cell-bg":p,"cell-border":b,"cell-valign":m}},s(t.attributes,["table"]))):t.attributes&&t.attributes.background&&t.attributes.background===d(p)?e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line","background"]))):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function le(e,t,o){const r=e.parentNode,n="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),i=Array.from(r.querySelectorAll("th")),a=l.indexOf(r)+1,d=i.indexOf(e)+1,c=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return 0===t.length()?t=(new re).insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,n=0;for(let e=0;e{"\n"===o?e.insert("\n",{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}}):e.insert(o,t.attributes)})}else e.insert(t.insert,t.attributes);return e},new re)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert(t.insert,Object.assign({},{"table-cell-line":{row:a,cell:d,rowspan:h,colspan:c}})):e.insert(t.insert,Object.assign({},s(t.attributes,["table","table-cell-line"]))),e),new re)}function ie(e,t,o){let r=new re;const n=e.querySelector("tr");if(null===n)return r;const l=Array.from(n.querySelectorAll("td")).concat(Array.from(n.querySelectorAll("th"))).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0),i=e.querySelectorAll("col").length;if(i===l)return t;{for(let e=0;e(t.insert(o.insert,o.attributes),o.attributes&&o.attributes["table-col"]&&(e+=o.insert.length,e===i&&(t=t.concat(r))),t),new re)}}const se=n.a.import("core/module"),ae=n.a.import("delta");class de extends se{static register(){n.a.register(E,!0),n.a.register(S,!0),n.a.register(N,!0),n.a.register(C,!0),n.a.register(q,!0),n.a.register(A,!0),n.a.register(T,!0),n.a.register(H,!0),n.a.register(H,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(n){if(this.table===n)return;this.table&&this.hideTableTools(),this.showTableTools(n,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;o.preventDefault();const r=a(o);if(!r||r.length<=0)return;const n=r.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=r.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],i=r.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let s=this.tableSelection.selectedTds.map(e=>e.domNode).includes(i);(this.tableSelection.selectedTds.length<=0||!s)&&this.tableSelection.setSelection(i.getBoundingClientRect(),i.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),n&&(this.tableOperationMenu=new te({table:n,row:l,cell:i,left:o.pageX,top:o.pageY},e,t.operationMenu))},!1);e.getModule("keyboard");e.keyboard.addBinding({key:"Backspace"},{},(function(e,t){if(0===e.index||this.quill.getLength()<=1)return!0;const[o]=this.quill.getLine(e.index);if(0===t.offset){const[t]=this.quill.getLine(e.index-1);if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==o.statics.blotName)return!1}return!0}));let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o),e.clipboard.addMatcher("td",ne),e.clipboard.addMatcher("th",le),e.clipboard.addMatcher("table",ie),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.quill.getSelection();if(null==e)return[null,null,null,-1];const[t,o]=this.quill.getLine(e.index);if(null==t||t.statics.blotName!==N.blotName)return[null,null,null,-1];const r=t.tableCell(),n=r.row();return[n.table(),n,r,o]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;let r=this.quill.getLeaf(o.index)[0],l=(new ae).retain(o.index);!function e(t){return!(!t||!t.parent)&&(o=t.parent,o.statics.blotName===C.blotName||e(t.parent));var o}(r)?(l.insert("\n"),l=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),l),l=new Array(e).fill(0).reduce(e=>{let o=M();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:B()}}),e),e)},l),this.quill.updateContents(l,n.a.sources.USER),this.quill.setSelection(o.index+t+1,n.a.sources.API)):console.warn("Can not insert table into a table cell.")}showTableTools(e,t,o){this.table=e,this.columnTool=new c(e,t,o),this.tableSelection=new R(e,t,o)}hideTableTools(){this.columnTool&&this.columnTool.destroy(),this.tableSelection&&this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}function ce(e){return{key:e?"ArrowUp":"ArrowDown",collapsed:!0,format:["table-cell-line"],handler(t,o){const r=e?"prev":"next";if(null!=o.line[r])return!0;const l=o.line.parent,i=l.parent[r];if(null!=i&&"table-row"===i.statics.blotName){let e=i.children.head,t=parseInt(e.formats().colspan,10),o=l,r=parseInt(o.formats().colspan,10);for(;null!=o.prev;)o=o.prev,r+=parseInt(o.formats().colspan,10);for(;null!=e.next&&t0&&this.quill.scroll.deleteAt(e.index,e.length);const r=Object.keys(t.format).reduce((e,r)=>(this.quill.scroll.query(r,o.BLOCK)&&!Array.isArray(t.format[r])&&(e[r]=t.format[r]),e),{});this.quill.insertText(e.index,"\n",r["table-cell-line"],n.a.sources.USER),this.quill.setSelection(e.index+1,n.a.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==r[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.a.sources.USER))})}},"table-cell-line up":ce(!0),"table-cell-line down":ce(!1),"down-to-table":{key:"ArrowDown",collapsed:!0,handler(e,t){const o=t.line.next;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows()[0].children.head.children.head;return this.quill.setSelection(e.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}},"up-to-table":{key:"ArrowUp",collapsed:!0,handler(e,t){const o=t.line.prev;if(o&&"table-view"===o.statics.blotName){const e=o.table().rows(),t=e[e.length-1].children.head.children.head;return this.quill.setSelection(t.offset(this.quill.scroll),0,n.a.sources.USER),!1}return!0}}};t.default=de}]).default})); \ No newline at end of file diff --git a/src/formats/table.js b/src/formats/table.js index 7e9ea8e..8687384 100644 --- a/src/formats/table.js +++ b/src/formats/table.js @@ -8,346 +8,369 @@ const Container = Quill.import("blots/container") const COL_ATTRIBUTES = ["width"] const COL_DEFAULT = { - width: 100 + width: 100 } const CELL_IDENTITY_KEYS = ["row", "cell"] const CELL_ATTRIBUTES = ["rowspan", "colspan"] const CELL_DEFAULT = { - rowspan: 1, - colspan: 1 + rowspan: 1, + colspan: 1 } const ERROR_LIMIT = 5 class TableCellLine extends Block { - static create(value) { - const node = super.create(value) - - CELL_IDENTITY_KEYS.forEach(key => { - let identityMaker = key === 'row' - ? rowId : cellId - node.setAttribute(`data-${key}`, value[key] || identityMaker()) - }) - - CELL_ATTRIBUTES.forEach(attrName => { - node.setAttribute(`data-${attrName}`, value[attrName] || CELL_DEFAULT[attrName]) - }) - - if (value['cell-bg']) { - node.setAttribute('data-cell-bg', value['cell-bg']) - } - - if (value['cell-border']) { - node.setAttribute('data-cell-border', value['cell-border']) - } - - return node - } - - static formats(domNode) { - const formats = {} - - return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border']).reduce((formats, attribute) => { - if (domNode.hasAttribute(`data-${attribute}`)) { - formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined - } - return formats - }, formats); - } - - format(name, value) { - if (CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).indexOf(name) > -1) { - if (value) { - this.domNode.setAttribute(`data-${name}`, value) - } else { - this.domNode.removeAttribute(`data-${name}`) - } - } else if (name === 'cell-bg') { - if (value) { - this.domNode.setAttribute('data-cell-bg', value) - } else { - this.domNode.removeAttribute('data-cell-bg') - } - } else if (name === 'cell-border') { - if (value) { - this.domNode.setAttribute('data-cell-border', value) - } else { - this.domNode.removeAttribute('data-cell-border') - } - } else if (name === 'header') { - if (!value) return; - const { row, cell, rowspan, colspan } = TableCellLine.formats(this.domNode) - super.format(name, { - value, - row, - cell, - rowspan, - colspan - }) - } else { - super.format(name, value) - } - } - - optimize(context) { - // cover shadowBlot's wrap call, pass params parentBlot initialize - // needed - const rowId = this.domNode.getAttribute('data-row') - const rowspan = this.domNode.getAttribute('data-rowspan') - const colspan = this.domNode.getAttribute('data-colspan') - const cellBg = this.domNode.getAttribute('data-cell-bg') - const cellBorder = this.domNode.getAttribute('data-cell-border') - if (this.statics.requiredContainer && - !(this.parent instanceof this.statics.requiredContainer)) { - this.wrap(this.statics.requiredContainer.blotName, { - row: rowId, - colspan, - rowspan, - 'cell-bg': cellBg, - 'cell-border': cellBorder - }) - } - super.optimize(context) - } - - tableCell() { - return this.parent - } + static create(value) { + const node = super.create(value) + + CELL_IDENTITY_KEYS.forEach(key => { + let identityMaker = key === 'row' + ? rowId : cellId + node.setAttribute(`data-${key}`, value[key] || identityMaker()) + }) + + CELL_ATTRIBUTES.forEach(attrName => { + node.setAttribute(`data-${attrName}`, value[attrName] || CELL_DEFAULT[attrName]) + }) + + if (value['cell-bg']) { + node.setAttribute('data-cell-bg', value['cell-bg']) + } + + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']) + } + + if (value['cell-valign']) { + node.setAttribute('data-cell-valign', value['cell-valign']) + } + + return node + } + + static formats(domNode) { + const formats = {} + + return CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).concat(['cell-bg', 'cell-border', 'cell-valign']).reduce((formats, attribute) => { + if (domNode.hasAttribute(`data-${attribute}`)) { + formats[attribute] = domNode.getAttribute(`data-${attribute}`) || undefined + } + return formats + }, formats) + } + + format(name, value) { + if (CELL_ATTRIBUTES.concat(CELL_IDENTITY_KEYS).indexOf(name) > -1) { + if (value) { + this.domNode.setAttribute(`data-${name}`, value) + } else { + this.domNode.removeAttribute(`data-${name}`) + } + } else if (name === 'cell-bg') { + if (value) { + this.domNode.setAttribute('data-cell-bg', value) + } else { + this.domNode.removeAttribute('data-cell-bg') + } + } else if (name === 'cell-border') { + if (value) { + this.domNode.setAttribute('data-cell-border', value) + } else { + this.domNode.removeAttribute('data-cell-border') + } + } else if (name === 'cell-valign') { + if (value) { + this.domNode.setAttribute(`data-${name}`, value) + } else { + this.domNode.removeAttribute(`data-${name}`) + } + } else if (name === 'header') { + if (!value) return; + const { row, cell, rowspan, colspan } = TableCellLine.formats(this.domNode) + super.format(name, { + value, + row, + cell, + rowspan, + colspan + }) + } else { + super.format(name, value) + } + } + + optimize(context) { + // cover shadowBlot's wrap call, pass params parentBlot initialize + // needed + const rowId = this.domNode.getAttribute('data-row') + const rowspan = this.domNode.getAttribute('data-rowspan') + const colspan = this.domNode.getAttribute('data-colspan') + const cellBg = this.domNode.getAttribute('data-cell-bg') + const cellBorder = this.domNode.getAttribute('data-cell-border') + const cellValign = this.domNode.getAttribute('data-cell-valign') + if (this.statics.requiredContainer && + !(this.parent instanceof this.statics.requiredContainer)) { + this.wrap(this.statics.requiredContainer.blotName, { + row: rowId, + colspan, + rowspan, + 'cell-bg': cellBg, + 'cell-border': cellBorder, + 'cell-valign': cellValign + }) + } + super.optimize(context) + } + + tableCell() { + return this.parent + } } TableCellLine.blotName = "table-cell-line" TableCellLine.className = "qlbt-cell-line" TableCellLine.tagName = "P" class TableCell extends Container { - checkMerge() { - if (super.checkMerge() && this.next.children.head != null) { - const thisHead = this.children.head.formats()[this.children.head.statics.blotName] - const thisTail = this.children.tail.formats()[this.children.tail.statics.blotName] - const nextHead = this.next.children.head.formats()[this.next.children.head.statics.blotName] - const nextTail = this.next.children.tail.formats()[this.next.children.tail.statics.blotName] - return ( - thisHead.cell === thisTail.cell && - thisHead.cell === nextHead.cell && - thisHead.cell === nextTail.cell - ) + checkMerge() { + if (super.checkMerge() && this.next.children.head != null) { + const thisHead = this.children.head.formats()[this.children.head.statics.blotName] + const thisTail = this.children.tail.formats()[this.children.tail.statics.blotName] + const nextHead = this.next.children.head.formats()[this.next.children.head.statics.blotName] + const nextTail = this.next.children.tail.formats()[this.next.children.tail.statics.blotName] + return ( + thisHead.cell === thisTail.cell && + thisHead.cell === nextHead.cell && + thisHead.cell === nextTail.cell + ) + } + return false } - return false - } - static create(value) { - const node = super.create(value) - node.setAttribute("data-row", value.row) + static create(value) { + const node = super.create(value) + node.setAttribute("data-row", value.row) - CELL_ATTRIBUTES.forEach(attrName => { - if (value[attrName]) { - node.setAttribute(attrName, value[attrName]) - } - }) + CELL_ATTRIBUTES.forEach(attrName => { + if (value[attrName]) { + node.setAttribute(attrName, value[attrName]) + } + }) - if (value['cell-bg']) { - node.setAttribute('data-cell-bg', value['cell-bg']) - node.style.backgroundColor = value['cell-bg'] - } + if (value['cell-bg']) { + node.setAttribute('data-cell-bg', value['cell-bg']) + node.style.backgroundColor = value['cell-bg'] + } - if (value['cell-border']) { - node.setAttribute('data-cell-border', value['cell-border']) + if (value['cell-border']) { + node.setAttribute('data-cell-border', value['cell-border']) + } + + if (value['cell-valign']) { + node.setAttribute('data-cell-valign', value['cell-valign']); + } + + return node } - return node - } + static formats(domNode) { + const formats = {} - static formats(domNode) { - const formats = {} + if (domNode.hasAttribute("data-row")) { + formats["row"] = domNode.getAttribute("data-row") + } - if (domNode.hasAttribute("data-row")) { - formats["row"] = domNode.getAttribute("data-row") - } + if (domNode.hasAttribute("data-cell-bg")) { + formats["cell-bg"] = domNode.getAttribute("data-cell-bg") + } - if (domNode.hasAttribute("data-cell-bg")) { - formats["cell-bg"] = domNode.getAttribute("data-cell-bg") - } + if (domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = domNode.getAttribute("data-cell-border") + } + + if (domNode.hasAttribute("data-cell-valign")) { + formats["cell-valign"] = domNode.getAttribute("data-cell-valign") + } - if (domNode.hasAttribute("data-cell-border")) { - formats["cell-border"] = domNode.getAttribute("data-cell-border") + return CELL_ATTRIBUTES.reduce((formats, attribute) => { + if (domNode.hasAttribute(attribute)) { + formats[attribute] = domNode.getAttribute(attribute) + } + + return formats + }, formats) } - if (domNode.hasAttribute("data-cell-border")) { - formats["cell-border"] = domNode.getAttribute("data-cell-border") + cellOffset() { + if (this.parent) { + return this.parent.children.indexOf(this) + } + return -1 } - return CELL_ATTRIBUTES.reduce((formats, attribute) => { - if (domNode.hasAttribute(attribute)) { - formats[attribute] = domNode.getAttribute(attribute) - } + formats() { + const formats = {} - return formats - }, formats) - } + if (this.domNode.hasAttribute("data-row")) { + formats["row"] = this.domNode.getAttribute("data-row") + } - cellOffset() { - if (this.parent) { - return this.parent.children.indexOf(this) - } - return -1 - } + if (this.domNode.hasAttribute("data-cell-bg")) { + formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg") + } - formats() { - const formats = {} + if (this.domNode.hasAttribute("data-cell-border")) { + formats["cell-border"] = this.domNode.getAttribute("data-cell-border") + } - if (this.domNode.hasAttribute("data-row")) { - formats["row"] = this.domNode.getAttribute("data-row") - } + if (this.domNode.hasAttribute("data-cell-valign")) { + formats["cell-valign"] = this.domNode.getAttribute("data-cell-valign") + } - if (this.domNode.hasAttribute("data-cell-bg")) { - formats["cell-bg"] = this.domNode.getAttribute("data-cell-bg") - } + return CELL_ATTRIBUTES.reduce((formats, attribute) => { + if (this.domNode.hasAttribute(attribute)) { + formats[attribute] = this.domNode.getAttribute(attribute) + } - if (this.domNode.hasAttribute("data-cell-border")) { - formats["cell-border"] = this.domNode.getAttribute("data-cell-border") + return formats + }, formats) } - - return CELL_ATTRIBUTES.reduce((formats, attribute) => { - if (this.domNode.hasAttribute(attribute)) { - formats[attribute] = this.domNode.getAttribute(attribute) - } - - return formats - }, formats) - } toggleAttribute (name, value) { - if (value) { - this.domNode.setAttribute(name, value) - } else { - this.domNode.removeAttribute(name) + if (value) { + this.domNode.setAttribute(name, value) + } else { + this.domNode.removeAttribute(name) + } } - } formatChildren (name, value) { - this.children.forEach(child => { - child.format(name, value) - }) - } - - format(name, value) { - if (CELL_ATTRIBUTES.indexOf(name) > -1) { - this.toggleAttribute(name, value) - this.formatChildren(name, value) - } else if (['row'].indexOf(name) > -1) { - this.toggleAttribute(`data-${name}`, value) - this.formatChildren(name, value) - } else if (name === 'cell-bg') { - this.toggleAttribute('data-cell-bg', value) - this.formatChildren(name, value) - - if (value) { - this.domNode.style.backgroundColor = value - } else { - this.domNode.style.backgroundColor = 'initial' - } + this.children.forEach(child => { + child.format(name, value) + }) + } + + format(name, value) { + if (CELL_ATTRIBUTES.indexOf(name) > -1) { + this.toggleAttribute(name, value) + this.formatChildren(name, value) + } else if (['row'].indexOf(name) > -1) { + this.toggleAttribute(`data-${name}`, value) + this.formatChildren(name, value) + } else if (name === 'cell-bg') { + this.toggleAttribute('data-cell-bg', value) + this.formatChildren(name, value) + + if (value) { + this.domNode.style.backgroundColor = value + } else { + this.domNode.style.backgroundColor = 'initial' + } } else if (name === 'cell-border'){ - this.toggleAttribute('data-cell-border', value) - this.formatChildren(name, value) - } else { - super.format(name, value) + this.toggleAttribute('data-cell-border', value) + this.formatChildren(name, value) + } else if (name === 'cell-valign') { + this.toggleAttribute('data-cell-valign', value) + this.formatChildren(name, value) + } else { + super.format(name, value) + } } - } - optimize(context) { - const rowId = this.domNode.getAttribute("data-row") + optimize(context) { + const rowId = this.domNode.getAttribute("data-row") - if (this.statics.requiredContainer && - !(this.parent instanceof this.statics.requiredContainer)) { - this.wrap(this.statics.requiredContainer.blotName, { - row: rowId - }) + if (this.statics.requiredContainer && + !(this.parent instanceof this.statics.requiredContainer)) { + this.wrap(this.statics.requiredContainer.blotName, { + row: rowId + }) + } + super.optimize(context) } - super.optimize(context) - } - row() { - return this.parent - } + row() { + return this.parent + } - rowOffset() { - if (this.row()) { - return this.row().rowOffset() + rowOffset() { + if (this.row()) { + return this.row().rowOffset() + } + return -1 } - return -1 - } - table() { - return this.row() && this.row().table() - } + table() { + return this.row() && this.row().table() + } } TableCell.blotName = "table" TableCell.tagName = "TD" class TableRow extends Container { - checkMerge() { - if (super.checkMerge() && this.next.children.head != null) { - const thisHead = this.children.head.formats() - const thisTail = this.children.tail.formats() - const nextHead = this.next.children.head.formats() - const nextTail = this.next.children.tail.formats() - - return ( - thisHead.row === thisTail.row && - thisHead.row === nextHead.row && - thisHead.row === nextTail.row - ) - } - return false - } - - static create(value) { - const node = super.create(value) - node.setAttribute("data-row", value.row) - return node - } - - formats() { - return ["row"].reduce((formats, attrName) => { - if (this.domNode.hasAttribute(`data-${attrName}`)) { - formats[attrName] = this.domNode.getAttribute(`data-${attrName}`) - } - return formats - }, {}) - } + checkMerge() { + if (super.checkMerge() && this.next.children.head != null) { + const thisHead = this.children.head.formats() + const thisTail = this.children.tail.formats() + const nextHead = this.next.children.head.formats() + const nextTail = this.next.children.tail.formats() + + return ( + thisHead.row === thisTail.row && + thisHead.row === nextHead.row && + thisHead.row === nextTail.row + ) + } + return false + } - optimize (context) { - // optimize function of ShadowBlot - if ( - this.statics.requiredContainer && - !(this.parent instanceof this.statics.requiredContainer) - ) { - this.wrap(this.statics.requiredContainer.blotName) + static create(value) { + const node = super.create(value) + node.setAttribute("data-row", value.row) + return node } - // optimize function of ParentBlot - // note: modified this optimize function because - // TableRow should not be removed when the length of its children was 0 - this.enforceAllowedChildren() - if (this.uiNode != null && this.uiNode !== this.domNode.firstChild) { - this.domNode.insertBefore(this.uiNode, this.domNode.firstChild) + formats() { + return ["row"].reduce((formats, attrName) => { + if (this.domNode.hasAttribute(`data-${attrName}`)) { + formats[attrName] = this.domNode.getAttribute(`data-${attrName}`) + } + return formats + }, {}) } - // optimize function of ContainerBlot - if (this.children.length > 0 && this.next != null && this.checkMerge()) { - this.next.moveChildren(this) - this.next.remove() + optimize (context) { + // optimize function of ShadowBlot + if ( + this.statics.requiredContainer && + !(this.parent instanceof this.statics.requiredContainer) + ) { + this.wrap(this.statics.requiredContainer.blotName) + } + + // optimize function of ParentBlot + // note: modified this optimize function because + // TableRow should not be removed when the length of its children was 0 + this.enforceAllowedChildren() + if (this.uiNode != null && this.uiNode !== this.domNode.firstChild) { + this.domNode.insertBefore(this.uiNode, this.domNode.firstChild) + } + + // optimize function of ContainerBlot + if (this.children.length > 0 && this.next != null && this.checkMerge()) { + this.next.moveChildren(this) + this.next.remove() + } } - } - rowOffset() { - if (this.parent) { - return this.parent.children.indexOf(this) + rowOffset() { + if (this.parent) { + return this.parent.children.indexOf(this) + } + return -1 } - return -1 - } - table() { - return this.parent && this.parent.parent - } + table() { + return this.parent && this.parent.parent + } } TableRow.blotName = "table-row" TableRow.tagName = "TR" @@ -358,34 +381,34 @@ TableBody.tagName = "TBODY" class TableCol extends Block { static create (value) { - let node = super.create(value) - COL_ATTRIBUTES.forEach(attrName => { - node.setAttribute(`${attrName}`, value[attrName] || COL_DEFAULT[attrName]) - }) - return node - } - - static formats(domNode) { - return COL_ATTRIBUTES.reduce((formats, attribute) => { - if (domNode.hasAttribute(`${attribute}`)) { - formats[attribute] = - domNode.getAttribute(`${attribute}`) || undefined - } - return formats - }, {}) - } - - format(name, value) { - if (COL_ATTRIBUTES.indexOf(name) > -1) { - this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]) - } else { - super.format(name, value) - } - } + let node = super.create(value) + COL_ATTRIBUTES.forEach(attrName => { + node.setAttribute(`${attrName}`, value[attrName] || COL_DEFAULT[attrName]) + }) + return node + } + + static formats(domNode) { + return COL_ATTRIBUTES.reduce((formats, attribute) => { + if (domNode.hasAttribute(`${attribute}`)) { + formats[attribute] = + domNode.getAttribute(`${attribute}`) || undefined + } + return formats + }, {}) + } + + format(name, value) { + if (COL_ATTRIBUTES.indexOf(name) > -1) { + this.domNode.setAttribute(`${name}`, value || COL_DEFAULT[name]) + } else { + super.format(name, value) + } + } html () { - return this.domNode.outerHTML - } + return this.domNode.outerHTML + } } TableCol.blotName = "table-col" TableCol.tagName = "col" @@ -395,492 +418,492 @@ TableColGroup.blotName = "table-col-group" TableColGroup.tagName = "colgroup" class TableContainer extends Container { - static create() { - let node = super.create() - return node - } + static create() { + let node = super.create() + return node + } constructor (scroll, domNode) { - super(scroll, domNode) - this.updateTableWidth() - } + super(scroll, domNode) + this.updateTableWidth() + } updateTableWidth () { - setTimeout(() => { - const colGroup = this.colGroup() - if (!colGroup) return - const tableWidth = colGroup.children.reduce((sumWidth, col) => { - sumWidth = sumWidth + parseInt(col.formats()[TableCol.blotName].width, 10) - return sumWidth - }, 0) - this.domNode.style.width = `${tableWidth}px` - }, 0) - } - - cells(column) { - return this.rows().map(row => row.children.at(column)) - } + setTimeout(() => { + const colGroup = this.colGroup() + if (!colGroup) return + const tableWidth = colGroup.children.reduce((sumWidth, col) => { + sumWidth = sumWidth + parseInt(col.formats()[TableCol.blotName].width, 10) + return sumWidth + }, 0) + this.domNode.style.width = `${tableWidth}px` + }, 0) + } + + cells(column) { + return this.rows().map(row => row.children.at(column)) + } colGroup () { - return this.children.head - } - - deleteColumns(compareRect, delIndexes = [], editorWrapper) { - const [body] = this.descendants(TableBody) - if (body == null || body.children.head == null) return - - const tableCells = this.descendants(TableCell) - const removedCells = [] - const modifiedCells = [] - - tableCells.forEach(cell => { - const cellRect = getRelativeRect( - cell.domNode.getBoundingClientRect(), - editorWrapper - ) - - if ( - cellRect.x + ERROR_LIMIT > compareRect.x && - cellRect.x1 - ERROR_LIMIT < compareRect.x1 - ) { - removedCells.push(cell) - } else if ( - cellRect.x < compareRect.x + ERROR_LIMIT && - cellRect.x1 > compareRect.x1 - ERROR_LIMIT - ) { - modifiedCells.push(cell) - } - }) - - if (removedCells.length === tableCells.length) { - this.tableDestroy() - return true - } - - // remove the matches column tool cell - delIndexes.forEach((delIndex) => { - this.colGroup().children.at(delIndexes[0]).remove() - }) - - removedCells.forEach(cell => { - cell.remove() - }) - - modifiedCells.forEach(cell => { - const cellColspan = parseInt(cell.formats().colspan, 10) - const cellWidth = parseInt(cell.formats().width, 10) - cell.format('colspan', cellColspan - delIndexes.length) - }) - - this.updateTableWidth() - } - - deleteRow(compareRect, editorWrapper) { - const [body] = this.descendants(TableBody) - if (body == null || body.children.head == null) return - - const tableCells = this.descendants(TableCell) - const tableRows = this.descendants(TableRow) - const removedCells = [] // cells to be removed - const modifiedCells = [] // cells to be modified - const fallCells = [] // cells to fall into next row - - // compute rows to remove - // bugfix: #21 There will be a empty tr left if delete the last row of a table - const removedRows = tableRows.filter(row => { - const rowRect = getRelativeRect( - row.domNode.getBoundingClientRect(), - editorWrapper - ) - - return rowRect.y > compareRect.y - ERROR_LIMIT && - rowRect.y1 < compareRect.y1 + ERROR_LIMIT - }) - - tableCells.forEach(cell => { - const cellRect = getRelativeRect( - cell.domNode.getBoundingClientRect(), - editorWrapper - ) - - if ( - cellRect.y > compareRect.y - ERROR_LIMIT && - cellRect.y1 < compareRect.y1 + ERROR_LIMIT - ) { - removedCells.push(cell) - } else if ( - cellRect.y < compareRect.y + ERROR_LIMIT && - cellRect.y1 > compareRect.y1 - ERROR_LIMIT - ) { - modifiedCells.push(cell) - - if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) { - fallCells.push(cell) - } - } - }) - - if (removedCells.length === tableCells.length) { - this.tableDestroy() - return - } - - // compute length of removed rows - const removedRowsLength = this.rows().reduce((sum, row) => { - let rowRect = getRelativeRect( - row.domNode.getBoundingClientRect(), - editorWrapper - ) - - if ( - rowRect.y > compareRect.y - ERROR_LIMIT && - rowRect.y1 < compareRect.y1 + ERROR_LIMIT - ) { - sum += 1 - } - return sum - }, 0) - - // it must excute before the table layout changed with other operation - fallCells.forEach(cell => { - const cellRect = getRelativeRect( - cell.domNode.getBoundingClientRect(), - editorWrapper - ) - const nextRow = cell.parent.next - const cellsInNextRow = nextRow.children - - const refCell = cellsInNextRow.reduce((ref, compareCell) => { - const compareRect = getRelativeRect( - compareCell.domNode.getBoundingClientRect(), - editorWrapper - ) - if (Math.abs(cellRect.x1 - compareRect.x) < ERROR_LIMIT) { - ref = compareCell - } - return ref - }, null) - - nextRow.insertBefore(cell, refCell) - cell.format('row', nextRow.formats().row) - }) - - removedCells.forEach(cell => { - cell.remove() - }) - - modifiedCells.forEach(cell => { - const cellRowspan = parseInt(cell.formats().rowspan, 10) - cell.format("rowspan", cellRowspan - removedRowsLength) - }) - - // remove selected rows - removedRows.forEach(row => row.remove()) - } - - tableDestroy() { - const quill = Quill.find(this.scroll.domNode.parentNode) - const tableModule = quill.getModule("better-table") - this.remove() - tableModule.hideTableTools() - quill.update(Quill.sources.USER) - } - - insertCell(tableRow, ref) { - const id = cellId() - const rId = tableRow.formats().row - const tableCell = this.scroll.create( - TableCell.blotName, - Object.assign({}, CELL_DEFAULT, { - row: rId - }) - ) - const cellLine = this.scroll.create(TableCellLine.blotName, { - row: rId, - cell: id - }) - tableCell.appendChild(cellLine) - - if (ref) { - tableRow.insertBefore(tableCell, ref) - } else { - tableRow.appendChild(tableCell) - } - } - - insertColumn(compareRect, colIndex, isRight = true, editorWrapper) { - const [body] = this.descendants(TableBody) - const [tableColGroup] = this.descendants(TableColGroup) - const tableCols = this.descendants(TableCol) - let addAsideCells = [] - let modifiedCells = [] - let affectedCells = [] - - if (body == null || body.children.head == null) return - const tableCells = this.descendants(TableCell) - tableCells.forEach(cell => { - const cellRect = getRelativeRect( - cell.domNode.getBoundingClientRect(), - editorWrapper - ) - - if (isRight) { - if (Math.abs(cellRect.x1 - compareRect.x1) < ERROR_LIMIT) { - // the right of selected boundary equal to the right of table cell, - // add a new table cell right aside this table cell - addAsideCells.push(cell) - } else if ( - compareRect.x1 - cellRect.x > ERROR_LIMIT && - compareRect.x1 - cellRect.x1 < -ERROR_LIMIT - ) { - // the right of selected boundary is inside this table cell - // colspan of this table cell will increase 1 - modifiedCells.push(cell) - } - } else { - if (Math.abs(cellRect.x - compareRect.x) < ERROR_LIMIT) { - // left of selected boundary equal to left of table cell, - // add a new table cell left aside this table cell - addAsideCells.push(cell) - } else if ( - compareRect.x - cellRect.x > ERROR_LIMIT && - compareRect.x - cellRect.x1 < -ERROR_LIMIT - ) { - // the left of selected boundary is inside this table cell - // colspan of this table cell will increase 1 - modifiedCells.push(cell) - } - } - }) - - addAsideCells.forEach(cell => { - const ref = isRight ? cell.next : cell - const id = cellId() - const tableRow = cell.parent - const rId = tableRow.formats().row - const cellFormats = cell.formats() - const tableCell = this.scroll.create( - TableCell.blotName, - Object.assign({}, CELL_DEFAULT, { - row: rId, - rowspan: cellFormats.rowspan + return this.children.head + } + + deleteColumns(compareRect, delIndexes = [], editorWrapper) { + const [body] = this.descendants(TableBody) + if (body == null || body.children.head == null) return + + const tableCells = this.descendants(TableCell) + const removedCells = [] + const modifiedCells = [] + + tableCells.forEach(cell => { + const cellRect = getRelativeRect( + cell.domNode.getBoundingClientRect(), + editorWrapper + ) + + if ( + cellRect.x + ERROR_LIMIT > compareRect.x && + cellRect.x1 - ERROR_LIMIT < compareRect.x1 + ) { + removedCells.push(cell) + } else if ( + cellRect.x < compareRect.x + ERROR_LIMIT && + cellRect.x1 > compareRect.x1 - ERROR_LIMIT + ) { + modifiedCells.push(cell) + } }) - ) - const cellLine = this.scroll.create(TableCellLine.blotName, { - row: rId, - cell: id, - rowspan: cellFormats.rowspan - }) - tableCell.appendChild(cellLine) - - if (ref) { - tableRow.insertBefore(tableCell, ref) - } else { - tableRow.appendChild(tableCell) - } - affectedCells.push(tableCell) - }) - - // insert new tableCol - const tableCol = this.scroll.create(TableCol.blotName, true) - let colRef = isRight ? tableCols[colIndex].next : tableCols[colIndex] - if (colRef) { - tableColGroup.insertBefore(tableCol, colRef) - } else { - tableColGroup.appendChild(tableCol) - } - - modifiedCells.forEach(cell => { - const cellColspan = cell.formats().colspan - cell.format('colspan', parseInt(cellColspan, 10) + 1) - affectedCells.push(cell) - }) - - affectedCells.sort((cellA, cellB) => { - let y1 = cellA.domNode.getBoundingClientRect().y - let y2 = cellB.domNode.getBoundingClientRect().y - return y1 - y2 - }) - - this.updateTableWidth() - return affectedCells - } - - insertRow(compareRect, isDown, editorWrapper) { - const [body] = this.descendants(TableBody) - if (body == null || body.children.head == null) return - - const tableCells = this.descendants(TableCell) - const rId = rowId() - const newRow = this.scroll.create(TableRow.blotName, { - row: rId - }) - let addBelowCells = [] - let modifiedCells = [] - let affectedCells = [] - - tableCells.forEach(cell => { - const cellRect = getRelativeRect( - cell.domNode.getBoundingClientRect(), - editorWrapper - ) - - if (isDown) { - if (Math.abs(cellRect.y1 - compareRect.y1) < ERROR_LIMIT) { - addBelowCells.push(cell) - } else if ( - compareRect.y1 - cellRect.y > ERROR_LIMIT && - compareRect.y1 - cellRect.y1 < -ERROR_LIMIT - ) { - modifiedCells.push(cell) - } - } else { - if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) { - addBelowCells.push(cell) - } else if ( - compareRect.y - cellRect.y > ERROR_LIMIT && - compareRect.y - cellRect.y1 < -ERROR_LIMIT - ) { - modifiedCells.push(cell) - } - } - }) - - // ordered table cells with rect.x, fix error for inserting - // new table cell in complicated table with wrong order. - const sortFunc = (cellA, cellB) => { - let x1 = cellA.domNode.getBoundingClientRect().x - let x2 = cellB.domNode.getBoundingClientRect().x - return x1 - x2 - } - addBelowCells.sort(sortFunc) - - addBelowCells.forEach(cell => { - const cId = cellId() - const cellFormats = cell.formats() - - const tableCell = this.scroll.create(TableCell.blotName, Object.assign( - {}, CELL_DEFAULT, { row: rId, colspan: cellFormats.colspan } - )) - const cellLine = this.scroll.create(TableCellLine.blotName, { - row: rId, - cell: cId, - colspan: cellFormats.colspan - }) - const empty = this.scroll.create(Break.blotName) - cellLine.appendChild(empty) - tableCell.appendChild(cellLine) - newRow.appendChild(tableCell) - affectedCells.push(tableCell) - }) - - modifiedCells.forEach(cell => { - const cellRowspan = parseInt(cell.formats().rowspan, 10) - cell.format("rowspan", cellRowspan + 1) - affectedCells.push(cell) - }) - - const refRow = this.rows().find(row => { - let rowRect = getRelativeRect( - row.domNode.getBoundingClientRect(), - editorWrapper - ) - if (isDown) { - return Math.abs(rowRect.y - compareRect.y - compareRect.height) < ERROR_LIMIT - } else { - return Math.abs(rowRect.y - compareRect.y) < ERROR_LIMIT - } - }) - body.insertBefore(newRow, refRow) - - // reordering affectedCells - affectedCells.sort(sortFunc) - return affectedCells - } - mergeCells (compareRect, mergingCells, rowspan, colspan, editorWrapper) { - const mergedCell = mergingCells.reduce((result, tableCell, index) => { - if (index !== 0) { - result && tableCell.moveChildren(result) - tableCell.remove() - } else { - tableCell.format('colspan', colspan) - tableCell.format('rowspan', rowspan) - result = tableCell - } - - return result - }, null) - - let rowId = mergedCell.domNode.getAttribute('data-row') - let cellId = mergedCell.children.head.domNode.getAttribute('data-cell') - mergedCell.children.forEach(cellLine => { - cellLine.format('cell', cellId) - cellLine.format('row', rowId) - cellLine.format('colspan', colspan) - cellLine.format('rowspan', rowspan) - }) - - return mergedCell - } + if (removedCells.length === tableCells.length) { + this.tableDestroy() + return true + } - unmergeCells (unmergingCells, editorWrapper) { - let cellFormats = {} - let cellRowspan = 1 - let cellColspan = 1 - - unmergingCells.forEach(tableCell => { - cellFormats = tableCell.formats() - cellRowspan = cellFormats.rowspan - cellColspan = cellFormats.colspan - - if (cellColspan > 1) { - let ref = tableCell.next - let row = tableCell.row() - tableCell.format('colspan', 1) - for (let i = cellColspan; i > 1; i--) { - this.insertCell(row, ref) - } - } - - if (cellRowspan > 1) { - let i = cellRowspan - let nextRow = tableCell.row().next - while (i > 1) { - let refInNextRow = nextRow.children - .reduce((result, cell) => { - let compareRect = getRelativeRect( - tableCell.domNode.getBoundingClientRect(), + // remove the matches column tool cell + delIndexes.forEach((delIndex) => { + this.colGroup().children.at(delIndexes[0]).remove() + }) + + removedCells.forEach(cell => { + cell.remove() + }) + + modifiedCells.forEach(cell => { + const cellColspan = parseInt(cell.formats().colspan, 10) + const cellWidth = parseInt(cell.formats().width, 10) + cell.format('colspan', cellColspan - delIndexes.length) + }) + + this.updateTableWidth() + } + + deleteRow(compareRect, editorWrapper) { + const [body] = this.descendants(TableBody) + if (body == null || body.children.head == null) return + + const tableCells = this.descendants(TableCell) + const tableRows = this.descendants(TableRow) + const removedCells = [] // cells to be removed + const modifiedCells = [] // cells to be modified + const fallCells = [] // cells to fall into next row + + // compute rows to remove + // bugfix: #21 There will be a empty tr left if delete the last row of a table + const removedRows = tableRows.filter(row => { + const rowRect = getRelativeRect( + row.domNode.getBoundingClientRect(), editorWrapper - ) - let cellRect = getRelativeRect( + ) + + return rowRect.y > compareRect.y - ERROR_LIMIT && + rowRect.y1 < compareRect.y1 + ERROR_LIMIT + }) + + tableCells.forEach(cell => { + const cellRect = getRelativeRect( cell.domNode.getBoundingClientRect(), editorWrapper - ) - if (Math.abs(compareRect.x1 - cellRect.x) < ERROR_LIMIT) { - result = cell - } - return result + ) + + if ( + cellRect.y > compareRect.y - ERROR_LIMIT && + cellRect.y1 < compareRect.y1 + ERROR_LIMIT + ) { + removedCells.push(cell) + } else if ( + cellRect.y < compareRect.y + ERROR_LIMIT && + cellRect.y1 > compareRect.y1 - ERROR_LIMIT + ) { + modifiedCells.push(cell) + + if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) { + fallCells.push(cell) + } + } + }) + + if (removedCells.length === tableCells.length) { + this.tableDestroy() + return + } + + // compute length of removed rows + const removedRowsLength = this.rows().reduce((sum, row) => { + let rowRect = getRelativeRect( + row.domNode.getBoundingClientRect(), + editorWrapper + ) + + if ( + rowRect.y > compareRect.y - ERROR_LIMIT && + rowRect.y1 < compareRect.y1 + ERROR_LIMIT + ) { + sum += 1 + } + return sum + }, 0) + + // it must excute before the table layout changed with other operation + fallCells.forEach(cell => { + const cellRect = getRelativeRect( + cell.domNode.getBoundingClientRect(), + editorWrapper + ) + const nextRow = cell.parent.next + const cellsInNextRow = nextRow.children + + const refCell = cellsInNextRow.reduce((ref, compareCell) => { + const compareRect = getRelativeRect( + compareCell.domNode.getBoundingClientRect(), + editorWrapper + ) + if (Math.abs(cellRect.x1 - compareRect.x) < ERROR_LIMIT) { + ref = compareCell + } + return ref }, null) - for (let i = cellColspan; i > 0; i--) { - this.insertCell(nextRow, refInNextRow) - } + nextRow.insertBefore(cell, refCell) + cell.format('row', nextRow.formats().row) + }) + + removedCells.forEach(cell => { + cell.remove() + }) - i -= 1 - nextRow = nextRow.next + modifiedCells.forEach(cell => { + const cellRowspan = parseInt(cell.formats().rowspan, 10) + cell.format("rowspan", cellRowspan - removedRowsLength) + }) + + // remove selected rows + removedRows.forEach(row => row.remove()) + } + + tableDestroy() { + const quill = Quill.find(this.scroll.domNode.parentNode) + const tableModule = quill.getModule("better-table") + this.remove() + tableModule.hideTableTools() + quill.update(Quill.sources.USER) + } + + insertCell(tableRow, ref) { + const id = cellId() + const rId = tableRow.formats().row + const tableCell = this.scroll.create( + TableCell.blotName, + Object.assign({}, CELL_DEFAULT, { + row: rId + }) + ) + const cellLine = this.scroll.create(TableCellLine.blotName, { + row: rId, + cell: id + }) + tableCell.appendChild(cellLine) + + if (ref) { + tableRow.insertBefore(tableCell, ref) + } else { + tableRow.appendChild(tableCell) } + } - tableCell.format('rowspan', 1) - } - }) - } + insertColumn(compareRect, colIndex, isRight = true, editorWrapper) { + const [body] = this.descendants(TableBody) + const [tableColGroup] = this.descendants(TableColGroup) + const tableCols = this.descendants(TableCol) + let addAsideCells = [] + let modifiedCells = [] + let affectedCells = [] + + if (body == null || body.children.head == null) return + const tableCells = this.descendants(TableCell) + tableCells.forEach(cell => { + const cellRect = getRelativeRect( + cell.domNode.getBoundingClientRect(), + editorWrapper + ) + + if (isRight) { + if (Math.abs(cellRect.x1 - compareRect.x1) < ERROR_LIMIT) { + // the right of selected boundary equal to the right of table cell, + // add a new table cell right aside this table cell + addAsideCells.push(cell) + } else if ( + compareRect.x1 - cellRect.x > ERROR_LIMIT && + compareRect.x1 - cellRect.x1 < -ERROR_LIMIT + ) { + // the right of selected boundary is inside this table cell + // colspan of this table cell will increase 1 + modifiedCells.push(cell) + } + } else { + if (Math.abs(cellRect.x - compareRect.x) < ERROR_LIMIT) { + // left of selected boundary equal to left of table cell, + // add a new table cell left aside this table cell + addAsideCells.push(cell) + } else if ( + compareRect.x - cellRect.x > ERROR_LIMIT && + compareRect.x - cellRect.x1 < -ERROR_LIMIT + ) { + // the left of selected boundary is inside this table cell + // colspan of this table cell will increase 1 + modifiedCells.push(cell) + } + } + }) + + addAsideCells.forEach(cell => { + const ref = isRight ? cell.next : cell + const id = cellId() + const tableRow = cell.parent + const rId = tableRow.formats().row + const cellFormats = cell.formats() + const tableCell = this.scroll.create( + TableCell.blotName, + Object.assign({}, CELL_DEFAULT, { + row: rId, + rowspan: cellFormats.rowspan + }) + ) + const cellLine = this.scroll.create(TableCellLine.blotName, { + row: rId, + cell: id, + rowspan: cellFormats.rowspan + }) + tableCell.appendChild(cellLine) + + if (ref) { + tableRow.insertBefore(tableCell, ref) + } else { + tableRow.appendChild(tableCell) + } + affectedCells.push(tableCell) + }) + + // insert new tableCol + const tableCol = this.scroll.create(TableCol.blotName, true) + let colRef = isRight ? tableCols[colIndex].next : tableCols[colIndex] + if (colRef) { + tableColGroup.insertBefore(tableCol, colRef) + } else { + tableColGroup.appendChild(tableCol) + } + + modifiedCells.forEach(cell => { + const cellColspan = cell.formats().colspan + cell.format('colspan', parseInt(cellColspan, 10) + 1) + affectedCells.push(cell) + }) + + affectedCells.sort((cellA, cellB) => { + let y1 = cellA.domNode.getBoundingClientRect().y + let y2 = cellB.domNode.getBoundingClientRect().y + return y1 - y2 + }) + + this.updateTableWidth() + return affectedCells + } + + insertRow(compareRect, isDown, editorWrapper) { + const [body] = this.descendants(TableBody) + if (body == null || body.children.head == null) return + + const tableCells = this.descendants(TableCell) + const rId = rowId() + const newRow = this.scroll.create(TableRow.blotName, { + row: rId + }) + let addBelowCells = [] + let modifiedCells = [] + let affectedCells = [] + + tableCells.forEach(cell => { + const cellRect = getRelativeRect( + cell.domNode.getBoundingClientRect(), + editorWrapper + ) + + if (isDown) { + if (Math.abs(cellRect.y1 - compareRect.y1) < ERROR_LIMIT) { + addBelowCells.push(cell) + } else if ( + compareRect.y1 - cellRect.y > ERROR_LIMIT && + compareRect.y1 - cellRect.y1 < -ERROR_LIMIT + ) { + modifiedCells.push(cell) + } + } else { + if (Math.abs(cellRect.y - compareRect.y) < ERROR_LIMIT) { + addBelowCells.push(cell) + } else if ( + compareRect.y - cellRect.y > ERROR_LIMIT && + compareRect.y - cellRect.y1 < -ERROR_LIMIT + ) { + modifiedCells.push(cell) + } + } + }) + + // ordered table cells with rect.x, fix error for inserting + // new table cell in complicated table with wrong order. + const sortFunc = (cellA, cellB) => { + let x1 = cellA.domNode.getBoundingClientRect().x + let x2 = cellB.domNode.getBoundingClientRect().x + return x1 - x2 + } + addBelowCells.sort(sortFunc) + + addBelowCells.forEach(cell => { + const cId = cellId() + const cellFormats = cell.formats() + + const tableCell = this.scroll.create(TableCell.blotName, Object.assign( + {}, CELL_DEFAULT, { row: rId, colspan: cellFormats.colspan } + )) + const cellLine = this.scroll.create(TableCellLine.blotName, { + row: rId, + cell: cId, + colspan: cellFormats.colspan + }) + const empty = this.scroll.create(Break.blotName) + cellLine.appendChild(empty) + tableCell.appendChild(cellLine) + newRow.appendChild(tableCell) + affectedCells.push(tableCell) + }) + + modifiedCells.forEach(cell => { + const cellRowspan = parseInt(cell.formats().rowspan, 10) + cell.format("rowspan", cellRowspan + 1) + affectedCells.push(cell) + }) - rows() { - const body = this.children.tail - if (body == null) return [] - return body.children.map(row => row) - } + const refRow = this.rows().find(row => { + let rowRect = getRelativeRect( + row.domNode.getBoundingClientRect(), + editorWrapper + ) + if (isDown) { + return Math.abs(rowRect.y - compareRect.y - compareRect.height) < ERROR_LIMIT + } else { + return Math.abs(rowRect.y - compareRect.y) < ERROR_LIMIT + } + }) + body.insertBefore(newRow, refRow) + + // reordering affectedCells + affectedCells.sort(sortFunc) + return affectedCells + } + + mergeCells (compareRect, mergingCells, rowspan, colspan, editorWrapper) { + const mergedCell = mergingCells.reduce((result, tableCell, index) => { + if (index !== 0) { + result && tableCell.moveChildren(result) + tableCell.remove() + } else { + tableCell.format('colspan', colspan) + tableCell.format('rowspan', rowspan) + result = tableCell + } + + return result + }, null) + + let rowId = mergedCell.domNode.getAttribute('data-row') + let cellId = mergedCell.children.head.domNode.getAttribute('data-cell') + mergedCell.children.forEach(cellLine => { + cellLine.format('cell', cellId) + cellLine.format('row', rowId) + cellLine.format('colspan', colspan) + cellLine.format('rowspan', rowspan) + }) + + return mergedCell + } + + unmergeCells (unmergingCells, editorWrapper) { + let cellFormats = {} + let cellRowspan = 1 + let cellColspan = 1 + + unmergingCells.forEach(tableCell => { + cellFormats = tableCell.formats() + cellRowspan = cellFormats.rowspan + cellColspan = cellFormats.colspan + + if (cellColspan > 1) { + let ref = tableCell.next + let row = tableCell.row() + tableCell.format('colspan', 1) + for (let i = cellColspan; i > 1; i--) { + this.insertCell(row, ref) + } + } + + if (cellRowspan > 1) { + let i = cellRowspan + let nextRow = tableCell.row().next + while (i > 1) { + let refInNextRow = nextRow.children + .reduce((result, cell) => { + let compareRect = getRelativeRect( + tableCell.domNode.getBoundingClientRect(), + editorWrapper + ) + let cellRect = getRelativeRect( + cell.domNode.getBoundingClientRect(), + editorWrapper + ) + if (Math.abs(compareRect.x1 - cellRect.x) < ERROR_LIMIT) { + result = cell + } + return result + }, null) + + for (let i = cellColspan; i > 0; i--) { + this.insertCell(nextRow, refInNextRow) + } + + i -= 1 + nextRow = nextRow.next + } + + tableCell.format('rowspan', 1) + } + }) + } + + rows() { + const body = this.children.tail + if (body == null) return [] + return body.children.map(row => row) + } } TableContainer.blotName = "table-container" TableContainer.className = "quill-better-table" @@ -888,24 +911,24 @@ TableContainer.tagName = "TABLE" class TableViewWrapper extends Container { constructor (scroll, domNode) { - super(scroll, domNode) - const quill = Quill.find(scroll.domNode.parentNode) - domNode.addEventListener('scroll', (e) => { - const tableModule = quill.getModule('better-table') - if (tableModule.columnTool) { - tableModule.columnTool.domNode.scrollLeft = e.target.scrollLeft - } - - if (tableModule.tableSelection && - tableModule.tableSelection.selectedTds.length > 0) { - tableModule.tableSelection.repositionHelpLines() - } - }, false) - } + super(scroll, domNode) + const quill = Quill.find(scroll.domNode.parentNode) + domNode.addEventListener('scroll', (e) => { + const tableModule = quill.getModule('better-table') + if (tableModule.columnTool) { + tableModule.columnTool.domNode.scrollLeft = e.target.scrollLeft + } + + if (tableModule.tableSelection && + tableModule.tableSelection.selectedTds.length > 0) { + tableModule.tableSelection.repositionHelpLines() + } + }, false) + } table () { - return this.children.head - } + return this.children.head + } } TableViewWrapper.blotName = "table-view" TableViewWrapper.className = "quill-better-table-wrapper" @@ -933,36 +956,36 @@ TableCol.requiredContainer = TableColGroup function rowId() { - const id = Math.random() - .toString(36) - .slice(2, 6) - return `row-${id}` + const id = Math.random() + .toString(36) + .slice(2, 6) + return `row-${id}` } function cellId() { - const id = Math.random() - .toString(36) - .slice(2, 6) - return `cell-${id}` + const id = Math.random() + .toString(36) + .slice(2, 6) + return `cell-${id}` } export { - // blots - TableCol, - TableColGroup, - TableCellLine, - TableCell, - TableRow, - TableBody, - TableContainer, - TableViewWrapper, - - // identity getters - rowId, - cellId, - - // attributes - CELL_IDENTITY_KEYS, - CELL_ATTRIBUTES + // blots + TableCol, + TableColGroup, + TableCellLine, + TableCell, + TableRow, + TableBody, + TableContainer, + TableViewWrapper, + + // identity getters + rowId, + cellId, + + // attributes + CELL_IDENTITY_KEYS, + CELL_ATTRIBUTES } diff --git a/src/utils/node-matchers.js b/src/utils/node-matchers.js index 57adbc6..bdf83be 100644 --- a/src/utils/node-matchers.js +++ b/src/utils/node-matchers.js @@ -5,207 +5,209 @@ const Delta = Quill.import('delta') // rebuild delta export function matchTableCell (node, delta, scroll) { - const row = node.parentNode; - const table = row.parentNode.tagName === 'TABLE' - ? row.parentNode - : row.parentNode.parentNode; - const rows = Array.from(table.querySelectorAll('tr')); - const cells = Array.from(row.querySelectorAll('td')); - const rowId = rows.indexOf(row) + 1; - const cellId = cells.indexOf(node) + 1; - const colspan = node.getAttribute('colspan') || false - const rowspan = node.getAttribute('rowspan') || false - const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' - const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); - const cellBorder = node.getAttribute('data-cell-border') || - (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none': undefined); - - // bugfix: empty table cells copied from other place will be removed unexpectedly - if (delta.length() === 0) { - delta = new Delta().insert('\n', { - 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-border':cellBorder } - }) - return delta - } - - delta = delta.reduce((newDelta, op) => { - if (op.insert && typeof op.insert === 'string') { - const lines = [] - let insertStr = op.insert - let start = 0 - for (let i = 0; i < op.insert.length; i++) { - if (insertStr.charAt(i) === '\n') { - if (i === 0) { - lines.push('\n') - } else { - lines.push(insertStr.substring(start, i)) - lines.push('\n') - } - start = i + 1 + const row = node.parentNode; + const table = row.parentNode.tagName === 'TABLE' + ? row.parentNode + : row.parentNode.parentNode; + const rows = Array.from(table.querySelectorAll('tr')); + const cells = Array.from(row.querySelectorAll('td')); + const rowId = rows.indexOf(row) + 1; + const cellId = cells.indexOf(node) + 1; + const colspan = node.getAttribute('colspan') || false + const rowspan = node.getAttribute('rowspan') || false + const cellBg = node.getAttribute('data-cell-bg') || node.style.backgroundColor // The td from external table has no 'data-cell-bg' + const borderColor = node.style && (node.style.borderColor || node.style.borderTopColor || node.style.borderRightColor || node.style.borderBottomColor || node.style.borderLeftColor); + const cellBorder = node.getAttribute('data-cell-border') || + (borderColor && convertToHex(borderColor) === '#fefefe' ? 'none': undefined); + + const cellValign = node.getAttribute('data-cell-valign'); + + // bugfix: empty table cells copied from other place will be removed unexpectedly + if (delta.length() === 0) { + delta = new Delta().insert('\n', { + 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-border': cellBorder, 'cell-valign': cellValign } + }) + return delta + } + + delta = delta.reduce((newDelta, op) => { + if (op.insert && typeof op.insert === 'string') { + const lines = [] + let insertStr = op.insert + let start = 0 + for (let i = 0; i < op.insert.length; i++) { + if (insertStr.charAt(i) === '\n') { + if (i === 0) { + lines.push('\n') + } else { + lines.push(insertStr.substring(start, i)) + lines.push('\n') + } + start = i + 1 + } + } + + const tailStr = insertStr.substring(start) + if (tailStr) lines.push(tailStr) + + lines.forEach(text => { + text === '\n' + ? newDelta.insert('\n', op.attributes) + : newDelta.insert(text, _omit(op.attributes, ['table', 'table-cell-line'])) + }) + } else { + newDelta.insert(op.insert, op.attributes) } - } - const tailStr = insertStr.substring(start) - if (tailStr) lines.push(tailStr) + return newDelta + }, new Delta()) - lines.forEach(text => { - text === '\n' - ? newDelta.insert('\n', op.attributes) - : newDelta.insert(text, _omit(op.attributes, ['table', 'table-cell-line'])) - }) - } else { - newDelta.insert(op.insert, op.attributes) - } + return delta.reduce((newDelta, op) => { + if (op.insert && typeof op.insert === 'string' && + op.insert.startsWith('\n')) { + newDelta.insert(op.insert, Object.assign( + {}, + Object.assign({}, { row: rowId }, op.attributes.table), + { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-bg': cellBg, 'cell-border': cellBorder, 'cell-valign': cellValign } }, + _omit(op.attributes, ['table']) + )) + } else { + // bugfix: remove background attr from the delta of table cell + // to prevent unexcepted background attr append. + if (op.attributes && op.attributes.background && op.attributes.background === convertToHex(cellBg)) { + newDelta.insert(op.insert, Object.assign( + {}, + _omit(op.attributes, ['table', 'table-cell-line', 'background']) + )) + } else { + newDelta.insert(op.insert, Object.assign( + {}, + _omit(op.attributes, ['table', 'table-cell-line']) + )) + } + } - return newDelta - }, new Delta()) - - return delta.reduce((newDelta, op) => { - if (op.insert && typeof op.insert === 'string' && - op.insert.startsWith('\n')) { - newDelta.insert(op.insert, Object.assign( - {}, - Object.assign({}, { row: rowId }, op.attributes.table), - { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan, 'cell-bg': cellBg , 'cell-border': cellBorder} }, - _omit(op.attributes, ['table']) - )) - } else { - // bugfix: remove background attr from the delta of table cell - // to prevent unexcepted background attr append. - if (op.attributes && op.attributes.background && op.attributes.background === convertToHex(cellBg)) { - newDelta.insert(op.insert, Object.assign( - {}, - _omit(op.attributes, ['table', 'table-cell-line', 'background']) - )) - } else { - newDelta.insert(op.insert, Object.assign( - {}, - _omit(op.attributes, ['table', 'table-cell-line']) - )) - } - } - - return newDelta - }, new Delta()) + return newDelta + }, new Delta()) } // replace th tag with td tag export function matchTableHeader (node, delta, scroll) { - const row = node.parentNode; - const table = row.parentNode.tagName === 'TABLE' - ? row.parentNode - : row.parentNode.parentNode; - const rows = Array.from(table.querySelectorAll('tr')); - const cells = Array.from(row.querySelectorAll('th')); - const rowId = rows.indexOf(row) + 1; - const cellId = cells.indexOf(node) + 1; - const colspan = node.getAttribute('colspan') || false - const rowspan = node.getAttribute('rowspan') || false - - // bugfix: empty table cells copied from other place will be removed unexpectedly - if (delta.length() === 0) { - delta = new Delta().insert('\n', { - 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } - }) - return delta - } - - delta = delta.reduce((newDelta, op) => { - if (op.insert && typeof op.insert === 'string') { - const lines = [] - let insertStr = op.insert - let start = 0 - for (let i = 0; i < op.insert.length; i++) { - if (insertStr.charAt(i) === '\n') { - if (i === 0) { - lines.push('\n') - } else { - lines.push(insertStr.substring(start, i)) - lines.push('\n') - } - start = i + 1 - } - } + const row = node.parentNode; + const table = row.parentNode.tagName === 'TABLE' + ? row.parentNode + : row.parentNode.parentNode; + const rows = Array.from(table.querySelectorAll('tr')); + const cells = Array.from(row.querySelectorAll('th')); + const rowId = rows.indexOf(row) + 1; + const cellId = cells.indexOf(node) + 1; + const colspan = node.getAttribute('colspan') || false + const rowspan = node.getAttribute('rowspan') || false + + // bugfix: empty table cells copied from other place will be removed unexpectedly + if (delta.length() === 0) { + delta = new Delta().insert('\n', { + 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } + }) + return delta + } - const tailStr = insertStr.substring(start) - if (tailStr) lines.push(tailStr) + delta = delta.reduce((newDelta, op) => { + if (op.insert && typeof op.insert === 'string') { + const lines = [] + let insertStr = op.insert + let start = 0 + for (let i = 0; i < op.insert.length; i++) { + if (insertStr.charAt(i) === '\n') { + if (i === 0) { + lines.push('\n') + } else { + lines.push(insertStr.substring(start, i)) + lines.push('\n') + } + start = i + 1 + } + } + + const tailStr = insertStr.substring(start) + if (tailStr) lines.push(tailStr) + + // bugfix: no '\n' in op.insert, push a '\n' to lines + if (lines.indexOf('\n') < 0) { + lines.push('\n') + } + + lines.forEach(text => { + text === '\n' + ? newDelta.insert('\n', { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } }) + : newDelta.insert(text, op.attributes) + }) + } else { + newDelta.insert(op.insert, op.attributes) + } - // bugfix: no '\n' in op.insert, push a '\n' to lines - if (lines.indexOf('\n') < 0) { - lines.push('\n') - } + return newDelta + }, new Delta()) - lines.forEach(text => { - text === '\n' - ? newDelta.insert('\n', { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } }) - : newDelta.insert(text, op.attributes) - }) - } else { - newDelta.insert(op.insert, op.attributes) - } - - return newDelta - }, new Delta()) - - return delta.reduce((newDelta, op) => { - if (op.insert && typeof op.insert === 'string' && - op.insert.startsWith('\n')) { - newDelta.insert(op.insert, Object.assign( - {}, - { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } } - )) - } else { - newDelta.insert(op.insert, Object.assign( - {}, - _omit(op.attributes, ['table', 'table-cell-line']) - )) - } + return delta.reduce((newDelta, op) => { + if (op.insert && typeof op.insert === 'string' && + op.insert.startsWith('\n')) { + newDelta.insert(op.insert, Object.assign( + {}, + { 'table-cell-line': { row: rowId, cell: cellId, rowspan, colspan } } + )) + } else { + newDelta.insert(op.insert, Object.assign( + {}, + _omit(op.attributes, ['table', 'table-cell-line']) + )) + } - return newDelta - }, new Delta()) + return newDelta + }, new Delta()) } // supplement colgroup and col export function matchTable (node, delta, scroll) { - let newColDelta = new Delta() - const topRow = node.querySelector('tr') - - // bugfix: empty table will return empty delta - if (topRow === null) return newColDelta - - const cellsInTopRow = Array.from(topRow.querySelectorAll('td')) - .concat(Array.from(topRow.querySelectorAll('th'))) - const maxCellsNumber = cellsInTopRow.reduce((sum, cell) => { - const cellColspan = cell.getAttribute('colspan') || 1 - sum = sum + parseInt(cellColspan, 10) - return sum - }, 0) - const colsNumber = node.querySelectorAll('col').length - - // issue #2 - // bugfix: the table copied from Excel had some default col tags missing - // add missing col tags - if (colsNumber === maxCellsNumber) { - return delta - } else { - for (let i = 0; i < maxCellsNumber - colsNumber; i++) { - newColDelta.insert('\n', { 'table-col': true }) - } - - if (colsNumber === 0) return newColDelta.concat(delta) - - let lastNumber = 0 - return delta.reduce((finalDelta, op) => { - finalDelta.insert(op.insert, op.attributes) - - if (op.attributes && op.attributes['table-col']) { - lastNumber += op.insert.length - if (lastNumber === colsNumber) { - finalDelta = finalDelta.concat(newColDelta) + let newColDelta = new Delta() + const topRow = node.querySelector('tr') + + // bugfix: empty table will return empty delta + if (topRow === null) return newColDelta + + const cellsInTopRow = Array.from(topRow.querySelectorAll('td')) + .concat(Array.from(topRow.querySelectorAll('th'))) + const maxCellsNumber = cellsInTopRow.reduce((sum, cell) => { + const cellColspan = cell.getAttribute('colspan') || 1 + sum = sum + parseInt(cellColspan, 10) + return sum + }, 0) + const colsNumber = node.querySelectorAll('col').length + + // issue #2 + // bugfix: the table copied from Excel had some default col tags missing + // add missing col tags + if (colsNumber === maxCellsNumber) { + return delta + } else { + for (let i = 0; i < maxCellsNumber - colsNumber; i++) { + newColDelta.insert('\n', { 'table-col': true }) } - } - - return finalDelta - }, new Delta()) - } + + if (colsNumber === 0) return newColDelta.concat(delta) + + let lastNumber = 0 + return delta.reduce((finalDelta, op) => { + finalDelta.insert(op.insert, op.attributes) + + if (op.attributes && op.attributes['table-col']) { + lastNumber += op.insert.length + if (lastNumber === colsNumber) { + finalDelta = finalDelta.concat(newColDelta) + } + } + + return finalDelta + }, new Delta()) + } }