quill-table-up 3.1.0 → 3.1.2
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/e2e/table-resize.test.ts +37 -6
- package/src/__tests__/unit/table-insert.test.ts +4 -4
- package/src/__tests__/unit/table-redo-undo.test.ts +2 -2
- package/src/__tests__/unit/utils.ts +23 -0
- package/src/modules/table-resize/table-resize-common.ts +4 -3
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
package/dist/index.js
CHANGED
|
@@ -126,7 +126,7 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
|
|
|
126
126
|
<!-- Icon from TDesign Icons by TDesign - https://github.com/Tencent/tdesign-icons/blob/main/LICENSE -->
|
|
127
127
|
<path fill="currentColor" d="M21 10v12h-2V12H5v10H3V10zm0-8v6H3V2zm-2 2H5v2h14z" />
|
|
128
128
|
</svg>
|
|
129
|
-
`;const yr=`color-selector`;async function br(e,t,n=!1){let r=e.getTextByCell(t),i=e.getHTMLByCell(t,n),a=new ClipboardItem({"text/plain":new Blob([r],{type:`text/plain`}),"text/html":new Blob([i],{type:`text/html`})});await navigator.clipboard.write([a])}const Z={Break:{name:`break`},CopyCell:{name:`CopyCell`,tip:`Copy cell`,icon:sr,handle(e,t){br.call(this,e,t,!1)}},CutCell:{name:`CutCell`,tip:`Cut cell`,icon:cr,handle(e,t){br.call(this,e,t,!0)}},InsertTop:{name:`InsertTop`,icon:fr,tip:`Insert row above`,handle(e,t){e.appendRow(t,!1)}},InsertRight:{name:`InsertRight`,icon:dr,tip:`Insert column right`,handle(e,t){e.appendCol(t,!0)}},InsertBottom:{name:`InsertBottom`,icon:lr,tip:`Insert row below`,handle(e,t){e.appendRow(t,!0)}},InsertLeft:{name:`InsertLeft`,icon:ur,tip:`Insert column Left`,handle(e,t){e.appendCol(t,!1)}},MergeCell:{name:`MergeCell`,icon:pr,tip:`Merge Cell`,handle(e,t){e.mergeCells(t)}},SplitCell:{name:`SplitCell`,icon:_r,tip:`Split Cell`,handle(e,t){e.splitCell(t)}},DeleteRow:{name:`DeleteRow`,icon:hr,tip:`Delete Row`,handle(e,t){e.removeRow(t)}},DeleteColumn:{name:`DeleteColumn`,icon:mr,tip:`Delete Column`,handle(e,t){e.removeCol(t)}},DeleteTable:{name:`DeleteTable`,icon:gr,tip:`Delete table`,handle(e,t){e.deleteTable(t)}},BackgroundColor:{name:`BackgroundColor`,icon:ir,isColorChoose:!0,tip:`Set background color`,key:`background-color`,handle(e,t,n){e.setCellAttrs(t,`background-color`,n,!0)}},BorderColor:{name:`BorderColor`,icon:ar,isColorChoose:!0,tip:`Set border color`,key:`border-color`,handle(e,t,n){e.setCellAttrs(t,`border-color`,n,!0)}},SwitchWidth:{name:`SwitchWidth`,icon:rr,tip:`Switch table width`,handle(){if(!this.table)return;let t=e.find(this.table);t&&(t.full?t.cancelFull():t.setFull())}},InsertCaption:{name:`InsertCaption`,icon:vr,tip:`Insert table caption`,handle(){if(!this.table)return;let n=e.find(this.table);if(!n)return;let r=this.quill.scroll.create(`text`,`Table Caption`).wrap(t.tableCaption,{tableId:n.tableId});n.insertBefore(r,n.children.head)}},ToggleTdBetweenTh:{name:`ToggleTdBetweenTh`,icon:or,tip:`Toggle td between th`,handle(e,t){for(let e of t)e.convertTableCell()}},ConvertTothead:{name:`ConvertTothead`,icon:or,tip:`Convert to thead`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`thead`)}},ConvertTotfoot:{name:`ConvertTotfoot`,icon:or,tip:`Convert to tfoot`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`tfoot`)}}},xr=l(`color-map`),Q={selectWrapper:xr.b(),used:xr.bm(`used`),item:xr.be(`item`),btn:xr.be(`btn`),map:xr.be(`content`),mapRow:xr.be(`content-row`)};var Sr=class extends Rn{static moduleName=`table-menu`;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;tooltipItem=[];activeTooltip=null;bem=l(`menu`);colorItemClass=`color-${R()}`;colorChooseTooltipOption={direction:`top`};constructor(t,n,i){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i);try{let e=localStorage.getItem(this.options.localstorageKey)||`[]`,t=JSON.parse(e);S(t)||(t=[]),t.slice(-10).map(e=>this.usedColors.add(e))}catch{}this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart)}updateUsedColor=dn(e=>{if(!e)return;if(this.usedColors.add(e),this.usedColors.size>10){let e=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),e.map(e=>this.usedColors.add(e))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));let t=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Q.used}`));for(let n of t){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=String(e),Array.from(n.querySelectorAll(`.${Q.item}[style*="background-color: ${t.style.backgroundColor}"]`)).length<=0&&n.appendChild(t);let r=Array.from(n.querySelectorAll(`.${Q.item}`)).slice(0,-10);for(let e of r)e.remove()}},1e3);hideWhenSelectionDragStart=()=>{this.hide()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&this.isMenuDisplay&&this.update()};resolveOptions(e){return Object.assign({tipText:!0,tools:[Z.InsertTop,Z.InsertRight,Z.InsertBottom,Z.InsertLeft,Z.Break,Z.MergeCell,Z.SplitCell,Z.Break,Z.DeleteRow,Z.DeleteColumn,Z.DeleteTable,Z.Break,Z.BackgroundColor,Z.BorderColor],localstorageKey:`__table-bg-used-color`,defaultColorMap:a},e)}buildTools(){let e=document.createElement(`div`);e.classList.add(this.bem.b()),Object.assign(e.style,{display:`flex`});for(let t of this.options.tools){let{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s=``}=t,c=document.createElement(`span`);if(c.classList.add(this.bem.be(`item`)),n===`break`)c.classList.add(this.bem.is(`break`));else{let e=document.createElement(`i`);if(e.classList.add(`icon`),x(r)?e.appendChild(r(this.tableModule)):e.innerHTML=r,c.appendChild(e),a&&o){let e=this.createColorChoose(c,{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s});this.tooltipItem.push(e),c.classList.add(yr)}else x(i)&&c.addEventListener(`click`,e=>{this.quill.focus(),i.call(this,this.tableModule,this.getSelectedTds(),e)},!1);let t=this.tableModule.options.texts[n]||s;this.options.tipText&&t&&s&&this.createTipText(c,t)}e.appendChild(c)}return e}createColorChoose(e,{handle:t,key:n}){let r=document.createElement(`div`);if(r.classList.add(Q.selectWrapper),this.options.defaultColorMap.length>0){let e=document.createElement(`div`);e.classList.add(Q.map);for(let t of this.options.defaultColorMap){let n=document.createElement(`div`);n.classList.add(Q.mapRow);for(let e of t){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=e,n.appendChild(t)}e.appendChild(n)}r.appendChild(e)}let i=document.createElement(`div`);i.classList.add(Q.mapRow),Object.assign(i.style,{marginTop:`4px`});let a=document.createElement(`div`);a.classList.add(Q.btn,`transparent`),a.textContent=this.tableModule.options.texts.transparent,a.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),`transparent`)});let o=document.createElement(`div`);o.classList.add(Q.btn,`clear`),o.textContent=this.tableModule.options.texts.clear,o.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),null)});let s=document.createElement(`div`);s.classList.add(Q.btn,`custom`),s.textContent=this.tableModule.options.texts.custom;let c=le({onChange:e=>{t.call(this,this.tableModule,this.getSelectedTds(),e),this.updateUsedColor(e)}}),{hide:l,destroy:u}=Zt(s,{direction:`right`,type:`click`,content:c,container:s});i.appendChild(a),i.appendChild(o),i.appendChild(s),r.appendChild(i);let d=document.createElement(`div`);d.classList.add(Q.used,this.colorItemClass);for(let e of this.usedColors){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=e,d.appendChild(t)}r.appendChild(d),r.addEventListener(`click`,e=>{e.stopPropagation(),l();let t=e.target,r=t.style.backgroundColor,i=this.getSelectedTds();if(t&&r&&i.length>0){if(this.tableModule.setCellAttrs(i,n,r,!0),!t.closest(`.${Q.item}`))return;this.updateUsedColor(r)}});let f=Zt(e,{type:`click`,content:r,onOpen:()=>{let e=this.tableModule.getModule(`table-selection`);return this.isMenuDisplay&&e&&e.hideDisplay(),this.setActiveTooltip(f),!1},onClose:()=>{let e=this.tableModule.getModule(`table-selection`);return this.isMenuDisplay&&e&&(e.updateWithSelectedTds(),e.showDisplay()),r.contains(c)&&l(),this.activeTooltip===f&&(this.activeTooltip=null),!1},onDestroy:()=>{u(),this.activeTooltip===f&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return f.isColorPick=!0,f}setActiveTooltip(e){this.activeTooltip&&this.activeTooltip!==e&&this.activeTooltip.hide(!0),this.activeTooltip=e}getSelectedTds(){return this.tableModule.getModule(`table-selection`)?.selectedTds||[]}createTipText(e,t){let n=Zt(e,{msg:t});n&&this.tooltipItem.push(n)}show(){this.table&&(this.menu&&this.hide(),this.menu=this.buildTools())}update(){this.table&&!this.quill.root.contains(this.table)&&this.setSelectionTable(void 0)}hide(){this.menu&&=(this.menu.remove(),null);for(let e of this.tooltipItem)e.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart),this.activeTooltip=null;for(let e of this.tooltipItem)e.destroy();this.tooltipItem=[],this.hide()}},Cr=class extends Sr{colorChooseTooltipOption={direction:`right`};constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.root.addEventListener(`contextmenu`,this.listenContextmenu),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}tableSelectioChange=e=>{e.selectedTds.length<=0&&this.hide()};listenContextmenu=e=>{e.preventDefault();let t=e.composedPath();if(!t||t.length<=0)return;let n=t.find(e=>e.tagName&&e.tagName.toUpperCase()===`TABLE`&&e.classList.contains(`ql-table`)),r=this.tableModule.getModule(`table-selection`);n&&r?.selectedTds?.length?(this.menu||=this.buildTools(),Object.assign(this.menu.style,{display:`flex`}),this.isMenuDisplay=!0,this.update({x:e.clientX,y:e.clientY}),document.addEventListener(`click`,()=>{this.hide()},{once:!0})):this.hide()};buildTools(){let e=super.buildTools();e.classList.add(this.bem.is(`contextmenu`));let t=e.getElementsByClassName(yr);for(let e of Array.from(t))e.addEventListener(`click`,e=>e.stopPropagation());return document.body.appendChild(e),e}createTipText(e,t){let n=document.createElement(`span`);n.textContent=t,e.appendChild(n)}show(){}update(e){super.update();let t=this.tableModule.getModule(`table-selection`);if(!this.table||!this.isMenuDisplay||!this.menu){this.hide();return}if(!e||!t?.isDisplaySelection)return;let n={display:`flex`,left:0,top:0},{x:r,y:i}=e;n.left=r,n.top=i,Object.assign(this.menu.style,{...n,left:`${n.left+window.scrollX}px`,top:`${n.top+window.scrollY}px`});let a=this.menu.getBoundingClientRect(),{left:o,top:s}=en(a);Object.assign(this.menu.style,{left:`${o+window.scrollX}px`,top:`${s+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener(`contextmenu`,this.listenContextmenu),super.destroy(),this.quill.off(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.off(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}},wr=class extends Sr{constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.on(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.on(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectionDisplayChange)}tableSelectionDragStart=()=>{this.hide()};tableSelectionDragEnd=e=>{e.selectedTds.length>0&&this.show()};tableSelectioChange=(e,t)=>{t.length<=0&&this.hide()};tableSelectionDisplayChange=e=>{e.dragging||this.update()};buildTools(){let e=super.buildTools();return this.tableModule.addContainer(e),e}show(){super.show(),this.update()}update(){if(super.update(),!this.menu&&this.table){this.show();return}let e=this.getSelectedTds();if(!this.menu||!this.table||e.length===0){(this.menu||!this.table)&&(this.isMenuDisplay=!1,this.menu&&this.menu.classList.add(this.bem.is(`hidden`)),this.hide());return}this.isMenuDisplay=!0,this.menu.classList.remove(this.bem.is(`hidden`));let t=this.tableModule.getModule(`table-selection`);t?.isDisplaySelection&&Yt(t.cellSelect,this.menu,{placement:`bottom`,middleware:[qt(),Kt({limiter:Jt()}),Gt(20)]}).then(({x:e,y:t})=>{this.menu&&Object.assign(this.menu.style,{left:`${e}px`,top:`${t}px`})})}destroy(){super.destroy(),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.off(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd)}};const Tr=e=>!e.full&&e.align===`right`;var Er=class extends Rn{static moduleName=`table-resize`;colIndex=-1;tableBlot;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=l(`drag-line`);constructor(e,t){super(e,t),this.tableModule=e,this.quill=t}findCurrentColIndex(e){return-1}colWidthChange(e,t,n){}async createConfirmDialog({message:e,confirm:t,cancel:n}){return new Promise(r=>{let i=document.createElement(`div`);Object.assign(i.style,{padding:`8px 12px`,fontSize:`14px`,lineHeight:`1.5`});let a=document.createElement(`p`);a.textContent=e;let o=document.createElement(`div`);Object.assign(o.style,{display:`flex`,justifyContent:`flex-end`,gap:`6px`});let s=ce({content:n}),c=ce({type:`confirm`,content:t});o.appendChild(s),o.appendChild(c),i.appendChild(a),i.appendChild(o);let{close:l}=ue({child:i});s.addEventListener(`click`,()=>{r(!1),l()}),c.addEventListener(`click`,()=>{r(!0),l()})})}async handleColMouseUp(){if(!this.dragColBreak||!this.tableBlot||this.colIndex===-1)return;let e=this.tableBlot.getCols(),t=Number.parseInt(this.dragColBreak.dataset.w||`0`),i=this.tableBlot.full,a=!1,o=[];if(i){let r=this.tableBlot.domNode.getBoundingClientRect().width,i=t/r*100,s=e[this.colIndex].width;if(i<s){if(i=Math.max(n.colMinWidthPre,i),e[this.colIndex+1]||e[this.colIndex-1]){let t=e[this.colIndex+1]?this.colIndex+1:this.colIndex-1;o.push({index:t,width:e[t].width+s-i})}else i=100;a=!0,o.push({index:this.colIndex,width:i})}else if(e[this.colIndex+1]){let t=s+e[this.colIndex+1].width;i=Math.min(t-n.colMinWidthPre,i),a=!0,o.push({index:this.colIndex,width:i},{index:this.colIndex+1,width:t-i})}}else this.tableBlot.domNode.style.width=`${Number.parseFloat(this.tableBlot.domNode.style.width)-e[this.colIndex].domNode.getBoundingClientRect().width+t}px`,a=!0,o.push({index:this.colIndex,width:t});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener(`mouseup`,this.handleColMouseUpFunc),document.removeEventListener(`mousemove`,this.handleColMouseMoveFunc),this.dragging=!1,a){let t=this.tableBlot.domNode.getBoundingClientRect().width;if(i){let n=0,r=new Set(o.map(({index:e,width:t})=>(n+=t,e)));for(let[t,i]of e.entries()){if(r.has(t))continue;n+=i.width}if(n>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableBlot.cancelFull(),i=!1;for(let[e,n]of o.entries()){let{width:r,index:i}=n;o[e]={index:i,width:r/100*t}}}}for(let{index:n,width:r}of o)e[n].width=`${Math.round(r)}${i?`%`:`px`}`,this.colWidthChange(n,{px:i?Math.round(r/100*t):Math.round(r),pre:Math.round(r)},i)}this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}getColumnRect(e){if(!this.tableBlot)return null;let t=this.tableBlot.getCols();if(e>=t.length)return null;let n=t[0].domNode.getBoundingClientRect().left;for(let r=0;r<e;r++){let e=t[r].domNode.getBoundingClientRect();n+=e.width}let r=t[e].domNode.getBoundingClientRect().width;return{left:n,right:n+r,width:r}}handleColMouseMove(e){if(e.preventDefault(),!this.dragColBreak||!this.tableBlot||this.colIndex===-1)return;let t=this.tableBlot.getCols(),r=this.getColumnRect(this.colIndex),i=this.tableBlot.domNode.getBoundingClientRect(),a=e.clientX;if(this.tableBlot.full){let e=n.colMinWidthPre/100*i.width,o=i.right;a>r.right&&t[this.colIndex+1]&&(o=Math.max(this.getColumnRect(this.colIndex+1).right-e,r.left+e));let s=r.left+e;a=Math.min(Math.max(a,s),o)}else Tr(this.tableBlot)?r.right-a<n.colMinWidthPx&&(a=r.right-n.colMinWidthPx):a-r.left<n.colMinWidthPx&&(a=r.left+n.colMinWidthPx);let o=a-r.left;return Tr(this.tableBlot)&&(o=r.right-a),this.dragColBreak.style.left=`${a}px`,this.dragColBreak.dataset.w=String(o),{left:a,width:o}}handleColMouseDown(e){if(e.button!==0||(e.preventDefault(),!this.tableBlot))return;let{rect:t}=X(this.tableBlot);if(!t)return;let n=this.tableBlot.getCols();if(this.colIndex=this.findCurrentColIndex(e),this.colIndex===-1)return;let r=n[this.colIndex].width,i=this.tableBlot.full?r/100*t.width:r;document.addEventListener(`mouseup`,this.handleColMouseUpFunc),document.addEventListener(`mousemove`,this.handleColMouseMoveFunc),this.dragging=!0;let a=document.createElement(`div`);a.classList.add(this.dragBEM.b(),this.dragBEM.is(`col`)),a.dataset.w=String(i);let o={top:t.y,left:e.clientX,height:t.height};Object.assign(a.style,{top:`${o.top}px`,left:`${o.left}px`,height:`${o.height}px`});let s=document.body;return s.appendChild(a),this.dragColBreak&&s.removeChild(this.dragColBreak),this.dragColBreak=a,o}findCurrentRowIndex(e){return-1}rowHeightChange(e,t){}handleRowMouseUp(){if(!this.tableBlot||!this.dragRowBreak||this.rowIndex===-1)return;let e=Number.parseInt(this.dragRowBreak.dataset.h||`0`);this.tableBlot.getRows()[this.rowIndex].setHeight(`${e}px`),this.rowHeightChange(this.rowIndex,e),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener(`mouseup`,this.handleRowMouseUpFunc),document.removeEventListener(`mousemove`,this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}handleRowMouseMove(e){if(!this.tableBlot||!this.dragRowBreak||this.rowIndex===-1)return;e.preventDefault();let t=this.tableBlot.getRows()[this.rowIndex].domNode.getBoundingClientRect(),r=e.clientY;return r-t.y<n.rowMinHeightPx&&(r=t.y+n.rowMinHeightPx),this.dragRowBreak.style.top=`${r}px`,this.dragRowBreak.dataset.h=String(r-t.y),{top:r,height:r-t.y}}handleRowMouseDown(e){if(e.button!==0||(e.preventDefault(),!this.tableBlot)||(this.rowIndex=this.findCurrentRowIndex(e),this.rowIndex===-1))return;this.dragging=!0,document.addEventListener(`mouseup`,this.handleRowMouseUpFunc),document.addEventListener(`mousemove`,this.handleRowMouseMoveFunc);let t=this.tableBlot.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,n=this.tableBlot.domNode.getBoundingClientRect(),r=document.createElement(`div`);r.classList.add(this.dragBEM.b(),this.dragBEM.is(`row`)),r.dataset.h=String(t);let i={top:e.clientY,left:n.x,width:n.width};Object.assign(r.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});let a=document.body;return a.appendChild(r),this.dragRowBreak&&a.removeChild(this.dragRowBreak),this.dragRowBreak=r,i}update(){}destroy(){}},Dr=class extends Er{root;tableWrapperBlot;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=l(`resize-box`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.root=this.tableModule.addContainer(this.bem.b()),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};setSelectionTable(t){if(this.table!==t){if(this.hide(),this.table=t,this.table){let t=e.find(this.table);t&&(this.tableBlot=t,this.tableWrapperBlot=this.tableBlot.parent),this.show()}this.update()}}handleResizerHeader(e,t,n){if(!this.table)return;let{clientX:r,clientY:i}=n,a=this.table.getBoundingClientRect();n.shiftKey||(this.lastHeaderSelect=null);let o=[{x:e?a.left:r,y:e?i:a.top},{x:e?a.right:r,y:e?i:a.bottom}];if(this.lastHeaderSelect){let t,n;if(this.lastHeaderSelect.isX){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=Math.min(e.left,a.left),n=e.top+e.height/2}else{let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=e.left+e.width/2,n=Math.min(e.top,a.top)}this.lastHeaderSelect.isX===e?e?(o[0].y=Math.min(o[0].y,n),o[1].y=Math.max(o[1].y,n)):(o[0].x=Math.min(o[0].x,t),o[1].x=Math.max(o[1].x,t)):(o[1]={x:Math.max(o[0].x,t),y:Math.max(o[0].y,n)},o[0]={x:Math.min(o[0].x,t),y:Math.min(o[0].y,n)})}else this.lastHeaderSelect={isX:e,index:t};let s=this.tableModule.getModule(`table-selection`);s&&(s.table=this.table,s.setSelectedTds(s.computeSelectedTds(...o)),s.show())}findCurrentColIndex(e){return Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`))).indexOf(e.target)}colWidthChange(e,t,n){let r=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)));r[e].style.width=n?`${t.pre}%`:`${t.px}px`}handleColMouseDownFunc=function(e){let t=this.handleColMouseDown(e);if(t&&this.dragColBreak&&this.tableBlot){let[e]=p(this.tableBlot,U),n=e&&e.side===`top`?0:this.size;Object.assign(this.dragColBreak.style,{top:`${t.top-n}px`,left:`${t.left}px`,height:`${t.height+this.size}px`})}return t}.bind(this);bindColEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`)));L.call(this,this.tableWrapperBlot.domNode,()=>{this.colHeadWrapper.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft});for(let[t,n]of e.entries())n.addEventListener(`click`,this.handleResizerHeader.bind(this,!1,t));for(let e of t)e.addEventListener(`mousedown`,this.handleColMouseDownFunc),e.addEventListener(`dragstart`,e=>e.preventDefault())}findCurrentRowIndex(e){return Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`))).indexOf(e.target)}rowHeightChange(e,t){let n=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)));n[e].style.height=`${t}px`}handleRowMouseDownFunc=function(e){let t=this.handleRowMouseDown(e);return t&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${t.top}px`,left:`${t.left-this.size}px`,width:`${t.width+this.size}px`}),t}.bind(this);bindRowEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`)));L.call(this,this.tableWrapperBlot.domNode,()=>{this.rowHeadWrapper.scrollTop=this.tableWrapperBlot.domNode.scrollTop});for(let[t,n]of e.entries())n.addEventListener(`click`,this.handleResizerHeader.bind(this,!0,t));for(let e of t)e.addEventListener(`mousedown`,this.handleRowMouseDownFunc),e.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.tableBlot||!this.tableWrapperBlot)return;let{rect:e}=X(this.tableBlot);if(!e)return;this.root.innerHTML=``,this.tableCols=this.tableBlot.getCols(),this.tableRows=this.tableBlot.getRows();let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();if(Object.assign(this.root.style,{top:`${Math.max(e.y,t.y)-n.y}px`,left:`${Math.max(e.x,t.x)-n.x}px`}),this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement(`div`),this.corner.classList.add(this.bem.be(`corner`)),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener(`click`,()=>{let e=this.tableModule.getModule(`table-selection`);e&&this.tableBlot&&(e.setSelectedTds(this.tableBlot.descendants(H)),e.show(),e.updateWithSelectedTds())}),this.root.appendChild(this.corner)),this.tableCols.length>0){let n=``;for(let[,t]of this.tableCols.entries()){let r=t.domNode.getBoundingClientRect().width;r===0&&(r=Number.parseInt(t.domNode.getAttribute(`width`),10)),n+=`<div class="${this.bem.be(`col-header`)}" style="width: ${r}px">
|
|
129
|
+
`;const yr=`color-selector`;async function br(e,t,n=!1){let r=e.getTextByCell(t),i=e.getHTMLByCell(t,n),a=new ClipboardItem({"text/plain":new Blob([r],{type:`text/plain`}),"text/html":new Blob([i],{type:`text/html`})});await navigator.clipboard.write([a])}const Z={Break:{name:`break`},CopyCell:{name:`CopyCell`,tip:`Copy cell`,icon:sr,handle(e,t){br.call(this,e,t,!1)}},CutCell:{name:`CutCell`,tip:`Cut cell`,icon:cr,handle(e,t){br.call(this,e,t,!0)}},InsertTop:{name:`InsertTop`,icon:fr,tip:`Insert row above`,handle(e,t){e.appendRow(t,!1)}},InsertRight:{name:`InsertRight`,icon:dr,tip:`Insert column right`,handle(e,t){e.appendCol(t,!0)}},InsertBottom:{name:`InsertBottom`,icon:lr,tip:`Insert row below`,handle(e,t){e.appendRow(t,!0)}},InsertLeft:{name:`InsertLeft`,icon:ur,tip:`Insert column Left`,handle(e,t){e.appendCol(t,!1)}},MergeCell:{name:`MergeCell`,icon:pr,tip:`Merge Cell`,handle(e,t){e.mergeCells(t)}},SplitCell:{name:`SplitCell`,icon:_r,tip:`Split Cell`,handle(e,t){e.splitCell(t)}},DeleteRow:{name:`DeleteRow`,icon:hr,tip:`Delete Row`,handle(e,t){e.removeRow(t)}},DeleteColumn:{name:`DeleteColumn`,icon:mr,tip:`Delete Column`,handle(e,t){e.removeCol(t)}},DeleteTable:{name:`DeleteTable`,icon:gr,tip:`Delete table`,handle(e,t){e.deleteTable(t)}},BackgroundColor:{name:`BackgroundColor`,icon:ir,isColorChoose:!0,tip:`Set background color`,key:`background-color`,handle(e,t,n){e.setCellAttrs(t,`background-color`,n,!0)}},BorderColor:{name:`BorderColor`,icon:ar,isColorChoose:!0,tip:`Set border color`,key:`border-color`,handle(e,t,n){e.setCellAttrs(t,`border-color`,n,!0)}},SwitchWidth:{name:`SwitchWidth`,icon:rr,tip:`Switch table width`,handle(){if(!this.table)return;let t=e.find(this.table);t&&(t.full?t.cancelFull():t.setFull())}},InsertCaption:{name:`InsertCaption`,icon:vr,tip:`Insert table caption`,handle(){if(!this.table)return;let n=e.find(this.table);if(!n)return;let r=this.quill.scroll.create(`text`,`Table Caption`).wrap(t.tableCaption,{tableId:n.tableId});n.insertBefore(r,n.children.head)}},ToggleTdBetweenTh:{name:`ToggleTdBetweenTh`,icon:or,tip:`Toggle td between th`,handle(e,t){for(let e of t)e.convertTableCell()}},ConvertTothead:{name:`ConvertTothead`,icon:or,tip:`Convert to thead`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`thead`)}},ConvertTotfoot:{name:`ConvertTotfoot`,icon:or,tip:`Convert to tfoot`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`tfoot`)}}},xr=l(`color-map`),Q={selectWrapper:xr.b(),used:xr.bm(`used`),item:xr.be(`item`),btn:xr.be(`btn`),map:xr.be(`content`),mapRow:xr.be(`content-row`)};var Sr=class extends Rn{static moduleName=`table-menu`;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;tooltipItem=[];activeTooltip=null;bem=l(`menu`);colorItemClass=`color-${R()}`;colorChooseTooltipOption={direction:`top`};constructor(t,n,i){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i);try{let e=localStorage.getItem(this.options.localstorageKey)||`[]`,t=JSON.parse(e);S(t)||(t=[]),t.slice(-10).map(e=>this.usedColors.add(e))}catch{}this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart)}updateUsedColor=dn(e=>{if(!e)return;if(this.usedColors.add(e),this.usedColors.size>10){let e=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),e.map(e=>this.usedColors.add(e))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));let t=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Q.used}`));for(let n of t){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=String(e),Array.from(n.querySelectorAll(`.${Q.item}[style*="background-color: ${t.style.backgroundColor}"]`)).length<=0&&n.appendChild(t);let r=Array.from(n.querySelectorAll(`.${Q.item}`)).slice(0,-10);for(let e of r)e.remove()}},1e3);hideWhenSelectionDragStart=()=>{this.hide()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&this.isMenuDisplay&&this.update()};resolveOptions(e){return Object.assign({tipText:!0,tools:[Z.InsertTop,Z.InsertRight,Z.InsertBottom,Z.InsertLeft,Z.Break,Z.MergeCell,Z.SplitCell,Z.Break,Z.DeleteRow,Z.DeleteColumn,Z.DeleteTable,Z.Break,Z.BackgroundColor,Z.BorderColor],localstorageKey:`__table-bg-used-color`,defaultColorMap:a},e)}buildTools(){let e=document.createElement(`div`);e.classList.add(this.bem.b()),Object.assign(e.style,{display:`flex`});for(let t of this.options.tools){let{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s=``}=t,c=document.createElement(`span`);if(c.classList.add(this.bem.be(`item`)),n===`break`)c.classList.add(this.bem.is(`break`));else{let e=document.createElement(`i`);if(e.classList.add(`icon`),x(r)?e.appendChild(r(this.tableModule)):e.innerHTML=r,c.appendChild(e),a&&o){let e=this.createColorChoose(c,{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s});this.tooltipItem.push(e),c.classList.add(yr)}else x(i)&&c.addEventListener(`click`,e=>{this.quill.focus(),i.call(this,this.tableModule,this.getSelectedTds(),e)},!1);let t=this.tableModule.options.texts[n]||s;this.options.tipText&&t&&s&&this.createTipText(c,t)}e.appendChild(c)}return e}createColorChoose(e,{handle:t,key:n}){let r=document.createElement(`div`);if(r.classList.add(Q.selectWrapper),this.options.defaultColorMap.length>0){let e=document.createElement(`div`);e.classList.add(Q.map);for(let t of this.options.defaultColorMap){let n=document.createElement(`div`);n.classList.add(Q.mapRow);for(let e of t){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=e,n.appendChild(t)}e.appendChild(n)}r.appendChild(e)}let i=document.createElement(`div`);i.classList.add(Q.mapRow),Object.assign(i.style,{marginTop:`4px`});let a=document.createElement(`div`);a.classList.add(Q.btn,`transparent`),a.textContent=this.tableModule.options.texts.transparent,a.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),`transparent`)});let o=document.createElement(`div`);o.classList.add(Q.btn,`clear`),o.textContent=this.tableModule.options.texts.clear,o.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),null)});let s=document.createElement(`div`);s.classList.add(Q.btn,`custom`),s.textContent=this.tableModule.options.texts.custom;let c=le({onChange:e=>{t.call(this,this.tableModule,this.getSelectedTds(),e),this.updateUsedColor(e)}}),{hide:l,destroy:u}=Zt(s,{direction:`right`,type:`click`,content:c,container:s});i.appendChild(a),i.appendChild(o),i.appendChild(s),r.appendChild(i);let d=document.createElement(`div`);d.classList.add(Q.used,this.colorItemClass);for(let e of this.usedColors){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=e,d.appendChild(t)}r.appendChild(d),r.addEventListener(`click`,e=>{e.stopPropagation(),l();let t=e.target,r=t.style.backgroundColor,i=this.getSelectedTds();if(t&&r&&i.length>0){if(this.tableModule.setCellAttrs(i,n,r,!0),!t.closest(`.${Q.item}`))return;this.updateUsedColor(r)}});let f=Zt(e,{type:`click`,content:r,onOpen:()=>{let e=this.tableModule.getModule(`table-selection`);return this.isMenuDisplay&&e&&e.hideDisplay(),this.setActiveTooltip(f),!1},onClose:()=>{let e=this.tableModule.getModule(`table-selection`);return this.isMenuDisplay&&e&&(e.updateWithSelectedTds(),e.showDisplay()),r.contains(c)&&l(),this.activeTooltip===f&&(this.activeTooltip=null),!1},onDestroy:()=>{u(),this.activeTooltip===f&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return f.isColorPick=!0,f}setActiveTooltip(e){this.activeTooltip&&this.activeTooltip!==e&&this.activeTooltip.hide(!0),this.activeTooltip=e}getSelectedTds(){return this.tableModule.getModule(`table-selection`)?.selectedTds||[]}createTipText(e,t){let n=Zt(e,{msg:t});n&&this.tooltipItem.push(n)}show(){this.table&&(this.menu&&this.hide(),this.menu=this.buildTools())}update(){this.table&&!this.quill.root.contains(this.table)&&this.setSelectionTable(void 0)}hide(){this.menu&&=(this.menu.remove(),null);for(let e of this.tooltipItem)e.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart),this.activeTooltip=null;for(let e of this.tooltipItem)e.destroy();this.tooltipItem=[],this.hide()}},Cr=class extends Sr{colorChooseTooltipOption={direction:`right`};constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.root.addEventListener(`contextmenu`,this.listenContextmenu),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}tableSelectioChange=e=>{e.selectedTds.length<=0&&this.hide()};listenContextmenu=e=>{e.preventDefault();let t=e.composedPath();if(!t||t.length<=0)return;let n=t.find(e=>e.tagName&&e.tagName.toUpperCase()===`TABLE`&&e.classList.contains(`ql-table`)),r=this.tableModule.getModule(`table-selection`);n&&r?.selectedTds?.length?(this.menu||=this.buildTools(),Object.assign(this.menu.style,{display:`flex`}),this.isMenuDisplay=!0,this.update({x:e.clientX,y:e.clientY}),document.addEventListener(`click`,()=>{this.hide()},{once:!0})):this.hide()};buildTools(){let e=super.buildTools();e.classList.add(this.bem.is(`contextmenu`));let t=e.getElementsByClassName(yr);for(let e of Array.from(t))e.addEventListener(`click`,e=>e.stopPropagation());return document.body.appendChild(e),e}createTipText(e,t){let n=document.createElement(`span`);n.textContent=t,e.appendChild(n)}show(){}update(e){super.update();let t=this.tableModule.getModule(`table-selection`);if(!this.table||!this.isMenuDisplay||!this.menu){this.hide();return}if(!e||!t?.isDisplaySelection)return;let n={display:`flex`,left:0,top:0},{x:r,y:i}=e;n.left=r,n.top=i,Object.assign(this.menu.style,{...n,left:`${n.left+window.scrollX}px`,top:`${n.top+window.scrollY}px`});let a=this.menu.getBoundingClientRect(),{left:o,top:s}=en(a);Object.assign(this.menu.style,{left:`${o+window.scrollX}px`,top:`${s+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener(`contextmenu`,this.listenContextmenu),super.destroy(),this.quill.off(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.off(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}},wr=class extends Sr{constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.on(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.on(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectionDisplayChange)}tableSelectionDragStart=()=>{this.hide()};tableSelectionDragEnd=e=>{e.selectedTds.length>0&&this.show()};tableSelectioChange=(e,t)=>{t.length<=0&&this.hide()};tableSelectionDisplayChange=e=>{e.dragging||this.update()};buildTools(){let e=super.buildTools();return this.tableModule.addContainer(e),e}show(){super.show(),this.update()}update(){if(super.update(),!this.menu&&this.table){this.show();return}let e=this.getSelectedTds();if(!this.menu||!this.table||e.length===0){(this.menu||!this.table)&&(this.isMenuDisplay=!1,this.menu&&this.menu.classList.add(this.bem.is(`hidden`)),this.hide());return}this.isMenuDisplay=!0,this.menu.classList.remove(this.bem.is(`hidden`));let t=this.tableModule.getModule(`table-selection`);t?.isDisplaySelection&&Yt(t.cellSelect,this.menu,{placement:`bottom`,middleware:[qt(),Kt({limiter:Jt()}),Gt(20)]}).then(({x:e,y:t})=>{this.menu&&Object.assign(this.menu.style,{left:`${e}px`,top:`${t}px`})})}destroy(){super.destroy(),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.off(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd)}};const Tr=e=>!e.full&&e.align===`right`;var Er=class extends Rn{static moduleName=`table-resize`;colIndex=-1;tableBlot;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=l(`drag-line`);constructor(e,t){super(e,t),this.tableModule=e,this.quill=t}findCurrentColIndex(e){return-1}colWidthChange(e,t,n){}async createConfirmDialog({message:e,confirm:t,cancel:n}){return new Promise(r=>{let i=document.createElement(`div`);Object.assign(i.style,{padding:`8px 12px`,fontSize:`14px`,lineHeight:`1.5`});let a=document.createElement(`p`);a.textContent=e;let o=document.createElement(`div`);Object.assign(o.style,{display:`flex`,justifyContent:`flex-end`,gap:`6px`});let s=ce({content:n}),c=ce({type:`confirm`,content:t});o.appendChild(s),o.appendChild(c),i.appendChild(a),i.appendChild(o);let{close:l}=ue({child:i});s.addEventListener(`click`,()=>{r(!1),l()}),c.addEventListener(`click`,()=>{r(!0),l()})})}async handleColMouseUp(){if(!this.dragColBreak||!this.tableBlot||this.colIndex===-1)return;let e=this.tableBlot.getCols(),t=Number.parseInt(this.dragColBreak.dataset.w||`0`),i=this.tableBlot.full,a=!1,o=[];if(i){let r=this.tableBlot.domNode.getBoundingClientRect().width,i=t/r*100,s=e[this.colIndex].width;if(i<s){if(i=Math.max(n.colMinWidthPre,i),e[this.colIndex+1]||e[this.colIndex-1]){let t=e[this.colIndex+1]?this.colIndex+1:this.colIndex-1;o.push({index:t,width:e[t].width+s-i})}else i=100;a=!0,o.push({index:this.colIndex,width:i})}else if(e[this.colIndex+1]){let t=s+e[this.colIndex+1].width;i=Math.min(t-n.colMinWidthPre,i),a=!0,o.push({index:this.colIndex,width:i},{index:this.colIndex+1,width:t-i})}}else this.tableBlot.domNode.style.width=`${Number.parseFloat(this.tableBlot.domNode.style.width)-e[this.colIndex].domNode.getBoundingClientRect().width+t}px`,a=!0,o.push({index:this.colIndex,width:t});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener(`mouseup`,this.handleColMouseUpFunc),document.removeEventListener(`mousemove`,this.handleColMouseMoveFunc),this.dragging=!1,a){let t=this.tableBlot.domNode.getBoundingClientRect().width;if(i){let n=0,r=new Set(o.map(({index:e,width:t})=>(n+=t,e)));for(let[t,i]of e.entries()){if(r.has(t))continue;n+=i.width}if(n>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableBlot.cancelFull(),i=!1;for(let[e,n]of o.entries()){let{width:r,index:i}=n;o[e]={index:i,width:r/100*t}}}}for(let{index:n,width:r}of o){let a=Number.parseFloat(r.toFixed(3));e[n].width=`${a}${i?`%`:`px`}`,this.colWidthChange(n,{px:i?Math.round(r/100*t):a,pre:a},i)}}this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}getColumnRect(e){if(!this.tableBlot)return null;let t=this.tableBlot.getCols();if(e>=t.length)return null;let n=t[0].domNode.getBoundingClientRect().left;for(let r=0;r<e;r++){let e=t[r].domNode.getBoundingClientRect();n+=e.width}let r=t[e].domNode.getBoundingClientRect().width;return{left:n,right:n+r,width:r}}handleColMouseMove(e){if(e.preventDefault(),!this.dragColBreak||!this.tableBlot||this.colIndex===-1)return;let t=this.tableBlot.getCols(),r=this.getColumnRect(this.colIndex),i=this.tableBlot.domNode.getBoundingClientRect(),a=e.clientX;if(this.tableBlot.full){let e=n.colMinWidthPre/100*i.width,o=i.right;a>r.right&&t[this.colIndex+1]&&(o=Math.max(this.getColumnRect(this.colIndex+1).right-e,r.left+e));let s=r.left+e;a=Math.min(Math.max(a,s),o)}else Tr(this.tableBlot)?r.right-a<n.colMinWidthPx&&(a=r.right-n.colMinWidthPx):a-r.left<n.colMinWidthPx&&(a=r.left+n.colMinWidthPx);let o=a-r.left;return Tr(this.tableBlot)&&(o=r.right-a),this.dragColBreak.style.left=`${a}px`,this.dragColBreak.dataset.w=String(o),{left:a,width:o}}handleColMouseDown(e){if(e.button!==0||(e.preventDefault(),!this.tableBlot))return;let{rect:t}=X(this.tableBlot);if(!t)return;let n=this.tableBlot.getCols();if(this.colIndex=this.findCurrentColIndex(e),this.colIndex===-1)return;let r=n[this.colIndex].width,i=this.tableBlot.full?r/100*t.width:r;document.addEventListener(`mouseup`,this.handleColMouseUpFunc),document.addEventListener(`mousemove`,this.handleColMouseMoveFunc),this.dragging=!0;let a=document.createElement(`div`);a.classList.add(this.dragBEM.b(),this.dragBEM.is(`col`)),a.dataset.w=String(i);let o={top:t.y,left:e.clientX,height:t.height};Object.assign(a.style,{top:`${o.top}px`,left:`${o.left}px`,height:`${o.height}px`});let s=document.body;return s.appendChild(a),this.dragColBreak&&s.removeChild(this.dragColBreak),this.dragColBreak=a,o}findCurrentRowIndex(e){return-1}rowHeightChange(e,t){}handleRowMouseUp(){if(!this.tableBlot||!this.dragRowBreak||this.rowIndex===-1)return;let e=Number.parseInt(this.dragRowBreak.dataset.h||`0`);this.tableBlot.getRows()[this.rowIndex].setHeight(`${e}px`),this.rowHeightChange(this.rowIndex,e),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener(`mouseup`,this.handleRowMouseUpFunc),document.removeEventListener(`mousemove`,this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}handleRowMouseMove(e){if(!this.tableBlot||!this.dragRowBreak||this.rowIndex===-1)return;e.preventDefault();let t=this.tableBlot.getRows()[this.rowIndex].domNode.getBoundingClientRect(),r=e.clientY;return r-t.y<n.rowMinHeightPx&&(r=t.y+n.rowMinHeightPx),this.dragRowBreak.style.top=`${r}px`,this.dragRowBreak.dataset.h=String(r-t.y),{top:r,height:r-t.y}}handleRowMouseDown(e){if(e.button!==0||(e.preventDefault(),!this.tableBlot)||(this.rowIndex=this.findCurrentRowIndex(e),this.rowIndex===-1))return;this.dragging=!0,document.addEventListener(`mouseup`,this.handleRowMouseUpFunc),document.addEventListener(`mousemove`,this.handleRowMouseMoveFunc);let t=this.tableBlot.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,n=this.tableBlot.domNode.getBoundingClientRect(),r=document.createElement(`div`);r.classList.add(this.dragBEM.b(),this.dragBEM.is(`row`)),r.dataset.h=String(t);let i={top:e.clientY,left:n.x,width:n.width};Object.assign(r.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});let a=document.body;return a.appendChild(r),this.dragRowBreak&&a.removeChild(this.dragRowBreak),this.dragRowBreak=r,i}update(){}destroy(){}},Dr=class extends Er{root;tableWrapperBlot;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=l(`resize-box`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.root=this.tableModule.addContainer(this.bem.b()),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};setSelectionTable(t){if(this.table!==t){if(this.hide(),this.table=t,this.table){let t=e.find(this.table);t&&(this.tableBlot=t,this.tableWrapperBlot=this.tableBlot.parent),this.show()}this.update()}}handleResizerHeader(e,t,n){if(!this.table)return;let{clientX:r,clientY:i}=n,a=this.table.getBoundingClientRect();n.shiftKey||(this.lastHeaderSelect=null);let o=[{x:e?a.left:r,y:e?i:a.top},{x:e?a.right:r,y:e?i:a.bottom}];if(this.lastHeaderSelect){let t,n;if(this.lastHeaderSelect.isX){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=Math.min(e.left,a.left),n=e.top+e.height/2}else{let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=e.left+e.width/2,n=Math.min(e.top,a.top)}this.lastHeaderSelect.isX===e?e?(o[0].y=Math.min(o[0].y,n),o[1].y=Math.max(o[1].y,n)):(o[0].x=Math.min(o[0].x,t),o[1].x=Math.max(o[1].x,t)):(o[1]={x:Math.max(o[0].x,t),y:Math.max(o[0].y,n)},o[0]={x:Math.min(o[0].x,t),y:Math.min(o[0].y,n)})}else this.lastHeaderSelect={isX:e,index:t};let s=this.tableModule.getModule(`table-selection`);s&&(s.table=this.table,s.setSelectedTds(s.computeSelectedTds(...o)),s.show())}findCurrentColIndex(e){return Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`))).indexOf(e.target)}colWidthChange(e,t,n){let r=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)));r[e].style.width=n?`${t.pre}%`:`${t.px}px`}handleColMouseDownFunc=function(e){let t=this.handleColMouseDown(e);if(t&&this.dragColBreak&&this.tableBlot){let[e]=p(this.tableBlot,U),n=e&&e.side===`top`?0:this.size;Object.assign(this.dragColBreak.style,{top:`${t.top-n}px`,left:`${t.left}px`,height:`${t.height+this.size}px`})}return t}.bind(this);bindColEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`)));L.call(this,this.tableWrapperBlot.domNode,()=>{this.colHeadWrapper.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft});for(let[t,n]of e.entries())n.addEventListener(`click`,this.handleResizerHeader.bind(this,!1,t));for(let e of t)e.addEventListener(`mousedown`,this.handleColMouseDownFunc),e.addEventListener(`dragstart`,e=>e.preventDefault())}findCurrentRowIndex(e){return Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`))).indexOf(e.target)}rowHeightChange(e,t){let n=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)));n[e].style.height=`${t}px`}handleRowMouseDownFunc=function(e){let t=this.handleRowMouseDown(e);return t&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${t.top}px`,left:`${t.left-this.size}px`,width:`${t.width+this.size}px`}),t}.bind(this);bindRowEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`)));L.call(this,this.tableWrapperBlot.domNode,()=>{this.rowHeadWrapper.scrollTop=this.tableWrapperBlot.domNode.scrollTop});for(let[t,n]of e.entries())n.addEventListener(`click`,this.handleResizerHeader.bind(this,!0,t));for(let e of t)e.addEventListener(`mousedown`,this.handleRowMouseDownFunc),e.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.tableBlot||!this.tableWrapperBlot)return;let{rect:e}=X(this.tableBlot);if(!e)return;this.root.innerHTML=``,this.tableCols=this.tableBlot.getCols(),this.tableRows=this.tableBlot.getRows();let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();if(Object.assign(this.root.style,{top:`${Math.max(e.y,t.y)-n.y}px`,left:`${Math.max(e.x,t.x)-n.x}px`}),this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement(`div`),this.corner.classList.add(this.bem.be(`corner`)),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener(`click`,()=>{let e=this.tableModule.getModule(`table-selection`);e&&this.tableBlot&&(e.setSelectedTds(this.tableBlot.descendants(H)),e.show(),e.updateWithSelectedTds())}),this.root.appendChild(this.corner)),this.tableCols.length>0){let n=``;for(let[,t]of this.tableCols.entries()){let r=t.domNode.getBoundingClientRect().width;r===0&&(r=Number.parseInt(t.domNode.getAttribute(`width`),10)),n+=`<div class="${this.bem.be(`col-header`)}" style="width: ${r}px">
|
|
130
130
|
<div class="${this.bem.be(`col-separator`)}" style="height: ${e.height+this.size-3}px"></div>
|
|
131
131
|
</div>`}let r=document.createElement(`div`);r.classList.add(this.bem.be(`col`));let i=document.createElement(`div`);i.classList.add(this.bem.be(`col-wrapper`)),Object.assign(r.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=n,r.appendChild(i),this.root.appendChild(r),r.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft,this.colHeadWrapper=r,this.bindColEvents()}if(this.tableRows.length>0){let n=``;for(let[,t]of this.tableRows.entries()){let r=`${t.domNode.getBoundingClientRect().height}px`;n+=`<div class="${this.bem.be(`row-header`)}" style="height: ${Number.parseFloat(r)}px">
|
|
132
132
|
<div class="${this.bem.be(`row-separator`)}" style="width: ${e.width+this.size-3}px"></div>
|