@ones-editor/editor 0.0.3-beta.41 → 0.0.3-beta.42
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.
|
@@ -5,7 +5,7 @@ export interface AutoSuggestMenuOptions {
|
|
|
5
5
|
showLoading?: boolean;
|
|
6
6
|
loadingElement?: HTMLElement;
|
|
7
7
|
placeholder?: HTMLElement | string;
|
|
8
|
-
noResultMessage?: HTMLElement | string;
|
|
8
|
+
noResultMessage?: HTMLElement | string | ((item: CommandItem) => HTMLElement);
|
|
9
9
|
highlight?: boolean;
|
|
10
10
|
onShow?: (menu: AutoSuggestMenu, containerId: string, blockIndex: number, offset: number) => boolean | undefined;
|
|
11
11
|
onClickItem: (menu: AutoSuggestMenu, item: CommandItem) => void;
|
package/dist/index.js
CHANGED
|
@@ -331,7 +331,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
331
331
|
<path d="M5.27137 5.61819C6.60787 5.61819 7.69131 4.53475 7.69131 3.19825C7.69131 1.86176 6.60787 0.77832 5.27137 0.77832C3.93488 0.77832 2.85144 1.86176 2.85144 3.19825C2.85144 4.53475 3.93488 5.61819 5.27137 5.61819Z" stroke="#999999" stroke-linejoin="round" fill="none"/>
|
|
332
332
|
<path d="M9.07413 10.8036H13.2226M11.1484 8.91895V13.1009V8.91895Z" stroke="#999999" stroke-linecap="square" fill="none"/>
|
|
333
333
|
<path d="M8.03712 8.38281H5.20234C3.65344 8.38281 2.87899 8.38281 2.28739 8.68423C1.76699 8.94939 1.3439 9.3725 1.07875 9.89289C0.777313 10.4845 0.777313 11.2589 0.777313 12.8078V13.2227H8.03712" stroke="#999999" stroke-linecap="square" stroke-linejoin="round" fill="none"/>
|
|
334
|
-
</svg>`;function Pw(n,t){var e;if(M(t,"menu-item"),!n.element){if(n.type==="section"){const o=b("div",["section-name"],null,n.name);t.appendChild(o)}else if(n.type!=="separator"){if(n.icon){const i=b("div",["menu-item-icon"],null);n.icon&&(i.innerHTML=n.icon),t.appendChild(i)}const o=b("div",["menu-item-name"],null,n.name);t.appendChild(o);const r=l0(n);if(r&&b("div",["item-shortcut","text"],t,r),n.children&&!n.element){const i=b("div",["menu-item-sub-indicator"],null);i.innerHTML=u0,t.appendChild(i)}if((e=n.states)!=null&&e.includes("checked")){const i=b("div",["menu-item-checked-icon"],null);i.innerHTML=Cw,t.appendChild(i)}}}}class Wo extends ec{constructor(t,e,o){super(t,e,{autoClose:!0,disablePageScroll:!0,...o})}manualShow(t,e){const o={theme:"menu",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"menu")}initItemElement(t,e){Pw(t,e)}}function $w(n,t,e){var o;return new Wo((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class oc extends ec{constructor(t,e,o){super(t,e,{itemElementTag:"button",tippyArrow:!1,...o})}getSubBarOptions(t){var r,i;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),a=s.getBoundingClientRect();return new DOMRect(a.left,c.top,a.width,c.height)};return{placement:(r=t.childrenPlacement)!=null?r:"top",getReferenceClientRect:e,offset:(i=t.childrenOffset)!=null?i:[0,4]}}manualShow(t,e){const o={theme:"toolbar",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),(!t.children||t.children.length===0)&&this.options.tooltipId&&(e.setAttribute(`data-editor-tooltip-${this.options.tooltipId}`,t.name),t.desc&&e.setAttribute(`data-editor-tooltip-desc-${this.options.tooltipId}`,t.desc));const o=e;if(!t.element)if(t.icon){const r=b("span",["toolbar-item-icon-container"],o);t.icon.trim().startsWith("<")?r.innerHTML=t.icon:r.innerText=t.icon}else{const r=b("span",["toolbar-item-name-container"],o);r.innerText=t.name}if(t.dropdown){e.setAttribute("data-dropdown","true");const r=b("span",["toolbar-item-dropdown-container"],o);r.innerHTML=Hu}t.states&&(t.states.indexOf("checked")!==-1&&M(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function jw(n,t,e){var o;return new oc((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const nF="";Pr.registerManualCommandBar("menu",$w),Pr.registerManualCommandBar("toolbar",jw);const y0=y("ui-base");class rc extends ec{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${N()}`,name:"",element:t}];super(r)}initCommandBarElement(t){M(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];d(y0,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return d(y0,e,"no item element"),e}}const oF="",w0=y("ui-base");class ic extends ec{constructor(e,o){super(ic.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){M(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];d(w0,e,"no dialog item");const o=e.element;return d(w0,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${N()}`,name:"",element:e}]}}const Hw=[-1,6,0,1,2,3,4,5],Fw=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],B0=y("color-palette");function E0(n,t,e,o){d(B0,n>0,"no color in palette");const r=t||1;d(B0,r>0,`invalid palette rows: ${r}`);const i=n/r,s=b("div",["palette-container",o],null);for(let l=0;l<r;l++){const c=b("div",["palette-container-row"],s);for(let a=0;a<i;a++){const u=e(l*i+a);c.appendChild(u)}}return s}function zw(n){const t=b("button",["color-button"],null),e=Hw[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=d0,t}function Uw(n){const t=b("button",["background-color-button"],null),e=Fw[n];return t.setAttribute("data-color-index",`${e}`),t}function Vw(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=S.t("colorPalette.reset"),n}function qw(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,S.t("colorPalette.colorDesc")),t.appendChild(E0(8,1,zw,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,S.t("colorPalette.backgroundDesc")),t.appendChild(E0(16,2,Uw,"background-color"))),n.clearColorButton!==!1&&t.appendChild(Vw()),t}function Ww(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&F(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&M(i,"selected")}const rF="",Gw={};class Zw extends Wt.TypedEmitter{constructor(e=Gw){super();h(this,"root");h(this,"handleClick",e=>{const o=e.target;if(!o||!(o instanceof Element))return;const r=o.closest("button");if(!r)return;if(lt(r,"clear-button")){this.setColor("backgroundColor",null),this.setColor("color",null),this.emit("onClick","clearColor",0);return}const i=r.getAttribute("data-color-index");if(!i)return;const s=Number.parseInt(i,10);Number.isNaN(s)||(lt(r,"color-button")?s===-1?(this.setColor("color",null),this.emit("onClick","clearColor",1)):(this.setColor("color",s),this.emit("onClick","color",s)):s===-1?(this.setColor("backgroundColor",null),this.emit("onClick","clearColor",2)):(this.setColor("backgroundColor",s),this.emit("onClick","backgroundColor",s)))});this.options=e,this.root=qw(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){Ww(this.root,e,o)}}class I0{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new Zw(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function Yw(){const n=b("button",["color-button"],null);return n.innerHTML=d0,n}function Ju(n,t){const[e,o]=t;e===null?n.removeAttribute("data-color"):n.setAttribute("data-color",`${e}`),o===null?n.removeAttribute("data-background-color"):n.setAttribute("data-background-color",`${o}`)}class Qw extends Wt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name","Text color");h(this,"dropdown",!0);h(this,"manualShowChildren",!0);h(this,"children",[]);h(this,"element");h(this,"colorPaletteItem");h(this,"latestColors",[null,null]);h(this,"handlePaletteClick",(e,o)=>{this.emit("onClick",e,o),e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=o:this.latestColors[1]=o:this.latestColors=[null,null],Ju(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new I0("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=Yw()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Ju(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Ju(this.element,this.latestColors)}}const iF="";function Xu(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&M(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&M(o,"required");const r=b("div",["editor-input-container"],e),i=b("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=b("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),F(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{M(e,"error"),s.innerText=l}}}function Kw(n){const t=document.getSelection();if(!t)return!0;const e=t.focusNode;if(!e)return!0;const o=t.focusOffset,r=e.childNodes[o];if(!r)return!0;if(r instanceof HTMLElement){const i=r.tagName.toLowerCase();if(r===n.input.inputElement)return!0;if(i==="input"||i==="textarea")return!1}return!0}const Jw=y("ui-base");class Xw{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{Kw(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new Wo([],void 0,{id:e.id}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose)}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(o=>o.type!=="section"&&o.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e,o){var a,u;if(((u=(a=this.options).onShow)==null?void 0:u.call(a,this,t,e,o))===!1)return;this.options.showLoading&&this.showLoading();const r=this.editor.getBlockByIndex(t,e);if(!vt(this.editor.rootContainer,r)||Z(this.editor,r)<o)return;const i=Oo(this.editor,r,Lt(this.editor,r,o));if(i.length===0)return;const s=i[0],l=_o(this.editor,r,"editor-auto-suggest-menu",s);this.menu.manualShow(l),this.options.placeholder&&this.showPlaceholder();const c=await this.options.queryItems(this,"");this.highlightText(""),this.setItems(c)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){this.setItems([{id:"placeholder",name:S.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close()}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close(),this.menu.removeAllListeners(),this.menu.destroy()}async handleSearchText(t){this.currentText=t;const e="auto-suggest";try{await Ue.lock(e),this.showLoading();const o=this.currentText,r=await this.options.queryItems(this,o);if(this.currentText===o&&(this.currentText=""),r.length===0){this.showNoResultMessage(t);return}this.setItems(r),this.options.highlight&&this.highlightText(o)}finally{Ue.release(e)}}highlightText(t){Jw.debug(`highlight menu text: ${t}`);const e=this.menu.content,o=(i,s)=>{if(!s)return i;let l="";const c=s.length,a=s.toLocaleLowerCase();let u=0;for(u=0;u<=i.length-c;u){const f=i.substring(u,u+c);f.toLocaleLowerCase()===a?(l+=`<span class="highlight">${f}</span>`,u+=c):(l+=i.charAt(u),u++)}return u<i.length&&(l+=i.substring(u)),l},r=i=>{if(lt(i,"text")){const s=i.textContent;if(!s)return;const l=o(s,t);i.innerHTML=l;return}Array.from(i.children).forEach(r)};r(e)}}const th=y("auto-suggest-menu");class eh{constructor(t,e){h(this,"menu");h(this,"anchor",null);h(this,"handleSelectionChanged",t=>{var o,r;if(!((o=this.menu)!=null&&o.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((r=this.anchor)==null?void 0:r.blockId)&&e.offset>=this.anchor.offset){const i=t.getBlockById(e.blockId);if(wt(fe(we(t,i),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});h(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=wt(Ml(t,i,r));if(d(th,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,c=r-l;return t.selection.selectBlock(i,l),c&&(t.deleteTextFromBlock(i,l,c),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});h(this,"onShow",(t,e,o,r)=>{var i;if((i=this.options)!=null&&i.onShow)return this.options.onShow(this,e,o,r)});h(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});h(this,"queryItems",(t,e)=>this.options.queryItems(this,e));h(this,"renderMenuItem",(t,e)=>{var r,i;return(i=(r=this.options).renderMenuItem)==null?void 0:i.call(r,this,e)});this.editor=t,this.options=e,this.menu=new Xw(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,noResultMessage:e.noResultMessage,highlight:e.highlight,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var o;return!((o=this.menu)!=null&&o.isVisible)||Ga(e.key)?!1:tm(e)&&!To(e)?(setTimeout(()=>{this.resetItems()}),!1):Za(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:G(t),offset:e,leftText:o,trigger:r};const i=U(j(t)),s=K(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var u;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l,offset:c}=s,a=t.getBlockByIndex(e,o);if(G(a)!==l)return!1;if((u=this.menu)!=null&&u.isVisible)this.resetItems();else if(this.options.trigger.indexOf(i)!==-1){if(r>0&&this.options.needSpaceBeforeTrigger&&t.getBlockString(a)[r-1]!==" ")return!1;const f=wt(Ml(t,a,c));this.popup(a,c,f,i)}return!1}handleUpdateCompositionText(t,e,o,r,i){var a;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,o);return G(c)!==l||(a=this.menu)!=null&&a.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=wt(Ml(t,i,r));if(d(th,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);th.debug(`search text: ${c}`),this.menu.handleSearchText(c)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}const yn=y("table-dom");function ho(n){return`${G(n)}_scroll`}function $t(n){const t=n.querySelector("div[data-type=table-content] >table");return d(yn,t instanceof HTMLTableElement,"invalid table"),t}function wn(n,t){const o=n.getCustom(ho(t)).contentElement.firstElementChild;d(yn,o instanceof HTMLElement,"invalid table content");let r=o.querySelector(":scope >div[data-type=table-tools]");return r||(r=b("div",[],o),r.setAttribute("data-type","table-tools")),d(yn,r,"no table tools"),r}function x0(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function os(n){const t=n.querySelector(":scope div[data-type=editor-container]");return d(yn,t,"no child container in cell"),t}function tB(n){const o=x0(n).map(r=>{const i=os(r),s=U(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Ci.default(o)}function jt(n){return it(n)==="table"}function nh(n){const t=j(n);if(Ct(t))return null;const e=z(t);return d(yn,e,"no parent block"),jt(e)?t:nh(e)}function Ee(n){if(jt(n))return n;const t=j(n);if(Ct(t))return null;const e=z(t);return d(yn,e,"no parent block"),jt(e)?e:Ee(e)}function eB(n,t){const e=n.querySelector("colgroup");d(yn,e,"no colgroup");const o=e.children[t];return d(yn,o,"no col"),d(yn,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function S0(n){try{return $t(n),!0}catch{return!1}}function nB(n){return At(n).querySelector(":scope > .block-helper")}function oB(n){const t=z(n.contentElement);d(yn,t,"no block");const e=nB(t);if(e){const o=Math.min(n.contentElement.offsetLeft,n.rootElement.scrollLeft),r=t.getBoundingClientRect().width;e.style.right=`${o+r}px`}}const Ie=y("doc-table-grid");class rB{constructor(t){h(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){d(Ie,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){d(Ie,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return d(Ie,e,"get cell, no cell"),e}getCellAllowEmpty(t){return d(Ie,t>=0&&t<this.cols(),`get cell, invalid col, ${t}`),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}forEach(t){this._cells.forEach(t)}}class oh{constructor(t){h(this,"_data");h(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new rB(this.colCount));this.fillGrid(),d(Ie,t.colsWidth,"no colsWidth"),d(Ie,this.colCount===t.colsWidth.length,"invalid col count")}get rowCount(){return this._data.rows}get colCount(){return this._data.cols}getNextEmptyCell(t,e){let o=t,r=e;for(;;){if(o+=1,o===this.colCount&&(o=0,r+=1),r>=this.rowCount)return null;if(this._rows[r].getCellAllowEmpty(o)===void 0)return{col:o,row:r}}}fillGrid(){const t=this._data.children;d(Ie,t,"no children");let e=0,o=0;t.forEach((r,i)=>{const s=this._data[`${r}_colSpan`]||1,l=this._data[`${r}_rowSpan`]||1;for(let a=0;a<l;a++)for(let u=0;u<s;u++)this._rows[o+a].setCell(e+u,{col:e,row:o,containerId:r,virtual:u!==0||a!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,o);c?(e=c.col,o=c.row):d(Ie,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{d(Ie,i,"no cell"),d(Ie,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];d(Ie,r,`get cell, no row: ${o}`);const i=r.getCell(e);return d(Ie,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return d(Ie,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const sc=y("table-data");function iB(n){const t=n.firstElementChild;return d(sc,t,"no child element for cell"),d(sc,mn(t),"cell first child is not a container"),d(sc,We(t),"cell first child is not a container"),t}function sB(n){const t=z(n);d(sc,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=iB(c),u=U(a);e.push(u),(c.colSpan>1||c.rowSpan>1)&&(o[`${u}_colSpan`]=c.colSpan,o[`${u}_rowSpan`]=c.rowSpan)})});const r=n.rows.length,i=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,c)=>l+c,0);return{id:G(t),type:it(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function Go(n){return new oh(n)}function lB(n){return Go(sB(n))}const qt=y("table-grid"),cB=60;class aB{constructor(t,e){h(this,"containerId");h(this,"row");h(this,"col");h(this,"colSpan");h(this,"rowSpan");h(this,"virtual");h(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return d(qt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);d(qt,t.length===1,"containers !== 1"),d(qt,mn(t[0]),"not a container");const e=t[0];return d(qt,We(e),"not a child container"),e}}class dB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new aB(t,o))})}get cells(){return this._cells}getCell(t){return d(qt,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const of=class{constructor(t){h(this,"_rows",[]);this.table=t,lB(t).forEach(r=>{this._rows.push(new dB(t,r))});const o=this.colCount;this._rows.forEach(r=>{d(qt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(d(qt,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return d(qt,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){d(qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,o=[];for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});o.push(i)}return o}toRealCells(t){const e=[];return t.forEach(o=>{const r=this.getRealCell(o);e.findIndex(i=>i.containerId===r.containerId)===-1&&e.push(r)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){d(qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let o=0;o<e;o++){const r=this.getCell({row:o,col:t});if(r.virtual||r.colSpan>1||r.rowSpan>1)return r}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const o=this.getCellById(e.containerId);return d(qt,!o.virtual,"found a virtual cell"),o}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.col,o),r=Math.max(i.col+i.colSpan-1,r)}),d(qt,o<=r,"min > max"),d(qt,o>=0,"min < 0"),d(qt,r<this.colCount,"max >= colCount"),[o,r]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.row,o),r=Math.max(i.row+i.rowSpan-1,r)}),d(qt,o<=r,"min > max"),d(qt,o>=0,"min < 0"),d(qt,r<this.rowCount,"max >= rowCount"),[o,r]}getSpannedRange(t,e){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),i=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let C=o;C<=r;C++)for(let v=i;v<=s;v++)l.push(this.getCell({row:C,col:v}));const c=this.toRealCells(l);let a=1e4,u=1e4,f=-1,m=-1;return c.forEach(C=>{u=Math.min(C.col,u),a=Math.min(C.row,a),m=Math.max(C.col+C.colSpan-1,m),f=Math.max(C.row+C.rowSpan-1,f)}),[{row:a,col:u},{row:f,col:m}]}getAllCells(){return this.getCells({col:0,row:0},{col:this.colCount-1,row:this.rowCount-1})}sub(t,e){const o=[];for(let r=t.row;r<=e.row;r++){const i=[];for(let s=t.col;s<=e.col;s++){const l=this.getCell({row:r,col:s});i.push(l)}o.push(i)}return o}getAllContainers(){return this.getAllCells().map(e=>e.container)}getCells(t,e){const o=[],r=this.getSpannedRange(t,e),i=r[0],s=r[1],l=Math.min(i.row,s.row),c=Math.max(i.row,s.row),a=Math.min(i.col,s.col),u=Math.max(i.col,s.col);for(let f=l;f<=c;f++)for(let m=a;m<=u;m++){const C=this.getCell({row:f,col:m});C.virtual||o.push(C)}return o}map(t){const e=[];for(let o=0;o<this.rowCount;o++){const r=[];for(let i=0;i<this.colCount;i++){const s=this.getCell({row:o,col:i});r.push(t(s))}e.push(r)}return e}getBottomCell(t){const e=this.rowCount;let o=t,r=t.row;for(;o.containerId===t.containerId;){if(r+=1,r>=e)return null;o=this.getCell({row:r,col:t.col})}return this.getRealCell(o)}getTopCell(t){let e=t,o=t.row;for(;e.containerId===t.containerId;){if(o-=1,o<0)return null;e=this.getCell({row:o,col:t.col})}return this.getRealCell(e)}get cells(){let t=[];return this._rows.forEach(e=>{t=t.concat(e.cells)}),t}getVirtualCellContainersGrid(){return this.map(t=>t.containerId)}static virtualCellContainersGridToChildren(t){const e=t,o=[];return e.forEach(r=>{r.forEach(i=>{o.indexOf(i)===-1&&o.push(i)})}),o}getCellById(t){const o=this.cells.find(r=>r.containerId===t);return d(qt,o,"cell not found"),o}getCellByCellElement(t){const e=os(t);return this.getCellByContainerId(U(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=tB(t),o=this.caches.getSync(e,()=>(qt.debug("create table grid"),new of(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable($t(t))}};let et=of;h(et,"caches",new Of(cB));function lc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const uB=y("table-selection-range");function sn(n,t,e){var x,O,A,P;const o=et.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),c=r.custom,a=i.custom,u=(x=c==null?void 0:c.rowIndex)!=null?x:s.row,f=(O=c==null?void 0:c.colIndex)!=null?O:s.col,m=(A=a==null?void 0:a.rowIndex)!=null?A:l.row+l.rowSpan-1,C=(P=a==null?void 0:a.colIndex)!=null?P:l.col+l.colSpan-1,v=Math.min(u,m),w=Math.max(u,m),E=Math.min(f,C),L=Math.max(f,C);return{fromRow:v,toRow:w,fromCol:E,toCol:L}}function rh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===G(t)){const i=et.fromBlock(t),{start:s,end:l}=r;d(uB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:u,toRow:f}=sn(t,s,l);if(u===0&&f===i.rowCount-1)for(let m=c;m<=a;m++)o.add(m);if(c===0&&a===i.colCount-1)for(let m=u;m<=f;m++)e.add(m)}return{selectedRows:e,selectedColumns:o}}const $r=y("delete-columns");function T0(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromRow:s,toRow:l}=sn(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.rowCount-1}function ih(n){var O;const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!T0(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=sn(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.colCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(A=>A.containerId);for(let A=0;A<l.length;A++){const P=l[A];for(let V=o;V<=r;V++){const nt=P[V];s.add(nt)}P.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(A=>!c.has(A))),u=r-o+1,f=new Map,m=new Map;s.forEach(A=>{if(a.has(A))return;const P=i.getCellByContainerId(A);if(d($r,P.colSpan>1,"invalid effected cell, colSpan === 1"),P.col<o){d($r,c.has(A),"invalid effected cell, not exists");let Et=P.col+P.colSpan-1;Et>r&&(Et=r);const re=Et-o+1,Xn=P.colSpan-re;f.set(A,Xn);return}d($r,P.col<=r,"invalid effected cell, col > endCol");const V=P.col,nt=P.col+P.colSpan-1,ot=P.col-o,ut=nt-V+1-u+ot;d($r,ut>0,"invalid effected cell, newSpanned <= 0");const dt=Cn(t.doc);m.set(A,{newContainerId:dt,colSpan:ut})});for(let A=0;A<l.length;A++){const P=l[A];for(let V=o;V<P.length;V++){const nt=P[V],ot=m.get(nt);ot&&(P[V]=ot.newContainerId)}}const C=Y.default(t.getBlockData(e));C.colsWidth.splice(o,r-o+1),a.forEach(A=>{lc(C,A)}),f.forEach((A,P)=>{d($r,A>=1,"invalid modified colSpan, colSpan < 1"),A===1?delete C[`${P}_colSpan`]:C[`${P}_colSpan`]=A}),m.forEach((A,P)=>{lc(C,P);const{newContainerId:V,colSpan:nt}=A;d($r,nt>=1,"invalid newContainerData, colSpan < 1"),nt>1&&(C[`${V}_colSpan`]=nt);const ot=i.getCellByContainerId(P).rowSpan;ot>1&&(C[`${V}_rowSpan`]=ot)});const w=(O=l[0][o])!=null?O:l[0][o-1],E=t.getChildContainerData(w)[0],L=et.virtualCellContainersGridToChildren(l),x={...C,cols:C.cols-u,children:L};Go(x),t.updateBlockData(e,x,Lt(t,E.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))}const jr=y("delete-rows");function D0(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromCol:s,toCol:l}=sn(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.colCount-1}function sh(n){const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!D0(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=sn(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(x=>x.containerId);for(let x=r;x>=o;x--)l[x].forEach(A=>s.add(A)),l.splice(x,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(x=>!c.has(x))),u=r-o+1,f=new Map,m=new Map;s.forEach(x=>{if(a.has(x))return;const O=i.getCellByContainerId(x);if(d(jr,O.rowSpan>1,"invalid effected cell, rowSpan === 1"),O.row<o){d(jr,c.has(x),"invalid effected cell, not exists");let ut=O.row+O.rowSpan-1;ut>r&&(ut=r);const dt=ut-o+1,Et=O.rowSpan-dt;f.set(x,Et);return}d(jr,O.row<=r,"invalid effected cell, col > endCol");const A=O.row,P=O.row+O.rowSpan-1,V=O.row-o,nt=P-A+1-u+V;d(jr,nt>0,"invalid effected cell, newSpanned <= 0");const ot=Cn(t.doc);m.set(x,{newContainerId:ot,rowSpan:nt})});for(let x=o;x<l.length;x++){const O=l[x];for(let A=0;A<O.length;A++){const P=O[A],V=m.get(P);V&&(O[A]=V.newContainerId)}}const C=Y.default(t.getBlockData(e));a.forEach(x=>{lc(C,x)}),f.forEach((x,O)=>{d(jr,x>=1,"invalid modified rowSpan, rowSpan < 1"),x===1?delete C[`${O}_rowSpan`]:C[`${O}_rowSpan`]=x}),m.forEach((x,O)=>{lc(C,O);const{newContainerId:A,rowSpan:P}=x;d(jr,P>=1,"invalid newContainerData, rowSpan < 1"),P>1&&(C[`${A}_rowSpan`]=P);const V=i.getCellByContainerId(O).colSpan;V>1&&(C[`${A}_colSpan`]=V)});const v=l[o]?l[o][0]:l[o-1][0],w=t.getChildContainerData(v)[0],E=et.virtualCellContainersGridToChildren(l),L={...C,rows:C.rows-u,children:E};Go(L),t.updateBlockData(e,L,Lt(t,w.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))}const rs=y("table-range");function cc(n){d(rs,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;d(rs,!t.isSimple(),"invalid start pos type"),d(rs,!e.isSimple(),"invalid end pos type");const o=n.getEditor();d(rs,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);d(rs,it(r)==="table","invalid block type, not a table block");const i=$t(r),s=et.fromTable(i),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),a=Math.min(l.row,c.row),u=Math.max(l.row,c.row),f=Math.min(l.col,c.col),m=Math.max(l.col,c.col),C=s.getCell({row:a,col:f}),v=s.getCell({row:u,col:m});return{editor:o,block:r,table:i,startCell:C,endCell:v,startRow:a,startCol:f,endRow:u,endCol:m}}const lh=y("split-cell");function ch(n,t,e){const o=et.fromBlock(t),r=o.getRealCell(e);d(lh,!r.virtual,"should not split virtual cell"),d(lh,r.colSpan>1||r.rowSpan>1,"cell does not has span data");const i=o.getVirtualCellContainersGrid();for(let f=0;f<r.rowSpan;f++)for(let m=0;m<r.colSpan;m++){if(f===0&&m===0)continue;const C=f+r.row,v=m+r.col,w=Cn(n.doc);i[C][v]=w}const s=n.getBlockData(t),l=Y.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=et.virtualCellContainersGridToChildren(i);const a=n.getChildContainerData(r.containerId)[0];d(lh,a,"no child block");const u=Lt(n,a.id,0);Go(l),n.updateBlockData(t,l,u)}function hB(n,t,e){e.forEach(o=>{const r=et.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&ch(n,t,o)})}function L0(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=cc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function ah(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=cc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return hB(t,e,l),!0}const Hr=y("merge-cells");function M0(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=cc(e);return s.cell!==l.cell}function R0(n){const t=cc(n),e=t.endCell,o=e.row+e.rowSpan-1,r=e.col+e.colSpan-1,i=G(t.block),s=t.editor;ah(n);const l=s.getBlockById(i),c=$t(l),{startRow:a,startCol:u}=t,f=Y.default(s.getBlockData(l));d(Hr,f.children,"no table children");const m=et.fromTable(c),C=[];for(let ut=a;ut<=o;ut++)for(let dt=u;dt<=r;dt++){const Et=m.getCell({row:ut,col:dt});d(Hr,!Et.virtual,"cell is virtual"),C.push(Et)}d(Hr,C.length>0,"no selected cells");const v=C[0],w=C.slice(1),E=m.getCellByContainerId(v.containerId).container,L=[];w.forEach(ut=>{const dt=m.getCellByContainerId(ut.containerId).container,Et=U(dt);if(!ud(s,dt)){const re=Xd(s,Et);s.insertDocAt(E,Ve(E),re)}L.push(Et)});const x=U(E),O=r-u+1,A=o-a+1;f[`${x}_colSpan`]=O,f[`${x}_rowSpan`]=A,L.forEach(ut=>{d(Hr,f.children,"no table children");const dt=f.children.indexOf(ut);d(Hr,dt>0,"no deleted container"),f.children.splice(dt,1)});const P=f,nt=s.getChildContainerData(x)[0];d(Hr,nt,"no child block");const ot=Lt(s,nt.id,0);Go(P),s.updateBlockData(l,P,ot),s.deleteChildContainers(L)}const dh=10,fB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class uh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(it(e)!=="table")return[];const r={blockId:G(e),blockKind:Ge(t,e),blockType:it(e)},i=[];M0(t,e,o)&&i.push({id:"table/merge-cells",name:"merge cells",icon:ew,groupIndex:dh,...r}),L0(t,e,o)&&i.push({id:"table/split-cell",name:"split cell",icon:nw,groupIndex:dh,...r});const s=T0(t,e,o),l=D0(t,e,o);return s&&l&&i.push({id:"table/delete",name:"delete tables",icon:ow,groupIndex:dh,...r}),i}executeCommand(t,e,o,r,i,s){return it(e)!=="table"||!new Set(fB).has(r.id)?!1:r.id==="table/merge-cells"?(R0(o),!0):r.id==="table/split-cell"?(ah(o),!0):r.id==="table/delete-columns"?(ih(o),!0):r.id==="table/delete-rows"?(sh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var O0=(n=>(n.COL_TITLE_TABLE="col-title-table",n.COL_TITLE_ITEM="col-title-item",n.STRIPE_STYLE_TABLE="stripe-style-table",n.NO_BORDER="table-no-border",n))(O0||{});const hh=6,is=20;function mB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function gB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function pB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function CB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function bB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function vB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function kB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const fh=y("get-selected-containers");function mh(n,t,e,o){d(fh,e.blockId===o.blockId,"only allow select in single table block"),d(fh,G(t)===e.blockId,"only allow select in single table block");const r=et.fromBlock(t),i=r.getCellByContainerId(e.childContainerId),s=r.getCellByContainerId(o.childContainerId);if(e.custom===void 0||o.custom===void 0)return r.getCells(i,s).map(E=>r.getCellContainer(E));const{fromCol:l,toCol:c,fromRow:a,toRow:u}=sn(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:u,col:c}).forEach(v=>{v.forEach(w=>{const E=r.getCellByContainerId(w.containerId);E.col<l||E.row<a||E.col+E.colSpan-1>c||E.row+E.rowSpan-1>u||f.has(w.containerId)||(f.add(w.containerId),m.push(E.container))})}),m}function yB(n,t,e){d(fh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return mh(n,o,t,e)}const Zo=y("table-cell-dom");function wB(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");d(Zo,r,"no parent cell");const i=z(r);if(d(Zo,i,"no parent block"),i===t)return r;o=i}return d(Zo,!1,"filed to get cell by child block id"),null}function qn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return d(Zo,e.childContainerId,"block position must have childContainerId attribute"),e;const r=wB(n,t,e.blockId),i=U(os(r));return bt(t,i)}function gh(n,t){const e=n.selection.range,o=qn(n,t,e.start),r=qn(n,t,e.end);return sn(t,o,r)}function A0(n,t,e,o){d(Zo,jt(t),"invalid table block");const r=wn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");d(Zo,l,"no top border bar container"),l.querySelectorAll(".table-border-bar-cell.top").forEach(a=>{const u=parseInt(a.getAttribute("data-top-index")||"0",10);o.includes(u)?M(a,"danger"):F(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");d(Zo,l,"no left border bar container"),l.querySelectorAll(".table-border-bar-cell.left").forEach(a=>{const u=parseInt(a.getAttribute("data-left-index")||"0",10);e.includes(u)?M(a,"danger"):F(a,"danger")})};i(),s()}function Fr(n,t,e=!0,o){const i=et.fromBlock(t).map(u=>u),{fromCol:s,toCol:l,fromRow:c,toRow:a}=gh(n,t);for(let u=0;u<i.length;u++){const f=i[u];for(let m=0;m<f.length;m++){const C=f[m],v=o?m>=s&&m+C.colSpan-1<=l:u>=c&&u+C.rowSpan-1<=a;e&&v?C.virtual||M(C.cell,"danger"):C.virtual||F(C.cell,"danger")}}}function zr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){A0(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=gh(n,t);if(o)for(let u=s;u<=l;u++)i.add(u);else for(let u=c;u<=a;u++)r.add(u);A0(n,t,Array.from(r),Array.from(i))}function _0(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=gh(n,t),l=et.fromBlock(t);let c=null,a=null;return e?(c=l.getCell({col:o,row:0}),a=l.getCell({col:r,row:l.rowCount-1}),Vt(n,{anchor:bt(t,c.containerId,{colIndex:o,rowIndex:0}),focus:bt(t,a.containerId,{colIndex:r,rowIndex:l.rowCount-1})})):(c=l.getCell({col:0,row:i}),a=l.getCell({col:l.colCount-1,row:s}),Vt(n,{anchor:bt(t,c.containerId,{colIndex:0,rowIndex:i}),focus:bt(t,a.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function BB(n,t){const e=n.selection.range,o=qn(n,t,e.start),r=qn(n,t,e.end);return mh(n,t,o,r)}const N0=["style-bg-color-0","style-bg-color-1","style-bg-color-2","style-bg-color-3","style-bg-color-4","style-bg-color-5","style-bg-color-6","style-bg-color-7","style-bg-color-8","style-bg-color-9","style-bg-color-10","style-bg-color-11","style-bg-color-12","style-bg-color-13"];function P0(n){return`style-bg-color-${n}`}function ss(n){return`${n}_background`}function EB(n,t,e){const o=$t(n),s=(e!=null?e:et.fromTable(o)).getCell(t).cell;for(let l=0;l<N0.length;l++){const c=N0[l];if(lt(s,c))return c}}function $0(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Y.default(n.getBlockData(t))},s=qn(n,t,o.start),l=qn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[ss(c)]=void 0:i[ss(c)]=P0(e)}else{const c=et.fromBlock(t),a=sn(t,s,l),u=new Set;for(let f=a.fromRow;f<=a.toRow;f++)for(let m=a.fromCol;m<=a.toCol;m++){const C=c.getCell({row:f,col:m});!u.has(C.containerId)&&C.col>=a.fromCol&&C.row>=a.fromRow&&C.col+C.colSpan-1<=a.toCol&&C.row+C.rowSpan-1<=a.toRow&&(u.add(C.containerId),e===-1?i[ss(C.containerId)]=void 0:i[ss(C.containerId)]=P0(e))}}n.updateBlockData(t,i)}function IB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const j0=y("table-chart");function xB(n,t){const e=wn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function SB(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){xB(n,t);return}const r=[],i=et.fromBlock(t),s=["line","bar","pie","radar"];let l=i.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let w=1;w<i.colCount;w++)c.push(i.getCell({row:0,col:w}).container.innerText);for(let w=1;w<i.rowCount;w++){const E=i.getCell({row:w,col:0}),x=E.container.innerText,O=[];for(let re=1;re<i.colCount;re++){const Xn=i.getCell({row:w,col:re}).container.innerText,te=Number.parseFloat(Xn)||0;O.push(te)}let A;const P=EB(t,E,i);P?A=window.getComputedStyle(n.rootElement).getPropertyValue(`--${P}`).trim():A=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[V,nt,ot,ut]=A?_a.fromString(A).toRgbaArray():[];if(!V&&!nt&&!ot&&!ut){const re=(w-1)%n.options.colors.length;A=n.options.colors[re],[V,nt,ot,ut]=_a.fromString(A).toRgbaArray()}const dt=A,Et=_a.fromRgba([V,nt,ot,ut/3]).toHexString();r.push({label:x,data:O,borderColor:dt,backgroundColor:Et,borderWidth:2})}const a=wn(n,t);let u=null,f=a.querySelector(".editor-table-chart");f?u=f.chartObject:f=b("div",["editor-table-chart"],a);const m=f;d(j0,m,"no chart container");const C=n.getComponentOptions("table"),v=(C==null?void 0:C.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await xo(v,"editor-chartjs"),u&&l!==u.config.type&&(u.destroy(),u=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(L=>{L.remove()}));const w=Pa.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(u)Pa.default(u.config,w),u.update();else{const L=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");u=new window.Chart(L,w),f.chartObject=u}}catch(w){j0.error(`failed to resolve chart cdn: ${JSON.stringify(w)}`)}}async function H0(n,t){await Ue.lock("updateTableChart");try{await SB(n,t)}finally{Ue.release("updateTableChart")}}const F0=Qt.default(H0,1e3);let z0=null;function ph(n,t,e){if(z0!==t&&(F0.flush(),z0=t),e.updateNow){H0(n,t);return}F0(n,t)}function Ch(n,t){jt(t)&&ph(n,t,{updateNow:!1})}function TB(n,t){jt(t)&&ph(n,t,{updateNow:!0})}const $e={SCROLL:"container-scroll-tool",COMMON:"container-border-shadow",RIGHT:"container-right-border-shadow",LEFT:"container-left-border-shadow",LAYOUT_SIGN:"container-layout-border-shadow",ACTIVE:"active"},ac={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},fo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function dc(n,t){return n.containers.get(t)}function U0(n){return n.closest(`.${fo.SCROLL_CONTAINER}`)}function ln(n){return n.firstElementChild}function xe(n){return n.closest(`.${fo.CONTAINER}`)}function ls(n){const t=xe(n);let e=t.querySelector(`:scope >.${fo.TOOL}`);return e||(e=b("div",[fo.TOOL],t)),e}function DB(n){return xe(n).firstElementChild}function cs(n){const t=window.getComputedStyle(n);return{paddingBottom:parseFloat(t.paddingBottom),paddingTop:parseFloat(t.paddingTop),paddingLeft:parseFloat(t.paddingLeft),paddingRight:parseFloat(t.paddingRight)}}function bh(n,t){const e=xe(t),o=dc(n,e),r=(o==null?void 0:o.safeRightSpace)||0,i=(o==null?void 0:o.safeLeftSpace)||0,l=(o==null?void 0:o.locatingContainer).getBoundingClientRect(),c=e.getBoundingClientRect(),a=c.width;let u=Math.floor(c.left-l.left-i);u<0&&(u=0);let f=l.right;f-=r;let m=f-c.right;return m<0&&(m=0),u=Math.round(u),m=Math.round(m),{originWidth:a,maxLeft:u,maxRight:m}}function LB(n,t){const e=bh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${0-o}px`,t.style.paddingLeft=`${o}px`}function MB(n,t){const e=bh(n,t);t.style.marginRight=`${0-e.maxRight}px`}function RB(n){if(n!==document.documentElement&&n!==document.body)return n.getBoundingClientRect();const t=0,e=0,o=document.documentElement.clientWidth,r=document.documentElement.clientHeight;return new DOMRect(t,e,o,r)}const V0=y("scroll-bar-handle"),OB=2;function Ur(n){const t=ls(n);let e=t.querySelector(`.${ac.SCROLL_BAR}`);return e||(e=b("div",[ac.SCROLL_BAR],t)),d(V0,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function uc(n,t){const e=U0(t),o=Ur(e),{paddingLeft:r,paddingRight:i}=cs(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const s=bh(n,e),{originWidth:l,maxRight:c}=s;MB(n,e),LB(n,e);const a=e.scrollWidth-e.clientWidth;d(V0,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${l+c-r-i}px`,o.firstElementChild.style.width=`${l+c+a-r-i}px`}function AB(n,t){const e=ln(n),{paddingLeft:o}=cs(e);if(lt(t,"fixed")){const i=xe(n).getBoundingClientRect();t.style.left=`${i.left+o}px`}else t.style.left=`${o}px`}function Vr(n,t){const e=n.getParentScrollContainer(),o=RB(e),r=t.getBoundingClientRect(),i=Ur(t),s=i.getBoundingClientRect(),l=dc(n,xe(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=ln(t),{paddingTop:u,paddingBottom:f}=cs(a),m=document.documentElement.clientHeight-c,C=o.top+e.clientHeight-m,v=m+Math.min(0,C);if(t.scrollWidth>t.clientWidth&&r.top+u<v-s.height&&r.bottom>v-s.height+f){M(i,ac.FIXED);const E=C>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+OB+E}px`}else F(i,ac.FIXED),i.style.bottom=`${f-s.height}px`;AB(t,i)}class _B{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(xe(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;Vr(this.scrollCore,e);const o=ln(e);uc(this.scrollCore,o)});this.scrollCore=t,this.callback=e;const r={root:this.scrollCore.getParentScrollContainer(),rootMargin:"20px",threshold:0};this.intersectionObserver=new IntersectionObserver(this.handleIntersection,r)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.intersectionObserver.observe(t)}unbind(t){this.intersectionObserver.unobserve(t)}destroy(){this.intersectionObserver.disconnect()}}const Yo=y("container-scroll-shadow");function q0(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=cs(e);o.style.top=`${i.top-r.top+s}px`,o.style.bottom=`${r.bottom-i.bottom+l}px`}function W0(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function NB(n){const t=ls(n);d(Yo,t,"no container tools");let e=t.querySelector(`.${$e.LEFT}`);if(!e){const l=ln(n),c=[$e.COMMON,$e.LEFT];e=b("div",c,t),d(Yo,e instanceof HTMLDivElement,"invalid child for container tools"),q0(e,n,l)}d(Yo,e instanceof HTMLElement,"invalid child for container tools");const r=xe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${i.left-r.left}px`;const s=n.scrollLeft;d(Yo,e instanceof HTMLDivElement,"invalid child for container tools"),W0(e,s),M(e,$e.ACTIVE)}function PB(n){const t=ls(n);let e=t.querySelector(`.${$e.RIGHT}`);if(!e){const l=ln(n),c=[$e.COMMON,$e.RIGHT];e=b("div",c,t),d(Yo,e instanceof HTMLDivElement,"no div, create shadow failed"),q0(e,n,l)}d(Yo,e instanceof HTMLElement,"");const r=xe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${r.right-i.right}px`;const s=n.scrollWidth-n.scrollLeft-n.clientWidth;d(Yo,e instanceof HTMLDivElement,"no shadow element"),W0(e,s),M(e,$e.ACTIVE)}function $B(n){const e=ls(n).querySelector(`.${$e.LEFT}`);e&&F(e,$e.ACTIVE)}function jB(n){const e=ls(n).querySelector(`.${$e.RIGHT}`);e&&F(e,$e.ACTIVE)}function as(n){const t=Math.round(n.scrollLeft),e=ln(n),{paddingLeft:o,paddingRight:r}=cs(e);n.scrollWidth-o<=n.clientWidth-r||n.scrollWidth-o<=t+n.clientWidth-r?jB(n):PB(n),e&&n.scrollLeft>=e.offsetLeft+o?NB(n):$B(n)}class HB{constructor(t){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=ln(e);as(e),uc(this.scrollCore,o),Vr(this.scrollCore,e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(xe(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleContentResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}const G0=y("container-scroll-observer");class FB{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;d(G0,e instanceof Element,"invalid target for scroll event");const o=Ur(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),as(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;d(G0,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=DB(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),as(i),this.callback(i)});h(this,"handlePrevent",t=>{t.stopPropagation()});h(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});h(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});h(this,"bindContentScroll",Qt.default(this.bindContentScrollCore,300));h(this,"bind",Qt.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=Ur(t);o||(t.scrollLeft=e),o&&r.scrollLeft!==e&&(r.scrollLeft=e)}bindCore(t){this.unbind(t),t.addEventListener("scroll",this.handleScroll),t.addEventListener("mousedown",this.handlePrevent)}unbind(t){t.removeEventListener("scroll",this.handleScroll),t.removeEventListener("mousedown",this.handlePrevent)}}class zB{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Vr(this.scrollCore,t)})});h(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});h(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const UB=y("scroll-wrap-resize-observer");class VB{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(xe(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;d(UB,e instanceof HTMLElement,"invalid target for observer entry");const o=U0(e);uc(this.scrollCore,e),as(o),Vr(this.scrollCore,o)});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleScrollWrapResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}class qB{constructor(t){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=ln(e);as(e),uc(this.scrollCore,o),Vr(this.scrollCore,e)})});h(this,"handleResize",t=>{t.forEach(e=>{const o=this.scrollContainersMap.get(e.target);o!=null&&o.length&&this.handleResizeEntry(o)})});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleResize)}bind(t){var r,i;const e=xe(t),o=(r=dc(this.scrollCore,e))==null?void 0:r.locatingContainer;this.scrollContainersMap.has(o)?(i=this.scrollContainersMap.get(o))==null||i.push(t):(this.scrollContainersMap.set(o,[t]),this.resizeObserver.observe(o))}unbind(t){var i,s;const e=xe(t),o=(i=dc(this.scrollCore,e))==null?void 0:i.locatingContainer;if(!o)return;const r=this.scrollContainersMap.get(o);this.scrollContainersMap.set(o,(r==null?void 0:r.filter(l=>l!==t))||[]),(s=this.scrollContainersMap.get(o))!=null&&s.length||(this.resizeObserver.unobserve(o),this.scrollContainersMap.delete(o))}destroy(){this.scrollContainersMap.clear(),this.resizeObserver.disconnect()}}const sF="";class WB extends Wt.TypedEmitter{constructor(e){super();h(this,"containerIntersectionObserver",null);h(this,"containerResizeObserver",null);h(this,"containerScrollObserver",null);h(this,"parentContainerScrollObserver",null);h(this,"scrollWrapResizeObserve",null);h(this,"locatingContainerResizeObserver",null);h(this,"isWindowEventBind",!1);h(this,"containers",new Map);h(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=ln(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});h(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{Vr(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new HB(this)),this.containerScrollObserver||(this.containerScrollObserver=new FB(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new zB(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new VB(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new qB(this)),this.isWindowEventBind||(window.addEventListener("resize",this.handleWindowEffect),this.getParentScrollContainer()!==document.documentElement&&window.addEventListener("scroll",this.handleWindowEffect))}getParentScrollContainer(){return this.parentContainer}getScrollContainerInViewable(){var e;return(e=this.parentContainerScrollObserver)==null?void 0:e.scrollContainers}unbindCore(e,o){var i,s,l,c,a,u;const r=Ur(e);(i=this.containerScrollObserver)==null||i.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(r),(l=this.scrollWrapResizeObserve)==null||l.unbind(o),(c=this.containerResizeObserver)==null||c.unbind(e),(a=this.parentContainerScrollObserver)==null||a.unbindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.unbind(e)}bindCore(e,o){var i,s,l,c,a,u;if(this.unbindCore(e,o),!e.closest("body"))return;const r=Ur(e);(i=this.containerScrollObserver)==null||i.bindContentScrollCore(e),(s=this.containerScrollObserver)==null||s.bindCore(r),(l=this.scrollWrapResizeObserve)==null||l.bind(o),(c=this.containerResizeObserver)==null||c.bind(e),(a=this.parentContainerScrollObserver)==null||a.bindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new _B(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=ln(o);this.unbindCore(o,r),this.containers.delete(e),(i=this.containerIntersectionObserver)==null||i.unbind(o),this.containers.size||this.destroy()}destroy(){var e,o,r,i,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(o=this.containerIntersectionObserver)==null||o.destroy(),(r=this.containerResizeObserver)==null||r.destroy(),(i=this.scrollWrapResizeObserve)==null||i.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const Z0=y("scroll-container"),hc=new Map;class GB extends Wt.TypedEmitter{constructor(){super(...arguments);h(this,"scrollListener");h(this,"options");h(this,"scrollContainerElement");h(this,"init",e=>{this.options=e;const o=b("div",[fo.CONTAINER],e.parentElement);St.isMac&&M(o,fo.MAC);const r=b("div",[fo.SCROLL_CONTAINER],o),i=b("div",[fo.SCROLL_AREA],r);i.style.paddingLeft=e.paddingLeft?`${e.paddingLeft}px`:"",i.style.paddingTop=e.paddingTop?`${e.paddingTop}px`:"",i.style.paddingBottom=e.paddingBottom?`${e.paddingBottom}px`:"",i.style.paddingRight=e.paddingRight?`${e.paddingRight}px`:"",i.appendChild(e.childElement);const s=e.parentContainer;this.scrollListener=hc.get(s),this.scrollListener||(this.scrollListener=new WB(s),hc.set(s,this.scrollListener)),this.scrollListener.unbind(o),this.scrollListener.bind(o,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollContainerElement=r});h(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return d(Z0,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),ln(this.scrollContainerElement)}get scrollOptions(){return d(Z0,this.options,"options cannot be undefined"),{...this.options}}handleBaseListenerDestroy(e){e.destroy()}destroy(){var o;(o=this.scrollListener)==null||o.off("scroll",this.handleContainerScroll);const e=xe(this.contentElement);e&&hc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),hc.delete(i))})}}function ZB(){return new GB}const fc=100,YB=40,vh=y("column-width");function QB(n,t,e){eB(n,t).style.width=`${e}px`}function KB(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const o=et.fromTable(n),r=Array(o.colCount).fill(-1),i=n.getBoundingClientRect().left;o.toRealCells(o.cells).forEach(c=>{const a=c.col+c.colSpan-1;r[a]===-1&&(r[a]=c.cell.getBoundingClientRect().right-i)}),vh.debug(`cellRightOffsets1: ${r.join()}`);for(let c=0;c<r.length;c++){const a=r[c];if(a===-1||c===0)continue;let u=c-1;for(;r[u]===-1&&(u--,u!==-1););const f=u===-1?0:r[u],C=(a-f)/(c-u);for(let v=u+1;v<c;v++)r[v]=f+C*(v-u)}vh.debug(`cellRightOffsets2: ${r.join()}`);const s=[];let l=0;for(let c=0;c<r.length;c++){const a=r[c];s.push(a-l),l=a}return vh.debug(`widths: ${s.join()}`),s}function ds(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const JB=y("table-resize-gripper"),Y0=7,kh=(Y0-1)/2,XB=3;function tE(n,t,e){const{rows:o}=n;for(let r=0;r<o.length;r++){const i=o[r],s=Array.from(i.cells);for(let l=0;l<s.length;l++){const c=s[l],a=c.getBoundingClientRect(),u=Math.round(a.right);if(Math.abs(t-u)<=kh&&a.top<=e&&e<=a.bottom)return c}}return null}function eE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function yh(n,t){return wn(n,t).querySelector(".table-resize-gripper")}function Q0(n,t){const e=yh(n,t);d(JB,!e,"resize gripper has already exists");const o=wn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function K0(n,t,e){let o=yh(n,t);o||(o=Q0(n,t));const i=$t(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(ho(t)).contentElement.getBoundingClientRect(),u=s.right-a.left;o.style.left=`${u-kh-hh-is}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${Y0}px`}function wh(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function nE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function oE(n,t,e,o){const r=t,i=et.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=ds(e);let a=o;const u=(m,C)=>{const v=C+1,w=m.col+m.colSpan;return c.slice(v,w).reduce((L,x)=>L+x,0)},f=new Set;for(let m=0;m<i.rowCount;m++){const C=i.getCell({row:m,col:l});if(f.has(C.cell))continue;f.add(C.cell);const v=C.cell,w=v.getBoundingClientRect();let E=o-w.left+kh-XB;const L=os(v),x=dd(n,L)||YB*C.colSpan,O=u(C,l),A=x-O;E<A&&(E=A);const P=w.left+E;a=Math.max(a,P)}return a}const rE=y("table-resize-drag-drop");class iE{constructor(t,e,o,r){h(this,"cursor","col-resize");this.editor=t,this.elem=e,this.data=o,this.onEnd=r}onDragStart(t,e,o){}onDragging(t,e,o,r,i){const{table:s,block:l,draggingRefCell:c}=t.data,u=oE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;d(rE,c,"no dragging cell");const m=et.fromTable(s).getCellByCellElement(c),C=m.col+m.colSpan-1,w=ds(s).slice(0,C).reduce((L,x)=>L+x,0),E=u-w;QB(s,C,E),K0(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=ds(t.data.table);nE(this.editor,t.data.block,s),wh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function sE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=z(e);return!o||!n.contains(o)||!jt(o)?null:o}y("table-resize");class lE{constructor(t){h(this,"draggingRefCell",null);h(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const o=e.target;if(!(o instanceof Element)||o.closest(".table-indicator"))return;const i=e,s=sE(t,i);if(!s||!S0(s)){wh(t);return}this.updateGripper(s,i.x,i.y)});this.editor=t,t.domEvents.addEventListener(document,"mousemove",this.handleMouseMove)}destroy(){this.editor.domEvents.removeEventListener(document,"mousemove",this.handleMouseMove)}updateGripper(t,e,o){const r=$t(t),i=tE(r,e,o);if(i){if(!yh(this.editor,t)){if(eE(this.editor))return;const l=Q0(this.editor,t),c={block:t,table:r,draggingRefCell:i};Va(new iE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}K0(this.editor,t,i)}else wh(this.editor)}}function J0(n){n.addCustom("table-mouse-event-handler",t=>new lE(t))}const X0=y("table-insert-column");function t5(n,t,e){const o=$t(t),r=et.fromTable(o),i=r.colCount;d(X0,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();for(let m=0;m<s.length;m++){const C=s[m],v=C[e-1],w=C[e];if(e===0||e===C.length||v!==w){const E=Cn(n.doc);C.splice(e,0,E)}else C.splice(e,0,v),l.add(v)}n.doc.endBatchUpdate();const c=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_colSpan`,v=c[C];d(X0,typeof v=="number"&&v>1,`no colSpan for containerId ${m}, ${v}`),c[C]=v+1});const a=c.colsWidth.concat();a.splice(e,0,fc);const u=et.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:u,colsWidth:a};Go(f),n.updateBlockData(t,f)}const mc=y("table-insert-row");function e5(n,t,e){const o=$t(t),r=et.fromTable(o),i=r.rowCount;d(mc,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();const c=[];for(let m=0;m<r.colCount;m++){const C=e>0&&s[e-1][m],v=e<r.rowCount&&s[e][m];if(d(mc,C||v,"no top and bottom cell"),e===0||e===r.rowCount||C!==v){const w=Cn(n.doc);c.push(w)}else d(mc,C,"no top cell"),c.push(C),l.add(C)}n.doc.endBatchUpdate(),s.splice(e,0,c);const a=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_rowSpan`,v=a[C];d(mc,typeof v=="number"&&v>1,`no rowSpan for containerId ${m}, ${v}`),a[C]=v+1});const u=et.virtualCellContainersGridToChildren(s),f={...a,rows:a.rows+1,children:u};Go(f),n.updateBlockData(t,f)}const Bh=y("paste-table-in-table-block");function cE(n,t,e,o){let r=et.fromBlock(e);const i=t.blocks.root[0];d(Bh,i,"no table data"),d(Bh,i.type==="table",`table data type is not table, but ${i.type}`);const s=i,l=r.getCellByCellElement(o),c=s.cols,a=s.rows,u=l.col,f=l.row,m=u+c,C=f+a,v=[];for(let w=u;w<m&&w<r.colCount;w++)for(let E=f;E<C&&E<r.rowCount;E++){const L=r.getCell({col:w,row:E});L.virtual?L.virtual&&v.push({col:w,row:E}):(L.colSpan>1||L.rowSpan>1)&&v.push({col:w,row:E})}n.undoManager.runInGroup(()=>{if(v.forEach(x=>{const O=et.fromBlock(e).getCell(x);(O.colSpan>1||O.rowSpan>1)&&ch(n,e,x)}),m>r.colCount)for(let x=r.colCount;x<m;x++)t5(n,e,x);if(C>r.rowCount)for(let x=r.rowCount;x<C;x++)e5(n,e,x);r=et.fromBlock(e);const w=new oh(s);let E;for(let x=0;x<w.colCount;x++)for(let O=0;O<w.rowCount;O++){const A=w.getCell({col:x,row:O});if(!A.virtual){const P=Gd(n.editorBlocks,t,A.containerId),V=u+x,nt=f+O,ot={col:V,row:nt},ut=r.getCellContainer(ot);Cp(n,ut,P),E=ut}}d(Bh,E,"no last container");const L=Gt(E);n.selection.selectBlock(L,Z(n,L))})}const n5=y("paste-in-table-block");class aE{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePasteDoc(t,e){if(!t.selection.range.isSimple()||t.selection.range.start.offset!==0)return!1;const r=t.selection.startBlock,i=j(r);if(Ct(i)||!ud(t,i))return!1;const s=z(i);if(d(n5,s,"no parent block"),!jt(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;n5.debug("paste child table in table");const a=et.fromBlock(s).getCellByContainerId(U(i)).cell;return cE(t,e,s,a),!0}}function o5(n){n.addCustom("table-block-paste-event",t=>new aE(t))}const Eh=y("table-select-columns");function dE(n,t,e,o,r){d(Eh,jt(t),"is not a table block");const i=et.fromBlock(t);d(Eh,e>=0&&e<i.colCount,"invalid from"),d(Eh,o>0&&e+o<=i.colCount,"invalid count");const s=i.getCell({row:0,col:e}),l=i.getCell({row:i.rowCount-1,col:e+o-1}),c=bt(t,s.containerId,{colIndex:e,rowIndex:0}),a=bt(t,l.containerId,{colIndex:e+o-1,rowIndex:i.rowCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const Ih=y("table-select-columns");function uE(n,t,e,o,r){d(Ih,jt(t),"is not a table block");const i=et.fromBlock(t);d(Ih,e>=0&&e<i.rowCount,"invalid from"),d(Ih,o>0&&e+o<=i.rowCount,"invalid count");const s=i.getCell({row:e,col:0}),l=i.getCell({row:e+o-1,col:i.colCount-1}),c=bt(t,s.containerId,{rowIndex:e,colIndex:0}),a=bt(t,l.containerId,{rowIndex:e+o-1,colIndex:i.colCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const lF="",r5=y("get-toolbar-reference-client");function hE(n,t){const e=n.selection.range;if(!e.isSimple()){d(r5,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);d(r5,ct(n,s),"not a complex block");const l=kt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const o=e.isReverse()?t.start:t.end,r=Vt(n,{anchor:o,focus:o}),i=Oo(n,t.block,r);if(i.length!==0)return i[0]}function fE(n){var t,e;if(n.children){let o=!1;const r=[];for(const i of n.children){if((t=i.states)!=null&&t.includes("checked")){o=!0;break}(e=n.defaultCheckedChildren)!=null&&e.includes(i.id)&&r.push(i)}if(!o&&(r==null?void 0:r.length))for(const i of r)Array.isArray(i.states)?i.states.push("checked"):i.states=["checked"]}}function gc(n){const t=(r,i)=>{const s=r.findIndex(c=>c.id===i.id);if(s===-1){r.push(i);return}const l=r[s];if(l.value!==i.value&&delete l.value,!!l.states){if(!i.states){l.states=[];return}l.states=$a.default(l.states,i.states)}},e=[],o=new Map;return n.forEach(r=>{var i,s;(i=r.children)!=null&&i.length&&(o.has(r.id)?(s=o.get(r.id))==null||s.push(...r.children):o.set(r.id,[...r.children])),t(e,r)}),o.forEach((r,i)=>{const s=e.find(l=>l.id===i);s&&(s.children=gc(r),fE(s))}),e}function pc(n){return n.getCustom("toolbar-handler")}const cF="";class mE{constructor(){h(this,"linkPopup",null);h(this,"form",{});h(this,"onFinished",null);h(this,"onClose",null);h(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:o}=this.form;(t=this.onFinished)==null||t.call(this,e.getInputValue()||o.getInputValue(),o.getInputValue()),this._destroy()}catch{}});h(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});h(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});h(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector(".submit-button");t.disabled=!1});h(this,"handleTextKeyboard",t=>{var e;if(!t.isComposing){if(t.key==="Enter"){(e=this.form.linkUrl)==null||e.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});h(this,"handleUrlKeyboard",t=>{if(!t.isComposing){if(t.key==="Enter"){this.handleOk(),t.preventDefault();return}t.key==="Escape"&&this.handleClose()}})}async checkValue(){const{linkUrl:t}=this.form;if(!t.getInputValue())throw t.setFieldError(S.t("link.urlPlaceholder")),new Error(S.t("link.urlPlaceholder"))}editLink(t){var u,f;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new rc(this.createPopupContent(o,r)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=i,s&&(this.onClose=s);const c=(u=this.linkPopup)==null?void 0:u.content.querySelector(".submit-button"),a=(f=this.linkPopup)==null?void 0:f.content.querySelector(".cancel-button");c==null||c.addEventListener("click",this.handleOk),a==null||a.addEventListener("click",this.handleClose)}createPopupContent(t,e){const o=b("div",["link-popup-content"],null);this.form.linkText=Xu(o,{label:S.t("link.textLabel"),required:!1,placeholder:S.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Xu(o,{className:"link-popup-gap",label:S.t("link.urlLabel"),required:!0,placeholder:S.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,S.t("link.cancelText"));const i=b("button",["submit-button"],r,S.t("link.submitText"));return i.disabled=!0,o}_destroy(){var o,r,i,s;const t=(o=this.linkPopup)==null?void 0:o.content.querySelector(".submit-button"),e=(r=this.linkPopup)==null?void 0:r.content.querySelector(".cancel-button");t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(i=this.linkPopup)==null||i.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function Cc(n,t){n.addCustom("link-editor",()=>new mE).editLink(t)}const gE=y("link-popup");function pE(n){return lt(n,"link")}function bc(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function CE(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&Re(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(xi(c))).getBoxProperties)==null?void 0:i.call(r,n,c);return a!=null&&a.boxCommands?(l=(s=a.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[]:[]}return n.isWritable()&&e&&H(n,t)&&pE(e)?[{id:"link-text",name:bc(e),element:b("span",["link-href-button"],null,bc(e))},{id:"edit-link",name:"Edit",icon:Ku},{id:"remove-link",name:"Remove link",icon:hw}]:Gm(n,t,"hovering-toolbar")}function bE(n,t,e){var c;const o=Br(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=bc(e);Cc(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,u)=>{try{const f=n.getBlockText(t),m=Dd(f,o.start,o.end-o.start),C=Ir(m,o.start,a,{link:u});n.setBlockText(t,C),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){gE.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function vE(n,t,e){const o=Br(t,e),r=n.getBlockText(t),i=bc(e),s=xr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function kE(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&Re(e)){const u=e,f=(l=(s=n.editorBoxes.getBoxClass(xi(u))).getBoxProperties)==null?void 0:l.call(s,n,u);if(f!=null&&f.boxCommands){f.boxCommands["hovering-toolbar"].executeCommand(n,t,u,o);return}return}const a=pc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?bE(n,t,e):o.id==="remove-link"&&vE(n,t,e);return}const r=Wm(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}const yE=[Fu,zu,Uu,Vu,qu,Wu,Gu,Zu];class wE{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){return 6}getAvailableCommands(t,e,o){if(H(t,e)){const r=G(e),i=it(e),s=Ge(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:S.t("commands.heading",{name:`${f+1}`}),icon:yE[f],states:c===f+1?["checked"]:[],value:`${f+1}`});return[{id:"turn-into",name:"",blockId:r,blockType:i,blockKind:s,element:f=>{var C;const m=b("span",["toolbar-item-name-container"],null);for(const v of f.children)if((C=v.states)!=null&&C.includes("checked"))return m.innerHTML=v.icon||nc,m;return m.innerHTML=nc,m},groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:S.t("commands.text"),icon:nc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(H(t,e)&&(r.id.startsWith("heading-")||r.id==="text")){const i=r.value?Number(r.value):null;return this.applyHeadingStyle(t,e,i),!0}return!1}}const vc=y("list-block");function at(n){return it(n)==="list"}function Ht(n){d(vc,at(n),"not a list block")}function je(n){Ht(n);const t=n.getAttribute("data-list-type");return d(vc,t,"no list type"),t}function kc(n){return at(n)&&je(n)==="text-only"}function Se(n){var t,e;return Ht(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function Te(n){var t,e;return Ht(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Qo(n){Ht(n);const t=n.getAttribute("data-list-group-id");return d(vc,t,"no group id"),t}function mo(n){var i,s,l,c,a;Ht(n);const t=(i=n.getAttribute("data-list-type"))!=null?i:"ordered",e=(l=Number.parseInt((s=n.getAttribute("data-list-start"))!=null?s:"1",10))!=null?l:1,o=(a=Number.parseInt((c=n.getAttribute("data-list-level"))!=null?c:"1",10))!=null?a:1,r=n.getAttribute("data-list-group-id");return d(vc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function yc(n){switch(n){case"ordered":return{ordered:!0,checkbox:null,textOnly:null};case"unordered":return{ordered:!1,checkbox:null,textOnly:null};case"checked":return{checkbox:"checked",ordered:!1,textOnly:null};case"unchecked":return{checkbox:"unchecked",ordered:!1,textOnly:null};case"text-only":return{checkbox:null,ordered:!1,textOnly:!0};default:return{checkbox:null,ordered:!0,textOnly:!1}}}function Wn(n){Ht(n);const{level:t,groupId:e,type:o}=mo(n);let r=gt(n);for(;r;){if(!at(r))return null;const{level:i,groupId:s,type:l}=mo(r);if(i<t)return null;if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;r=gt(r)}return null}function Ko(n){Ht(n);const{level:t,groupId:e,type:o}=mo(n);let r=ht(n);for(;r;){if(at(r)){const{level:i,groupId:s,type:l}=mo(r);if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;if(i<t)return null}r=ht(r)}return null}function i5(n){Ht(n);const t=[];let e=Wn(n);for(;e;)t.unshift(e),e=Wn(e);return t}function wc(n){Ht(n);const t=[];let e=Ko(n);for(;e;)t.push(e),e=Ko(e);return t}function us(n){Ht(n);let t=Wn(n);for(;t;){const e=Wn(t);if(!e)return t;t=e}return n}function BE(n){Ht(n);let t=Ko(n);for(;t;){const e=Ko(t);if(!e)return t;t=e}return null}function EE(n,t){const e=i5(n),o=wc(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function Bc(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:N();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(o==null?void 0:o.resetGroupId)){const c={...l,start:e};o!=null&&o.resetGroupId&&(c.groupId=r),n.updateBlockData(s,c)}l.textOnly||(e+=1)})}function xh(n,t,e,o){const r=EE(t,{withSelf:!0});r.length!==0&&Bc(n,r,e,o)}function IE(n){const t={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};let e="",o=n;return Object.entries(t).forEach(([r,i])=>{for(;o>=i;)e+=r,o-=i}),e.toLowerCase()}const xE="abcdefghijklmnopqrstuvwxyz";function s5(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=xE[t];return e?s5(e)+o:o}function SE(n){return`${n}`}const l5=[SE,s5,IE];function TE(n,t){const e=l5[(n-1)%l5.length];return e(t)}function DE(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class Jo{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=us(e),i=Se(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||xh(this.editor,this.listBrother,this.listStart,this.options)}}function LE(n,t,e=1){if(!t)return null;let o=gt(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return at(o)?o:null}o=gt(o)}return null}function c5(n,t){const e=n.getAttribute("data-style-heading"),o=LE(n,e);if(o)return o;const r=gt(n);if(r&&at(r)&&je(r)===t)return r;const i=ht(n);return i&&at(i)&&je(i)===t?i:null}function ME(n,t,e){var E,L,x;const o=(E=e.data)!=null?E:{},r=1,i=(L=o.listType)!=null?L:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(x=s.text)!=null?x:[];const c=n.selection.range.focus;if(!c.isSimple())return null;let u=wt(l);const f=c.offset;f<=ce(l)&&(l=fe(l,f).right,u=u.substring(0,f));let m=1;i==="ordered"&&(m=Number.parseInt(u,10)||1);let C=N();const v=c5(t,i);if(v){if(K(t)>K(v))m=Se(v)+1;else{const O=Se(v);O>1&&(m=O-1)}C=Qo(v)}const w={id:N(),type:"list",level:r,start:m,groupId:C,ordered:!1,text:l};return s.quoted&&(w.quoted=!0),s.heading&&(w.heading=s.heading),i==="ordered"?w.ordered=!0:(i==="checked"||i==="unchecked")&&(w.checkbox=i),{blockData:w,onConverted:(O,A)=>{new Jo(O,A).fix()}}}const RE=8,Mt=y("list-block");class Ec{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,kc(e))return;const o=us(e),r=Se(o);this.listStart=r,o===e?this.listBrother=Ko(o):this.listBrother=o}fix(){!this.listBrother||xh(this.editor,this.listBrother,this.listStart)}}function OE(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function Sh(n,t,e,o){if(Mt.debug("drag a block on a list block"),!H(n,t))return!1;d(Mt,at(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=mo(e),c=o==="after"?i+1:i,a=n.getBlockData(t),u={id:N(),type:"list",groupId:l,level:s,start:c,text:a.text,...yc(r)};OE(n,e,u);let f=K(e);const m=j(e);o==="after"&&(f+=1);let C=null;at(t)&&(C=new Ec(n,t));const v=n.insertBlock(U(m),f,u,Sl(u.id,0));return n.deleteBlock(t),new Jo(n,v).fix(),C==null||C.fix(),!0}function AE(n,t,e,o){if(Mt.debug("drag a list between text blocks"),o==="after"){const a=ht(e);if(a&&at(a))return Sh(n,t,a,"before")}if(o==="before"){const a=gt(e);if(a&&at(a))return Sh(n,t,a,"after")}const i={...n.getBlockData(t),groupId:N(),start:1,level:1};let s=K(e);const l=j(e);o==="after"&&(s+=1),n.insertBlock(U(l),s,i,Sl(i.id,0));const c=new Ec(n,t);return n.deleteBlock(t),c.fix(),!0}function _E(n,t,e,o,r){if(il(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);d(Mt,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=r;return!l&&c?(d(Mt,t===c,"block !== target block"),d(Mt,at(c),"target is not a list block"),Sh(n,s,c,o)):AE(n,s,c,o)}function a5(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function NE(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${TE(t,(o=n.start)!=null?o:1)}.`:DE(t)}const PE=`<?xml version="1.0" ?>
|
|
334
|
+
</svg>`;function Pw(n,t){var e;if(M(t,"menu-item"),!n.element){if(n.type==="section"){const o=b("div",["section-name"],null,n.name);t.appendChild(o)}else if(n.type!=="separator"){if(n.icon){const i=b("div",["menu-item-icon"],null);n.icon&&(i.innerHTML=n.icon),t.appendChild(i)}const o=b("div",["menu-item-name"],null,n.name);t.appendChild(o);const r=l0(n);if(r&&b("div",["item-shortcut","text"],t,r),n.children&&!n.element){const i=b("div",["menu-item-sub-indicator"],null);i.innerHTML=u0,t.appendChild(i)}if((e=n.states)!=null&&e.includes("checked")){const i=b("div",["menu-item-checked-icon"],null);i.innerHTML=Cw,t.appendChild(i)}}}}class Wo extends ec{constructor(t,e,o){super(t,e,{autoClose:!0,disablePageScroll:!0,...o})}manualShow(t,e){const o={theme:"menu",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"menu")}initItemElement(t,e){Pw(t,e)}}function $w(n,t,e){var o;return new Wo((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class oc extends ec{constructor(t,e,o){super(t,e,{itemElementTag:"button",tippyArrow:!1,...o})}getSubBarOptions(t){var r,i;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),a=s.getBoundingClientRect();return new DOMRect(a.left,c.top,a.width,c.height)};return{placement:(r=t.childrenPlacement)!=null?r:"top",getReferenceClientRect:e,offset:(i=t.childrenOffset)!=null?i:[0,4]}}manualShow(t,e){const o={theme:"toolbar",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),(!t.children||t.children.length===0)&&this.options.tooltipId&&(e.setAttribute(`data-editor-tooltip-${this.options.tooltipId}`,t.name),t.desc&&e.setAttribute(`data-editor-tooltip-desc-${this.options.tooltipId}`,t.desc));const o=e;if(!t.element)if(t.icon){const r=b("span",["toolbar-item-icon-container"],o);t.icon.trim().startsWith("<")?r.innerHTML=t.icon:r.innerText=t.icon}else{const r=b("span",["toolbar-item-name-container"],o);r.innerText=t.name}if(t.dropdown){e.setAttribute("data-dropdown","true");const r=b("span",["toolbar-item-dropdown-container"],o);r.innerHTML=Hu}t.states&&(t.states.indexOf("checked")!==-1&&M(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function jw(n,t,e){var o;return new oc((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const nF="";Pr.registerManualCommandBar("menu",$w),Pr.registerManualCommandBar("toolbar",jw);const y0=y("ui-base");class rc extends ec{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${N()}`,name:"",element:t}];super(r)}initCommandBarElement(t){M(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];d(y0,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return d(y0,e,"no item element"),e}}const oF="",w0=y("ui-base");class ic extends ec{constructor(e,o){super(ic.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){M(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];d(w0,e,"no dialog item");const o=e.element;return d(w0,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${N()}`,name:"",element:e}]}}const Hw=[-1,6,0,1,2,3,4,5],Fw=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],B0=y("color-palette");function E0(n,t,e,o){d(B0,n>0,"no color in palette");const r=t||1;d(B0,r>0,`invalid palette rows: ${r}`);const i=n/r,s=b("div",["palette-container",o],null);for(let l=0;l<r;l++){const c=b("div",["palette-container-row"],s);for(let a=0;a<i;a++){const u=e(l*i+a);c.appendChild(u)}}return s}function zw(n){const t=b("button",["color-button"],null),e=Hw[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=d0,t}function Uw(n){const t=b("button",["background-color-button"],null),e=Fw[n];return t.setAttribute("data-color-index",`${e}`),t}function Vw(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=S.t("colorPalette.reset"),n}function qw(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,S.t("colorPalette.colorDesc")),t.appendChild(E0(8,1,zw,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,S.t("colorPalette.backgroundDesc")),t.appendChild(E0(16,2,Uw,"background-color"))),n.clearColorButton!==!1&&t.appendChild(Vw()),t}function Ww(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&F(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&M(i,"selected")}const rF="",Gw={};class Zw extends Wt.TypedEmitter{constructor(e=Gw){super();h(this,"root");h(this,"handleClick",e=>{const o=e.target;if(!o||!(o instanceof Element))return;const r=o.closest("button");if(!r)return;if(lt(r,"clear-button")){this.setColor("backgroundColor",null),this.setColor("color",null),this.emit("onClick","clearColor",0);return}const i=r.getAttribute("data-color-index");if(!i)return;const s=Number.parseInt(i,10);Number.isNaN(s)||(lt(r,"color-button")?s===-1?(this.setColor("color",null),this.emit("onClick","clearColor",1)):(this.setColor("color",s),this.emit("onClick","color",s)):s===-1?(this.setColor("backgroundColor",null),this.emit("onClick","clearColor",2)):(this.setColor("backgroundColor",s),this.emit("onClick","backgroundColor",s)))});this.options=e,this.root=qw(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){Ww(this.root,e,o)}}class I0{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new Zw(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function Yw(){const n=b("button",["color-button"],null);return n.innerHTML=d0,n}function Ju(n,t){const[e,o]=t;e===null?n.removeAttribute("data-color"):n.setAttribute("data-color",`${e}`),o===null?n.removeAttribute("data-background-color"):n.setAttribute("data-background-color",`${o}`)}class Qw extends Wt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name","Text color");h(this,"dropdown",!0);h(this,"manualShowChildren",!0);h(this,"children",[]);h(this,"element");h(this,"colorPaletteItem");h(this,"latestColors",[null,null]);h(this,"handlePaletteClick",(e,o)=>{this.emit("onClick",e,o),e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=o:this.latestColors[1]=o:this.latestColors=[null,null],Ju(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new I0("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=Yw()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Ju(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Ju(this.element,this.latestColors)}}const iF="";function Xu(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&M(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&M(o,"required");const r=b("div",["editor-input-container"],e),i=b("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=b("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),F(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{M(e,"error"),s.innerText=l}}}function Kw(n){const t=document.getSelection();if(!t)return!0;const e=t.focusNode;if(!e)return!0;const o=t.focusOffset,r=e.childNodes[o];if(!r)return!0;if(r instanceof HTMLElement){const i=r.tagName.toLowerCase();if(r===n.input.inputElement)return!0;if(i==="input"||i==="textarea")return!1}return!0}const Jw=y("ui-base");class Xw{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{Kw(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new Wo([],void 0,{id:e.id}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose)}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(o=>o.type!=="section"&&o.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e,o){var a,u;if(((u=(a=this.options).onShow)==null?void 0:u.call(a,this,t,e,o))===!1)return;this.options.showLoading&&this.showLoading();const r=this.editor.getBlockByIndex(t,e);if(!vt(this.editor.rootContainer,r)||Z(this.editor,r)<o)return;const i=Oo(this.editor,r,Lt(this.editor,r,o));if(i.length===0)return;const s=i[0],l=_o(this.editor,r,"editor-auto-suggest-menu",s);this.menu.manualShow(l),this.options.placeholder&&this.showPlaceholder();const c=await this.options.queryItems(this,"");this.highlightText(""),this.setItems(c)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){if(this.options.noResultMessage){const e={name:"",id:"placeholder",states:["disabled"]};typeof this.options.noResultMessage=="string"?e.name=this.options.noResultMessage:(this.options.noResultMessage instanceof HTMLElement||typeof this.options.noResultMessage=="function")&&(e.element=this.options.noResultMessage),this.setItems([e])}else this.setItems([{id:"placeholder",name:S.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close()}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close(),this.menu.removeAllListeners(),this.menu.destroy()}async handleSearchText(t){this.currentText=t;const e="auto-suggest";try{await Ue.lock(e),this.showLoading();const o=this.currentText,r=await this.options.queryItems(this,o);if(this.currentText===o&&(this.currentText=""),r.length===0){this.showNoResultMessage(t);return}this.setItems(r),this.options.highlight&&this.highlightText(o)}finally{Ue.release(e)}}highlightText(t){Jw.debug(`highlight menu text: ${t}`);const e=this.menu.content,o=(i,s)=>{if(!s)return i;let l="";const c=s.length,a=s.toLocaleLowerCase();let u=0;for(u=0;u<=i.length-c;u){const f=i.substring(u,u+c);f.toLocaleLowerCase()===a?(l+=`<span class="highlight">${f}</span>`,u+=c):(l+=i.charAt(u),u++)}return u<i.length&&(l+=i.substring(u)),l},r=i=>{if(lt(i,"text")){const s=i.textContent;if(!s)return;const l=o(s,t);i.innerHTML=l;return}Array.from(i.children).forEach(r)};r(e)}}const th=y("auto-suggest-menu");class eh{constructor(t,e){h(this,"menu");h(this,"anchor",null);h(this,"handleSelectionChanged",t=>{var o,r;if(!((o=this.menu)!=null&&o.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((r=this.anchor)==null?void 0:r.blockId)&&e.offset>=this.anchor.offset){const i=t.getBlockById(e.blockId);if(wt(fe(we(t,i),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});h(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=wt(Ml(t,i,r));if(d(th,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,c=r-l;return t.selection.selectBlock(i,l),c&&(t.deleteTextFromBlock(i,l,c),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});h(this,"onShow",(t,e,o,r)=>{var i;if((i=this.options)!=null&&i.onShow)return this.options.onShow(this,e,o,r)});h(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});h(this,"queryItems",(t,e)=>this.options.queryItems(this,e));h(this,"renderMenuItem",(t,e)=>{var r,i;return(i=(r=this.options).renderMenuItem)==null?void 0:i.call(r,this,e)});this.editor=t,this.options=e,this.menu=new Xw(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,noResultMessage:e.noResultMessage,highlight:e.highlight,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var o;return!((o=this.menu)!=null&&o.isVisible)||Ga(e.key)?!1:tm(e)&&!To(e)?(setTimeout(()=>{this.resetItems()}),!1):Za(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:G(t),offset:e,leftText:o,trigger:r};const i=U(j(t)),s=K(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var u;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l,offset:c}=s,a=t.getBlockByIndex(e,o);if(G(a)!==l)return!1;if((u=this.menu)!=null&&u.isVisible)this.resetItems();else if(this.options.trigger.indexOf(i)!==-1){if(r>0&&this.options.needSpaceBeforeTrigger&&t.getBlockString(a)[r-1]!==" ")return!1;const f=wt(Ml(t,a,c));this.popup(a,c,f,i)}return!1}handleUpdateCompositionText(t,e,o,r,i){var a;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,o);return G(c)!==l||(a=this.menu)!=null&&a.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=wt(Ml(t,i,r));if(d(th,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);th.debug(`search text: ${c}`),this.menu.handleSearchText(c)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}const yn=y("table-dom");function ho(n){return`${G(n)}_scroll`}function $t(n){const t=n.querySelector("div[data-type=table-content] >table");return d(yn,t instanceof HTMLTableElement,"invalid table"),t}function wn(n,t){const o=n.getCustom(ho(t)).contentElement.firstElementChild;d(yn,o instanceof HTMLElement,"invalid table content");let r=o.querySelector(":scope >div[data-type=table-tools]");return r||(r=b("div",[],o),r.setAttribute("data-type","table-tools")),d(yn,r,"no table tools"),r}function x0(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function os(n){const t=n.querySelector(":scope div[data-type=editor-container]");return d(yn,t,"no child container in cell"),t}function tB(n){const o=x0(n).map(r=>{const i=os(r),s=U(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Ci.default(o)}function jt(n){return it(n)==="table"}function nh(n){const t=j(n);if(Ct(t))return null;const e=z(t);return d(yn,e,"no parent block"),jt(e)?t:nh(e)}function Ee(n){if(jt(n))return n;const t=j(n);if(Ct(t))return null;const e=z(t);return d(yn,e,"no parent block"),jt(e)?e:Ee(e)}function eB(n,t){const e=n.querySelector("colgroup");d(yn,e,"no colgroup");const o=e.children[t];return d(yn,o,"no col"),d(yn,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function S0(n){try{return $t(n),!0}catch{return!1}}function nB(n){return At(n).querySelector(":scope > .block-helper")}function oB(n){const t=z(n.contentElement);d(yn,t,"no block");const e=nB(t);if(e){const o=Math.min(n.contentElement.offsetLeft,n.rootElement.scrollLeft),r=t.getBoundingClientRect().width;e.style.right=`${o+r}px`}}const Ie=y("doc-table-grid");class rB{constructor(t){h(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){d(Ie,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){d(Ie,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return d(Ie,e,"get cell, no cell"),e}getCellAllowEmpty(t){return d(Ie,t>=0&&t<this.cols(),`get cell, invalid col, ${t}`),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}forEach(t){this._cells.forEach(t)}}class oh{constructor(t){h(this,"_data");h(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new rB(this.colCount));this.fillGrid(),d(Ie,t.colsWidth,"no colsWidth"),d(Ie,this.colCount===t.colsWidth.length,"invalid col count")}get rowCount(){return this._data.rows}get colCount(){return this._data.cols}getNextEmptyCell(t,e){let o=t,r=e;for(;;){if(o+=1,o===this.colCount&&(o=0,r+=1),r>=this.rowCount)return null;if(this._rows[r].getCellAllowEmpty(o)===void 0)return{col:o,row:r}}}fillGrid(){const t=this._data.children;d(Ie,t,"no children");let e=0,o=0;t.forEach((r,i)=>{const s=this._data[`${r}_colSpan`]||1,l=this._data[`${r}_rowSpan`]||1;for(let a=0;a<l;a++)for(let u=0;u<s;u++)this._rows[o+a].setCell(e+u,{col:e,row:o,containerId:r,virtual:u!==0||a!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,o);c?(e=c.col,o=c.row):d(Ie,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{d(Ie,i,"no cell"),d(Ie,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];d(Ie,r,`get cell, no row: ${o}`);const i=r.getCell(e);return d(Ie,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return d(Ie,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const sc=y("table-data");function iB(n){const t=n.firstElementChild;return d(sc,t,"no child element for cell"),d(sc,mn(t),"cell first child is not a container"),d(sc,We(t),"cell first child is not a container"),t}function sB(n){const t=z(n);d(sc,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=iB(c),u=U(a);e.push(u),(c.colSpan>1||c.rowSpan>1)&&(o[`${u}_colSpan`]=c.colSpan,o[`${u}_rowSpan`]=c.rowSpan)})});const r=n.rows.length,i=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,c)=>l+c,0);return{id:G(t),type:it(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function Go(n){return new oh(n)}function lB(n){return Go(sB(n))}const qt=y("table-grid"),cB=60;class aB{constructor(t,e){h(this,"containerId");h(this,"row");h(this,"col");h(this,"colSpan");h(this,"rowSpan");h(this,"virtual");h(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return d(qt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);d(qt,t.length===1,"containers !== 1"),d(qt,mn(t[0]),"not a container");const e=t[0];return d(qt,We(e),"not a child container"),e}}class dB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new aB(t,o))})}get cells(){return this._cells}getCell(t){return d(qt,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const of=class{constructor(t){h(this,"_rows",[]);this.table=t,lB(t).forEach(r=>{this._rows.push(new dB(t,r))});const o=this.colCount;this._rows.forEach(r=>{d(qt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(d(qt,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return d(qt,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){d(qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,o=[];for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});o.push(i)}return o}toRealCells(t){const e=[];return t.forEach(o=>{const r=this.getRealCell(o);e.findIndex(i=>i.containerId===r.containerId)===-1&&e.push(r)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){d(qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let o=0;o<e;o++){const r=this.getCell({row:o,col:t});if(r.virtual||r.colSpan>1||r.rowSpan>1)return r}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const o=this.getCellById(e.containerId);return d(qt,!o.virtual,"found a virtual cell"),o}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.col,o),r=Math.max(i.col+i.colSpan-1,r)}),d(qt,o<=r,"min > max"),d(qt,o>=0,"min < 0"),d(qt,r<this.colCount,"max >= colCount"),[o,r]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.row,o),r=Math.max(i.row+i.rowSpan-1,r)}),d(qt,o<=r,"min > max"),d(qt,o>=0,"min < 0"),d(qt,r<this.rowCount,"max >= rowCount"),[o,r]}getSpannedRange(t,e){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),i=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let C=o;C<=r;C++)for(let v=i;v<=s;v++)l.push(this.getCell({row:C,col:v}));const c=this.toRealCells(l);let a=1e4,u=1e4,f=-1,m=-1;return c.forEach(C=>{u=Math.min(C.col,u),a=Math.min(C.row,a),m=Math.max(C.col+C.colSpan-1,m),f=Math.max(C.row+C.rowSpan-1,f)}),[{row:a,col:u},{row:f,col:m}]}getAllCells(){return this.getCells({col:0,row:0},{col:this.colCount-1,row:this.rowCount-1})}sub(t,e){const o=[];for(let r=t.row;r<=e.row;r++){const i=[];for(let s=t.col;s<=e.col;s++){const l=this.getCell({row:r,col:s});i.push(l)}o.push(i)}return o}getAllContainers(){return this.getAllCells().map(e=>e.container)}getCells(t,e){const o=[],r=this.getSpannedRange(t,e),i=r[0],s=r[1],l=Math.min(i.row,s.row),c=Math.max(i.row,s.row),a=Math.min(i.col,s.col),u=Math.max(i.col,s.col);for(let f=l;f<=c;f++)for(let m=a;m<=u;m++){const C=this.getCell({row:f,col:m});C.virtual||o.push(C)}return o}map(t){const e=[];for(let o=0;o<this.rowCount;o++){const r=[];for(let i=0;i<this.colCount;i++){const s=this.getCell({row:o,col:i});r.push(t(s))}e.push(r)}return e}getBottomCell(t){const e=this.rowCount;let o=t,r=t.row;for(;o.containerId===t.containerId;){if(r+=1,r>=e)return null;o=this.getCell({row:r,col:t.col})}return this.getRealCell(o)}getTopCell(t){let e=t,o=t.row;for(;e.containerId===t.containerId;){if(o-=1,o<0)return null;e=this.getCell({row:o,col:t.col})}return this.getRealCell(e)}get cells(){let t=[];return this._rows.forEach(e=>{t=t.concat(e.cells)}),t}getVirtualCellContainersGrid(){return this.map(t=>t.containerId)}static virtualCellContainersGridToChildren(t){const e=t,o=[];return e.forEach(r=>{r.forEach(i=>{o.indexOf(i)===-1&&o.push(i)})}),o}getCellById(t){const o=this.cells.find(r=>r.containerId===t);return d(qt,o,"cell not found"),o}getCellByCellElement(t){const e=os(t);return this.getCellByContainerId(U(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=tB(t),o=this.caches.getSync(e,()=>(qt.debug("create table grid"),new of(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable($t(t))}};let et=of;h(et,"caches",new Of(cB));function lc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const uB=y("table-selection-range");function sn(n,t,e){var x,O,A,P;const o=et.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),c=r.custom,a=i.custom,u=(x=c==null?void 0:c.rowIndex)!=null?x:s.row,f=(O=c==null?void 0:c.colIndex)!=null?O:s.col,m=(A=a==null?void 0:a.rowIndex)!=null?A:l.row+l.rowSpan-1,C=(P=a==null?void 0:a.colIndex)!=null?P:l.col+l.colSpan-1,v=Math.min(u,m),w=Math.max(u,m),E=Math.min(f,C),L=Math.max(f,C);return{fromRow:v,toRow:w,fromCol:E,toCol:L}}function rh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===G(t)){const i=et.fromBlock(t),{start:s,end:l}=r;d(uB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:u,toRow:f}=sn(t,s,l);if(u===0&&f===i.rowCount-1)for(let m=c;m<=a;m++)o.add(m);if(c===0&&a===i.colCount-1)for(let m=u;m<=f;m++)e.add(m)}return{selectedRows:e,selectedColumns:o}}const $r=y("delete-columns");function T0(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromRow:s,toRow:l}=sn(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.rowCount-1}function ih(n){var O;const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!T0(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=sn(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.colCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(A=>A.containerId);for(let A=0;A<l.length;A++){const P=l[A];for(let V=o;V<=r;V++){const nt=P[V];s.add(nt)}P.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(A=>!c.has(A))),u=r-o+1,f=new Map,m=new Map;s.forEach(A=>{if(a.has(A))return;const P=i.getCellByContainerId(A);if(d($r,P.colSpan>1,"invalid effected cell, colSpan === 1"),P.col<o){d($r,c.has(A),"invalid effected cell, not exists");let Et=P.col+P.colSpan-1;Et>r&&(Et=r);const re=Et-o+1,Xn=P.colSpan-re;f.set(A,Xn);return}d($r,P.col<=r,"invalid effected cell, col > endCol");const V=P.col,nt=P.col+P.colSpan-1,ot=P.col-o,ut=nt-V+1-u+ot;d($r,ut>0,"invalid effected cell, newSpanned <= 0");const dt=Cn(t.doc);m.set(A,{newContainerId:dt,colSpan:ut})});for(let A=0;A<l.length;A++){const P=l[A];for(let V=o;V<P.length;V++){const nt=P[V],ot=m.get(nt);ot&&(P[V]=ot.newContainerId)}}const C=Y.default(t.getBlockData(e));C.colsWidth.splice(o,r-o+1),a.forEach(A=>{lc(C,A)}),f.forEach((A,P)=>{d($r,A>=1,"invalid modified colSpan, colSpan < 1"),A===1?delete C[`${P}_colSpan`]:C[`${P}_colSpan`]=A}),m.forEach((A,P)=>{lc(C,P);const{newContainerId:V,colSpan:nt}=A;d($r,nt>=1,"invalid newContainerData, colSpan < 1"),nt>1&&(C[`${V}_colSpan`]=nt);const ot=i.getCellByContainerId(P).rowSpan;ot>1&&(C[`${V}_rowSpan`]=ot)});const w=(O=l[0][o])!=null?O:l[0][o-1],E=t.getChildContainerData(w)[0],L=et.virtualCellContainersGridToChildren(l),x={...C,cols:C.cols-u,children:L};Go(x),t.updateBlockData(e,x,Lt(t,E.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))}const jr=y("delete-rows");function D0(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromCol:s,toCol:l}=sn(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.colCount-1}function sh(n){const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!D0(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=sn(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(x=>x.containerId);for(let x=r;x>=o;x--)l[x].forEach(A=>s.add(A)),l.splice(x,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(x=>!c.has(x))),u=r-o+1,f=new Map,m=new Map;s.forEach(x=>{if(a.has(x))return;const O=i.getCellByContainerId(x);if(d(jr,O.rowSpan>1,"invalid effected cell, rowSpan === 1"),O.row<o){d(jr,c.has(x),"invalid effected cell, not exists");let ut=O.row+O.rowSpan-1;ut>r&&(ut=r);const dt=ut-o+1,Et=O.rowSpan-dt;f.set(x,Et);return}d(jr,O.row<=r,"invalid effected cell, col > endCol");const A=O.row,P=O.row+O.rowSpan-1,V=O.row-o,nt=P-A+1-u+V;d(jr,nt>0,"invalid effected cell, newSpanned <= 0");const ot=Cn(t.doc);m.set(x,{newContainerId:ot,rowSpan:nt})});for(let x=o;x<l.length;x++){const O=l[x];for(let A=0;A<O.length;A++){const P=O[A],V=m.get(P);V&&(O[A]=V.newContainerId)}}const C=Y.default(t.getBlockData(e));a.forEach(x=>{lc(C,x)}),f.forEach((x,O)=>{d(jr,x>=1,"invalid modified rowSpan, rowSpan < 1"),x===1?delete C[`${O}_rowSpan`]:C[`${O}_rowSpan`]=x}),m.forEach((x,O)=>{lc(C,O);const{newContainerId:A,rowSpan:P}=x;d(jr,P>=1,"invalid newContainerData, rowSpan < 1"),P>1&&(C[`${A}_rowSpan`]=P);const V=i.getCellByContainerId(O).colSpan;V>1&&(C[`${A}_colSpan`]=V)});const v=l[o]?l[o][0]:l[o-1][0],w=t.getChildContainerData(v)[0],E=et.virtualCellContainersGridToChildren(l),L={...C,rows:C.rows-u,children:E};Go(L),t.updateBlockData(e,L,Lt(t,w.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))}const rs=y("table-range");function cc(n){d(rs,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;d(rs,!t.isSimple(),"invalid start pos type"),d(rs,!e.isSimple(),"invalid end pos type");const o=n.getEditor();d(rs,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);d(rs,it(r)==="table","invalid block type, not a table block");const i=$t(r),s=et.fromTable(i),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),a=Math.min(l.row,c.row),u=Math.max(l.row,c.row),f=Math.min(l.col,c.col),m=Math.max(l.col,c.col),C=s.getCell({row:a,col:f}),v=s.getCell({row:u,col:m});return{editor:o,block:r,table:i,startCell:C,endCell:v,startRow:a,startCol:f,endRow:u,endCol:m}}const lh=y("split-cell");function ch(n,t,e){const o=et.fromBlock(t),r=o.getRealCell(e);d(lh,!r.virtual,"should not split virtual cell"),d(lh,r.colSpan>1||r.rowSpan>1,"cell does not has span data");const i=o.getVirtualCellContainersGrid();for(let f=0;f<r.rowSpan;f++)for(let m=0;m<r.colSpan;m++){if(f===0&&m===0)continue;const C=f+r.row,v=m+r.col,w=Cn(n.doc);i[C][v]=w}const s=n.getBlockData(t),l=Y.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=et.virtualCellContainersGridToChildren(i);const a=n.getChildContainerData(r.containerId)[0];d(lh,a,"no child block");const u=Lt(n,a.id,0);Go(l),n.updateBlockData(t,l,u)}function hB(n,t,e){e.forEach(o=>{const r=et.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&ch(n,t,o)})}function L0(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=cc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function ah(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=cc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return hB(t,e,l),!0}const Hr=y("merge-cells");function M0(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=cc(e);return s.cell!==l.cell}function R0(n){const t=cc(n),e=t.endCell,o=e.row+e.rowSpan-1,r=e.col+e.colSpan-1,i=G(t.block),s=t.editor;ah(n);const l=s.getBlockById(i),c=$t(l),{startRow:a,startCol:u}=t,f=Y.default(s.getBlockData(l));d(Hr,f.children,"no table children");const m=et.fromTable(c),C=[];for(let ut=a;ut<=o;ut++)for(let dt=u;dt<=r;dt++){const Et=m.getCell({row:ut,col:dt});d(Hr,!Et.virtual,"cell is virtual"),C.push(Et)}d(Hr,C.length>0,"no selected cells");const v=C[0],w=C.slice(1),E=m.getCellByContainerId(v.containerId).container,L=[];w.forEach(ut=>{const dt=m.getCellByContainerId(ut.containerId).container,Et=U(dt);if(!ud(s,dt)){const re=Xd(s,Et);s.insertDocAt(E,Ve(E),re)}L.push(Et)});const x=U(E),O=r-u+1,A=o-a+1;f[`${x}_colSpan`]=O,f[`${x}_rowSpan`]=A,L.forEach(ut=>{d(Hr,f.children,"no table children");const dt=f.children.indexOf(ut);d(Hr,dt>0,"no deleted container"),f.children.splice(dt,1)});const P=f,nt=s.getChildContainerData(x)[0];d(Hr,nt,"no child block");const ot=Lt(s,nt.id,0);Go(P),s.updateBlockData(l,P,ot),s.deleteChildContainers(L)}const dh=10,fB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class uh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(it(e)!=="table")return[];const r={blockId:G(e),blockKind:Ge(t,e),blockType:it(e)},i=[];M0(t,e,o)&&i.push({id:"table/merge-cells",name:"merge cells",icon:ew,groupIndex:dh,...r}),L0(t,e,o)&&i.push({id:"table/split-cell",name:"split cell",icon:nw,groupIndex:dh,...r});const s=T0(t,e,o),l=D0(t,e,o);return s&&l&&i.push({id:"table/delete",name:"delete tables",icon:ow,groupIndex:dh,...r}),i}executeCommand(t,e,o,r,i,s){return it(e)!=="table"||!new Set(fB).has(r.id)?!1:r.id==="table/merge-cells"?(R0(o),!0):r.id==="table/split-cell"?(ah(o),!0):r.id==="table/delete-columns"?(ih(o),!0):r.id==="table/delete-rows"?(sh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var O0=(n=>(n.COL_TITLE_TABLE="col-title-table",n.COL_TITLE_ITEM="col-title-item",n.STRIPE_STYLE_TABLE="stripe-style-table",n.NO_BORDER="table-no-border",n))(O0||{});const hh=6,is=20;function mB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function gB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function pB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function CB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function bB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function vB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function kB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const fh=y("get-selected-containers");function mh(n,t,e,o){d(fh,e.blockId===o.blockId,"only allow select in single table block"),d(fh,G(t)===e.blockId,"only allow select in single table block");const r=et.fromBlock(t),i=r.getCellByContainerId(e.childContainerId),s=r.getCellByContainerId(o.childContainerId);if(e.custom===void 0||o.custom===void 0)return r.getCells(i,s).map(E=>r.getCellContainer(E));const{fromCol:l,toCol:c,fromRow:a,toRow:u}=sn(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:u,col:c}).forEach(v=>{v.forEach(w=>{const E=r.getCellByContainerId(w.containerId);E.col<l||E.row<a||E.col+E.colSpan-1>c||E.row+E.rowSpan-1>u||f.has(w.containerId)||(f.add(w.containerId),m.push(E.container))})}),m}function yB(n,t,e){d(fh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return mh(n,o,t,e)}const Zo=y("table-cell-dom");function wB(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");d(Zo,r,"no parent cell");const i=z(r);if(d(Zo,i,"no parent block"),i===t)return r;o=i}return d(Zo,!1,"filed to get cell by child block id"),null}function qn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return d(Zo,e.childContainerId,"block position must have childContainerId attribute"),e;const r=wB(n,t,e.blockId),i=U(os(r));return bt(t,i)}function gh(n,t){const e=n.selection.range,o=qn(n,t,e.start),r=qn(n,t,e.end);return sn(t,o,r)}function A0(n,t,e,o){d(Zo,jt(t),"invalid table block");const r=wn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");d(Zo,l,"no top border bar container"),l.querySelectorAll(".table-border-bar-cell.top").forEach(a=>{const u=parseInt(a.getAttribute("data-top-index")||"0",10);o.includes(u)?M(a,"danger"):F(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");d(Zo,l,"no left border bar container"),l.querySelectorAll(".table-border-bar-cell.left").forEach(a=>{const u=parseInt(a.getAttribute("data-left-index")||"0",10);e.includes(u)?M(a,"danger"):F(a,"danger")})};i(),s()}function Fr(n,t,e=!0,o){const i=et.fromBlock(t).map(u=>u),{fromCol:s,toCol:l,fromRow:c,toRow:a}=gh(n,t);for(let u=0;u<i.length;u++){const f=i[u];for(let m=0;m<f.length;m++){const C=f[m],v=o?m>=s&&m+C.colSpan-1<=l:u>=c&&u+C.rowSpan-1<=a;e&&v?C.virtual||M(C.cell,"danger"):C.virtual||F(C.cell,"danger")}}}function zr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){A0(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=gh(n,t);if(o)for(let u=s;u<=l;u++)i.add(u);else for(let u=c;u<=a;u++)r.add(u);A0(n,t,Array.from(r),Array.from(i))}function _0(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=gh(n,t),l=et.fromBlock(t);let c=null,a=null;return e?(c=l.getCell({col:o,row:0}),a=l.getCell({col:r,row:l.rowCount-1}),Vt(n,{anchor:bt(t,c.containerId,{colIndex:o,rowIndex:0}),focus:bt(t,a.containerId,{colIndex:r,rowIndex:l.rowCount-1})})):(c=l.getCell({col:0,row:i}),a=l.getCell({col:l.colCount-1,row:s}),Vt(n,{anchor:bt(t,c.containerId,{colIndex:0,rowIndex:i}),focus:bt(t,a.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function BB(n,t){const e=n.selection.range,o=qn(n,t,e.start),r=qn(n,t,e.end);return mh(n,t,o,r)}const N0=["style-bg-color-0","style-bg-color-1","style-bg-color-2","style-bg-color-3","style-bg-color-4","style-bg-color-5","style-bg-color-6","style-bg-color-7","style-bg-color-8","style-bg-color-9","style-bg-color-10","style-bg-color-11","style-bg-color-12","style-bg-color-13"];function P0(n){return`style-bg-color-${n}`}function ss(n){return`${n}_background`}function EB(n,t,e){const o=$t(n),s=(e!=null?e:et.fromTable(o)).getCell(t).cell;for(let l=0;l<N0.length;l++){const c=N0[l];if(lt(s,c))return c}}function $0(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Y.default(n.getBlockData(t))},s=qn(n,t,o.start),l=qn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[ss(c)]=void 0:i[ss(c)]=P0(e)}else{const c=et.fromBlock(t),a=sn(t,s,l),u=new Set;for(let f=a.fromRow;f<=a.toRow;f++)for(let m=a.fromCol;m<=a.toCol;m++){const C=c.getCell({row:f,col:m});!u.has(C.containerId)&&C.col>=a.fromCol&&C.row>=a.fromRow&&C.col+C.colSpan-1<=a.toCol&&C.row+C.rowSpan-1<=a.toRow&&(u.add(C.containerId),e===-1?i[ss(C.containerId)]=void 0:i[ss(C.containerId)]=P0(e))}}n.updateBlockData(t,i)}function IB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const j0=y("table-chart");function xB(n,t){const e=wn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function SB(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){xB(n,t);return}const r=[],i=et.fromBlock(t),s=["line","bar","pie","radar"];let l=i.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let w=1;w<i.colCount;w++)c.push(i.getCell({row:0,col:w}).container.innerText);for(let w=1;w<i.rowCount;w++){const E=i.getCell({row:w,col:0}),x=E.container.innerText,O=[];for(let re=1;re<i.colCount;re++){const Xn=i.getCell({row:w,col:re}).container.innerText,te=Number.parseFloat(Xn)||0;O.push(te)}let A;const P=EB(t,E,i);P?A=window.getComputedStyle(n.rootElement).getPropertyValue(`--${P}`).trim():A=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[V,nt,ot,ut]=A?_a.fromString(A).toRgbaArray():[];if(!V&&!nt&&!ot&&!ut){const re=(w-1)%n.options.colors.length;A=n.options.colors[re],[V,nt,ot,ut]=_a.fromString(A).toRgbaArray()}const dt=A,Et=_a.fromRgba([V,nt,ot,ut/3]).toHexString();r.push({label:x,data:O,borderColor:dt,backgroundColor:Et,borderWidth:2})}const a=wn(n,t);let u=null,f=a.querySelector(".editor-table-chart");f?u=f.chartObject:f=b("div",["editor-table-chart"],a);const m=f;d(j0,m,"no chart container");const C=n.getComponentOptions("table"),v=(C==null?void 0:C.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await xo(v,"editor-chartjs"),u&&l!==u.config.type&&(u.destroy(),u=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(L=>{L.remove()}));const w=Pa.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(u)Pa.default(u.config,w),u.update();else{const L=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");u=new window.Chart(L,w),f.chartObject=u}}catch(w){j0.error(`failed to resolve chart cdn: ${JSON.stringify(w)}`)}}async function H0(n,t){await Ue.lock("updateTableChart");try{await SB(n,t)}finally{Ue.release("updateTableChart")}}const F0=Qt.default(H0,1e3);let z0=null;function ph(n,t,e){if(z0!==t&&(F0.flush(),z0=t),e.updateNow){H0(n,t);return}F0(n,t)}function Ch(n,t){jt(t)&&ph(n,t,{updateNow:!1})}function TB(n,t){jt(t)&&ph(n,t,{updateNow:!0})}const $e={SCROLL:"container-scroll-tool",COMMON:"container-border-shadow",RIGHT:"container-right-border-shadow",LEFT:"container-left-border-shadow",LAYOUT_SIGN:"container-layout-border-shadow",ACTIVE:"active"},ac={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},fo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function dc(n,t){return n.containers.get(t)}function U0(n){return n.closest(`.${fo.SCROLL_CONTAINER}`)}function ln(n){return n.firstElementChild}function xe(n){return n.closest(`.${fo.CONTAINER}`)}function ls(n){const t=xe(n);let e=t.querySelector(`:scope >.${fo.TOOL}`);return e||(e=b("div",[fo.TOOL],t)),e}function DB(n){return xe(n).firstElementChild}function cs(n){const t=window.getComputedStyle(n);return{paddingBottom:parseFloat(t.paddingBottom),paddingTop:parseFloat(t.paddingTop),paddingLeft:parseFloat(t.paddingLeft),paddingRight:parseFloat(t.paddingRight)}}function bh(n,t){const e=xe(t),o=dc(n,e),r=(o==null?void 0:o.safeRightSpace)||0,i=(o==null?void 0:o.safeLeftSpace)||0,l=(o==null?void 0:o.locatingContainer).getBoundingClientRect(),c=e.getBoundingClientRect(),a=c.width;let u=Math.floor(c.left-l.left-i);u<0&&(u=0);let f=l.right;f-=r;let m=f-c.right;return m<0&&(m=0),u=Math.round(u),m=Math.round(m),{originWidth:a,maxLeft:u,maxRight:m}}function LB(n,t){const e=bh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${0-o}px`,t.style.paddingLeft=`${o}px`}function MB(n,t){const e=bh(n,t);t.style.marginRight=`${0-e.maxRight}px`}function RB(n){if(n!==document.documentElement&&n!==document.body)return n.getBoundingClientRect();const t=0,e=0,o=document.documentElement.clientWidth,r=document.documentElement.clientHeight;return new DOMRect(t,e,o,r)}const V0=y("scroll-bar-handle"),OB=2;function Ur(n){const t=ls(n);let e=t.querySelector(`.${ac.SCROLL_BAR}`);return e||(e=b("div",[ac.SCROLL_BAR],t)),d(V0,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function uc(n,t){const e=U0(t),o=Ur(e),{paddingLeft:r,paddingRight:i}=cs(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const s=bh(n,e),{originWidth:l,maxRight:c}=s;MB(n,e),LB(n,e);const a=e.scrollWidth-e.clientWidth;d(V0,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${l+c-r-i}px`,o.firstElementChild.style.width=`${l+c+a-r-i}px`}function AB(n,t){const e=ln(n),{paddingLeft:o}=cs(e);if(lt(t,"fixed")){const i=xe(n).getBoundingClientRect();t.style.left=`${i.left+o}px`}else t.style.left=`${o}px`}function Vr(n,t){const e=n.getParentScrollContainer(),o=RB(e),r=t.getBoundingClientRect(),i=Ur(t),s=i.getBoundingClientRect(),l=dc(n,xe(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=ln(t),{paddingTop:u,paddingBottom:f}=cs(a),m=document.documentElement.clientHeight-c,C=o.top+e.clientHeight-m,v=m+Math.min(0,C);if(t.scrollWidth>t.clientWidth&&r.top+u<v-s.height&&r.bottom>v-s.height+f){M(i,ac.FIXED);const E=C>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+OB+E}px`}else F(i,ac.FIXED),i.style.bottom=`${f-s.height}px`;AB(t,i)}class _B{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(xe(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;Vr(this.scrollCore,e);const o=ln(e);uc(this.scrollCore,o)});this.scrollCore=t,this.callback=e;const r={root:this.scrollCore.getParentScrollContainer(),rootMargin:"20px",threshold:0};this.intersectionObserver=new IntersectionObserver(this.handleIntersection,r)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.intersectionObserver.observe(t)}unbind(t){this.intersectionObserver.unobserve(t)}destroy(){this.intersectionObserver.disconnect()}}const Yo=y("container-scroll-shadow");function q0(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=cs(e);o.style.top=`${i.top-r.top+s}px`,o.style.bottom=`${r.bottom-i.bottom+l}px`}function W0(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function NB(n){const t=ls(n);d(Yo,t,"no container tools");let e=t.querySelector(`.${$e.LEFT}`);if(!e){const l=ln(n),c=[$e.COMMON,$e.LEFT];e=b("div",c,t),d(Yo,e instanceof HTMLDivElement,"invalid child for container tools"),q0(e,n,l)}d(Yo,e instanceof HTMLElement,"invalid child for container tools");const r=xe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${i.left-r.left}px`;const s=n.scrollLeft;d(Yo,e instanceof HTMLDivElement,"invalid child for container tools"),W0(e,s),M(e,$e.ACTIVE)}function PB(n){const t=ls(n);let e=t.querySelector(`.${$e.RIGHT}`);if(!e){const l=ln(n),c=[$e.COMMON,$e.RIGHT];e=b("div",c,t),d(Yo,e instanceof HTMLDivElement,"no div, create shadow failed"),q0(e,n,l)}d(Yo,e instanceof HTMLElement,"");const r=xe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${r.right-i.right}px`;const s=n.scrollWidth-n.scrollLeft-n.clientWidth;d(Yo,e instanceof HTMLDivElement,"no shadow element"),W0(e,s),M(e,$e.ACTIVE)}function $B(n){const e=ls(n).querySelector(`.${$e.LEFT}`);e&&F(e,$e.ACTIVE)}function jB(n){const e=ls(n).querySelector(`.${$e.RIGHT}`);e&&F(e,$e.ACTIVE)}function as(n){const t=Math.round(n.scrollLeft),e=ln(n),{paddingLeft:o,paddingRight:r}=cs(e);n.scrollWidth-o<=n.clientWidth-r||n.scrollWidth-o<=t+n.clientWidth-r?jB(n):PB(n),e&&n.scrollLeft>=e.offsetLeft+o?NB(n):$B(n)}class HB{constructor(t){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=ln(e);as(e),uc(this.scrollCore,o),Vr(this.scrollCore,e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(xe(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleContentResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}const G0=y("container-scroll-observer");class FB{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;d(G0,e instanceof Element,"invalid target for scroll event");const o=Ur(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),as(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;d(G0,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=DB(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),as(i),this.callback(i)});h(this,"handlePrevent",t=>{t.stopPropagation()});h(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});h(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});h(this,"bindContentScroll",Qt.default(this.bindContentScrollCore,300));h(this,"bind",Qt.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=Ur(t);o||(t.scrollLeft=e),o&&r.scrollLeft!==e&&(r.scrollLeft=e)}bindCore(t){this.unbind(t),t.addEventListener("scroll",this.handleScroll),t.addEventListener("mousedown",this.handlePrevent)}unbind(t){t.removeEventListener("scroll",this.handleScroll),t.removeEventListener("mousedown",this.handlePrevent)}}class zB{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Vr(this.scrollCore,t)})});h(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});h(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const UB=y("scroll-wrap-resize-observer");class VB{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(xe(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;d(UB,e instanceof HTMLElement,"invalid target for observer entry");const o=U0(e);uc(this.scrollCore,e),as(o),Vr(this.scrollCore,o)});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleScrollWrapResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}class qB{constructor(t){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=ln(e);as(e),uc(this.scrollCore,o),Vr(this.scrollCore,e)})});h(this,"handleResize",t=>{t.forEach(e=>{const o=this.scrollContainersMap.get(e.target);o!=null&&o.length&&this.handleResizeEntry(o)})});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleResize)}bind(t){var r,i;const e=xe(t),o=(r=dc(this.scrollCore,e))==null?void 0:r.locatingContainer;this.scrollContainersMap.has(o)?(i=this.scrollContainersMap.get(o))==null||i.push(t):(this.scrollContainersMap.set(o,[t]),this.resizeObserver.observe(o))}unbind(t){var i,s;const e=xe(t),o=(i=dc(this.scrollCore,e))==null?void 0:i.locatingContainer;if(!o)return;const r=this.scrollContainersMap.get(o);this.scrollContainersMap.set(o,(r==null?void 0:r.filter(l=>l!==t))||[]),(s=this.scrollContainersMap.get(o))!=null&&s.length||(this.resizeObserver.unobserve(o),this.scrollContainersMap.delete(o))}destroy(){this.scrollContainersMap.clear(),this.resizeObserver.disconnect()}}const sF="";class WB extends Wt.TypedEmitter{constructor(e){super();h(this,"containerIntersectionObserver",null);h(this,"containerResizeObserver",null);h(this,"containerScrollObserver",null);h(this,"parentContainerScrollObserver",null);h(this,"scrollWrapResizeObserve",null);h(this,"locatingContainerResizeObserver",null);h(this,"isWindowEventBind",!1);h(this,"containers",new Map);h(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=ln(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});h(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{Vr(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new HB(this)),this.containerScrollObserver||(this.containerScrollObserver=new FB(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new zB(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new VB(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new qB(this)),this.isWindowEventBind||(window.addEventListener("resize",this.handleWindowEffect),this.getParentScrollContainer()!==document.documentElement&&window.addEventListener("scroll",this.handleWindowEffect))}getParentScrollContainer(){return this.parentContainer}getScrollContainerInViewable(){var e;return(e=this.parentContainerScrollObserver)==null?void 0:e.scrollContainers}unbindCore(e,o){var i,s,l,c,a,u;const r=Ur(e);(i=this.containerScrollObserver)==null||i.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(r),(l=this.scrollWrapResizeObserve)==null||l.unbind(o),(c=this.containerResizeObserver)==null||c.unbind(e),(a=this.parentContainerScrollObserver)==null||a.unbindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.unbind(e)}bindCore(e,o){var i,s,l,c,a,u;if(this.unbindCore(e,o),!e.closest("body"))return;const r=Ur(e);(i=this.containerScrollObserver)==null||i.bindContentScrollCore(e),(s=this.containerScrollObserver)==null||s.bindCore(r),(l=this.scrollWrapResizeObserve)==null||l.bind(o),(c=this.containerResizeObserver)==null||c.bind(e),(a=this.parentContainerScrollObserver)==null||a.bindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new _B(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=ln(o);this.unbindCore(o,r),this.containers.delete(e),(i=this.containerIntersectionObserver)==null||i.unbind(o),this.containers.size||this.destroy()}destroy(){var e,o,r,i,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(o=this.containerIntersectionObserver)==null||o.destroy(),(r=this.containerResizeObserver)==null||r.destroy(),(i=this.scrollWrapResizeObserve)==null||i.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const Z0=y("scroll-container"),hc=new Map;class GB extends Wt.TypedEmitter{constructor(){super(...arguments);h(this,"scrollListener");h(this,"options");h(this,"scrollContainerElement");h(this,"init",e=>{this.options=e;const o=b("div",[fo.CONTAINER],e.parentElement);St.isMac&&M(o,fo.MAC);const r=b("div",[fo.SCROLL_CONTAINER],o),i=b("div",[fo.SCROLL_AREA],r);i.style.paddingLeft=e.paddingLeft?`${e.paddingLeft}px`:"",i.style.paddingTop=e.paddingTop?`${e.paddingTop}px`:"",i.style.paddingBottom=e.paddingBottom?`${e.paddingBottom}px`:"",i.style.paddingRight=e.paddingRight?`${e.paddingRight}px`:"",i.appendChild(e.childElement);const s=e.parentContainer;this.scrollListener=hc.get(s),this.scrollListener||(this.scrollListener=new WB(s),hc.set(s,this.scrollListener)),this.scrollListener.unbind(o),this.scrollListener.bind(o,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollContainerElement=r});h(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return d(Z0,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),ln(this.scrollContainerElement)}get scrollOptions(){return d(Z0,this.options,"options cannot be undefined"),{...this.options}}handleBaseListenerDestroy(e){e.destroy()}destroy(){var o;(o=this.scrollListener)==null||o.off("scroll",this.handleContainerScroll);const e=xe(this.contentElement);e&&hc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),hc.delete(i))})}}function ZB(){return new GB}const fc=100,YB=40,vh=y("column-width");function QB(n,t,e){eB(n,t).style.width=`${e}px`}function KB(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const o=et.fromTable(n),r=Array(o.colCount).fill(-1),i=n.getBoundingClientRect().left;o.toRealCells(o.cells).forEach(c=>{const a=c.col+c.colSpan-1;r[a]===-1&&(r[a]=c.cell.getBoundingClientRect().right-i)}),vh.debug(`cellRightOffsets1: ${r.join()}`);for(let c=0;c<r.length;c++){const a=r[c];if(a===-1||c===0)continue;let u=c-1;for(;r[u]===-1&&(u--,u!==-1););const f=u===-1?0:r[u],C=(a-f)/(c-u);for(let v=u+1;v<c;v++)r[v]=f+C*(v-u)}vh.debug(`cellRightOffsets2: ${r.join()}`);const s=[];let l=0;for(let c=0;c<r.length;c++){const a=r[c];s.push(a-l),l=a}return vh.debug(`widths: ${s.join()}`),s}function ds(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const JB=y("table-resize-gripper"),Y0=7,kh=(Y0-1)/2,XB=3;function tE(n,t,e){const{rows:o}=n;for(let r=0;r<o.length;r++){const i=o[r],s=Array.from(i.cells);for(let l=0;l<s.length;l++){const c=s[l],a=c.getBoundingClientRect(),u=Math.round(a.right);if(Math.abs(t-u)<=kh&&a.top<=e&&e<=a.bottom)return c}}return null}function eE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function yh(n,t){return wn(n,t).querySelector(".table-resize-gripper")}function Q0(n,t){const e=yh(n,t);d(JB,!e,"resize gripper has already exists");const o=wn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function K0(n,t,e){let o=yh(n,t);o||(o=Q0(n,t));const i=$t(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(ho(t)).contentElement.getBoundingClientRect(),u=s.right-a.left;o.style.left=`${u-kh-hh-is}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${Y0}px`}function wh(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function nE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function oE(n,t,e,o){const r=t,i=et.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=ds(e);let a=o;const u=(m,C)=>{const v=C+1,w=m.col+m.colSpan;return c.slice(v,w).reduce((L,x)=>L+x,0)},f=new Set;for(let m=0;m<i.rowCount;m++){const C=i.getCell({row:m,col:l});if(f.has(C.cell))continue;f.add(C.cell);const v=C.cell,w=v.getBoundingClientRect();let E=o-w.left+kh-XB;const L=os(v),x=dd(n,L)||YB*C.colSpan,O=u(C,l),A=x-O;E<A&&(E=A);const P=w.left+E;a=Math.max(a,P)}return a}const rE=y("table-resize-drag-drop");class iE{constructor(t,e,o,r){h(this,"cursor","col-resize");this.editor=t,this.elem=e,this.data=o,this.onEnd=r}onDragStart(t,e,o){}onDragging(t,e,o,r,i){const{table:s,block:l,draggingRefCell:c}=t.data,u=oE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;d(rE,c,"no dragging cell");const m=et.fromTable(s).getCellByCellElement(c),C=m.col+m.colSpan-1,w=ds(s).slice(0,C).reduce((L,x)=>L+x,0),E=u-w;QB(s,C,E),K0(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=ds(t.data.table);nE(this.editor,t.data.block,s),wh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function sE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=z(e);return!o||!n.contains(o)||!jt(o)?null:o}y("table-resize");class lE{constructor(t){h(this,"draggingRefCell",null);h(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const o=e.target;if(!(o instanceof Element)||o.closest(".table-indicator"))return;const i=e,s=sE(t,i);if(!s||!S0(s)){wh(t);return}this.updateGripper(s,i.x,i.y)});this.editor=t,t.domEvents.addEventListener(document,"mousemove",this.handleMouseMove)}destroy(){this.editor.domEvents.removeEventListener(document,"mousemove",this.handleMouseMove)}updateGripper(t,e,o){const r=$t(t),i=tE(r,e,o);if(i){if(!yh(this.editor,t)){if(eE(this.editor))return;const l=Q0(this.editor,t),c={block:t,table:r,draggingRefCell:i};Va(new iE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}K0(this.editor,t,i)}else wh(this.editor)}}function J0(n){n.addCustom("table-mouse-event-handler",t=>new lE(t))}const X0=y("table-insert-column");function t5(n,t,e){const o=$t(t),r=et.fromTable(o),i=r.colCount;d(X0,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();for(let m=0;m<s.length;m++){const C=s[m],v=C[e-1],w=C[e];if(e===0||e===C.length||v!==w){const E=Cn(n.doc);C.splice(e,0,E)}else C.splice(e,0,v),l.add(v)}n.doc.endBatchUpdate();const c=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_colSpan`,v=c[C];d(X0,typeof v=="number"&&v>1,`no colSpan for containerId ${m}, ${v}`),c[C]=v+1});const a=c.colsWidth.concat();a.splice(e,0,fc);const u=et.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:u,colsWidth:a};Go(f),n.updateBlockData(t,f)}const mc=y("table-insert-row");function e5(n,t,e){const o=$t(t),r=et.fromTable(o),i=r.rowCount;d(mc,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();const c=[];for(let m=0;m<r.colCount;m++){const C=e>0&&s[e-1][m],v=e<r.rowCount&&s[e][m];if(d(mc,C||v,"no top and bottom cell"),e===0||e===r.rowCount||C!==v){const w=Cn(n.doc);c.push(w)}else d(mc,C,"no top cell"),c.push(C),l.add(C)}n.doc.endBatchUpdate(),s.splice(e,0,c);const a=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_rowSpan`,v=a[C];d(mc,typeof v=="number"&&v>1,`no rowSpan for containerId ${m}, ${v}`),a[C]=v+1});const u=et.virtualCellContainersGridToChildren(s),f={...a,rows:a.rows+1,children:u};Go(f),n.updateBlockData(t,f)}const Bh=y("paste-table-in-table-block");function cE(n,t,e,o){let r=et.fromBlock(e);const i=t.blocks.root[0];d(Bh,i,"no table data"),d(Bh,i.type==="table",`table data type is not table, but ${i.type}`);const s=i,l=r.getCellByCellElement(o),c=s.cols,a=s.rows,u=l.col,f=l.row,m=u+c,C=f+a,v=[];for(let w=u;w<m&&w<r.colCount;w++)for(let E=f;E<C&&E<r.rowCount;E++){const L=r.getCell({col:w,row:E});L.virtual?L.virtual&&v.push({col:w,row:E}):(L.colSpan>1||L.rowSpan>1)&&v.push({col:w,row:E})}n.undoManager.runInGroup(()=>{if(v.forEach(x=>{const O=et.fromBlock(e).getCell(x);(O.colSpan>1||O.rowSpan>1)&&ch(n,e,x)}),m>r.colCount)for(let x=r.colCount;x<m;x++)t5(n,e,x);if(C>r.rowCount)for(let x=r.rowCount;x<C;x++)e5(n,e,x);r=et.fromBlock(e);const w=new oh(s);let E;for(let x=0;x<w.colCount;x++)for(let O=0;O<w.rowCount;O++){const A=w.getCell({col:x,row:O});if(!A.virtual){const P=Gd(n.editorBlocks,t,A.containerId),V=u+x,nt=f+O,ot={col:V,row:nt},ut=r.getCellContainer(ot);Cp(n,ut,P),E=ut}}d(Bh,E,"no last container");const L=Gt(E);n.selection.selectBlock(L,Z(n,L))})}const n5=y("paste-in-table-block");class aE{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePasteDoc(t,e){if(!t.selection.range.isSimple()||t.selection.range.start.offset!==0)return!1;const r=t.selection.startBlock,i=j(r);if(Ct(i)||!ud(t,i))return!1;const s=z(i);if(d(n5,s,"no parent block"),!jt(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;n5.debug("paste child table in table");const a=et.fromBlock(s).getCellByContainerId(U(i)).cell;return cE(t,e,s,a),!0}}function o5(n){n.addCustom("table-block-paste-event",t=>new aE(t))}const Eh=y("table-select-columns");function dE(n,t,e,o,r){d(Eh,jt(t),"is not a table block");const i=et.fromBlock(t);d(Eh,e>=0&&e<i.colCount,"invalid from"),d(Eh,o>0&&e+o<=i.colCount,"invalid count");const s=i.getCell({row:0,col:e}),l=i.getCell({row:i.rowCount-1,col:e+o-1}),c=bt(t,s.containerId,{colIndex:e,rowIndex:0}),a=bt(t,l.containerId,{colIndex:e+o-1,rowIndex:i.rowCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const Ih=y("table-select-columns");function uE(n,t,e,o,r){d(Ih,jt(t),"is not a table block");const i=et.fromBlock(t);d(Ih,e>=0&&e<i.rowCount,"invalid from"),d(Ih,o>0&&e+o<=i.rowCount,"invalid count");const s=i.getCell({row:e,col:0}),l=i.getCell({row:e+o-1,col:i.colCount-1}),c=bt(t,s.containerId,{rowIndex:e,colIndex:0}),a=bt(t,l.containerId,{rowIndex:e+o-1,colIndex:i.colCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const lF="",r5=y("get-toolbar-reference-client");function hE(n,t){const e=n.selection.range;if(!e.isSimple()){d(r5,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);d(r5,ct(n,s),"not a complex block");const l=kt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const o=e.isReverse()?t.start:t.end,r=Vt(n,{anchor:o,focus:o}),i=Oo(n,t.block,r);if(i.length!==0)return i[0]}function fE(n){var t,e;if(n.children){let o=!1;const r=[];for(const i of n.children){if((t=i.states)!=null&&t.includes("checked")){o=!0;break}(e=n.defaultCheckedChildren)!=null&&e.includes(i.id)&&r.push(i)}if(!o&&(r==null?void 0:r.length))for(const i of r)Array.isArray(i.states)?i.states.push("checked"):i.states=["checked"]}}function gc(n){const t=(r,i)=>{const s=r.findIndex(c=>c.id===i.id);if(s===-1){r.push(i);return}const l=r[s];if(l.value!==i.value&&delete l.value,!!l.states){if(!i.states){l.states=[];return}l.states=$a.default(l.states,i.states)}},e=[],o=new Map;return n.forEach(r=>{var i,s;(i=r.children)!=null&&i.length&&(o.has(r.id)?(s=o.get(r.id))==null||s.push(...r.children):o.set(r.id,[...r.children])),t(e,r)}),o.forEach((r,i)=>{const s=e.find(l=>l.id===i);s&&(s.children=gc(r),fE(s))}),e}function pc(n){return n.getCustom("toolbar-handler")}const cF="";class mE{constructor(){h(this,"linkPopup",null);h(this,"form",{});h(this,"onFinished",null);h(this,"onClose",null);h(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:o}=this.form;(t=this.onFinished)==null||t.call(this,e.getInputValue()||o.getInputValue(),o.getInputValue()),this._destroy()}catch{}});h(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});h(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});h(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector(".submit-button");t.disabled=!1});h(this,"handleTextKeyboard",t=>{var e;if(!t.isComposing){if(t.key==="Enter"){(e=this.form.linkUrl)==null||e.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});h(this,"handleUrlKeyboard",t=>{if(!t.isComposing){if(t.key==="Enter"){this.handleOk(),t.preventDefault();return}t.key==="Escape"&&this.handleClose()}})}async checkValue(){const{linkUrl:t}=this.form;if(!t.getInputValue())throw t.setFieldError(S.t("link.urlPlaceholder")),new Error(S.t("link.urlPlaceholder"))}editLink(t){var u,f;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new rc(this.createPopupContent(o,r)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=i,s&&(this.onClose=s);const c=(u=this.linkPopup)==null?void 0:u.content.querySelector(".submit-button"),a=(f=this.linkPopup)==null?void 0:f.content.querySelector(".cancel-button");c==null||c.addEventListener("click",this.handleOk),a==null||a.addEventListener("click",this.handleClose)}createPopupContent(t,e){const o=b("div",["link-popup-content"],null);this.form.linkText=Xu(o,{label:S.t("link.textLabel"),required:!1,placeholder:S.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Xu(o,{className:"link-popup-gap",label:S.t("link.urlLabel"),required:!0,placeholder:S.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,S.t("link.cancelText"));const i=b("button",["submit-button"],r,S.t("link.submitText"));return i.disabled=!0,o}_destroy(){var o,r,i,s;const t=(o=this.linkPopup)==null?void 0:o.content.querySelector(".submit-button"),e=(r=this.linkPopup)==null?void 0:r.content.querySelector(".cancel-button");t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(i=this.linkPopup)==null||i.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function Cc(n,t){n.addCustom("link-editor",()=>new mE).editLink(t)}const gE=y("link-popup");function pE(n){return lt(n,"link")}function bc(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function CE(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&Re(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(xi(c))).getBoxProperties)==null?void 0:i.call(r,n,c);return a!=null&&a.boxCommands?(l=(s=a.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[]:[]}return n.isWritable()&&e&&H(n,t)&&pE(e)?[{id:"link-text",name:bc(e),element:b("span",["link-href-button"],null,bc(e))},{id:"edit-link",name:"Edit",icon:Ku},{id:"remove-link",name:"Remove link",icon:hw}]:Gm(n,t,"hovering-toolbar")}function bE(n,t,e){var c;const o=Br(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=bc(e);Cc(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,u)=>{try{const f=n.getBlockText(t),m=Dd(f,o.start,o.end-o.start),C=Ir(m,o.start,a,{link:u});n.setBlockText(t,C),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){gE.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function vE(n,t,e){const o=Br(t,e),r=n.getBlockText(t),i=bc(e),s=xr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function kE(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&Re(e)){const u=e,f=(l=(s=n.editorBoxes.getBoxClass(xi(u))).getBoxProperties)==null?void 0:l.call(s,n,u);if(f!=null&&f.boxCommands){f.boxCommands["hovering-toolbar"].executeCommand(n,t,u,o);return}return}const a=pc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?bE(n,t,e):o.id==="remove-link"&&vE(n,t,e);return}const r=Wm(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}const yE=[Fu,zu,Uu,Vu,qu,Wu,Gu,Zu];class wE{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){return 6}getAvailableCommands(t,e,o){if(H(t,e)){const r=G(e),i=it(e),s=Ge(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:S.t("commands.heading",{name:`${f+1}`}),icon:yE[f],states:c===f+1?["checked"]:[],value:`${f+1}`});return[{id:"turn-into",name:"",blockId:r,blockType:i,blockKind:s,element:f=>{var C;const m=b("span",["toolbar-item-name-container"],null);for(const v of f.children)if((C=v.states)!=null&&C.includes("checked"))return m.innerHTML=v.icon||nc,m;return m.innerHTML=nc,m},groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:S.t("commands.text"),icon:nc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(H(t,e)&&(r.id.startsWith("heading-")||r.id==="text")){const i=r.value?Number(r.value):null;return this.applyHeadingStyle(t,e,i),!0}return!1}}const vc=y("list-block");function at(n){return it(n)==="list"}function Ht(n){d(vc,at(n),"not a list block")}function je(n){Ht(n);const t=n.getAttribute("data-list-type");return d(vc,t,"no list type"),t}function kc(n){return at(n)&&je(n)==="text-only"}function Se(n){var t,e;return Ht(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function Te(n){var t,e;return Ht(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Qo(n){Ht(n);const t=n.getAttribute("data-list-group-id");return d(vc,t,"no group id"),t}function mo(n){var i,s,l,c,a;Ht(n);const t=(i=n.getAttribute("data-list-type"))!=null?i:"ordered",e=(l=Number.parseInt((s=n.getAttribute("data-list-start"))!=null?s:"1",10))!=null?l:1,o=(a=Number.parseInt((c=n.getAttribute("data-list-level"))!=null?c:"1",10))!=null?a:1,r=n.getAttribute("data-list-group-id");return d(vc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function yc(n){switch(n){case"ordered":return{ordered:!0,checkbox:null,textOnly:null};case"unordered":return{ordered:!1,checkbox:null,textOnly:null};case"checked":return{checkbox:"checked",ordered:!1,textOnly:null};case"unchecked":return{checkbox:"unchecked",ordered:!1,textOnly:null};case"text-only":return{checkbox:null,ordered:!1,textOnly:!0};default:return{checkbox:null,ordered:!0,textOnly:!1}}}function Wn(n){Ht(n);const{level:t,groupId:e,type:o}=mo(n);let r=gt(n);for(;r;){if(!at(r))return null;const{level:i,groupId:s,type:l}=mo(r);if(i<t)return null;if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;r=gt(r)}return null}function Ko(n){Ht(n);const{level:t,groupId:e,type:o}=mo(n);let r=ht(n);for(;r;){if(at(r)){const{level:i,groupId:s,type:l}=mo(r);if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;if(i<t)return null}r=ht(r)}return null}function i5(n){Ht(n);const t=[];let e=Wn(n);for(;e;)t.unshift(e),e=Wn(e);return t}function wc(n){Ht(n);const t=[];let e=Ko(n);for(;e;)t.push(e),e=Ko(e);return t}function us(n){Ht(n);let t=Wn(n);for(;t;){const e=Wn(t);if(!e)return t;t=e}return n}function BE(n){Ht(n);let t=Ko(n);for(;t;){const e=Ko(t);if(!e)return t;t=e}return null}function EE(n,t){const e=i5(n),o=wc(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function Bc(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:N();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(o==null?void 0:o.resetGroupId)){const c={...l,start:e};o!=null&&o.resetGroupId&&(c.groupId=r),n.updateBlockData(s,c)}l.textOnly||(e+=1)})}function xh(n,t,e,o){const r=EE(t,{withSelf:!0});r.length!==0&&Bc(n,r,e,o)}function IE(n){const t={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};let e="",o=n;return Object.entries(t).forEach(([r,i])=>{for(;o>=i;)e+=r,o-=i}),e.toLowerCase()}const xE="abcdefghijklmnopqrstuvwxyz";function s5(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=xE[t];return e?s5(e)+o:o}function SE(n){return`${n}`}const l5=[SE,s5,IE];function TE(n,t){const e=l5[(n-1)%l5.length];return e(t)}function DE(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class Jo{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=us(e),i=Se(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||xh(this.editor,this.listBrother,this.listStart,this.options)}}function LE(n,t,e=1){if(!t)return null;let o=gt(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return at(o)?o:null}o=gt(o)}return null}function c5(n,t){const e=n.getAttribute("data-style-heading"),o=LE(n,e);if(o)return o;const r=gt(n);if(r&&at(r)&&je(r)===t)return r;const i=ht(n);return i&&at(i)&&je(i)===t?i:null}function ME(n,t,e){var E,L,x;const o=(E=e.data)!=null?E:{},r=1,i=(L=o.listType)!=null?L:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(x=s.text)!=null?x:[];const c=n.selection.range.focus;if(!c.isSimple())return null;let u=wt(l);const f=c.offset;f<=ce(l)&&(l=fe(l,f).right,u=u.substring(0,f));let m=1;i==="ordered"&&(m=Number.parseInt(u,10)||1);let C=N();const v=c5(t,i);if(v){if(K(t)>K(v))m=Se(v)+1;else{const O=Se(v);O>1&&(m=O-1)}C=Qo(v)}const w={id:N(),type:"list",level:r,start:m,groupId:C,ordered:!1,text:l};return s.quoted&&(w.quoted=!0),s.heading&&(w.heading=s.heading),i==="ordered"?w.ordered=!0:(i==="checked"||i==="unchecked")&&(w.checkbox=i),{blockData:w,onConverted:(O,A)=>{new Jo(O,A).fix()}}}const RE=8,Mt=y("list-block");class Ec{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,kc(e))return;const o=us(e),r=Se(o);this.listStart=r,o===e?this.listBrother=Ko(o):this.listBrother=o}fix(){!this.listBrother||xh(this.editor,this.listBrother,this.listStart)}}function OE(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function Sh(n,t,e,o){if(Mt.debug("drag a block on a list block"),!H(n,t))return!1;d(Mt,at(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=mo(e),c=o==="after"?i+1:i,a=n.getBlockData(t),u={id:N(),type:"list",groupId:l,level:s,start:c,text:a.text,...yc(r)};OE(n,e,u);let f=K(e);const m=j(e);o==="after"&&(f+=1);let C=null;at(t)&&(C=new Ec(n,t));const v=n.insertBlock(U(m),f,u,Sl(u.id,0));return n.deleteBlock(t),new Jo(n,v).fix(),C==null||C.fix(),!0}function AE(n,t,e,o){if(Mt.debug("drag a list between text blocks"),o==="after"){const a=ht(e);if(a&&at(a))return Sh(n,t,a,"before")}if(o==="before"){const a=gt(e);if(a&&at(a))return Sh(n,t,a,"after")}const i={...n.getBlockData(t),groupId:N(),start:1,level:1};let s=K(e);const l=j(e);o==="after"&&(s+=1),n.insertBlock(U(l),s,i,Sl(i.id,0));const c=new Ec(n,t);return n.deleteBlock(t),c.fix(),!0}function _E(n,t,e,o,r){if(il(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);d(Mt,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=r;return!l&&c?(d(Mt,t===c,"block !== target block"),d(Mt,at(c),"target is not a list block"),Sh(n,s,c,o)):AE(n,s,c,o)}function a5(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function NE(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${TE(t,(o=n.start)!=null?o:1)}.`:DE(t)}const PE=`<?xml version="1.0" ?>
|
|
335
335
|
<svg t="1666868766077" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3547" width="16" height="16">
|
|
336
336
|
<path d="M864 128H160c-17.6 0-32 14.4-32 32v704c0 17.6 14.4 32 32 32h704c17.6 0 32-14.4 32-32V160c0-17.6-14.4-32-32-32zM428 718.4l-45.6 45.6-45.6-45.6-116-117.6 45.6-45.6L383.2 672l367.2-367.2 45.6 45.6-368 368z" p-id="3548" fill="#1296db"></path>
|
|
337
337
|
</svg>
|