@opentiny/fluent-editor 3.18.2 → 3.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -323,7 +323,7 @@ ${Ba(this.code(e,n))}
323
323
  `,o),l=a.index+1),this.quill.updateContents(c,h.sources.USER),this.quill.setSelection(l,h.sources.SILENT),this.quill.focus(),Object.keys(s.format).forEach(d=>{!V(o[d])||Array.isArray(s.format[d])||d==="code"||d==="link"||this.quill.format(d,s.format[d],h.sources.USER)}),this.needInsertBr=!0}};e.keyboard.bindings.Enter=e.keyboard.bindings.Enter.map(a=>a.format===void 0&&a.shiftKey===null?r:a),this.on("click",this.handleMouseClick),this.on("mouseover",this.handleMouseEnter),e.emitter.on(mu,async({mention:a,name:s})=>{const[o]=a&&[a]||await this.options.search(s);this.options.remove(o)}),i.appendChild(this.mentionListEL),e.container.parentElement.insertBefore(i,e.container)}static register(){h.register(Dr)}on(e,n){this.mentionListEL.addEventListener(e,i=>{let r=i.target,a;for(;this.mentionListEL.contains(r)&&r!==this.mentionListEL;)r.classList.contains(this.options.itemClass)&&(a=r),r=r.parentElement;a&&n.call(this,a,this.getMentionItemIndex(a))})}getMentionItemIndex(e){return[].reduce.call(this.mentionListEL.children,(n,i,r)=>i===e?r:n,-1)}handleMouseClick(e,n){this.selectMentionItem(n,!0),this.quill.focus()}handleMouseEnter(e,n){this.activeMentionIndex=n,this.highlightMentionItem(n)}getActiveMentionItem(){return this.mentionListEL.querySelector(`.${this.options.itemActiveClass}`)}isOpen(){return!this.mentionListEL.classList.contains(this.options.listHideClass)}async searchMentionListByTerm(e){const n=await this.options.search(e);if(this.latestMentionList=n,!n||n.length===0)return this.hideMentionList();this.showMentionList(n)}showMentionList(e){this.isOpen()||this.mentionListEL.classList.remove(this.options.listHideClass),this.activeMentionIndex=0,this.setMentionListPos(),this.render(e)}hideMentionList(){this.isOpen()&&(this.activeMentionIndex=0,this.mentionListEL.classList.add(this.options.listHideClass))}setMentionListPos(){const e=this.quill.selection.savedRange.index,n=this.quill.getBounds(e),{left:i,top:r}=n,a=this.quill.container,s=a.parentNode,{left:o,top:l}=a.getBoundingClientRect(),{left:c,top:d}=s.getBoundingClientRect(),p=o-c,_=l-d,m=i+p-5,g=r+_+20;this.mentionListEL.style.cssText+=`
324
324
  left: ${m}px;
325
325
  top: ${g}px;
326
- `}render(e){const n=document.createElement("div");[].forEach.call(e,(i,r)=>{const a=document.createElement("li");a.classList.add(this.options.itemClass),r===this.activeMentionIndex&&a.classList.add(this.options.itemActiveClass);const s=this.options.renderMentionItem(i);a.insertAdjacentElement("afterbegin",s),n.appendChild(a)}),this.mentionListEL.innerHTML=n.innerHTML}highlightMentionItem(e){const n=this.getActiveMentionItem();n&&n.classList.remove(this.options.itemActiveClass);const i=this.mentionListEL.querySelector(`.${this.options.itemClass}:nth-of-type(${e+1})`);i&&(i.classList.add(this.options.itemActiveClass),this.scrollIntoView(i))}scrollIntoView(e){const n=e;if(n.scrollIntoViewIfNeeded){n.scrollIntoViewIfNeeded(!1);return}if(e.scrollIntoView){e.scrollIntoView(!1);return}}selectMentionItem(e=this.activeMentionIndex,n){const i=this.latestMentionList[e];this.insertMentionBlot(i,n),this.options.select(i),this.hideMentionList()}insertMentionBlot(e,n){const i=this.options.renderMentionText(e),r=new uc().retain(this.latestMentionCharPos).delete(this.latestCaretPos-this.latestMentionCharPos).insert({[Dr.blotName]:{char:this.options.mentionChar,text:i,mention:e,link:this.options.defaultLink,target:this.options.target,searchKey:this.options.searchKey}});n?this.quill.updateContents(r,h.sources.USER):this.quill.updateContents(r,h.sources.API),this.quill.setSelection(this.latestMentionCharPos+1,h.sources.API)}}const gT=h.imports["blots/embed"];class Ha extends gT{static create(){return super.create()}optimize(){this.prev===null&&this.remove()}length(){return 1}}Ha.blotName="soft-break";Ha.tagName="BR";Ha.className="ql-soft-break";const ET=h.imports["blots/inline"];class Va extends ET{}Va.blotName="strike";Va.tagName="u";Va.className="ql-custom-strike";const fT="qlrte__op-menu-item",ST="qlrte__op-menu-dividing",hT="qlrte__op-menu-subtitle",bT="qlrte__op-menu-color-picker",_c="qlrte__op-menu-color-picker-item",us=["width"],Sr={width:100},ft=["row","cell"],ze=["rowspan","colspan"],fa={rowspan:1,colspan:1},H=5,_s=32,pc=16,ps=16,Js=50,Sa=29,eo=["#5170ff","var(--brand-1, #5170ff)"],TT=40,mc=150,CT=205,na=["left","right","top","bottom"],NT=h.imports["blots/block"];class Rn extends NT{static create(e){typeof e=="string"&&(e={value:e});const n=super.create(e.value);return ft.forEach(i=>{e[i]&&n.setAttribute(`data-${i}`,e[i])}),ze.forEach(i=>{e[i]&&n.setAttribute(`data-${i}`,e[i])}),n}static formats(e){const n={};return n.value=this.tagName.indexOf(e.tagName)+1,ze.concat(ft).reduce((i,r)=>(e.hasAttribute(`data-${r}`)&&(i[r]=e.getAttribute(`data-${r}`)||void 0),i),n)}format(e,n){Object.prototype.toString.call(n)==="[object Object]"&&(n=n.value);const i=Rn.formats(this.domNode),{row:r,cell:a,rowspan:s,colspan:o}=i;e===Rn.blotName?n?super.format(e,{value:n,row:r,cell:a,rowspan:s,colspan:o}):r?this.replaceWith("table-cell-line",{row:r,cell:a,rowspan:s,colspan:o}):super.format(e,n):super.format(e,n)}optimize(e){const{row:n,cell:i,rowspan:r,colspan:a}=Rn.formats(this.domNode);if(n&&this.parent.statics.blotName!=="table"&&this.wrap("table",{row:n,cell:i,colspan:a,rowspan:r}),this.enforceAllowedChildren(),!V(this.uiNode)&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length===0)if(V(this.statics.defaultChild))this.remove();else{const s=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(s)}this.cache={}}}Rn.blotName="header";Rn.tagName=["H1","H2","H3","H4","H5","H6"];const AT=h.imports["blots/block"],RT=h.imports["blots/container"];class tn extends RT{format(e,n){const{row:i,cell:r,rowspan:a,colspan:s}=this.domNode.dataset;e===tn.blotName&&(n?super.format(e,{row:i,cell:r,rowspan:a,colspan:s}):i&&this.replaceWith("table-cell-line",{row:i,cell:r,rowspan:a,colspan:s}))}}tn.blotName="list-container";tn.tagName="OL";class nn extends AT{constructor(e,n){super(e,n);const i=h.find(e.domNode.parentNode),r=i.getSelection();if(r){const[o]=i.getLine(r.index),l=o.domNode.closest("td");l&&[...ft,...ze].forEach(c=>l.dataset[c]&&n.setAttribute(`data-${c}`,l.dataset[c]))}const a=n.ownerDocument.createElement("span"),s=o=>{if(!e.isEnabled())return;const{value:l}=this.statics.formats(n,e);l==="checked"?(this.format("list","unchecked"),o.preventDefault()):l==="unchecked"&&(this.format("list","checked"),o.preventDefault())};a.addEventListener("mousedown",s),a.addEventListener("touchstart",s),this.attachUI(a)}static create(e){const n=super.create();return typeof e=="string"?e={value:e}:[...ft,...ze].forEach(i=>{e[i]&&(n.dataset[i]=e[i])}),n.classList.add(e.value),n}static formats(e){const n={};return n.value=e.classList.item(0)||void 0,[...ze,...ft].reduce((i,r)=>(e.dataset[r]&&(i[r]=e.dataset[r]),i),n)}static register(){h.register({"formats/list-container":tn},!0)}format(e,n){if(e!==nn.blotName){super.format(e,n);return}const i=n&&typeof n=="object"?n.value:n,r=this.domNode.classList[0],a=this.domNode.closest(".editing-select-able"),s=a&&h.find(a),o=this.domNode.querySelectorAll("img[data-image-id]");if(!i||i===r)if(o&&o.length&&o.forEach(l=>{l.style.verticalAlign="baseLine"}),s&&s.statics.blotName==="table"){const l=s.formats();this.replaceWith("table-cell-line",l),this.parent.statics.blotName===tn.blotName&&this.parent.unwrap()}else super.format(e,n);else r?this.domNode.className=this.domNode.className.replace(r,i):this.domNode.classList.add(i)}optimize(e){const n=this.prev&&this.prev.domNode.lastChild;if(n&&n.className&&n.className.indexOf("ql-soft-break")>=0){this.domNode.childNodes.forEach((o,l)=>{l>0&&this.prev.domNode.appendChild(o)}),this.remove();return}super.optimize(e);const i=OT(this.parent.domNode),r=nn.formats(this.domNode),a=this.domNode.dataset||[],s=this.domNode.querySelectorAll("img[data-image-id]");if(i.list!==r.value){const o=this.parent.domNode.classList[0];o?this.parent.domNode.className=this.parent.domNode.className.replace(o,r.value):this.parent.domNode.classList.add(r.value)}a.cell&&!i.cell&&([...ft,...ze].forEach(o=>(r[o]||a[o])&&this.parent.domNode.setAttribute(`data-${o}`,r[o]||a[o])),this.parent.parent.statics.blotName!=="table"&&(delete r.list,this.wrap("table",r))),s&&s.forEach(o=>{o.style.verticalAlign="top"})}}nn.blotName="list";nn.tagName="LI";tn.allowedChildren=[nn];nn.requiredContainer=tn;function OT(t){const e={};return t.tagName==="OL"&&(e.list=t.classList.item(0)),[...ze,...ft].reduce((n,i)=>(t.hasAttribute(`data-${i}`)&&(n[i]=t.getAttribute(`data-${i}`)||void 0),n),e)}function X(t,e){if(typeof e=="object")for(const n in e)n&&(Array.isArray(e[n])?e[n].forEach(i=>{t.style[n]=i}):t.style[n]=e[n])}function pe(t,e){const n=e.getBoundingClientRect();return{x:(t.x||t.left)-(n.x||n.left)-e.scrollLeft,y:(t.y||t.top)-(n.y||n.top)-e.scrollTop,x1:(t.x||t.left)-(n.x||n.left)-e.scrollLeft+t.width,y1:(t.y||t.top)-(n.y||n.top)-e.scrollTop+t.height,width:t.width,height:t.height}}const vT=function(t){t&&t.parentNode&&t.parentNode.removeChild(t)},gc=function(t,e,n){if(!t)throw new TypeError("Array.from requires an array-like object - not null or undefined");let i=t.length,r=[];for(let a=0;a<i;a++)typeof e=="function"?r.push(e.call(n,t[a])):r.push(t[a]);return r},Ec=h.imports["blots/break"],Eu=h.imports["blots/block"],Li=h.imports["blots/container"];class We extends Eu{static create(e){const n=super.create(e);return e.tdBgColor&&(n.setAttribute("data-parent-bg",e.tdBgColor),delete e.tdBgColor),ft.forEach(i=>{const r=i==="row"?yn:Nn;n.setAttribute(`data-${i}`,e[i]||r())}),ze.forEach(i=>{n.setAttribute(`data-${i}`,e[i]||fa[i])}),e.height&&n.setAttribute("height",e.height),n}static formats(e){const n={};return n.list&&(n.list=e.classList.item(0)),fu(e,n)}toggleAttribute(e,n){n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e)}formatChildren(e,n){this.children.forEach(i=>{i.format&&i.format(e,n),i.domNode.style&&(i.domNode.tagName==="SPAN"&&n?i.domNode.style.backgroundColor=n:i.domNode.style.backgroundColor="initial")})}format(e,n){if([...ze,...ft,"parent-bg"].indexOf(e)>-1)n?this.domNode.setAttribute(`data-${e}`,n):this.domNode.removeAttribute(`data-${e}`);else if(e==="header"){if(!n)return;const{row:i,cell:r,rowspan:a,colspan:s}=We.formats(this.domNode);super.format(e,{value:n,row:i,cell:r,rowspan:a,colspan:s})}else super.format(e,n);switch(!0){case e==="cell-bg":this.toggleAttribute("data-cell-bg",n),this.formatChildren(e,n)}}optimize(e){super.optimize(e);const{row:n,cell:i,rowspan:r,colspan:a}=this.domNode.dataset,s=We.formats(this.domNode),o=this.parent.formats();this.statics.requiredContainer&&!(this.parent instanceof this.statics.requiredContainer)?this.wrap(this.statics.requiredContainer.blotName,{row:n,cell:i,rowspan:r,colspan:a}):_u(s,o)||(this.parent.format("row",s.row),this.parent.format("cell",s.cell),this.parent.format("rowspan",s.rowspan),this.parent.format("colspan",s.colspan));const l=this.domNode.getAttribute("height");l&&(this.parent.domNode.style.height=l)}tableCell(){return this.parent}}We.blotName="table-cell-line";We.className="qlbt-cell-line";We.tagName="DIV";class Pe extends Li{static create(e={row:yn()}){const n=super.create(e);return ft.forEach(i=>{n.setAttribute(`data-${i}`,e[i])}),ze.forEach(i=>{e[i]&&n.setAttribute(i,e[i])}),n}static formats(e){const n={height:void 0,row:void 0};return n.height=e.getAttribute("height")||void 0,e.hasAttribute("data-row")&&(n.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(n["cell-bg"]=e.getAttribute("data-cell-bg")||void 0),ze.reduce((i,r)=>(e.hasAttribute(r)&&(i[r]=e.getAttribute(r)),i),n)}checkMerge(){if(super.checkMerge()&&!V(this.next.children.head)){const e=s=>s.formats&&s.formats()[s.statics.blotName]||{cell:s.domNode.getAttribute("data-cell")},n=e(this.children.head),i=e(this.children.tail),r=e(this.next.children.head),a=e(this.next.children.tail);return n.cell===i.cell&&n.cell===r.cell&&n.cell===a.cell}return!1}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell")&&(e.cell=this.domNode.getAttribute("data-cell")),ze.reduce((n,i)=>(this.domNode.hasAttribute(i)&&(n[i]=this.domNode.getAttribute(i)),n),e)}toggleAttribute(e,n){n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e)}formatChildren(e,n){this.children.forEach(i=>{i.format(e,n)})}format(e,n){const i=h.find(this.scroll.domNode.parentNode);switch(!0){case ze.indexOf(e)>-1:this.toggleAttribute(e,n);break;case["row","cell"].indexOf(e)>-1:this.toggleAttribute(`data-${e}`,n);break;case e==="background":{this.domNode.querySelectorAll("div.qlbt-cell-line[data-parent-bg]").forEach(a=>a.removeAttribute("data-parent-bg")),this.domNode.style.background="",this.domNode.style.backgroundColor=n,this.children.head.format("parent-bg",n);break}case e==="size":{const r=i.getIndex(this.children.head),a=i.getIndex(this.children.tail)+this.children.tail.length(),s=a-r>0?a-r:0;i.setSelection(r,s,h.sources.USER),i.format(e,n,h.sources.USER),i.setSelection(r)}case e==="cell-bg":this.toggleAttribute("data-cell-bg",n),this.toggleAttribute("data-parent-bg",n),this.formatChildren(e,n),n?this.domNode.style.backgroundColor=n:this.domNode.style.backgroundColor="initial"}}optimize(e){const n=Array.from(this.domNode.childNodes).find(a=>a.getAttribute("data-parent-bg")),i=n&&n.getAttribute("data-parent-bg");i&&i!==this.domNode.style.backgroundColor&&(this.domNode.style.backgroundColor=i);const r=this.domNode.getAttribute("data-row");this.statics.requiredContainer&&!(this.parent instanceof this.statics.requiredContainer)?this.wrap(this.statics.requiredContainer.blotName,{row:r}):r!==this.parent.formats().row&&this.parent.format("row",r),this.children.forEach(a=>{if(V(a.next))return;const s=this.getFormat(a.domNode),o=this.getFormat(a.next.domNode);if(s.cell!==o.cell){const l=this.splitAfter(a);l&&l.optimize(),this.prev&&this.prev.optimize()}}),super.optimize(e)}getFormat(e){const n={},i=e.childNodes[0];return i&&e.tagName==="OL"&&(n.list=i.classList.item(0)),fu(e,n)}row(){return this.parent}rowOffset(){return this.row()?-1:this.row().rowOffset()}table(){return this.row()&&this.row().table()}}Pe.blotName="table";Pe.tagName="TD";class xt extends Li{static create(e){const n=super.create(e);return e.row&&n.setAttribute("data-row",e.row),n}checkMerge(){if(super.checkMerge()&&!V(this.next.children.head)){const e=this.children.head.formats(),n=this.children.tail.formats(),i=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===n.row&&e.row===i.row&&e.row===r.row}return!1}formats(){return["row"].reduce((e,n)=>(this.domNode.hasAttribute(`data-${n}`)&&(e[n]=this.domNode.getAttribute(`data-${n}`)),e),{})}format(e,n){this.domNode.setAttribute(`data-${e}`,n)}optimize(e){this.statics.requiredContainer&&!(this.parent instanceof this.statics.requiredContainer)&&this.wrap(this.statics.requiredContainer.blotName),this.children.forEach(n=>{if(V(n.next))return;const i=n.formats(),r=n.next.formats();if(i.row!==r.row){const a=this.splitAfter(n);a&&a.optimize(),this.prev&&this.prev.optimize()}}),super.optimize(e)}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}xt.blotName="table-row";xt.tagName="TR";class St extends Li{}St.blotName="table-body";St.tagName="TBODY";class On extends Eu{static create(e){const n=super.create(e);return us.forEach(i=>{n.setAttribute(`${i}`,e[i]||Sr[i])}),n}static formats(e){return us.reduce((n,i)=>(e.hasAttribute(`${i}`)&&(n[i]=e.getAttribute(`${i}`)||void 0),n),{})}format(e,n){us.indexOf(e)>-1?this.domNode.setAttribute(`${e}`,n||Sr[e]):super.format(e,n)}html(){return this.domNode.outerHTML}}On.blotName="table-col";On.tagName="col";class Ln extends Li{optimize(e){if(super.optimize(e),this.parent&&this.statics.requiredContainer&&this.parent instanceof this.statics.requiredContainer&&this.parent.updateTableWidth(),this.parent.parent.domNode.className==="quill-better-table-wrapper"&&this.parent.parent.domNode.tagName==="DIV"&&this.parent.domNode.children.length>=2&&this.parent.domNode.children[0].tagName==="COLGROUP"&&this.parent.domNode.children[1].tagName==="TBODY"){let n="",i=0,r=0;for(let s=0;s<this.parent.domNode.children.length;s++)this.parent.domNode.children[s].tagName==="TBODY"?(n===""&&(n=this.parent.domNode.children[s].children[0].getAttribute("data-row")),i=this.findTdColspanInTbody(this.parent.domNode.children[s],n)):this.parent.domNode.children[s].tagName==="COLGROUP"&&(r=this.parent.domNode.children[s].children.length);let a=this.parent.domNode.nextElementSibling;for(;a&&a.tagName==="TABLE";){for(let s=0;s<a.children.length;s++)a.children[s].tagName==="TBODY"&&(i+=this.findTdColspanInTbody(a.children[s],n));a=a.nextElementSibling}if(r<i){let s=i-r;for(let o=0;o<s;o++){let l=document.createElement("col");l.width=this.parent.domNode.children[0].children[this.parent.domNode.children[0].children.length-1].width;let c=document.createElement("br");l.appendChild(c),this.parent.domNode.children[0].appendChild(l),this.parent.domNode.style.width+=l.width}}}}findTdColspanInTbody(e,n){let i=0;for(let r=0;r<e.children.length;r++){if(e.children[r].getAttribute("data-row")!==n)return i;for(let a=0;a<e.children[r].children.length;a++)e.children[r].children[a].colSpan&&(i+=e.children[r].children[a].colSpan)}return i}}Ln.blotName="table-col-group";Ln.tagName="colgroup";class sn extends Li{constructor(e,n){super(e,n),n.setAttribute("contenteditable",!1),this.updateTableWidth()}static create(){return super.create()}updateTableWidth(){let e=this.colGroup();if(!e)if(this.parent&&this.parent.children.head&&this.domNode.hasAttribute("style"))e=this.parent.children.head.children.head,this.domNode=this.parent.children.head.domNode;else return this.domNode.tagName==="TABLE",void 0;const n=e.children.reduce((i,r)=>{const a=r.formats()[On.blotName];let s=Sr.width;return a&&a.width&&(s=parseInt(a.width,10)),i=i+s,i},0);this.domNode.removeAttribute("style"),this.domNode.style.width=`${n}px`,e.next&&setTimeout(()=>{let i=0,r;const a=e.children.length,s=this.descendants(xt);for(let o=0;o<s.length;o++){const l=s[o].domNode.querySelectorAll("td");if(l.length===a){r=l;break}}e.children.forEach(o=>{if(r&&o.domNode.width==="auto"){const l=getComputedStyle(r[i]).width,c=parseInt(l,10);o.domNode.width=c<Sr.width&&Sr.width||c}i++})})}cells(e){return this.rows().map(n=>n.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,n=[],i){const[r]=this.descendants(St);if(V(r)||V(r.children.head))return;const a=this.descendants(Pe),s=[],o=[];if(a.forEach(l=>{const c=pe(l.domNode.getBoundingClientRect(),i);c.x+H>e.x&&c.x1-H<e.x1?s.push(l):c.x<e.x+H&&c.x1>e.x1-H&&o.push(l)}),s.length===a.length)return this.tableDestroy(),!0;n.forEach(()=>{let l=this.colGroup().children.at(n[0]);!l||this.colGroup().children.at(n[0]).domNode!==this.colGroup().domNode.children[n[0]]?this.colGroup().domNode.removeChild(this.colGroup().domNode.children[n[0]]):l.remove()}),s.forEach(l=>{l.remove()}),o.forEach(l=>{const c=parseInt(l.formats().colspan,10);l.format("colspan",c-n.length)}),this.updateTableWidth()}deleteRow(e,n){const[i]=this.descendants(St);if(V(i)||V(i.children.head))return;const r=this.descendants(Pe),a=this.descendants(xt),s=[],o=[],l=[];if(r.forEach(d=>{const p=pe(d.domNode.getBoundingClientRect(),n);p.y>e.y-H&&p.y1<e.y1+H?s.push(d):p.y<e.y+H&&p.y1>e.y1-H&&(o.push(d),Math.abs(p.y-e.y)<H&&l.push(d))}),s.length===r.length){this.tableDestroy();return}const c=this.rows().reduce((d,p)=>{const _=pe(p.domNode.getBoundingClientRect(),n);return _.y>e.y-H&&_.y1<e.y1+H&&(d+=1),d},0);l.forEach(d=>{const p=pe(d.domNode.getBoundingClientRect(),n),_=d.parent.next,g=_.children.reduce((S,b)=>{const C=pe(b.domNode.getBoundingClientRect(),n);return p.x1-C.x<H&&(S=b),S},null);_.insertBefore(d,g);const f=_.formats().row;d.format("row",f),d.children.forEach(S=>{S.format("row",f)})}),o.forEach(d=>{const _=parseInt(d.formats().rowspan,10)-c;d.domNode.removeAttribute("style"),d.format("rowspan",_),d.children.forEach(m=>{m.format("rowspan",_)})}),s.forEach(d=>{d.remove()}),a.forEach(d=>{d.children.length===0&&d.remove()})}tableDestroy(){const e=h.find(this.scroll.domNode.parentNode),n=e.getModule("better-table");this.remove(),n.hideTableTools(),e.update(h.sources.USER)}insertCell(e,n,i=""){const r=Nn(),a=e.formats().row,s=this.scroll.create(Pe.blotName,{...fa,row:a});s.domNode.style.backgroundColor=i;const o=this.scroll.create(We.blotName,{row:a,cell:r});s.appendChild(o),n?e.insertBefore(s,n):e.appendChild(s)}insertColumn(e,n,i=!0,r){const[a]=this.descendants(St),[s]=this.descendants(Ln),o=this.descendants(On),l=[],c=[],d=[];if(V(a)||V(a.children.head))return;this.descendants(Pe).forEach(g=>{const f=pe(g.domNode.getBoundingClientRect(),r);i?Math.abs(f.x1-e.x1)<H?l.push(g):e.x1-f.x>H&&e.x1-f.x1<-H&&c.push(g):Math.abs(f.x-e.x)<H?l.push(g):e.x-f.x>H&&e.x-f.x1<-H&&c.push(g)}),l.forEach(g=>{const f=i?g.next:g,S=Nn(),b=g.parent,C=b.formats().row,A=g.formats(),R=this.scroll.create(Pe.blotName,{...fa,row:C,rowspan:A.rowspan}),v=this.scroll.create(We.blotName,{row:C,cell:S,rowspan:A.rowspan});R.appendChild(v),f?b.insertBefore(R,f):b.appendChild(R),d.push(R)});const _=this.scroll.create(On.blotName,!0);let m;return i?m=o[n]&&o[n].next:m=o[n],m?s.insertBefore(_,m):s.appendChild(_),c.forEach(g=>{const f=g.formats().colspan;g.format("colspan",parseInt(f,10)+1),d.push(g)}),d.sort((g,f)=>{const S=g.domNode.getBoundingClientRect().y,b=f.domNode.getBoundingClientRect().y;return S-b}),this.updateTableWidth(),d}insertRow(e,n,i){const[r]=this.descendants(St);if(V(r)||V(r.children.head))return;const a=this.descendants(Pe),s=yn(),o=this.scroll.create(xt.blotName,{row:s}),l=[],c=[],d=[];a.forEach(m=>{const g=pe(m.domNode.getBoundingClientRect(),i);n?Math.abs(g.y1-e.y1)<H?l.push(m):e.y1-g.y>H&&e.y1-g.y1<-H&&c.push(m):Math.abs(g.y-e.y)<H?l.push(m):e.y-g.y>H&&e.y-g.y1<-H&&c.push(m)});const p=(m,g)=>{const f=m.domNode.getBoundingClientRect().x,S=g.domNode.getBoundingClientRect().x;return f-S};l.sort(p),l.forEach(m=>{const g=Nn(),f=m.formats(),S=this.scroll.create(Pe.blotName,{...fa,row:s,cell:g,colspan:f.colspan}),b=this.scroll.create(We.blotName,{row:s,cell:g,colspan:f.colspan}),C=this.scroll.create(Ec.blotName);b.appendChild(C),S.appendChild(b),o.appendChild(S),d.push(S)}),c.forEach(m=>{const g=parseInt(m.formats().rowspan,10);m.format("rowspan",g+1),d.push(m)});const _=this.rows().find(m=>{const g=pe(m.domNode.getBoundingClientRect(),i);return n?Math.abs(g.y-e.y-e.height)<H:Math.abs(g.y-e.y)<H});return r.insertBefore(o,_),d.sort(p),d}mergeCells(e,n,i,r,a){const s=n.reduce((c,d,p)=>{if(p!==0)c&&d.moveChildren(c),d.remove();else if(d.format("colspan",r),d.format("rowspan",i),c=d,i>1){const _=Sa*i+i-1;(parseInt(d.domNode.style.height,10)||0)<_&&(d.domNode.style.height=`${_}px`)}return c},null),o=s.domNode.getAttribute("data-row"),l=s.children.head.domNode.getAttribute("data-cell");return s.children.forEach(c=>{c.domNode.setAttribute("data-parent-bg",s.domNode.style.backgroundColor),c.children.head.domNode.style&&(c.children.head.domNode.style.backgroundColor=s.domNode.style.backgroundColor),!c.prev||c.domNode.innerText.trim()?(c.format("cell",l),c.format("row",o),c.format("colspan",r),c.format("rowspan",i)):c.remove()}),s}unmergeCells(e,n){let i={},r=1,a=1;e.forEach(s=>{const o=s.domNode.style.backgroundColor;if(i=s.formats(),r=i.rowspan,a=i.colspan,a>1){const l=s.next,c=s.row();s.format("colspan",1),s.domNode.children&&s.domNode.children[0].tagName==="DIV"&&s.domNode.children[0].getAttribute("data-colspan")&&s.domNode.children[0].setAttribute("data-colspan",1);for(let d=a;d>1;d--)this.insertCell(c,l,o)}if(r>1){let l=r,c=s.row().next;for(;l>1;){const d=c.children.reduce((p,_)=>{const m=pe(s.domNode.getBoundingClientRect(),n),g=pe(_.domNode.getBoundingClientRect(),n);return Math.abs(m.x1-g.x)<H&&(p=_),p},null);for(let p=a;p>0;p--)this.insertCell(c,d,o);l-=1,c=c.next}s.domNode.removeAttribute("style"),s.domNode.children&&s.domNode.children[0].tagName==="DIV"&&s.domNode.children[0].getAttribute("data-rowspan")&&s.domNode.children[0].setAttribute("data-rowspan",1),s.format("rowspan",1)}})}emptyCells(e){e.forEach(n=>{const i=n.formats(),r=this.scroll.create(We.blotName,{row:i.row||yn(),cell:i.cell||Nn(),rowspan:i.rowspan,colspan:i.colspan}),a=this.scroll.create(Ec.blotName);r.appendChild(a),n.domNode.innerHTML="",n.appendChild(r)})}rows(){const e=this.children.tail;return V(e)?[]:e.children.map(n=>n)}}sn.blotName="ql-table-container";sn.className="quill-better-table";sn.tagName="TABLE";class ni extends Li{constructor(e,n){super(e,n);const i=h.find(e.domNode.parentNode);i.options.readOnly&&(n.style.overflow="auto"),n.addEventListener("scroll",r=>{const a=i.getModule("better-table");a.columnTool&&(a.columnTool.domNode.scrollLeft=r.target.scrollLeft),a.tableSelection&&a.tableSelection.selectedTds.length>0&&a.tableSelection.repositionHelpLines()},!1)}}ni.blotName="table-view";ni.className="quill-better-table-wrapper";ni.tagName="DIV";ni.allowedChildren=[sn];sn.requiredContainer=ni;sn.allowedChildren=[St,Ln];St.requiredContainer=sn;St.allowedChildren=[xt];xt.requiredContainer=St;xt.allowedChildren=[Pe];Pe.requiredContainer=xt;Pe.allowedChildren=[We,Rn,nn,tn];We.requiredContainer=Pe;Ln.allowedChildren=[On];Ln.requiredContainer=sn;On.requiredContainer=Ln;function yn(){return`row-${Math.random().toString(36).slice(2,6)}`}function Nn(){return`cell-${Math.random().toString(36).slice(2,6)}`}function fu(t,e){return ze.concat(ft).reduce((n,i)=>(t.hasAttribute(`data-${i}`)&&(n[i]=t.getAttribute(`data-${i}`)||void 0),n),e)}class yT{constructor(e,n,i){if(!e)return null;this.table=e,this.quill=n,this.modulesContainer=i,this.domNode=null,this.oldRootScrollTop=this.quill.root.scrollTop,this.initColTool(),this.quill.root===this.quill.scrollingContainer&&this.quill.root.addEventListener("scroll",this.handleQuillRootScroll.bind(this))}handleQuillRootScroll(){this.domNode&&(this.domNode.style.marginTop=`${this.oldRootScrollTop-this.quill.root.scrollTop}px`)}initColTool(){const e=this.quill.root.parentNode,n=e.getBoundingClientRect(),i=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-table-control-panel"),this.columnCtrlPanel=document.createElement("div"),this.columnCtrlPanel.classList.add("qlbt-column-control-panel"),this.domNode.appendChild(this.columnCtrlPanel),this.leftMask=document.createElement("div"),this.leftMask.classList.add("qlbt-left-mask"),X(this.leftMask,{height:`${i.height+50}px`}),this.domNode.appendChild(this.leftMask),this.rowCtrlPanel=document.createElement("div"),this.rowCtrlPanel.classList.add("qlbt-row-control-panel"),this.domNode.appendChild(this.rowCtrlPanel),this.updateRowToolCells(),this.updateColToolCells(),this.modulesContainer.appendChild(this.domNode),X(this.domNode,{width:"100%",height:`${ps}px`,left:"0px",top:`${i.top-n.top+e.scrollTop-25}px`})}createToolCell(e){window.quillIsIntable=!0;const n=document.createElement("div"),i=document.createElement("div"),r=document.createElement("div");return e?(n.classList.add("qlbt-row-tool-cell"),i.classList.add("qlbt-row-tool-cell-selector"),r.classList.add("qlbt-row-tool-cell-holder"),X(n,{width:`${pc}px`})):(n.classList.add("qlbt-col-tool-cell"),i.classList.add("qlbt-col-tool-cell-selector"),r.classList.add("qlbt-col-tool-cell-holder"),X(n,{height:`${ps}px`})),n.appendChild(i),n.appendChild(r),n}updateColToolCells(){const e=h.find(this.table);if(!e)return;const n=e.colGroup().children,i=Math.max(Array.from(n).length,e.colGroup().domNode.children.length),r=Array.from(this.columnCtrlPanel.querySelectorAll(".qlbt-col-tool-cell")),a=Math.max(r.length,i);for(let s=0;s<a;s++){let o=n.at(s),l=0;!o||o.domNode!==e.colGroup().domNode.children[s]?(o=e.colGroup().domNode.children[s],l=o?o.width:e.colGroup().domNode.children[s-1].width):l=parseInt(o.formats()[o.statics.blotName].width,10);let c=null;r[s]?r[s]&&s>=i?r[s].remove():(c=r[s],X(c,{"min-width":`${l}px`})):(c=this.createToolCell(!1),this.columnCtrlPanel.appendChild(c),this.addColCellSelectHandler(c),this.addColCellHolderHandler(c),X(c,{"min-width":`${l}px`}))}}updateRowToolCells(){const e=h.find(this.table);if(!e)return;let n=Array.from(e.domNode.querySelectorAll("tr"));n=n.filter(a=>a.children.length);const i=Array.from(this.rowCtrlPanel.querySelectorAll(".qlbt-row-tool-cell")),r=Math.max(i.length,n.length);for(let a=0;a<r;a++){const s=n[a];let o=s&&getComputedStyle(s).height;o==="auto"&&(o=s.querySelector("td").style.height||"30px");let l=s&&parseFloat(o);l<Sa&&(l=s&&s.childNodes[0]&&parseFloat(getComputedStyle(s.childNodes[0]).height));let c=null;i[a]?i[a]&&a>=n.length?i[a].remove():(c=i[a],X(c,{height:`${l}px`})):(c=this.createToolCell(!0),this.rowCtrlPanel.appendChild(c),this.addRowCellSelectHandler(c),this.addRowCellHolderHandler(c),X(c,{height:`${l}px`}))}}destroy(){return window.quillIsIntable=!1,this.domNode.remove(),null}addRowCellSelectHandler(e){const n=e.querySelector(".qlbt-row-tool-cell-selector"),i=r=>{r.preventDefault();const a=r.target.parentNode,s=a.getBoundingClientRect(),o=this.quill.root.parentNode.getBoundingClientRect(),l=this.table.getBoundingClientRect(),c=this.quill.getModule("better-table").tableSelection;c.boundary={x:l.left-o.left,x1:l.left-o.left+l.width-2,y:s.top-o.top,y1:s.top-o.top+s.height-1,width:l.width-2,height:s.height-1},c.selectedTds=c.computeSelectedTds(),c.repositionHelpLines(),a.classList.add("qlbt-tool-cell-on"),this.activeToolCell=a};n.addEventListener("click",i,!1)}addRowCellHolderHandler(e){const n=e.querySelector(".qlbt-row-tool-cell-holder");let i=!1,r=0,a=0,s=0,o=0,l={},c={},d=null;const p=g=>{g.preventDefault(),i&&(a=g.clientY,o+a-r>=Sa?s=a-r:s=Sa-o,X(d,{top:`${c.top+c.height+s}px`}))},_=g=>{g.preventDefault();const S=Array.from(this.domNode.querySelectorAll(".qlbt-row-tool-cell")).indexOf(e),b=Array.from(this.table.querySelectorAll("tr")),C=Array.from(b[S].childNodes),A=C.find(D=>D.getAttribute("rowspan")==="1"&&D.innerText!==`
326
+ `}render(e){const n=document.createElement("div");[].forEach.call(e,(i,r)=>{const a=document.createElement("li");a.classList.add(this.options.itemClass),r===this.activeMentionIndex&&a.classList.add(this.options.itemActiveClass);const s=this.options.renderMentionItem(i);a.insertAdjacentElement("afterbegin",s),n.appendChild(a)}),this.mentionListEL.innerHTML=n.innerHTML}highlightMentionItem(e){const n=this.getActiveMentionItem();n&&n.classList.remove(this.options.itemActiveClass);const i=this.mentionListEL.querySelector(`.${this.options.itemClass}:nth-of-type(${e+1})`);i&&(i.classList.add(this.options.itemActiveClass),this.scrollIntoView(i))}scrollIntoView(e){const n=e;if(n.scrollIntoViewIfNeeded){n.scrollIntoViewIfNeeded(!1);return}if(e.scrollIntoView){e.scrollIntoView(!1);return}}selectMentionItem(e=this.activeMentionIndex,n){const i=this.latestMentionList[e];this.insertMentionBlot(i,n),this.options.select(i),this.hideMentionList()}insertMentionBlot(e,n){const i=this.options.renderMentionText(e),r=new uc().retain(this.latestMentionCharPos).delete(this.latestCaretPos-this.latestMentionCharPos).insert({[Dr.blotName]:{char:this.options.mentionChar,text:i,mention:e,link:this.options.defaultLink,target:this.options.target,searchKey:this.options.searchKey}});n?this.quill.updateContents(r,h.sources.USER):this.quill.updateContents(r,h.sources.API),this.quill.setSelection(this.latestMentionCharPos+1,h.sources.API)}}const gT=h.imports["blots/embed"];class Ha extends gT{static create(){return super.create()}optimize(){this.prev===null&&this.remove()}length(){return 1}}Ha.blotName="soft-break";Ha.tagName="BR";Ha.className="ql-soft-break";const ET=h.imports["blots/inline"];class Va extends ET{}Va.blotName="strike";Va.tagName="u";Va.className="ql-custom-strike";const fT="qlrte__op-menu-item",ST="qlrte__op-menu-dividing",hT="qlrte__op-menu-subtitle",bT="qlrte__op-menu-color-picker",_c="qlrte__op-menu-color-picker-item",us=["width"],Sr={width:100},ft=["row","cell"],ze=["rowspan","colspan"],fa={rowspan:1,colspan:1},H=5,_s=32,pc=16,ps=16,Js=50,Sa=29,eo=["#5170ff","var(--brand-1, #5170ff)"],TT=40,mc=150,CT=205,na=["left","right","top","bottom"],NT=h.imports["blots/block"];class Rn extends NT{static create(e){typeof e=="string"&&(e={value:e});const n=super.create(e.value);return ft.forEach(i=>{e[i]&&n.setAttribute(`data-${i}`,e[i])}),ze.forEach(i=>{e[i]&&n.setAttribute(`data-${i}`,e[i])}),n}static formats(e){const n={};return n.value=this.tagName.indexOf(e.tagName)+1,ze.concat(ft).reduce((i,r)=>(e.hasAttribute(`data-${r}`)&&(i[r]=e.getAttribute(`data-${r}`)||void 0),i),n)}format(e,n){Object.prototype.toString.call(n)==="[object Object]"&&(n=n.value);const i=Rn.formats(this.domNode),{row:r,cell:a,rowspan:s,colspan:o}=i;e===Rn.blotName?n?super.format(e,{value:n,row:r,cell:a,rowspan:s,colspan:o}):r?this.replaceWith("table-cell-line",{row:r,cell:a,rowspan:s,colspan:o}):super.format(e,n):super.format(e,n)}optimize(e){const{row:n,cell:i,rowspan:r,colspan:a}=Rn.formats(this.domNode);if(n&&this.parent.statics.blotName!=="table"&&this.wrap("table",{row:n,cell:i,colspan:a,rowspan:r}),this.enforceAllowedChildren(),!V(this.uiNode)&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length===0)if(V(this.statics.defaultChild))this.remove();else{const s=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(s)}this.cache={}}}Rn.blotName="header";Rn.tagName=["H1","H2","H3","H4","H5","H6"];const AT=h.imports["blots/block"],RT=h.imports["blots/container"];class tn extends RT{format(e,n){const{row:i,cell:r,rowspan:a,colspan:s}=this.domNode.dataset;e===tn.blotName&&(n?super.format(e,{row:i,cell:r,rowspan:a,colspan:s}):i&&this.replaceWith("table-cell-line",{row:i,cell:r,rowspan:a,colspan:s}))}}tn.blotName="list-container";tn.tagName="OL";class nn extends AT{constructor(e,n){super(e,n);const i=h.find(e.domNode.parentNode),r=i.getSelection();if(r){const[o]=i.getLine(r.index),l=o.domNode.closest("td");l&&[...ft,...ze].forEach(c=>l.dataset[c]&&n.setAttribute(`data-${c}`,l.dataset[c]))}const a=n.ownerDocument.createElement("span"),s=o=>{if(!e.isEnabled())return;const{value:l}=this.statics.formats(n,e);l==="checked"?(this.format("list","unchecked"),o.preventDefault()):l==="unchecked"&&(this.format("list","checked"),o.preventDefault())};a.addEventListener("mousedown",s),a.addEventListener("touchstart",s),this.attachUI(a)}static create(e){const n=super.create();return typeof e=="string"?e={value:e}:[...ft,...ze].forEach(i=>{e[i]&&(n.dataset[i]=e[i])}),n.classList.add(e.value),n}static formats(e){const n={};return n.value=e.classList.item(0)||void 0,[...ze,...ft].reduce((i,r)=>(e.dataset[r]&&(i[r]=e.dataset[r]),i),n)}static register(){h.register({"formats/list-container":tn},!0)}format(e,n){if(e!==nn.blotName){super.format(e,n);return}const i=n&&typeof n=="object"?n.value:n,r=this.domNode.classList[0],a=this.domNode.closest(".editing-select-able"),s=a&&h.find(a),o=this.domNode.querySelectorAll("img[data-image-id]");if(!i||i===r)if(o&&o.length&&o.forEach(l=>{l.style.verticalAlign="baseLine"}),s&&s.statics.blotName==="table"){const l=s.formats();this.replaceWith("table-cell-line",l),this.parent.statics.blotName===tn.blotName&&this.parent.unwrap()}else super.format(e,n);else r?this.domNode.className=this.domNode.className.replace(r,i):this.domNode.classList.add(i)}optimize(e){const n=this.prev&&this.prev.domNode.lastChild;if(n&&n.className&&n.className.indexOf("ql-soft-break")>=0){this.domNode.childNodes.forEach((o,l)=>{l>0&&this.prev.domNode.appendChild(o)}),this.remove();return}super.optimize(e);const i=OT(this.parent.domNode),r=nn.formats(this.domNode),a=this.domNode.dataset||[],s=this.domNode.querySelectorAll("img[data-image-id]");if(i.list!==r.value){const o=this.parent.domNode.classList[0];o?this.parent.domNode.className=this.parent.domNode.className.replace(o,r.value):this.parent.domNode.classList.add(r.value)}a.cell&&!i.cell&&([...ft,...ze].forEach(o=>(r[o]||a[o])&&this.parent.domNode.setAttribute(`data-${o}`,r[o]||a[o])),this.parent.parent.statics.blotName!=="table"&&(delete r.list,this.wrap("table",r))),s&&s.forEach(o=>{o.style.verticalAlign="top"})}}nn.blotName="list";nn.tagName="LI";tn.allowedChildren=[nn];nn.requiredContainer=tn;function OT(t){const e={};return t.tagName==="OL"&&(e.list=t.classList.item(0)),[...ze,...ft].reduce((n,i)=>(t.hasAttribute(`data-${i}`)&&(n[i]=t.getAttribute(`data-${i}`)||void 0),n),e)}function X(t,e){if(typeof e=="object")for(const n in e)n&&(Array.isArray(e[n])?e[n].forEach(i=>{t.style[n]=i}):t.style[n]=e[n])}function pe(t,e){const n=e.getBoundingClientRect();return{x:(t.x||t.left)-(n.x||n.left)-e.scrollLeft,y:(t.y||t.top)-(n.y||n.top)-e.scrollTop,x1:(t.x||t.left)-(n.x||n.left)-e.scrollLeft+t.width,y1:(t.y||t.top)-(n.y||n.top)-e.scrollTop+t.height,width:t.width,height:t.height}}const vT=function(t){t&&t.parentNode&&t.parentNode.removeChild(t)},gc=function(t,e,n){if(!t)throw new TypeError("Array.from requires an array-like object - not null or undefined");let i=t.length,r=[];for(let a=0;a<i;a++)typeof e=="function"?r.push(e.call(n,t[a])):r.push(t[a]);return r},Ec=h.imports["blots/break"],Eu=h.imports["blots/block"],Li=h.imports["blots/container"];class We extends Eu{static create(e){const n=super.create(e);return e.tdBgColor&&(n.setAttribute("data-parent-bg",e.tdBgColor),delete e.tdBgColor),ft.forEach(i=>{const r=i==="row"?yn:Nn;n.setAttribute(`data-${i}`,e[i]||r())}),[...ze,"cell-bg"].forEach(i=>{const r=e[i]||fa[i];r&&n.setAttribute(`data-${i}`,r)}),e.height&&n.setAttribute("height",e.height),n}static formats(e){const n={};return n.list&&(n.list=e.classList.item(0)),fu(e,n,["cell-bg"])}toggleAttribute(e,n){n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e)}formatChildren(e,n){this.children.forEach(i=>{i.format&&i.format(e,n),i.domNode.style&&(i.domNode.tagName==="SPAN"&&n?i.domNode.style.backgroundColor=n:i.domNode.style.backgroundColor="initial")})}format(e,n){if([...ze,...ft,"parent-bg"].indexOf(e)>-1)n?this.domNode.setAttribute(`data-${e}`,n):this.domNode.removeAttribute(`data-${e}`);else if(e==="header"){if(!n)return;const{row:i,cell:r,rowspan:a,colspan:s}=We.formats(this.domNode);super.format(e,{value:n,row:i,cell:r,rowspan:a,colspan:s})}else super.format(e,n);switch(!0){case e==="cell-bg":this.toggleAttribute("data-cell-bg",n)}}optimize(e){super.optimize(e);const{row:n,cell:i,rowspan:r,colspan:a,cellBg:s}=this.domNode.dataset,o=We.formats(this.domNode),l=this.parent.formats();this.statics.requiredContainer&&!(this.parent instanceof this.statics.requiredContainer)?this.wrap(this.statics.requiredContainer.blotName,{row:n,cell:i,rowspan:r,colspan:a,cellBg:s}):_u(o,l)||(this.parent.format("row",o.row),this.parent.format("cell",o.cell),this.parent.format("rowspan",o.rowspan),this.parent.format("colspan",o.colspan),o["cell-bg"]&&this.parent.setCellBg(o["cell-bg"]));const c=this.domNode.getAttribute("height");c&&(this.parent.domNode.style.height=c)}tableCell(){return this.parent}}We.blotName="table-cell-line";We.className="qlbt-cell-line";We.tagName="DIV";class Pe extends Li{static create(e={row:yn()}){const n=super.create(e);return ft.forEach(i=>{n.setAttribute(`data-${i}`,e[i])}),ze.forEach(i=>{e[i]&&n.setAttribute(i,e[i])}),n}static formats(e){const n={height:void 0,row:void 0};return n.height=e.getAttribute("height")||void 0,e.hasAttribute("data-row")&&(n.row=e.getAttribute("data-row")),e.hasAttribute("data-cell-bg")&&(n["cell-bg"]=e.getAttribute("data-cell-bg")||void 0),ze.reduce((i,r)=>(e.hasAttribute(r)&&(i[r]=e.getAttribute(r)),i),n)}checkMerge(){if(super.checkMerge()&&!V(this.next.children.head)){const e=s=>s.formats&&s.formats()[s.statics.blotName]||{cell:s.domNode.getAttribute("data-cell")},n=e(this.children.head),i=e(this.children.tail),r=e(this.next.children.head),a=e(this.next.children.tail);return n.cell===i.cell&&n.cell===r.cell&&n.cell===a.cell}return!1}cellOffset(){return this.parent?this.parent.children.indexOf(this):-1}formats(){const e={};return this.domNode.hasAttribute("data-row")&&(e.row=this.domNode.getAttribute("data-row")),this.domNode.hasAttribute("data-cell")&&(e.cell=this.domNode.getAttribute("data-cell")),ze.reduce((n,i)=>(this.domNode.hasAttribute(i)&&(n[i]=this.domNode.getAttribute(i)),n),e)}toggleAttribute(e,n){n?this.domNode.setAttribute(e,n):this.domNode.removeAttribute(e)}formatChildren(e,n){this.children.forEach(i=>{i.format(e,n)})}setCellBg(e){e?this.domNode.style.backgroundColor=e:this.domNode.style.backgroundColor="initial"}format(e,n){const i=h.find(this.scroll.domNode.parentNode);switch(!0){case ze.indexOf(e)>-1:this.toggleAttribute(e,n);break;case["row","cell"].indexOf(e)>-1:this.toggleAttribute(`data-${e}`,n);break;case e==="background":{this.domNode.querySelectorAll("div.qlbt-cell-line[data-parent-bg]").forEach(a=>a.removeAttribute("data-parent-bg")),this.domNode.style.background="",this.domNode.style.backgroundColor=n,this.children.head.format("parent-bg",n);break}case e==="size":{const r=i.getIndex(this.children.head),a=i.getIndex(this.children.tail)+this.children.tail.length(),s=a-r>0?a-r:0;i.setSelection(r,s,h.sources.USER),i.format(e,n,h.sources.USER),i.setSelection(r)}case e==="cell-bg":this.toggleAttribute("data-cell-bg",n),this.toggleAttribute("data-parent-bg",n),this.formatChildren(e,n),this.setCellBg(n)}}optimize(e){const n=Array.from(this.domNode.childNodes).find(a=>a.getAttribute("data-parent-bg")),i=n&&n.getAttribute("data-parent-bg");i&&i!==this.domNode.style.backgroundColor&&(this.domNode.style.backgroundColor=i);const r=this.domNode.getAttribute("data-row");this.statics.requiredContainer&&!(this.parent instanceof this.statics.requiredContainer)?this.wrap(this.statics.requiredContainer.blotName,{row:r}):r!==this.parent.formats().row&&this.parent.format("row",r),this.children.forEach(a=>{if(V(a.next))return;const s=this.getFormat(a.domNode),o=this.getFormat(a.next.domNode);if(s.cell!==o.cell){const l=this.splitAfter(a);l&&l.optimize(),this.prev&&this.prev.optimize()}}),super.optimize(e)}getFormat(e){const n={},i=e.childNodes[0];return i&&e.tagName==="OL"&&(n.list=i.classList.item(0)),fu(e,n)}row(){return this.parent}rowOffset(){return this.row()?-1:this.row().rowOffset()}table(){return this.row()&&this.row().table()}}Pe.blotName="table";Pe.tagName="TD";class xt extends Li{static create(e){const n=super.create(e);return e.row&&n.setAttribute("data-row",e.row),n}checkMerge(){if(super.checkMerge()&&!V(this.next.children.head)){const e=this.children.head.formats(),n=this.children.tail.formats(),i=this.next.children.head.formats(),r=this.next.children.tail.formats();return e.row===n.row&&e.row===i.row&&e.row===r.row}return!1}formats(){return["row"].reduce((e,n)=>(this.domNode.hasAttribute(`data-${n}`)&&(e[n]=this.domNode.getAttribute(`data-${n}`)),e),{})}format(e,n){this.domNode.setAttribute(`data-${e}`,n)}optimize(e){this.statics.requiredContainer&&!(this.parent instanceof this.statics.requiredContainer)&&this.wrap(this.statics.requiredContainer.blotName),this.children.forEach(n=>{if(V(n.next))return;const i=n.formats(),r=n.next.formats();if(i.row!==r.row){const a=this.splitAfter(n);a&&a.optimize(),this.prev&&this.prev.optimize()}}),super.optimize(e)}rowOffset(){return this.parent?this.parent.children.indexOf(this):-1}table(){return this.parent&&this.parent.parent}}xt.blotName="table-row";xt.tagName="TR";class St extends Li{}St.blotName="table-body";St.tagName="TBODY";class On extends Eu{static create(e){const n=super.create(e);return us.forEach(i=>{n.setAttribute(`${i}`,e[i]||Sr[i])}),n}static formats(e){return us.reduce((n,i)=>(e.hasAttribute(`${i}`)&&(n[i]=e.getAttribute(`${i}`)||void 0),n),{})}format(e,n){us.indexOf(e)>-1?this.domNode.setAttribute(`${e}`,n||Sr[e]):super.format(e,n)}html(){return this.domNode.outerHTML}}On.blotName="table-col";On.tagName="col";class Ln extends Li{optimize(e){if(super.optimize(e),this.parent&&this.statics.requiredContainer&&this.parent instanceof this.statics.requiredContainer&&this.parent.updateTableWidth(),this.parent.parent.domNode.className==="quill-better-table-wrapper"&&this.parent.parent.domNode.tagName==="DIV"&&this.parent.domNode.children.length>=2&&this.parent.domNode.children[0].tagName==="COLGROUP"&&this.parent.domNode.children[1].tagName==="TBODY"){let n="",i=0,r=0;for(let s=0;s<this.parent.domNode.children.length;s++)this.parent.domNode.children[s].tagName==="TBODY"?(n===""&&(n=this.parent.domNode.children[s].children[0].getAttribute("data-row")),i=this.findTdColspanInTbody(this.parent.domNode.children[s],n)):this.parent.domNode.children[s].tagName==="COLGROUP"&&(r=this.parent.domNode.children[s].children.length);let a=this.parent.domNode.nextElementSibling;for(;a&&a.tagName==="TABLE";){for(let s=0;s<a.children.length;s++)a.children[s].tagName==="TBODY"&&(i+=this.findTdColspanInTbody(a.children[s],n));a=a.nextElementSibling}if(r<i){let s=i-r;for(let o=0;o<s;o++){let l=document.createElement("col");l.width=this.parent.domNode.children[0].children[this.parent.domNode.children[0].children.length-1].width;let c=document.createElement("br");l.appendChild(c),this.parent.domNode.children[0].appendChild(l),this.parent.domNode.style.width+=l.width}}}}findTdColspanInTbody(e,n){let i=0;for(let r=0;r<e.children.length;r++){if(e.children[r].getAttribute("data-row")!==n)return i;for(let a=0;a<e.children[r].children.length;a++)e.children[r].children[a].colSpan&&(i+=e.children[r].children[a].colSpan)}return i}}Ln.blotName="table-col-group";Ln.tagName="colgroup";class sn extends Li{constructor(e,n){super(e,n),n.setAttribute("contenteditable",!1),this.updateTableWidth()}static create(){return super.create()}updateTableWidth(){let e=this.colGroup();if(!e)if(this.parent&&this.parent.children.head&&this.domNode.hasAttribute("style"))e=this.parent.children.head.children.head,this.domNode=this.parent.children.head.domNode;else return this.domNode.tagName==="TABLE",void 0;const n=e.children.reduce((i,r)=>{const a=r.formats()[On.blotName];let s=Sr.width;return a&&a.width&&(s=parseInt(a.width,10)),i=i+s,i},0);this.domNode.removeAttribute("style"),this.domNode.style.width=`${n}px`,e.next&&setTimeout(()=>{let i=0,r;const a=e.children.length,s=this.descendants(xt);for(let o=0;o<s.length;o++){const l=s[o].domNode.querySelectorAll("td");if(l.length===a){r=l;break}}e.children.forEach(o=>{if(r&&o.domNode.width==="auto"){const l=getComputedStyle(r[i]).width,c=parseInt(l,10);o.domNode.width=c<Sr.width&&Sr.width||c}i++})})}cells(e){return this.rows().map(n=>n.children.at(e))}colGroup(){return this.children.head}deleteColumns(e,n=[],i){const[r]=this.descendants(St);if(V(r)||V(r.children.head))return;const a=this.descendants(Pe),s=[],o=[];if(a.forEach(l=>{const c=pe(l.domNode.getBoundingClientRect(),i);c.x+H>e.x&&c.x1-H<e.x1?s.push(l):c.x<e.x+H&&c.x1>e.x1-H&&o.push(l)}),s.length===a.length)return this.tableDestroy(),!0;n.forEach(()=>{let l=this.colGroup().children.at(n[0]);!l||this.colGroup().children.at(n[0]).domNode!==this.colGroup().domNode.children[n[0]]?this.colGroup().domNode.removeChild(this.colGroup().domNode.children[n[0]]):l.remove()}),s.forEach(l=>{l.remove()}),o.forEach(l=>{const c=parseInt(l.formats().colspan,10);l.format("colspan",c-n.length)}),this.updateTableWidth()}deleteRow(e,n){const[i]=this.descendants(St);if(V(i)||V(i.children.head))return;const r=this.descendants(Pe),a=this.descendants(xt),s=[],o=[],l=[];if(r.forEach(d=>{const p=pe(d.domNode.getBoundingClientRect(),n);p.y>e.y-H&&p.y1<e.y1+H?s.push(d):p.y<e.y+H&&p.y1>e.y1-H&&(o.push(d),Math.abs(p.y-e.y)<H&&l.push(d))}),s.length===r.length){this.tableDestroy();return}const c=this.rows().reduce((d,p)=>{const _=pe(p.domNode.getBoundingClientRect(),n);return _.y>e.y-H&&_.y1<e.y1+H&&(d+=1),d},0);l.forEach(d=>{const p=pe(d.domNode.getBoundingClientRect(),n),_=d.parent.next,g=_.children.reduce((S,b)=>{const C=pe(b.domNode.getBoundingClientRect(),n);return p.x1-C.x<H&&(S=b),S},null);_.insertBefore(d,g);const f=_.formats().row;d.format("row",f),d.children.forEach(S=>{S.format("row",f)})}),o.forEach(d=>{const _=parseInt(d.formats().rowspan,10)-c;d.domNode.removeAttribute("style"),d.format("rowspan",_),d.children.forEach(m=>{m.format("rowspan",_)})}),s.forEach(d=>{d.remove()}),a.forEach(d=>{d.children.length===0&&d.remove()})}tableDestroy(){const e=h.find(this.scroll.domNode.parentNode),n=e.getModule("better-table");this.remove(),n.hideTableTools(),e.update(h.sources.USER)}insertCell(e,n,i=""){const r=Nn(),a=e.formats().row,s=this.scroll.create(Pe.blotName,{...fa,row:a});s.domNode.style.backgroundColor=i;const o=this.scroll.create(We.blotName,{row:a,cell:r});s.appendChild(o),n?e.insertBefore(s,n):e.appendChild(s)}insertColumn(e,n,i=!0,r){const[a]=this.descendants(St),[s]=this.descendants(Ln),o=this.descendants(On),l=[],c=[],d=[];if(V(a)||V(a.children.head))return;this.descendants(Pe).forEach(g=>{const f=pe(g.domNode.getBoundingClientRect(),r);i?Math.abs(f.x1-e.x1)<H?l.push(g):e.x1-f.x>H&&e.x1-f.x1<-H&&c.push(g):Math.abs(f.x-e.x)<H?l.push(g):e.x-f.x>H&&e.x-f.x1<-H&&c.push(g)}),l.forEach(g=>{const f=i?g.next:g,S=Nn(),b=g.parent,C=b.formats().row,A=g.formats(),R=this.scroll.create(Pe.blotName,{...fa,row:C,rowspan:A.rowspan}),v=this.scroll.create(We.blotName,{row:C,cell:S,rowspan:A.rowspan});R.appendChild(v),f?b.insertBefore(R,f):b.appendChild(R),d.push(R)});const _=this.scroll.create(On.blotName,!0);let m;return i?m=o[n]&&o[n].next:m=o[n],m?s.insertBefore(_,m):s.appendChild(_),c.forEach(g=>{const f=g.formats().colspan;g.format("colspan",parseInt(f,10)+1),d.push(g)}),d.sort((g,f)=>{const S=g.domNode.getBoundingClientRect().y,b=f.domNode.getBoundingClientRect().y;return S-b}),this.updateTableWidth(),d}insertRow(e,n,i){const[r]=this.descendants(St);if(V(r)||V(r.children.head))return;const a=this.descendants(Pe),s=yn(),o=this.scroll.create(xt.blotName,{row:s}),l=[],c=[],d=[];a.forEach(m=>{const g=pe(m.domNode.getBoundingClientRect(),i);n?Math.abs(g.y1-e.y1)<H?l.push(m):e.y1-g.y>H&&e.y1-g.y1<-H&&c.push(m):Math.abs(g.y-e.y)<H?l.push(m):e.y-g.y>H&&e.y-g.y1<-H&&c.push(m)});const p=(m,g)=>{const f=m.domNode.getBoundingClientRect().x,S=g.domNode.getBoundingClientRect().x;return f-S};l.sort(p),l.forEach(m=>{const g=Nn(),f=m.formats(),S=this.scroll.create(Pe.blotName,{...fa,row:s,cell:g,colspan:f.colspan}),b=this.scroll.create(We.blotName,{row:s,cell:g,colspan:f.colspan}),C=this.scroll.create(Ec.blotName);b.appendChild(C),S.appendChild(b),o.appendChild(S),d.push(S)}),c.forEach(m=>{const g=parseInt(m.formats().rowspan,10);m.format("rowspan",g+1),d.push(m)});const _=this.rows().find(m=>{const g=pe(m.domNode.getBoundingClientRect(),i);return n?Math.abs(g.y-e.y-e.height)<H:Math.abs(g.y-e.y)<H});return r.insertBefore(o,_),d.sort(p),d}mergeCells(e,n,i,r,a){const s=n.reduce((c,d,p)=>{if(p!==0)c&&d.moveChildren(c),d.remove();else if(d.format("colspan",r),d.format("rowspan",i),c=d,i>1){const _=Sa*i+i-1;(parseInt(d.domNode.style.height,10)||0)<_&&(d.domNode.style.height=`${_}px`)}return c},null),o=s.domNode.getAttribute("data-row"),l=s.children.head.domNode.getAttribute("data-cell");return s.children.forEach(c=>{c.domNode.setAttribute("data-parent-bg",s.domNode.style.backgroundColor),c.children.head.domNode.style&&(c.children.head.domNode.style.backgroundColor=s.domNode.style.backgroundColor),!c.prev||c.domNode.innerText.trim()?(c.format("cell",l),c.format("row",o),c.format("colspan",r),c.format("rowspan",i)):c.remove()}),s}unmergeCells(e,n){let i={},r=1,a=1;e.forEach(s=>{const o=s.domNode.style.backgroundColor;if(i=s.formats(),r=i.rowspan,a=i.colspan,a>1){const l=s.next,c=s.row();s.format("colspan",1),s.domNode.children&&s.domNode.children[0].tagName==="DIV"&&s.domNode.children[0].getAttribute("data-colspan")&&s.domNode.children[0].setAttribute("data-colspan",1);for(let d=a;d>1;d--)this.insertCell(c,l,o)}if(r>1){let l=r,c=s.row().next;for(;l>1;){const d=c.children.reduce((p,_)=>{const m=pe(s.domNode.getBoundingClientRect(),n),g=pe(_.domNode.getBoundingClientRect(),n);return Math.abs(m.x1-g.x)<H&&(p=_),p},null);for(let p=a;p>0;p--)this.insertCell(c,d,o);l-=1,c=c.next}s.domNode.removeAttribute("style"),s.domNode.children&&s.domNode.children[0].tagName==="DIV"&&s.domNode.children[0].getAttribute("data-rowspan")&&s.domNode.children[0].setAttribute("data-rowspan",1),s.format("rowspan",1)}})}emptyCells(e){e.forEach(n=>{const i=n.formats(),r=this.scroll.create(We.blotName,{row:i.row||yn(),cell:i.cell||Nn(),rowspan:i.rowspan,colspan:i.colspan}),a=this.scroll.create(Ec.blotName);r.appendChild(a),n.domNode.innerHTML="",n.appendChild(r)})}rows(){const e=this.children.tail;return V(e)?[]:e.children.map(n=>n)}}sn.blotName="ql-table-container";sn.className="quill-better-table";sn.tagName="TABLE";class ni extends Li{constructor(e,n){super(e,n);const i=h.find(e.domNode.parentNode);i.options.readOnly&&(n.style.overflow="auto"),n.addEventListener("scroll",r=>{const a=i.getModule("better-table");a.columnTool&&(a.columnTool.domNode.scrollLeft=r.target.scrollLeft),a.tableSelection&&a.tableSelection.selectedTds.length>0&&a.tableSelection.repositionHelpLines()},!1)}}ni.blotName="table-view";ni.className="quill-better-table-wrapper";ni.tagName="DIV";ni.allowedChildren=[sn];sn.requiredContainer=ni;sn.allowedChildren=[St,Ln];St.requiredContainer=sn;St.allowedChildren=[xt];xt.requiredContainer=St;xt.allowedChildren=[Pe];Pe.requiredContainer=xt;Pe.allowedChildren=[We,Rn,nn,tn];We.requiredContainer=Pe;Ln.allowedChildren=[On];Ln.requiredContainer=sn;On.requiredContainer=Ln;function yn(){return`row-${Math.random().toString(36).slice(2,6)}`}function Nn(){return`cell-${Math.random().toString(36).slice(2,6)}`}function fu(t,e,n=[]){return[...ze,...ft,...n].reduce((i,r)=>(t.hasAttribute(`data-${r}`)&&(i[r]=t.getAttribute(`data-${r}`)||void 0),i),e)}class yT{constructor(e,n,i){if(!e)return null;this.table=e,this.quill=n,this.modulesContainer=i,this.domNode=null,this.oldRootScrollTop=this.quill.root.scrollTop,this.initColTool(),this.quill.root===this.quill.scrollingContainer&&this.quill.root.addEventListener("scroll",this.handleQuillRootScroll.bind(this))}handleQuillRootScroll(){this.domNode&&(this.domNode.style.marginTop=`${this.oldRootScrollTop-this.quill.root.scrollTop}px`)}initColTool(){const e=this.quill.root.parentNode,n=e.getBoundingClientRect(),i=this.table.parentNode.getBoundingClientRect();this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-table-control-panel"),this.columnCtrlPanel=document.createElement("div"),this.columnCtrlPanel.classList.add("qlbt-column-control-panel"),this.domNode.appendChild(this.columnCtrlPanel),this.leftMask=document.createElement("div"),this.leftMask.classList.add("qlbt-left-mask"),X(this.leftMask,{height:`${i.height+50}px`}),this.domNode.appendChild(this.leftMask),this.rowCtrlPanel=document.createElement("div"),this.rowCtrlPanel.classList.add("qlbt-row-control-panel"),this.domNode.appendChild(this.rowCtrlPanel),this.updateRowToolCells(),this.updateColToolCells(),this.modulesContainer.appendChild(this.domNode),X(this.domNode,{width:"100%",height:`${ps}px`,left:"0px",top:`${i.top-n.top+e.scrollTop-25}px`})}createToolCell(e){window.quillIsIntable=!0;const n=document.createElement("div"),i=document.createElement("div"),r=document.createElement("div");return e?(n.classList.add("qlbt-row-tool-cell"),i.classList.add("qlbt-row-tool-cell-selector"),r.classList.add("qlbt-row-tool-cell-holder"),X(n,{width:`${pc}px`})):(n.classList.add("qlbt-col-tool-cell"),i.classList.add("qlbt-col-tool-cell-selector"),r.classList.add("qlbt-col-tool-cell-holder"),X(n,{height:`${ps}px`})),n.appendChild(i),n.appendChild(r),n}updateColToolCells(){const e=h.find(this.table);if(!e)return;const n=e.colGroup().children,i=Math.max(Array.from(n).length,e.colGroup().domNode.children.length),r=Array.from(this.columnCtrlPanel.querySelectorAll(".qlbt-col-tool-cell")),a=Math.max(r.length,i);for(let s=0;s<a;s++){let o=n.at(s),l=0;!o||o.domNode!==e.colGroup().domNode.children[s]?(o=e.colGroup().domNode.children[s],l=o?o.width:e.colGroup().domNode.children[s-1].width):l=parseInt(o.formats()[o.statics.blotName].width,10);let c=null;r[s]?r[s]&&s>=i?r[s].remove():(c=r[s],X(c,{"min-width":`${l}px`})):(c=this.createToolCell(!1),this.columnCtrlPanel.appendChild(c),this.addColCellSelectHandler(c),this.addColCellHolderHandler(c),X(c,{"min-width":`${l}px`}))}}updateRowToolCells(){const e=h.find(this.table);if(!e)return;let n=Array.from(e.domNode.querySelectorAll("tr"));n=n.filter(a=>a.children.length);const i=Array.from(this.rowCtrlPanel.querySelectorAll(".qlbt-row-tool-cell")),r=Math.max(i.length,n.length);for(let a=0;a<r;a++){const s=n[a];let o=s&&getComputedStyle(s).height;o==="auto"&&(o=s.querySelector("td").style.height||"30px");let l=s&&parseFloat(o);l<Sa&&(l=s&&s.childNodes[0]&&parseFloat(getComputedStyle(s.childNodes[0]).height));let c=null;i[a]?i[a]&&a>=n.length?i[a].remove():(c=i[a],X(c,{height:`${l}px`})):(c=this.createToolCell(!0),this.rowCtrlPanel.appendChild(c),this.addRowCellSelectHandler(c),this.addRowCellHolderHandler(c),X(c,{height:`${l}px`}))}}destroy(){return window.quillIsIntable=!1,this.domNode.remove(),null}addRowCellSelectHandler(e){const n=e.querySelector(".qlbt-row-tool-cell-selector"),i=r=>{r.preventDefault();const a=r.target.parentNode,s=a.getBoundingClientRect(),o=this.quill.root.parentNode.getBoundingClientRect(),l=this.table.getBoundingClientRect(),c=this.quill.getModule("better-table").tableSelection;c.boundary={x:l.left-o.left,x1:l.left-o.left+l.width-2,y:s.top-o.top,y1:s.top-o.top+s.height-1,width:l.width-2,height:s.height-1},c.selectedTds=c.computeSelectedTds(),c.repositionHelpLines(),a.classList.add("qlbt-tool-cell-on"),this.activeToolCell=a};n.addEventListener("click",i,!1)}addRowCellHolderHandler(e){const n=e.querySelector(".qlbt-row-tool-cell-holder");let i=!1,r=0,a=0,s=0,o=0,l={},c={},d=null;const p=g=>{g.preventDefault(),i&&(a=g.clientY,o+a-r>=Sa?s=a-r:s=Sa-o,X(d,{top:`${c.top+c.height+s}px`}))},_=g=>{g.preventDefault();const S=Array.from(this.domNode.querySelectorAll(".qlbt-row-tool-cell")).indexOf(e),b=Array.from(this.table.querySelectorAll("tr")),C=Array.from(b[S].childNodes),A=C.find(D=>D.getAttribute("rowspan")==="1"&&D.innerText!==`
327
327
  `);if(i){let D=`${o+s}px`;if(A){C.forEach(F=>F.getAttribute("rowspan")==="1"&&X(F,{height:D}));const k=getComputedStyle(A).height;D=parseInt(k,10)>o+s&&k||D}X(e,{height:D}),C.forEach(k=>k.getAttribute("rowspan")==="1"&&X(k,{height:D}));const Y=this.table.parentNode.getBoundingClientRect();X(this.leftMask,{height:`${Y.height+50}px`}),r=0,a=0,s=0,o=0,i=!1,n.classList.remove("dragging")}this.quill.root.parentNode.removeEventListener("mousemove",p,!1),document.removeEventListener("mouseup",_,!1),l={},c={},d.remove(),d=null;const R=this.quill.getModule("better-table");R.tableScrollBar.resetTableHeight(this.table);const I=R.tableSelection;I&&I.selectedTds.length&&I.refreshHelpLinesPosition()},m=g=>{g.preventDefault(),this.quill.root.parentNode.addEventListener("mousemove",p,!1),document.addEventListener("mouseup",_,!1),l=this.table.getBoundingClientRect();const f=this.table.parentNode.getBoundingClientRect(),S=l.width>f.width&&f.width||l.width;c=e.getBoundingClientRect(),d=document.createElement("div"),X(d,{position:"fixed",top:`${c.top+c.height}px`,left:`${c.left}px`,zIndex:"100",width:`${S+pc+9}px`,height:"1px",backgroundColor:eo}),this.quill.root.parentNode.appendChild(d),i=!0,r=g.clientY,o=c.height,n.classList.add("dragging")};n.addEventListener("mousedown",m,!1)}addColCellSelectHandler(e){const n=e.querySelector(".qlbt-col-tool-cell-selector"),i=r=>{r.preventDefault();const a=r.target.parentNode,s=a.getBoundingClientRect(),o=this.quill.root.parentNode.getBoundingClientRect(),l=this.table.getBoundingClientRect(),c=this.quill.getModule("better-table").tableSelection;c.boundary={x:s.left-o.left-1,x1:s.left-o.left+s.width-2,y:l.top-o.top,y1:l.top-o.top+l.height-2,width:s.width,height:l.height-2},c.selectedTds=c.computeSelectedTds(),c.repositionHelpLines(),a.classList.add("qlbt-tool-cell-on"),this.activeToolCell=a};n.addEventListener("click",i,!1)}addColCellHolderHandler(e){const n=h.find(this.table),i=e.querySelector(".qlbt-col-tool-cell-holder");let r=!1,a=0,s=0,o=0,l=0,c={},d=null,p={},_=null;const m=S=>{if(S.preventDefault(),r){s=S.clientX,l+s-a>=Js?o=s-a:o=Js-l;let b=p.left+p.width-1+o;d&&(b-=d.left),X(_,{left:`${b}px`})}},g=S=>{S.preventDefault();const C=Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell")).indexOf(e);let A=n.colGroup().children.at(C);if((!A||A.domNode!==n.colGroup().domNode.children[C])&&(A=n.colGroup().domNode.children[C]),r){const R=parseInt(l+o,10);A.format?A.format("width",R):A.width=R,X(e,{"min-width":`${R}px`}),a=0,s=0,o=0,l=0,r=!1,i.classList.remove("dragging")}this.quill.root.parentNode.removeEventListener("mousemove",m,!1),document.removeEventListener("mouseup",g,!1),c={},d=null,p={},_.remove(),_=null,n.updateTableWidth(),setTimeout(()=>{this.updateRowToolCells();const R=this.quill.getModule("better-table");R.tableScrollBar.updateScrollBar();const I=R.tableSelection;I&&I.selectedTds.length&&I.refreshHelpLinesPosition()})},f=S=>{S.preventDefault(),this.quill.root.parentNode.addEventListener("mousemove",m,!1),document.addEventListener("mouseup",g,!1),c=this.table.getBoundingClientRect(),p=e.getBoundingClientRect();let b="fixed",C=p.top,A=p.left+p.width-1;this.quill.root===this.quill.scrollingContainer&&(b="absolute",d=this.quill.root.getBoundingClientRect(),C-=d.top,A-=d.left),_=document.createElement("div"),X(_,{position:b,top:`${C}px`,left:`${A}px`,zIndex:"100",height:`${c.height+ps+8}px`,width:"1px",backgroundColor:eo}),this.quill.root.parentNode.appendChild(_),r=!0,a=S.clientX,l=p.width,i.classList.add("dragging")};i.addEventListener("mousedown",f,!1)}colToolCells(){return Array.from(this.domNode.querySelectorAll(".qlbt-col-tool-cell"))}}const fc={copyCells:{text:"Copy Cells",handler(){this.onCopy("copy")}},copyTable:{text:"Copy Table",handler(){this.tableColumnTool.destroy(),this.tableScrollBar.destroy(),this.tableSelection.clearSelection();const t=this.table.cloneNode(!0);t.querySelectorAll("tr[data-row]").forEach(n=>n.removeAttribute("data-row")),t.style.position="fixed",t.style.top=0,t.style.left=0,t.style.clip="rect(0,0,0,0)",document.body.appendChild(t),this.setCopyRange(t),document.execCommand("copy"),t.remove()}},cutCells:{text:"Cut Cells",handler(){this.onCopy("cut")}},emptyCells:{text:"Empty Cells",handler(){const t=h.find(this.table),{selectedTds:e}=this.tableSelection;t.emptyCells(e)}},insertColumnRight:{text:"Insert Column After",handler(){const t=h.find(this.table),e=Sc(this.columnToolCells,this.boundary,(i,r)=>Math.abs(i.x+i.width-r.x1)<=H,this.quill.root.parentNode),n=t.insertColumn(this.boundary,e,!0,this.quill.root.parentNode);this.tableColumnTool.updateColToolCells(),this.quill.update(h.sources.USER),this.tableSelection.setSelection(n[0].domNode.getBoundingClientRect(),n[0].domNode.getBoundingClientRect()),setTimeout(()=>this.tableScrollBar.updateScrollBar())}},insertColumnLeft:{text:"Insert Column Before",handler(){const t=h.find(this.table),e=Sc(this.columnToolCells,this.boundary,(i,r)=>Math.abs(i.x-r.x)<=H,this.quill.root.parentNode),n=t.insertColumn(this.boundary,e,!1,this.quill.root.parentNode);this.tableColumnTool.updateColToolCells(),this.quill.update(h.sources.USER),this.tableSelection.setSelection(n[0].domNode.getBoundingClientRect(),n[0].domNode.getBoundingClientRect()),setTimeout(()=>this.tableScrollBar.updateScrollBar())}},insertRowUp:{text:"Insert Row Above",handler(){const e=h.find(this.table).insertRow(this.boundary,!1,this.quill.root.parentNode);this.tableColumnTool.updateRowToolCells(),this.quill.update(h.sources.USER),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect()),setTimeout(()=>this.tableScrollBar.resetTableHeight(this.table))}},insertRowDown:{text:"Insert Row Below",handler(){const e=h.find(this.table).insertRow(this.boundary,!0,this.quill.root.parentNode);this.tableColumnTool.updateRowToolCells(),this.quill.update(h.sources.USER),this.tableSelection.setSelection(e[0].domNode.getBoundingClientRect(),e[0].domNode.getBoundingClientRect()),setTimeout(()=>this.tableScrollBar.resetTableHeight(this.table))}},mergeCells:{text:"Merge Cells",handler(){const t=h.find(this.table),e=t.rows().reduce((r,a)=>{const s=pe(a.domNode.getBoundingClientRect(),this.quill.root.parentNode);return s.y>this.boundary.y-H&&s.y+s.height<this.boundary.y+this.boundary.height+H&&(r+=1),r},0),n=this.columnToolCells.reduce((r,a)=>{const s=pe(a.getBoundingClientRect(),this.quill.root.parentNode);return s.x>this.boundary.x-H&&s.x+s.width<this.boundary.x+this.boundary.width+H&&(r+=1),r},0),i=t.mergeCells(this.boundary,this.selectedTds,e,n,this.quill.root.parentNode);this.quill.update(h.sources.USER),this.tableSelection.setSelection(i.domNode.getBoundingClientRect(),i.domNode.getBoundingClientRect())}},unmergeCells:{text:"Split Cells",handler(){h.find(this.table).unmergeCells(this.selectedTds,this.quill.root.parentNode),this.quill.update(h.sources.USER),this.tableSelection.clearSelection()}},deleteColumn:{text:"Delete Columns",handler(){const t=h.find(this.table),e=MT(this.columnToolCells,this.boundary,(i,r)=>i.x+H>r.x&&i.x+i.width-H<r.x1,this.quill.root.parentNode);t.deleteColumns(this.boundary,e,this.quill.root.parentNode)||(this.tableColumnTool.updateColToolCells(),this.quill.update(h.sources.USER),this.tableSelection.clearSelection()),setTimeout(()=>this.tableScrollBar.updateScrollBar())}},deleteRow:{text:"Delete Rows",handler(){h.find(this.table).deleteRow(this.boundary,this.quill.root.parentNode)||(this.tableColumnTool.updateRowToolCells(),this.quill.update(h.sources.USER),this.tableSelection.clearSelection())}},deleteTable:{text:"Remove Table",handler(){const t=this.quill.getModule("better-table"),e=h.find(this.table);t.hideTableTools(),e.remove(),this.quill.update(h.sources.USER),this.quill.focus()}}},IT=["white","red","yellow","blue"],ms=new WeakMap;let DT=Oa.subTitleBgColor;class LT{constructor(e,n,i){const r=n.getModule("better-table");this.tableSelection=r.tableSelection,this.table=e.table,this.quill=n,this.options=i,this.menuItems={...fc,...i.items},this.tableColumnTool=r.columnTool,this.tableScrollBar=r.tableScrollBar,this.boundary=this.tableSelection.boundary,this.selectedTds=this.tableSelection.selectedTds,this.destroyHandler=this.destroy.bind(this),this.columnToolCells=this.tableColumnTool.colToolCells(),this.colorSubTitle=i.color&&i.color.text?i.color.text:DT,this.cellColors=i.color&&i.color.colors?i.color.colors:IT,this.menuInitial(e),this.mount(),document.addEventListener("click",this.destroyHandler,!1)}mount(){this.quill.root.parentNode.appendChild(this.domNode)}destroy(){const e=gc(this.domNode.querySelectorAll("."+fT)),n=gc(this.domNode.querySelectorAll("."+_c));return e.concat(n).forEach(r=>{if(ms.has(r)){const a=ms.get(r);a&&typeof a=="function"&&a()}}),vT(this.domNode),document.removeEventListener("mousedown",this.destroyHandler,!1),null}menuInitial({cell:e,left:n,top:i}){const r=e.getAttribute("rowspan"),a=e.getAttribute("colspan"),s=window.innerHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight),o=Object.keys(this.menuItems)||[],l=TT*o.length||mc,c=wT(this.quill.root.parentNode,n,i),d=n-c.offsetX,p=i-c.offsetY,_={left:`${d}px`,top:`${p}px`,"min-height":`${mc}px`,width:`${CT}px`};l+i>s&&l<s&&(delete _.top,_.bottom="10px"),this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-operation-menu"),X(this.domNode,_);for(const f in this.menuItems)if(this.menuItems[f]){const S={...fc[f],...this.menuItems[f]},b=this.menuItemCreator(S);f==="mergeCells"&&this.tableSelection.selectedTds.length===1||f==="unmergeCells"&&r===1&&a===1?b.classList.add("qlbt-operation-menu-disabled"):b.addEventListener("mouseup",S.handler.bind(this),!1),this.domNode.appendChild(b)}this.options.color&&this.options.color!==!1&&(this.domNode.appendChild(m()),this.domNode.appendChild(g(this.colorSubTitle)),this.domNode.appendChild(this.colorsItemCreator(this.cellColors)));function m(){const f=document.createElement("div");return f.classList.add(ST),f}function g(f){const S=document.createElement("div");return S.classList.add(hT),S.innerText=f,S}}colorsItemCreator(e){const n=this,i=document.createElement("div");i.classList.add(bT),e.forEach(a=>{const s=r(a);i.appendChild(s)});function r(a){const s=document.createElement("div");s.classList.add(_c),s.setAttribute("data-color",a),s.style.backgroundColor=a;const o=function(){const l=n.tableSelection.selectedTds;l&&l.length>0&&l.forEach(c=>{c.domNode.children[0].setAttribute("data-parent-bg",a),c.format("cell-bg",a)})};return s.addEventListener("click",o,!1),ms.set(s,()=>{s.removeEventListener("click",o,!1)}),s}return i}menuItemCreator({text:e}){const n=document.createElement("div");return n.classList.add("qlbt-operation-menu-item"),n.innerText=e,n}onCopy(e){const{selectedTds:n}=this.tableSelection,i=this.createVirtualTable(n,e);document.body.appendChild(i),this.setCopyRange(i),this.tableSelection.preSelectedTable=i,this.tableSelection.preSelectedTds=n,document.execCommand("copy"),i.remove(),e==="cut"&&h.find(this.table).emptyCells(n)}createVirtualTable(e,n){const i=document.createElement("table");i.style.position="fixed",i.style.top=0,i.style.left=0,i.style.clip="rect(0,0,0,0)";let r="",a=null;return e.forEach(s=>{const{domNode:o,parent:l}=s,c=l.domNode.getAttribute("data-row"),d=o.firstChild.dataset.rowspan,p=o.firstChild.dataset.colspan,_=o.firstChild.dataset.row,m=o.firstChild.dataset.cell;s.dataCell=m,s.dataRow=_,s.dataColSpan=p,s.dataRowSpan=d,c!==r&&(r!==""&&i.appendChild(a),a=document.createElement("tr"),r=c);const g=o.offsetWidth,f=o.cloneNode(!0);f.setAttribute("width",g),a.appendChild(f)}),i.appendChild(a),i}setCopyRange(e){const n=document.createRange(),i=window.getSelection();n.selectNodeContents(e),i.removeAllRanges(),i.addRange(n)}groupTableCell(e){const n=[];let i="",r="",a=0;return e.forEach(s=>{i=s.parent.domNode.getAttribute("data-row"),i!==r&&(r!==""&&a++,n[a]=[],r=i),n[a].push(s)}),n}}function Sc(t,e,n,i){return t.reduce((r,a)=>{const s=pe(a.getBoundingClientRect(),i);return n(s,e)&&(r=t.indexOf(a)),r},!1)}function MT(t,e,n,i){return t.reduce((r,a)=>{const s=pe(a.getBoundingClientRect(),i);return n(s,e)&&r.push(t.indexOf(a)),r},[])}function wT(t,e,n){if(!t)return{offsetX:0,offsetY:0};const i=document.createElement("div");X(i,{opacity:"0",position:"fixed",left:`${e}px`,top:`${n}px`,width:"1px",height:"1px",zIndex:"-999999"}),t.appendChild(i);const r=i.getBoundingClientRect();return t.removeChild(i),{offsetX:r.left-e,offsetY:r.top-n}}class xT{constructor(e,n,i){if(!e)return;this.table=e,this.quill=n,this.modulesContainer=i,this.domNode=null,this.oldRootScrollTop=this.quill.root.scrollTop,this.prev=0;const a=this.quill.getModule("better-table").columnTool;this.columnToolDomNode=a.domNode,this.columnCtrlPanel=a.columnCtrlPanel,this.leftMask=a.leftMask,this.updateScrollBar(),this.quill.root===this.quill.scrollingContainer&&this.quill.root.addEventListener("scroll",this.handleQuillRootScroll.bind(this))}handleQuillRootScroll(){if(!this.domNode)return;const e=this.table.getBoundingClientRect(),n=this.quill.root.parentNode.getBoundingClientRect(),i=e.top+_s,r=e.top+e.height-1,a=n.top+n.height;a<r&&a>i?this.isTableOverflow||(this.isTableOverflow=!0,X(this.domNode,{display:"block",top:`${this.containerRect.height-_s}px`,marginTop:"0px"})):a<=i?(this.isTableOverflow=!1,this.domNode.style.display="none"):(this.setScrollBarToBottom(),X(this.domNode,{marginTop:`${this.oldRootScrollTop-this.quill.root.scrollTop}px`}))}setScrollBarToBottom(){if(this.isTableOverflow){this.isTableOverflow=!1;const e=this.tableRect.top+this.tableRect.height-this.containerRect.top-1;X(this.domNode,{display:"block",top:`${e}px`})}}resetTableHeight(e){this.domNode&&(this.tableRect.height=e.getBoundingClientRect().height,this.isTableOverflow=!this.isTableOverflow,this.handleQuillRootScroll())}setScrollBarMove(e,n){const i=parseInt(getComputedStyle(this.scrollBar).left,10);let r=n?e-this.prev+i:i+e;this.showMask(r),r=this.getLimitedDistance(r);const a=this.tableViewRect.width/this.tableRect.width,s=r/a,o=this.tableViewRect.left-this.containerRect.left-s;X(this.scrollBar,{left:`${r}px`}),X(this.columnCtrlPanel,{left:`${o}px`}),this.table.parentNode.scrollLeft=s,n&&(this.prev=e);const l=this.quill.getModule("better-table").tableSelection;l&&l.selectedTds.length&&l.refreshHelpLinesPosition()}handleScrollBarMouseDown(e){e.preventDefault(),this.prev=e.clientX,this.subscriber=n=>{n.preventDefault(),n.stopPropagation(),this.setScrollBarMove(n.clientX,!0)},this.quill.root.parentNode.addEventListener("mousemove",this.subscriber,!1),document.addEventListener("mouseup",this.handleScrollBarMouseup.bind(this),!1)}handleScrollBarMouseup(e){e.preventDefault(),this.quill.root.parentNode.removeEventListener("mousemove",this.subscriber),document.removeEventListener("mouseup",this.handleScrollBarMouseup.bind(this),!1)}handleWheel(e){if(e.shiftKey){const{deltaY:n}=e;this.setScrollBarMove(n,!1)}}showMask(e){e>=Math.floor(this.maxBarLeft)?X(this.leftMask,{display:"block"}):e<=0?X(this.leftMask,{display:"none"}):X(this.leftMask,{display:"block"})}getLimitedDistance(e){return e>=Math.floor(this.maxBarLeft)?e=this.maxBarLeft:e<=0&&(e=0),e}updateScrollBar(){var r;if(!((r=this.table)!=null&&r.parentNode))return;const e=this.table.getBoundingClientRect(),n=this.table.parentNode.getBoundingClientRect(),i=e.width-n.width;this.tableRect=e,this.tableViewRect=n,this.tableMoveDistance=i,this.oldRootScrollTop=this.quill.root.scrollTop,i>0?this.createScrollBar():this.destroyScrollBar()}createScrollBar(){const n=this.quill.root.parentNode.getBoundingClientRect();this.containerRect=n,X(this.columnCtrlPanel,{left:`${this.tableViewRect.left-n.left-this.table.parentNode.scrollLeft}px`}),this.domNode&&this.domNode.remove(),this.domNode=document.createElement("div"),this.domNode.classList.add("qlbt-table-scroll-bar-panel"),this.scrollBar=document.createElement("div"),this.scrollBar.classList.add("qlbt-table-scroll-bar"),this.scrollBar.addEventListener("mousedown",this.handleScrollBarMouseDown.bind(this),!1);const i=this.tableViewRect.width/this.tableRect.width,r=this.tableViewRect.width-this.tableMoveDistance*i;X(this.scrollBar,{width:`${r}px`}),this.domNode.appendChild(this.scrollBar);const a=this.table.parentNode.scrollLeft;if(this.maxBarLeft=this.tableMoveDistance*i,a){const o=a*i;this.showMask(o),X(this.scrollBar,{left:`${this.getLimitedDistance(o)}px`})}const s=this.tableRect.top+this.tableRect.height-n.top-1;this.isTableOverflow=n.top+n.height<this.tableRect.top+this.tableRect.height,this.modulesContainer.appendChild(this.domNode),X(this.domNode,{top:`${Math.min(n.height-_s,s)}px`}),document.addEventListener("wheel",this.handleWheel.bind(this))}destroyScrollBar(){X(this.leftMask,{display:"none"}),this.columnCtrlPanel.removeAttribute("style"),this.maxBarLeft=null,this.destroy()}destroy(){this.domNode&&this.domNode.remove(),this.quill.root.removeEventListener("scroll",this.handleQuillRootScroll.bind(this)),document.removeEventListener("wheel",this.handleWheel.bind(this))}}class PT{constructor(e,n,i){if(!e)return null;this.table=e,this.quill=n,this.modulesContainer=i,this.parent=this.quill.root.parentNode,this.boundary={},this.selectedTds=[],this.dragging=!1,this.preSelectedTable=null,this.oldRootScrollTop=this.quill.root.scrollTop,this.selectingHandler=this.mouseDownHandler.bind(this),this.tdEditHandler=this.setTdEditable.bind(this),this.tdResizeHandler=this.resizeTd.bind(this),this.helpLinesInitial(),this.isEditorHasScrollBar(),this.quill.root.parentNode.addEventListener("mousedown",this.selectingHandler,!1),this.quill.on("text-change",this.tdResizeHandler),this.quill.root===this.quill.scrollingContainer&&this.quill.root.addEventListener("scroll",this.handleQuillRootScroll.bind(this))}handleQuillRootScroll(){na.forEach(e=>{const n=this[e];n&&(n.style.marginTop=`${this.oldRootScrollTop-this.quill.root.scrollTop}px`)})}isEditorHasScrollBar(){this.quill.root.scrollHeight>this.quill.root.clientHeight?X(this.modulesContainer,{width:"calc(100% - 23px)"}):this.modulesContainer.removeAttribute("style")}helpLinesInitial(){na.forEach(e=>{if(this[e]=document.createElement("div"),this[e].classList.add("qlbt-selection-line"),e==="left"){this[e].classList.add("qlbt-selection-line-first");const n=document.createElement("div");this[e].appendChild(n)}if(e==="bottom"){this[e].classList.add("qlbt-selection-line-last");const n=document.createElement("div");this[e].appendChild(n)}X(this[e],{position:"absolute",display:"none","background-color":eo}),this.modulesContainer.appendChild(this[e])})}mouseDownHandler(e){if(e.button!==0)return;const n=this,r=this.quill.getModule("better-table").columnTool;r.activeToolCell&&(r.activeToolCell.classList.remove("qlbt-tool-cell-on"),r.activeToolCell=null),e.target.closest(".quill-better-table")?e.shiftKey?(this.endTd=e.target.closest("td[data-row]"),this.drawSelection(this,!0),this.startTd!==this.endTd&&this.quill.blur()):(this.startTd=e.target.closest("td[data-row]"),this.drawSelection(this,!1),this.dragging=!0,this.parent.addEventListener("mousemove",a,!1),document.addEventListener("mouseup",s,!1)):e.target.closest(".qlbt-selection-line")&&(this.parent.addEventListener("mousemove",a,!1),document.addEventListener("mouseup",s,!1));function a(o){o.stopPropagation(),!(o.button!==0||!o.target.closest(".quill-better-table"))&&(n.endTd=o.target.closest("td[data-row]"),n.endTd&&(n.drawSelection(n,!0),n.startTd!==n.endTd&&n.quill.blur()))}function s(){n.parent.removeEventListener("mousemove",a,!1),document.removeEventListener("mouseup",s,!1),n.dragging=!1}}drawSelection(e,n){e.startTdRect=pe(e.startTd.getBoundingClientRect(),e.quill.root.parentNode);let i=e.startTdRect;n&&(e.endTdRect=pe(e.endTd.getBoundingClientRect(),e.quill.root.parentNode),i=e.endTdRect),e.boundary=pr(e.startTdRect,i),e.selectedTds=e.computeSelectedTds(),e.repositionHelpLines()}setTdEditable(e){if(!this.editTd)return;this.parent.removeEventListener("keypress",this.tdEditHandler,!1);const n=this.editTd.domNode;if(n.removeEventListener("click",this.tdEditHandler,!1),n.classList.add("editing-select-able"),n.setAttribute("contenteditable",!0),e.type==="keypress"){if(n.childNodes.length>1||n.firstChild.innerHTML!=="<br>"){const i=n.firstChild.cloneNode();i.innerHTML="<br>",n.innerHTML="",n.appendChild(i)}n.focus()}}resizeTd(){if(!this.editTd||this.left&&!this.left.offsetParent)return;if(this.selectedTds.length>1)this.refreshHelpLinesPosition();else{const r=this.editTd.domNode,a=pe(r.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=pr(a,a),this.repositionHelpLines()}this.isEditorHasScrollBar();const e=this.quill.getModule("better-table"),n=e.columnTool;if(n){n.updateRowToolCells();const r=this.table.parentNode.getBoundingClientRect();n.leftMask&&X(n.leftMask,{height:`${r.height+50}px`})}e.tableScrollBar.resetTableHeight(this.table)}resetTd(e){const n=e.target;n.classList.remove("editing-select-able"),n.setAttribute("contenteditable",!1),n.removeAttribute("contenteditable")}correctBoundary(){h.find(this.table).descendants(Pe).forEach(i=>{const{x:r,y:a,width:s,height:o}=pe(i.domNode.getBoundingClientRect(),this.quill.root.parentNode);(r+H>=this.boundary.x&&r+H<=this.boundary.x1||r-H+s>=this.boundary.x&&r-H+s<=this.boundary.x1)&&(a+H>=this.boundary.y&&a+H<=this.boundary.y1||a-H+o>=this.boundary.y&&a-H+o<=this.boundary.y1)&&(this.boundary=pr(this.boundary,{x:r,y:a,width:s,height:o}))})}computeSelectedTds(){const i=h.find(this.table).descendants(Pe).reduce((r,a)=>{const{x:s,y:o,width:l,height:c}=pe(a.domNode.getBoundingClientRect(),this.quill.root.parentNode);return s+H>=this.boundary.x&&s-H+l<=this.boundary.x1&&o+H>=this.boundary.y&&o-H+c<=this.boundary.y1&&r.push(a),r},[]);return i.length===1&&this.editTd!==i[0]&&(this.table.querySelectorAll("td[contenteditable=true]").forEach(a=>this.resetTd({target:a})),this.editTd=i[0],this.editTd.domNode.addEventListener("mousedown",this.tdEditHandler,!1),this.parent.addEventListener("keypress",this.tdEditHandler,!1)),i}repositionHelpLines(){this.oldRootScrollTop=this.quill.root.scrollTop,this.left&&(X(this.left,{display:"block",left:`${this.boundary.x-1}px`,top:`${this.boundary.y}px`,height:`${this.boundary.height+1}px`,width:"1px","margin-top":"0px"}),X(this.right,{display:"block",left:`${this.boundary.x1}px`,top:`${this.boundary.y-1}px`,height:`${this.boundary.height+1}px`,width:"1px","margin-top":"0px"}),X(this.top,{display:"block",left:`${this.boundary.x-1}px`,top:`${this.boundary.y-1}px`,width:`${this.boundary.width+1}px`,height:"1px","margin-top":"0px"}),X(this.bottom,{display:"block",left:`${this.boundary.x-1}px`,top:`${this.boundary.y1}px`,width:`${this.boundary.width+1}px`,height:"1px","margin-top":"0px"}))}refreshHelpLinesPosition(){const e=pe(this.selectedTds[0].domNode.getBoundingClientRect(),this.quill.root.parentNode),n=pe(this.selectedTds[this.selectedTds.length-1].domNode.getBoundingClientRect(),this.quill.root.parentNode);this.boundary=pr(e,n),this.repositionHelpLines()}destroy(){return this.table.querySelectorAll("td[contenteditable=true]").forEach(n=>this.resetTd({target:n})),na.forEach(n=>{this[n]&&(this[n].remove(),this[n]=null)}),this.quill.root.parentNode.removeEventListener("mousedown",this.selectingHandler,!1),delete this.editTd,null}setSelection(e,n){this.boundary=pr(pe(e,this.quill.root.parentNode),pe(n,this.quill.root.parentNode)),this.correctBoundary(),this.selectedTds=this.computeSelectedTds(),this.repositionHelpLines()}clearSelection(){this.table.querySelectorAll("td[contenteditable=true]").forEach(n=>this.resetTd({target:n})),this.boundary={},this.selectedTds=[],na.forEach(n=>{this[n]&&X(this[n],{display:"none"})})}}function pr(t,e){const n=Math.min(t.x,e.x,t.x+t.width-1,e.x+e.width-1),i=Math.max(t.x,e.x,t.x+t.width-1,e.x+e.width-1),r=Math.min(t.y,e.y,t.y+t.height-1,e.y+e.height-1),a=Math.max(t.y,e.y,t.y+t.height-1,e.y+e.height-1),s=i-n,o=a-r;return{x:n,x1:i,y:r,y1:a,width:s,height:o}}const bt=h.imports.delta,to=h.imports.parchment.InlineBlot;function kT(t,e){t.style.height.indexOf("pt")&&t.removeAttribute("style");const n=t.parentNode;let i=n.dataset.row;i||(i=n.dataset.row=yn());let r=t.dataset.cell;(!r||r==="undefined")&&(r=Nn());const a=t.getAttribute("colspan")||1,s=t.getAttribute("rowspan")||1;if(e.length()===0)return e=new bt().insert(`
328
328
  `,{"table-cell-line":{row:i,cell:r,rowspan:s,colspan:a}}),e;e=e.reduce((c,d)=>(d.insert&&typeof d.insert=="string"?qa(d.insert).forEach(_=>{if(_===`
329
329
  `){let m={};const g={row:i,cell:r,rowspan:s,colspan:a};switch(d.attributes.table&&delete d.attributes.table,!0){case!!d.attributes.header:m=Object.assign(d.attributes.header,g);break;case!!d.attributes.list:m={list:Object.assign(d.attributes.list,g)};break;default:m={"table-cell-line":g}}d.attributes.background&&m["table-cell-line"]&&(m["table-cell-line"].tdBgColor=d.attributes.background),c.insert(`