@ones-editor/editor 0.0.3-beta.52 → 0.0.3-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -334,7 +334,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
334
334
|
<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"/>
|
|
335
335
|
<path d="M9.07413 10.8036H13.2226M11.1484 8.91895V13.1009V8.91895Z" stroke="#999999" stroke-linecap="square" fill="none"/>
|
|
336
336
|
<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"/>
|
|
337
|
-
</svg>`;function gB(n,t){var e;if(A(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 r=b("div",["menu-item-icon"],null);n.icon&&(r.innerHTML=n.icon),t.appendChild(r)}const o=b("div",["menu-item-name"],null,n.name);if(t.appendChild(o),n.subText&&b("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const r=b("div",["menu-item-sub-indicator"],null);r.innerHTML=J2,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=Yw,t.appendChild(r)}}}}class tr extends gc{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){A(t,"menu")}initItemElement(t,e){gB(t,e)}}function pB(n,t,e){var o;return new tr((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class ps extends gc{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){A(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),this.options.tooltipId&&t.name&&!t.disableTooltip&&(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=Ju}t.states&&(t.states.indexOf("checked")!==-1&&A(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function CB(n,t,e){var o;return new ps((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const lz="";Hr.registerManualCommandBar("menu",pB),Hr.registerManualCommandBar("toolbar",CB);const cz="",l5=w("ui-base");class bc extends gc{constructor(e,o){super(bc.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){A(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];d(l5,e,"no dialog item");const o=e.element;return d(l5,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 bB=[-1,6,0,1,2,3,4,5],vB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],c5=w("color-palette");function a5(n,t,e,o){d(c5,n>0,"no color in palette");const r=t||1;d(c5,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 kB(n){const t=b("button",["color-button"],null),e=bB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=K2,t}function yB(n){const t=b("button",["background-color-button"],null),e=vB[n];return t.setAttribute("data-color-index",`${e}`),t}function wB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=T.t("colorPalette.reset"),n}function BB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.colorDesc")),t.appendChild(a5(8,1,kB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.backgroundDesc")),t.appendChild(a5(16,2,yB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(wB()),t}function EB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&z(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&A(i,"selected")}const az="",IB={};class xB extends Yt.TypedEmitter{constructor(e=IB){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(nt(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)||(nt(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=BB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){EB(this.root,e,o)}}class d5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new xB(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function TB(){const n=b("button",["color-button"],null);return n.innerHTML=K2,n}function dh(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 SB extends Yt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name",T.t("colorPalette.name"));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],dh(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new d5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=TB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,dh(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,dh(this.element,this.latestColors)}}const dz="";function uh(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&A(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&A(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),z(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{A(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function hh(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 DB=w("ui-base");class LB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{hh(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new tr([],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(!It(this.editor.rootContainer,r)||W(this.editor,r)<o)return;const i=Ho(this.editor,r,At(this.editor,r,o));if(i.length===0)return;const s=i[0],l=zo(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:T.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 qe.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{qe.release(e)}}highlightText(t){DB.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(nt(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 fh=w("auto-suggest-menu");class mh{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(vt(be(ue(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=vt(Ul(t,i,r));if(d(fh,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 LB(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)||rd(e.key)?!1:km(e)&&!Oo(e)?(setTimeout(()=>{this.resetItems()}),!1):id(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:q(t),offset:e,leftText:o,trigger:r};const i=U(H(t)),s=J(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var u;const s=t.selection.range.start;if(!s.isSimple()||e==="root"&&o===0)return!1;const{blockId:l,offset:c}=s,a=t.getBlockByIndex(e,o);if(q(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=vt(Ul(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 q(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=vt(Ul(t,i,r));if(d(fh,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);fh.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()}}function MB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const RB={"insert-hr":{shortcut:"/hr"},"insert-uml":{shortcut:"/uml"},"insert-table":{shortcut:"/table"},"insert-image":{shortcut:"/image"},"insert-code":{shortcut:"/code"},"insert-link":{shortcut:"/link"},"insert-drawio":{shortcut:"/uml"},"insert-video":{shortcut:"/video"},"insert-audio":{shortcut:"/audio"},"insert-math":{shortcut:"/math"},"insert-webPage":{shortcut:"/web"},"insert-bilibili":{shortcut:"/bilibili"},"insert-youku":{shortcut:"/youku"},"insert-figma":{shortcut:"/figma"},"insert-modao":{shortcut:"/modao"},"insert-tencent":{shortcut:"/tencent"},"insert-unordered":{shortcut:"/bl"},"insert-ordered":{shortcut:"/nu"},"insert-checkbox":{shortcut:"/todo"},"insert-quote":{shortcut:"/quote"},...MB()};function fe(n){var t;return(t=RB[n])==null?void 0:t.shortcut}function AB(n){var t;return(t=n.subText)!=null?t:""}const In=w("table-dom");function Co(n){return`${q(n)}_scroll`}function jt(n){const t=n.querySelector("div[data-type=table-content] >table");return d(In,t instanceof HTMLTableElement,"invalid table"),t}function xn(n,t){const o=n.getCustom(Co(t)).contentElement.firstElementChild;d(In,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(In,r,"no table tools"),r}function u5(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function Cs(n){const t=n.querySelector(":scope div[data-type=editor-container]");return d(In,t,"no child container in cell"),t}function OB(n){const o=u5(n).map(r=>{const i=Cs(r),s=U(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Ei.default(o)}function Ht(n){return rt(n)==="table"}function gh(n){const t=H(n);if(pt(t))return null;const e=F(t);return d(In,e,"no parent block"),Ht(e)?t:gh(e)}function Me(n){if(Ht(n))return n;const t=H(n);if(pt(t))return null;const e=F(t);return d(In,e,"no parent block"),Ht(e)?e:Me(e)}function _B(n,t){const e=n.querySelector("colgroup");d(In,e,"no colgroup");const o=e.children[t];return d(In,o,"no col"),d(In,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function h5(n){try{return jt(n),!0}catch{return!1}}function NB(n){return Rt(n).querySelector(":scope > .block-helper")}function f5(n){const t=F(n.contentElement);d(In,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 Re=w("doc-table-grid");class $B{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(Re,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){d(Re,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return d(Re,e,"get cell, no cell"),e}getCellAllowEmpty(t){return d(Re,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 vc{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 $B(this.colCount));this.fillGrid(),d(Re,t.colsWidth,"no colsWidth"),d(Re,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(Re,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(Re,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{d(Re,i,"no cell"),d(Re,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];d(Re,r,`get cell, no row: ${o}`);const i=r.getCell(e);return d(Re,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return d(Re,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const kc=w("table-data");function PB(n){const t=n.firstElementChild;return d(kc,t,"no child element for cell"),d(kc,bn(t),"cell first child is not a container"),d(kc,Ye(t),"cell first child is not a container"),t}function jB(n){const t=F(n);d(kc,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=PB(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:q(t),type:rt(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function er(n){return new vc(n)}function HB(n){return er(jB(n))}const Zt=w("table-grid"),FB=60;class zB{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(Zt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);d(Zt,t.length===1,"containers !== 1"),d(Zt,bn(t[0]),"not a container");const e=t[0];return d(Zt,Ye(e),"not a child container"),e}}class UB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new zB(t,o))})}get cells(){return this._cells}getCell(t){return d(Zt,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 Ef=class{constructor(t){h(this,"_rows",[]);this.table=t,HB(t).forEach(r=>{this._rows.push(new UB(t,r))});const o=this.colCount;this._rows.forEach(r=>{d(Zt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(d(Zt,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(Zt,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(Zt,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(Zt,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(Zt,!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(Zt,o<=r,"min > max"),d(Zt,o>=0,"min < 0"),d(Zt,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(Zt,o<=r,"min > max"),d(Zt,o>=0,"min < 0"),d(Zt,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(Zt,o,"cell not found"),o}getCellByCellElement(t){const e=Cs(t);return this.getCellByContainerId(U(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=OB(t),o=this.caches.getSync(e,()=>(Zt.debug("create table grid"),new Ef(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let et=Ef;h(et,"caches",new Xf(FB));function yc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const VB=w("table-selection-range");function an(n,t,e){var I,M,R,$;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=(I=c==null?void 0:c.rowIndex)!=null?I:s.row,f=(M=c==null?void 0:c.colIndex)!=null?M:s.col,m=(R=a==null?void 0:a.rowIndex)!=null?R:l.row+l.rowSpan-1,C=($=a==null?void 0:a.colIndex)!=null?$:l.col+l.colSpan-1,v=Math.min(u,m),B=Math.max(u,m),y=Math.min(f,C),S=Math.max(f,C);return{fromRow:v,toRow:B,fromCol:y,toCol:S}}function ph(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===q(t)){const i=et.fromBlock(t),{start:s,end:l}=r;d(VB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(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 Fr=w("delete-columns");function m5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{fromRow:s,toRow:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.rowCount-1}function Ch(n){var M;const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!m5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=an(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(R=>R.containerId);for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<=r;Z++){const ot=$[Z];s.add(ot)}$.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(R=>!c.has(R))),u=r-o+1,f=new Map,m=new Map;s.forEach(R=>{if(a.has(R))return;const $=i.getCellByContainerId(R);if(d(Fr,$.colSpan>1,"invalid effected cell, colSpan === 1"),$.col<o){d(Fr,c.has(R),"invalid effected cell, not exists");let yt=$.col+$.colSpan-1;yt>r&&(yt=r);const se=yt-o+1,eo=$.colSpan-se;f.set(R,eo);return}d(Fr,$.col<=r,"invalid effected cell, col > endCol");const Z=$.col,ot=$.col+$.colSpan-1,st=$.col-o,mt=ot-Z+1-u+st;d(Fr,mt>0,"invalid effected cell, newSpanned <= 0");const ut=yn(t.doc);m.set(R,{newContainerId:ut,colSpan:mt})});for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<$.length;Z++){const ot=$[Z],st=m.get(ot);st&&($[Z]=st.newContainerId)}}const C=Y.default(t.getBlockData(e));C.colsWidth.splice(o,r-o+1),a.forEach(R=>{yc(C,R)}),f.forEach((R,$)=>{d(Fr,R>=1,"invalid modified colSpan, colSpan < 1"),R===1?C[`${$}_colSpan`]=void 0:C[`${$}_colSpan`]=R}),m.forEach((R,$)=>{yc(C,$);const{newContainerId:Z,colSpan:ot}=R;d(Fr,ot>=1,"invalid newContainerData, colSpan < 1"),ot>1&&(C[`${Z}_colSpan`]=ot);const st=i.getCellByContainerId($).rowSpan;st>1&&(C[`${Z}_rowSpan`]=st)});const B=(M=l[0][o])!=null?M:l[0][o-1],y=t.getChildContainerData(B)[0],S=et.virtualCellContainersGridToChildren(l),I={...C,cols:C.cols-u,children:S};er(I),t.undoManager.runInGroup(()=>{t.updateBlockData(e,I,At(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const zr=w("delete-rows");function g5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{fromCol:s,toCol:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.colCount-1}function bh(n){const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!g5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=an(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(I=>I.containerId);for(let I=r;I>=o;I--)l[I].forEach(R=>s.add(R)),l.splice(I,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(I=>!c.has(I))),u=r-o+1,f=new Map,m=new Map;s.forEach(I=>{if(a.has(I))return;const M=i.getCellByContainerId(I);if(d(zr,M.rowSpan>1,"invalid effected cell, rowSpan === 1"),M.row<o){d(zr,c.has(I),"invalid effected cell, not exists");let mt=M.row+M.rowSpan-1;mt>r&&(mt=r);const ut=mt-o+1,yt=M.rowSpan-ut;f.set(I,yt);return}d(zr,M.row<=r,"invalid effected cell, col > endCol");const R=M.row,$=M.row+M.rowSpan-1,Z=M.row-o,ot=$-R+1-u+Z;d(zr,ot>0,"invalid effected cell, newSpanned <= 0");const st=yn(t.doc);m.set(I,{newContainerId:st,rowSpan:ot})});for(let I=o;I<l.length;I++){const M=l[I];for(let R=0;R<M.length;R++){const $=M[R],Z=m.get($);Z&&(M[R]=Z.newContainerId)}}const C=Y.default(t.getBlockData(e));a.forEach(I=>{yc(C,I)}),f.forEach((I,M)=>{d(zr,I>=1,"invalid modified rowSpan, rowSpan < 1"),I===1?delete C[`${M}_rowSpan`]:C[`${M}_rowSpan`]=I}),m.forEach((I,M)=>{yc(C,M);const{newContainerId:R,rowSpan:$}=I;d(zr,$>=1,"invalid newContainerData, rowSpan < 1"),$>1&&(C[`${R}_rowSpan`]=$);const Z=i.getCellByContainerId(M).colSpan;Z>1&&(C[`${R}_colSpan`]=Z)});const v=l[o]?l[o][0]:l[o-1][0],B=t.getChildContainerData(v)[0],y=et.virtualCellContainersGridToChildren(l),S={...C,rows:C.rows-u,children:y};er(S),t.undoManager.runInGroup(()=>{t.updateBlockData(e,S,At(t,B.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const bs=w("table-range");function wc(n){d(bs,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;d(bs,!t.isSimple(),"invalid start pos type"),d(bs,!e.isSimple(),"invalid end pos type");const o=n.getEditor();d(bs,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);d(bs,rt(r)==="table","invalid block type, not a table block");const i=jt(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 vh=w("split-cell");function kh(n,t,e){const o=et.fromBlock(t),r=o.getRealCell(e);d(vh,!r.virtual,"should not split virtual cell"),d(vh,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,B=yn(n.doc);i[C][v]=B}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(vh,a,"no child block");const u=At(n,a.id,0);er(l),n.updateBlockData(t,l,u)}function qB(n,t,e){e.forEach(o=>{const r=et.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&kh(n,t,o)})}function p5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{startCell:s,endCell:l}=wc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function yh(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=wc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return qB(t,e,l),!0}const Ur=w("merge-cells");function C5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{startCell:s,endCell:l}=wc(e);return s.cell!==l.cell}function b5(n){const t=wc(n),e=t.endCell,o=e.row+e.rowSpan-1,r=e.col+e.colSpan-1,i=q(t.block),s=t.editor;yh(n);const l=s.getBlockById(i),c=jt(l),{startRow:a,startCol:u}=t,f=Y.default(s.getBlockData(l));d(Ur,f.children,"no table children");const m=et.fromTable(c),C=[];for(let mt=a;mt<=o;mt++)for(let ut=u;ut<=r;ut++){const yt=m.getCell({row:mt,col:ut});d(Ur,!yt.virtual,"cell is virtual"),C.push(yt)}d(Ur,C.length>0,"no selected cells");const v=C[0],B=C.slice(1),y=m.getCellByContainerId(v.containerId).container,S=[];B.forEach(mt=>{const ut=m.getCellByContainerId(mt.containerId).container,yt=U(ut);if(!Bd(s,ut)){const se=R0(s,yt);s.insertDocAt(y,Ge(y),se)}S.push(yt)});const I=U(y),M=r-u+1,R=o-a+1;f[`${I}_colSpan`]=M,f[`${I}_rowSpan`]=R,S.forEach(mt=>{d(Ur,f.children,"no table children");const ut=f.children.indexOf(mt);d(Ur,ut>0,"no deleted container"),f.children.splice(ut,1)});const $=f,ot=s.getChildContainerData(I)[0];d(Ur,ot,"no child block");const st=At(s,ot.id,0);er($),s.updateBlockData(l,$,st),s.deleteChildContainers(S)}const wh=10,WB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Bh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(rt(e)!=="table")return[];const r={blockId:q(e),blockKind:Qe(t,e),blockType:rt(e)},i=[];C5(t,e,o)&&i.push({id:"table/merge-cells",name:T.t("table.mergeCell"),icon:Aw,groupIndex:wh,...r}),p5(t,e,o)&&i.push({id:"table/split-cell",name:T.t("table.splitCell"),icon:Ow,groupIndex:wh,...r});const s=m5(t,e,o),l=g5(t,e,o);return s&&l&&i.push({id:"table/delete",name:T.t("table.deleteTable"),icon:_w,groupIndex:wh,...r}),i}executeCommand(t,e,o,r,i,s){return rt(e)!=="table"||!new Set(WB).has(r.id)?!1:r.id==="table/merge-cells"?(b5(o),!0):r.id==="table/split-cell"?(yh(o),!0):r.id==="table/delete-columns"?(Ch(o),!0):r.id==="table/delete-rows"?(bh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var v5=(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))(v5||{});const Eh=6,vs=20;function GB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function ZB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function YB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function QB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function KB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function JB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function XB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const Ih=w("get-selected-containers");function xh(n,t,e,o){d(Ih,e.blockId===o.blockId,"only allow select in single table block"),d(Ih,q(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(y=>r.getCellContainer(y));const{fromCol:l,toCol:c,fromRow:a,toRow:u}=an(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:u,col:c}).forEach(v=>{v.forEach(B=>{const y=r.getCellByContainerId(B.containerId);y.col<l||y.row<a||y.col+y.colSpan-1>c||y.row+y.rowSpan-1>u||f.has(B.containerId)||(f.add(B.containerId),m.push(y.container))})}),m}function tE(n,t,e){d(Ih,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return xh(n,o,t,e)}const nr=w("table-cell-dom");function eE(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");d(nr,r,"no parent cell");const i=F(r);if(d(nr,i,"no parent block"),i===t)return r;o=i}return d(nr,!1,"filed to get cell by child block id"),null}function Gn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return d(nr,e.childContainerId,"block position must have childContainerId attribute"),e;const r=eE(n,t,e.blockId),i=U(Cs(r));return wt(t,i)}function Th(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return an(t,o,r)}function k5(n,t,e,o){d(nr,Ht(t),"invalid table block");const r=xn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");d(nr,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)?A(a,"danger"):z(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");d(nr,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)?A(a,"danger"):z(a,"danger")})};i(),s()}function Vr(n,t,e=!0,o){const i=et.fromBlock(t).map(u=>u),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Th(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||A(C.cell,"danger"):C.virtual||z(C.cell,"danger")}}}function qr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){k5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Th(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);k5(n,t,Array.from(r),Array.from(i))}function y5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Th(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}),Wt(n,{anchor:wt(t,c.containerId,{colIndex:o,rowIndex:0}),focus:wt(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}),Wt(n,{anchor:wt(t,c.containerId,{colIndex:0,rowIndex:i}),focus:wt(t,a.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function nE(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return xh(n,t,o,r)}const w5=["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 B5(n){return`style-bg-color-${n}`}function ks(n){return`${n}_background`}function oE(n,t,e){const o=jt(n),s=(e!=null?e:et.fromTable(o)).getCell(t).cell;for(let l=0;l<w5.length;l++){const c=w5[l];if(nt(s,c))return c}}function E5(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Y.default(n.getBlockData(t))},s=Gn(n,t,o.start),l=Gn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[ks(c)]=void 0:i[ks(c)]=B5(e)}else{const c=et.fromBlock(t),a=an(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[ks(C.containerId)]=void 0:i[ks(C.containerId)]=B5(e))}}n.updateBlockData(t,i)}function rE(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const I5=w("table-chart");function iE(n,t){const e=xn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function sE(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){iE(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 B=1;B<i.colCount;B++)c.push(i.getCell({row:0,col:B}).container.innerText);for(let B=1;B<i.rowCount;B++){const y=i.getCell({row:B,col:0}),I=y.container.innerText,M=[];for(let se=1;se<i.colCount;se++){const eo=i.getCell({row:B,col:se}).container.innerText,ee=Number.parseFloat(eo)||0;M.push(ee)}let R;const $=oE(t,y,i);$?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${$}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[Z,ot,st,mt]=R?Wa.fromString(R).toRgbaArray():[];if(!Z&&!ot&&!st&&!mt){const se=(B-1)%n.options.colors.length;R=n.options.colors[se],[Z,ot,st,mt]=Wa.fromString(R).toRgbaArray()}const ut=R,yt=Wa.fromRgba([Z,ot,st,mt/3]).toHexString();r.push({label:I,data:M,borderColor:ut,backgroundColor:yt,borderWidth:2})}const a=xn(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(I5,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 Ro(v,"editor-chartjs"),u&&l!==u.config.type&&(u.destroy(),u=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(S=>{S.remove()}));const B=Ga.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(u)Ga.default(u.config,B),u.update();else{const S=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");u=new window.Chart(S,B),f.chartObject=u}}catch(B){I5.error(`failed to resolve chart cdn: ${JSON.stringify(B)}`)}}async function x5(n,t){await qe.lock("updateTableChart");try{await sE(n,t)}finally{qe.release("updateTableChart")}}const T5=Xt.default(x5,1e3);let S5=null;function Sh(n,t,e){if(S5!==t&&(T5.flush(),S5=t),e.updateNow){x5(n,t);return}T5(n,t)}function Dh(n,t){Ht(t)&&Sh(n,t,{updateNow:!1})}function lE(n,t){Ht(t)&&Sh(n,t,{updateNow:!0})}const je={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"},Bc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},bo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Ec(n,t){return n.containers.get(t)}function D5(n){return n.closest(`.${bo.SCROLL_CONTAINER}`)}function dn(n){return n.firstElementChild}function Ae(n){return n.closest(`.${bo.CONTAINER}`)}function ys(n){const t=Ae(n);let e=t.querySelector(`:scope >.${bo.TOOL}`);return e||(e=b("div",[bo.TOOL],t)),e}function cE(n){return Ae(n).firstElementChild}function Ic(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}function He(n,t){const e=Ic(n);return t/e}function ws(n){const t=window.getComputedStyle(n),e=Ic(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Wr(n){const t=Ic(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function aE(n,t){const e=Ic(n);return n[t]*e}function Lh(n,t){const e=Ae(t),o=Ec(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 dE(n,t){const e=Lh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${He(t,0-o)}px`,t.style.paddingLeft=`${He(t,o)}px`}function uE(n,t){const e=Lh(n,t);t.style.marginRight=`${He(t,0-e.maxRight)}px`}function hE(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 L5=w("scroll-bar-handle"),fE=2;function Gr(n){const t=ys(n);let e=t.querySelector(`.${Bc.SCROLL_BAR}`);return e||(e=b("div",[Bc.SCROLL_BAR],t)),d(L5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function xc(n,t){const e=D5(t),o=Gr(e),{scrollWidth:r,clientWidth:i}=Wr(e),{paddingLeft:s,paddingRight:l}=ws(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const c=Lh(n,e),{originWidth:a,maxRight:u}=c;uE(n,e),dE(n,e);const f=r-i;d(L5,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${He(e,a+u-s-l)}px`,o.firstElementChild.style.width=`${He(e,a+u+f-s-l)}px`}function mE(n,t){const e=dn(n),{paddingLeft:o}=ws(e);if(nt(t,"fixed")){const i=Ae(n).getBoundingClientRect();t.style.left=`${He(n,i.left+o)}px`}else t.style.left=`${He(n,o)}px`}function Zr(n,t){var I;const e=n.getParentScrollContainer(),o=hE(e),r=t.getBoundingClientRect(),i=Gr(t),s=i.getBoundingClientRect(),l=Ec(n,Ae(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=dn(t),{paddingTop:u,paddingBottom:f}=ws(a),{scrollWidth:m,clientWidth:C}=Wr(t),v=document.documentElement.clientHeight-c,B=o.top+Wr(e).clientHeight-v,y=v+Math.min(0,B);if(m>C&&r.top+u<y-s.height&&r.bottom>y-s.height+f&&!((I=l==null?void 0:l.isSetScale)!=null&&I.call(l))){A(i,Bc.FIXED);const M=B>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+fE+M}px`}else z(i,Bc.FIXED),i.style.bottom=`${He(t,f-s.height)}px`;mE(t,i)}class gE{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;Zr(this.scrollCore,e);const o=dn(e);xc(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 or=w("container-scroll-shadow");function M5(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=ws(e);o.style.top=`${He(t,i.top-r.top+s)}px`,o.style.bottom=`${He(t,r.bottom-i.bottom+l)}px`}function R5(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function pE(n){const t=ys(n);d(or,t,"no container tools");let e=t.querySelector(`.${je.LEFT}`);if(!e){const l=dn(n),c=[je.COMMON,je.LEFT];e=b("div",c,t),d(or,e instanceof HTMLDivElement,"invalid child for container tools"),M5(e,n,l)}d(or,e instanceof HTMLElement,"invalid child for container tools");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${He(n,i.left-r.left)}px`;const s=Wr(n).scrollLeft;d(or,e instanceof HTMLDivElement,"invalid child for container tools"),R5(e,s),A(e,je.ACTIVE)}function CE(n){const t=ys(n);let e=t.querySelector(`.${je.RIGHT}`);if(!e){const u=dn(n),f=[je.COMMON,je.RIGHT];e=b("div",f,t),d(or,e instanceof HTMLDivElement,"no div, create shadow failed"),M5(e,n,u)}d(or,e instanceof HTMLElement,"");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${He(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Wr(n),a=s-l-c;d(or,e instanceof HTMLDivElement,"no shadow element"),R5(e,a),A(e,je.ACTIVE)}function bE(n){const e=ys(n).querySelector(`.${je.LEFT}`);e&&z(e,je.ACTIVE)}function vE(n){const e=ys(n).querySelector(`.${je.RIGHT}`);e&&z(e,je.ACTIVE)}function Bs(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Wr(n),r=dn(n),{paddingLeft:i,paddingRight:s}=ws(r),l=aE(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?vE(n):CE(n),r&&t>=l+i?pE(n):bE(n)}class kE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=dn(e);Bs(e),xc(this.scrollCore,o),Zr(this.scrollCore,e),this.callback(e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,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 A5=w("container-scroll-observer");class yE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;d(A5,e instanceof Element,"invalid target for scroll event");const o=Gr(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),Bs(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;d(A5,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=cE(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),Bs(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",Xt.default(this.bindContentScrollCore,300));h(this,"bind",Xt.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=Gr(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 wE{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Zr(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 BE=w("scroll-wrap-resize-observer");class EE{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;d(BE,e instanceof HTMLElement,"invalid target for observer entry");const o=D5(e);xc(this.scrollCore,e),Bs(o),Zr(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 IE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=dn(e);Bs(e),xc(this.scrollCore,o),Zr(this.scrollCore,e),this.callback(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.callback=e,this.resizeObserver=new ResizeObserver(this.handleResize)}bind(t){var r,i;const e=Ae(t),o=(r=Ec(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=Ae(t),o=(i=Ec(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 uz="";class xE extends Yt.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,"handleResize",e=>{this.emit("resize",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=dn(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=>{Zr(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new kE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new yE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new wE(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new EE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new IE(this,this.handleResize)),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=Gr(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=Gr(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 gE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=dn(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 O5=w("scroll-container"),Tc=new Map;class TE extends Yt.TypedEmitter{constructor(){super(...arguments);h(this,"scrollListener");h(this,"options");h(this,"scrollContainerElement");h(this,"init",e=>{this.options=e;const o=b("div",[bo.CONTAINER],e.parentElement);xt.isMac&&A(o,bo.MAC);const r=b("div",[bo.SCROLL_CONTAINER],o),i=b("div",[bo.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=Tc.get(s),this.scrollListener||(this.scrollListener=new xE(s),Tc.set(s,this.scrollListener)),this.scrollListener.unbind(o),this.scrollListener.bind(o,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollListener.on("resize",this.handleResize),this.scrollContainerElement=r});h(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)});h(this,"handleResize",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return d(O5,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),dn(this.scrollContainerElement)}get scrollOptions(){return d(O5,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=Ae(this.contentElement);e&&Tc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),Tc.delete(i))})}}function SE(){return new TE}const Sc=100,DE=40,Mh=w("column-width");function LE(n,t,e){_B(n,t).style.width=`${e}px`}function ME(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)}),Mh.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)}Mh.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 Mh.debug(`widths: ${s.join()}`),s}function Es(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const RE=w("table-resize-gripper"),_5=7,Rh=(_5-1)/2,AE=3;function OE(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)<=Rh&&a.top<=e&&e<=a.bottom)return c}}return null}function _E(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Ah(n,t){return xn(n,t).querySelector(".table-resize-gripper")}function N5(n,t){const e=Ah(n,t);d(RE,!e,"resize gripper has already exists");const o=xn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function $5(n,t,e){let o=Ah(n,t);o||(o=N5(n,t));const i=jt(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(Co(t)).contentElement.getBoundingClientRect(),u=s.right-a.left;o.style.left=`${u-Rh-Eh-vs}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${_5}px`}function Oh(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 $E(n,t,e,o){const r=t,i=et.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=Es(e);let a=o;const u=(m,C)=>{const v=C+1,B=m.col+m.colSpan;return c.slice(v,B).reduce((S,I)=>S+I,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,B=v.getBoundingClientRect();let y=o-B.left+Rh-AE;const S=Cs(v),I=wd(n,S)||DE*C.colSpan,M=u(C,l),R=I-M;y<R&&(y=R);const $=B.left+y;a=Math.max(a,$)}return a}const PE=w("table-resize-drag-drop");class jE{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=$E(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;d(PE,c,"no dragging cell");const m=et.fromTable(s).getCellByCellElement(c),C=m.col+m.colSpan-1,B=Es(s).slice(0,C).reduce((S,I)=>S+I,0),y=u-B;LE(s,C,y),$5(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=Es(t.data.table);NE(this.editor,t.data.block,s),Oh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function HE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=F(e);return!o||!n.contains(o)||!Ht(o)?null:o}w("table-resize");class FE{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=HE(t,i);if(!s||!h5(s)){Oh(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=jt(t),i=OE(r,e,o);if(i){if(!Ah(this.editor,t)){if(_E(this.editor))return;const l=N5(this.editor,t),c={block:t,table:r,draggingRefCell:i};ed(new jE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}$5(this.editor,t,i)}else Oh(this.editor)}}function P5(n){n.addCustom("table-mouse-event-handler",t=>new FE(t))}const j5=w("table-insert-column");function H5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.colCount;d(j5,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],B=C[e];if(e===0||e===C.length||v!==B){const y=yn(n.doc);C.splice(e,0,y)}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(j5,typeof v=="number"&&v>1,`no colSpan for containerId ${m}, ${v}`),c[C]=v+1});const a=c.colsWidth.concat();a.splice(e,0,Sc);const u=et.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:u,colsWidth:a};er(f),n.updateBlockData(t,f)}const Dc=w("table-insert-row");function F5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.rowCount;d(Dc,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(Dc,C||v,"no top and bottom cell"),e===0||e===r.rowCount||C!==v){const B=yn(n.doc);c.push(B)}else d(Dc,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(Dc,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};er(f),n.updateBlockData(t,f)}const _h=w("paste-table-in-table-block");function zE(n,t,e,o){let r=et.fromBlock(e);const i=t.blocks.root[0];d(_h,i,"no table data"),d(_h,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 B=u;B<m&&B<r.colCount;B++)for(let y=f;y<C&&y<r.rowCount;y++){const S=r.getCell({col:B,row:y});S.virtual?S.virtual&&v.push({col:B,row:y}):(S.colSpan>1||S.rowSpan>1)&&v.push({col:B,row:y})}n.undoManager.runInGroup(()=>{if(v.forEach(I=>{const M=et.fromBlock(e).getCell(I);(M.colSpan>1||M.rowSpan>1)&&kh(n,e,I)}),m>r.colCount)for(let I=r.colCount;I<m;I++)H5(n,e,I);if(C>r.rowCount)for(let I=r.rowCount;I<C;I++)F5(n,e,I);r=et.fromBlock(e);const B=new vc(s);let y;for(let I=0;I<B.colCount;I++)for(let M=0;M<B.rowCount;M++){const R=B.getCell({col:I,row:M});if(!R.virtual){const $=hu(n.editorBlocks,t,R.containerId),Z=u+I,ot=f+M,st={col:Z,row:ot},mt=r.getCellContainer(st);Hp(n,mt,$),y=mt}}d(_h,y,"no last container");const S=Qt(y);n.selection.selectBlock(S,W(n,S))})}const z5=w("paste-in-table-block");class UE{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=H(r);if(pt(i)||!Bd(t,i))return!1;const s=F(i);if(d(z5,s,"no parent block"),!Ht(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;z5.debug("paste child table in table");const a=et.fromBlock(s).getCellByContainerId(U(i)).cell;return zE(t,e,s,a),!0}}function U5(n){n.addCustom("table-block-paste-event",t=>new UE(t))}const Nh=w("table-select-columns");function VE(n,t,e,o,r){d(Nh,Ht(t),"is not a table block");const i=et.fromBlock(t);d(Nh,e>=0&&e<i.colCount,"invalid from"),d(Nh,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=wt(t,s.containerId,{colIndex:e,rowIndex:0}),a=wt(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 $h=w("table-select-columns");function qE(n,t,e,o,r){d($h,Ht(t),"is not a table block");const i=et.fromBlock(t);d($h,e>=0&&e<i.rowCount,"invalid from"),d($h,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=wt(t,s.containerId,{rowIndex:e,colIndex:0}),a=wt(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 hz="",V5=w("get-toolbar-reference-client");function WE(n,t){const e=n.selection.range;if(!e.isSimple()){d(V5,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);d(V5,at(n,s),"not a complex block");const l=bt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const o=e.isReverse()?t.start:t.end,r=Wt(n,{anchor:o,focus:o}),i=Ho(n,t.block,r);if(i.length!==0)return i[0]}function GE(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 Lc(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=Za.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=Lc(r),GE(s))}),e}function Mc(n){return n.getCustom("toolbar-handler")}const fz="";class ZE{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(T.t("link.urlPlaceholder")),new Error(T.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 ms(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=uh(o,{label:T.t("link.textLabel"),required:!1,placeholder:T.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=uh(o,{className:"link-popup-gap",label:T.t("link.urlLabel"),required:!0,placeholder:T.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,T.t("link.cancelText"));const i=b("button",["submit-button"],r,T.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 Rc(n,t){n.addCustom("link-editor",()=>new ZE).editLink(t)}const YE=w("link-popup");function QE(n){return nt(n,"link")}function Ac(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function KE(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&_e(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(Ri(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&&j(n,t)&&QE(e)?[{id:"link-text",name:Ac(e),disableTooltip:!0,element:b("span",["link-href-button"],null,Ac(e))},{id:"edit-link",name:"Edit",icon:ah},{id:"remove-link",name:"Remove link",icon:Vw}]:fg(n,t,"hovering-toolbar")}function JE(n,t,e){var c;const o=so(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=Ac(e);Rc(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,u)=>{try{const f=n.getBlockText(t),m=Hd(f,o.start,o.end-o.start),C=Sr(m,o.start,a,{link:u});n.setBlockText(t,C),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){YE.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function XE(n,t,e){const o=so(t,e),r=n.getBlockText(t),i=Ac(e),s=Dr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function tI(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&_e(e)){const u=e,f=(l=(s=n.editorBoxes.getBoxClass(Ri(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=Mc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?JE(n,t,e):o.id==="remove-link"&&XE(n,t,e);return}const r=hg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function Oc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const eI=[Xu,th,eh,nh,oh,rh,ih,sh];class nI{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Oc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if(j(t,e)){const r=q(e),i=rt(e),s=Qe(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:T.t("commands.heading",{name:`${f+1}`}),icon:eI[f],states:c===f+1?["checked"]:[],value:`${f+1}`});const u=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||Cc,m;return m.innerHTML=Cc,m};return[{id:"turn-into",name:T.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:u,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:T.t("commands.text"),icon:Cc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(j(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}}function _c(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function oI(n,t){let e;const o=_c(t);if(!o)e=1;else{if(o>=12)return e=12,!1;e=o+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function q5(n,t){const e=_c(t);if(!e)return!1;const o=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...o,padding:e-1}),!0):(n.updateBlockData(t,{...o,padding:null}),!0)}function Ph(n){return n.readonly||!n.isWritable()}function rI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;j(n,o)&&oI(n,o)}),!0}function iI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;j(n,o)&&q5(n,o)}),!0}function sI(n){return Ph(n)?!1:n.undoManager.runInGroup(()=>(rI(n),!0))}function lI(n){return Ph(n)?!1:n.undoManager.runInGroup(()=>(iI(n),!0))}function cI(n){if(Ph(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!j(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!_c(t)))return q5(n,t),!0}class aI{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const mz="",dI={Tab:sI,"Shift+Tab":lI,Backspace:cI},Nc=w("list-block");function ct(n){return rt(n)==="list"}function Ft(n){d(Nc,ct(n),"not a list block")}function Fe(n){Ft(n);const t=n.getAttribute("data-list-type");return d(Nc,t,"no list type"),t}function $c(n){return ct(n)&&Fe(n)==="text-only"}function un(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function me(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Yr(n){Ft(n);const t=n.getAttribute("data-list-group-id");return d(Nc,t,"no group id"),t}function vo(n){var i,s,l,c,a;Ft(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(Nc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function jh(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 Zn(n){Ft(n);const{level:t,groupId:e,type:o}=vo(n);let r=gt(n);for(;r;){if(!ct(r))return null;const{level:i,groupId:s,type:l}=vo(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 rr(n){Ft(n);const{level:t,groupId:e,type:o}=vo(n);let r=dt(n);for(;r;){if(ct(r)){const{level:i,groupId:s,type:l}=vo(r);if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;if(i<t)return null}r=dt(r)}return null}function W5(n){Ft(n);const t=[];let e=Zn(n);for(;e;)t.unshift(e),e=Zn(e);return t}function Is(n){Ft(n);const t=[];let e=rr(n);for(;e;)t.push(e),e=rr(e);return t}function xs(n){Ft(n);let t=Zn(n);for(;t;){const e=Zn(t);if(!e)return t;t=e}return n}function uI(n){Ft(n);let t=rr(n);for(;t;){const e=rr(t);if(!e)return t;t=e}return null}function G5(n,t){const e=W5(n),o=Is(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function Ts(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 Hh(n,t,e,o){const r=G5(t,{withSelf:!0});r.length!==0&&Ts(n,r,e,o)}function hI(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 fI="abcdefghijklmnopqrstuvwxyz";function Z5(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=fI[t];return e?Z5(e)+o:o}function mI(n){return`${n}`}const Y5=[mI,Z5,hI];function gI(n,t){const e=Y5[(n-1)%Y5.length];return e(t)}function pI(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class ir{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=xs(e),i=un(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||Hh(this.editor,this.listBrother,this.listStart,this.options)}}function CI(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 ct(o)?o:null}o=gt(o)}return null}function bI(n,t){const e=n.getAttribute("data-style-heading"),o=CI(n,e);if(o)return o;const r=gt(n);if(r&&ct(r)&&Fe(r)===t)return r;const i=dt(n);return i&&ct(i)&&Fe(i)===t?i:null}function vI(n,t,e){var y,S,I,M;const o=(y=e.data)!=null?y:{};let r=1;if(ct(t))r=me(t);else{const R=_c(t);R&&(r=R+1),r>8&&(r=8)}const i=(S=o.listType)!=null?S:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(I=s.text)!=null?I:[];const c=n.selection.range.focus;if(!c.isSimple())return null;let u=vt(l);const f=(M=e.offset)!=null?M:c.offset;f<=de(l)&&(l=be(l,f).right,u=u.substring(0,f));let m=1;i==="ordered"&&(m=Number.parseInt(u,10)||1);let C=N();const v=bI(t,i);if(v){if(J(t)>J(v))m=un(v)+1;else{const R=un(v);R>1&&(m=R-1)}C=Yr(v)}const B={id:N(),type:"list",level:r,start:m,groupId:C,ordered:!1,text:l};return s.quoted&&(B.quoted=!0),s.heading&&(B.heading=s.heading),i==="ordered"?B.ordered=!0:(i==="checked"||i==="unchecked")&&(B.checkbox=i),{blockData:B,onConverted:(R,$)=>{new ir(R,$).fix()}}}function Qr(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function kI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${gI(t,(o=n.start)!=null?o:1)}.`:pI(t)}function Pc(n){return n==="checked"||n==="unchecked"}function Q5(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===0)return!0;const l=e.blocks[i][s-1];if(l.type!=="list")return!0;const c=Qr(r),a=Qr(l);return c!==a&&(!Pc(c)||!Pc(a))||r.level>l.level}function K5(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===e.blocks[i].length-1)return!0;const l=e.blocks[i][s+1];if(l.type!=="list")return!0;const c=Qr(r),a=Qr(l);return c!==a&&(!Pc(c)||!Pc(a))||r.level>l.level}function yI(n,t,e,o,r){var s,l,c;const i=t;if(o==="text"){let a=((s=ve.convertTo)==null?void 0:s.call(ve,n,t,e,"text",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,a}if(o==="markdown"){let a=((l=ve.convertTo)==null?void 0:l.call(ve,n,t,e,"markdown",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,Q5(n,t,e,r)&&(a=`${a}`),K5(n,t,e,r)&&(a=`${a}`,u<=1&&(a+=`
|
|
337
|
+
</svg>`;function gB(n,t){var e;if(A(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 r=b("div",["menu-item-icon"],null);n.icon&&(r.innerHTML=n.icon),t.appendChild(r)}const o=b("div",["menu-item-name","text"],null,n.name);if(t.appendChild(o),n.subText&&b("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const r=b("div",["menu-item-sub-indicator"],null);r.innerHTML=J2,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=Yw,t.appendChild(r)}}}}class tr extends gc{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){A(t,"menu")}initItemElement(t,e){gB(t,e)}}function pB(n,t,e){var o;return new tr((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class ps extends gc{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){A(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),this.options.tooltipId&&t.name&&!t.disableTooltip&&(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=Ju}t.states&&(t.states.indexOf("checked")!==-1&&A(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function CB(n,t,e){var o;return new ps((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const lz="";Hr.registerManualCommandBar("menu",pB),Hr.registerManualCommandBar("toolbar",CB);const cz="",l5=w("ui-base");class bc extends gc{constructor(e,o){super(bc.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){A(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];d(l5,e,"no dialog item");const o=e.element;return d(l5,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 bB=[-1,6,0,1,2,3,4,5],vB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],c5=w("color-palette");function a5(n,t,e,o){d(c5,n>0,"no color in palette");const r=t||1;d(c5,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 kB(n){const t=b("button",["color-button"],null),e=bB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=K2,t}function yB(n){const t=b("button",["background-color-button"],null),e=vB[n];return t.setAttribute("data-color-index",`${e}`),t}function wB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=T.t("colorPalette.reset"),n}function BB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.colorDesc")),t.appendChild(a5(8,1,kB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.backgroundDesc")),t.appendChild(a5(16,2,yB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(wB()),t}function EB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&z(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&A(i,"selected")}const az="",IB={};class xB extends Yt.TypedEmitter{constructor(e=IB){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(nt(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)||(nt(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=BB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){EB(this.root,e,o)}}class d5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new xB(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function TB(){const n=b("button",["color-button"],null);return n.innerHTML=K2,n}function dh(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 SB extends Yt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name",T.t("colorPalette.name"));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],dh(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new d5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=TB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,dh(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,dh(this.element,this.latestColors)}}const dz="";function uh(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&A(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&A(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),z(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{A(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function hh(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 DB=w("ui-base");class LB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{hh(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new tr([],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(!It(this.editor.rootContainer,r)||W(this.editor,r)<o)return;const i=Ho(this.editor,r,At(this.editor,r,o));if(i.length===0)return;const s=i[0],l=zo(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:T.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 qe.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.replace(/^\s+|\s+$/g,""))}finally{qe.release(e)}}highlightText(t){DB.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){let f=i.substring(u,u+c);if(f.toLocaleLowerCase()===a){u+=c;const m=i.charAt(u);let C=!1;f.endsWith(" ")&&(C=!0,f=f.trimEnd()),l+=`<span class="highlight">${f}${m===" "||C?" ":""}</span>`}else l+=i.charAt(u),u++}return u<i.length&&(l+=i.substring(u)),l},r=i=>{if(nt(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 fh=w("auto-suggest-menu");class mh{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(vt(be(ue(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=vt(Ul(t,i,r));if(d(fh,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 LB(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)||rd(e.key)?!1:km(e)&&!Oo(e)?(setTimeout(()=>{this.resetItems()}),!1):id(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:q(t),offset:e,leftText:o,trigger:r};const i=U(H(t)),s=J(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var u;const s=t.selection.range.start;if(!s.isSimple()||e==="root"&&o===0)return!1;const{blockId:l,offset:c}=s,a=t.getBlockByIndex(e,o);if(q(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=vt(Ul(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 q(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=vt(Ul(t,i,r));if(d(fh,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);fh.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()}}function MB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const RB={"insert-hr":{shortcut:"/hr"},"insert-uml":{shortcut:"/uml"},"insert-table":{shortcut:"/table"},"insert-image":{shortcut:"/image"},"insert-code":{shortcut:"/code"},"insert-link":{shortcut:"/link"},"insert-drawio":{shortcut:"/uml"},"insert-video":{shortcut:"/video"},"insert-audio":{shortcut:"/audio"},"insert-math":{shortcut:"/math"},"insert-webPage":{shortcut:"/web"},"insert-bilibili":{shortcut:"/bilibili"},"insert-youku":{shortcut:"/youku"},"insert-figma":{shortcut:"/figma"},"insert-modao":{shortcut:"/modao"},"insert-tencent":{shortcut:"/tencent"},"insert-unordered":{shortcut:"/bl"},"insert-ordered":{shortcut:"/nu"},"insert-checkbox":{shortcut:"/todo"},"insert-quote":{shortcut:"/quote"},...MB()};function fe(n){var t;return(t=RB[n])==null?void 0:t.shortcut}function AB(n){var t;return(t=n.subText)!=null?t:""}const In=w("table-dom");function Co(n){return`${q(n)}_scroll`}function jt(n){const t=n.querySelector("div[data-type=table-content] >table");return d(In,t instanceof HTMLTableElement,"invalid table"),t}function xn(n,t){const o=n.getCustom(Co(t)).contentElement.firstElementChild;d(In,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(In,r,"no table tools"),r}function u5(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function Cs(n){const t=n.querySelector(":scope div[data-type=editor-container]");return d(In,t,"no child container in cell"),t}function OB(n){const o=u5(n).map(r=>{const i=Cs(r),s=U(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Ei.default(o)}function Ht(n){return rt(n)==="table"}function gh(n){const t=H(n);if(pt(t))return null;const e=F(t);return d(In,e,"no parent block"),Ht(e)?t:gh(e)}function Me(n){if(Ht(n))return n;const t=H(n);if(pt(t))return null;const e=F(t);return d(In,e,"no parent block"),Ht(e)?e:Me(e)}function _B(n,t){const e=n.querySelector("colgroup");d(In,e,"no colgroup");const o=e.children[t];return d(In,o,"no col"),d(In,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function h5(n){try{return jt(n),!0}catch{return!1}}function NB(n){return Rt(n).querySelector(":scope > .block-helper")}function f5(n){const t=F(n.contentElement);d(In,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 Re=w("doc-table-grid");class $B{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(Re,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){d(Re,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return d(Re,e,"get cell, no cell"),e}getCellAllowEmpty(t){return d(Re,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 vc{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 $B(this.colCount));this.fillGrid(),d(Re,t.colsWidth,"no colsWidth"),d(Re,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(Re,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(Re,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{d(Re,i,"no cell"),d(Re,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];d(Re,r,`get cell, no row: ${o}`);const i=r.getCell(e);return d(Re,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return d(Re,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const kc=w("table-data");function PB(n){const t=n.firstElementChild;return d(kc,t,"no child element for cell"),d(kc,bn(t),"cell first child is not a container"),d(kc,Ye(t),"cell first child is not a container"),t}function jB(n){const t=F(n);d(kc,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=PB(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:q(t),type:rt(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function er(n){return new vc(n)}function HB(n){return er(jB(n))}const Zt=w("table-grid"),FB=60;class zB{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(Zt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);d(Zt,t.length===1,"containers !== 1"),d(Zt,bn(t[0]),"not a container");const e=t[0];return d(Zt,Ye(e),"not a child container"),e}}class UB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new zB(t,o))})}get cells(){return this._cells}getCell(t){return d(Zt,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 Ef=class{constructor(t){h(this,"_rows",[]);this.table=t,HB(t).forEach(r=>{this._rows.push(new UB(t,r))});const o=this.colCount;this._rows.forEach(r=>{d(Zt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(d(Zt,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(Zt,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(Zt,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(Zt,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(Zt,!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(Zt,o<=r,"min > max"),d(Zt,o>=0,"min < 0"),d(Zt,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(Zt,o<=r,"min > max"),d(Zt,o>=0,"min < 0"),d(Zt,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(Zt,o,"cell not found"),o}getCellByCellElement(t){const e=Cs(t);return this.getCellByContainerId(U(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=OB(t),o=this.caches.getSync(e,()=>(Zt.debug("create table grid"),new Ef(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let et=Ef;h(et,"caches",new Xf(FB));function yc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const VB=w("table-selection-range");function an(n,t,e){var I,M,R,$;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=(I=c==null?void 0:c.rowIndex)!=null?I:s.row,f=(M=c==null?void 0:c.colIndex)!=null?M:s.col,m=(R=a==null?void 0:a.rowIndex)!=null?R:l.row+l.rowSpan-1,C=($=a==null?void 0:a.colIndex)!=null?$:l.col+l.colSpan-1,v=Math.min(u,m),B=Math.max(u,m),y=Math.min(f,C),S=Math.max(f,C);return{fromRow:v,toRow:B,fromCol:y,toCol:S}}function ph(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===q(t)){const i=et.fromBlock(t),{start:s,end:l}=r;d(VB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(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 Fr=w("delete-columns");function m5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{fromRow:s,toRow:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.rowCount-1}function Ch(n){var M;const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!m5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=an(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(R=>R.containerId);for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<=r;Z++){const ot=$[Z];s.add(ot)}$.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(R=>!c.has(R))),u=r-o+1,f=new Map,m=new Map;s.forEach(R=>{if(a.has(R))return;const $=i.getCellByContainerId(R);if(d(Fr,$.colSpan>1,"invalid effected cell, colSpan === 1"),$.col<o){d(Fr,c.has(R),"invalid effected cell, not exists");let yt=$.col+$.colSpan-1;yt>r&&(yt=r);const se=yt-o+1,eo=$.colSpan-se;f.set(R,eo);return}d(Fr,$.col<=r,"invalid effected cell, col > endCol");const Z=$.col,ot=$.col+$.colSpan-1,st=$.col-o,mt=ot-Z+1-u+st;d(Fr,mt>0,"invalid effected cell, newSpanned <= 0");const ut=yn(t.doc);m.set(R,{newContainerId:ut,colSpan:mt})});for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<$.length;Z++){const ot=$[Z],st=m.get(ot);st&&($[Z]=st.newContainerId)}}const C=Y.default(t.getBlockData(e));C.colsWidth.splice(o,r-o+1),a.forEach(R=>{yc(C,R)}),f.forEach((R,$)=>{d(Fr,R>=1,"invalid modified colSpan, colSpan < 1"),R===1?C[`${$}_colSpan`]=void 0:C[`${$}_colSpan`]=R}),m.forEach((R,$)=>{yc(C,$);const{newContainerId:Z,colSpan:ot}=R;d(Fr,ot>=1,"invalid newContainerData, colSpan < 1"),ot>1&&(C[`${Z}_colSpan`]=ot);const st=i.getCellByContainerId($).rowSpan;st>1&&(C[`${Z}_rowSpan`]=st)});const B=(M=l[0][o])!=null?M:l[0][o-1],y=t.getChildContainerData(B)[0],S=et.virtualCellContainersGridToChildren(l),I={...C,cols:C.cols-u,children:S};er(I),t.undoManager.runInGroup(()=>{t.updateBlockData(e,I,At(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const zr=w("delete-rows");function g5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{fromCol:s,toCol:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.colCount-1}function bh(n){const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!g5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=an(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(I=>I.containerId);for(let I=r;I>=o;I--)l[I].forEach(R=>s.add(R)),l.splice(I,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(I=>!c.has(I))),u=r-o+1,f=new Map,m=new Map;s.forEach(I=>{if(a.has(I))return;const M=i.getCellByContainerId(I);if(d(zr,M.rowSpan>1,"invalid effected cell, rowSpan === 1"),M.row<o){d(zr,c.has(I),"invalid effected cell, not exists");let mt=M.row+M.rowSpan-1;mt>r&&(mt=r);const ut=mt-o+1,yt=M.rowSpan-ut;f.set(I,yt);return}d(zr,M.row<=r,"invalid effected cell, col > endCol");const R=M.row,$=M.row+M.rowSpan-1,Z=M.row-o,ot=$-R+1-u+Z;d(zr,ot>0,"invalid effected cell, newSpanned <= 0");const st=yn(t.doc);m.set(I,{newContainerId:st,rowSpan:ot})});for(let I=o;I<l.length;I++){const M=l[I];for(let R=0;R<M.length;R++){const $=M[R],Z=m.get($);Z&&(M[R]=Z.newContainerId)}}const C=Y.default(t.getBlockData(e));a.forEach(I=>{yc(C,I)}),f.forEach((I,M)=>{d(zr,I>=1,"invalid modified rowSpan, rowSpan < 1"),I===1?delete C[`${M}_rowSpan`]:C[`${M}_rowSpan`]=I}),m.forEach((I,M)=>{yc(C,M);const{newContainerId:R,rowSpan:$}=I;d(zr,$>=1,"invalid newContainerData, rowSpan < 1"),$>1&&(C[`${R}_rowSpan`]=$);const Z=i.getCellByContainerId(M).colSpan;Z>1&&(C[`${R}_colSpan`]=Z)});const v=l[o]?l[o][0]:l[o-1][0],B=t.getChildContainerData(v)[0],y=et.virtualCellContainersGridToChildren(l),S={...C,rows:C.rows-u,children:y};er(S),t.undoManager.runInGroup(()=>{t.updateBlockData(e,S,At(t,B.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const bs=w("table-range");function wc(n){d(bs,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;d(bs,!t.isSimple(),"invalid start pos type"),d(bs,!e.isSimple(),"invalid end pos type");const o=n.getEditor();d(bs,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);d(bs,rt(r)==="table","invalid block type, not a table block");const i=jt(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 vh=w("split-cell");function kh(n,t,e){const o=et.fromBlock(t),r=o.getRealCell(e);d(vh,!r.virtual,"should not split virtual cell"),d(vh,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,B=yn(n.doc);i[C][v]=B}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(vh,a,"no child block");const u=At(n,a.id,0);er(l),n.updateBlockData(t,l,u)}function qB(n,t,e){e.forEach(o=>{const r=et.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&kh(n,t,o)})}function p5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{startCell:s,endCell:l}=wc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function yh(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=wc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return qB(t,e,l),!0}const Ur=w("merge-cells");function C5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||rt(t)!=="table")return!1;const{startCell:s,endCell:l}=wc(e);return s.cell!==l.cell}function b5(n){const t=wc(n),e=t.endCell,o=e.row+e.rowSpan-1,r=e.col+e.colSpan-1,i=q(t.block),s=t.editor;yh(n);const l=s.getBlockById(i),c=jt(l),{startRow:a,startCol:u}=t,f=Y.default(s.getBlockData(l));d(Ur,f.children,"no table children");const m=et.fromTable(c),C=[];for(let mt=a;mt<=o;mt++)for(let ut=u;ut<=r;ut++){const yt=m.getCell({row:mt,col:ut});d(Ur,!yt.virtual,"cell is virtual"),C.push(yt)}d(Ur,C.length>0,"no selected cells");const v=C[0],B=C.slice(1),y=m.getCellByContainerId(v.containerId).container,S=[];B.forEach(mt=>{const ut=m.getCellByContainerId(mt.containerId).container,yt=U(ut);if(!Bd(s,ut)){const se=R0(s,yt);s.insertDocAt(y,Ge(y),se)}S.push(yt)});const I=U(y),M=r-u+1,R=o-a+1;f[`${I}_colSpan`]=M,f[`${I}_rowSpan`]=R,S.forEach(mt=>{d(Ur,f.children,"no table children");const ut=f.children.indexOf(mt);d(Ur,ut>0,"no deleted container"),f.children.splice(ut,1)});const $=f,ot=s.getChildContainerData(I)[0];d(Ur,ot,"no child block");const st=At(s,ot.id,0);er($),s.updateBlockData(l,$,st),s.deleteChildContainers(S)}const wh=10,WB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Bh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(rt(e)!=="table")return[];const r={blockId:q(e),blockKind:Qe(t,e),blockType:rt(e)},i=[];C5(t,e,o)&&i.push({id:"table/merge-cells",name:T.t("table.mergeCell"),icon:Aw,groupIndex:wh,...r}),p5(t,e,o)&&i.push({id:"table/split-cell",name:T.t("table.splitCell"),icon:Ow,groupIndex:wh,...r});const s=m5(t,e,o),l=g5(t,e,o);return s&&l&&i.push({id:"table/delete",name:T.t("table.deleteTable"),icon:_w,groupIndex:wh,...r}),i}executeCommand(t,e,o,r,i,s){return rt(e)!=="table"||!new Set(WB).has(r.id)?!1:r.id==="table/merge-cells"?(b5(o),!0):r.id==="table/split-cell"?(yh(o),!0):r.id==="table/delete-columns"?(Ch(o),!0):r.id==="table/delete-rows"?(bh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var v5=(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))(v5||{});const Eh=6,vs=20;function GB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function ZB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function YB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function QB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function KB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function JB(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function XB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const Ih=w("get-selected-containers");function xh(n,t,e,o){d(Ih,e.blockId===o.blockId,"only allow select in single table block"),d(Ih,q(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(y=>r.getCellContainer(y));const{fromCol:l,toCol:c,fromRow:a,toRow:u}=an(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:u,col:c}).forEach(v=>{v.forEach(B=>{const y=r.getCellByContainerId(B.containerId);y.col<l||y.row<a||y.col+y.colSpan-1>c||y.row+y.rowSpan-1>u||f.has(B.containerId)||(f.add(B.containerId),m.push(y.container))})}),m}function tE(n,t,e){d(Ih,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return xh(n,o,t,e)}const nr=w("table-cell-dom");function eE(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");d(nr,r,"no parent cell");const i=F(r);if(d(nr,i,"no parent block"),i===t)return r;o=i}return d(nr,!1,"filed to get cell by child block id"),null}function Gn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return d(nr,e.childContainerId,"block position must have childContainerId attribute"),e;const r=eE(n,t,e.blockId),i=U(Cs(r));return wt(t,i)}function Th(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return an(t,o,r)}function k5(n,t,e,o){d(nr,Ht(t),"invalid table block");const r=xn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");d(nr,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)?A(a,"danger"):z(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");d(nr,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)?A(a,"danger"):z(a,"danger")})};i(),s()}function Vr(n,t,e=!0,o){const i=et.fromBlock(t).map(u=>u),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Th(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||A(C.cell,"danger"):C.virtual||z(C.cell,"danger")}}}function qr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){k5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Th(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);k5(n,t,Array.from(r),Array.from(i))}function y5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Th(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}),Wt(n,{anchor:wt(t,c.containerId,{colIndex:o,rowIndex:0}),focus:wt(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}),Wt(n,{anchor:wt(t,c.containerId,{colIndex:0,rowIndex:i}),focus:wt(t,a.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function nE(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return xh(n,t,o,r)}const w5=["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 B5(n){return`style-bg-color-${n}`}function ks(n){return`${n}_background`}function oE(n,t,e){const o=jt(n),s=(e!=null?e:et.fromTable(o)).getCell(t).cell;for(let l=0;l<w5.length;l++){const c=w5[l];if(nt(s,c))return c}}function E5(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Y.default(n.getBlockData(t))},s=Gn(n,t,o.start),l=Gn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[ks(c)]=void 0:i[ks(c)]=B5(e)}else{const c=et.fromBlock(t),a=an(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[ks(C.containerId)]=void 0:i[ks(C.containerId)]=B5(e))}}n.updateBlockData(t,i)}function rE(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const I5=w("table-chart");function iE(n,t){const e=xn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function sE(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){iE(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 B=1;B<i.colCount;B++)c.push(i.getCell({row:0,col:B}).container.innerText);for(let B=1;B<i.rowCount;B++){const y=i.getCell({row:B,col:0}),I=y.container.innerText,M=[];for(let se=1;se<i.colCount;se++){const eo=i.getCell({row:B,col:se}).container.innerText,ee=Number.parseFloat(eo)||0;M.push(ee)}let R;const $=oE(t,y,i);$?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${$}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[Z,ot,st,mt]=R?Wa.fromString(R).toRgbaArray():[];if(!Z&&!ot&&!st&&!mt){const se=(B-1)%n.options.colors.length;R=n.options.colors[se],[Z,ot,st,mt]=Wa.fromString(R).toRgbaArray()}const ut=R,yt=Wa.fromRgba([Z,ot,st,mt/3]).toHexString();r.push({label:I,data:M,borderColor:ut,backgroundColor:yt,borderWidth:2})}const a=xn(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(I5,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 Ro(v,"editor-chartjs"),u&&l!==u.config.type&&(u.destroy(),u=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(S=>{S.remove()}));const B=Ga.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(u)Ga.default(u.config,B),u.update();else{const S=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");u=new window.Chart(S,B),f.chartObject=u}}catch(B){I5.error(`failed to resolve chart cdn: ${JSON.stringify(B)}`)}}async function x5(n,t){await qe.lock("updateTableChart");try{await sE(n,t)}finally{qe.release("updateTableChart")}}const T5=Xt.default(x5,1e3);let S5=null;function Sh(n,t,e){if(S5!==t&&(T5.flush(),S5=t),e.updateNow){x5(n,t);return}T5(n,t)}function Dh(n,t){Ht(t)&&Sh(n,t,{updateNow:!1})}function lE(n,t){Ht(t)&&Sh(n,t,{updateNow:!0})}const je={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"},Bc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},bo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Ec(n,t){return n.containers.get(t)}function D5(n){return n.closest(`.${bo.SCROLL_CONTAINER}`)}function dn(n){return n.firstElementChild}function Ae(n){return n.closest(`.${bo.CONTAINER}`)}function ys(n){const t=Ae(n);let e=t.querySelector(`:scope >.${bo.TOOL}`);return e||(e=b("div",[bo.TOOL],t)),e}function cE(n){return Ae(n).firstElementChild}function Ic(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}function He(n,t){const e=Ic(n);return t/e}function ws(n){const t=window.getComputedStyle(n),e=Ic(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Wr(n){const t=Ic(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function aE(n,t){const e=Ic(n);return n[t]*e}function Lh(n,t){const e=Ae(t),o=Ec(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 dE(n,t){const e=Lh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${He(t,0-o)}px`,t.style.paddingLeft=`${He(t,o)}px`}function uE(n,t){const e=Lh(n,t);t.style.marginRight=`${He(t,0-e.maxRight)}px`}function hE(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 L5=w("scroll-bar-handle"),fE=2;function Gr(n){const t=ys(n);let e=t.querySelector(`.${Bc.SCROLL_BAR}`);return e||(e=b("div",[Bc.SCROLL_BAR],t)),d(L5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function xc(n,t){const e=D5(t),o=Gr(e),{scrollWidth:r,clientWidth:i}=Wr(e),{paddingLeft:s,paddingRight:l}=ws(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const c=Lh(n,e),{originWidth:a,maxRight:u}=c;uE(n,e),dE(n,e);const f=r-i;d(L5,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${He(e,a+u-s-l)}px`,o.firstElementChild.style.width=`${He(e,a+u+f-s-l)}px`}function mE(n,t){const e=dn(n),{paddingLeft:o}=ws(e);if(nt(t,"fixed")){const i=Ae(n).getBoundingClientRect();t.style.left=`${He(n,i.left+o)}px`}else t.style.left=`${He(n,o)}px`}function Zr(n,t){var I;const e=n.getParentScrollContainer(),o=hE(e),r=t.getBoundingClientRect(),i=Gr(t),s=i.getBoundingClientRect(),l=Ec(n,Ae(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=dn(t),{paddingTop:u,paddingBottom:f}=ws(a),{scrollWidth:m,clientWidth:C}=Wr(t),v=document.documentElement.clientHeight-c,B=o.top+Wr(e).clientHeight-v,y=v+Math.min(0,B);if(m>C&&r.top+u<y-s.height&&r.bottom>y-s.height+f&&!((I=l==null?void 0:l.isSetScale)!=null&&I.call(l))){A(i,Bc.FIXED);const M=B>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+fE+M}px`}else z(i,Bc.FIXED),i.style.bottom=`${He(t,f-s.height)}px`;mE(t,i)}class gE{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;Zr(this.scrollCore,e);const o=dn(e);xc(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 or=w("container-scroll-shadow");function M5(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=ws(e);o.style.top=`${He(t,i.top-r.top+s)}px`,o.style.bottom=`${He(t,r.bottom-i.bottom+l)}px`}function R5(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function pE(n){const t=ys(n);d(or,t,"no container tools");let e=t.querySelector(`.${je.LEFT}`);if(!e){const l=dn(n),c=[je.COMMON,je.LEFT];e=b("div",c,t),d(or,e instanceof HTMLDivElement,"invalid child for container tools"),M5(e,n,l)}d(or,e instanceof HTMLElement,"invalid child for container tools");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${He(n,i.left-r.left)}px`;const s=Wr(n).scrollLeft;d(or,e instanceof HTMLDivElement,"invalid child for container tools"),R5(e,s),A(e,je.ACTIVE)}function CE(n){const t=ys(n);let e=t.querySelector(`.${je.RIGHT}`);if(!e){const u=dn(n),f=[je.COMMON,je.RIGHT];e=b("div",f,t),d(or,e instanceof HTMLDivElement,"no div, create shadow failed"),M5(e,n,u)}d(or,e instanceof HTMLElement,"");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${He(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Wr(n),a=s-l-c;d(or,e instanceof HTMLDivElement,"no shadow element"),R5(e,a),A(e,je.ACTIVE)}function bE(n){const e=ys(n).querySelector(`.${je.LEFT}`);e&&z(e,je.ACTIVE)}function vE(n){const e=ys(n).querySelector(`.${je.RIGHT}`);e&&z(e,je.ACTIVE)}function Bs(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Wr(n),r=dn(n),{paddingLeft:i,paddingRight:s}=ws(r),l=aE(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?vE(n):CE(n),r&&t>=l+i?pE(n):bE(n)}class kE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=dn(e);Bs(e),xc(this.scrollCore,o),Zr(this.scrollCore,e),this.callback(e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,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 A5=w("container-scroll-observer");class yE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;d(A5,e instanceof Element,"invalid target for scroll event");const o=Gr(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),Bs(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;d(A5,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=cE(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),Bs(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",Xt.default(this.bindContentScrollCore,300));h(this,"bind",Xt.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=Gr(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 wE{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Zr(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 BE=w("scroll-wrap-resize-observer");class EE{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;d(BE,e instanceof HTMLElement,"invalid target for observer entry");const o=D5(e);xc(this.scrollCore,e),Bs(o),Zr(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 IE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=dn(e);Bs(e),xc(this.scrollCore,o),Zr(this.scrollCore,e),this.callback(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.callback=e,this.resizeObserver=new ResizeObserver(this.handleResize)}bind(t){var r,i;const e=Ae(t),o=(r=Ec(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=Ae(t),o=(i=Ec(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 uz="";class xE extends Yt.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,"handleResize",e=>{this.emit("resize",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=dn(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=>{Zr(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new kE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new yE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new wE(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new EE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new IE(this,this.handleResize)),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=Gr(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=Gr(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 gE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=dn(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 O5=w("scroll-container"),Tc=new Map;class TE extends Yt.TypedEmitter{constructor(){super(...arguments);h(this,"scrollListener");h(this,"options");h(this,"scrollContainerElement");h(this,"init",e=>{this.options=e;const o=b("div",[bo.CONTAINER],e.parentElement);xt.isMac&&A(o,bo.MAC);const r=b("div",[bo.SCROLL_CONTAINER],o),i=b("div",[bo.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=Tc.get(s),this.scrollListener||(this.scrollListener=new xE(s),Tc.set(s,this.scrollListener)),this.scrollListener.unbind(o),this.scrollListener.bind(o,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollListener.on("resize",this.handleResize),this.scrollContainerElement=r});h(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)});h(this,"handleResize",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return d(O5,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),dn(this.scrollContainerElement)}get scrollOptions(){return d(O5,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=Ae(this.contentElement);e&&Tc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),Tc.delete(i))})}}function SE(){return new TE}const Sc=100,DE=40,Mh=w("column-width");function LE(n,t,e){_B(n,t).style.width=`${e}px`}function ME(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)}),Mh.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)}Mh.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 Mh.debug(`widths: ${s.join()}`),s}function Es(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const RE=w("table-resize-gripper"),_5=7,Rh=(_5-1)/2,AE=3;function OE(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)<=Rh&&a.top<=e&&e<=a.bottom)return c}}return null}function _E(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Ah(n,t){return xn(n,t).querySelector(".table-resize-gripper")}function N5(n,t){const e=Ah(n,t);d(RE,!e,"resize gripper has already exists");const o=xn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function $5(n,t,e){let o=Ah(n,t);o||(o=N5(n,t));const i=jt(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(Co(t)).contentElement.getBoundingClientRect(),u=s.right-a.left;o.style.left=`${u-Rh-Eh-vs}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${_5}px`}function Oh(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 $E(n,t,e,o){const r=t,i=et.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=Es(e);let a=o;const u=(m,C)=>{const v=C+1,B=m.col+m.colSpan;return c.slice(v,B).reduce((S,I)=>S+I,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,B=v.getBoundingClientRect();let y=o-B.left+Rh-AE;const S=Cs(v),I=wd(n,S)||DE*C.colSpan,M=u(C,l),R=I-M;y<R&&(y=R);const $=B.left+y;a=Math.max(a,$)}return a}const PE=w("table-resize-drag-drop");class jE{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=$E(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;d(PE,c,"no dragging cell");const m=et.fromTable(s).getCellByCellElement(c),C=m.col+m.colSpan-1,B=Es(s).slice(0,C).reduce((S,I)=>S+I,0),y=u-B;LE(s,C,y),$5(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=Es(t.data.table);NE(this.editor,t.data.block,s),Oh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function HE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=F(e);return!o||!n.contains(o)||!Ht(o)?null:o}w("table-resize");class FE{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=HE(t,i);if(!s||!h5(s)){Oh(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=jt(t),i=OE(r,e,o);if(i){if(!Ah(this.editor,t)){if(_E(this.editor))return;const l=N5(this.editor,t),c={block:t,table:r,draggingRefCell:i};ed(new jE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}$5(this.editor,t,i)}else Oh(this.editor)}}function P5(n){n.addCustom("table-mouse-event-handler",t=>new FE(t))}const j5=w("table-insert-column");function H5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.colCount;d(j5,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],B=C[e];if(e===0||e===C.length||v!==B){const y=yn(n.doc);C.splice(e,0,y)}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(j5,typeof v=="number"&&v>1,`no colSpan for containerId ${m}, ${v}`),c[C]=v+1});const a=c.colsWidth.concat();a.splice(e,0,Sc);const u=et.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:u,colsWidth:a};er(f),n.updateBlockData(t,f)}const Dc=w("table-insert-row");function F5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.rowCount;d(Dc,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(Dc,C||v,"no top and bottom cell"),e===0||e===r.rowCount||C!==v){const B=yn(n.doc);c.push(B)}else d(Dc,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(Dc,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};er(f),n.updateBlockData(t,f)}const _h=w("paste-table-in-table-block");function zE(n,t,e,o){let r=et.fromBlock(e);const i=t.blocks.root[0];d(_h,i,"no table data"),d(_h,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 B=u;B<m&&B<r.colCount;B++)for(let y=f;y<C&&y<r.rowCount;y++){const S=r.getCell({col:B,row:y});S.virtual?S.virtual&&v.push({col:B,row:y}):(S.colSpan>1||S.rowSpan>1)&&v.push({col:B,row:y})}n.undoManager.runInGroup(()=>{if(v.forEach(I=>{const M=et.fromBlock(e).getCell(I);(M.colSpan>1||M.rowSpan>1)&&kh(n,e,I)}),m>r.colCount)for(let I=r.colCount;I<m;I++)H5(n,e,I);if(C>r.rowCount)for(let I=r.rowCount;I<C;I++)F5(n,e,I);r=et.fromBlock(e);const B=new vc(s);let y;for(let I=0;I<B.colCount;I++)for(let M=0;M<B.rowCount;M++){const R=B.getCell({col:I,row:M});if(!R.virtual){const $=hu(n.editorBlocks,t,R.containerId),Z=u+I,ot=f+M,st={col:Z,row:ot},mt=r.getCellContainer(st);Hp(n,mt,$),y=mt}}d(_h,y,"no last container");const S=Qt(y);n.selection.selectBlock(S,W(n,S))})}const z5=w("paste-in-table-block");class UE{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=H(r);if(pt(i)||!Bd(t,i))return!1;const s=F(i);if(d(z5,s,"no parent block"),!Ht(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;z5.debug("paste child table in table");const a=et.fromBlock(s).getCellByContainerId(U(i)).cell;return zE(t,e,s,a),!0}}function U5(n){n.addCustom("table-block-paste-event",t=>new UE(t))}const Nh=w("table-select-columns");function VE(n,t,e,o,r){d(Nh,Ht(t),"is not a table block");const i=et.fromBlock(t);d(Nh,e>=0&&e<i.colCount,"invalid from"),d(Nh,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=wt(t,s.containerId,{colIndex:e,rowIndex:0}),a=wt(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 $h=w("table-select-columns");function qE(n,t,e,o,r){d($h,Ht(t),"is not a table block");const i=et.fromBlock(t);d($h,e>=0&&e<i.rowCount,"invalid from"),d($h,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=wt(t,s.containerId,{rowIndex:e,colIndex:0}),a=wt(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 hz="",V5=w("get-toolbar-reference-client");function WE(n,t){const e=n.selection.range;if(!e.isSimple()){d(V5,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);d(V5,at(n,s),"not a complex block");const l=bt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const o=e.isReverse()?t.start:t.end,r=Wt(n,{anchor:o,focus:o}),i=Ho(n,t.block,r);if(i.length!==0)return i[0]}function GE(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 Lc(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=Za.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=Lc(r),GE(s))}),e}function Mc(n){return n.getCustom("toolbar-handler")}const fz="";class ZE{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(T.t("link.urlPlaceholder")),new Error(T.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 ms(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=uh(o,{label:T.t("link.textLabel"),required:!1,placeholder:T.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=uh(o,{className:"link-popup-gap",label:T.t("link.urlLabel"),required:!0,placeholder:T.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,T.t("link.cancelText"));const i=b("button",["submit-button"],r,T.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 Rc(n,t){n.addCustom("link-editor",()=>new ZE).editLink(t)}const YE=w("link-popup");function QE(n){return nt(n,"link")}function Ac(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function KE(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&_e(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(Ri(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&&j(n,t)&&QE(e)?[{id:"link-text",name:Ac(e),disableTooltip:!0,element:b("span",["link-href-button"],null,Ac(e))},{id:"edit-link",name:"Edit",icon:ah},{id:"remove-link",name:"Remove link",icon:Vw}]:fg(n,t,"hovering-toolbar")}function JE(n,t,e){var c;const o=so(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=Ac(e);Rc(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,u)=>{try{const f=n.getBlockText(t),m=Hd(f,o.start,o.end-o.start),C=Sr(m,o.start,a,{link:u});n.setBlockText(t,C),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){YE.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function XE(n,t,e){const o=so(t,e),r=n.getBlockText(t),i=Ac(e),s=Dr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function tI(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&_e(e)){const u=e,f=(l=(s=n.editorBoxes.getBoxClass(Ri(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=Mc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?JE(n,t,e):o.id==="remove-link"&&XE(n,t,e);return}const r=hg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function Oc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const eI=[Xu,th,eh,nh,oh,rh,ih,sh];class nI{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Oc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if(j(t,e)){const r=q(e),i=rt(e),s=Qe(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:T.t("commands.heading",{name:`${f+1}`}),icon:eI[f],states:c===f+1?["checked"]:[],value:`${f+1}`});const u=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||Cc,m;return m.innerHTML=Cc,m};return[{id:"turn-into",name:T.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:u,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:T.t("commands.text"),icon:Cc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(j(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}}function _c(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function oI(n,t){let e;const o=_c(t);if(!o)e=1;else{if(o>=12)return e=12,!1;e=o+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function q5(n,t){const e=_c(t);if(!e)return!1;const o=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...o,padding:e-1}),!0):(n.updateBlockData(t,{...o,padding:null}),!0)}function Ph(n){return n.readonly||!n.isWritable()}function rI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;j(n,o)&&oI(n,o)}),!0}function iI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;j(n,o)&&q5(n,o)}),!0}function sI(n){return Ph(n)?!1:n.undoManager.runInGroup(()=>(rI(n),!0))}function lI(n){return Ph(n)?!1:n.undoManager.runInGroup(()=>(iI(n),!0))}function cI(n){if(Ph(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!j(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!_c(t)))return q5(n,t),!0}class aI{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const mz="",dI={Tab:sI,"Shift+Tab":lI,Backspace:cI},Nc=w("list-block");function ct(n){return rt(n)==="list"}function Ft(n){d(Nc,ct(n),"not a list block")}function Fe(n){Ft(n);const t=n.getAttribute("data-list-type");return d(Nc,t,"no list type"),t}function $c(n){return ct(n)&&Fe(n)==="text-only"}function un(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function me(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Yr(n){Ft(n);const t=n.getAttribute("data-list-group-id");return d(Nc,t,"no group id"),t}function vo(n){var i,s,l,c,a;Ft(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(Nc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function jh(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 Zn(n){Ft(n);const{level:t,groupId:e,type:o}=vo(n);let r=gt(n);for(;r;){if(!ct(r))return null;const{level:i,groupId:s,type:l}=vo(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 rr(n){Ft(n);const{level:t,groupId:e,type:o}=vo(n);let r=dt(n);for(;r;){if(ct(r)){const{level:i,groupId:s,type:l}=vo(r);if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;if(i<t)return null}r=dt(r)}return null}function W5(n){Ft(n);const t=[];let e=Zn(n);for(;e;)t.unshift(e),e=Zn(e);return t}function Is(n){Ft(n);const t=[];let e=rr(n);for(;e;)t.push(e),e=rr(e);return t}function xs(n){Ft(n);let t=Zn(n);for(;t;){const e=Zn(t);if(!e)return t;t=e}return n}function uI(n){Ft(n);let t=rr(n);for(;t;){const e=rr(t);if(!e)return t;t=e}return null}function G5(n,t){const e=W5(n),o=Is(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function Ts(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 Hh(n,t,e,o){const r=G5(t,{withSelf:!0});r.length!==0&&Ts(n,r,e,o)}function hI(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 fI="abcdefghijklmnopqrstuvwxyz";function Z5(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=fI[t];return e?Z5(e)+o:o}function mI(n){return`${n}`}const Y5=[mI,Z5,hI];function gI(n,t){const e=Y5[(n-1)%Y5.length];return e(t)}function pI(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class ir{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=xs(e),i=un(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||Hh(this.editor,this.listBrother,this.listStart,this.options)}}function CI(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 ct(o)?o:null}o=gt(o)}return null}function bI(n,t){const e=n.getAttribute("data-style-heading"),o=CI(n,e);if(o)return o;const r=gt(n);if(r&&ct(r)&&Fe(r)===t)return r;const i=dt(n);return i&&ct(i)&&Fe(i)===t?i:null}function vI(n,t,e){var y,S,I,M;const o=(y=e.data)!=null?y:{};let r=1;if(ct(t))r=me(t);else{const R=_c(t);R&&(r=R+1),r>8&&(r=8)}const i=(S=o.listType)!=null?S:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(I=s.text)!=null?I:[];const c=n.selection.range.focus;if(!c.isSimple())return null;let u=vt(l);const f=(M=e.offset)!=null?M:c.offset;f<=de(l)&&(l=be(l,f).right,u=u.substring(0,f));let m=1;i==="ordered"&&(m=Number.parseInt(u,10)||1);let C=N();const v=bI(t,i);if(v){if(J(t)>J(v))m=un(v)+1;else{const R=un(v);R>1&&(m=R-1)}C=Yr(v)}const B={id:N(),type:"list",level:r,start:m,groupId:C,ordered:!1,text:l};return s.quoted&&(B.quoted=!0),s.heading&&(B.heading=s.heading),i==="ordered"?B.ordered=!0:(i==="checked"||i==="unchecked")&&(B.checkbox=i),{blockData:B,onConverted:(R,$)=>{new ir(R,$).fix()}}}function Qr(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function kI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${gI(t,(o=n.start)!=null?o:1)}.`:pI(t)}function Pc(n){return n==="checked"||n==="unchecked"}function Q5(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===0)return!0;const l=e.blocks[i][s-1];if(l.type!=="list")return!0;const c=Qr(r),a=Qr(l);return c!==a&&(!Pc(c)||!Pc(a))||r.level>l.level}function K5(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===e.blocks[i].length-1)return!0;const l=e.blocks[i][s+1];if(l.type!=="list")return!0;const c=Qr(r),a=Qr(l);return c!==a&&(!Pc(c)||!Pc(a))||r.level>l.level}function yI(n,t,e,o,r){var s,l,c;const i=t;if(o==="text"){let a=((s=ve.convertTo)==null?void 0:s.call(ve,n,t,e,"text",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,a}if(o==="markdown"){let a=((l=ve.convertTo)==null?void 0:l.call(ve,n,t,e,"markdown",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,Q5(n,t,e,r)&&(a=`${a}`),K5(n,t,e,r)&&(a=`${a}`,u<=1&&(a+=`
|
|
338
338
|
`)),a}if(o==="html"){let a=((c=ve.convertTo)==null?void 0:c.call(ve,n,t,e,"html",r))||"";a=a.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?a=`<input type="checkbox" checked="checked" disabled="disabled" /> ${a}`:i.checkbox==="unchecked"&&(a=`<input type="checkbox" disabled="disabled" /> ${a}`);let u="ul";return i.ordered?(a=`<li value="${i.start}">${a}</li>`,u="ol"):a=`<li>${a}</li>`,Q5(n,t,e,r)&&(a=`<${u}>${a}`),K5(n,t,e,r)&&(a=`${a}</${u}>`),a}return""}const wI=8,Ot=w("list-block");class jc{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,$c(e))return;const o=xs(e),r=un(o);this.listStart=r,o===e?this.listBrother=rr(o):this.listBrother=o}fix(){!this.listBrother||Hh(this.editor,this.listBrother,this.listStart)}}function BI(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function Fh(n,t,e,o){if(Ot.debug("drag a block on a list block"),!j(n,t))return!1;d(Ot,ct(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=vo(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,...jh(r)};BI(n,e,u);let f=J(e);const m=H(e);o==="after"&&(f+=1);let C=null;ct(t)&&(C=new jc(n,t));const v=n.insertBlock(U(m),f,u,Fl(u.id,0));return n.deleteBlock(t),new ir(n,v).fix(),C==null||C.fix(),!0}function EI(n,t,e,o){if(Ot.debug("drag a list between text blocks"),o==="after"){const a=dt(e);if(a&&ct(a))return Fh(n,t,a,"before")}if(o==="before"){const a=gt(e);if(a&&ct(a))return Fh(n,t,a,"after")}const i={...n.getBlockData(t),groupId:N(),start:1,level:1};let s=J(e);const l=H(e);o==="after"&&(s+=1),n.insertBlock(U(l),s,i,Fl(i.id,0));const c=new jc(n,t);return n.deleteBlock(t),c.fix(),!0}function II(n,t,e,o,r){if(kl(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);d(Ot,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=r;return!l&&c?(d(Ot,t===c,"block !== target block"),d(Ot,ct(c),"target is not a list block"),Fh(n,s,c,o)):EI(n,s,c,o)}const xI=`<?xml version="1.0" ?>
|
|
339
339
|
<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">
|
|
340
340
|
<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>
|
|
@@ -364,7 +364,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
364
364
|
</svg>
|
|
365
365
|
`;function yx(n){return go("list-to-mindmap",T.t("mindmap.viewAsMindMap"),kx,[],n.clientId)}const gz="";class Hc{constructor(t){h(this,"toMindmapButton");h(this,"currentBlock",null);h(this,"handleHoveringBlock",t=>{!this.editor.isWritable()||(t&&ct(t)&&Fe(t)!=="unchecked"&&Fe(t)!=="checked"?Rt(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove())});h(this,"handleMouseEnter",()=>{const t=F(this.toMindmapButton);d(Ot,t&&ct(t),"no parent list"),qh(this.editor,t,!0),this.currentBlock=t});h(this,"handleMouseLeave",()=>{this.currentBlock&&(qh(this.editor,this.currentBlock,!1),this.currentBlock=null)});h(this,"handleClick",()=>{const t=F(this.toMindmapButton);d(Ot,t&&ct(t),"no parent list"),Wh(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:o4})});this.editor=t,Nt.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=yx(t),t.domEvents.addEventListener(this.toMindmapButton,"mouseenter",this.handleMouseEnter),t.domEvents.addEventListener(this.toMindmapButton,"mouseleave",this.handleMouseLeave),t.domEvents.addEventListener(this.toMindmapButton,"click",this.handleClick)}static get(t){return t.findCustomByType(Hc)}destroy(){Nt.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}const wx={list:{confirm:"\u786E\u5B9A",setStart:"\u8BBE\u7F6E\u7F16\u53F7",continueList:"\u7EE7\u7EED\u7F16\u53F7",restartList:"\u5F00\u59CB\u65B0\u5217\u8868",changeNumber:"\u4FEE\u6539\u7F16\u53F7\u503C",numberLabel:"\u7F16\u53F7\u987A\u5E8F",mention:{tooltip:"\u63D0\u53CA\u4EBA\u5458\u5E76\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u663E\u793A\u4E3A\u8111\u56FE",autoFit:"\u81EA\u52A8\u7F29\u653E",fullScreen:"\u5168\u5C4F\u67E5\u770B",close:"\u5173\u95ED",exitFullscreen:"\u9000\u51FA\u5168\u5C4F"}},Bx={list:{confirm:"OK",setStart:"Set the number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"@Mention someone"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto fit",fullScreen:"Fullscreen",close:"Close",exitFullscreen:"Exit fullscreen"}};T.mergeLang({"zh-CN":wx,"en-US":Bx});const pz="";function Ex(n,t,e){var o;t==="beginDrag"&&((o=Hc.get(n))==null||o.hide())}const u4={...ve,blockType:"list",createBlockContent:vx,convertFrom:vI,convertTo:yI,handleDrop:II,notify:Ex},Yh=w("paragraph");class Ix{constructor(t){h(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){const o=[],r={"unordered-list":[T.t("commands.unordered"),xt.isMac?T.t("commandDesc.mac.unordered"):T.t("commandDesc.window.unordered"),$w],"ordered-list":[T.t("commands.ordered"),xt.isMac?T.t("commandDesc.mac.ordered"):T.t("commandDesc.window.ordered"),Nw],"check-list":[T.t("commands.check"),void 0,Pw],link:[T.t("commands.link"),xt.isMac?T.t("commandDesc.mac.link"):T.t("commandDesc.window.link"),n5],quoted:[T.t("commands.quote"),void 0,jw]};if(j(t,e)){const i=q(e),s=rt(e),l=Qe(t,e),c=t.getBlockData(e);Object.entries(r).forEach(([a,[u,f,m]])=>{const C=[];if(this.isChecked(c,a)&&C.push("checked"),a==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&C.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:a,name:u,desc:f,states:C,icon:m,groupIndex:600})})}return o}convertLink(t,e,o){d(Yh,Ir(e.start),""),d(Yh,Ir(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(C,v)=>{t.undoManager.runInGroup(()=>{try{let B=$l(t.getBlockText(o),i,s,C);B=_l(i,C.length,B,"link",v),t.setBlockText(o,B),t.selection.selectBlock(o,i+C.length),t.focus()}catch(B){Yh.error(B)}})},c=()=>{t.focus()},a=Ho(t,o,e)[0];if(!a)return;const u=zo(t,o,"link-button-anchor",a),f=t.getBlockText(o),m=Nl(f,i);Rc(t,{target:u,linkText:t.getSelectedText(),linkUrl:(m==null?void 0:m.link)||"",onFinished:l,onClose:c,placement:r})}convertToList(t,e,o){const r=Oi(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=J(e),s=H(e);t.deleteBlock(e),t.insertBlock(U(s),i,r.blockData)})}executeCommand(t,e,o,r){var c;if(!j(t,e))return!1;const i=r.id,s=(c=r.states)==null?void 0:c.includes("checked");let l=!1;if(i==="unordered-list"&&(s?Jr(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?Jr(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?Jr(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const u=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:u?void 0:!0}),l=!0}if(i==="link"){const a=Mc(t);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const xx={left:gs,right:lh,center:ch};class Tx{constructor(t){h(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(xx).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(j(t,e)){const r=q(e),i=rt(e),s=Qe(t,e),l=t.getBlockData(e),c=a=>{var f;const u=b("span",["toolbar-item-name-container"],null);for(const m of a.children)if((f=m.states)!=null&&f.includes("checked"))return u.innerHTML=m.icon||gs,u;return u.innerHTML=gs,u};return[{id:"align",name:T.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:c,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:T.t("commands.alignLeft"),icon:gs,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:T.t("commands.alignCenter"),icon:ch,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:T.t("commands.alignRight"),icon:lh,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),!0}return!1}}function Sx(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const o=n.getBlockById(e.start.blockId);return Ui(n,o,e.start.offset).charType==="box"}const Dx=w("toolbar-handler"),Lx={id:"",name:"",type:"separator"};class Xr{constructor(t){h(this,"toolbar");h(this,"toolbarType","object");h(this,"mouseDown",!1);h(this,"oldRange",null);h(this,"hoveringBlock",null);h(this,"hoveringTextChild",null);h(this,"_disableTextToolbar",!1);h(this,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&tI(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});h(this,"handleClose",()=>{hh(this.editor)&&this.editor.focus()});h(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});h(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});h(this,"handleHoveringBlockChildChange",(t,e,o,r)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close();return}this.showObjectToolbar()}});h(this,"handleSelectionChange",Xt.default(t=>{if(d(Dx,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){this.toolbar.close(),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close(),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new ps([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),Nt.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Nt.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new nI(t)),t.editorCommandProviders.registerCommandProvider(new Ix(t)),t.editorCommandProviders.registerCommandProvider(new Tx(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close()}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),Nt.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&It(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){if(this._disableTextToolbar||!this.editor.isWritable())return;const o=this.editor.selection.range.getSelectedBlocks();if(o.length===0)return;const r=o[0];if(!r)return;if(o.length===1&&Te(r.block)){t==="click"&&this.showObjectToolbar();return}if(Sx(this.editor))return;const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(u=>{const f=u.groupIndex,m=s.get(f);m?m.push(u):s.set(f,[u])});const l=[[]],c=Array.from(s.entries()).sort((u,f)=>u[0]-f[0]);for(let u=0;u<c.length;u++){const[,f]=c[u];if(f.length===0)continue;let m=l[l.length-1];m.length>0&&m[m.length-1].groupIndex!==f[f.length-1].groupIndex&&(m=[],l.push(m)),m.push(...Lc(f))}if(l.length===0){this.toolbar.close();return}this.toolbarType="text";const a=[];if(l.forEach((u,f)=>{const m=u.sort((C,v)=>{var B,y;return((B=C.order)!=null?B:0)-((y=v.order)!=null?y:0)});a.push(...m),f!==l.length-1&&a.push(Lx)}),a.length===0){this.toolbar.close();return}if(this.toolbar.updateItems(a),!this.toolbar.isVisible){const u=o[o.length-1],f=!this.editor.selection.range.isReverse()&&u!==r,m=f?u:r,C=WE(this.editor,m),v=zo(this.editor,m.block,"editor-quick-menu",C);this.toolbar.manualShow(v,{placement:f?"bottom":"top"})}}showObjectToolbar(){var r,i;if(!this.hoveringBlock)return;const t=this.hoveringBlock,e=this.hoveringTextChild,o=KE(this.editor,t,e);if(!o.length){this.toolbar.close();return}this.toolbarType="object",this.toolbar.isVisible&&((i=(r=this.toolbar)==null?void 0:r.tippyInstance)==null?void 0:i.reference)!==t&&this.toolbar.close(),this.toolbar.updateItems(o),this.toolbar.isVisible||this.toolbar.manualShow(e||it(t),{placement:e?"bottom":"top"})}static register(t){return t.addCustom("toolbar-handler",e=>new Xr(e))}static get(t){return t.getCustom("toolbar-handler")}}const Mx=[Xu,th,eh,nh,oh,rh,ih,sh],Rx={Unordered:i5,Ordered:s5,Checkbox:o5,Quote:r5};function Qh(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>Qh(o,t))}function Ax(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function Kh(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=Oc();e<=4?e=5:e<8&&(e+=1);let o=n;for(;o<=e;){const i=`heading-${o}`;(r=t.insertBlockCommandItems)==null||r.push({id:i,icon:Mx[o-1],name:T.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:fe(i)}),o++}return t}function Ox(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,o)=>{var i;const r=`insert-${e.toLocaleLowerCase()}`;(i=n.insertBlockCommandItems)==null||i.push({id:r,name:T.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:Rx[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:fe(r)})}),n}class h4{getCommands(){const t=Kh(),e=Ox();return[...t.insertBlockCommandItems||[],...e.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;if(s.startsWith("heading-"))Ax(t,o,Number.parseInt(i!=null?i:"1",10)||1);else if(i==="ordered"||i==="unordered"||i==="checkbox"){if(!t.selection.range.focus.isSimple())return null;const c=Oi(t,o,"list",{offset:0,data:{listType:i==="checkbox"?"unchecked":i}});if(c){const a=t.getBlockIndex(o);t.deleteBlock(o),t.insertBlock(e,a,c.blockData)}}else i==="quote"&&t.updateBlockData(o,{quoted:!0});return null}async handleUpdateBlockCore(t,e){const o=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,o,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:o,blockIndex:r}=e,i=t.insertTextBlock(void 0,o,r);return this.updateBlock(t,e.containerId,i,e.item)}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=U(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else o.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex}));return null}}class Jh{constructor(){h(this,"dataUrl","");h(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const _x=w("mathjax-converter"),Nx="MathJax-script";async function $x(n){var o;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((o=t==null?void 0:t.cdn)==null?void 0:o.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await Ro(e,Nx)}function Px(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function f4(n,t){const e="mathjax2Svg";try{await qe.lock(e),Px(),await $x(n);const o=await window.MathJax.tex2svgPromise(t),r=o.querySelector("merror");if(r)throw new Error(r.textContent);return o.querySelector("svg").outerHTML}catch(o){throw _x.error(o),o}finally{qe.release(e)}}async function m4(n,t){const e=await f4(n,t);return e?await Bm(e,"image/svg+xml"):""}async function Xh(n,t){const o=await f4(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const g4=w("edit-mathjax");class jx{constructor(){h(this,"editMathjaxPopup",null);h(this,"onChange",null);h(this,"tex","");h(this,"handleShow",()=>{setTimeout(()=>{this.getTextarea().focus()})});h(this,"handleClose",t=>{var o;const e=t.content.querySelector("textarea");if(e){const r=e.value;r!==this.tex&&((o=this.onChange)==null||o.call(this,r))}});h(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close()),this.handleChange(t.target.value))});h(this,"handleChange",Xt.default(t=>{var e;(e=this.onChange)==null||e.call(this,t)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new ms(this.createPopupContent(e));else{const r=this.getTextarea();r.value=e}this.tex=e,this.editMathjaxPopup.addListener("show",this.handleShow),this.editMathjaxPopup.manualShow(t,{theme:"light"}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=o}createPopupContent(t){const e=b("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),e}getTextarea(){d(g4,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return d(g4,t,"no textarea"),t}destroy(){var t;this.onChange=null,(t=this.editMathjaxPopup)==null||t.removeAllListeners()}}function p4(n,t,e,o){n.addCustom("mathjax-editor",()=>new jx).editMathjax(t,e.trim(),o)}function Hx(){return{insert:" ",attributes:{id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function t1(n,t){const e=n.getBoxData(t),o=F(t);if(!o)return;const r=so(o,t);n.selection.selectBlock(o,r.start,r.end);const i=async s=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await qe.lock("convertAndUploadMathjax");const l=await Xh(n,s);n.updateBoxData({...e,tex:s,src:l})}catch(l){const c=n.getBoxData(t);n.addCustom(`mathjax-box-${c.id}`,()=>new Jh).setError(l),n.updateBoxData({...e,tex:s,src:""})}finally{qe.release("convertAndUploadMathjax")}};p4(n,t,e.tex,i)}const Fx=w("mathjax-box");function e1(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,e1)}async function zx(n,t,e){try{if(!t.tex.trim())return;const o=await m4(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=gd(r);i.innerHTML="";const s=b("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",e1)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");A(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function Ux(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new Jh);if(r.src||i.dataUrl){const c=b("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(c,"load",e1);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=T.t("mathjax.emptyText"),b("span",s,e,l),zx(n,r,i)}function Vx(n,t){const e={id:N(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return Xh(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{Fx.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function qx(n,t,e,o){const r=t;return o==="text"?r.tex:o==="markdown"?` $${r.tex}$ `:r.src?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:`<code>$${r.tex}$</code>`}function Wx(n,t,e){t1(n,t)}const Fc={boxType:"math",updateBoxContent:Ux,convertFrom:Vx,convertTo:qx,handleClickBox:Wx};async function Gx(n,t,e){try{const o=t.embedData,r=await m4(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=it(i);s.innerHTML="";const l=b("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function Zx(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=F(t.target);if(!e||!Te(e)||Oe(e)!=="math")return;const o=it(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!It(r,t.target))return;const s=n.getBlockData(e).embedData;p4(n,r,s.mathjaxText,async l=>{const c=await Xh(n,l),a={mathjaxText:l,src:c};n.updateEmbedData(e,a)})}function Yx(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new Jh);if(n.domEvents.addEventListener(t,"click",Zx),o.src||r.dataUrl){const i=b("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,b("span",["mathjax-tex-text"],t,o.mathjaxText),Gx(n,e,r)}function Qx(n,t,e){if(!j(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=nd(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:N(),type:"embed",embedType:"math",embedData:i}}}function Kx(n){return{name:"Mathjax"}}function Jx(n,t){const e=it(t);n.domEvents.removeAllListeners(e)}function Xx(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
|
|
366
366
|
$$${r.mathjaxText}$$
|
|
367
|
-
`:r.mathjaxText}const n1={embedType:"math",createEmbedContent:Yx,getOptions:Kx,convertFrom:Qx,handleDeleteBlock:Jx,convertTo:Xx},Cz="",tT={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},eT={mathjax:{emptyText:"Empty Tex",abstract:"TeX"}};T.mergeLang({"zh-CN":tT,"en-US":eT});function nT(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o);if(!vt(s).endsWith("$$$$"))return!1;const c=o-4,a=o,u={id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c),n.insertBoxToBlock(r,c,u),setTimeout(()=>{const f=n.getBoxById(u.id);t1(n,f)})}),!0}class oT{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&nT(t,e,o,r))}}const C4=w("inline-box-items");function rT(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);Tt(n,o)||(o=n.insertTextBlock([],t,e));const r=Hx();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return d(C4,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);t1(n,l)},100),o})}function iT(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return Tt(n,o)||(r="top-start"),Rc(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{Tt(n,o)||(o=n.insertTextBlock([],t,e));const a=$e(l,{link:c}),u=$e(" ",null),f=[a,u];n.insertTextToBlock(o,0,f),n.selection.selectBlock(o,de(f)),n.focus()}catch(a){C4.error(a)}})},onClose:()=>{n.focus()},placement:r}),o}async function sT(n,t){switch(t.item.id){case"insert-math":return rT(n,t.containerId,t.blockIndex);case"insert-link":return iT(n,t.containerId,t.blockIndex);default:return null}}function lT(){return{name:"text",insertBlockCommandItems:[{id:"insert-math",name:T.t("quickMenu.inlineBox.math"),icon:qw,order:900,group:"common",subText:fe("insert-math")},{id:"insert-link",name:T.t("quickMenu.inlineBox.link"),icon:n5,order:400,group:"common",subText:fe("insert-link")}],handleInsertEmptyBlock:sT}}const cT={basics:100,system:200,common:300,thirdParty:400};function aT(n){var o,r;const t=(r=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:r.commandProviders;if(!t)return[];const e=[];return[...t,new h4].forEach(i=>{const s=i.getCommands(n);e.push(...s.map(l=>({...l,itemType:"insert-block",commandProvider:i})))}),e}function dT(n){const t=[];n.editorBlocks.forEach(o=>{if(!o.getOptions)return;const r=o.getOptions(n);!r.insertBlockCommandItems||(r.insertBlockCommandItems.forEach(i=>{Qh(i,r)}),t.push(...r.insertBlockCommandItems))});const e=lT();return e.insertBlockCommandItems.forEach(o=>{Qh(o,e)}),t.push(...e.insertBlockCommandItems),t.push(...aT(n)),t}function o1(n){const t=dT(n),e=new Map;t.forEach(i=>{var c;const s=(c=i.group)!=null?c:"";let l=e.get(s);l?l.items.push(i):(l={group:s,order:i.groupOrder||cT[s]||1e3,items:[i]},e.set(s,l))});const o=Array.from(e.values());o.sort((i,s)=>i.order-s.order),o.forEach(i=>{i.items.sort((s,l)=>{var c,a;return((c=s.order)!=null?c:0)-((a=l.order)!=null?a:0)})});const r=[];return o.forEach((i,s)=>{const l=T.t(`blockMenu.section.${i.group||"common"}`),c=l===i.group?i.group:l;r.push({id:`section-${s}`,name:c,type:"section",group:i.group,itemType:"insert-block"}),r.push(...i.items.map(a=>({...a})))}),r}function uT(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=U(r);let l=n.getBlockIndex(o);if(Tt(n,o)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:i,blockIndex:l,item:t})}const b4=w("quick-menu"),hT={id:"quick-menu",trigger:["/"]};class zc{constructor(t,e=hT){h(this,"suggest");h(this,"items");h(this,"maxHeading");h(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const o=new Set,r=e.toLocaleLowerCase();return this.items.filter(i=>{var s;return i.type==="section"?!0:i.name.toLocaleLowerCase().indexOf(r)!==-1||AB(i).toLocaleLowerCase().indexOf(r)!==-1||i.group&&((s=i.group)==null?void 0:s.toLocaleLowerCase().indexOf(r))!==-1?(o.add(i.group),!0):!1}).filter(i=>i.type==="section"?o.has(i.group):!0)}return this.items});h(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!Ko(i)){const s=F(H(i));if(s&&rt(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(d(b4,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),d(b4,this.suggest.anchor,"invalid suggest, no anchor"),uT(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=Oc(),this.suggest=new mh(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=o1(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=Oc();if(o!==this.maxHeading){const r=new h4,s=r.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:r}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=o}}}class r1{constructor(t){h(this,"instance");h(this,"mousedown",!1);h(this,"currentInstance",null);h(this,"attributeName","");h(this,"attributeDesc","");h(this,"observer",null);h(this,"observerCallback",null);h(this,"createContent",t=>{var i;const e=(i=t.getAttribute(this.attributeName))!=null?i:"",o=t.getAttribute(this.attributeDesc);if(!o)return e;const r=b("div",[],null);return b("span",[],r,e),o&&b("span",["editor-tooltip-desc"],r,o),r});h(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});h(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});h(this,"handleShow",t=>{var r;const e=t.reference;if(!e||!It(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);return!(o&&Date.now()-o<1e3)});this.editor=t;const e=t.clientId;this.attributeName=`data-editor-tooltip-${e}`,this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=qa.delegate(document.body,{delay:200,target:`[${this.attributeName}]`,content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Xt.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,o={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,o)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}}const fT={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-subscript":"subscript","text/style-superscript":"superscript"};function mT(n,t){const e=new Set(Object.keys(fT)),o=t.filter(i=>e.has(i.id));return Lc(o)}function Uc(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=mT(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),Xr.get(n).update("selectionChange"),!0):!1}const i1={"CtrlOrCmd+B":n=>Uc(n,"style-bold"),"CtrlOrCmd+I":n=>Uc(n,"style-italic"),"CtrlOrCmd+U":n=>Uc(n,"style-underline"),"CtrlOrCmd+D":n=>Uc(n,"style-strikethrough")},gT={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u4E8B\u9879",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}},pT={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"Todo list",quote:"Quote"},inlineBox:{math:"Math",link:"Link"},link:{textLabel:"Text",urlLabel:"Link Address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter the link address",submitText:"Ok",cancelText:"Cancel"}},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"Todo list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Align center",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}};T.mergeLang({"zh-CN":gT,"en-US":pT});const bz="";function sr(n,...t){const e=go(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function v4(n){Mc(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function CT(n){return b("div",["insert-column-button","drop-marker"],n)}const k4=w("row-height");function y4(n){const t=et.fromTable(n),e=n.rows;d(k4,e.length===t.rowCount,"row count mismatch");const o=Array(t.rowCount).fill(0);for(let r=0;r<e.length;){let i=1,l=e[r].getBoundingClientRect().height,c=r+1;for(;c<e.length;){const a=e[c];if(a.cells.length!==0)break;i++,c++,l+=a.getBoundingClientRect().height}for(let a=0;a<i;a++)o[r+a]=l/i;r=c}return k4.debug("heights",o.join(", ")),o}const ko=w("table-border-bar-dom");function Ss(n,t){d(ko,Ht(t),"invalid table block");const e=jt(t),o=xn(n,t),r=(a,u,f)=>{const m=b("div",["button-root",u],a),C=b("div",["button-container",u],m);m.setAttribute(`data-${u}-index`,`${f}`),C.setAttribute(`data-editor-tooltip-${n.clientId}`,u==="left"?T.t("table.insertRow"):T.t("table.insertCol")),b("span",["insert-indicator"],C),CT(C)},{selectedRows:i,selectedColumns:s}=ph(n,t),l=()=>{const a=o.querySelector(".table-border-bar-container.top");d(ko,a,"no top border bar container");const u=b("div",["table-border-bar-container","top"],null),f=b("div",["table-border-bar","top"],u),m=ME(e);b("span",["table-border-bar-cell","corner"],f);const v=et.fromTable(e).colCount;n.selection.range.isSimple()&&r(f,"top",0);for(let B=0;B<v;B++){const y=B===v-1?m[B]+2:m[B],S=b("span",["table-border-bar-cell","top"],f);s.has(B)&&S.classList.add("selected"),S.setAttribute("data-top-index",`${B}`),S.style.width=`${y}px`,n.selection.range.isSimple()&&r(f,"top",B+1)}Mi(a,u)},c=()=>{const a=o.querySelector(".table-border-bar-container.left");d(ko,a,"no left border bar container");const u=b("div",["table-border-bar-container","left"],null),f=b("div",["table-border-bar","left"],u),m=y4(e);n.selection.range.isSimple()&&r(f,"left",0),Array.from(e.rows).forEach((C,v,B)=>{const y=b("span",["table-border-bar-cell","left"],f);i.has(v)&&y.classList.add("selected"),y.setAttribute("data-left-index",`${v}`);const S=v===B.length-1?m[v]+2:m[v];y.style.height=`${S}px`,n.selection.range.isSimple()&&r(f,"left",v+1)}),Mi(a,u)};l(),c()}function w4(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(ko,o&&Ht(o),"invalid table block"),Ss(n,o),n.selection.caret.update()}function s1(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(ko,o&&Ht(o),"invalid table block");const r=e.closest(".button-root");if(r){if(r.classList.contains("top")){const i=parseInt(r.getAttribute("data-top-index")||"0",10);H5(n,o,i),Ss(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);F5(n,o,i),Ss(n,o)}}}function l1(n,t){var s;v4(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var c;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const a=F(l.target),u=l.target.closest(".table-border-bar");if(a===e&&u){const f=parseInt((c=l.target.getAttribute(`data-${o}-index`))!=null?c:"0",10),m=Math.min(r,f),C=Math.abs(r-f)+1;nt(l.target,"top")&&o==="top"?VE(n,a,m,C,{reverse:!0}):nt(l.target,"left")&&o==="left"&&qE(n,a,m,C,{reverse:!0})}}l.type==="mouseup"&&(e=null,r=void 0,o=void 0,document.body.removeEventListener("mousemove",i),document.body.removeEventListener("mouseup",i))};t.target instanceof HTMLElement&&nt(t.target,"table-border-bar-cell")&&(e=F(t.target),nt(t.target,"top")?o="top":nt(t.target,"left")&&(o="left"),o&&e&&(r=parseInt((s=t.target.getAttribute(`data-${o}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",i),document.body.addEventListener("mouseup",i)))}function bT(n,t){d(ko,Ht(t),"invalid table block");const e=xn(n,t),o=b("div",["table-border-bar-container","top"],e),r=b("div",["table-border-bar-container","left"],e);Ss(n,t),n.domEvents.addEventListener(it(t),"scroll",w4),n.domEvents.addEventListener(o,"click",s1),n.domEvents.addEventListener(r,"click",s1),n.domEvents.addEventListener(o,"mousedown",l1),n.domEvents.addEventListener(r,"mousedown",l1)}function B4(n,t){if(!n.isWritable())return;if(xn(n,t).querySelector(".table-border-bar-container")){Ss(n,t);return}bT(n,t)}function E4(n,t){d(ko,Ht(t),"invalid table block"),xn(n,t).querySelectorAll(".table-border-bar-container").forEach(r=>{n.domEvents.removeEventListener(r,"click",s1),n.domEvents.removeEventListener(r,"mousedown",l1),r.remove()}),n.domEvents.removeEventListener(it(t),"scroll",w4)}function vT(n,t){d(ko,Ht(t),"invalid table block");const o=xn(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class kT{constructor(t,e){h(this,"toolbar");h(this,"handleSelectionChange",(t,e)=>{e==="delete-columns"?(Vr(this.editor,this.tableBlock,!0,!0),qr(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Vr(this.editor,this.tableBlock,!0,!1),qr(this.editor,this.tableBlock,!0,!1)):(Vr(this.editor,this.tableBlock,!1),qr(this.editor,this.tableBlock,!1))});h(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?Ch(this.editor.selection.range):e.id==="delete-rows"&&bh(this.editor.selection.range)});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ps([],void 0,{overflowBoundary:o==null?void 0:o.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick)}close(){this.toolbar.close()}update(){const{selectedColumns:t,selectedRows:e}=ph(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close();return}if(t.size===0&&e.size===0){this.toolbar.close();return}const o=Ho(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close();return}if(t.size>0){const r={id:"delete-columns",name:T.t("table.deleteCol"),icon:Rw};this.toolbar.updateItems([r]);const i=zo(this.editor,this.tableBlock,"editor-quick-menu",o);this.toolbar.manualShow(i,{placement:"top"})}else{const r={id:"delete-rows",name:T.t("table.deleteRow"),icon:Mw};this.toolbar.updateItems([r]);const i=new DOMRect(o.left-15,o.top,o.width,o.height),s=zo(this.editor,this.tableBlock,"editor-quick-menu",i);this.toolbar.manualShow(s,{placement:"left"})}}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const Vc=w("table-border-bar");class yT{constructor(t,e){h(this,"toolbar");h(this,"resizeObserver");h(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():E4(this.editor,this.tableBlock)});h(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(q(this.tableBlock));this.resizeObserver.observe(jt(t))})});h(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,d(Vc,this.tableBlock,"no table block"),Vc.debug("create table border bar"),B4(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(jt(this.tableBlock)),this.toolbar=new kT(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){Vc.debug("destroy table border bar"),this.resizeObserver.disconnect(),E4(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){Vc.debug("update table border bar"),B4(this.editor,this.tableBlock),this.toolbar.update()}}const wT=w("table-border-bar");class BT{constructor(t){h(this,"activeTableBar",null);h(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||It(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});h(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const i=t.getBlockById(e.start.blockId);if(Ht(i)){const s=H(i),l=F(s);l&&(o=Me(l))}else o=Me(i)}else{const i=t.getBlockById(e.start.blockId),s=Me(i),l=t.getBlockById(e.end.blockId),c=Me(l);s===c&&(o=s)}((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new yT(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(d(wT,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function I4(n,t){const e=n.addCustom("table-border-bar",o=>new BT(o));t==="update"&&e.update()}const Be=w("table-cell-menu"),ET="style-bg-color-";class IT{constructor(t){h(this,"activeTableBlock",null);h(this,"targetButton",null);h(this,"manualMenu",null);h(this,"colorPaletteItem",null);h(this,"handlePrevent",(t,e)=>{e.stopPropagation()});h(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId);if(Ht(r)){const i=H(r),s=F(i);s&&(o=Me(s))}else o=Me(r)}else{const r=t.getBlockById(e.start.blockId),i=Me(r),s=t.getBlockById(e.end.blockId),l=Me(s);i===l&&(o=i)}if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=et.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;e.isCollapsed()?s=this.getCellByChildBlockId(r,i.blockId):i instanceof Je&&(t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});h(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});h(this,"createBkgColorItem",()=>{const t=b("div",["cell-background-color-item"],null);b("span",[],t,T.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();b("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=b("span",["item-sub-indicator"],t);return r.innerHTML=J2,t});h(this,"handleCommand",t=>{var r;d(Be,this.activeTableBlock,"no target table block");const e=((r=t.states)==null?void 0:r.includes("checked"))||!1,o=t.value;switch(t.id){case"delete-select-row":bh(y5(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":Ch(y5(this.editor,this.activeTableBlock,!0));break;case"merge-cell":b5(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":XB(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":rE(this.editor,this.activeTableBlock,o==="show-chart"),Sh(this.editor,this.activeTableBlock,{updateNow:!0});break}});h(this,"handleSelectionChange",(t,e)=>{d(Be,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Vr(this.editor,this.activeTableBlock,!0,!1),qr(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Vr(this.editor,this.activeTableBlock,!0,!0),qr(this.editor,this.activeTableBlock,!0,!0)):(Vr(this.editor,this.activeTableBlock,!1),qr(this.editor,this.activeTableBlock,!1))});h(this,"handleClick",()=>{var t;d(Be,this.activeTableBlock,"no target table block"),d(Be,this.targetButton,"no target button"),v4(this.editor),nt(this.targetButton,"active")?(z(this.targetButton,"active"),(t=this.manualMenu)==null||t.close()):(A(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new tr(this.createCommandMenu()),this.manualMenu.on("click",(e,o)=>{var r;this.handleCommand(o),(r=this.manualMenu)==null||r.close()}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",()=>{this.targetButton&&z(this.targetButton,"active"),this.editor.focus()})),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"}))});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close(),this.targetButton&&(z(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");d(Be,r,"no parent cell");const i=F(r);if(d(Be,i,"no parent block"),jt(i)===t.table)return t.getCellByCellElement(r);o=i}return d(Be,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(":scope > .table-cell-menu-btn")||t.appendChild(this.targetButton):(this.targetButton=b("button",["table-cell-menu-btn"],t),this.targetButton.innerHTML=Ju,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),d(Be,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=et.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);kh(this.editor,this.activeTableBlock,{col:o,row:r})}else yh(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;d(Be,this.activeTableBlock,"no target table block");const t=nE(this.editor,this.activeTableBlock),e=this.editor.getBlockData(this.activeTableBlock),o=new Set;for(const i of t){if(o.size>1)break;const s=U(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(ET.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){d(Be,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=C5(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const u=Gn(this.editor,this.activeTableBlock,o.start);o=Wt(this.editor,{anchor:u,focus:u})}const r=p5(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,a=t.chart;return this.colorPaletteItem=new d5("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(u,f)=>{var m;switch(d(Be,this.activeTableBlock,"no target table block"),u){case"clearColor":E5(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":E5(this.editor,this.activeTableBlock,f);break}(m=this.manualMenu)==null||m.close()}),[{id:"cell-background-color",name:T.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:T.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:T.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:T.t("table.deleteSelectRow")},{id:"delete-select-col",name:T.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:T.t("table.tableConfigKey"),children:[{id:"row-title",name:T.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:T.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:T.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?T.t("table.tableConfig.showBorder"):T.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:a?T.t("table.tableConfig.hideChart"):T.t("table.tableConfig.showChart"),value:a?"hide-chart":"show-chart"}]}]}handleRowTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?QB(this.editor,this.activeTableBlock):YB(this.editor,this.activeTableBlock)}handleColTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?ZB(this.editor,this.activeTableBlock):GB(this.editor,this.activeTableBlock)}handleStripeStyle(t){d(Be,this.activeTableBlock,"no target table block"),t?JB(this.editor,this.activeTableBlock):KB(this.editor,this.activeTableBlock)}}function x4(n){n.addCustom("table-cell-menu",t=>new IT(t))}const qc=w("table-container");function c1(n){const t=n.closest("td");return d(qc,t,"no parent cell for a table cell container"),t}function T4(n){const t=jt(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function a1(n,t,e,o){const r=et.fromBlock(n),i=r.getCellByContainerId(U(t));if(e==="ArrowDown"){const s=r.getBottomCell(i);return s?s.container:null}if(e==="ArrowUp"){const s=r.getTopCell(i);return s?s.container:null}if(e==="ArrowLeft"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(qc,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(qc,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}d(qc,!1,`invalid navigation type: ${e}`)}const xT=12,TT=90,Wc=23,S4=2;class ST{constructor(t){h(this,"scrollTableBlock",null);h(this,"autoScrollDir",null);h(this,"autoScrollTimer",null);h(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const o=F(e);if(o&&It(this.editor.rootContainer,o)){const r=Me(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});h(this,"handleAutoScroll",b7.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Co(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),l=r.getBoundingClientRect(),c=Math.min(l.bottom,s),a=Math.max(l.top,0);i.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):i.top<a&&t.clientY<=a?this.setAutoScroll("top"):o.scrollLeft>0&&t.clientX<i.left?this.setAutoScroll("left"):o.scrollLeft<o.scrollWidth-o.offsetWidth&&t.clientX>i.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));h(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const o=t.getBlockById(e.start.blockId),r=Me(o);if(r){const i=t.getCustom(Co(r)),s=i.rootElement.getBoundingClientRect(),l=Ke(t,o,e.start);if(s.left>l.left){const c=e.start.offset===0?xT:S4;i.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?TT:S4;i.rootElement.scrollLeft+=l.right-s.right+c}}}else{const o=t.getBlockById(e.start.blockId),r=Me(o),i=t.getBlockById(e.end.blockId),s=Me(i);if(r&&r===s){const l=t.getCustom(Co(r)),c=l.rootElement.getBoundingClientRect();let a=null;if(e.isSimple())a=e.isReverse()?Ke(t,o,e.start):Ke(t,i,e.end);else{const u=c1(Br(t,e.start.childContainerId)),f=c1(Br(t,e.end.childContainerId));a=e.isReverse()?u.getBoundingClientRect():f.getBoundingClientRect()}c.left>a.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-a.left:c.right<a.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=a.right-c.right)}}});h(this,"handleScroll",t=>{f5(t),this.editor.selection.caret.update()});h(this,"handleReset",t=>{f5(t),this.editor.selection.caret.update()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Co(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),c=r.getBoundingClientRect(),a=Math.min(c.bottom,l),u=Math.max(c.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=Wc,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=Wc,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=Wc,(r.scrollTop>=r.scrollHeight-s||i.bottom<=a)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=Wc,(r.scrollTop<=0||i.top>=u)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function D4(n){return n.addCustom("table-scroll-events",t=>new ST(t))}const Tn=w("create-content");function L4(n,t,e){const o=new vc(e),r=e.rows,i=e.cols;d(Tn,r>=1,`invalid rows: ${r}`),d(Tn,i>=1,`invalid cols: ${i}`),d(Tn,e.children,"no table children");const s=b("table",[],null),l=e.colsWidth,c=b("colgroup",[],s);for(let f=0;f<o.colCount;f++){const m=b("col",[],c);m.style.width=`${l[f]||Sc}px`}const a=b("tbody",[],s);let u=0;for(let f=0;f<r;f++){const m=b("tr",[],a);for(let C=0;C<i;C++){const v=o.getCell({col:C,row:f});if(v.virtual)d(Tn,v.colSpan>1||v.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const B=e.children[u],y=b("td",[],m);v.colSpan>1&&(y.colSpan=v.colSpan),v.rowSpan>1&&(y.rowSpan=v.rowSpan);const S=e[ks(B)];S&&A(y,S),C===0&&e.hasColTitle&&A(y,v5.COL_TITLE_ITEM),n.createChildContainer(t,y,B),u+=1}}}return d(Tn,u===e.children.length,"container count mismatch"),e.noBorder&&A(s,"no-border"),e.chart&&A(s,"editor-table-chart"),e.isStripeStyle&&A(s,"stripe"),e.hasRowTitle&&A(s,"row-title"),e.hasColTitle&&A(s,"col-title"),s}function DT(n,t,e,o,r){d(Tn,r.type==="table","not table data"),d(Tn,U(e)===t[t.length-1].containerId,"invalid path");const i=r,s=ro(o,"div");try{const l=b("div",[],null);l.setAttribute("data-type","table-content");const c=L4(n,t,i);c.classList.add("drag-preview-element"),l.appendChild(c),P5(n),U5(n),I4(n,"create"),x4(n),vw(n,Dh);const a=n.getComponentOptions("table"),u=n.addCustom(Co(o),()=>SE());u.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:pt(e)?n.scrollContainer:e,locatingContainer:pt(e)?(a==null?void 0:a.locatingContainer)||n.parent:e,paddingLeft:Eh+vs,paddingTop:Eh+vs,paddingBottom:vs/2,paddingRight:vs/2,barFloatWindowBottom:a==null?void 0:a.barFloatWindowBottom,isSetScale:a==null?void 0:a.isSetScale});const f=D4(n);u.on("scroll",f.handleReset),u.on("resize",f.handleReset),setTimeout(()=>{lE(n,o)})}catch{const c=`invalid table data: ${JSON.stringify(i)}`;Tn.error(c);const a=b("div",["error"],s);a.innerText=c}return s}function LT(n,t,e){d(Tn,e.type==="table","not table data");const o=e,r=it(t);try{const i=jt(t),s=jo(t),l=L4(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),P5(n),U5(n),I4(n,"update"),x4(n),Dh(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;Tn.error(s);const l=b("div",["error"],r);l.innerText=s}}function MT(n,t){let e,o,r=!1;if([...t].every(m=>m==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=nd(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let m=0;m<3;m++)e.forEach(C=>{l.push(yn(n.doc,m===0?C:""))});const c=Array(s).fill(Sc),a=l[r?0:s],u=n.doc.getContainerBlocks(a)[0].id;return{blockData:{id:N(),type:"table",rows:i,cols:s,children:l,colsWidth:c},focusBlockId:u}}function RT(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let a=0;a<e;a++)for(let u=0;u<o;u++)r.push(yn(n.doc));const i=Array(o).fill(Sc),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:N(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const M4=w("table-selection-to-doc");function AT(n,t){const{start:e,end:o,block:r}=t,i=rt(r);d(M4,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return ao(n.editorBlocks,n.doc.toJSON(),s);d(M4,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=et.fromBlock(r),{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(r,e,o),m={},C=[],v=n.doc.toJSON();let B={};l.sub({row:u,col:c},{row:f,col:a}).forEach((Z,ot)=>{Z.forEach((st,mt)=>{const ut=st.containerId;if(C.indexOf(ut)!==-1)return;C.push(ut);let yt;if(st.virtual){const ee=l.getCellByContainerId(st.containerId),Ue=c+mt;let Eo=ee.col+ee.colSpan-1;Eo>a&&(Eo=a);const gr=Eo-Ue+1;gr>1&&(m[`${ut}_colSpan`]=gr);const pr=u+ot;let Io=ee.row+ee.rowSpan-1;Io>f&&(Io=f);const ya=Io-pr+1;ya>1&&(m[`${ut}_rowSpan`]=ya),yt=Zo()}else{if(yt=hu(n.editorBlocks,v,ut),st.col+st.colSpan>a+1){const ee=a-st.col+1;ee>1&&(m[`${ut}_colSpan`]=ee)}else st.colSpan>1&&(m[`${ut}_colSpan`]=st.colSpan);if(st.row+st.rowSpan>f+1){const ee=f-st.row+1;ee>1&&(m[`${ut}_rowSpan`]=ee)}else st.rowSpan>1&&(m[`${ut}_rowSpan`]=st.rowSpan)}const{root:se,...eo}=yt.blocks;B={...B,...eo,[ut]:se}})});const S=Es(jt(r)).slice(c,a+1);return{blocks:{root:[{id:N(),type:i,children:C,colsWidth:S,rows:f-u+1,cols:a-c+1,...m}],...B},meta:{},comments:{}}}function OT(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function _T(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function NT(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function $T(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function PT(n,t,e){const o=t.col,r=t.row,i=e.col,s=e.row,l={left:o,top:r,right:i,bottom:s};let c=!1;do{if(c=!1,!OT(n,l)){l.top--,c=!0;continue}if(!_T(n,l)){l.left--,c=!0;continue}if(!NT(n,l)){l.bottom++,c=!0;continue}if(!$T(n,l)){l.right++,c=!0;continue}}while(c);return l}function jT(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=et.fromBlock(t),i=r.map(M=>M.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=Math.min(s.row,l.row),a=Math.max(s.row,l.row),u=Math.min(s.col,l.col),f=Math.max(s.col,l.col),m=PT(i,{row:c,col:u},{row:a,col:f}),C=r.getCell({row:m.top,col:m.left}),v=r.getCell({row:m.bottom,col:m.right}),B=r.getCell({row:m.top,col:m.right}),y=r.getCell({row:m.bottom,col:m.left});let S,I;return s.row<=l.row?s.col<=l.col?(S=C,I=v):(S=B,I=y):s.col<l.col?(S=y,I=B):(S=v,I=C),console.log(`move ${S.col}, ${S.row}, -> ${I.col}, ${I.row}`),{anchor:wt(t,S.containerId),focus:wt(t,I.containerId)}}function R4(n,t,e){if(e.isSimple())return[jt(t).getBoundingClientRect()];const o=jt(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:c}=an(t,e.start,e.end),a=Es(o),u=a.slice(0,i).reduce((B,y)=>B+y,0),f=u+a.slice(i,l+1).reduce((B,y)=>B+y,0),m=y4(o);let C=m.slice(0,s).reduce((B,y)=>B+y,0);const v=C+m.slice(s,c+1).reduce((B,y)=>B+y,0);if(s===0){const B=vT(n,t);C-=B}return[new DOMRect(r.left+u,r.top+C,f-u,v-C)]}w("table-size");const HT=40;function Gc(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),o=Number.parseInt(e.borderLeft,10),r=Number.parseInt(e.borderRight,10);return(o+r)/2}function FT(n,t,e){const o=wd(n,e.container);return o!==void 0?o+Gc(t):HT*e.colSpan-Gc(t)}function zT(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getRealCell({col:s,row:o});if(l.virtual)continue;let c=FT(n,t,l);const a=ug(l.container,{withPadding:!0});a&&a>c&&(c=a),r+=c+Gc(t)}return r}function UT(n,t){const e=jt(t),o=et.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,zT(n,e,o,s));const i=Gc(e);return r+=i,r}const Yn=w("table-creator");async function VT(n,t){return n.undoManager.runInGroup(()=>{var c,a;const e=t.item,o=(c=e.colCount)!=null?c:5,r=(a=e.rowCount)!=null?a:3,i=RT(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,At(n,l,0))})}class qT{constructor(){h(this,"id","insert-table");h(this,"name","Create table");h(this,"element");h(this,"closeable",null);h(this,"colCount");h(this,"rowCount");h(this,"setCloseable",t=>{this.closeable=t});h(this,"destroy",()=>{this.closeable=null});h(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);h(this,"handleTableCreatorClick",t=>{var m,C;t.preventDefault(),t.stopPropagation();const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");d(Yn,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;d(Yn,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const a=s.substring(l.length).split("-");d(Yn,a.length===2,"invalid cell id");const u=Number.parseInt(a[0],10)+1,f=Number.parseInt(a[1],10)+1;Yn.debug(`${u}, ${f}`),this.colCount=f,this.rowCount=u,(m=this.closeable)==null||m.click(this,this.element),(C=this.closeable)==null||C.close(),this.handleTableCreatorLeave()});h(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const o=this.getTableCreatorCellId(t,e),r=document.getElementById(o);r&&z(r,"active")}});h(this,"handleTableCreatorCellEnter",t=>{const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";d(Yn,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");d(Yn,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let a=0;a<9;a++)for(let u=0;u<9;u++){const f=this.getTableCreatorCellId(a,u),m=document.getElementById(f);d(Yn,m,"no cell"),a<=l&&u<=c?A(m,"active"):z(m,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=b("div",["table-creator"],null),e=(o,r,i)=>{const s=b("div",["table-creator-cell"],o);return s.id=this.getTableCreatorCellId(r,i),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let o=0;o<9;o++){const r=b("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function WT(){return new qT}function GT(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function A4(n){const t=GT(n);return n.length+t}function ZT(n,t){const e=A4(n),o=t-e;return o>0?n+" ".repeat(o):n}function YT(n,t,e,o,r){const i=t,s=new vc(i);if(o==="markdown"||o==="text"){const l=y=>e.blocks[y].map((M,R)=>o==="markdown"?nu(n,M,e,[...r,{containerId:y,blockIndex:R}]):ql(n,M,e,[...r,{containerId:y,blockIndex:R}])),c=y=>l(y).join(" ").replace(/\n/g," ").trim(),a=new Map,u=new Map;for(let y=0;y<s.colCount;y++){let S=0;for(let I=0;I<s.rowCount;I++){const M=s.getCell({row:I,col:y});let R="";M.virtual||(R=c(M.containerId)),a.set(`${I},${y}`,R),S=Math.max(S,A4(R))}u.set(y,S)}const f=y=>{const S=a.get(`${y.row},${y.col}`)||"",I=u.get(y.col)||0;return ZT(S,I)},m=[];let C="|",v="|";for(let y=0;y<s.colCount;y++){const S=f({row:0,col:y});C+=` ${S} |`;const I="-".repeat((u.get(y)||0)+2);v+=`${I}|`}m.push(C),m.push(v);for(let y=1;y<s.rowCount;y++){let S="|";for(let I=0;I<s.colCount;I++){const M=f({row:y,col:I});S+=` ${M} |`}m.push(S)}return`${m.join(`
|
|
367
|
+
`:r.mathjaxText}const n1={embedType:"math",createEmbedContent:Yx,getOptions:Kx,convertFrom:Qx,handleDeleteBlock:Jx,convertTo:Xx},Cz="",tT={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},eT={mathjax:{emptyText:"Empty Tex",abstract:"TeX"}};T.mergeLang({"zh-CN":tT,"en-US":eT});function nT(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o);if(!vt(s).endsWith("$$$$"))return!1;const c=o-4,a=o,u={id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c),n.insertBoxToBlock(r,c,u),setTimeout(()=>{const f=n.getBoxById(u.id);t1(n,f)})}),!0}class oT{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&nT(t,e,o,r))}}const C4=w("inline-box-items");function rT(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);Tt(n,o)||(o=n.insertTextBlock([],t,e));const r=Hx();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return d(C4,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);t1(n,l)},100),o})}function iT(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return Tt(n,o)||(r="top-start"),Rc(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{Tt(n,o)||(o=n.insertTextBlock([],t,e));const a=$e(l,{link:c}),u=$e(" ",null),f=[a,u];n.insertTextToBlock(o,0,f),n.selection.selectBlock(o,de(f)),n.focus()}catch(a){C4.error(a)}})},onClose:()=>{n.focus()},placement:r}),o}async function sT(n,t){switch(t.item.id){case"insert-math":return rT(n,t.containerId,t.blockIndex);case"insert-link":return iT(n,t.containerId,t.blockIndex);default:return null}}function lT(){return{name:"text",insertBlockCommandItems:[{id:"insert-math",name:T.t("quickMenu.inlineBox.math"),icon:qw,order:900,group:"common",subText:fe("insert-math")},{id:"insert-link",name:T.t("quickMenu.inlineBox.link"),icon:n5,order:400,group:"common",subText:fe("insert-link")}],handleInsertEmptyBlock:sT}}const cT={basics:100,system:200,common:300,thirdParty:400};function aT(n){var o,r;const t=(r=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:r.commandProviders;if(!t)return[];const e=[];return[...t,new h4].forEach(i=>{const s=i.getCommands(n);e.push(...s.map(l=>({...l,itemType:"insert-block",commandProvider:i})))}),e}function dT(n){const t=[];n.editorBlocks.forEach(o=>{if(!o.getOptions)return;const r=o.getOptions(n);!r.insertBlockCommandItems||(r.insertBlockCommandItems.forEach(i=>{Qh(i,r)}),t.push(...r.insertBlockCommandItems))});const e=lT();return e.insertBlockCommandItems.forEach(o=>{Qh(o,e)}),t.push(...e.insertBlockCommandItems),t.push(...aT(n)),t}function o1(n){const t=dT(n),e=new Map;t.forEach(i=>{var c;const s=(c=i.group)!=null?c:"";let l=e.get(s);l?l.items.push(i):(l={group:s,order:i.groupOrder||cT[s]||1e3,items:[i]},e.set(s,l))});const o=Array.from(e.values());o.sort((i,s)=>i.order-s.order),o.forEach(i=>{i.items.sort((s,l)=>{var c,a;return((c=s.order)!=null?c:0)-((a=l.order)!=null?a:0)})});const r=[];return o.forEach((i,s)=>{const l=T.t(`blockMenu.section.${i.group||"common"}`),c=l===i.group?i.group:l;r.push({id:`section-${s}`,name:c,type:"section",group:i.group,itemType:"insert-block"}),r.push(...i.items.map(a=>({...a})))}),r}function uT(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=U(r);let l=n.getBlockIndex(o);if(Tt(n,o)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:i,blockIndex:l,item:t})}const b4=w("quick-menu"),hT={id:"quick-menu",trigger:["/"]};class zc{constructor(t,e=hT){h(this,"suggest");h(this,"items");h(this,"maxHeading");h(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const o=new Set,r=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,"");return this.items.filter(i=>{var s;return i.type==="section"?!0:i.name.toLocaleLowerCase().indexOf(r)!==-1||AB(i).toLocaleLowerCase().indexOf(r)!==-1||i.group&&((s=i.group)==null?void 0:s.toLocaleLowerCase().indexOf(r))!==-1?(o.add(i.group),!0):!1}).filter(i=>i.type==="section"?o.has(i.group):!0)}return this.items});h(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!Ko(i)){const s=F(H(i));if(s&&rt(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(d(b4,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),d(b4,this.suggest.anchor,"invalid suggest, no anchor"),uT(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=Oc(),this.suggest=new mh(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=o1(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=Oc();if(o!==this.maxHeading){const r=new h4,s=r.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:r}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=o}}}class r1{constructor(t){h(this,"instance");h(this,"mousedown",!1);h(this,"currentInstance",null);h(this,"attributeName","");h(this,"attributeDesc","");h(this,"observer",null);h(this,"observerCallback",null);h(this,"createContent",t=>{var i;const e=(i=t.getAttribute(this.attributeName))!=null?i:"",o=t.getAttribute(this.attributeDesc);if(!o)return e;const r=b("div",[],null);return b("span",[],r,e),o&&b("span",["editor-tooltip-desc"],r,o),r});h(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});h(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});h(this,"handleShow",t=>{var r;const e=t.reference;if(!e||!It(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);return!(o&&Date.now()-o<1e3)});this.editor=t;const e=t.clientId;this.attributeName=`data-editor-tooltip-${e}`,this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=qa.delegate(document.body,{delay:200,target:`[${this.attributeName}]`,content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Xt.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,o={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,o)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}}const fT={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-subscript":"subscript","text/style-superscript":"superscript"};function mT(n,t){const e=new Set(Object.keys(fT)),o=t.filter(i=>e.has(i.id));return Lc(o)}function Uc(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=mT(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),Xr.get(n).update("selectionChange"),!0):!1}const i1={"CtrlOrCmd+B":n=>Uc(n,"style-bold"),"CtrlOrCmd+I":n=>Uc(n,"style-italic"),"CtrlOrCmd+U":n=>Uc(n,"style-underline"),"CtrlOrCmd+D":n=>Uc(n,"style-strikethrough")},gT={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u4E8B\u9879",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}},pT={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"Todo list",quote:"Quote"},inlineBox:{math:"Math",link:"Link"},link:{textLabel:"Text",urlLabel:"Link Address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter the link address",submitText:"Ok",cancelText:"Cancel"}},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"Todo list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Align center",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}};T.mergeLang({"zh-CN":gT,"en-US":pT});const bz="";function sr(n,...t){const e=go(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function v4(n){Mc(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function CT(n){return b("div",["insert-column-button","drop-marker"],n)}const k4=w("row-height");function y4(n){const t=et.fromTable(n),e=n.rows;d(k4,e.length===t.rowCount,"row count mismatch");const o=Array(t.rowCount).fill(0);for(let r=0;r<e.length;){let i=1,l=e[r].getBoundingClientRect().height,c=r+1;for(;c<e.length;){const a=e[c];if(a.cells.length!==0)break;i++,c++,l+=a.getBoundingClientRect().height}for(let a=0;a<i;a++)o[r+a]=l/i;r=c}return k4.debug("heights",o.join(", ")),o}const ko=w("table-border-bar-dom");function Ss(n,t){d(ko,Ht(t),"invalid table block");const e=jt(t),o=xn(n,t),r=(a,u,f)=>{const m=b("div",["button-root",u],a),C=b("div",["button-container",u],m);m.setAttribute(`data-${u}-index`,`${f}`),C.setAttribute(`data-editor-tooltip-${n.clientId}`,u==="left"?T.t("table.insertRow"):T.t("table.insertCol")),b("span",["insert-indicator"],C),CT(C)},{selectedRows:i,selectedColumns:s}=ph(n,t),l=()=>{const a=o.querySelector(".table-border-bar-container.top");d(ko,a,"no top border bar container");const u=b("div",["table-border-bar-container","top"],null),f=b("div",["table-border-bar","top"],u),m=ME(e);b("span",["table-border-bar-cell","corner"],f);const v=et.fromTable(e).colCount;n.selection.range.isSimple()&&r(f,"top",0);for(let B=0;B<v;B++){const y=B===v-1?m[B]+2:m[B],S=b("span",["table-border-bar-cell","top"],f);s.has(B)&&S.classList.add("selected"),S.setAttribute("data-top-index",`${B}`),S.style.width=`${y}px`,n.selection.range.isSimple()&&r(f,"top",B+1)}Mi(a,u)},c=()=>{const a=o.querySelector(".table-border-bar-container.left");d(ko,a,"no left border bar container");const u=b("div",["table-border-bar-container","left"],null),f=b("div",["table-border-bar","left"],u),m=y4(e);n.selection.range.isSimple()&&r(f,"left",0),Array.from(e.rows).forEach((C,v,B)=>{const y=b("span",["table-border-bar-cell","left"],f);i.has(v)&&y.classList.add("selected"),y.setAttribute("data-left-index",`${v}`);const S=v===B.length-1?m[v]+2:m[v];y.style.height=`${S}px`,n.selection.range.isSimple()&&r(f,"left",v+1)}),Mi(a,u)};l(),c()}function w4(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(ko,o&&Ht(o),"invalid table block"),Ss(n,o),n.selection.caret.update()}function s1(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(ko,o&&Ht(o),"invalid table block");const r=e.closest(".button-root");if(r){if(r.classList.contains("top")){const i=parseInt(r.getAttribute("data-top-index")||"0",10);H5(n,o,i),Ss(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);F5(n,o,i),Ss(n,o)}}}function l1(n,t){var s;v4(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var c;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const a=F(l.target),u=l.target.closest(".table-border-bar");if(a===e&&u){const f=parseInt((c=l.target.getAttribute(`data-${o}-index`))!=null?c:"0",10),m=Math.min(r,f),C=Math.abs(r-f)+1;nt(l.target,"top")&&o==="top"?VE(n,a,m,C,{reverse:!0}):nt(l.target,"left")&&o==="left"&&qE(n,a,m,C,{reverse:!0})}}l.type==="mouseup"&&(e=null,r=void 0,o=void 0,document.body.removeEventListener("mousemove",i),document.body.removeEventListener("mouseup",i))};t.target instanceof HTMLElement&&nt(t.target,"table-border-bar-cell")&&(e=F(t.target),nt(t.target,"top")?o="top":nt(t.target,"left")&&(o="left"),o&&e&&(r=parseInt((s=t.target.getAttribute(`data-${o}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",i),document.body.addEventListener("mouseup",i)))}function bT(n,t){d(ko,Ht(t),"invalid table block");const e=xn(n,t),o=b("div",["table-border-bar-container","top"],e),r=b("div",["table-border-bar-container","left"],e);Ss(n,t),n.domEvents.addEventListener(it(t),"scroll",w4),n.domEvents.addEventListener(o,"click",s1),n.domEvents.addEventListener(r,"click",s1),n.domEvents.addEventListener(o,"mousedown",l1),n.domEvents.addEventListener(r,"mousedown",l1)}function B4(n,t){if(!n.isWritable())return;if(xn(n,t).querySelector(".table-border-bar-container")){Ss(n,t);return}bT(n,t)}function E4(n,t){d(ko,Ht(t),"invalid table block"),xn(n,t).querySelectorAll(".table-border-bar-container").forEach(r=>{n.domEvents.removeEventListener(r,"click",s1),n.domEvents.removeEventListener(r,"mousedown",l1),r.remove()}),n.domEvents.removeEventListener(it(t),"scroll",w4)}function vT(n,t){d(ko,Ht(t),"invalid table block");const o=xn(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class kT{constructor(t,e){h(this,"toolbar");h(this,"handleSelectionChange",(t,e)=>{e==="delete-columns"?(Vr(this.editor,this.tableBlock,!0,!0),qr(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Vr(this.editor,this.tableBlock,!0,!1),qr(this.editor,this.tableBlock,!0,!1)):(Vr(this.editor,this.tableBlock,!1),qr(this.editor,this.tableBlock,!1))});h(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?Ch(this.editor.selection.range):e.id==="delete-rows"&&bh(this.editor.selection.range)});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ps([],void 0,{overflowBoundary:o==null?void 0:o.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick)}close(){this.toolbar.close()}update(){const{selectedColumns:t,selectedRows:e}=ph(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close();return}if(t.size===0&&e.size===0){this.toolbar.close();return}const o=Ho(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close();return}if(t.size>0){const r={id:"delete-columns",name:T.t("table.deleteCol"),icon:Rw};this.toolbar.updateItems([r]);const i=zo(this.editor,this.tableBlock,"editor-quick-menu",o);this.toolbar.manualShow(i,{placement:"top"})}else{const r={id:"delete-rows",name:T.t("table.deleteRow"),icon:Mw};this.toolbar.updateItems([r]);const i=new DOMRect(o.left-15,o.top,o.width,o.height),s=zo(this.editor,this.tableBlock,"editor-quick-menu",i);this.toolbar.manualShow(s,{placement:"left"})}}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const Vc=w("table-border-bar");class yT{constructor(t,e){h(this,"toolbar");h(this,"resizeObserver");h(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():E4(this.editor,this.tableBlock)});h(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(q(this.tableBlock));this.resizeObserver.observe(jt(t))})});h(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,d(Vc,this.tableBlock,"no table block"),Vc.debug("create table border bar"),B4(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(jt(this.tableBlock)),this.toolbar=new kT(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){Vc.debug("destroy table border bar"),this.resizeObserver.disconnect(),E4(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){Vc.debug("update table border bar"),B4(this.editor,this.tableBlock),this.toolbar.update()}}const wT=w("table-border-bar");class BT{constructor(t){h(this,"activeTableBar",null);h(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||It(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});h(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const i=t.getBlockById(e.start.blockId);if(Ht(i)){const s=H(i),l=F(s);l&&(o=Me(l))}else o=Me(i)}else{const i=t.getBlockById(e.start.blockId),s=Me(i),l=t.getBlockById(e.end.blockId),c=Me(l);s===c&&(o=s)}((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new yT(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(d(wT,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function I4(n,t){const e=n.addCustom("table-border-bar",o=>new BT(o));t==="update"&&e.update()}const Be=w("table-cell-menu"),ET="style-bg-color-";class IT{constructor(t){h(this,"activeTableBlock",null);h(this,"targetButton",null);h(this,"manualMenu",null);h(this,"colorPaletteItem",null);h(this,"handlePrevent",(t,e)=>{e.stopPropagation()});h(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId);if(Ht(r)){const i=H(r),s=F(i);s&&(o=Me(s))}else o=Me(r)}else{const r=t.getBlockById(e.start.blockId),i=Me(r),s=t.getBlockById(e.end.blockId),l=Me(s);i===l&&(o=i)}if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=et.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;e.isCollapsed()?s=this.getCellByChildBlockId(r,i.blockId):i instanceof Je&&(t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});h(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});h(this,"createBkgColorItem",()=>{const t=b("div",["cell-background-color-item"],null);b("span",[],t,T.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();b("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=b("span",["item-sub-indicator"],t);return r.innerHTML=J2,t});h(this,"handleCommand",t=>{var r;d(Be,this.activeTableBlock,"no target table block");const e=((r=t.states)==null?void 0:r.includes("checked"))||!1,o=t.value;switch(t.id){case"delete-select-row":bh(y5(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":Ch(y5(this.editor,this.activeTableBlock,!0));break;case"merge-cell":b5(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":XB(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":rE(this.editor,this.activeTableBlock,o==="show-chart"),Sh(this.editor,this.activeTableBlock,{updateNow:!0});break}});h(this,"handleSelectionChange",(t,e)=>{d(Be,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Vr(this.editor,this.activeTableBlock,!0,!1),qr(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Vr(this.editor,this.activeTableBlock,!0,!0),qr(this.editor,this.activeTableBlock,!0,!0)):(Vr(this.editor,this.activeTableBlock,!1),qr(this.editor,this.activeTableBlock,!1))});h(this,"handleClick",()=>{var t;d(Be,this.activeTableBlock,"no target table block"),d(Be,this.targetButton,"no target button"),v4(this.editor),nt(this.targetButton,"active")?(z(this.targetButton,"active"),(t=this.manualMenu)==null||t.close()):(A(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new tr(this.createCommandMenu()),this.manualMenu.on("click",(e,o)=>{var r;this.handleCommand(o),(r=this.manualMenu)==null||r.close()}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",()=>{this.targetButton&&z(this.targetButton,"active"),this.editor.focus()})),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"}))});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close(),this.targetButton&&(z(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");d(Be,r,"no parent cell");const i=F(r);if(d(Be,i,"no parent block"),jt(i)===t.table)return t.getCellByCellElement(r);o=i}return d(Be,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(":scope > .table-cell-menu-btn")||t.appendChild(this.targetButton):(this.targetButton=b("button",["table-cell-menu-btn"],t),this.targetButton.innerHTML=Ju,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),d(Be,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=et.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);kh(this.editor,this.activeTableBlock,{col:o,row:r})}else yh(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;d(Be,this.activeTableBlock,"no target table block");const t=nE(this.editor,this.activeTableBlock),e=this.editor.getBlockData(this.activeTableBlock),o=new Set;for(const i of t){if(o.size>1)break;const s=U(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(ET.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){d(Be,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=C5(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const u=Gn(this.editor,this.activeTableBlock,o.start);o=Wt(this.editor,{anchor:u,focus:u})}const r=p5(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,a=t.chart;return this.colorPaletteItem=new d5("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(u,f)=>{var m;switch(d(Be,this.activeTableBlock,"no target table block"),u){case"clearColor":E5(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":E5(this.editor,this.activeTableBlock,f);break}(m=this.manualMenu)==null||m.close()}),[{id:"cell-background-color",name:T.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:T.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:T.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:T.t("table.deleteSelectRow")},{id:"delete-select-col",name:T.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:T.t("table.tableConfigKey"),children:[{id:"row-title",name:T.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:T.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:T.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?T.t("table.tableConfig.showBorder"):T.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:a?T.t("table.tableConfig.hideChart"):T.t("table.tableConfig.showChart"),value:a?"hide-chart":"show-chart"}]}]}handleRowTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?QB(this.editor,this.activeTableBlock):YB(this.editor,this.activeTableBlock)}handleColTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?ZB(this.editor,this.activeTableBlock):GB(this.editor,this.activeTableBlock)}handleStripeStyle(t){d(Be,this.activeTableBlock,"no target table block"),t?JB(this.editor,this.activeTableBlock):KB(this.editor,this.activeTableBlock)}}function x4(n){n.addCustom("table-cell-menu",t=>new IT(t))}const qc=w("table-container");function c1(n){const t=n.closest("td");return d(qc,t,"no parent cell for a table cell container"),t}function T4(n){const t=jt(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function a1(n,t,e,o){const r=et.fromBlock(n),i=r.getCellByContainerId(U(t));if(e==="ArrowDown"){const s=r.getBottomCell(i);return s?s.container:null}if(e==="ArrowUp"){const s=r.getTopCell(i);return s?s.container:null}if(e==="ArrowLeft"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(qc,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(qc,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}d(qc,!1,`invalid navigation type: ${e}`)}const xT=12,TT=90,Wc=23,S4=2;class ST{constructor(t){h(this,"scrollTableBlock",null);h(this,"autoScrollDir",null);h(this,"autoScrollTimer",null);h(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const o=F(e);if(o&&It(this.editor.rootContainer,o)){const r=Me(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});h(this,"handleAutoScroll",b7.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Co(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),l=r.getBoundingClientRect(),c=Math.min(l.bottom,s),a=Math.max(l.top,0);i.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):i.top<a&&t.clientY<=a?this.setAutoScroll("top"):o.scrollLeft>0&&t.clientX<i.left?this.setAutoScroll("left"):o.scrollLeft<o.scrollWidth-o.offsetWidth&&t.clientX>i.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));h(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const o=t.getBlockById(e.start.blockId),r=Me(o);if(r){const i=t.getCustom(Co(r)),s=i.rootElement.getBoundingClientRect(),l=Ke(t,o,e.start);if(s.left>l.left){const c=e.start.offset===0?xT:S4;i.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?TT:S4;i.rootElement.scrollLeft+=l.right-s.right+c}}}else{const o=t.getBlockById(e.start.blockId),r=Me(o),i=t.getBlockById(e.end.blockId),s=Me(i);if(r&&r===s){const l=t.getCustom(Co(r)),c=l.rootElement.getBoundingClientRect();let a=null;if(e.isSimple())a=e.isReverse()?Ke(t,o,e.start):Ke(t,i,e.end);else{const u=c1(Br(t,e.start.childContainerId)),f=c1(Br(t,e.end.childContainerId));a=e.isReverse()?u.getBoundingClientRect():f.getBoundingClientRect()}c.left>a.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-a.left:c.right<a.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=a.right-c.right)}}});h(this,"handleScroll",t=>{f5(t),this.editor.selection.caret.update()});h(this,"handleReset",t=>{f5(t),this.editor.selection.caret.update()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Co(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),c=r.getBoundingClientRect(),a=Math.min(c.bottom,l),u=Math.max(c.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=Wc,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=Wc,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=Wc,(r.scrollTop>=r.scrollHeight-s||i.bottom<=a)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=Wc,(r.scrollTop<=0||i.top>=u)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function D4(n){return n.addCustom("table-scroll-events",t=>new ST(t))}const Tn=w("create-content");function L4(n,t,e){const o=new vc(e),r=e.rows,i=e.cols;d(Tn,r>=1,`invalid rows: ${r}`),d(Tn,i>=1,`invalid cols: ${i}`),d(Tn,e.children,"no table children");const s=b("table",[],null),l=e.colsWidth,c=b("colgroup",[],s);for(let f=0;f<o.colCount;f++){const m=b("col",[],c);m.style.width=`${l[f]||Sc}px`}const a=b("tbody",[],s);let u=0;for(let f=0;f<r;f++){const m=b("tr",[],a);for(let C=0;C<i;C++){const v=o.getCell({col:C,row:f});if(v.virtual)d(Tn,v.colSpan>1||v.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const B=e.children[u],y=b("td",[],m);v.colSpan>1&&(y.colSpan=v.colSpan),v.rowSpan>1&&(y.rowSpan=v.rowSpan);const S=e[ks(B)];S&&A(y,S),C===0&&e.hasColTitle&&A(y,v5.COL_TITLE_ITEM),n.createChildContainer(t,y,B),u+=1}}}return d(Tn,u===e.children.length,"container count mismatch"),e.noBorder&&A(s,"no-border"),e.chart&&A(s,"editor-table-chart"),e.isStripeStyle&&A(s,"stripe"),e.hasRowTitle&&A(s,"row-title"),e.hasColTitle&&A(s,"col-title"),s}function DT(n,t,e,o,r){d(Tn,r.type==="table","not table data"),d(Tn,U(e)===t[t.length-1].containerId,"invalid path");const i=r,s=ro(o,"div");try{const l=b("div",[],null);l.setAttribute("data-type","table-content");const c=L4(n,t,i);c.classList.add("drag-preview-element"),l.appendChild(c),P5(n),U5(n),I4(n,"create"),x4(n),vw(n,Dh);const a=n.getComponentOptions("table"),u=n.addCustom(Co(o),()=>SE());u.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:pt(e)?n.scrollContainer:e,locatingContainer:pt(e)?(a==null?void 0:a.locatingContainer)||n.parent:e,paddingLeft:Eh+vs,paddingTop:Eh+vs,paddingBottom:vs/2,paddingRight:vs/2,barFloatWindowBottom:a==null?void 0:a.barFloatWindowBottom,isSetScale:a==null?void 0:a.isSetScale});const f=D4(n);u.on("scroll",f.handleReset),u.on("resize",f.handleReset),setTimeout(()=>{lE(n,o)})}catch{const c=`invalid table data: ${JSON.stringify(i)}`;Tn.error(c);const a=b("div",["error"],s);a.innerText=c}return s}function LT(n,t,e){d(Tn,e.type==="table","not table data");const o=e,r=it(t);try{const i=jt(t),s=jo(t),l=L4(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),P5(n),U5(n),I4(n,"update"),x4(n),Dh(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;Tn.error(s);const l=b("div",["error"],r);l.innerText=s}}function MT(n,t){let e,o,r=!1;if([...t].every(m=>m==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=nd(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let m=0;m<3;m++)e.forEach(C=>{l.push(yn(n.doc,m===0?C:""))});const c=Array(s).fill(Sc),a=l[r?0:s],u=n.doc.getContainerBlocks(a)[0].id;return{blockData:{id:N(),type:"table",rows:i,cols:s,children:l,colsWidth:c},focusBlockId:u}}function RT(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let a=0;a<e;a++)for(let u=0;u<o;u++)r.push(yn(n.doc));const i=Array(o).fill(Sc),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:N(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const M4=w("table-selection-to-doc");function AT(n,t){const{start:e,end:o,block:r}=t,i=rt(r);d(M4,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return ao(n.editorBlocks,n.doc.toJSON(),s);d(M4,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=et.fromBlock(r),{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(r,e,o),m={},C=[],v=n.doc.toJSON();let B={};l.sub({row:u,col:c},{row:f,col:a}).forEach((Z,ot)=>{Z.forEach((st,mt)=>{const ut=st.containerId;if(C.indexOf(ut)!==-1)return;C.push(ut);let yt;if(st.virtual){const ee=l.getCellByContainerId(st.containerId),Ue=c+mt;let Eo=ee.col+ee.colSpan-1;Eo>a&&(Eo=a);const gr=Eo-Ue+1;gr>1&&(m[`${ut}_colSpan`]=gr);const pr=u+ot;let Io=ee.row+ee.rowSpan-1;Io>f&&(Io=f);const ya=Io-pr+1;ya>1&&(m[`${ut}_rowSpan`]=ya),yt=Zo()}else{if(yt=hu(n.editorBlocks,v,ut),st.col+st.colSpan>a+1){const ee=a-st.col+1;ee>1&&(m[`${ut}_colSpan`]=ee)}else st.colSpan>1&&(m[`${ut}_colSpan`]=st.colSpan);if(st.row+st.rowSpan>f+1){const ee=f-st.row+1;ee>1&&(m[`${ut}_rowSpan`]=ee)}else st.rowSpan>1&&(m[`${ut}_rowSpan`]=st.rowSpan)}const{root:se,...eo}=yt.blocks;B={...B,...eo,[ut]:se}})});const S=Es(jt(r)).slice(c,a+1);return{blocks:{root:[{id:N(),type:i,children:C,colsWidth:S,rows:f-u+1,cols:a-c+1,...m}],...B},meta:{},comments:{}}}function OT(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function _T(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function NT(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function $T(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function PT(n,t,e){const o=t.col,r=t.row,i=e.col,s=e.row,l={left:o,top:r,right:i,bottom:s};let c=!1;do{if(c=!1,!OT(n,l)){l.top--,c=!0;continue}if(!_T(n,l)){l.left--,c=!0;continue}if(!NT(n,l)){l.bottom++,c=!0;continue}if(!$T(n,l)){l.right++,c=!0;continue}}while(c);return l}function jT(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=et.fromBlock(t),i=r.map(M=>M.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=Math.min(s.row,l.row),a=Math.max(s.row,l.row),u=Math.min(s.col,l.col),f=Math.max(s.col,l.col),m=PT(i,{row:c,col:u},{row:a,col:f}),C=r.getCell({row:m.top,col:m.left}),v=r.getCell({row:m.bottom,col:m.right}),B=r.getCell({row:m.top,col:m.right}),y=r.getCell({row:m.bottom,col:m.left});let S,I;return s.row<=l.row?s.col<=l.col?(S=C,I=v):(S=B,I=y):s.col<l.col?(S=y,I=B):(S=v,I=C),console.log(`move ${S.col}, ${S.row}, -> ${I.col}, ${I.row}`),{anchor:wt(t,S.containerId),focus:wt(t,I.containerId)}}function R4(n,t,e){if(e.isSimple())return[jt(t).getBoundingClientRect()];const o=jt(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:c}=an(t,e.start,e.end),a=Es(o),u=a.slice(0,i).reduce((B,y)=>B+y,0),f=u+a.slice(i,l+1).reduce((B,y)=>B+y,0),m=y4(o);let C=m.slice(0,s).reduce((B,y)=>B+y,0);const v=C+m.slice(s,c+1).reduce((B,y)=>B+y,0);if(s===0){const B=vT(n,t);C-=B}return[new DOMRect(r.left+u,r.top+C,f-u,v-C)]}w("table-size");const HT=40;function Gc(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),o=Number.parseInt(e.borderLeft,10),r=Number.parseInt(e.borderRight,10);return(o+r)/2}function FT(n,t,e){const o=wd(n,e.container);return o!==void 0?o+Gc(t):HT*e.colSpan-Gc(t)}function zT(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getRealCell({col:s,row:o});if(l.virtual)continue;let c=FT(n,t,l);const a=ug(l.container,{withPadding:!0});a&&a>c&&(c=a),r+=c+Gc(t)}return r}function UT(n,t){const e=jt(t),o=et.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,zT(n,e,o,s));const i=Gc(e);return r+=i,r}const Yn=w("table-creator");async function VT(n,t){return n.undoManager.runInGroup(()=>{var c,a;const e=t.item,o=(c=e.colCount)!=null?c:5,r=(a=e.rowCount)!=null?a:3,i=RT(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,At(n,l,0))})}class qT{constructor(){h(this,"id","insert-table");h(this,"name","Create table");h(this,"element");h(this,"closeable",null);h(this,"colCount");h(this,"rowCount");h(this,"setCloseable",t=>{this.closeable=t});h(this,"destroy",()=>{this.closeable=null});h(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);h(this,"handleTableCreatorClick",t=>{var m,C;t.preventDefault(),t.stopPropagation();const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");d(Yn,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;d(Yn,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const a=s.substring(l.length).split("-");d(Yn,a.length===2,"invalid cell id");const u=Number.parseInt(a[0],10)+1,f=Number.parseInt(a[1],10)+1;Yn.debug(`${u}, ${f}`),this.colCount=f,this.rowCount=u,(m=this.closeable)==null||m.click(this,this.element),(C=this.closeable)==null||C.close(),this.handleTableCreatorLeave()});h(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const o=this.getTableCreatorCellId(t,e),r=document.getElementById(o);r&&z(r,"active")}});h(this,"handleTableCreatorCellEnter",t=>{const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";d(Yn,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");d(Yn,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let a=0;a<9;a++)for(let u=0;u<9;u++){const f=this.getTableCreatorCellId(a,u),m=document.getElementById(f);d(Yn,m,"no cell"),a<=l&&u<=c?A(m,"active"):z(m,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=b("div",["table-creator"],null),e=(o,r,i)=>{const s=b("div",["table-creator-cell"],o);return s.id=this.getTableCreatorCellId(r,i),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let o=0;o<9;o++){const r=b("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function WT(){return new qT}function GT(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function A4(n){const t=GT(n);return n.length+t}function ZT(n,t){const e=A4(n),o=t-e;return o>0?n+" ".repeat(o):n}function YT(n,t,e,o,r){const i=t,s=new vc(i);if(o==="markdown"||o==="text"){const l=y=>e.blocks[y].map((M,R)=>o==="markdown"?nu(n,M,e,[...r,{containerId:y,blockIndex:R}]):ql(n,M,e,[...r,{containerId:y,blockIndex:R}])),c=y=>l(y).join(" ").replace(/\n/g," ").trim(),a=new Map,u=new Map;for(let y=0;y<s.colCount;y++){let S=0;for(let I=0;I<s.rowCount;I++){const M=s.getCell({row:I,col:y});let R="";M.virtual||(R=c(M.containerId)),a.set(`${I},${y}`,R),S=Math.max(S,A4(R))}u.set(y,S)}const f=y=>{const S=a.get(`${y.row},${y.col}`)||"",I=u.get(y.col)||0;return ZT(S,I)},m=[];let C="|",v="|";for(let y=0;y<s.colCount;y++){const S=f({row:0,col:y});C+=` ${S} |`;const I="-".repeat((u.get(y)||0)+2);v+=`${I}|`}m.push(C),m.push(v);for(let y=1;y<s.rowCount;y++){let S="|";for(let I=0;I<s.colCount;I++){const M=f({row:y,col:I});S+=` ${M} |`}m.push(S)}return`${m.join(`
|
|
368
368
|
`)}
|
|
369
369
|
`}if(o==="html"){const l=a=>e.blocks[a].map((m,C)=>eu(n,m,e,[...r,{containerId:a,blockIndex:C}])).join(`
|
|
370
370
|
`),c=[];c.push("<table>");for(let a=0;a<s.rowCount;a++){let u="<tr>";for(let f=0;f<s.colCount;f++){const m=s.getCell({row:a,col:f});if(m.virtual)u+="<td></td>";else{const C=l(m.containerId);u+=`<td colSpan="${m.colSpan}" rowSpan="${m.rowSpan}">${C}</td>`}}u+="</tr>",c.push(u)}return c.push("</table>"),c.join(`
|