quill-table-up 3.3.2 → 3.4.0

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/README.md CHANGED
@@ -69,7 +69,7 @@ const quill = new Quill('#editor', {
69
69
  | ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------ |
70
70
  | full | if set `true`. width max will be 100% | `boolean` | `false` |
71
71
  | fullSwitch | enable to choose insert a full width table | `boolean` | `true` |
72
- | texts | the text used to create the table | `TableTextOptions` | `defaultTexts` |
72
+ | texts | the text used to create the table | `TableTextOptions \| ((key: string) => string)` | `defaultTexts` |
73
73
  | customSelect | display a custom select to custom row and column number add a table. module provides default selector `defaultCustomSelect` | `(tableModule: TableUp, picker: Picker) => Promise<HTMLElement> \| HTMLElement` | - |
74
74
  | customBtn | display a custom button to custom row and column number add a table. it only when use `defaultCustomSelect` will effect | `boolean` | `false` |
75
75
  | icon | picker svg icon string. it will set with `innerHTML` | `string` | `origin table icon` |
@@ -116,6 +116,48 @@ const defaultTexts = {
116
116
 
117
117
  </details>
118
118
 
119
+ ### `texts` Dynamic Usage
120
+
121
+ You can pass `texts` as a function.\
122
+ When internal UI reads a text, it will call `texts(key)` and use the returned string.
123
+
124
+ ```ts
125
+ let locale: 'en' | 'zh' = 'en';
126
+
127
+ const textMap = {
128
+ en: {
129
+ customBtnText: 'Custom',
130
+ confirmText: 'Confirm',
131
+ cancelText: 'Cancel',
132
+ },
133
+ zh: {
134
+ customBtnText: '自定义',
135
+ confirmText: '确认',
136
+ cancelText: '取消',
137
+ },
138
+ } as const;
139
+
140
+ const quill = new Quill('#editor', {
141
+ modules: {
142
+ [TableUp.moduleName]: {
143
+ customSelect: defaultCustomSelect,
144
+ customBtn: true,
145
+ texts: key => textMap[locale][key as keyof typeof textMap.en] || '',
146
+ modules: [
147
+ { module: TableSelection },
148
+ { module: TableMenuContextmenu },
149
+ ],
150
+ },
151
+ },
152
+ });
153
+
154
+ // switch language
155
+ locale = 'zh';
156
+ await quill.getModule(TableUp.moduleName).refreshUI();
157
+ ```
158
+
159
+ `refreshUI()` will rebuild table-up UI and read latest text values.
160
+
119
161
  ## Export Internal Module
120
162
 
121
163
  ### TableSelection
package/dist/index.d.ts CHANGED
@@ -983,6 +983,7 @@ interface TableTextOptions extends TableCreatorTextOptions, TableMenuTexts {
983
983
  transparent: string;
984
984
  perWidthInsufficient: string;
985
985
  }
986
+ type TableTextOptionsInput = Partial<TableTextOptions> | ((this: TableUp, key: string) => string);
986
987
  interface TableUpExtraModule extends Constructor<any, [TableUp, Quill, any]> {
987
988
  moduleName: string;
988
989
  }
@@ -1000,6 +1001,9 @@ interface TableUpOptions {
1000
1001
  autoMergeCell: boolean;
1001
1002
  modules: TableUpModule[];
1002
1003
  }
1004
+ interface TableUpOptionsInput extends Partial<Omit<TableUpOptions, 'texts'>> {
1005
+ texts?: TableTextOptionsInput;
1006
+ }
1003
1007
  interface TableColValue {
1004
1008
  tableId: string;
1005
1009
  colId: string;
@@ -1225,6 +1229,7 @@ declare class TableUp {
1225
1229
  static register(): void;
1226
1230
  quill: Quill;
1227
1231
  options: TableUpOptions;
1232
+ textOptionsInput: TableTextOptionsInput | undefined;
1228
1233
  toolBox: HTMLDivElement;
1229
1234
  fixTableByLisenter: (this: any) => void;
1230
1235
  selector?: HTMLElement;
@@ -1232,36 +1237,13 @@ declare class TableUp {
1232
1237
  editableObserver: MutationObserver;
1233
1238
  modules: Record<string, Constructor>;
1234
1239
  get statics(): any;
1235
- constructor(quill: Quill, options: Partial<TableUpOptions>);
1240
+ constructor(quill: Quill, options: TableUpOptionsInput);
1236
1241
  initialContainer(): HTMLDivElement;
1237
1242
  addContainer(classes: string | HTMLElement): HTMLElement;
1238
- resolveOptions(options: Partial<TableUpOptions>): TableUpOptions;
1239
- resolveTexts(options: Partial<TableTextOptions>): {
1240
- fullCheckboxText: string;
1241
- customBtnText: string;
1242
- confirmText: string;
1243
- cancelText: string;
1244
- rowText: string;
1245
- colText: string;
1246
- notPositiveNumberError: string;
1247
- custom: string;
1248
- clear: string;
1249
- transparent: string;
1250
- perWidthInsufficient: string;
1251
- CopyCell: string;
1252
- CutCell: string;
1253
- InsertTop: string;
1254
- InsertRight: string;
1255
- InsertBottom: string;
1256
- InsertLeft: string;
1257
- MergeCell: string;
1258
- SplitCell: string;
1259
- DeleteRow: string;
1260
- DeleteColumn: string;
1261
- DeleteTable: string;
1262
- BackgroundColor: string;
1263
- BorderColor: string;
1264
- } & Partial<TableTextOptions>;
1243
+ getToolbarPicker(): QuillThemePicker | undefined;
1244
+ resolveOptions(options: TableUpOptionsInput): TableUpOptions;
1245
+ resolveTexts(options?: TableTextOptionsInput): TableTextOptions;
1246
+ refreshUI(): Promise<void>;
1265
1247
  initModules(): void;
1266
1248
  listenEditableChange(): void;
1267
1249
  destroyModules(): void;
@@ -1290,5 +1272,5 @@ declare class TableUp {
1290
1272
  convertTableBodyByCells(tableBlot: TableMainFormat, selecteds: TableCellInnerFormat[], tag: TableBodyTag): void;
1291
1273
  }
1292
1274
  //#endregion
1293
- export { BlockEmbedOverride, BlockOverride, ClipboardOptions, Constructor, ContainerFormat, InternalModule, InternalTableMenuModule, InternalTableSelectionModule, Matcher, MenuTooltipInstance, Position, QuillTheme, QuillThemePicker, RelactiveRect, ScrollOverride, Scrollbar, SelectionData, Selector, SkipRowCount, TableAlign, TableBodyFormat, TableBodyTag, TableCaptionFormat, TableCaptionValue, TableCellFormat, TableCellInnerFormat, TableCellValue, TableClipboard, TableColFormat, TableColValue, TableColgroupFormat, TableConstantsData, TableCreatorTextOptions, TableDomSelector, TableFootFormat, TableHeadFormat, TableMainFormat, TableMenuCommon, TableMenuContextmenu, TableMenuOptions, TableMenuOptionsInput, TableMenuSelect, TableMenuTexts, TableModuleLifecycle, TableResizeBox, TableResizeBoxOptions, TableResizeCommon, TableResizeCommonHelper, TableResizeLine, TableResizeScale, TableResizeScaleOptions, TableRowFormat, TableRowValue, TableSelection, TableSelectionOptions, TableTextOptions, TableUp, TableUp as default, TableUpExtraModule, TableUpModule, TableUpOptions, TableValue, TableVirtualScrollbar, TableWrapperFormat, Tool, ToolOption, ToolOptionBreak, Writable, applyCellUpdates, blotName, createColorPicker, createSelectBox, createTooltip, defaultCustomSelect, findParentBlot, findParentBlots, getCellPositions, getColRect, getCountByPosition, getTableCellStructure, getTableMainRect, groupCellByRow, isCellsSpan, isTableAlignRight, parsePasteDelta, pasteCells, pasteWithLoop, pasteWithStructure, prepareCellUpdate, randomId, removeOverlappingCells, tableMenuTools, tableUpEvent, tableUpInternal, tableUpSize, updateTableConstants };
1275
+ export { BlockEmbedOverride, BlockOverride, ClipboardOptions, Constructor, ContainerFormat, InternalModule, InternalTableMenuModule, InternalTableSelectionModule, Matcher, MenuTooltipInstance, Position, QuillTheme, QuillThemePicker, RelactiveRect, ScrollOverride, Scrollbar, SelectionData, Selector, SkipRowCount, TableAlign, TableBodyFormat, TableBodyTag, TableCaptionFormat, TableCaptionValue, TableCellFormat, TableCellInnerFormat, TableCellValue, TableClipboard, TableColFormat, TableColValue, TableColgroupFormat, TableConstantsData, TableCreatorTextOptions, TableDomSelector, TableFootFormat, TableHeadFormat, TableMainFormat, TableMenuCommon, TableMenuContextmenu, TableMenuOptions, TableMenuOptionsInput, TableMenuSelect, TableMenuTexts, TableModuleLifecycle, TableResizeBox, TableResizeBoxOptions, TableResizeCommon, TableResizeCommonHelper, TableResizeLine, TableResizeScale, TableResizeScaleOptions, TableRowFormat, TableRowValue, TableSelection, TableSelectionOptions, TableTextOptions, TableTextOptionsInput, TableUp, TableUp as default, TableUpExtraModule, TableUpModule, TableUpOptions, TableUpOptionsInput, TableValue, TableVirtualScrollbar, TableWrapperFormat, Tool, ToolOption, ToolOptionBreak, Writable, applyCellUpdates, blotName, createColorPicker, createSelectBox, createTooltip, defaultCustomSelect, findParentBlot, findParentBlots, getCellPositions, getColRect, getCountByPosition, getTableCellStructure, getTableMainRect, groupCellByRow, isCellsSpan, isTableAlignRight, parsePasteDelta, pasteCells, pasteWithLoop, pasteWithStructure, prepareCellUpdate, randomId, removeOverlappingCells, tableMenuTools, tableUpEvent, tableUpInternal, tableUpSize, updateTableConstants };
1294
1276
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -130,7 +130,7 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
130
130
  <div class="${this.bem.be(`col-separator`)}" style="height: ${e.height+this.options.size-3}px"></div>
131
131
  </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`col`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`col-wrapper`)),Object.assign(i.style,{transform:`translateY(-${this.options.size}px)`,maxWidth:`${r.width}px`,height:`${this.options.size}px`}),Object.assign(a.style,{width:`${e.width}px`}),a.innerHTML=n,i.appendChild(a),this.root.appendChild(i),i.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft,this.colHeadWrapper=i,this.bindColEvents()}if(n.length>0){let t=``;for(let r=0;r<n.length;r++){let i=r,a=n[r],o=a.domNode.getBoundingClientRect().height;if(a.children.length===1&&(a.children.head?.emptyRow.length||0)>0){let e=a.children.head.emptyRow.length;for(let t=r+1;t<n.length&&t<=r+e;t++){let e=n[t];o+=e.domNode.getBoundingClientRect().height}r+=e}t+=`<div class="${this.bem.be(`row-header`)}" data-index="${i}" style="height: ${o}px">
132
132
  <div class="${this.bem.be(`row-separator`)}" style="width: ${e.width+this.options.size-3}px"></div>
133
- </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`row`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`row-wrapper`)),Object.assign(i.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${r.height}px`}),Object.assign(a.style,{height:`${e.height}px`}),a.innerHTML=t,i.appendChild(a),this.root.appendChild(i),i.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}let[o]=p(this.tableBlot,Rn),s=!o||o?.side!==`top`;s?this.root.classList.remove(this.bem.is(`caption-bottom`)):this.root.classList.add(this.bem.is(`caption-bottom`));let c=-1*this.options.size,l=-1*this.options.size;kr(this.tableBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c=Math.min(r.width,e.width),l=Math.min(r.width,e.width)):this.root.classList.remove(this.bem.is(`align-right`)),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${c}px)`,top:`${s?0:e.height+this.options.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`,maxHeight:`${r.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${s?0:e.height+this.options.size}px`,maxWidth:`${r.width}px`})}show(){!this.table||!this.tableBlot||(this.root.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=an(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),F.call(this,this.quill.root,()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is(`hidden`)),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0)}destroy(){super.destroy(),this.hide(),I.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.root.remove()}},Lr=class extends Nr{static moduleName=`table-resize-line`;colResizer;rowResizer;currentTableCell;tableCellBlot;bem=l(`resize-line`);stopColDrag;stopRowDrag;scrollHandler=[];constructor(t,n){super(t,n),this.tableModule=t,this.quill=n,this.colResizer=this.tableModule.addContainer(this.bem.be(`col`)),this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show())}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};findTableCell(e){for(let t of e.composedPath()){if(t instanceof HTMLElement&&[`TD`,`TH`].includes(t.tagName))return t;if(t===document.body)return null}return null}pointermoveHandler=n=>{if(this.dragging||this.tableModule.getModule(i.tableSelectionName)?.dragging)return;let r=this.findTableCell(n);if(!r)return this.hide();let a=e.find(r);a&&this.currentTableCell!==r&&(this.show(),this.currentTableCell=r,this.tableCellBlot=a,this.tableBlot=u(a,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer(),F.call(this,this.quill.root,()=>{this.dragging||this.hideResizer()}))};findDragColIndex(e){return this.tableCellBlot?e.findIndex(e=>e.colId===this.tableCellBlot.colId):-1}updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;this.colResizer.remove();let{rect:e}=J(this.tableBlot);if(!e)return;this.colResizer=this.tableModule.addContainer(this.bem.be(`col`));let t=this.tableCellBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),r=t.right-n.x;kr(this.tableBlot)&&(r=t.left-n.x),Object.assign(this.colResizer.style,{top:`${e.y-n.y}px`,left:`${r}px`,height:`${e.height}px`});let{stop:i}=en(this.colResizer,{axis:`x`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragXCommon.startValue=r.x;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:`${Math.max(n.y,r.y)-i.y}px`,left:`${t.clientX-i.x}px`,height:`${Math.min(n.height,r.height)}px`})},onMove:({position:e})=>{if(!this.dragXCommon.dragBreak)return;let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=`${t-n.x}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.colResizer){let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.colResizer.style.left=`${t-n.x}px`}this.updateTableCol(e.x),this.removeBreak()}});this.stopColDrag&&this.stopColDrag(),this.stopColDrag=i,this.colResizer.addEventListener(`dragstart`,e=>e.preventDefault())}findDragRowIndex(e){if(!this.tableCellBlot)return-1;let t=this.tableCellBlot.parent;return t instanceof H?e.indexOf(t):-1}updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let e=this.tableCellBlot;this.rowResizer.remove();let{rect:t}=J(this.tableBlot);if(!t)return;this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`));let n=e.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:`${n.bottom-r.y}px`,left:`${t.x-r.x}px`,width:`${t.width}px`});let{stop:i}=en(this.rowResizer,{axis:`y`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragYCommon.startValue=r.y;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:`${t.clientY-i.y}px`,left:`${Math.max(n.x,r.x)-i.x}px`,width:`${Math.min(n.width,r.width)}px`})},onMove:({position:e})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=`${t-n.y}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.rowResizer){let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.rowResizer.style.left=`${t-n.y}px`}this.updateTableRow(e.y),this.removeBreak()}});this.stopRowDrag&&this.stopRowDrag(),this.stopRowDrag=i,this.rowResizer.addEventListener(`dragstart`,e=>e.preventDefault())}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is(`hidden`)),this.colResizer.classList.remove(this.bem.is(`hidden`)),this.table.addEventListener(`pointermove`,this.pointermoveHandler))}hideResizer(){!this.rowResizer||!this.colResizer||(this.rowResizer.classList.add(this.bem.is(`hidden`)),this.colResizer.classList.add(this.bem.is(`hidden`)))}hide(){this.currentTableCell=void 0,I.call(this),this.hideResizer(),this.table&&this.table.removeEventListener(`pointermove`,this.pointermoveHandler)}destroy(){super.destroy(),this.colResizer&&=(this.colResizer.remove(),void 0),this.rowResizer&&=(this.rowResizer.remove(),void 0),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},Rr=class extends Y{static moduleName=`table-resize-scale`;scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l(`scale`);options;root;block;resizeobserver=new ResizeObserver(()=>this.update());constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(r),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())};resolveOptions(e){return Object.assign({blockSize:12,offset:6},e)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.block=document.createElement(`div`),this.block.classList.add(this.bem.be(`block`)),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let e=[],t=[];en(this.block,{onStart:()=>{this.tableMainBlot&&(e=this.tableMainBlot.getCols().map(e=>({blot:e,width:Math.floor(e.width)})),t=this.tableMainBlot.getRows().map(e=>({blot:e,height:Math.floor(e.domNode.getBoundingClientRect().height)})))},onMove:({movePosition:r})=>{if(!this.tableMainBlot)return;let i=kr(this.tableMainBlot)?-1:1,a=r.x*i,o=r.y,s=Math.floor(a/e.length),c=Math.floor(o/t.length);for(let{blot:t,width:r}of e)t.width=Math.max(r+s,n.colMinWidthPx);for(let{blot:e,height:r}of t)e.setHeight(`${Math.max(r+c,n.rowMinHeightPx)}px`)},onEnd:()=>{e=[],t=[]}}),this.block.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.block||!this.root||!this.tableMainBlot||!this.tableWrapperBlot)return;if(this.tableMainBlot.full){this.hide();return}let{rect:e}=J(this.tableMainBlot);if(!e)return;let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),{scrollTop:r,scrollLeft:i}=this.tableWrapperBlot.domNode,a=this.options.blockSize*2+this.options.offset,o=Math.min(e.width,t.width)+a,s=Math.min(e.height,t.height)+a;Object.assign(this.root.style,{width:`${o}px`,height:`${s}px`,left:`${Math.max(e.x,t.x)-n.x-this.options.blockSize}px`,top:`${Math.max(e.y,t.y)-n.y-this.options.blockSize}px`});let c={left:`${e.width+a-i}px`,top:`${s-r}px`};kr(this.tableMainBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is(`align-right`)),Object.assign(this.block.style,c)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),F.call(this,this.quill.root,()=>this.update()),F.call(this,this.tableWrapperBlot.domNode,()=>this.update())),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0),I.call(this)}destroy(){super.destroy(),this.hide(),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect()}};const zr={size:`height`,offset:`offsetHeight`,scrollDirection:`scrollTop`,scrollSize:`scrollHeight`,axis:`y`,direction:`top`,client:`clientY`},Br={size:`width`,offset:`offsetWidth`,scrollDirection:`scrollLeft`,scrollSize:`scrollWidth`,axis:`x`,direction:`left`,client:`clientX`};var Vr=class{minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth=``;sizeHeight=``;size=``;bem=l(`scrollbar`);tableMainBlot;ob;container;scrollbar;thumb=document.createElement(`div`);scrollHandler=[];propertyMap;thumbState={x:0,y:0};get isVertical(){return this.options.isVertical}constructor(t,n,r){this.quill=t,this.table=n,this.options=r,this.tableMainBlot=e.find(this.table),this.container=n.parentElement,this.propertyMap=this.isVertical?zr:Br,this.calculateSize(),this.ob=new ResizeObserver(()=>this.update()),this.ob.observe(n),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),F.call(this,this.quill.root,()=>this.setScrollbarPosition()),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:e,head:t,body:n,foot:r}=J(this.tableMainBlot),i=t||n||r;if(!i||!e)return;let{scrollLeft:a,scrollTop:o,offsetLeft:s,offsetTop:c}=this.quill.root,{offsetLeft:l,offsetTop:u}=this.container,{offsetLeft:d,offsetTop:f}=i.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),h=l+d-s,g=u+f-c;this.isVertical?h+=Math.min(p,e.width):g+=Math.min(m,e.height),this.tableMainBlot&&this.tableMainBlot.align!==`left`&&(h+=this.table.offsetLeft-l),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,e.height):p}px`,transform:`translate(${h-a}px, ${g-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let e=this.container.offsetHeight-this.gap,t=this.container.offsetWidth-this.gap,n=e**2/this.container.scrollHeight,r=t**2/this.container.scrollWidth,i=Math.max(n,this.minSize),a=Math.max(r,this.minSize);this.ratioY=n/(e-n)/(i/(e-i)),this.ratioX=r/(t-r)/(a/(t-a)),this.sizeWidth=a+this.gap<t?`${a}px`:``,this.sizeHeight=i+this.gap<e?`${i}px`:``,this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let e=document.createElement(`div`);e.classList.add(this.bem.b(),this.isVertical?this.bem.is(`vertical`):this.bem.is(`horizontal`),this.bem.is(`transparent`)),Object.assign(e.style,{display:`none`}),this.thumb.classList.add(this.bem.be(`thumb`));let t=null,n=e=>{if(this.cursorDown===!1)return;let t=this.thumbState[this.propertyMap.axis];if(!t)return;let n=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],r=((this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-e[this.propertyMap.client])*-1-(this.thumb[this.propertyMap.offset]-t))*100*n/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=r*this.container[this.propertyMap.scrollSize]/100},r=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=t},i=e=>{e.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r),t=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener(`mousedown`,e=>{if(e.stopPropagation(),e.ctrlKey||[1,2].includes(e.button))return;window.getSelection()?.removeAllRanges(),i(e);let t=e.currentTarget;t&&(this.thumbState[this.propertyMap.axis]=t[this.propertyMap.offset]-(e[this.propertyMap.client]-t.getBoundingClientRect()[this.propertyMap.direction]))});let a=[this.table,e];for(let e of a)e.addEventListener(`mouseenter`,this.showScrollbar),e.addEventListener(`mouseleave`,this.hideScrollbar);return F.call(this,this.container,()=>{this.containerScrollHandler(this.container)}),e.appendChild(this.thumb),e}containerScrollHandler(e){let t=e[this.propertyMap.offset]-this.gap;this.move=e[this.propertyMap.scrollDirection]*100/t*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis.toUpperCase()}(${this.move}%)`})}showScrollbar=hn(()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?`block`:`none`,requestAnimationFrame(()=>{this.scrollbar.classList.remove(this.bem.is(`transparent`))})},200);hideScrollbar=hn(()=>{this.cursorLeave=!0,!this.cursorDown&&(this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.addEventListener(`transitionend`,this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is(`transparent`)))},200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?`block`:`none`};destroy(){this.ob.disconnect(),I.call(this),this.table.removeEventListener(`mouseenter`,this.showScrollbar),this.table.removeEventListener(`mouseleave`,this.hideScrollbar)}},Hr=class extends Y{static moduleName=`table-scrollbar`;scrollbarContainer;scrollbar=[];bem=l(`scrollbar`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n;let i=l(`scrollbar`);this.quill.container.classList.add(i.bm(`virtual`)),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be(`container`)),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())};hide(){for(let e of this.scrollbar)e.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=``}show(){if(this.table){this.scrollbar=[new Vr(this.quill,this.table,{isVertical:!0}),new Vr(this.quill,this.table,{isVertical:!1})];for(let e of this.scrollbar)this.scrollbarContainer.appendChild(e.scrollbar),e.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let e of this.scrollbar)e.calculateSize(),e.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){super.destroy(),this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Ur=class extends Y{static moduleName=i.tableSelectionName;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l(`selection`);autoScroller;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(e){this._dragging!==e&&(this._dragging=e,this.quill.emitter.emit(e?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,n,i={}){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=an(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener(`paste`,this.handlePaste),document.addEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.autoScroller=new ln(50,40),this.hide()}handlePaste=e=>{if(!(document.activeElement&&this.quill.root.contains(document.activeElement))||this.quill.getSelection())return;let n=e.clipboardData;if(!n)return;e.preventDefault();let r=this.selectedTds;if(r.length<=0)return;let i=n.getData(`text/html`),a=this.quill.clipboard.convert({html:i}).ops.filter(e=>e.attributes?.[t.tableCellInner]);a.length!==0&&Gn({quill:this.quill,talbeModule:this.tableModule},r,a)};keyboardHandler=async e=>{if(e.ctrlKey)switch(e.key){case`c`:case`x`:await wr(this.tableModule,this.selectedTds,e.key===`x`);break}else (e.key===`Backspace`||e.key===`Delete`)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let e of this.selectedTds)if(!e.domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),n=document.activeElement;if(!(t||!this.quill.root.contains(n))){if(this.table){let t=e.find(this.table),n=t.descendants(V);if(this.selectedTds.length===n.length){t.remove();return}}for(let e of this.selectedTds){let t=e.clone();t.appendChild(e.scroll.create(`block`)),e.parent.insertBefore(t,e),e.remove()}}}setSelectedTds(e){let t=new Set(this.selectedTds),n=this.selectedTds.length===e.length&&e.every(e=>t.has(e));this.selectedTds=e,n||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}quillSelectionChangeHandler=(n,r,i)=>{if(i!==e.sources.API&&n&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(n),[r]=this.quill.getLine(n.index),i=!!e[t.tableCellInner]&&!!r,a=r&&this.selectedTds.some(e=>e.domNode.contains(r.domNode));if(i&&!a)try{let e=u(r,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else i&&a||this.hide()}};setSelectionData(e,t){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=t;if(!n||!i)return;let o=document.createRange(),s=this.selectionDirectionUp(t);s?(o.setStart(n,r),o.setEnd(n,r)):(o.setStart(n,r),o.setEnd(i,a)),e.removeAllRanges(),e.addRange(o),s&&e.extend(i,a)}selectionDirectionUp(e){let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:i}=e;if(!t||!r)return!1;if(t===r)return n>i;let a=t.compareDocumentPosition(r);return a&Node.DOCUMENT_POSITION_CONTAINS||a&Node.DOCUMENT_POSITION_CONTAINED_BY?(a&Node.DOCUMENT_POSITION_FOLLOWING)!==0:(a&Node.DOCUMENT_POSITION_PRECEDING)!==0}resolveOptions(e){return Object.assign({selectColor:`#0589f340`},e)}selectionChangeHandler=()=>{let n=window.getSelection();if(!n)return;let{anchorNode:r,focusNode:i,anchorOffset:a,focusOffset:o}=n;if(!r||!i)return;let s=e.find(r),c=e.find(i);if(!s||!c||s.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;let l=f(s),u=f(c),d=l.has(t.tableColgroup),p=u.has(t.tableColgroup);if(d||p){let e=r,s=a,c=i,f=o;if(d){let n=l.get(t.tableWrapper).descendants(V);n.length>0&&(e=n[0].domNode,s=0)}if(p){let e=u.get(t.tableWrapper).descendants(V);e.length>0&&(c=e[0].domNode,f=0)}this.setSelectionData(n,{anchorNode:e,anchorOffset:s,focusNode:c,focusOffset:f});return}let m=l.has(t.tableCellInner),h=u.has(t.tableCellInner),g=m&&h;if(g){let e=l.get(t.tableCellInner),n=u.get(t.tableCellInner);g&&=e!==n}if(m&&h&&g||!m&&h||!h&&m){this.setSelectionData(n,this.lastSelection),this.selectedTds.length>0&&this.hide();return}this.lastSelection={anchorNode:r,anchorOffset:a,focusNode:i,focusOffset:o}};helpLinesInitial(){this.cellSelectWrap.style.setProperty(`--select-color`,this.options.selectColor);let e=document.createElement(`div`);return e.classList.add(this.bem.be(`line`)),this.cellSelectWrap.appendChild(e),e}computeSelectedTds(t,n){if(!this.table)return[];let r=e.find(this.table);if(!r)return[];let i=new Set(r.descendants(U).map((e,t)=>(e.index=t,e))),a=this.getScrollPositionDiff(),{rect:o}=J(r);if(!o)return[];let s=t.x+a.x,c=t.y+a.y,l={x:Math.max(o.left,Math.min(n.x,s)),y:Math.max(o.top,Math.min(n.y,c)),x1:Math.min(o.right,Math.max(n.x,s)),y1:Math.min(o.bottom,Math.max(n.y,c))},u=new Set,d=!0;for(;d;){d=!1;for(let e of i){e.__rect||=e.domNode.getBoundingClientRect();let{x:t,y:n,right:r,bottom:a}=e.__rect;if(tn({x:Math.floor(l.x),y:Math.floor(l.y),x1:Math.floor(l.x1),y1:Math.floor(l.y1)},{x:Math.floor(t),y:Math.floor(n),x1:Math.floor(r),y1:Math.floor(a)},0,u.size===0)){u.add(e),i.delete(e),l={x:Math.min(l.x,t),y:Math.min(l.y,n),x1:Math.max(l.x1,r),y1:Math.max(l.y1,a)},d=!0;break}}}for(let e of[...u,...i])delete e.__rect;return this.boundary=nn({...l,width:l.x1-l.x,height:l.y1-l.y},this.quill.root),Array.from(u).toSorted((e,t)=>e.index-t.index).map(e=>(delete e.index,e.getCellInner()))}getScrollPositionDiff(){let{x:e,y:t}=this.getTableViewScroll(),{x:n,y:r}=sn(this.quill.root);return this.selectedTableScrollX=e,this.selectedTableScrollY=t,this.selectedEditorScrollX=n,this.selectedEditorScrollY=r,this.startScrollRecordPosition.reduce((e,{x:t,y:n},r)=>{let{x:i,y:a}=sn(this.scrollRecordEls[r]);return e.x+=t-i,e.y+=n-a,e},{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let e of this.scrollRecordEls)this.startScrollRecordPosition.push(sn(e))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(t){let{button:n,target:r,clientX:i,clientY:a}=t,o=r.closest(`table`),s=r.closest(`caption`);if(n!==0||!o||s)return;this.setSelectionTable(o);let c=o.dataset.tableId,l={x:i,y:a};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(l,l)),this.show();let u=e=>{this.dragging=!0;let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`.ql-table`),o=n.closest(`caption`);if(t!==0||o||!a||a.dataset.tableId!==c)return;let s={x:r,y:i};this.setSelectedTds(this.computeSelectedTds(l,s)),this.selectedTds.length>1&&this.quill.blur(),this.update(),this.autoScroller.updateMousePosition(r,i)},d=()=>{document.body.removeEventListener(`mousemove`,u,!1),document.body.removeEventListener(`mouseup`,d,!1),this.autoScroller.stop(),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener(`mousemove`,u,!1),document.body.addEventListener(`mouseup`,d,!1);let f=e.find(o);if(!f)return;let p=f.parent.domNode;this.autoScroller.updateMousePosition(i,a),this.autoScroller.start(p)}updateWithSelectedTds(){if(this.selectedTds.length<=0){this.hide();return}let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.selectedTds){let r=n.domNode.getBoundingClientRect();e.x=Math.min(e.x,r.left),e.y=Math.min(e.y,r.top),t.x=Math.max(t.x,r.right),t.y=Math.max(t.y,r.bottom)}this.setSelectedTds(this.computeSelectedTds(e,t)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table){this.hide();return}if(this.selectedTds.length===0||!this.boundary)return;let{x:e,y:t}=sn(this.quill.root),{x:n,y:i}=this.getTableViewScroll(),a=this.table.parentElement.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),s=a.x-o.x,c=a.y-o.y;Object.assign(this.cellSelect.style,{left:`${this.selectedEditorScrollX*2-e+this.boundary.x+this.selectedTableScrollX-n-s}px`,top:`${this.selectedEditorScrollY*2-t+this.boundary.y+this.selectedTableScrollY-i-c}px`,width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${s}px`,top:`${c}px`,width:`${a.width}px`,height:`${a.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?sn(this.table.parentElement):{x:0,y:0}}setSelectionTable(e){this.table!==e&&(this.table=e,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:`block`}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(I.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener(`keydown`,this.keyboardHandler),F.call(this,this.quill.root,()=>{this.update()}),F.call(this,this.table.parentElement,()=>{this.update()}))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:`none`}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){I.call(this),this.quill.root.removeEventListener(`keydown`,this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){super.destroy(),this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),I.call(this),document.removeEventListener(`paste`,this.handlePaste),document.removeEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Wr=e.import(`parchment`),$=e.import(`delta`),Gr=e.import(`ui/icons`),Kr=e.import(`blots/break`),qr=e.import(`blots/block`),Jr=e.import(`blots/block/embed`);function Yr(e,{tableId:n,rowId:r,colId:i}){let a={tableId:n,rowId:r,colId:i,colspan:1,rowspan:1},o=e.create(t.tableCell,a),s=e.create(t.tableCellInner,a),c=e.create(`block`);return c.appendChild(e.create(`break`)),s.appendChild(c),o.appendChild(s),o}function Xr(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),$r.moduleName=i.moduleName,$r.toolName=t.tableWrapper,R.blotName=t.container,Rn.blotName=t.tableCaption,q.blotName=t.tableWrapper,G.blotName=t.tableMain,K.blotName=t.tableColgroup,W.blotName=t.tableCol,Vn.blotName=t.tableHead,B.blotName=t.tableBody,Bn.blotName=t.tableFoot,H.blotName=t.tableRow,U.blotName=t.tableCell,V.blotName=t.tableCellInner,o.add(t.tableCellInner)}function Zr(t,n){return w({onSelect:(r,i)=>{t.insertTable(r,i,e.sources.USER),n&&n.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Qr(n){return{bindInHead:!1,key:n?`ArrowUp`:`ArrowDown`,collapsed:!0,format:[t.tableCellInner],handler(r,i){let a=n?`prev`:`next`,o=n?`tail`:`head`;if(i.line[a])return!0;let s=this.quill.selection.getBounds(r.index),c=i.line.domNode.getBoundingClientRect();if(!s||!c)return!0;if(n){if(s.top-c.top>3)return!0}else if(c.bottom-s.bottom>3)return!0;let l,u,f,p;try{[l,u,f,p]=d(i.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m=u.getColIds(),h=l.descendants(Rn,0)[0],g;if(h){let e=window.getComputedStyle(h.domNode);g=a===`next`&&e.captionSide===`bottom`?h:a===`next`?l.next:h}else g=l[a];if(i.line[a]||!g)return!0;let _=f[a];if(_){let t=m.indexOf(p.colId),n=_.getCellByColId(m[t],a);if(!n)return!0;let r=n.children[o];r.children&&(r=r.children[o]);let s=r.offset(this.quill.scroll)+Math.min(i.offset,r.length()-1);this.quill.setSelection(s,0,e.sources.USER)}else{let t=g.offset(this.quill.scroll)+(n?g.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var $r=class r{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:`Backspace`,collapsed:!0,offset:0,handler(e,n){let r=this.quill.getLine(e.index)[0];return r.prev instanceof q?(r.prev.remove(),!1):!(n.format[t.tableCellInner]&&r.offset(u(r,t.tableCellInner))===0)}},"forbid remove table by delete":{bindInHead:!0,key:`Delete`,collapsed:!0,handler(e,n){let r=this.quill.getLine(e.index),i=r[0],a=r[1];return!((i.next instanceof q||i.next instanceof W)&&a===i.length()-1||n.format[t.tableCellInner]&&i===u(i,t.tableCellInner).children.tail&&a===i.length()-1)}},"table up":Qr(!0),"table down":Qr(!1),"table caption break":{bindInHead:!0,key:`Enter`,shiftKey:null,format:[t.tableCaption],handler(e,t){return!1}}};static register(){q.allowedChildren=[G],G.allowedChildren=[K,Rn,Vn,B,Bn],G.requiredContainer=q,Rn.requiredContainer=G,K.allowedChildren=[W],K.requiredContainer=G,Vn.allowedChildren=[H],Vn.requiredContainer=G,B.allowedChildren=[H],B.requiredContainer=G,Bn.allowedChildren=[H],Bn.requiredContainer=G,H.allowedChildren=[U],U.allowedChildren=[V,Kr],U.requiredContainer=H,V.requiredContainer=U;let n=new Set([`table`]),r=Object.entries(e.imports).filter(([e,t])=>{let r=e.split(`formats/`)[1];return e.startsWith(`formats/`)&&!n.has(r)&&(g(t,qr)||g(t,Jr))}).reduce((e,[t,n])=>{let r=g(n,Jr)?Dn:Tn;return e[t]=class extends h(n,[r]){static register(){}},e},{});e.register({"blots/scroll":Nn,"blots/block":Tn,"blots/block/embed":Dn,...r,[`blots/${t.container}`]:R,[`formats/${t.tableCell}`]:U,[`formats/${t.tableCellInner}`]:V,[`formats/${t.tableRow}`]:H,[`formats/${t.tableHead}`]:Vn,[`formats/${t.tableBody}`]:B,[`formats/${t.tableFoot}`]:Bn,[`formats/${t.tableCol}`]:W,[`formats/${t.tableColgroup}`]:K,[`formats/${t.tableCaption}`]:Rn,[`formats/${t.tableMain}`]:G,[`formats/${t.tableWrapper}`]:q,"modules/clipboard":or},!0)}quill;options;toolBox;fixTableByLisenter=hn(this.balanceTables,100);selector;resizeOb;editableObserver;modules={};get statics(){return this.constructor}constructor(e,t){this.quill=e,this.options=this.resolveOptions(t||{}),this.toolBox=this.initialContainer();let n=this.quill.getModule(`toolbar`);if(n&&this.quill.theme.pickers){let[,e]=(n.controls||[]).find(([e])=>e===this.statics.toolName)||[];if(e?.tagName.toLocaleLowerCase()===`select`){let t=this.quill.theme.pickers.find(t=>t.select===e);t&&(t.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,t),t.label.addEventListener(`mousedown`,()=>{if(!this.selector||!t)return;let{leftLimited:e}=rn(this.selector.getBoundingClientRect());if(e){let e=t.label.getBoundingClientRect();Object.assign(t.options.style,{transform:`translateX(calc(-100% + ${e.width}px))`})}else Object.assign(t.options.style,{transform:void 0})}))}}let i=this.quill.getModule(`keyboard`);for(let e of Object.values(r.keyboradHandler))e.bindInHead?i.bindings[e.key].unshift(e):i.addBinding(e.key,e);this.initModules(),this.listenEditableChange(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let e=l(`toolbox`),t=this.quill.addContainer(e.b());return this.resizeOb=new ResizeObserver(()=>{let e=this.quill.root.getBoundingClientRect(),{offsetLeft:n,offsetTop:r}=this.quill.root;Object.assign(t.style,{top:`${r}px`,left:`${n}px`,width:`${e.width}px`,height:`${e.height}px`})}),this.resizeOb.observe(this.quill.root),t}addContainer(e){if(C(e)){let t=document.createElement(`div`);for(let n of e.split(` `))t.classList.add(n);return this.toolBox.appendChild(t),t}else return this.toolBox.appendChild(e),e}resolveOptions(e){return Object.assign({customBtn:!1,texts:this.resolveTexts(e.texts||{}),full:!1,fullSwitch:!0,icon:Gr.table,autoMergeCell:!0,modules:[]},e)}resolveTexts(e){return Object.assign({fullCheckboxText:`Insert full width table`,customBtnText:`Custom`,confirmText:`Confirm`,cancelText:`Cancel`,rowText:`Row`,colText:`Column`,notPositiveNumberError:`Please enter a positive integer`,custom:`Custom`,clear:`Clear`,transparent:`Transparent`,perWidthInsufficient:`The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?`,CopyCell:`Copy cell`,CutCell:`Cut cell`,InsertTop:`Insert row above`,InsertRight:`Insert column right`,InsertBottom:`Insert row below`,InsertLeft:`Insert column Left`,MergeCell:`Merge Cell`,SplitCell:`Split Cell`,DeleteRow:`Delete Row`,DeleteColumn:`Delete Column`,DeleteTable:`Delete table`,BackgroundColor:`Set background color`,BorderColor:`Set border color`},e)}initModules(){if(this.quill.isEnabled())for(let e of this.options.modules)this.modules[e.module.moduleName]=new e.module(this,this.quill,e.options)}listenEditableChange(){this.editableObserver=new MutationObserver(e=>{for(let t of e)if(t.type===`attributes`&&t.attributeName===`contenteditable`){this.quill.root.getAttribute(`contenteditable`)===`false`?this.destroyModules():this.initModules();break}}),this.editableObserver.observe(this.quill.root,{attributes:!0,attributeFilter:[`contenteditable`]})}destroyModules(){for(let[e,t]of Object.entries(this.modules))if(t&&typeof t.destroy==`function`)try{t.destroy()}catch(t){console.warn(`Failed to destroy module ${e}:`,t)}this.modules={}}getModule(e){return this.modules[e]}quillHack(){let n=this.quill.getSemanticHTML;this.quill.getSemanticHTML=((r=0,i)=>{let a=n.call(this.quill,r,i),o=e.import(`formats/${t.tableWrapper}`),s=new DOMParser().parseFromString(a,`text/html`);for(let e of Array.from(s.querySelectorAll(`.${o.className} caption[contenteditable], .${o.className} .${U.className} > [contenteditable]`)))e.removeAttribute(`contenteditable`);return s.body.innerHTML});let r=this.quill.format;this.quill.format=function(n,a,o=e.sources.API){if(!(this.scroll.query(n).prototype instanceof Wr.EmbedBlot)){let e=this.getModule(i.moduleName),s=this.getSelection(!0),c=this.getFormat(s),l=e.getModule(i.tableSelectionName);if(!c[t.tableCellInner]||s.length>0||e&&l&&l.selectedTds.length<=1)return r.call(this,n,a,o);if(e&&l&&l.selectedTds.length>0){let e=l.selectedTds,t=!1,r=[];for(let i of e){let e=i.offset(this.scroll),o=i.length();r.push({index:e,length:o}),this.getFormat(e,o)[n]!==a&&(t=!0)}let i=t?a:!1,s=new $;for(let[e,{index:t,length:a}]of r.entries()){let o=e===0?0:r[e-1].index+r[e-1].length;s.retain(t-o).retain(a,{[n]:i})}let c=this.updateContents(s,o);return this.blur(),c}}return r.call(this,n,a,o)};let a=this.quill.theme.modules.toolbar;if(a){let n=a.handlers?.clean;if(n){let r=(e,n,r=()=>``)=>{let i=this.quill.getText(e,n),[a,o]=this.quill.getLine(e+n),s=0,c=new $;a!=null&&(s=a.length()-o,c=a.delta().slice(o,o+s-1).insert(`
133
+ </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`row`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`row-wrapper`)),Object.assign(i.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${r.height}px`}),Object.assign(a.style,{height:`${e.height}px`}),a.innerHTML=t,i.appendChild(a),this.root.appendChild(i),i.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}let[o]=p(this.tableBlot,Rn),s=!o||o?.side!==`top`;s?this.root.classList.remove(this.bem.is(`caption-bottom`)):this.root.classList.add(this.bem.is(`caption-bottom`));let c=-1*this.options.size,l=-1*this.options.size;kr(this.tableBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c=Math.min(r.width,e.width),l=Math.min(r.width,e.width)):this.root.classList.remove(this.bem.is(`align-right`)),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${c}px)`,top:`${s?0:e.height+this.options.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`,maxHeight:`${r.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${s?0:e.height+this.options.size}px`,maxWidth:`${r.width}px`})}show(){!this.table||!this.tableBlot||(this.root.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=an(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),F.call(this,this.quill.root,()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is(`hidden`)),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0)}destroy(){super.destroy(),this.hide(),I.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.root.remove()}},Lr=class extends Nr{static moduleName=`table-resize-line`;colResizer;rowResizer;currentTableCell;tableCellBlot;bem=l(`resize-line`);stopColDrag;stopRowDrag;scrollHandler=[];constructor(t,n){super(t,n),this.tableModule=t,this.quill=n,this.colResizer=this.tableModule.addContainer(this.bem.be(`col`)),this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show())}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};findTableCell(e){for(let t of e.composedPath()){if(t instanceof HTMLElement&&[`TD`,`TH`].includes(t.tagName))return t;if(t===document.body)return null}return null}pointermoveHandler=n=>{if(this.dragging||this.tableModule.getModule(i.tableSelectionName)?.dragging)return;let r=this.findTableCell(n);if(!r)return this.hide();let a=e.find(r);a&&this.currentTableCell!==r&&(this.show(),this.currentTableCell=r,this.tableCellBlot=a,this.tableBlot=u(a,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer(),F.call(this,this.quill.root,()=>{this.dragging||this.hideResizer()}))};findDragColIndex(e){return this.tableCellBlot?e.findIndex(e=>e.colId===this.tableCellBlot.colId):-1}updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;this.colResizer.remove();let{rect:e}=J(this.tableBlot);if(!e)return;this.colResizer=this.tableModule.addContainer(this.bem.be(`col`));let t=this.tableCellBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),r=t.right-n.x;kr(this.tableBlot)&&(r=t.left-n.x),Object.assign(this.colResizer.style,{top:`${e.y-n.y}px`,left:`${r}px`,height:`${e.height}px`});let{stop:i}=en(this.colResizer,{axis:`x`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragXCommon.startValue=r.x;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:`${Math.max(n.y,r.y)-i.y}px`,left:`${t.clientX-i.x}px`,height:`${Math.min(n.height,r.height)}px`})},onMove:({position:e})=>{if(!this.dragXCommon.dragBreak)return;let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=`${t-n.x}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.colResizer){let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.colResizer.style.left=`${t-n.x}px`}this.updateTableCol(e.x),this.removeBreak()}});this.stopColDrag&&this.stopColDrag(),this.stopColDrag=i,this.colResizer.addEventListener(`dragstart`,e=>e.preventDefault())}findDragRowIndex(e){if(!this.tableCellBlot)return-1;let t=this.tableCellBlot.parent;return t instanceof H?e.indexOf(t):-1}updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let e=this.tableCellBlot;this.rowResizer.remove();let{rect:t}=J(this.tableBlot);if(!t)return;this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`));let n=e.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:`${n.bottom-r.y}px`,left:`${t.x-r.x}px`,width:`${t.width}px`});let{stop:i}=en(this.rowResizer,{axis:`y`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragYCommon.startValue=r.y;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:`${t.clientY-i.y}px`,left:`${Math.max(n.x,r.x)-i.x}px`,width:`${Math.min(n.width,r.width)}px`})},onMove:({position:e})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=`${t-n.y}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.rowResizer){let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.rowResizer.style.left=`${t-n.y}px`}this.updateTableRow(e.y),this.removeBreak()}});this.stopRowDrag&&this.stopRowDrag(),this.stopRowDrag=i,this.rowResizer.addEventListener(`dragstart`,e=>e.preventDefault())}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is(`hidden`)),this.colResizer.classList.remove(this.bem.is(`hidden`)),this.table.addEventListener(`pointermove`,this.pointermoveHandler))}hideResizer(){!this.rowResizer||!this.colResizer||(this.rowResizer.classList.add(this.bem.is(`hidden`)),this.colResizer.classList.add(this.bem.is(`hidden`)))}hide(){this.currentTableCell=void 0,I.call(this),this.hideResizer(),this.table&&this.table.removeEventListener(`pointermove`,this.pointermoveHandler)}destroy(){super.destroy(),this.colResizer&&=(this.colResizer.remove(),void 0),this.rowResizer&&=(this.rowResizer.remove(),void 0),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},Rr=class extends Y{static moduleName=`table-resize-scale`;scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l(`scale`);options;root;block;resizeobserver=new ResizeObserver(()=>this.update());constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(r),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())};resolveOptions(e){return Object.assign({blockSize:12,offset:6},e)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.block=document.createElement(`div`),this.block.classList.add(this.bem.be(`block`)),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let e=[],t=[];en(this.block,{onStart:()=>{this.tableMainBlot&&(e=this.tableMainBlot.getCols().map(e=>({blot:e,width:Math.floor(e.width)})),t=this.tableMainBlot.getRows().map(e=>({blot:e,height:Math.floor(e.domNode.getBoundingClientRect().height)})))},onMove:({movePosition:r})=>{if(!this.tableMainBlot)return;let i=kr(this.tableMainBlot)?-1:1,a=r.x*i,o=r.y,s=Math.floor(a/e.length),c=Math.floor(o/t.length);for(let{blot:t,width:r}of e)t.width=Math.max(r+s,n.colMinWidthPx);for(let{blot:e,height:r}of t)e.setHeight(`${Math.max(r+c,n.rowMinHeightPx)}px`)},onEnd:()=>{e=[],t=[]}}),this.block.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.block||!this.root||!this.tableMainBlot||!this.tableWrapperBlot)return;if(this.tableMainBlot.full){this.hide();return}let{rect:e}=J(this.tableMainBlot);if(!e)return;let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),{scrollTop:r,scrollLeft:i}=this.tableWrapperBlot.domNode,a=this.options.blockSize*2+this.options.offset,o=Math.min(e.width,t.width)+a,s=Math.min(e.height,t.height)+a;Object.assign(this.root.style,{width:`${o}px`,height:`${s}px`,left:`${Math.max(e.x,t.x)-n.x-this.options.blockSize}px`,top:`${Math.max(e.y,t.y)-n.y-this.options.blockSize}px`});let c={left:`${e.width+a-i}px`,top:`${s-r}px`};kr(this.tableMainBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is(`align-right`)),Object.assign(this.block.style,c)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),F.call(this,this.quill.root,()=>this.update()),F.call(this,this.tableWrapperBlot.domNode,()=>this.update())),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0),I.call(this)}destroy(){super.destroy(),this.hide(),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect()}};const zr={size:`height`,offset:`offsetHeight`,scrollDirection:`scrollTop`,scrollSize:`scrollHeight`,axis:`y`,direction:`top`,client:`clientY`},Br={size:`width`,offset:`offsetWidth`,scrollDirection:`scrollLeft`,scrollSize:`scrollWidth`,axis:`x`,direction:`left`,client:`clientX`};var Vr=class{minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth=``;sizeHeight=``;size=``;bem=l(`scrollbar`);tableMainBlot;ob;container;scrollbar;thumb=document.createElement(`div`);scrollHandler=[];propertyMap;thumbState={x:0,y:0};get isVertical(){return this.options.isVertical}constructor(t,n,r){this.quill=t,this.table=n,this.options=r,this.tableMainBlot=e.find(this.table),this.container=n.parentElement,this.propertyMap=this.isVertical?zr:Br,this.calculateSize(),this.ob=new ResizeObserver(()=>this.update()),this.ob.observe(n),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),F.call(this,this.quill.root,()=>this.setScrollbarPosition()),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:e,head:t,body:n,foot:r}=J(this.tableMainBlot),i=t||n||r;if(!i||!e)return;let{scrollLeft:a,scrollTop:o,offsetLeft:s,offsetTop:c}=this.quill.root,{offsetLeft:l,offsetTop:u}=this.container,{offsetLeft:d,offsetTop:f}=i.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),h=l+d-s,g=u+f-c;this.isVertical?h+=Math.min(p,e.width):g+=Math.min(m,e.height),this.tableMainBlot&&this.tableMainBlot.align!==`left`&&(h+=this.table.offsetLeft-l),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,e.height):p}px`,transform:`translate(${h-a}px, ${g-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let e=this.container.offsetHeight-this.gap,t=this.container.offsetWidth-this.gap,n=e**2/this.container.scrollHeight,r=t**2/this.container.scrollWidth,i=Math.max(n,this.minSize),a=Math.max(r,this.minSize);this.ratioY=n/(e-n)/(i/(e-i)),this.ratioX=r/(t-r)/(a/(t-a)),this.sizeWidth=a+this.gap<t?`${a}px`:``,this.sizeHeight=i+this.gap<e?`${i}px`:``,this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let e=document.createElement(`div`);e.classList.add(this.bem.b(),this.isVertical?this.bem.is(`vertical`):this.bem.is(`horizontal`),this.bem.is(`transparent`)),Object.assign(e.style,{display:`none`}),this.thumb.classList.add(this.bem.be(`thumb`));let t=null,n=e=>{if(this.cursorDown===!1)return;let t=this.thumbState[this.propertyMap.axis];if(!t)return;let n=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],r=((this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-e[this.propertyMap.client])*-1-(this.thumb[this.propertyMap.offset]-t))*100*n/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=r*this.container[this.propertyMap.scrollSize]/100},r=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=t},i=e=>{e.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r),t=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener(`mousedown`,e=>{if(e.stopPropagation(),e.ctrlKey||[1,2].includes(e.button))return;window.getSelection()?.removeAllRanges(),i(e);let t=e.currentTarget;t&&(this.thumbState[this.propertyMap.axis]=t[this.propertyMap.offset]-(e[this.propertyMap.client]-t.getBoundingClientRect()[this.propertyMap.direction]))});let a=[this.table,e];for(let e of a)e.addEventListener(`mouseenter`,this.showScrollbar),e.addEventListener(`mouseleave`,this.hideScrollbar);return F.call(this,this.container,()=>{this.containerScrollHandler(this.container)}),e.appendChild(this.thumb),e}containerScrollHandler(e){let t=e[this.propertyMap.offset]-this.gap;this.move=e[this.propertyMap.scrollDirection]*100/t*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis.toUpperCase()}(${this.move}%)`})}showScrollbar=hn(()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?`block`:`none`,requestAnimationFrame(()=>{this.scrollbar.classList.remove(this.bem.is(`transparent`))})},200);hideScrollbar=hn(()=>{this.cursorLeave=!0,!this.cursorDown&&(this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.addEventListener(`transitionend`,this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is(`transparent`)))},200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?`block`:`none`};destroy(){this.ob.disconnect(),I.call(this),this.table.removeEventListener(`mouseenter`,this.showScrollbar),this.table.removeEventListener(`mouseleave`,this.hideScrollbar)}},Hr=class extends Y{static moduleName=`table-scrollbar`;scrollbarContainer;scrollbar=[];bem=l(`scrollbar`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n;let i=l(`scrollbar`);this.quill.container.classList.add(i.bm(`virtual`)),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be(`container`)),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())};hide(){for(let e of this.scrollbar)e.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=``}show(){if(this.table){this.scrollbar=[new Vr(this.quill,this.table,{isVertical:!0}),new Vr(this.quill,this.table,{isVertical:!1})];for(let e of this.scrollbar)this.scrollbarContainer.appendChild(e.scrollbar),e.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let e of this.scrollbar)e.calculateSize(),e.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){super.destroy(),this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Ur=class extends Y{static moduleName=i.tableSelectionName;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l(`selection`);autoScroller;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(e){this._dragging!==e&&(this._dragging=e,this.quill.emitter.emit(e?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,n,i={}){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=an(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener(`paste`,this.handlePaste),document.addEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.autoScroller=new ln(50,40),this.hide()}handlePaste=e=>{if(!(document.activeElement&&this.quill.root.contains(document.activeElement))||this.quill.getSelection())return;let n=e.clipboardData;if(!n)return;e.preventDefault();let r=this.selectedTds;if(r.length<=0)return;let i=n.getData(`text/html`),a=this.quill.clipboard.convert({html:i}).ops.filter(e=>e.attributes?.[t.tableCellInner]);a.length!==0&&Gn({quill:this.quill,talbeModule:this.tableModule},r,a)};keyboardHandler=async e=>{if(e.ctrlKey)switch(e.key){case`c`:case`x`:await wr(this.tableModule,this.selectedTds,e.key===`x`);break}else (e.key===`Backspace`||e.key===`Delete`)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let e of this.selectedTds)if(!e.domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),n=document.activeElement;if(!(t||!this.quill.root.contains(n))){if(this.table){let t=e.find(this.table),n=t.descendants(V);if(this.selectedTds.length===n.length){t.remove();return}}for(let e of this.selectedTds){let t=e.clone();t.appendChild(e.scroll.create(`block`)),e.parent.insertBefore(t,e),e.remove()}}}setSelectedTds(e){let t=new Set(this.selectedTds),n=this.selectedTds.length===e.length&&e.every(e=>t.has(e));this.selectedTds=e,n||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}quillSelectionChangeHandler=(n,r,i)=>{if(i!==e.sources.API&&n&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(n),[r]=this.quill.getLine(n.index),i=!!e[t.tableCellInner]&&!!r,a=r&&this.selectedTds.some(e=>e.domNode.contains(r.domNode));if(i&&!a)try{let e=u(r,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else i&&a||this.hide()}};setSelectionData(e,t){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=t;if(!n||!i)return;let o=document.createRange(),s=this.selectionDirectionUp(t);s?(o.setStart(n,r),o.setEnd(n,r)):(o.setStart(n,r),o.setEnd(i,a)),e.removeAllRanges(),e.addRange(o),s&&e.extend(i,a)}selectionDirectionUp(e){let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:i}=e;if(!t||!r)return!1;if(t===r)return n>i;let a=t.compareDocumentPosition(r);return a&Node.DOCUMENT_POSITION_CONTAINS||a&Node.DOCUMENT_POSITION_CONTAINED_BY?(a&Node.DOCUMENT_POSITION_FOLLOWING)!==0:(a&Node.DOCUMENT_POSITION_PRECEDING)!==0}resolveOptions(e){return Object.assign({selectColor:`#0589f340`},e)}selectionChangeHandler=()=>{let n=window.getSelection();if(!n)return;let{anchorNode:r,focusNode:i,anchorOffset:a,focusOffset:o}=n;if(!r||!i)return;let s=e.find(r),c=e.find(i);if(!s||!c||s.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;let l=f(s),u=f(c),d=l.has(t.tableColgroup),p=u.has(t.tableColgroup);if(d||p){let e=r,s=a,c=i,f=o;if(d){let n=l.get(t.tableWrapper).descendants(V);n.length>0&&(e=n[0].domNode,s=0)}if(p){let e=u.get(t.tableWrapper).descendants(V);e.length>0&&(c=e[0].domNode,f=0)}this.setSelectionData(n,{anchorNode:e,anchorOffset:s,focusNode:c,focusOffset:f});return}let m=l.has(t.tableCellInner),h=u.has(t.tableCellInner),g=m&&h;if(g){let e=l.get(t.tableCellInner),n=u.get(t.tableCellInner);g&&=e!==n}if(m&&h&&g||!m&&h||!h&&m){this.setSelectionData(n,this.lastSelection),this.selectedTds.length>0&&this.hide();return}this.lastSelection={anchorNode:r,anchorOffset:a,focusNode:i,focusOffset:o}};helpLinesInitial(){this.cellSelectWrap.style.setProperty(`--select-color`,this.options.selectColor);let e=document.createElement(`div`);return e.classList.add(this.bem.be(`line`)),this.cellSelectWrap.appendChild(e),e}computeSelectedTds(t,n){if(!this.table)return[];let r=e.find(this.table);if(!r)return[];let i=new Set(r.descendants(U).map((e,t)=>(e.index=t,e))),a=this.getScrollPositionDiff(),{rect:o}=J(r);if(!o)return[];let s=t.x+a.x,c=t.y+a.y,l={x:Math.max(o.left,Math.min(n.x,s)),y:Math.max(o.top,Math.min(n.y,c)),x1:Math.min(o.right,Math.max(n.x,s)),y1:Math.min(o.bottom,Math.max(n.y,c))},u=new Set,d=!0;for(;d;){d=!1;for(let e of i){e.__rect||=e.domNode.getBoundingClientRect();let{x:t,y:n,right:r,bottom:a}=e.__rect;if(tn({x:Math.floor(l.x),y:Math.floor(l.y),x1:Math.floor(l.x1),y1:Math.floor(l.y1)},{x:Math.floor(t),y:Math.floor(n),x1:Math.floor(r),y1:Math.floor(a)},0,u.size===0)){u.add(e),i.delete(e),l={x:Math.min(l.x,t),y:Math.min(l.y,n),x1:Math.max(l.x1,r),y1:Math.max(l.y1,a)},d=!0;break}}}for(let e of[...u,...i])delete e.__rect;return this.boundary=nn({...l,width:l.x1-l.x,height:l.y1-l.y},this.quill.root),Array.from(u).toSorted((e,t)=>e.index-t.index).map(e=>(delete e.index,e.getCellInner()))}getScrollPositionDiff(){let{x:e,y:t}=this.getTableViewScroll(),{x:n,y:r}=sn(this.quill.root);return this.selectedTableScrollX=e,this.selectedTableScrollY=t,this.selectedEditorScrollX=n,this.selectedEditorScrollY=r,this.startScrollRecordPosition.reduce((e,{x:t,y:n},r)=>{let{x:i,y:a}=sn(this.scrollRecordEls[r]);return e.x+=t-i,e.y+=n-a,e},{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let e of this.scrollRecordEls)this.startScrollRecordPosition.push(sn(e))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(t){let{button:n,target:r,clientX:i,clientY:a}=t,o=r.closest(`table`),s=r.closest(`caption`);if(n!==0||!o||s)return;this.setSelectionTable(o);let c=o.dataset.tableId,l={x:i,y:a};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(l,l)),this.show();let u=e=>{this.dragging=!0;let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`.ql-table`),o=n.closest(`caption`);if(t!==0||o||!a||a.dataset.tableId!==c)return;let s={x:r,y:i};this.setSelectedTds(this.computeSelectedTds(l,s)),this.selectedTds.length>1&&this.quill.blur(),this.update(),this.autoScroller.updateMousePosition(r,i)},d=()=>{document.body.removeEventListener(`mousemove`,u,!1),document.body.removeEventListener(`mouseup`,d,!1),this.autoScroller.stop(),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener(`mousemove`,u,!1),document.body.addEventListener(`mouseup`,d,!1);let f=e.find(o);if(!f)return;let p=f.parent.domNode;this.autoScroller.updateMousePosition(i,a),this.autoScroller.start(p)}updateWithSelectedTds(){if(this.selectedTds.length<=0){this.hide();return}let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.selectedTds){let r=n.domNode.getBoundingClientRect();e.x=Math.min(e.x,r.left),e.y=Math.min(e.y,r.top),t.x=Math.max(t.x,r.right),t.y=Math.max(t.y,r.bottom)}this.setSelectedTds(this.computeSelectedTds(e,t)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table){this.hide();return}if(this.selectedTds.length===0||!this.boundary)return;let{x:e,y:t}=sn(this.quill.root),{x:n,y:i}=this.getTableViewScroll(),a=this.table.parentElement.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),s=a.x-o.x,c=a.y-o.y;Object.assign(this.cellSelect.style,{left:`${this.selectedEditorScrollX*2-e+this.boundary.x+this.selectedTableScrollX-n-s}px`,top:`${this.selectedEditorScrollY*2-t+this.boundary.y+this.selectedTableScrollY-i-c}px`,width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${s}px`,top:`${c}px`,width:`${a.width}px`,height:`${a.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?sn(this.table.parentElement):{x:0,y:0}}setSelectionTable(e){this.table!==e&&(this.table=e,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:`block`}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(I.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener(`keydown`,this.keyboardHandler),F.call(this,this.quill.root,()=>{this.update()}),F.call(this,this.table.parentElement,()=>{this.update()}))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:`none`}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){I.call(this),this.quill.root.removeEventListener(`keydown`,this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){super.destroy(),this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),I.call(this),document.removeEventListener(`paste`,this.handlePaste),document.removeEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Wr=e.import(`parchment`),$=e.import(`delta`),Gr=e.import(`ui/icons`),Kr=e.import(`blots/break`),qr=e.import(`blots/block`),Jr=e.import(`blots/block/embed`);function Yr(e,{tableId:n,rowId:r,colId:i}){let a={tableId:n,rowId:r,colId:i,colspan:1,rowspan:1},o=e.create(t.tableCell,a),s=e.create(t.tableCellInner,a),c=e.create(`block`);return c.appendChild(e.create(`break`)),s.appendChild(c),o.appendChild(s),o}function Xr(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),$r.moduleName=i.moduleName,$r.toolName=t.tableWrapper,R.blotName=t.container,Rn.blotName=t.tableCaption,q.blotName=t.tableWrapper,G.blotName=t.tableMain,K.blotName=t.tableColgroup,W.blotName=t.tableCol,Vn.blotName=t.tableHead,B.blotName=t.tableBody,Bn.blotName=t.tableFoot,H.blotName=t.tableRow,U.blotName=t.tableCell,V.blotName=t.tableCellInner,o.add(t.tableCellInner)}function Zr(t,n){return w({onSelect:(r,i)=>{t.insertTable(r,i,e.sources.USER),n&&n.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Qr(n){return{bindInHead:!1,key:n?`ArrowUp`:`ArrowDown`,collapsed:!0,format:[t.tableCellInner],handler(r,i){let a=n?`prev`:`next`,o=n?`tail`:`head`;if(i.line[a])return!0;let s=this.quill.selection.getBounds(r.index),c=i.line.domNode.getBoundingClientRect();if(!s||!c)return!0;if(n){if(s.top-c.top>3)return!0}else if(c.bottom-s.bottom>3)return!0;let l,u,f,p;try{[l,u,f,p]=d(i.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m=u.getColIds(),h=l.descendants(Rn,0)[0],g;if(h){let e=window.getComputedStyle(h.domNode);g=a===`next`&&e.captionSide===`bottom`?h:a===`next`?l.next:h}else g=l[a];if(i.line[a]||!g)return!0;let _=f[a];if(_){let t=m.indexOf(p.colId),n=_.getCellByColId(m[t],a);if(!n)return!0;let r=n.children[o];r.children&&(r=r.children[o]);let s=r.offset(this.quill.scroll)+Math.min(i.offset,r.length()-1);this.quill.setSelection(s,0,e.sources.USER)}else{let t=g.offset(this.quill.scroll)+(n?g.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var $r=class r{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:`Backspace`,collapsed:!0,offset:0,handler(e,n){let r=this.quill.getLine(e.index)[0];return r.prev instanceof q?(r.prev.remove(),!1):!(n.format[t.tableCellInner]&&r.offset(u(r,t.tableCellInner))===0)}},"forbid remove table by delete":{bindInHead:!0,key:`Delete`,collapsed:!0,handler(e,n){let r=this.quill.getLine(e.index),i=r[0],a=r[1];return!((i.next instanceof q||i.next instanceof W)&&a===i.length()-1||n.format[t.tableCellInner]&&i===u(i,t.tableCellInner).children.tail&&a===i.length()-1)}},"table up":Qr(!0),"table down":Qr(!1),"table caption break":{bindInHead:!0,key:`Enter`,shiftKey:null,format:[t.tableCaption],handler(e,t){return!1}}};static register(){q.allowedChildren=[G],G.allowedChildren=[K,Rn,Vn,B,Bn],G.requiredContainer=q,Rn.requiredContainer=G,K.allowedChildren=[W],K.requiredContainer=G,Vn.allowedChildren=[H],Vn.requiredContainer=G,B.allowedChildren=[H],B.requiredContainer=G,Bn.allowedChildren=[H],Bn.requiredContainer=G,H.allowedChildren=[U],U.allowedChildren=[V,Kr],U.requiredContainer=H,V.requiredContainer=U;let n=new Set([`table`]),r=Object.entries(e.imports).filter(([e,t])=>{let r=e.split(`formats/`)[1];return e.startsWith(`formats/`)&&!n.has(r)&&(g(t,qr)||g(t,Jr))}).reduce((e,[t,n])=>{let r=g(n,Jr)?Dn:Tn;return e[t]=class extends h(n,[r]){static register(){}},e},{});e.register({"blots/scroll":Nn,"blots/block":Tn,"blots/block/embed":Dn,...r,[`blots/${t.container}`]:R,[`formats/${t.tableCell}`]:U,[`formats/${t.tableCellInner}`]:V,[`formats/${t.tableRow}`]:H,[`formats/${t.tableHead}`]:Vn,[`formats/${t.tableBody}`]:B,[`formats/${t.tableFoot}`]:Bn,[`formats/${t.tableCol}`]:W,[`formats/${t.tableColgroup}`]:K,[`formats/${t.tableCaption}`]:Rn,[`formats/${t.tableMain}`]:G,[`formats/${t.tableWrapper}`]:q,"modules/clipboard":or},!0)}quill;options;textOptionsInput;toolBox;fixTableByLisenter=hn(this.balanceTables,100);selector;resizeOb;editableObserver;modules={};get statics(){return this.constructor}constructor(e,t){this.quill=e,this.textOptionsInput=t?.texts,this.options=this.resolveOptions(t||{}),this.toolBox=this.initialContainer();let n=this.getToolbarPicker();n&&(n.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,n),n.label.addEventListener(`mousedown`,()=>{if(!this.selector)return;let{leftLimited:e}=rn(this.selector.getBoundingClientRect());if(e){let e=n.label.getBoundingClientRect();Object.assign(n.options.style,{transform:`translateX(calc(-100% + ${e.width}px))`})}else Object.assign(n.options.style,{transform:void 0})}));let i=this.quill.getModule(`keyboard`);for(let e of Object.values(r.keyboradHandler))e.bindInHead?i.bindings[e.key].unshift(e):i.addBinding(e.key,e);this.initModules(),this.listenEditableChange(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let e=l(`toolbox`),t=this.quill.addContainer(e.b());return this.resizeOb=new ResizeObserver(()=>{let e=this.quill.root.getBoundingClientRect(),{offsetLeft:n,offsetTop:r}=this.quill.root;Object.assign(t.style,{top:`${r}px`,left:`${n}px`,width:`${e.width}px`,height:`${e.height}px`})}),this.resizeOb.observe(this.quill.root),t}addContainer(e){if(C(e)){let t=document.createElement(`div`);for(let n of e.split(` `))t.classList.add(n);return this.toolBox.appendChild(t),t}else return this.toolBox.appendChild(e),e}getToolbarPicker(){let e=this.quill.getModule(`toolbar`);if(!e||!this.quill.theme.pickers)return;let[,t]=(e.controls||[]).find(([e])=>e===this.statics.toolName)||[];if(t?.tagName.toLocaleLowerCase()===`select`)return this.quill.theme.pickers.find(e=>e.select===t)}resolveOptions(e){let{texts:t,...n}=e;return Object.assign({customBtn:!1,texts:this.resolveTexts(t),full:!1,fullSwitch:!0,icon:Gr.table,autoMergeCell:!0,modules:[]},n)}resolveTexts(e){let t={fullCheckboxText:`Insert full width table`,customBtnText:`Custom`,confirmText:`Confirm`,cancelText:`Cancel`,rowText:`Row`,colText:`Column`,notPositiveNumberError:`Please enter a positive integer`,custom:`Custom`,clear:`Clear`,transparent:`Transparent`,perWidthInsufficient:`The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?`,CopyCell:`Copy cell`,CutCell:`Cut cell`,InsertTop:`Insert row above`,InsertRight:`Insert column right`,InsertBottom:`Insert row below`,InsertLeft:`Insert column Left`,MergeCell:`Merge Cell`,SplitCell:`Split Cell`,DeleteRow:`Delete Row`,DeleteColumn:`Delete Column`,DeleteTable:`Delete table`,BackgroundColor:`Set background color`,BorderColor:`Set border color`};if(x(e)){let n=e,r=this;return new Proxy(t,{get(e,t){if(typeof t!=`string`)return Reflect.get(e,t);let i=n.call(r,t);return C(i)?i:e[t]}})}return Object.assign(t,e)}async refreshUI(){this.options.texts=this.resolveTexts(this.textOptionsInput);let e=this.getToolbarPicker();e&&(e.label.innerHTML=this.options.icon,await this.buildCustomSelect(this.options.customSelect,e));for(let e of Object.values(this.modules))e&&typeof e.hide==`function`&&e.hide()}initModules(){if(this.quill.isEnabled())for(let e of this.options.modules)this.modules[e.module.moduleName]=new e.module(this,this.quill,e.options)}listenEditableChange(){this.editableObserver=new MutationObserver(e=>{for(let t of e)if(t.type===`attributes`&&t.attributeName===`contenteditable`){this.quill.root.getAttribute(`contenteditable`)===`false`?this.destroyModules():this.initModules();break}}),this.editableObserver.observe(this.quill.root,{attributes:!0,attributeFilter:[`contenteditable`]})}destroyModules(){for(let[e,t]of Object.entries(this.modules))if(t&&typeof t.destroy==`function`)try{t.destroy()}catch(t){console.warn(`Failed to destroy module ${e}:`,t)}this.modules={}}getModule(e){return this.modules[e]}quillHack(){let n=this.quill.getSemanticHTML;this.quill.getSemanticHTML=((r=0,i)=>{let a=n.call(this.quill,r,i),o=e.import(`formats/${t.tableWrapper}`),s=new DOMParser().parseFromString(a,`text/html`);for(let e of Array.from(s.querySelectorAll(`.${o.className} caption[contenteditable], .${o.className} .${U.className} > [contenteditable]`)))e.removeAttribute(`contenteditable`);return s.body.innerHTML});let r=this.quill.format;this.quill.format=function(n,a,o=e.sources.API){if(!(this.scroll.query(n).prototype instanceof Wr.EmbedBlot)){let e=this.getModule(i.moduleName),s=this.getSelection(!0),c=this.getFormat(s),l=e.getModule(i.tableSelectionName);if(!c[t.tableCellInner]||s.length>0||e&&l&&l.selectedTds.length<=1)return r.call(this,n,a,o);if(e&&l&&l.selectedTds.length>0){let e=l.selectedTds,t=!1,r=[];for(let i of e){let e=i.offset(this.scroll),o=i.length();r.push({index:e,length:o}),this.getFormat(e,o)[n]!==a&&(t=!0)}let i=t?a:!1,s=new $;for(let[e,{index:t,length:a}]of r.entries()){let o=e===0?0:r[e-1].index+r[e-1].length;s.retain(t-o).retain(a,{[n]:i})}let c=this.updateContents(s,o);return this.blur(),c}}return r.call(this,n,a,o)};let a=this.quill.theme.modules.toolbar;if(a){let n=a.handlers?.clean;if(n){let r=(e,n,r=()=>``)=>{let i=this.quill.getText(e,n),[a,o]=this.quill.getLine(e+n),s=0,c=new $;a!=null&&(s=a.length()-o,c=a.delta().slice(o,o+s-1).insert(`
134
134
  `));let l=this.quill.getContents(e,n+s),u=l.diff(new $().insert(i).concat(c)),d=0;return new $(u.ops.map(e=>{let{attributes:n,...i}=e;if(e.insert?d-=C(e.insert)?e.insert.length:1:e.retain?d+=re(e.retain)?e.retain:1:e.delete&&(d+=e.delete),n){let{[t.tableCellInner]:e,...a}=n;if(r){let e=l.slice(d-1,d).ops[0];if(e?.attributes?.[t.tableCellInner]){let{style:n,...o}=e.attributes[t.tableCellInner],s=r(n);return s?{...i,attributes:{...a,[t.tableCellInner]:{style:s,...o}}}:{...i,attributes:{...a,[t.tableCellInner]:o}}}}return{...i,attributes:{...a}}}return e}))};a.handlers.clean=function(a){let o=this.quill.getModule(i.moduleName),s=this.quill.getSelection();if(s&&s.length>0&&this.quill.getFormat(s)[t.tableCellInner]){let t=r(s.index,s.length,!1),n=new $().retain(s.index).concat(t);this.quill.updateContents(n,e.sources.USER);return}let c=o.getModule(i.tableSelectionName);if(o&&c&&c.selectedTds.length>0&&c.table){let t=e.find(c.table);if(!t){console.warn(`TableMainFormat not found`);return}let n=c.selectedTds,i=new Set,a=[];for(let e of n)if(e.parent instanceof U){for(let t of e.parent.getNearByCell(`top`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`bottom`}));for(let t of e.parent.getNearByCell(`left`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`right`}));i.add(e.parent),a.push({td:e.parent,cleanBorder:!0})}let o=t.descendants(U),s=new Map(o.map((e,t)=>[e,t]));a.sort((e,t)=>s.get(e.td)-s.get(t.td));let l=new $,u=0;for(let{td:e,cleanBorder:t}of a){let n=e.getCellInner().offset(this.quill.scroll),i=e.getCellInner().length(),a=r(n,i-1,e=>{if(!e||t===!0)return``;let n=pn(e);return mn(Object.keys(n).filter(e=>!e.startsWith(dn(`border-${t}`))).reduce((e,t)=>(e[t]=n[t],e),{}))}),o=new $().retain(n-u).concat(a);l=l.concat(o),u=n+i}this.quill.updateContents(l,e.sources.USER),n.length>1&&this.quill.blur();return}return n.call(this,a)}}}}async buildCustomSelect(e,t){if(!e||!x(e))return;let n=document.createElement(`span`);if(n.classList.add(`ql-custom-select`),this.selector=await e(this,t),n.appendChild(this.selector),this.options.fullSwitch){let e=l(`creator`),t=document.createElement(`label`);t.classList.add(e.be(`checkbox`));let r=document.createElement(`input`);r.type=`checkbox`,r.checked=this.options.full,r.addEventListener(`change`,()=>{this.options.full=r.checked});let i=document.createElement(`span`);i.textContent=this.options.texts.fullCheckboxText,t.appendChild(r),t.appendChild(i),n.appendChild(t)}t.options.innerHTML=``,t.options.appendChild(n)}setCellAttrs(e,t,n,r=!1){if(e.length!==0)for(let i of e)i.setFormatValue(t,n,r)}getTextByCell(e){let t=``;for(let n of e){let e=n.offset(this.quill.scroll),r=n.length();for(let n of this.quill.getContents(e,r).ops)C(n.insert)&&(t+=n.insert)}return t}getHTMLByCell(e,n=!1){if(e.length===0)return``;let r=null;try{for(let n of e){let e=u(n,t.tableMain);if(r||=e,e!==r)return console.error(`tableMain is not same`),``}}catch{return console.error(`tds must be in same tableMain`),``}if(!r)return``;let i=this.quill.getIndex(r),a=r.length(),o=this.quill.getSemanticHTML(i,a),s=new DOMParser().parseFromString(o,`text/html`),c=Array.from(s.querySelectorAll(`col`)),l=c.map(e=>e.dataset.colId),d=[],f=new Set,p=new Set;for(let t of e){f.add(t.colId);let e=t.colId,n=l.indexOf(e);for(let e=0;e<t.colspan;e++)f.add(l[n+e]);p.add(`${t.rowId}-${t.colId}`)}for(let e=0;e<c.length;e++){let t=c[e];f.has(t.dataset.colId)?d.push(t.getAttribute(`width`)):(t.remove(),c.splice(e--,1))}let m=0,h=null;for(let e of Array.from(s.querySelectorAll(`td, th`)))if(p.has(`${e.dataset.rowId}-${e.dataset.colId}`))h!==e.dataset.rowId&&(m+=1,h=e.dataset.rowId);else{let t=e.parentElement;e.remove(),t&&t.children.length<=0&&t.remove()}let g=c.map(e=>W.value(e));if(r.full){let e=g.reduce((e,t)=>t.width+e,0);for(let[t,n]of g.entries())n.width=Math.round(n.width/e*100),c[t].setAttribute(`width`,`${n.width}%`)}else{let e=0;for(let t of g)e+=t.width;let t=s.querySelector(`table`);t.style.width=`${e}px`}if(n){let t=r.getRows();if(m===t.length)this.removeCol(e);else for(let t of e)t.domNode.innerHTML=`<p><br></p>`}return s.body.innerHTML}insertTable(r,i,a=e.sources.API){if(r>=30||i>=30)throw Error(`Both rows and columns must be less than 30.`);this.quill.focus();let o=this.quill.getSelection();if(o==null)return;let[s]=this.quill.getLeaf(o.index);if(!s)return;if(c(s))throw Error(`Not supported ${s.statics.blotName} insert into table.`);let l=L(),u=Array(i).fill(0).map(()=>L()),d=this.calculateTableCellBorderWidth(),f=getComputedStyle(this.quill.root),p=Number.parseInt(f.paddingLeft),m=Number.parseInt(f.paddingRight),h=this.quill.root.scrollHeight>this.quill.root.clientHeight?cn({target:this.quill.root}):0,g=Number.parseInt(f.width)-p-m-d-h,_=this.options.full?`${Math.max(1/i*100,n.colMinWidthPre)}%`:`${Math.max(Math.floor(g/i),n.colMinWidthPx)}px`,v=[{retain:o.index}],y=this.quill.getContents(o.index,1),[,b]=this.quill.getLine(o.index);y.ops[0].insert!==`
135
135
  `&&b!==0&&v.push({insert:`
136
136
  `});for(let e=0;e<i;e++)v.push({insert:{[t.tableCol]:{width:_,tableId:l,colId:u[e],full:this.options.full}}});for(let e=0;e<r;e++){let e=L();for(let n=0;n<i;n++)v.push({insert:`