From 6eab1027fef72042abd582274b70b4d68afbcc94 Mon Sep 17 00:00:00 2001 From: loway Date: Thu, 25 Apr 2019 16:22:14 +0800 Subject: [PATCH] [build]production --- dist/demo/demo1.js | 2 +- dist/quill-better-table | 14 +++++++------- dist/quill-better-table.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/demo/demo1.js b/dist/demo/demo1.js index 50f3e9d..c94b324 100644 --- a/dist/demo/demo1.js +++ b/dist/demo/demo1.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(!v[e]||!x[e])return;for(var o in x[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(b[o]=t[o]);0==--g&&0===y&&q()}(e,o),t&&t(e,o)};var o,l=!0,n="24ab327e97998cf74839",r=1e4,i={},s=[],a=[];function d(e){var t=E[e];if(!t)return S;var l=function(l){return t.hot.active?(E[l]?-1===E[l].parents.indexOf(e)&&E[l].parents.push(e):(s=[e],o=l),-1===t.children.indexOf(l)&&t.children.push(l)):(console.warn("[HMR] unexpected require("+l+") from disposed module "+e),s=[]),S(l)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return S[e]},set:function(t){S[e]=t}}};for(var r in S)Object.prototype.hasOwnProperty.call(S,r)&&"e"!==r&&"t"!==r&&Object.defineProperty(l,r,n(r));return l.e=function(e){return"ready"===h&&p("prepare"),y++,S.e(e).then(t,function(e){throw t(),e});function t(){y--,"prepare"===h&&(w[e]||T(e),0===y&&0===g&&q())}},l.t=function(e,t){return 1&t&&(e=l(e)),S.t(e,-2&t)},l}function c(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 l=0;l=0&&t._disposeHandlers.splice(o,1)},check:N,apply:R,status:function(e){if(!e)return h;u.push(e)},addStatusHandler:function(e){u.push(e)},removeStatusHandler:function(e){var t=u.indexOf(e);t>=0&&u.splice(t,1)},data:i[e]};return o=void 0,t}var u=[],h="idle";function p(e){h=e;for(var t=0;t0;){var n=l.pop(),r=n.id,i=n.chain;if((a=E[r])&&!a.hot._selfAccepted){if(a.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:r};if(a.hot._main)return{type:"unaccepted",chain:i,moduleId:r};for(var s=0;s ")),N.type){case"self-declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of self decline: "+N.moduleId+O));break;case"declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of declined dependency: "+N.moduleId+" in "+N.parentId+O));break;case"unaccepted":t.onUnaccepted&&t.onUnaccepted(N),t.ignoreUnaccepted||(T=new Error("Aborted because "+d+" is not accepted"+O));break;case"accepted":t.onAccepted&&t.onAccepted(N),q=!0;break;case"disposed":t.onDisposed&&t.onDisposed(N),R=!0;break;default:throw new Error("Unexception type "+N.type)}if(T)return p("abort"),Promise.reject(T);if(q)for(d in y[d]=b[d],u(g,N.outdatedModules),N.outdatedDependencies)Object.prototype.hasOwnProperty.call(N.outdatedDependencies,d)&&(f[d]||(f[d]=[]),u(f[d],N.outdatedDependencies[d]));R&&(u(g,[N.moduleId]),y[d]=w)}var A,B=[];for(l=0;l0;)if(d=I.pop(),a=E[d]){var _={},k=a.hot._disposeHandlers;for(r=0;r=0&&D.parents.splice(A,1))}}for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d]))for(M=f[d],r=0;r=0&&a.children.splice(A,1);for(d in p("apply"),n=m,y)Object.prototype.hasOwnProperty.call(y,d)&&(e[d]=y[d]);var $=null;for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d])){M=f[d];var j=[];for(l=0;l{let l=`${o}Id`;t.setAttribute(`data-${o}`,e[o]||l())}),f.forEach(o=>{t.setAttribute(`data-${o}`,e[o]||b[o])}),t}static formats(e){return f.concat(p).reduce((t,o)=>(e.hasAttribute(`data-${o}`)&&(t[o]=e.getAttribute(`data-${o}`)||void 0),t),{})}format(e,t){f.concat(p).indexOf(e)>-1?t?this.domNode.setAttribute(`data-${e}`,t):this.domNode.removeAttribute(`data-${e}`):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),l=parseInt(this.domNode.getAttribute("data-colspan"),10);!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:l,rowspan:o}),super.optimize(e)}tableCell(){return this.parent}}g.blotName="table-cell-line",g.ClassName="qlbt-cell-line",g.tagName="DIV";class y extends c{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()["table-cell-line"],t=this.children.tail.formats()["table-cell-line"],o=this.next.children.head.formats()["table-cell-line"],l=this.next.children.tail.formats()["table-cell-line"];return e.cell===t.cell&&e.cell===o.cell&&e.cell===l.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),f.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),f.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")),f.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){f.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute(`data-${e}`,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()}}y.blotName="table",y.tagName="TD";class w extends c{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(),l=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===l.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),{})}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}w.blotName="table-row",w.tagName="TR";class x extends c{}x.blotName="table-body",x.tagName="TBODY";class v extends d{static create(e){let t=super.create(e);return u.forEach(o=>{t.setAttribute(`${o}`,e[o]||h[o])}),t}static formats(e){return u.reduce((t,o)=>(e.hasAttribute(`${o}`)&&(t[o]=e.getAttribute(`${o}`)||void 0),t),{})}format(e,t){u.indexOf(e)>-1?this.domNode.setAttribute(`${e}`,t||h[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}v.blotName="table-col",v.tagName="col";class C extends c{}C.blotName="table-col-group",C.tagName="colgroup";class N extends c{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()[v.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){var l=this.descendants(x);const r=n(l,1)[0];if(null==r||null==r.children.head)return;const i=this.descendants(y),a=[],d=[];if(i.forEach(t=>{const l=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),o);l.x+m>e.x&&l.x1-me.x1-m&&d.push(t)}),a.length===i.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),a.forEach(e=>{e.remove()}),d.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){var o=this.descendants(x);const l=n(o,1)[0];if(null==l||null==l.children.head)return;const r=this.descendants(y),i=[],a=[],d=[];if(r.forEach(o=>{const l=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),t);l.y>e.y-m&&l.y1e.y1-m&&(a.push(o),Math.abs(l.y-e.y){let n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),t);return n.y>e.y-m&&n.y1{const o=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),l=e.parent.next,n=l.children.reduce((e,l)=>{const n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x){e.remove()}),a.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)})}tableDestroy(){const e=i.default.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(i.default.sources.USER)}insertCell(e,t){const o=R(),l=e.formats().row,n=this.scroll.create(y.blotName,Object.assign({},b,{row:l})),r=this.scroll.create(g.blotName,{row:l,cell:o});n.appendChild(r),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,l){var r=this.descendants(x);const i=n(r,1)[0];var a=this.descendants(C);const d=n(a,1)[0],c=this.descendants(v);let u=[],h=[],p=[];if(null==i||null==i.children.head)return;this.descendants(y).forEach(t=>{const n=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),l);o?Math.abs(n.x1-e.x1)m&&e.x1-n.x1<-m&&h.push(t):Math.abs(n.x-e.x)m&&e.x-n.x1<-m&&h.push(t)}),u.forEach(e=>{const t=o?e.next:e,l=R(),n=e.parent,r=n.formats().row,i=e.formats(),s=this.scroll.create(y.blotName,Object.assign({},b,{row:r,rowspan:i.rowspan})),a=this.scroll.create(g.blotName,{row:r,cell:l,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),p.push(s)});const f=this.scroll.create(v.blotName,!0);let w=o?c[t].next:c[t];return w?d.insertBefore(f,w):d.appendChild(f),h.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),p.push(e)}),p.sort((e,t)=>{return e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y}),this.updateTableWidth(),p}insertRow(e,t,o){var l=this.descendants(x);const r=n(l,1)[0];if(null==r||null==r.children.head)return;const i=this.descendants(y),d=q(),c=this.scroll.create(w.blotName,{row:d});let u=[],h=[],p=[];i.forEach(l=>{const n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)m&&e.y1-n.y1<-m&&h.push(l):Math.abs(n.y-e.y)m&&e.y-n.y1<-m&&h.push(l)});const f=(e,t)=>{return e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x};u.sort(f),u.forEach(e=>{const t=R(),o=e.formats(),l=this.scroll.create(y.blotName,Object.assign({},b,{row:d,colspan:o.colspan})),n=this.scroll.create(g.blotName,{row:d,cell:t,colspan:o.colspan}),r=this.scroll.create(a.blotName);n.appendChild(r),l.appendChild(n),c.appendChild(l),p.push(l)}),h.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),p.push(e)});const v=this.rows().find(l=>{let n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",l),t.format("rowspan",o),e=t),e),null);let i=r.domNode.getAttribute("data-row"),s=r.children.head.domNode.getAttribute("data-cell");return r.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",l),e.format("rowspan",o)}),r}unmergeCells(e,t){let o={},l=1,n=1;e.forEach(e=>{if(o=e.formats(),l=o.rowspan,(n=o.colspan)>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(l>1){let o=l,r=e.row().next;for(;o>1;){let l=r.children.reduce((o,l)=>{let n=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),r=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-r.x)0;e--)this.insertCell(r,l);o-=1,r=r.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}N.blotName="table-container",N.className="quill-better-table",N.tagName="TABLE";class T extends c{constructor(e,t){super(e,t);const o=i.default.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)}}function q(){return`row-${Math.random().toString(36).slice(2,6)}`}function R(){return`cell-${Math.random().toString(36).slice(2,6)}`}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[N],N.requiredContainer=T,N.allowedChildren=[x,C],x.requiredContainer=N,x.allowedChildren=[w],w.requiredContainer=x,w.allowedChildren=[y],y.requiredContainer=w,y.allowedChildren=[g],g.requiredContainer=y,C.allowedChildren=[v],C.requiredContainer=N,v.requiredContainer=C,t.TableCol=v,t.TableColGroup=C,t.TableCellLine=g,t.TableCell=y,t.TableRow=w,t.TableBody=x,t.TableContainer=N,t.TableViewWrapper=T,t.rowId=q,t.cellId=R},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var o=[],l=!0,n=!1,r=void 0;try{for(var i,s=e[Symbol.iterator]();!(l=(i=s.next()).done)&&(o.push(i.value),!t||o.length!==t);l=!0);}catch(e){n=!0,r=e}finally{try{!l&&s.return&&s.return()}finally{if(n)throw r}}return o}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=d(o(0)),r=d(o(4)),i=d(o(5)),s=d(o(6)),a=o(2);function d(e){return e&&e.__esModule?e:{default:e}}const c=n.default.import("core/module"),u=n.default.import("delta");class h extends c{static register(){n.default.register(a.TableCol,!0),n.default.register(a.TableColGroup,!0),n.default.register(a.TableCellLine,!0),n.default.register(a.TableCell,!0),n.default.register(a.TableRow,!0),n.default.register(a.TableBody,!0),n.default.register(a.TableContainer,!0),n.default.register(a.TableViewWrapper,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{if(!o.path||o.path.length<=0)return;const l=o.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(l){if(this.table===l)return;this.table&&this.hideTableTools(),this.showTableTools(l,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;if(o.preventDefault(),!o.path||o.path.length<=0)return;const l=o.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],n=o.path.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],r=o.path.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let i=this.tableSelection.selectedTds.map(e=>e.domNode).includes(r);(this.tableSelection.selectedTds.length<=0||!i)&&this.tableSelection.setSelection(r.getBoundingClientRect(),r.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),l&&(this.tableOperationMenu=new s.default({table:l,row:n,cell:r,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;var o=this.quill.getLine(e.index);const n=l(o,1)[0];if(0===t.offset){var r=this.quill.getLine(e.index-1);const t=l(r,1)[0];if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==n.statics.blotName)return!1}return!0});let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o)}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];var t=this.quill.getLine(e.index),o=l(t,2);const n=o[0],r=o[1];if(null==n||n.statics.blotName!==a.TableCellLine.blotName)return[null,null,null,-1];const i=n.tableCell(),s=i.row();return[s.table(),s,i,r]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;this.quill.getLeaf(o.index)[0],this.quill.getLeaf(o.index+1)[0];let l=(new u).retain(o.index);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=(0,a.rowId)();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:(0,a.cellId)()}}),e),e)},l),this.quill.updateContents(l,n.default.sources.USER),this.quill.setSelection(o.index+1,n.default.sources.SILENT)}showTableTools(e,t,o){this.table=e,this.columnTool=new r.default(e,t,o),this.tableSelection=new i.default(e,t,o)}hideTableTools(){this.columnTool.destroy(),this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}h.keyboardBindings={"table-cell-line backspace":{key:"Backspace",format:["table-cell-line"],collapsed:!0,offset:0,handler(e,t){var o=this.quill.getLine(e.index),n=l(o,2);const r=n[0];n[1];return!(!r.prev||"table-cell-line"!==r.prev.statics.blotName)}},"table-cell-line delete":{key:"Delete",format:["table-cell-line"],collapsed:!0,suffix:/^$/,handler(){}},"table-cell-line enter":{key:"Enter",shiftKey:null,format:["table-cell-line"],handler(e,t){if(this.quill.selection&&this.quill.selection.composing)return;const o=n.default.imports.parchment.Scope;e.length>0&&this.quill.scroll.deleteAt(e.index,e.length);const l=Object.keys(t.format).reduce((e,l)=>(this.quill.scroll.query(l,o.BLOCK)&&!Array.isArray(t.format[l])&&(e[l]=t.format[l]),e),{});this.quill.insertText(e.index,"\n",l["table-cell-line"],n.default.sources.USER),this.quill.setSelection(e.index+1,n.default.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==l[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.default.sources.USER))})}}},t.default=h},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l,n=o(0),r=(l=n)&&l.__esModule?l:{default:l},i=o(1);const s=12,a=12,d=50,c="#35A7ED";t.default=class{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),(0,i.css)(this.domNode,{width:`${o.width}px`,height:`${s}px`,left:`${o.left-t.left+e.scrollLeft}px`,top:`${o.top-t.top+e.scrollTop-s-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"),(0,i.css)(e,{height:`${a}px`}),e.appendChild(t),e}updateToolCells(){const e=r.default.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,l=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let n=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=l?n[e].remove():(s=n[e],(0,i.css)(s,{"min-width":`${r}px`})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),(0,i.css)(s,{"min-width":`${r}px`}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=r.default.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let l=!1,n=0,a=0,u=0,h=0,p={},f={},b=null;const m=e=>{e.preventDefault(),l&&(a=e.clientX,u=h+a-n>=d?a-n:d-h,(0,i.css)(b,{left:`${f.left+f.width-1+u}px`}))},g=r=>{r.preventDefault();const s=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),d=t.colGroup().children.at(s);l&&(d.format("width",h+u),(0,i.css)(e,{"min-width":`${h+u}px`}),n=0,a=0,u=0,h=0,l=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",m,!1),document.removeEventListener("mouseup",g,!1),p={},f={},b.remove(),b=null,t.updateTableWidth();const c=this.quill.getModule("better-table").tableSelection;c&&c.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",m,!1),document.addEventListener("mouseup",g,!1),p=this.table.getBoundingClientRect(),f=e.getBoundingClientRect(),b=document.createElement("div"),(0,i.css)(b,{position:"fixed",top:`${f.top}px`,left:`${f.left+f.width-1}px`,zIndex:"100",height:`${p.height+s+4}px`,width:"1px",backgroundColor:c}),document.body.appendChild(b),l=!0,n=t.clientX,h=f.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l,n=o(0),r=(l=n)&&l.__esModule?l:{default:l},i=o(1),s=o(2);const a="#35A7ED",d=["left","right","top","bottom"],c=2;function u(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),l=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),r=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:l,y:n,y1:r,width:l-o,height:r-n}}t.default=class{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.clearSelectionHanler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHanler)}helpLinesInitial(){let e=this.quill.root.parentNode;d.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),(0,i.css)(this[t],{position:"absolute",display:"none","background-color":a}),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]"),l=(0,i.getRelativeRect)(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]"),r=(0,i.getRelativeRect)(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=u(l,r),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=u(l,l),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){r.default.find(this.table).descendants(s.TableCell).forEach(e=>{var t=(0,i.getRelativeRect)(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);let o=t.x,l=t.y,n=t.width,r=t.height;(o+c>=this.boundary.x&&o+c<=this.boundary.x1||o-c+n>=this.boundary.x&&o-c+n<=this.boundary.x1)&&(l+c>=this.boundary.y&&l+c<=this.boundary.y1||l-c+r>=this.boundary.y&&l-c+r<=this.boundary.y1)&&(this.boundary=u(this.boundary,{x:o,y:l,width:n,height:r}))})}computeSelectedTds(){return r.default.find(this.table).descendants(s.TableCell).reduce((e,t)=>{var o=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);let l=o.x,n=o.y,r=o.width,s=o.height;return l+c>=this.boundary.x&&l-c+r<=this.boundary.x1&&n+c>=this.boundary.y&&n-c+s<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;(0,i.css)(this.left,{display:"block",left:`${this.boundary.x-e-1}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.right,{display:"block",left:`${this.boundary.x1-e}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.top,{display:"block",left:`${this.boundary.x-1-e}px`,top:`${this.boundary.y}px`,width:`${this.boundary.width+1}px`,height:"1px"}),(0,i.css)(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=(0,i.getRelativeRect)(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=(0,i.getRelativeRect)(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=u(e,t),this.repositionHelpLines()}destroy(){return d.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHanler),null}setSelection(e,t){this.boundary=u((0,i.getRelativeRect)(e,this.quill.root.parentNode),(0,i.getRelativeRect)(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],d.forEach(e=>{this[e]&&(0,i.css)(this[e],{display:"none"})})}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l,n=o(0),r=(l=n)&&l.__esModule?l:{default:l},i=o(1);const s=150,a=200,d={insertColumnRight:{text:"Insert column right",handler(){const e=r.default.find(this.table);let t=c(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.default.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",handler(){const e=r.default.find(this.table);let t=c(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.default.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",handler(){const e=r.default.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(r.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",handler(){const e=r.default.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(r.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",handler(){const e=r.default.find(this.table),t=e.rows().reduce((e,t)=>{let o=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=(0,i.getRelativeRect)(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.widthe.x+5>t.x&&e.x+e.width-5{let r=(0,i.getRelativeRect)(t.getBoundingClientRect(),s);return n(r,l)&&e.push(o.indexOf(t)),e},[]));var o,l,n,s;e.deleteColumns(this.boundary,t,this.quill.root.parentNode)||(this.tableColumnTool.updateToolCells(),this.quill.update(r.default.sources.USER),this.tableSelection.clearSelection())}},deleteRow:{text:"Delete selected rows",handler(){r.default.find(this.table).deleteRow(this.boundary,this.quill.root.parentNode),this.quill.update(r.default.sources.USER),this.tableSelection.clearSelection()}},deleteTable:{text:"Delete table",handler(){const e=this.quill.getModule("better-table"),t=r.default.find(this.table);e.hideTableTools(),t.remove(),this.quill.update(r.default.sources.USER)}}};function c(e,t,o,l){return e.reduce((n,r)=>{let s=(0,i.getRelativeRect)(r.getBoundingClientRect(),l);return o(s,t)&&(n=e.indexOf(r)),n},!1)}t.default=class{constructor(e,t,o){const l=t.getModule("better-table");this.tableSelection=l.tableSelection,this.table=e.table,this.quill=t,this.options=o,this.menuItems=Object.assign({},d,o.items),this.tableColumnTool=l.columnTool,this.boundary=this.tableSelection.boundary,this.selectedTds=this.tableSelection.selectedTds,this.destroyHanlder=this.destroy.bind(this),this.columnToolCells=this.tableColumnTool.colToolCells(),this.menuInitial(e),this.mount(),document.addEventListener("click",this.destroyHanlder,!1)}mount(){document.body.appendChild(this.domNode)}destroy(){return this.domNode.remove(),document.removeEventListener("click",this.destroyHanlder,!1),null}menuInitial({table:e,left:t,top:o}){this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-operation-menu"),(0,i.css)(this.domNode,{position:"absolute",left:`${t}px`,top:`${o}px`,"min-height":`${s}px`,width:`${a}px`});for(let e in this.menuItems)this.menuItems[e]&&this.domNode.appendChild(this.menuItemCreator(Object.assign({},d[e],this.menuItems[e])))}menuItemCreator({text:e,handler:t}){const o=document.createElement("div");return o.classList.add("qlbt-operation-menu-item"),o.innerText=e,o.addEventListener("click",t.bind(this),!1),o}}},function(e,t,o){},,,function(e,t,o){"use strict";var l,n=o(3),r=(l=n)&&l.__esModule?l:{default:l};o(7),Quill.register({"modules/better-table":r.default},!0),window.onload=(()=>{let e=new Quill("#editor-wrapper",{theme:"snow",modules:{table:!1,"better-table":{operationMenu:{items:{unmergeCells:{text:"Another unmerge cells name"}}}},keyboard:{bindings:r.default.keyboardBindings}}}).getModule("better-table");document.body.querySelector("#insert-table").onclick=(()=>{e.insertTable(3,3)}),document.body.querySelector("#get-table").onclick=(()=>{console.log(e.getTable())})})}]).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(!v[e]||!x[e])return;for(var o in x[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(b[o]=t[o]);0==--g&&0===y&&q()}(e,o),t&&t(e,o)};var o,r=!0,l="20a71d310cbb3386ec65",n=1e4,i={},s=[],a=[];function d(e){var t=E[e];if(!t)return S;var r=function(r){return t.hot.active?(E[r]?-1===E[r].parents.indexOf(e)&&E[r].parents.push(e):(s=[e],o=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),s=[]),S(r)},l=function(e){return{configurable:!0,enumerable:!0,get:function(){return S[e]},set:function(t){S[e]=t}}};for(var n in S)Object.prototype.hasOwnProperty.call(S,n)&&"e"!==n&&"t"!==n&&Object.defineProperty(r,n,l(n));return r.e=function(e){return"ready"===h&&p("prepare"),y++,S.e(e).then(t,function(e){throw t(),e});function t(){y--,"prepare"===h&&(w[e]||T(e),0===y&&0===g&&q())}},r.t=function(e,t){return 1&t&&(e=r(e)),S.t(e,-2&t)},r}function c(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 r=0;r=0&&t._disposeHandlers.splice(o,1)},check:N,apply:R,status:function(e){if(!e)return h;u.push(e)},addStatusHandler:function(e){u.push(e)},removeStatusHandler:function(e){var t=u.indexOf(e);t>=0&&u.splice(t,1)},data:i[e]};return o=void 0,t}var u=[],h="idle";function p(e){h=e;for(var t=0;t0;){var l=r.pop(),n=l.id,i=l.chain;if((a=E[n])&&!a.hot._selfAccepted){if(a.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:n};if(a.hot._main)return{type:"unaccepted",chain:i,moduleId:n};for(var s=0;s ")),N.type){case"self-declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of self decline: "+N.moduleId+A));break;case"declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of declined dependency: "+N.moduleId+" in "+N.parentId+A));break;case"unaccepted":t.onUnaccepted&&t.onUnaccepted(N),t.ignoreUnaccepted||(T=new Error("Aborted because "+d+" is not accepted"+A));break;case"accepted":t.onAccepted&&t.onAccepted(N),q=!0;break;case"disposed":t.onDisposed&&t.onDisposed(N),R=!0;break;default:throw new Error("Unexception type "+N.type)}if(T)return p("abort"),Promise.reject(T);if(q)for(d in y[d]=b[d],u(g,N.outdatedModules),N.outdatedDependencies)Object.prototype.hasOwnProperty.call(N.outdatedDependencies,d)&&(f[d]||(f[d]=[]),u(f[d],N.outdatedDependencies[d]));R&&(u(g,[N.moduleId]),y[d]=w)}var O,B=[];for(r=0;r0;)if(d=_.pop(),a=E[d]){var I={},j=a.hot._disposeHandlers;for(n=0;n=0&&k.parents.splice(O,1))}}for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d]))for(M=f[d],n=0;n=0&&a.children.splice(O,1);for(d in p("apply"),l=m,y)Object.prototype.hasOwnProperty.call(y,d)&&(e[d]=y[d]);var D=null;for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d])){M=f[d];var $=[];for(r=0;rt.includes(r)?o:Object.assign({},o,{[r]:e[r]}),{})}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CELL_ATTRIBUTES=t.cellId=t.rowId=t.TableViewWrapper=t.TableContainer=t.TableBody=t.TableRow=t.TableCell=t.TableCellLine=t.TableColGroup=t.TableCol=void 0;var r,l=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var o=[],r=!0,l=!1,n=void 0;try{for(var i,s=e[Symbol.iterator]();!(r=(i=s.next()).done)&&(o.push(i.value),!t||o.length!==t);r=!0);}catch(e){l=!0,n=e}finally{try{!r&&s.return&&s.return()}finally{if(l)throw n}}return o}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=o(0),i=(r=n)&&r.__esModule?r:{default:r},s=o(1);const a=i.default.import("blots/break"),d=i.default.import("blots/block"),c=i.default.import("blots/container"),u=["width"],h={width:100},p=["row","cell"],f=["rowspan","colspan"],b={rowspan:1,colspan:1},m=5;class g extends d{static create(e){const t=super.create(e);return p.forEach(o=>{let r=`${o}Id`;t.setAttribute(`data-${o}`,e[o]||r())}),f.forEach(o=>{t.setAttribute(`data-${o}`,e[o]||b[o])}),t}static formats(e){return f.concat(p).reduce((t,o)=>(e.hasAttribute(`data-${o}`)&&(t[o]=e.getAttribute(`data-${o}`)||void 0),t),{})}format(e,t){f.concat(p).indexOf(e)>-1?t?this.domNode.setAttribute(`data-${e}`,t):this.domNode.removeAttribute(`data-${e}`):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),r=parseInt(this.domNode.getAttribute("data-colspan"),10);!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:r,rowspan:o}),super.optimize(e)}tableCell(){return this.parent}}g.blotName="table-cell-line",g.ClassName="qlbt-cell-line",g.tagName="DIV";class y extends c{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()["table-cell-line"],t=this.children.tail.formats()["table-cell-line"],o=this.next.children.head.formats()["table-cell-line"],r=this.next.children.tail.formats()["table-cell-line"];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),f.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),f.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")),f.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){f.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute(`data-${e}`,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()}}y.blotName="table",y.tagName="TD";class w extends c{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}}w.blotName="table-row",w.tagName="TR";class x extends c{}x.blotName="table-body",x.tagName="TBODY";class v extends d{static create(e){let t=super.create(e);return u.forEach(o=>{t.setAttribute(`${o}`,e[o]||h[o])}),t}static formats(e){return u.reduce((t,o)=>(e.hasAttribute(`${o}`)&&(t[o]=e.getAttribute(`${o}`)||void 0),t),{})}format(e,t){u.indexOf(e)>-1?this.domNode.setAttribute(`${e}`,t||h[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}v.blotName="table-col",v.tagName="col";class C extends c{}C.blotName="table-col-group",C.tagName="colgroup";class N extends c{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()[v.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){var r=this.descendants(x);const n=l(r,1)[0];if(null==n||null==n.children.head)return;const i=this.descendants(y),a=[],d=[];if(i.forEach(t=>{const r=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),o);r.x+m>e.x&&r.x1-me.x1-m&&d.push(t)}),a.length===i.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),a.forEach(e=>{e.remove()}),d.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){var o=this.descendants(x);const r=l(o,1)[0];if(null==r||null==r.children.head)return;const n=this.descendants(y),i=[],a=[],d=[];if(n.forEach(o=>{const r=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),t);r.y>e.y-m&&r.y1e.y1-m&&(a.push(o),Math.abs(r.y-e.y){let l=(0,s.getRelativeRect)(r.domNode.getBoundingClientRect(),t);return l.y>e.y-m&&l.y1{const o=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),r=e.parent.next,l=r.children.reduce((e,r)=>{const l=(0,s.getRelativeRect)(r.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-l.x){e.remove()}),a.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)})}tableDestroy(){const e=i.default.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(i.default.sources.USER)}insertCell(e,t){const o=R(),r=e.formats().row,l=this.scroll.create(y.blotName,Object.assign({},b,{row:r})),n=this.scroll.create(g.blotName,{row:r,cell:o});l.appendChild(n),t?e.insertBefore(l,t):e.appendChild(l)}insertColumn(e,t,o=!0,r){var n=this.descendants(x);const i=l(n,1)[0];var a=this.descendants(C);const d=l(a,1)[0],c=this.descendants(v);let u=[],h=[],p=[];if(null==i||null==i.children.head)return;this.descendants(y).forEach(t=>{const l=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),r);o?Math.abs(l.x1-e.x1)m&&e.x1-l.x1<-m&&h.push(t):Math.abs(l.x-e.x)m&&e.x-l.x1<-m&&h.push(t)}),u.forEach(e=>{const t=o?e.next:e,r=R(),l=e.parent,n=l.formats().row,i=e.formats(),s=this.scroll.create(y.blotName,Object.assign({},b,{row:n,rowspan:i.rowspan})),a=this.scroll.create(g.blotName,{row:n,cell:r,rowspan:i.rowspan});s.appendChild(a),t?l.insertBefore(s,t):l.appendChild(s),p.push(s)});const f=this.scroll.create(v.blotName,!0);let w=o?c[t].next:c[t];return w?d.insertBefore(f,w):d.appendChild(f),h.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),p.push(e)}),p.sort((e,t)=>{return e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y}),this.updateTableWidth(),p}insertRow(e,t,o){var r=this.descendants(x);const n=l(r,1)[0];if(null==n||null==n.children.head)return;const i=this.descendants(y),d=q(),c=this.scroll.create(w.blotName,{row:d});let u=[],h=[],p=[];i.forEach(r=>{const l=(0,s.getRelativeRect)(r.domNode.getBoundingClientRect(),o);t?Math.abs(l.y1-e.y1)m&&e.y1-l.y1<-m&&h.push(r):Math.abs(l.y-e.y)m&&e.y-l.y1<-m&&h.push(r)});const f=(e,t)=>{return e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x};u.sort(f),u.forEach(e=>{const t=R(),o=e.formats(),r=this.scroll.create(y.blotName,Object.assign({},b,{row:d,colspan:o.colspan})),l=this.scroll.create(g.blotName,{row:d,cell:t,colspan:o.colspan}),n=this.scroll.create(a.blotName);l.appendChild(n),r.appendChild(l),c.appendChild(r),p.push(r)}),h.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),p.push(e)});const v=this.rows().find(r=>{let l=(0,s.getRelativeRect)(r.domNode.getBoundingClientRect(),o);return t?Math.abs(l.y-e.y-e.height)(0!==l?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",r),t.format("rowspan",o),e=t),e),null);let i=n.domNode.getAttribute("data-row"),s=n.children.head.domNode.getAttribute("data-cell");return n.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",r),e.format("rowspan",o)}),n}unmergeCells(e,t){let o={},r=1,l=1;e.forEach(e=>{if(o=e.formats(),r=o.rowspan,(l=o.colspan)>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=l;e>1;e--)this.insertCell(o,t)}if(r>1){let o=r,n=e.row().next;for(;o>1;){let r=n.children.reduce((o,r)=>{let l=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),n=(0,s.getRelativeRect)(r.domNode.getBoundingClientRect(),t);return Math.abs(l.x1-n.x)0;e--)this.insertCell(n,r);o-=1,n=n.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}N.blotName="table-container",N.className="quill-better-table",N.tagName="TABLE";class T extends c{constructor(e,t){super(e,t);const o=i.default.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)}}function q(){return`row-${Math.random().toString(36).slice(2,6)}`}function R(){return`cell-${Math.random().toString(36).slice(2,6)}`}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[N],N.requiredContainer=T,N.allowedChildren=[x,C],x.requiredContainer=N,x.allowedChildren=[w],w.requiredContainer=x,w.allowedChildren=[y],y.requiredContainer=w,y.allowedChildren=[g],g.requiredContainer=y,C.allowedChildren=[v],C.requiredContainer=N,v.requiredContainer=C,t.TableCol=v,t.TableColGroup=C,t.TableCellLine=g,t.TableCell=y,t.TableRow=w,t.TableBody=x,t.TableContainer=N,t.TableViewWrapper=T,t.rowId=q,t.cellId=R,t.CELL_ATTRIBUTES=f},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var o=[],r=!0,l=!1,n=void 0;try{for(var i,s=e[Symbol.iterator]();!(r=(i=s.next()).done)&&(o.push(i.value),!t||o.length!==t);r=!0);}catch(e){l=!0,n=e}finally{try{!r&&s.return&&s.return()}finally{if(l)throw n}}return o}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),l=c(o(0)),n=c(o(4)),i=c(o(5)),s=c(o(6)),a=o(7),d=o(2);function c(e){return e&&e.__esModule?e:{default:e}}const u=l.default.import("core/module"),h=l.default.import("delta");class p extends u{static register(){l.default.register(d.TableCol,!0),l.default.register(d.TableColGroup,!0),l.default.register(d.TableCellLine,!0),l.default.register(d.TableCell,!0),l.default.register(d.TableRow,!0),l.default.register(d.TableBody,!0),l.default.register(d.TableContainer,!0),l.default.register(d.TableViewWrapper,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{if(!o.path||o.path.length<=0)return;const r=o.path.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;if(o.preventDefault(),!o.path||o.path.length<=0)return;const r=o.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],l=o.path.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],n=o.path.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let i=this.tableSelection.selectedTds.map(e=>e.domNode).includes(n);(this.tableSelection.selectedTds.length<=0||!i)&&this.tableSelection.setSelection(n.getBoundingClientRect(),n.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),r&&(this.tableOperationMenu=new s.default({table:r,row:l,cell:n,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;var o=this.quill.getLine(e.index);const l=r(o,1)[0];if(0===t.offset){var n=this.quill.getLine(e.index-1);const t=r(n,1)[0];if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==l.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",a.matchTableCell),e.clipboard.addMatcher("table",a.matchTable),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];var t=this.quill.getLine(e.index),o=r(t,2);const l=o[0],n=o[1];if(null==l||l.statics.blotName!==d.TableCellLine.blotName)return[null,null,null,-1];const i=l.tableCell(),s=i.row();return[s.table(),s,i,n]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;this.quill.getLeaf(o.index)[0],this.quill.getLeaf(o.index+1)[0];let r=(new h).retain(o.index);r.insert("\n"),r=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),r),r=new Array(e).fill(0).reduce(e=>{let o=(0,d.rowId)();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:(0,d.cellId)()}}),e),e)},r),this.quill.updateContents(r,l.default.sources.USER),this.quill.setSelection(o.index+1,l.default.sources.SILENT)}showTableTools(e,t,o){this.table=e,this.columnTool=new n.default(e,t,o),this.tableSelection=new i.default(e,t,o)}hideTableTools(){this.columnTool.destroy(),this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}p.keyboardBindings={"table-cell-line backspace":{key:"Backspace",format:["table-cell-line"],collapsed:!0,offset:0,handler(e,t){var o=this.quill.getLine(e.index),l=r(o,2);const n=l[0];l[1];return!(!n.prev||"table-cell-line"!==n.prev.statics.blotName)}},"table-cell-line delete":{key:"Delete",format:["table-cell-line"],collapsed:!0,suffix:/^$/,handler(){}},"table-cell-line enter":{key:"Enter",shiftKey:null,format:["table-cell-line"],handler(e,t){if(this.quill.selection&&this.quill.selection.composing)return;const o=l.default.imports.parchment.Scope;e.length>0&&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"],l.default.sources.USER),this.quill.setSelection(e.index+1,l.default.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],l.default.sources.USER))})}}},t.default=p},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,l=o(0),n=(r=l)&&r.__esModule?r:{default:r},i=o(1);const s=12,a=12,d=50,c="#35A7ED";t.default=class{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),(0,i.css)(this.domNode,{width:`${o.width}px`,height:`${s}px`,left:`${o.left-t.left+e.scrollLeft}px`,top:`${o.top-t.top+e.scrollTop-s-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"),(0,i.css)(e,{height:`${a}px`}),e.appendChild(t),e}updateToolCells(){const e=n.default.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 l=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=r?l[e].remove():(s=l[e],(0,i.css)(s,{"min-width":`${n}px`})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),(0,i.css)(s,{"min-width":`${n}px`}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=n.default.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,l=0,a=0,u=0,h=0,p={},f={},b=null;const m=e=>{e.preventDefault(),r&&(a=e.clientX,u=h+a-l>=d?a-l:d-h,(0,i.css)(b,{left:`${f.left+f.width-1+u}px`}))},g=n=>{n.preventDefault();const s=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),d=t.colGroup().children.at(s);r&&(d.format("width",h+u),(0,i.css)(e,{"min-width":`${h+u}px`}),l=0,a=0,u=0,h=0,r=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",m,!1),document.removeEventListener("mouseup",g,!1),p={},f={},b.remove(),b=null,t.updateTableWidth();const c=this.quill.getModule("better-table").tableSelection;c&&c.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",m,!1),document.addEventListener("mouseup",g,!1),p=this.table.getBoundingClientRect(),f=e.getBoundingClientRect(),b=document.createElement("div"),(0,i.css)(b,{position:"fixed",top:`${f.top}px`,left:`${f.left+f.width-1}px`,zIndex:"100",height:`${p.height+s+4}px`,width:"1px",backgroundColor:c}),document.body.appendChild(b),r=!0,l=t.clientX,h=f.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,l=o(0),n=(r=l)&&r.__esModule?r:{default:r},i=o(1),s=o(2);const a="#35A7ED",d=["left","right","top","bottom"],c=2;function u(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),l=Math.min(e.y,t.y,e.y+e.height-1,t.y+t.height-1),n=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:r,y:l,y1:n,width:r-o,height:n-l}}t.default=class{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.clearSelectionHanler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHanler)}helpLinesInitial(){let e=this.quill.root.parentNode;d.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),(0,i.css)(this[t],{position:"absolute",display:"none","background-color":a}),e.appendChild(this[t])})}mouseDownHandler(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;this.quill.root.addEventListener("mousemove",l,!1),this.quill.root.addEventListener("mouseup",function e(o){t.quill.root.removeEventListener("mousemove",l,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1},!1);const t=this,o=e.target.closest("td[data-row]"),r=(0,i.getRelativeRect)(o.getBoundingClientRect(),this.quill.root.parentNode);function l(e){if(0!==e.button||!e.target.closest(".quill-better-table"))return;const l=e.target.closest("td[data-row]"),n=(0,i.getRelativeRect)(l.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=u(r,n),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==l&&t.quill.blur()}this.dragging=!0,this.boundary=u(r,r),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){n.default.find(this.table).descendants(s.TableCell).forEach(e=>{var t=(0,i.getRelativeRect)(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);let o=t.x,r=t.y,l=t.width,n=t.height;(o+c>=this.boundary.x&&o+c<=this.boundary.x1||o-c+l>=this.boundary.x&&o-c+l<=this.boundary.x1)&&(r+c>=this.boundary.y&&r+c<=this.boundary.y1||r-c+n>=this.boundary.y&&r-c+n<=this.boundary.y1)&&(this.boundary=u(this.boundary,{x:o,y:r,width:l,height:n}))})}computeSelectedTds(){return n.default.find(this.table).descendants(s.TableCell).reduce((e,t)=>{var o=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);let r=o.x,l=o.y,n=o.width,s=o.height;return r+c>=this.boundary.x&&r-c+n<=this.boundary.x1&&l+c>=this.boundary.y&&l-c+s<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;(0,i.css)(this.left,{display:"block",left:`${this.boundary.x-e-1}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.right,{display:"block",left:`${this.boundary.x1-e}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.top,{display:"block",left:`${this.boundary.x-1-e}px`,top:`${this.boundary.y}px`,width:`${this.boundary.width+1}px`,height:"1px"}),(0,i.css)(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=(0,i.getRelativeRect)(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=(0,i.getRelativeRect)(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=u(e,t),this.repositionHelpLines()}destroy(){return d.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHanler),null}setSelection(e,t){this.boundary=u((0,i.getRelativeRect)(e,this.quill.root.parentNode),(0,i.getRelativeRect)(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],d.forEach(e=>{this[e]&&(0,i.css)(this[e],{display:"none"})})}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,l=o(0),n=(r=l)&&r.__esModule?r:{default:r},i=o(1);const s=150,a=200,d={insertColumnRight:{text:"Insert column right",handler(){const e=n.default.find(this.table);let t=c(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.default.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.default.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",handler(){const e=n.default.find(this.table);let t=c(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.default.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,n.default.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",handler(){const e=n.default.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(n.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",handler(){const e=n.default.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(n.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,n.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",handler(){const e=n.default.find(this.table),t=e.rows().reduce((e,t)=>{let o=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=(0,i.getRelativeRect)(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.widthe.x+5>t.x&&e.x+e.width-5{let n=(0,i.getRelativeRect)(t.getBoundingClientRect(),s);return l(n,r)&&e.push(o.indexOf(t)),e},[]));var o,r,l,s;e.deleteColumns(this.boundary,t,this.quill.root.parentNode)||(this.tableColumnTool.updateToolCells(),this.quill.update(n.default.sources.USER),this.tableSelection.clearSelection())}},deleteRow:{text:"Delete selected rows",handler(){n.default.find(this.table).deleteRow(this.boundary,this.quill.root.parentNode),this.quill.update(n.default.sources.USER),this.tableSelection.clearSelection()}},deleteTable:{text:"Delete table",handler(){const e=this.quill.getModule("better-table"),t=n.default.find(this.table);e.hideTableTools(),t.remove(),this.quill.update(n.default.sources.USER)}}};function c(e,t,o,r){return e.reduce((l,n)=>{let s=(0,i.getRelativeRect)(n.getBoundingClientRect(),r);return o(s,t)&&(l=e.indexOf(n)),l},!1)}t.default=class{constructor(e,t,o){const r=t.getModule("better-table");this.tableSelection=r.tableSelection,this.table=e.table,this.quill=t,this.options=o,this.menuItems=Object.assign({},d,o.items),this.tableColumnTool=r.columnTool,this.boundary=this.tableSelection.boundary,this.selectedTds=this.tableSelection.selectedTds,this.destroyHanlder=this.destroy.bind(this),this.columnToolCells=this.tableColumnTool.colToolCells(),this.menuInitial(e),this.mount(),document.addEventListener("click",this.destroyHanlder,!1)}mount(){document.body.appendChild(this.domNode)}destroy(){return this.domNode.remove(),document.removeEventListener("click",this.destroyHanlder,!1),null}menuInitial({table:e,left:t,top:o}){this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-operation-menu"),(0,i.css)(this.domNode,{position:"absolute",left:`${t}px`,top:`${o}px`,"min-height":`${s}px`,width:`${a}px`});for(let e in this.menuItems)this.menuItems[e]&&this.domNode.appendChild(this.menuItemCreator(Object.assign({},d[e],this.menuItems[e])))}menuItemCreator({text:e,handler:t}){const o=document.createElement("div");return o.classList.add("qlbt-operation-menu-item"),o.innerText=e,o.addEventListener("click",t.bind(this),!1),o}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.matchTableCell=function(e,t,o){const r=e.parentNode,l="TABLE"===r.parentNode.tagName?r.parentNode:r.parentNode.parentNode,n=Array.from(l.querySelectorAll("tr")),a=Array.from(r.querySelectorAll("td")),d=n.indexOf(r)+1,c=a.indexOf(e)+1,u=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const o=[];let r=t.insert,l=0;for(let e=0;e{"\n"===o?e.insert("\n",t.attributes):e.insert(o,(0,i._omit)(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new s)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert("\n",Object.assign({},Object.assign({},{row:d},t.attributes.table),{"table-cell-line":{row:d,cell:c,rowspan:h,colspan:u}},(0,i._omit)(t.attributes,["table"]))).insert(t.insert.substring(1),(0,i._omit)(t.attributes,["table","table-cell-line"])):e.insert(t.insert,Object.assign({},(0,i._omit)(t.attributes,["table","table-cell-line"]))),e),new s)},t.matchTable=function(e,t,o){if(e.querySelectorAll("colgroup").length>0)return t;let r=new s;const l=e.querySelector("tr"),n=Array.from(l.querySelectorAll("td")).reduce((e,t)=>{const o=t.getAttribute("colspan")||1;return e+=parseInt(o,10)},0);for(let e=0;e{let e=new Quill("#editor-wrapper",{theme:"snow",modules:{table:!1,"better-table":{operationMenu:{items:{unmergeCells:{text:"Another unmerge cells name"}}}},keyboard:{bindings:n.default.keyboardBindings}}}).getModule("better-table");document.body.querySelector("#insert-table").onclick=(()=>{e.insertTable(3,3)}),document.body.querySelector("#get-table").onclick=(()=>{console.log(e.getTable())})})}]).default}); \ No newline at end of file diff --git a/dist/quill-better-table b/dist/quill-better-table index 4e9b724..a9d83fe 100644 --- a/dist/quill-better-table +++ b/dist/quill-better-table @@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ var hotApplyOnUpdate = true; /******/ // eslint-disable-next-line no-unused-vars -/******/ var hotCurrentHash = "24ab327e97998cf74839"; +/******/ var hotCurrentHash = "20a71d310cbb3386ec65"; /******/ var hotRequestTimeout = 10000; /******/ var hotCurrentModuleData = {}; /******/ var hotCurrentChildModule; @@ -798,23 +798,23 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ /******/ // Load entry module and return exports -/******/ return hotCreateRequire(9)(__webpack_require__.s = 9); +/******/ return hotCreateRequire(10)(__webpack_require__.s = 10); /******/ }) /************************************************************************/ /******/ ({ -/***/ 7: +/***/ 10: /***/ (function(module, exports, __webpack_require__) { -// extracted by mini-css-extract-plugin +module.exports = __webpack_require__(8); + /***/ }), -/***/ 9: +/***/ 8: /***/ (function(module, exports, __webpack_require__) { -module.exports = __webpack_require__(7); - +// extracted by mini-css-extract-plugin /***/ }) diff --git a/dist/quill-better-table.js b/dist/quill-better-table.js index e0573f3..4d0bae1 100644 --- a/dist/quill-better-table.js +++ b/dist/quill-better-table.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(!v[e]||!x[e])return;for(var o in x[e]=!1,t)Object.prototype.hasOwnProperty.call(t,o)&&(b[o]=t[o]);0==--g&&0===y&&q()}(e,o),t&&t(e,o)};var o,l=!0,n="24ab327e97998cf74839",r=1e4,i={},s=[],a=[];function d(e){var t=E[e];if(!t)return S;var l=function(l){return t.hot.active?(E[l]?-1===E[l].parents.indexOf(e)&&E[l].parents.push(e):(s=[e],o=l),-1===t.children.indexOf(l)&&t.children.push(l)):(console.warn("[HMR] unexpected require("+l+") from disposed module "+e),s=[]),S(l)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return S[e]},set:function(t){S[e]=t}}};for(var r in S)Object.prototype.hasOwnProperty.call(S,r)&&"e"!==r&&"t"!==r&&Object.defineProperty(l,r,n(r));return l.e=function(e){return"ready"===h&&p("prepare"),y++,S.e(e).then(t,function(e){throw t(),e});function t(){y--,"prepare"===h&&(w[e]||T(e),0===y&&0===g&&q())}},l.t=function(e,t){return 1&t&&(e=l(e)),S.t(e,-2&t)},l}function c(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 l=0;l=0&&t._disposeHandlers.splice(o,1)},check:N,apply:R,status:function(e){if(!e)return h;u.push(e)},addStatusHandler:function(e){u.push(e)},removeStatusHandler:function(e){var t=u.indexOf(e);t>=0&&u.splice(t,1)},data:i[e]};return o=void 0,t}var u=[],h="idle";function p(e){h=e;for(var t=0;t0;){var n=l.pop(),r=n.id,i=n.chain;if((a=E[r])&&!a.hot._selfAccepted){if(a.hot._selfDeclined)return{type:"self-declined",chain:i,moduleId:r};if(a.hot._main)return{type:"unaccepted",chain:i,moduleId:r};for(var s=0;s ")),N.type){case"self-declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of self decline: "+N.moduleId+O));break;case"declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of declined dependency: "+N.moduleId+" in "+N.parentId+O));break;case"unaccepted":t.onUnaccepted&&t.onUnaccepted(N),t.ignoreUnaccepted||(T=new Error("Aborted because "+d+" is not accepted"+O));break;case"accepted":t.onAccepted&&t.onAccepted(N),q=!0;break;case"disposed":t.onDisposed&&t.onDisposed(N),R=!0;break;default:throw new Error("Unexception type "+N.type)}if(T)return p("abort"),Promise.reject(T);if(q)for(d in y[d]=b[d],u(g,N.outdatedModules),N.outdatedDependencies)Object.prototype.hasOwnProperty.call(N.outdatedDependencies,d)&&(f[d]||(f[d]=[]),u(f[d],N.outdatedDependencies[d]));R&&(u(g,[N.moduleId]),y[d]=w)}var A,B=[];for(l=0;l0;)if(d=I.pop(),a=E[d]){var _={},D=a.hot._disposeHandlers;for(r=0;r=0&&$.parents.splice(A,1))}}for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d]))for(M=f[d],r=0;r=0&&a.children.splice(A,1);for(d in p("apply"),n=m,y)Object.prototype.hasOwnProperty.call(y,d)&&(e[d]=y[d]);var j=null;for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d])){M=f[d];var k=[];for(l=0;l{let l=`${o}Id`;t.setAttribute(`data-${o}`,e[o]||l())}),f.forEach(o=>{t.setAttribute(`data-${o}`,e[o]||b[o])}),t}static formats(e){return f.concat(p).reduce((t,o)=>(e.hasAttribute(`data-${o}`)&&(t[o]=e.getAttribute(`data-${o}`)||void 0),t),{})}format(e,t){f.concat(p).indexOf(e)>-1?t?this.domNode.setAttribute(`data-${e}`,t):this.domNode.removeAttribute(`data-${e}`):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),o=this.domNode.getAttribute("data-rowspan"),l=parseInt(this.domNode.getAttribute("data-colspan"),10);!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:l,rowspan:o}),super.optimize(e)}tableCell(){return this.parent}}g.blotName="table-cell-line",g.ClassName="qlbt-cell-line",g.tagName="DIV";class y extends c{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()["table-cell-line"],t=this.children.tail.formats()["table-cell-line"],o=this.next.children.head.formats()["table-cell-line"],l=this.next.children.tail.formats()["table-cell-line"];return e.cell===t.cell&&e.cell===o.cell&&e.cell===l.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),f.forEach(o=>{e[o]&&t.setAttribute(o,e[o])}),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),f.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")),f.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){f.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute(`data-${e}`,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()}}y.blotName="table",y.tagName="TD";class w extends c{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(),l=this.next.children.tail.formats();return e.row===t.row&&e.row===o.row&&e.row===l.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),{})}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}w.blotName="table-row",w.tagName="TR";class x extends c{}x.blotName="table-body",x.tagName="TBODY";class v extends d{static create(e){let t=super.create(e);return u.forEach(o=>{t.setAttribute(`${o}`,e[o]||h[o])}),t}static formats(e){return u.reduce((t,o)=>(e.hasAttribute(`${o}`)&&(t[o]=e.getAttribute(`${o}`)||void 0),t),{})}format(e,t){u.indexOf(e)>-1?this.domNode.setAttribute(`${e}`,t||h[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}v.blotName="table-col",v.tagName="col";class C extends c{}C.blotName="table-col-group",C.tagName="colgroup";class N extends c{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()[v.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){var l=this.descendants(x);const r=n(l,1)[0];if(null==r||null==r.children.head)return;const i=this.descendants(y),a=[],d=[];if(i.forEach(t=>{const l=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),o);l.x+m>e.x&&l.x1-me.x1-m&&d.push(t)}),a.length===i.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),a.forEach(e=>{e.remove()}),d.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){var o=this.descendants(x);const l=n(o,1)[0];if(null==l||null==l.children.head)return;const r=this.descendants(y),i=[],a=[],d=[];if(r.forEach(o=>{const l=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),t);l.y>e.y-m&&l.y1e.y1-m&&(a.push(o),Math.abs(l.y-e.y){let n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),t);return n.y>e.y-m&&n.y1{const o=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),l=e.parent.next,n=l.children.reduce((e,l)=>{const n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),t);return Math.abs(o.x1-n.x){e.remove()}),a.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)})}tableDestroy(){const e=i.default.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(i.default.sources.USER)}insertCell(e,t){const o=R(),l=e.formats().row,n=this.scroll.create(y.blotName,Object.assign({},b,{row:l})),r=this.scroll.create(g.blotName,{row:l,cell:o});n.appendChild(r),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,o=!0,l){var r=this.descendants(x);const i=n(r,1)[0];var a=this.descendants(C);const d=n(a,1)[0],c=this.descendants(v);let u=[],h=[],p=[];if(null==i||null==i.children.head)return;this.descendants(y).forEach(t=>{const n=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),l);o?Math.abs(n.x1-e.x1)m&&e.x1-n.x1<-m&&h.push(t):Math.abs(n.x-e.x)m&&e.x-n.x1<-m&&h.push(t)}),u.forEach(e=>{const t=o?e.next:e,l=R(),n=e.parent,r=n.formats().row,i=e.formats(),s=this.scroll.create(y.blotName,Object.assign({},b,{row:r,rowspan:i.rowspan})),a=this.scroll.create(g.blotName,{row:r,cell:l,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),p.push(s)});const f=this.scroll.create(v.blotName,!0);let w=o?c[t].next:c[t];return w?d.insertBefore(f,w):d.appendChild(f),h.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),p.push(e)}),p.sort((e,t)=>{return e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y}),this.updateTableWidth(),p}insertRow(e,t,o){var l=this.descendants(x);const r=n(l,1)[0];if(null==r||null==r.children.head)return;const i=this.descendants(y),d=q(),c=this.scroll.create(w.blotName,{row:d});let u=[],h=[],p=[];i.forEach(l=>{const n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),o);t?Math.abs(n.y1-e.y1)m&&e.y1-n.y1<-m&&h.push(l):Math.abs(n.y-e.y)m&&e.y-n.y1<-m&&h.push(l)});const f=(e,t)=>{return e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x};u.sort(f),u.forEach(e=>{const t=R(),o=e.formats(),l=this.scroll.create(y.blotName,Object.assign({},b,{row:d,colspan:o.colspan})),n=this.scroll.create(g.blotName,{row:d,cell:t,colspan:o.colspan}),r=this.scroll.create(a.blotName);n.appendChild(r),l.appendChild(n),c.appendChild(l),p.push(l)}),h.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),p.push(e)});const v=this.rows().find(l=>{let n=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),o);return t?Math.abs(n.y-e.y-e.height)(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",l),t.format("rowspan",o),e=t),e),null);let i=r.domNode.getAttribute("data-row"),s=r.children.head.domNode.getAttribute("data-cell");return r.children.forEach(e=>{e.format("cell",s),e.format("row",i),e.format("colspan",l),e.format("rowspan",o)}),r}unmergeCells(e,t){let o={},l=1,n=1;e.forEach(e=>{if(o=e.formats(),l=o.rowspan,(n=o.colspan)>1){let t=e.next,o=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(o,t)}if(l>1){let o=l,r=e.row().next;for(;o>1;){let l=r.children.reduce((o,l)=>{let n=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),r=(0,s.getRelativeRect)(l.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-r.x)0;e--)this.insertCell(r,l);o-=1,r=r.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}N.blotName="table-container",N.className="quill-better-table",N.tagName="TABLE";class T extends c{constructor(e,t){super(e,t);const o=i.default.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)}}function q(){return`row-${Math.random().toString(36).slice(2,6)}`}function R(){return`cell-${Math.random().toString(36).slice(2,6)}`}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[N],N.requiredContainer=T,N.allowedChildren=[x,C],x.requiredContainer=N,x.allowedChildren=[w],w.requiredContainer=x,w.allowedChildren=[y],y.requiredContainer=w,y.allowedChildren=[g],g.requiredContainer=y,C.allowedChildren=[v],C.requiredContainer=N,v.requiredContainer=C,t.TableCol=v,t.TableColGroup=C,t.TableCellLine=g,t.TableCell=y,t.TableRow=w,t.TableBody=x,t.TableContainer=N,t.TableViewWrapper=T,t.rowId=q,t.cellId=R},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var o=[],l=!0,n=!1,r=void 0;try{for(var i,s=e[Symbol.iterator]();!(l=(i=s.next()).done)&&(o.push(i.value),!t||o.length!==t);l=!0);}catch(e){n=!0,r=e}finally{try{!l&&s.return&&s.return()}finally{if(n)throw r}}return o}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=d(o(0)),r=d(o(4)),i=d(o(5)),s=d(o(6)),a=o(2);function d(e){return e&&e.__esModule?e:{default:e}}const c=n.default.import("core/module"),u=n.default.import("delta");class h extends c{static register(){n.default.register(a.TableCol,!0),n.default.register(a.TableColGroup,!0),n.default.register(a.TableCellLine,!0),n.default.register(a.TableCell,!0),n.default.register(a.TableRow,!0),n.default.register(a.TableBody,!0),n.default.register(a.TableContainer,!0),n.default.register(a.TableViewWrapper,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",o=>{if(!o.path||o.path.length<=0)return;const l=o.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(l){if(this.table===l)return;this.table&&this.hideTableTools(),this.showTableTools(l,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",o=>{if(!this.table)return!0;if(o.preventDefault(),!o.path||o.path.length<=0)return;const l=o.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],n=o.path.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],r=o.path.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let i=this.tableSelection.selectedTds.map(e=>e.domNode).includes(r);(this.tableSelection.selectedTds.length<=0||!i)&&this.tableSelection.setSelection(r.getBoundingClientRect(),r.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),l&&(this.tableOperationMenu=new s.default({table:l,row:n,cell:r,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;var o=this.quill.getLine(e.index);const n=l(o,1)[0];if(0===t.offset){var r=this.quill.getLine(e.index-1);const t=l(r,1)[0];if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==n.statics.blotName)return!1}return!0});let o=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,o)}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];var t=this.quill.getLine(e.index),o=l(t,2);const n=o[0],r=o[1];if(null==n||n.statics.blotName!==a.TableCellLine.blotName)return[null,null,null,-1];const i=n.tableCell(),s=i.row();return[s.table(),s,i,r]}insertTable(e,t){const o=this.quill.getSelection(!0);if(null==o)return;this.quill.getLeaf(o.index)[0],this.quill.getLeaf(o.index+1)[0];let l=(new u).retain(o.index);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=(0,a.rowId)();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:o,cell:(0,a.cellId)()}}),e),e)},l),this.quill.updateContents(l,n.default.sources.USER),this.quill.setSelection(o.index+1,n.default.sources.SILENT)}showTableTools(e,t,o){this.table=e,this.columnTool=new r.default(e,t,o),this.tableSelection=new i.default(e,t,o)}hideTableTools(){this.columnTool.destroy(),this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}h.keyboardBindings={"table-cell-line backspace":{key:"Backspace",format:["table-cell-line"],collapsed:!0,offset:0,handler(e,t){var o=this.quill.getLine(e.index),n=l(o,2);const r=n[0];n[1];return!(!r.prev||"table-cell-line"!==r.prev.statics.blotName)}},"table-cell-line delete":{key:"Delete",format:["table-cell-line"],collapsed:!0,suffix:/^$/,handler(){}},"table-cell-line enter":{key:"Enter",shiftKey:null,format:["table-cell-line"],handler(e,t){if(this.quill.selection&&this.quill.selection.composing)return;const o=n.default.imports.parchment.Scope;e.length>0&&this.quill.scroll.deleteAt(e.index,e.length);const l=Object.keys(t.format).reduce((e,l)=>(this.quill.scroll.query(l,o.BLOCK)&&!Array.isArray(t.format[l])&&(e[l]=t.format[l]),e),{});this.quill.insertText(e.index,"\n",l["table-cell-line"],n.default.sources.USER),this.quill.setSelection(e.index+1,n.default.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==l[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.default.sources.USER))})}}},t.default=h},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l,n=o(0),r=(l=n)&&l.__esModule?l:{default:l},i=o(1);const s=12,a=12,d=50,c="#35A7ED";t.default=class{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),(0,i.css)(this.domNode,{width:`${o.width}px`,height:`${s}px`,left:`${o.left-t.left+e.scrollLeft}px`,top:`${o.top-t.top+e.scrollTop-s-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"),(0,i.css)(e,{height:`${a}px`}),e.appendChild(t),e}updateToolCells(){const e=r.default.find(this.table),t=e.children.tail.children.head.children,o=e.colGroup().children,l=function(e){return e.reduce((e,t)=>{const o=t.formats().colspan;return e+=parseInt(o,10)},0)}(t);let n=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=l?n[e].remove():(s=n[e],(0,i.css)(s,{"min-width":`${r}px`})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),(0,i.css)(s,{"min-width":`${r}px`}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=r.default.find(this.table),o=e.querySelector(".qlbt-col-tool-cell-holder");let l=!1,n=0,a=0,u=0,h=0,p={},f={},b=null;const m=e=>{e.preventDefault(),l&&(a=e.clientX,u=h+a-n>=d?a-n:d-h,(0,i.css)(b,{left:`${f.left+f.width-1+u}px`}))},g=r=>{r.preventDefault();const s=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),d=t.colGroup().children.at(s);l&&(d.format("width",h+u),(0,i.css)(e,{"min-width":`${h+u}px`}),n=0,a=0,u=0,h=0,l=!1,o.classList.remove("dragging")),document.removeEventListener("mousemove",m,!1),document.removeEventListener("mouseup",g,!1),p={},f={},b.remove(),b=null,t.updateTableWidth();const c=this.quill.getModule("better-table").tableSelection;c&&c.clearSelection()};o.addEventListener("mousedown",t=>{document.addEventListener("mousemove",m,!1),document.addEventListener("mouseup",g,!1),p=this.table.getBoundingClientRect(),f=e.getBoundingClientRect(),b=document.createElement("div"),(0,i.css)(b,{position:"fixed",top:`${f.top}px`,left:`${f.left+f.width-1}px`,zIndex:"100",height:`${p.height+s+4}px`,width:"1px",backgroundColor:c}),document.body.appendChild(b),l=!0,n=t.clientX,h=f.width,o.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l,n=o(0),r=(l=n)&&l.__esModule?l:{default:l},i=o(1),s=o(2);const a="#35A7ED",d=["left","right","top","bottom"],c=2;function u(e,t){let o=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),l=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),r=Math.max(e.y,t.y,e.y+e.height-1,t.y+t.height-1);return{x:o,x1:l,y:n,y1:r,width:l-o,height:r-n}}t.default=class{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.clearSelectionHanler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHanler)}helpLinesInitial(){let e=this.quill.root.parentNode;d.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),(0,i.css)(this[t],{position:"absolute",display:"none","background-color":a}),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]"),l=(0,i.getRelativeRect)(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]"),r=(0,i.getRelativeRect)(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=u(l,r),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),o!==n&&t.quill.blur()}this.dragging=!0,this.boundary=u(l,l),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){r.default.find(this.table).descendants(s.TableCell).forEach(e=>{var t=(0,i.getRelativeRect)(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);let o=t.x,l=t.y,n=t.width,r=t.height;(o+c>=this.boundary.x&&o+c<=this.boundary.x1||o-c+n>=this.boundary.x&&o-c+n<=this.boundary.x1)&&(l+c>=this.boundary.y&&l+c<=this.boundary.y1||l-c+r>=this.boundary.y&&l-c+r<=this.boundary.y1)&&(this.boundary=u(this.boundary,{x:o,y:l,width:n,height:r}))})}computeSelectedTds(){return r.default.find(this.table).descendants(s.TableCell).reduce((e,t)=>{var o=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);let l=o.x,n=o.y,r=o.width,s=o.height;return l+c>=this.boundary.x&&l-c+r<=this.boundary.x1&&n+c>=this.boundary.y&&n-c+s<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;(0,i.css)(this.left,{display:"block",left:`${this.boundary.x-e-1}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.right,{display:"block",left:`${this.boundary.x1-e}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.top,{display:"block",left:`${this.boundary.x-1-e}px`,top:`${this.boundary.y}px`,width:`${this.boundary.width+1}px`,height:"1px"}),(0,i.css)(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=(0,i.getRelativeRect)(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=(0,i.getRelativeRect)(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=u(e,t),this.repositionHelpLines()}destroy(){return d.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHanler),null}setSelection(e,t){this.boundary=u((0,i.getRelativeRect)(e,this.quill.root.parentNode),(0,i.getRelativeRect)(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],d.forEach(e=>{this[e]&&(0,i.css)(this[e],{display:"none"})})}}},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l,n=o(0),r=(l=n)&&l.__esModule?l:{default:l},i=o(1);const s=150,a=200,d={insertColumnRight:{text:"Insert column right",handler(){const e=r.default.find(this.table);let t=c(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.default.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",handler(){const e=r.default.find(this.table);let t=c(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.default.sources.USER),this.quill.setSelection(this.quill.getIndex(o[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(o[0].domNode.getBoundingClientRect(),o[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",handler(){const e=r.default.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(r.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",handler(){const e=r.default.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(r.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,r.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",handler(){const e=r.default.find(this.table),t=e.rows().reduce((e,t)=>{let o=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return o.y>this.boundary.y-5&&o.y+o.height{let o=(0,i.getRelativeRect)(t.getBoundingClientRect(),this.quill.root.parentNode);return o.x>this.boundary.x-5&&o.x+o.widthe.x+5>t.x&&e.x+e.width-5{let r=(0,i.getRelativeRect)(t.getBoundingClientRect(),s);return n(r,l)&&e.push(o.indexOf(t)),e},[]));var o,l,n,s;e.deleteColumns(this.boundary,t,this.quill.root.parentNode)||(this.tableColumnTool.updateToolCells(),this.quill.update(r.default.sources.USER),this.tableSelection.clearSelection())}},deleteRow:{text:"Delete selected rows",handler(){r.default.find(this.table).deleteRow(this.boundary,this.quill.root.parentNode),this.quill.update(r.default.sources.USER),this.tableSelection.clearSelection()}},deleteTable:{text:"Delete table",handler(){const e=this.quill.getModule("better-table"),t=r.default.find(this.table);e.hideTableTools(),t.remove(),this.quill.update(r.default.sources.USER)}}};function c(e,t,o,l){return e.reduce((n,r)=>{let s=(0,i.getRelativeRect)(r.getBoundingClientRect(),l);return o(s,t)&&(n=e.indexOf(r)),n},!1)}t.default=class{constructor(e,t,o){const l=t.getModule("better-table");this.tableSelection=l.tableSelection,this.table=e.table,this.quill=t,this.options=o,this.menuItems=Object.assign({},d,o.items),this.tableColumnTool=l.columnTool,this.boundary=this.tableSelection.boundary,this.selectedTds=this.tableSelection.selectedTds,this.destroyHanlder=this.destroy.bind(this),this.columnToolCells=this.tableColumnTool.colToolCells(),this.menuInitial(e),this.mount(),document.addEventListener("click",this.destroyHanlder,!1)}mount(){document.body.appendChild(this.domNode)}destroy(){return this.domNode.remove(),document.removeEventListener("click",this.destroyHanlder,!1),null}menuInitial({table:e,left:t,top:o}){this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-operation-menu"),(0,i.css)(this.domNode,{position:"absolute",left:`${t}px`,top:`${o}px`,"min-height":`${s}px`,width:`${a}px`});for(let e in this.menuItems)this.menuItems[e]&&this.domNode.appendChild(this.menuItemCreator(Object.assign({},d[e],this.menuItems[e])))}menuItemCreator({text:e,handler:t}){const o=document.createElement("div");return o.classList.add("qlbt-operation-menu-item"),o.innerText=e,o.addEventListener("click",t.bind(this),!1),o}}},,function(e,t,o){e.exports=o(3)}]).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,r){!function(e,t){if(!v[e]||!x[e])return;for(var r in x[e]=!1,t)Object.prototype.hasOwnProperty.call(t,r)&&(b[r]=t[r]);0==--g&&0===y&&q()}(e,r),t&&t(e,r)};var r,o=!0,n="20a71d310cbb3386ec65",l=1e4,i={},s=[],a=[];function d(e){var t=E[e];if(!t)return S;var o=function(o){return t.hot.active?(E[o]?-1===E[o].parents.indexOf(e)&&E[o].parents.push(e):(s=[e],r=o),-1===t.children.indexOf(o)&&t.children.push(o)):(console.warn("[HMR] unexpected require("+o+") from disposed module "+e),s=[]),S(o)},n=function(e){return{configurable:!0,enumerable:!0,get:function(){return S[e]},set:function(t){S[e]=t}}};for(var l in S)Object.prototype.hasOwnProperty.call(S,l)&&"e"!==l&&"t"!==l&&Object.defineProperty(o,l,n(l));return o.e=function(e){return"ready"===h&&p("prepare"),y++,S.e(e).then(t,function(e){throw t(),e});function t(){y--,"prepare"===h&&(w[e]||T(e),0===y&&0===g&&q())}},o.t=function(e,t){return 1&t&&(e=o(e)),S.t(e,-2&t)},o}function c(e){var t={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_disposeHandlers:[],_main:r!==e,active:!0,accept:function(e,r){if(void 0===e)t._selfAccepted=!0;else if("function"==typeof e)t._selfAccepted=e;else if("object"==typeof e)for(var o=0;o=0&&t._disposeHandlers.splice(r,1)},check:N,apply:R,status:function(e){if(!e)return h;u.push(e)},addStatusHandler:function(e){u.push(e)},removeStatusHandler:function(e){var t=u.indexOf(e);t>=0&&u.splice(t,1)},data:i[e]};return r=void 0,t}var u=[],h="idle";function p(e){h=e;for(var t=0;t0;){var n=o.pop(),l=n.id,i=n.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 ")),N.type){case"self-declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of self decline: "+N.moduleId+A));break;case"declined":t.onDeclined&&t.onDeclined(N),t.ignoreDeclined||(T=new Error("Aborted because of declined dependency: "+N.moduleId+" in "+N.parentId+A));break;case"unaccepted":t.onUnaccepted&&t.onUnaccepted(N),t.ignoreUnaccepted||(T=new Error("Aborted because "+d+" is not accepted"+A));break;case"accepted":t.onAccepted&&t.onAccepted(N),q=!0;break;case"disposed":t.onDisposed&&t.onDisposed(N),R=!0;break;default:throw new Error("Unexception type "+N.type)}if(T)return p("abort"),Promise.reject(T);if(q)for(d in y[d]=b[d],u(g,N.outdatedModules),N.outdatedDependencies)Object.prototype.hasOwnProperty.call(N.outdatedDependencies,d)&&(f[d]||(f[d]=[]),u(f[d],N.outdatedDependencies[d]));R&&(u(g,[N.moduleId]),y[d]=w)}var O,B=[];for(o=0;o0;)if(d=_.pop(),a=E[d]){var I={},j=a.hot._disposeHandlers;for(l=0;l=0&&k.parents.splice(O,1))}}for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d]))for(M=f[d],l=0;l=0&&a.children.splice(O,1);for(d in p("apply"),n=m,y)Object.prototype.hasOwnProperty.call(y,d)&&(e[d]=y[d]);var D=null;for(d in f)if(Object.prototype.hasOwnProperty.call(f,d)&&(a=E[d])){M=f[d];var $=[];for(o=0;ot.includes(o)?r:Object.assign({},r,{[o]:e[o]}),{})}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CELL_ATTRIBUTES=t.cellId=t.rowId=t.TableViewWrapper=t.TableContainer=t.TableBody=t.TableRow=t.TableCell=t.TableCellLine=t.TableColGroup=t.TableCol=void 0;var o,n=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,n=!1,l=void 0;try{for(var i,s=e[Symbol.iterator]();!(o=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);o=!0);}catch(e){n=!0,l=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw l}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),l=r(0),i=(o=l)&&o.__esModule?o:{default:o},s=r(1);const a=i.default.import("blots/break"),d=i.default.import("blots/block"),c=i.default.import("blots/container"),u=["width"],h={width:100},p=["row","cell"],f=["rowspan","colspan"],b={rowspan:1,colspan:1},m=5;class g extends d{static create(e){const t=super.create(e);return p.forEach(r=>{let o=`${r}Id`;t.setAttribute(`data-${r}`,e[r]||o())}),f.forEach(r=>{t.setAttribute(`data-${r}`,e[r]||b[r])}),t}static formats(e){return f.concat(p).reduce((t,r)=>(e.hasAttribute(`data-${r}`)&&(t[r]=e.getAttribute(`data-${r}`)||void 0),t),{})}format(e,t){f.concat(p).indexOf(e)>-1?t?this.domNode.setAttribute(`data-${e}`,t):this.domNode.removeAttribute(`data-${e}`):super.format(e,t)}optimize(e){const t=this.domNode.getAttribute("data-row"),r=this.domNode.getAttribute("data-rowspan"),o=parseInt(this.domNode.getAttribute("data-colspan"),10);!this.statics.requiredContainer||this.parent instanceof this.statics.requiredContainer||this.wrap(this.statics.requiredContainer.blotName,{row:t,colspan:o,rowspan:r}),super.optimize(e)}tableCell(){return this.parent}}g.blotName="table-cell-line",g.ClassName="qlbt-cell-line",g.tagName="DIV";class y extends c{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats()["table-cell-line"],t=this.children.tail.formats()["table-cell-line"],r=this.next.children.head.formats()["table-cell-line"],o=this.next.children.tail.formats()["table-cell-line"];return e.cell===t.cell&&e.cell===r.cell&&e.cell===o.cell}return!1}static create(e){const t=super.create(e);return t.setAttribute("data-row",e.row),f.forEach(r=>{e[r]&&t.setAttribute(r,e[r])}),t}static formats(e){const t={};return e.hasAttribute("data-row")&&(t.row=e.getAttribute("data-row")),f.reduce((t,r)=>(e.hasAttribute(r)&&(t[r]=e.getAttribute(r)),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")),f.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(r=>{r.format(e,t)})}format(e,t){f.indexOf(e)>-1?(this.toggleAttribute(e,t),this.formatChildren(e,t)):["row"].indexOf(e)>-1?(this.toggleAttribute(`data-${e}`,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()}}y.blotName="table",y.tagName="TD";class w extends c{checkMerge(){if(super.checkMerge()&&null!=this.next.children.head){const e=this.children.head.formats(),t=this.children.tail.formats(),r=this.next.children.head.formats(),o=this.next.children.tail.formats();return e.row===t.row&&e.row===r.row&&e.row===o.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}}w.blotName="table-row",w.tagName="TR";class x extends c{}x.blotName="table-body",x.tagName="TBODY";class v extends d{static create(e){let t=super.create(e);return u.forEach(r=>{t.setAttribute(`${r}`,e[r]||h[r])}),t}static formats(e){return u.reduce((t,r)=>(e.hasAttribute(`${r}`)&&(t[r]=e.getAttribute(`${r}`)||void 0),t),{})}format(e,t){u.indexOf(e)>-1?this.domNode.setAttribute(`${e}`,t||h[e]):super.format(e,t)}html(){return this.domNode.outerHTML}}v.blotName="table-col",v.tagName="col";class C extends c{}C.blotName="table-col-group",C.tagName="colgroup";class N extends c{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()[v.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=[],r){var o=this.descendants(x);const l=n(o,1)[0];if(null==l||null==l.children.head)return;const i=this.descendants(y),a=[],d=[];if(i.forEach(t=>{const o=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),r);o.x+m>e.x&&o.x1-me.x1-m&&d.push(t)}),a.length===i.length)return this.tableDestroy(),!0;t.forEach(e=>{this.colGroup().children.at(t[0]).remove()}),a.forEach(e=>{e.remove()}),d.forEach(e=>{const r=parseInt(e.formats().colspan,10);parseInt(e.formats().width,10);e.format("colspan",r-t.length)}),this.updateTableWidth()}deleteRow(e,t){var r=this.descendants(x);const o=n(r,1)[0];if(null==o||null==o.children.head)return;const l=this.descendants(y),i=[],a=[],d=[];if(l.forEach(r=>{const o=(0,s.getRelativeRect)(r.domNode.getBoundingClientRect(),t);o.y>e.y-m&&o.y1e.y1-m&&(a.push(r),Math.abs(o.y-e.y){let n=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),t);return n.y>e.y-m&&n.y1{const r=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),o=e.parent.next,n=o.children.reduce((e,o)=>{const n=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),t);return Math.abs(r.x1-n.x){e.remove()}),a.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t-c)})}tableDestroy(){const e=i.default.find(this.scroll.domNode.parentNode),t=e.getModule("better-table");this.remove(),t.hideTableTools(),e.update(i.default.sources.USER)}insertCell(e,t){const r=R(),o=e.formats().row,n=this.scroll.create(y.blotName,Object.assign({},b,{row:o})),l=this.scroll.create(g.blotName,{row:o,cell:r});n.appendChild(l),t?e.insertBefore(n,t):e.appendChild(n)}insertColumn(e,t,r=!0,o){var l=this.descendants(x);const i=n(l,1)[0];var a=this.descendants(C);const d=n(a,1)[0],c=this.descendants(v);let u=[],h=[],p=[];if(null==i||null==i.children.head)return;this.descendants(y).forEach(t=>{const n=(0,s.getRelativeRect)(t.domNode.getBoundingClientRect(),o);r?Math.abs(n.x1-e.x1)m&&e.x1-n.x1<-m&&h.push(t):Math.abs(n.x-e.x)m&&e.x-n.x1<-m&&h.push(t)}),u.forEach(e=>{const t=r?e.next:e,o=R(),n=e.parent,l=n.formats().row,i=e.formats(),s=this.scroll.create(y.blotName,Object.assign({},b,{row:l,rowspan:i.rowspan})),a=this.scroll.create(g.blotName,{row:l,cell:o,rowspan:i.rowspan});s.appendChild(a),t?n.insertBefore(s,t):n.appendChild(s),p.push(s)});const f=this.scroll.create(v.blotName,!0);let w=r?c[t].next:c[t];return w?d.insertBefore(f,w):d.appendChild(f),h.forEach(e=>{const t=e.formats().colspan;e.format("colspan",parseInt(t,10)+1),p.push(e)}),p.sort((e,t)=>{return e.domNode.getBoundingClientRect().y-t.domNode.getBoundingClientRect().y}),this.updateTableWidth(),p}insertRow(e,t,r){var o=this.descendants(x);const l=n(o,1)[0];if(null==l||null==l.children.head)return;const i=this.descendants(y),d=q(),c=this.scroll.create(w.blotName,{row:d});let u=[],h=[],p=[];i.forEach(o=>{const n=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),r);t?Math.abs(n.y1-e.y1)m&&e.y1-n.y1<-m&&h.push(o):Math.abs(n.y-e.y)m&&e.y-n.y1<-m&&h.push(o)});const f=(e,t)=>{return e.domNode.getBoundingClientRect().x-t.domNode.getBoundingClientRect().x};u.sort(f),u.forEach(e=>{const t=R(),r=e.formats(),o=this.scroll.create(y.blotName,Object.assign({},b,{row:d,colspan:r.colspan})),n=this.scroll.create(g.blotName,{row:d,cell:t,colspan:r.colspan}),l=this.scroll.create(a.blotName);n.appendChild(l),o.appendChild(n),c.appendChild(o),p.push(o)}),h.forEach(e=>{const t=parseInt(e.formats().rowspan,10);e.format("rowspan",t+1),p.push(e)});const v=this.rows().find(o=>{let n=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),r);return t?Math.abs(n.y-e.y-e.height)(0!==n?(e&&t.moveChildren(e),t.remove()):(t.format("colspan",o),t.format("rowspan",r),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",o),e.format("rowspan",r)}),l}unmergeCells(e,t){let r={},o=1,n=1;e.forEach(e=>{if(r=e.formats(),o=r.rowspan,(n=r.colspan)>1){let t=e.next,r=e.row();e.format("colspan",1);for(let e=n;e>1;e--)this.insertCell(r,t)}if(o>1){let r=o,l=e.row().next;for(;r>1;){let o=l.children.reduce((r,o)=>{let n=(0,s.getRelativeRect)(e.domNode.getBoundingClientRect(),t),l=(0,s.getRelativeRect)(o.domNode.getBoundingClientRect(),t);return Math.abs(n.x1-l.x)0;e--)this.insertCell(l,o);r-=1,l=l.next}e.format("rowspan",1)}})}rows(){const e=this.children.tail;return null==e?[]:e.children.map(e=>e)}}N.blotName="table-container",N.className="quill-better-table",N.tagName="TABLE";class T extends c{constructor(e,t){super(e,t);const r=i.default.find(e.domNode.parentNode);t.addEventListener("scroll",e=>{const t=r.getModule("better-table");t.columnTool&&(t.columnTool.domNode.scrollLeft=e.target.scrollLeft),t.tableSelection&&t.tableSelection.selectedTds.length>0&&t.tableSelection.repositionHelpLines()},!1)}}function q(){return`row-${Math.random().toString(36).slice(2,6)}`}function R(){return`cell-${Math.random().toString(36).slice(2,6)}`}T.blotName="table-view",T.className="quill-better-table-wrapper",T.tagName="DIV",T.allowedChildren=[N],N.requiredContainer=T,N.allowedChildren=[x,C],x.requiredContainer=N,x.allowedChildren=[w],w.requiredContainer=x,w.allowedChildren=[y],y.requiredContainer=w,y.allowedChildren=[g],g.requiredContainer=y,C.allowedChildren=[v],C.requiredContainer=N,v.requiredContainer=C,t.TableCol=v,t.TableColGroup=C,t.TableCellLine=g,t.TableCell=y,t.TableRow=w,t.TableBody=x,t.TableContainer=N,t.TableViewWrapper=T,t.rowId=q,t.cellId=R,t.CELL_ATTRIBUTES=f},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,n=!1,l=void 0;try{for(var i,s=e[Symbol.iterator]();!(o=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);o=!0);}catch(e){n=!0,l=e}finally{try{!o&&s.return&&s.return()}finally{if(n)throw l}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=c(r(0)),l=c(r(4)),i=c(r(5)),s=c(r(6)),a=r(7),d=r(2);function c(e){return e&&e.__esModule?e:{default:e}}const u=n.default.import("core/module"),h=n.default.import("delta");class p extends u{static register(){n.default.register(d.TableCol,!0),n.default.register(d.TableColGroup,!0),n.default.register(d.TableCellLine,!0),n.default.register(d.TableCell,!0),n.default.register(d.TableRow,!0),n.default.register(d.TableBody,!0),n.default.register(d.TableContainer,!0),n.default.register(d.TableViewWrapper,!0)}constructor(e,t){super(e,t),this.quill.root.addEventListener("click",r=>{if(!r.path||r.path.length<=0)return;const o=r.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0];if(o){if(this.table===o)return;this.table&&this.hideTableTools(),this.showTableTools(o,e,t)}else this.table&&this.hideTableTools()},!1),this.quill.root.addEventListener("contextmenu",r=>{if(!this.table)return!0;if(r.preventDefault(),!r.path||r.path.length<=0)return;const o=r.path.filter(e=>e.tagName&&"TABLE"===e.tagName.toUpperCase()&&e.classList.contains("quill-better-table"))[0],n=r.path.filter(e=>e.tagName&&"TR"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0],l=r.path.filter(e=>e.tagName&&"TD"===e.tagName.toUpperCase()&&e.getAttribute("data-row"))[0];let i=this.tableSelection.selectedTds.map(e=>e.domNode).includes(l);(this.tableSelection.selectedTds.length<=0||!i)&&this.tableSelection.setSelection(l.getBoundingClientRect(),l.getBoundingClientRect()),this.tableOperationMenu&&(this.tableOperationMenu=this.tableOperationMenu.destroy()),o&&(this.tableOperationMenu=new s.default({table:o,row:n,cell:l,left:r.pageX,top:r.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;var r=this.quill.getLine(e.index);const n=o(r,1)[0];if(0===t.offset){var l=this.quill.getLine(e.index-1);const t=o(l,1)[0];if(null!=t&&"table-cell-line"===t.statics.blotName&&"table-cell-line"!==n.statics.blotName)return!1}return!0});let r=e.keyboard.bindings.Backspace.pop();e.keyboard.bindings.Backspace.splice(0,1,r),e.clipboard.addMatcher("td",a.matchTableCell),e.clipboard.addMatcher("table",a.matchTable),e.clipboard.matchers=e.clipboard.matchers.filter(e=>"tr"!==e[0])}getTable(e=this.quill.getSelection()){if(null==e)return[null,null,null,-1];var t=this.quill.getLine(e.index),r=o(t,2);const n=r[0],l=r[1];if(null==n||n.statics.blotName!==d.TableCellLine.blotName)return[null,null,null,-1];const i=n.tableCell(),s=i.row();return[s.table(),s,i,l]}insertTable(e,t){const r=this.quill.getSelection(!0);if(null==r)return;this.quill.getLeaf(r.index)[0],this.quill.getLeaf(r.index+1)[0];let o=(new h).retain(r.index);o.insert("\n"),o=new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-col":!0}),e),o),o=new Array(e).fill(0).reduce(e=>{let r=(0,d.rowId)();return new Array(t).fill("\n").reduce((e,t)=>(e.insert(t,{"table-cell-line":{row:r,cell:(0,d.cellId)()}}),e),e)},o),this.quill.updateContents(o,n.default.sources.USER),this.quill.setSelection(r.index+1,n.default.sources.SILENT)}showTableTools(e,t,r){this.table=e,this.columnTool=new l.default(e,t,r),this.tableSelection=new i.default(e,t,r)}hideTableTools(){this.columnTool.destroy(),this.tableSelection.destroy(),this.tableOperationMenu&&this.tableOperationMenu.destroy(),this.columnTool=null,this.tableSelection=null,this.tableOperationMenu=null,this.table=null}}p.keyboardBindings={"table-cell-line backspace":{key:"Backspace",format:["table-cell-line"],collapsed:!0,offset:0,handler(e,t){var r=this.quill.getLine(e.index),n=o(r,2);const l=n[0];n[1];return!(!l.prev||"table-cell-line"!==l.prev.statics.blotName)}},"table-cell-line delete":{key:"Delete",format:["table-cell-line"],collapsed:!0,suffix:/^$/,handler(){}},"table-cell-line enter":{key:"Enter",shiftKey:null,format:["table-cell-line"],handler(e,t){if(this.quill.selection&&this.quill.selection.composing)return;const r=n.default.imports.parchment.Scope;e.length>0&&this.quill.scroll.deleteAt(e.index,e.length);const o=Object.keys(t.format).reduce((e,o)=>(this.quill.scroll.query(o,r.BLOCK)&&!Array.isArray(t.format[o])&&(e[o]=t.format[o]),e),{});this.quill.insertText(e.index,"\n",o["table-cell-line"],n.default.sources.USER),this.quill.setSelection(e.index+1,n.default.sources.SILENT),this.quill.focus(),Object.keys(t.format).forEach(e=>{null==o[e]&&(Array.isArray(t.format[e])||"link"!==e&&this.quill.format(e,t.format[e],n.default.sources.USER))})}}},t.default=p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o,n=r(0),l=(o=n)&&o.__esModule?o:{default:o},i=r(1);const s=12,a=12,d=50,c="#35A7ED";t.default=class{constructor(e,t,r){if(!e)return null;this.table=e,this.quill=t,this.options=r,this.domNode=null,this.initColTool()}initColTool(){const e=this.quill.root.parentNode,t=(this.table.getBoundingClientRect(),e.getBoundingClientRect()),r=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-col-tool"),this.updateToolCells(),e.appendChild(this.domNode),(0,i.css)(this.domNode,{width:`${r.width}px`,height:`${s}px`,left:`${r.left-t.left+e.scrollLeft}px`,top:`${r.top-t.top+e.scrollTop-s-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"),(0,i.css)(e,{height:`${a}px`}),e.appendChild(t),e}updateToolCells(){const e=l.default.find(this.table),t=e.children.tail.children.head.children,r=e.colGroup().children,o=function(e){return e.reduce((e,t)=>{const r=t.formats().colspan;return e+=parseInt(r,10)},0)}(t);let n=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"));for(let e=0;e=o?n[e].remove():(s=n[e],(0,i.css)(s,{"min-width":`${l}px`})):(s=this.createToolCell(),this.domNode.appendChild(s),this.addColCellHolderHandler(s),(0,i.css)(s,{"min-width":`${l}px`}))}}destroy(){return this.domNode.remove(),null}addColCellHolderHandler(e){const t=l.default.find(this.table),r=e.querySelector(".qlbt-col-tool-cell-holder");let o=!1,n=0,a=0,u=0,h=0,p={},f={},b=null;const m=e=>{e.preventDefault(),o&&(a=e.clientX,u=h+a-n>=d?a-n:d-h,(0,i.css)(b,{left:`${f.left+f.width-1+u}px`}))},g=l=>{l.preventDefault();const s=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e),d=t.colGroup().children.at(s);o&&(d.format("width",h+u),(0,i.css)(e,{"min-width":`${h+u}px`}),n=0,a=0,u=0,h=0,o=!1,r.classList.remove("dragging")),document.removeEventListener("mousemove",m,!1),document.removeEventListener("mouseup",g,!1),p={},f={},b.remove(),b=null,t.updateTableWidth();const c=this.quill.getModule("better-table").tableSelection;c&&c.clearSelection()};r.addEventListener("mousedown",t=>{document.addEventListener("mousemove",m,!1),document.addEventListener("mouseup",g,!1),p=this.table.getBoundingClientRect(),f=e.getBoundingClientRect(),b=document.createElement("div"),(0,i.css)(b,{position:"fixed",top:`${f.top}px`,left:`${f.left+f.width-1}px`,zIndex:"100",height:`${p.height+s+4}px`,width:"1px",backgroundColor:c}),document.body.appendChild(b),o=!0,n=t.clientX,h=f.width,r.classList.add("dragging")},!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o,n=r(0),l=(o=n)&&o.__esModule?o:{default:o},i=r(1),s=r(2);const a="#35A7ED",d=["left","right","top","bottom"],c=2;function u(e,t){let r=Math.min(e.x,t.x,e.x+e.width-1,t.x+t.width-1),o=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:r,x1:o,y:n,y1:l,width:o-r,height:l-n}}t.default=class{constructor(e,t,r){if(!e)return null;this.table=e,this.quill=t,this.options=r,this.boundary={},this.selectedTds=[],this.dragging=!1,this.selectingHandler=this.mouseDownHandler.bind(this),this.clearSelectionHanler=this.clearSelection.bind(this),this.helpLinesInitial(),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.clearSelectionHanler)}helpLinesInitial(){let e=this.quill.root.parentNode;d.forEach(t=>{this[t]=document.createElement("div"),this[t].classList.add("qlbt-selection-line"),(0,i.css)(this[t],{position:"absolute",display:"none","background-color":a}),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(r){t.quill.root.removeEventListener("mousemove",n,!1),t.quill.root.removeEventListener("mouseup",e,!1),t.dragging=!1},!1);const t=this,r=e.target.closest("td[data-row]"),o=(0,i.getRelativeRect)(r.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=(0,i.getRelativeRect)(n.getBoundingClientRect(),t.quill.root.parentNode);t.boundary=u(o,l),t.correctBoundary(),t.selectedTds=t.computeSelectedTds(),t.repositionHelpLines(),r!==n&&t.quill.blur()}this.dragging=!0,this.boundary=u(o,o),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}correctBoundary(){l.default.find(this.table).descendants(s.TableCell).forEach(e=>{var t=(0,i.getRelativeRect)(e.domNode.getBoundingClientRect(),this.quill.root.parentNode);let r=t.x,o=t.y,n=t.width,l=t.height;(r+c>=this.boundary.x&&r+c<=this.boundary.x1||r-c+n>=this.boundary.x&&r-c+n<=this.boundary.x1)&&(o+c>=this.boundary.y&&o+c<=this.boundary.y1||o-c+l>=this.boundary.y&&o-c+l<=this.boundary.y1)&&(this.boundary=u(this.boundary,{x:r,y:o,width:n,height:l}))})}computeSelectedTds(){return l.default.find(this.table).descendants(s.TableCell).reduce((e,t)=>{var r=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);let o=r.x,n=r.y,l=r.width,s=r.height;return o+c>=this.boundary.x&&o-c+l<=this.boundary.x1&&n+c>=this.boundary.y&&n-c+s<=this.boundary.y1&&e.push(t),e},[])}repositionHelpLines(){const e=this.table.parentNode.scrollLeft;(0,i.css)(this.left,{display:"block",left:`${this.boundary.x-e-1}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.right,{display:"block",left:`${this.boundary.x1-e}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px"}),(0,i.css)(this.top,{display:"block",left:`${this.boundary.x-1-e}px`,top:`${this.boundary.y}px`,width:`${this.boundary.width+1}px`,height:"1px"}),(0,i.css)(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=(0,i.getRelativeRect)(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),t=(0,i.getRelativeRect)(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=u(e,t),this.repositionHelpLines()}destroy(){return d.forEach(e=>{this[e].remove(),this[e]=null}),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),this.quill.off("text-change",this.clearSelectionHanler),null}setSelection(e,t){this.boundary=u((0,i.getRelativeRect)(e,this.quill.root.parentNode),(0,i.getRelativeRect)(t,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.boundary={},this.selectedTds=[],d.forEach(e=>{this[e]&&(0,i.css)(this[e],{display:"none"})})}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o,n=r(0),l=(o=n)&&o.__esModule?o:{default:o},i=r(1);const s=150,a=200,d={insertColumnRight:{text:"Insert column right",handler(){const e=l.default.find(this.table);let t=c(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x+e.width-t.x1)<=5,this.quill.root.parentNode);const r=e.insertColumn(this.boundary,t,!0,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(l.default.sources.USER),this.quill.setSelection(this.quill.getIndex(r[0]),0,l.default.sources.SILENT),this.tableSelection.setSelection(r[0].domNode.getBoundingClientRect(),r[0].domNode.getBoundingClientRect())}},insertColumnLeft:{text:"Insert column left",handler(){const e=l.default.find(this.table);let t=c(this.columnToolCells,this.boundary,(e,t)=>Math.abs(e.x-t.x)<=5,this.quill.root.parentNode);const r=e.insertColumn(this.boundary,t,!1,this.quill.root.parentNode);this.tableColumnTool.updateToolCells(),this.quill.update(l.default.sources.USER),this.quill.setSelection(this.quill.getIndex(r[0]),0,l.default.sources.SILENT),this.tableSelection.setSelection(r[0].domNode.getBoundingClientRect(),r[0].domNode.getBoundingClientRect())}},insertRowUp:{text:"Insert row up",handler(){const e=l.default.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.quill.update(l.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,l.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},insertRowDown:{text:"Insert row down",handler(){const e=l.default.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.quill.update(l.default.sources.USER),this.quill.setSelection(this.quill.getIndex(e[0]),0,l.default.sources.SILENT),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect())}},mergeCells:{text:"Merge selected cells",handler(){const e=l.default.find(this.table),t=e.rows().reduce((e,t)=>{let r=(0,i.getRelativeRect)(t.domNode.getBoundingClientRect(),this.quill.root.parentNode);return r.y>this.boundary.y-5&&r.y+r.height{let r=(0,i.getRelativeRect)(t.getBoundingClientRect(),this.quill.root.parentNode);return r.x>this.boundary.x-5&&r.x+r.widthe.x+5>t.x&&e.x+e.width-5{let l=(0,i.getRelativeRect)(t.getBoundingClientRect(),s);return n(l,o)&&e.push(r.indexOf(t)),e},[]));var r,o,n,s;e.deleteColumns(this.boundary,t,this.quill.root.parentNode)||(this.tableColumnTool.updateToolCells(),this.quill.update(l.default.sources.USER),this.tableSelection.clearSelection())}},deleteRow:{text:"Delete selected rows",handler(){l.default.find(this.table).deleteRow(this.boundary,this.quill.root.parentNode),this.quill.update(l.default.sources.USER),this.tableSelection.clearSelection()}},deleteTable:{text:"Delete table",handler(){const e=this.quill.getModule("better-table"),t=l.default.find(this.table);e.hideTableTools(),t.remove(),this.quill.update(l.default.sources.USER)}}};function c(e,t,r,o){return e.reduce((n,l)=>{let s=(0,i.getRelativeRect)(l.getBoundingClientRect(),o);return r(s,t)&&(n=e.indexOf(l)),n},!1)}t.default=class{constructor(e,t,r){const o=t.getModule("better-table");this.tableSelection=o.tableSelection,this.table=e.table,this.quill=t,this.options=r,this.menuItems=Object.assign({},d,r.items),this.tableColumnTool=o.columnTool,this.boundary=this.tableSelection.boundary,this.selectedTds=this.tableSelection.selectedTds,this.destroyHanlder=this.destroy.bind(this),this.columnToolCells=this.tableColumnTool.colToolCells(),this.menuInitial(e),this.mount(),document.addEventListener("click",this.destroyHanlder,!1)}mount(){document.body.appendChild(this.domNode)}destroy(){return this.domNode.remove(),document.removeEventListener("click",this.destroyHanlder,!1),null}menuInitial({table:e,left:t,top:r}){this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-operation-menu"),(0,i.css)(this.domNode,{position:"absolute",left:`${t}px`,top:`${r}px`,"min-height":`${s}px`,width:`${a}px`});for(let e in this.menuItems)this.menuItems[e]&&this.domNode.appendChild(this.menuItemCreator(Object.assign({},d[e],this.menuItems[e])))}menuItemCreator({text:e,handler:t}){const r=document.createElement("div");return r.classList.add("qlbt-operation-menu-item"),r.innerText=e,r.addEventListener("click",t.bind(this),!1),r}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.matchTableCell=function(e,t,r){const o=e.parentNode,n="TABLE"===o.parentNode.tagName?o.parentNode:o.parentNode.parentNode,l=Array.from(n.querySelectorAll("tr")),a=Array.from(o.querySelectorAll("td")),d=l.indexOf(o)+1,c=a.indexOf(e)+1,u=e.getAttribute("colspan")||!1,h=e.getAttribute("rowspan")||!1;return(t=t.reduce((e,t)=>{if(t.insert&&"string"==typeof t.insert){const r=[];let o=t.insert,n=0;for(let e=0;e{"\n"===r?e.insert("\n",t.attributes):e.insert(r,(0,i._omit)(t.attributes,["table","table-cell-line"]))})}else e.insert(t.insert,t.attributes);return e},new s)).reduce((e,t)=>(t.insert&&"string"==typeof t.insert&&t.insert.startsWith("\n")?e.insert("\n",Object.assign({},Object.assign({},{row:d},t.attributes.table),{"table-cell-line":{row:d,cell:c,rowspan:h,colspan:u}},(0,i._omit)(t.attributes,["table"]))).insert(t.insert.substring(1),(0,i._omit)(t.attributes,["table","table-cell-line"])):e.insert(t.insert,Object.assign({},(0,i._omit)(t.attributes,["table","table-cell-line"]))),e),new s)},t.matchTable=function(e,t,r){if(e.querySelectorAll("colgroup").length>0)return t;let o=new s;const n=e.querySelector("tr"),l=Array.from(n.querySelectorAll("td")).reduce((e,t)=>{const r=t.getAttribute("colspan")||1;return e+=parseInt(r,10)},0);for(let e=0;e