@ones-editor/editor 0.0.3-beta.64 → 0.0.3-beta.66
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
|
@@ -338,7 +338,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
338
338
|
<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"/>
|
|
339
339
|
<path d="M9.07413 10.8036H13.2226M11.1484 8.91895V13.1009V8.91895Z" stroke="#999999" stroke-linecap="square" fill="none"/>
|
|
340
340
|
<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"/>
|
|
341
|
-
</svg>`;function tB(n,t){var e;if(M(t,"menu-item"),!n.element){if(n.type==="section"){const o=b("div",["section-name"],null,n.name);t.appendChild(o)}else if(n.type!=="separator"){if(n.icon){const 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=p5,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=Ow,t.appendChild(r)}}}}class sr extends Tc{constructor(t,e,o){super(t,e,{autoClose:!0,disablePageScroll:!0,...o})}manualShow(t,e){const o={theme:"menu",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"menu")}initItemElement(t,e){tB(t,e)}}function eB(n,t,e){var o;return new sr((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class Ts extends Tc{constructor(t,e,o){super(t,e,{itemElementTag:"button",tippyArrow:!1,...o})}getSubBarOptions(t){var r,i;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),a=s.getBoundingClientRect();return new DOMRect(a.left,c.top,a.width,c.height)};return{placement:(r=t.childrenPlacement)!=null?r:"top",getReferenceClientRect:e,offset:(i=t.childrenOffset)!=null?i:[0,4]}}manualShow(t,e){const o={theme:"toolbar",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),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=hh}t.states&&(t.states.indexOf("checked")!==-1&&M(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function nB(n,t,e){var o;return new Ts((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const KU="";Gr.registerManualCommandBar("menu",eB),Gr.registerManualCommandBar("toolbar",nB);const XU="",E5=w("ui-base");class Ss extends Tc{constructor(e,o){super(Ss.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){M(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];u(E5,e,"no dialog item");const o=e.element;return u(E5,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${P()}`,name:"",element:e}]}}const oB=[-1,6,0,1,2,3,4,5],rB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],I5=w("color-palette");function x5(n,t,e,o){u(I5,n>0,"no color in palette");const r=t||1;u(I5,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 d=e(l*i+a);c.appendChild(d)}}return s}function iB(n){const t=b("button",["color-button"],null),e=oB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=g5,t}function sB(n){const t=b("button",["background-color-button"],null),e=rB[n];return t.setAttribute("data-color-index",`${e}`),t}function lB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=x.t("colorPalette.reset"),n}function cB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.colorDesc")),t.appendChild(x5(8,1,iB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.backgroundDesc")),t.appendChild(x5(16,2,sB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(lB()),t}function aB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&j(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&M(i,"selected")}const tV="",uB={};class dB extends Yt.TypedEmitter{constructor(e=uB){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(ot(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)||(ot(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=cB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){aB(this.root,e,o)}}class T5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new dB(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function hB(){const n=b("button",["color-button"],null);return n.innerHTML=g5,n}function Bh(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 fB extends Yt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name",x.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],Bh(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new T5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=hB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Bh(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Bh(this.element,this.latestColors)}}const eV="";function Eh(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&M(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&M(o,"required");const r=b("div",["editor-input-container"],e),i=b("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=b("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),j(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{M(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function Ih(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 mB=w("ui-base");class gB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{Ih(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new sr([],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,d;if(((d=(a=this.options).onShow)==null?void 0:d.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)||G(this.editor,r)<o)return;const i=uo(this.editor,r,Ot(this.editor,r,o));if(i.length===0)return;const s=i[0],l=mo(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:x.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 We.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{We.release(e)}}highlightText(t){mB.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 d=0;for(d=0;d<=i.length-c;d){const f=i.substring(d,d+c);f.toLocaleLowerCase()===a?(l+=`<span class="highlight">${f}</span>`,d+=c):(l+=i.charAt(d),d++)}return d<i.length&&(l+=i.substring(d)),l},r=i=>{if(ot(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 xh=w("auto-suggest-menu");class Th{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(bt(ve(ge(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=bt(oc(t,i,r));if(u(xh,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 gB(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)||Au(e.key)?!1:_m(e)&&!Vo(e)?(setTimeout(()=>{this.resetItems()}),!1):bu(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:z(t),offset:e,leftText:o,trigger:r};const i=V(H(t)),s=K(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var d;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(z(a)!==l)return!1;if((d=this.menu)!=null&&d.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=bt(oc(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 z(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=bt(oc(t,i,r));if(u(xh,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);xh.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 pB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const CB={"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"},...pB()};function Ce(n){var t;return(t=CB[n])==null?void 0:t.shortcut}function AB(n){var t;return(t=n.subText)!=null?t:""}const xn=w("table-dom");function Io(n){return`${z(n)}_scroll`}function jt(n){const t=n.querySelector("div[data-type=table-content] >table");return u(xn,t instanceof HTMLTableElement,"invalid table"),t}function Tn(n,t){const o=n.getCustom(Io(t)).contentElement.firstElementChild;u(xn,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")),u(xn,r,"no table tools"),r}function S5(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function Ds(n){const t=n.querySelector(":scope div[data-type=editor-container]");return u(xn,t,"no child container in cell"),t}function bB(n){const o=S5(n).map(r=>{const i=Ds(r),s=V(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return wr.default(o)}function Zt(n){return rt(n)==="table"}function Sh(n){const t=H(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?t:Sh(e)}function Qn(n){if(Zt(n))return n;const t=H(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?e:Qn(e)}function vB(n,t){const e=n.querySelector("colgroup");u(xn,e,"no colgroup");const o=e.children[t];return u(xn,o,"no col"),u(xn,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function D5(n){try{return jt(n),!0}catch{return!1}}function yB(n){return Rt(n).querySelector(":scope > .block-helper")}function L5(n){const t=U(n.contentElement);u(xn,t,"no block");const e=yB(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 kB{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){u(Re,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){u(Re,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return u(Re,e,"get cell, no cell"),e}getCellAllowEmpty(t){return u(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 Dc{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 kB(this.colCount));this.fillGrid(),u(Re,t.colsWidth,"no colsWidth"),u(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;u(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 d=0;d<s;d++)this._rows[o+a].setCell(e+d,{col:e,row:o,containerId:r,virtual:d!==0||a!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,o);c?(e=c.col,o=c.row):u(Re,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{u(Re,i,"no cell"),u(Re,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];u(Re,r,`get cell, no row: ${o}`);const i=r.getCell(e);return u(Re,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return u(Re,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Lc=w("table-data");function wB(n){const t=n.firstElementChild;return u(Lc,t,"no child element for cell"),u(Lc,vn(t),"cell first child is not a container"),u(Lc,Ye(t),"cell first child is not a container"),t}function BB(n){const t=U(n);u(Lc,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=wB(c),d=V(a);e.push(d),(c.colSpan>1||c.rowSpan>1)&&(o[`${d}_colSpan`]=c.colSpan,o[`${d}_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:z(t),type:rt(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function lr(n){return new Dc(n)}function EB(n){return lr(BB(n))}const Qt=w("table-grid"),IB=60;class xB{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 u(Qt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);u(Qt,t.length===1,"containers !== 1"),u(Qt,vn(t[0]),"not a container");const e=t[0];return u(Qt,Ye(e),"not a child container"),e}}class TB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new xB(t,o))})}get cells(){return this._cells}getCell(t){return u(Qt,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const zf=class{constructor(t){h(this,"_rows",[]);this.table=t,EB(t).forEach(r=>{this._rows.push(new TB(t,r))});const o=this.colCount;this._rows.forEach(r=>{u(Qt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(u(Qt,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return u(Qt,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){u(Qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,o=[];for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});o.push(i)}return o}toRealCells(t){const e=[];return t.forEach(o=>{const r=this.getRealCell(o);e.findIndex(i=>i.containerId===r.containerId)===-1&&e.push(r)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){u(Qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let o=0;o<e;o++){const r=this.getCell({row:o,col:t});if(r.virtual||r.colSpan>1||r.rowSpan>1)return r}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const o=this.getCellById(e.containerId);return u(Qt,!o.virtual,"found a virtual cell"),o}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.col,o),r=Math.max(i.col+i.colSpan-1,r)}),u(Qt,o<=r,"min > max"),u(Qt,o>=0,"min < 0"),u(Qt,r<this.colCount,"max >= colCount"),[o,r]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.row,o),r=Math.max(i.row+i.rowSpan-1,r)}),u(Qt,o<=r,"min > max"),u(Qt,o>=0,"min < 0"),u(Qt,r<this.rowCount,"max >= rowCount"),[o,r]}getSpannedRange(t,e){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),i=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let p=o;p<=r;p++)for(let A=i;A<=s;A++)l.push(this.getCell({row:p,col:A}));const c=this.toRealCells(l);let a=1e4,d=1e4,f=-1,m=-1;return c.forEach(p=>{d=Math.min(p.col,d),a=Math.min(p.row,a),m=Math.max(p.col+p.colSpan-1,m),f=Math.max(p.row+p.rowSpan-1,f)}),[{row:a,col:d},{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),d=Math.max(i.col,s.col);for(let f=l;f<=c;f++)for(let m=a;m<=d;m++){const p=this.getCell({row:f,col:m});p.virtual||o.push(p)}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 u(Qt,o,"cell not found"),o}getCellByCellElement(t){const e=Ds(t);return this.getCellByContainerId(V(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=bB(t),o=this.caches.getSync(e,()=>(Qt.debug("create table grid"),new zf(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let nt=zf;h(nt,"caches",new pm(IB));function Mc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const SB=w("table-selection-range");function dn(n,t,e){var E,L,R,_;const o=nt.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),c=r.custom,a=i.custom,d=(E=c==null?void 0:c.rowIndex)!=null?E:s.row,f=(L=c==null?void 0:c.colIndex)!=null?L:s.col,m=(R=a==null?void 0:a.rowIndex)!=null?R:l.row+l.rowSpan-1,p=(_=a==null?void 0:a.colIndex)!=null?_:l.col+l.colSpan-1,A=Math.min(d,m),k=Math.max(d,m),y=Math.min(f,p),T=Math.max(f,p);return{fromRow:A,toRow:k,fromCol:y,toCol:T}}function Dh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===z(t)){const i=nt.fromBlock(t),{start:s,end:l}=r;u(SB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:d,toRow:f}=dn(t,s,l);if(d===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=d;m<=f;m++)e.add(m)}return{selectedRows:e,selectedColumns:o}}function Lh(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const o=n.getBlockById(t.start.blockId);if(Zt(o)){const r=H(o),i=U(r);i&&(e=Qn(i))}else e=Qn(o)}else{const o=n.getBlockById(t.start.blockId),r=Qn(o),i=n.getBlockById(t.end.blockId),s=Qn(i);r===s&&(e=r)}return e}const Zr=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}=dn(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.rowCount-1}function Mh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var L;const e=t.getBlockById(n.start.blockId);if(!M5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=dn(e,n.start,n.end),i=nt.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 W=o;W<=r;W++){const it=_[W];s.add(it)}_.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(R=>!c.has(R))),d=r-o+1,f=new Map,m=new Map;s.forEach(R=>{if(a.has(R))return;const _=i.getCellByContainerId(R);if(u(Zr,_.colSpan>1,"invalid effected cell, colSpan === 1"),_.col<o){u(Zr,c.has(R),"invalid effected cell, not exists");let kt=_.col+_.colSpan-1;kt>r&&(kt=r);const ue=kt-o+1,ro=_.colSpan-ue;f.set(R,ro);return}u(Zr,_.col<=r,"invalid effected cell, col > endCol");const W=_.col,it=_.col+_.colSpan-1,lt=_.col-o,gt=it-W+1-d+lt;u(Zr,gt>0,"invalid effected cell, newSpanned <= 0");const ht=wn(t.doc);m.set(R,{newContainerId:ht,colSpan:gt})});for(let R=0;R<l.length;R++){const _=l[R];for(let W=o;W<_.length;W++){const it=_[W],lt=m.get(it);lt&&(_[W]=lt.newContainerId)}}const p=Q.default(t.getBlockData(e));p.colsWidth.splice(o,r-o+1),a.forEach(R=>{Mc(p,R)}),f.forEach((R,_)=>{u(Zr,R>=1,"invalid modified colSpan, colSpan < 1"),R===1?p[`${_}_colSpan`]=void 0:p[`${_}_colSpan`]=R}),m.forEach((R,_)=>{Mc(p,_);const{newContainerId:W,colSpan:it}=R;u(Zr,it>=1,"invalid newContainerData, colSpan < 1"),it>1&&(p[`${W}_colSpan`]=it);const lt=i.getCellByContainerId(_).rowSpan;lt>1&&(p[`${W}_rowSpan`]=lt)});const k=(L=l[0][o])!=null?L:l[0][o-1],y=t.getChildContainerData(k)[0],T=nt.virtualCellContainersGridToChildren(l),E={...p,cols:p.cols-d,children:T};lr(E),t.updateBlockData(e,E,Ot(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Qr=w("delete-rows");function R5(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}=dn(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.colCount-1}function Rh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!R5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=dn(e,n.start,n.end),i=nt.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(E=>E.containerId);for(let E=r;E>=o;E--)l[E].forEach(R=>s.add(R)),l.splice(E,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(E=>!c.has(E))),d=r-o+1,f=new Map,m=new Map;s.forEach(E=>{if(a.has(E))return;const L=i.getCellByContainerId(E);if(u(Qr,L.rowSpan>1,"invalid effected cell, rowSpan === 1"),L.row<o){u(Qr,c.has(E),"invalid effected cell, not exists");let gt=L.row+L.rowSpan-1;gt>r&&(gt=r);const ht=gt-o+1,kt=L.rowSpan-ht;f.set(E,kt);return}u(Qr,L.row<=r,"invalid effected cell, col > endCol");const R=L.row,_=L.row+L.rowSpan-1,W=L.row-o,it=_-R+1-d+W;u(Qr,it>0,"invalid effected cell, newSpanned <= 0");const lt=wn(t.doc);m.set(E,{newContainerId:lt,rowSpan:it})});for(let E=o;E<l.length;E++){const L=l[E];for(let R=0;R<L.length;R++){const _=L[R],W=m.get(_);W&&(L[R]=W.newContainerId)}}const p=Q.default(t.getBlockData(e));a.forEach(E=>{Mc(p,E)}),f.forEach((E,L)=>{u(Qr,E>=1,"invalid modified rowSpan, rowSpan < 1"),E===1?delete p[`${L}_rowSpan`]:p[`${L}_rowSpan`]=E}),m.forEach((E,L)=>{Mc(p,L);const{newContainerId:R,rowSpan:_}=E;u(Qr,_>=1,"invalid newContainerData, rowSpan < 1"),_>1&&(p[`${R}_rowSpan`]=_);const W=i.getCellByContainerId(L).colSpan;W>1&&(p[`${R}_colSpan`]=W)});const A=l[o]?l[o][0]:l[o-1][0],k=t.getChildContainerData(A)[0],y=nt.virtualCellContainersGridToChildren(l),T={...p,rows:p.rows-d,children:y};lr(T),t.updateBlockData(e,T,Ot(t,k.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Ls=w("table-range");function Rc(n){u(Ls,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;u(Ls,!t.isSimple(),"invalid start pos type"),u(Ls,!e.isSimple(),"invalid end pos type");const o=n.getEditor();u(Ls,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);u(Ls,rt(r)==="table","invalid block type, not a table block");const i=jt(r),s=nt.fromTable(i),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),a=Math.min(l.row,c.row),d=Math.max(l.row,c.row),f=Math.min(l.col,c.col),m=Math.max(l.col,c.col),p=s.getCell({row:a,col:f}),A=s.getCell({row:d,col:m});return{editor:o,block:r,table:i,startCell:p,endCell:A,startRow:a,startCol:f,endRow:d,endCol:m}}const Oh=w("split-cell");function Nh(n,t,e){n.undoManager.runInGroup(()=>{const o=nt.fromBlock(t),r=o.getRealCell(e);u(Oh,!r.virtual,"should not split virtual cell"),u(Oh,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 p=f+r.row,A=m+r.col,k=wn(n.doc);i[p][A]=k}const s=n.getBlockData(t),l=Q.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=nt.virtualCellContainersGridToChildren(i);const a=n.getChildContainerData(r.containerId)[0];u(Oh,a,"no child block");const d=Ot(n,a.id,0);lr(l),n.updateBlockData(t,l,d)})}function DB(n,t,e){e.forEach(o=>{const r=nt.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Nh(n,t,o)})}function O5(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}=Rc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function Ph(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Rc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return DB(t,e,l),!0}const Yr=w("merge-cells");function N5(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}=Rc(e);return s.cell!==l.cell}function P5(n){const t=Rc(n),e=t.editor;e.undoManager.runInGroup(()=>{const o=t.endCell,r=o.row+o.rowSpan-1,i=o.col+o.colSpan-1,s=z(t.block);Ph(n);const l=e.getBlockById(s),c=jt(l),{startRow:a,startCol:d}=t,f=Q.default(e.getBlockData(l));u(Yr,f.children,"no table children");const m=nt.fromTable(c),p=[];for(let gt=a;gt<=r;gt++)for(let ht=d;ht<=i;ht++){const kt=m.getCell({row:gt,col:ht});u(Yr,!kt.virtual,"cell is virtual"),p.push(kt)}u(Yr,p.length>0,"no selected cells");const A=p[0],k=p.slice(1),y=m.getCellByContainerId(A.containerId).container,T=[];k.forEach(gt=>{const ht=m.getCellByContainerId(gt.containerId).container,kt=V(ht);if(!Fu(e,ht)){const ue=Y0(e,kt);e.insertDocAt(y,Ze(y),ue)}T.push(kt)});const E=V(y),L=i-d+1,R=r-a+1;f[`${E}_colSpan`]=L,f[`${E}_rowSpan`]=R,T.forEach(gt=>{u(Yr,f.children,"no table children");const ht=f.children.indexOf(gt);u(Yr,ht>0,"no deleted container"),f.children.splice(ht,1)});const _=f,it=e.getChildContainerData(E)[0];u(Yr,it,"no child block");const lt=Ot(e,it.id,0);lr(_),e.updateBlockData(l,_,lt),e.deleteChildContainers(T)})}const $h=10,LB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class _h{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(rt(e)!=="table")return[];const r={blockId:z(e),blockKind:Je(t,e),blockType:rt(e)},i=[];N5(t,e,o)&&i.push({id:"table/merge-cells",name:x.t("table.mergeCell"),icon:Aw,groupIndex:$h,...r}),O5(t,e,o)&&i.push({id:"table/split-cell",name:x.t("table.splitCell"),icon:bw,groupIndex:$h,...r});const s=M5(t,e,o),l=R5(t,e,o);return s&&l&&i.push({id:"table/delete",name:x.t("table.deleteTable"),icon:vw,groupIndex:$h,...r}),i}executeCommand(t,e,o,r,i,s){return rt(e)!=="table"||!new Set(LB).has(r.id)?!1:r.id==="table/merge-cells"?(P5(o),!0):r.id==="table/split-cell"?(Ph(o),!0):r.id==="table/delete-columns"?(Mh(o),!0):r.id==="table/delete-rows"?(Rh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var $5=(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))($5||{});const Fh=6,Ms=20,Hh="table-cell-menu-btn";function MB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function RB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function OB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function NB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function PB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function $B(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function _B(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const jh=w("get-selected-containers");function zh(n,t,e,o){u(jh,e.blockId===o.blockId,"only allow select in single table block"),u(jh,z(t)===e.blockId,"only allow select in single table block");const r=nt.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:d}=dn(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:d,col:c}).forEach(A=>{A.forEach(k=>{const y=r.getCellByContainerId(k.containerId);y.col<l||y.row<a||y.col+y.colSpan-1>c||y.row+y.rowSpan-1>d||f.has(k.containerId)||(f.add(k.containerId),m.push(y.container))})}),m}function FB(n,t,e){u(jh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return zh(n,o,t,e)}const cr=w("table-cell-dom");function HB(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");u(cr,r,"no parent cell");const i=U(r);if(u(cr,i,"no parent block"),i===t)return r;o=i}return u(cr,!1,"filed to get cell by child block id"),null}function Yn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return u(cr,e.childContainerId,"block position must have childContainerId attribute"),e;const r=HB(n,t,e.blockId),i=V(Ds(r));return wt(t,i)}function Uh(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return dn(t,o,r)}function _5(n,t,e,o){u(cr,Zt(t),"invalid table block");const r=Tn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");u(cr,l,"no top border bar container"),l.querySelectorAll(".table-border-bar-cell.top").forEach(a=>{const d=parseInt(a.getAttribute("data-top-index")||"0",10);o.includes(d)?M(a,"danger"):j(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");u(cr,l,"no left border bar container"),l.querySelectorAll(".table-border-bar-cell.left").forEach(a=>{const d=parseInt(a.getAttribute("data-left-index")||"0",10);e.includes(d)?M(a,"danger"):j(a,"danger")})};i(),s()}function Jr(n,t,e=!0,o){const i=nt.fromBlock(t).map(d=>d),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Uh(n,t);for(let d=0;d<i.length;d++){const f=i[d];for(let m=0;m<f.length;m++){const p=f[m],A=o?m>=s&&m+p.colSpan-1<=l:d>=c&&d+p.rowSpan-1<=a;e&&A?p.virtual||M(p.cell,"danger"):p.virtual||j(p.cell,"danger")}}}function Kr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){_5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Uh(n,t);if(o)for(let d=s;d<=l;d++)i.add(d);else for(let d=c;d<=a;d++)r.add(d);_5(n,t,Array.from(r),Array.from(i))}function F5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Uh(n,t),l=nt.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 jB(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return zh(n,t,o,r)}const H5=["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 j5(n){return`style-bg-color-${n}`}function Rs(n){return`${n}_background`}function zB(n,t,e){const o=jt(n),s=(e!=null?e:nt.fromTable(o)).getCell(t).cell;for(let l=0;l<H5.length;l++){const c=H5[l];if(ot(s,c))return c}}function z5(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Q.default(n.getBlockData(t))},s=Yn(n,t,o.start),l=Yn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[Rs(c)]=void 0:i[Rs(c)]=j5(e)}else{const c=nt.fromBlock(t),a=dn(t,s,l),d=new Set;for(let f=a.fromRow;f<=a.toRow;f++)for(let m=a.fromCol;m<=a.toCol;m++){const p=c.getCell({row:f,col:m});!d.has(p.containerId)&&p.col>=a.fromCol&&p.row>=a.fromRow&&p.col+p.colSpan-1<=a.toCol&&p.row+p.rowSpan-1<=a.toRow&&(d.add(p.containerId),e===-1?i[Rs(p.containerId)]=void 0:i[Rs(p.containerId)]=j5(e))}}n.updateBlockData(t,i)}function UB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const U5=w("table-chart");function VB(n,t){const e=Tn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function qB(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){VB(n,t);return}const r=[],i=nt.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 k=1;k<i.colCount;k++)c.push(i.getCell({row:0,col:k}).container.innerText);for(let k=1;k<i.rowCount;k++){const y=i.getCell({row:k,col:0}),E=y.container.innerText,L=[];for(let ue=1;ue<i.colCount;ue++){const ro=i.getCell({row:k,col:ue}).container.innerText,oe=Number.parseFloat(ro)||0;L.push(oe)}let R;const _=zB(t,y,i);_?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${_}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[W,it,lt,gt]=R?iu.fromString(R).toRgbaArray():[];if(!W&&!it&&!lt&&!gt){const ue=(k-1)%n.options.colors.length;R=n.options.colors[ue],[W,it,lt,gt]=iu.fromString(R).toRgbaArray()}const ht=R,kt=iu.fromRgba([W,it,lt,gt/3]).toHexString();r.push({label:E,data:L,borderColor:ht,backgroundColor:kt,borderWidth:2})}const a=Tn(n,t);let d=null,f=a.querySelector(".editor-table-chart");f?d=f.chartObject:f=b("div",["editor-table-chart"],a);const m=f;u(U5,m,"no chart container");const p=n.getComponentOptions("table"),A=(p==null?void 0:p.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await zo(A,"editor-chartjs"),d&&l!==d.config.type&&(d.destroy(),d=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(T=>{T.remove()}));const k=su.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(d)su.default(d.config,k),d.update();else{const T=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");d=new window.Chart(T,k),f.chartObject=d}}catch(k){U5.error(`failed to resolve chart cdn: ${JSON.stringify(k)}`)}}async function V5(n,t){await We.lock("updateTableChart");try{await qB(n,t)}finally{We.release("updateTableChart")}}const q5=te.default(V5,1e3);let W5=null;function Vh(n,t,e){if(W5!==t&&(q5.flush(),W5=t),e.updateNow){V5(n,t);return}q5(n,t)}function qh(n,t){Zt(t)&&Vh(n,t,{updateNow:!1})}function WB(n,t){Zt(t)&&Vh(n,t,{updateNow:!0})}const He={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"},Oc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},xo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Nc(n,t){return n.containers.get(t)}function G5(n){return n.closest(`.${xo.SCROLL_CONTAINER}`)}function hn(n){return n.firstElementChild}function Oe(n){return n.closest(`.${xo.CONTAINER}`)}function Os(n){const t=Oe(n);let e=t.querySelector(`:scope >.${xo.TOOL}`);return e||(e=b("div",[xo.TOOL],t)),e}function GB(n){return Oe(n).firstElementChild}function Pc(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}function je(n,t){const e=Pc(n);return t/e}function Ns(n){const t=window.getComputedStyle(n),e=Pc(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Xr(n){const t=Pc(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function ZB(n,t){const e=Pc(n);return n[t]*e}function Wh(n,t){const e=Oe(t),o=Nc(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 d=Math.floor(c.left-l.left-i);d<0&&(d=0);let f=l.right;f-=r;let m=f-c.right;return m<0&&(m=0),d=Math.round(d),m=Math.round(m),{originWidth:a,maxLeft:d,maxRight:m}}function QB(n,t){const e=Wh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${je(t,0-o)}px`,t.style.paddingLeft=`${je(t,o)}px`}function YB(n,t){const e=Wh(n,t);t.style.marginRight=`${je(t,0-e.maxRight)}px`}function JB(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 Z5=w("scroll-bar-handle"),KB=2;function ti(n){const t=Os(n);let e=t.querySelector(`.${Oc.SCROLL_BAR}`);return e||(e=b("div",[Oc.SCROLL_BAR],t)),u(Z5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function $c(n,t){const e=G5(t),o=ti(e),{scrollWidth:r,clientWidth:i}=Xr(e),{paddingLeft:s,paddingRight:l}=Ns(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const c=Wh(n,e),{originWidth:a,maxRight:d}=c;YB(n,e),QB(n,e);const f=r-i;u(Z5,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${je(e,a+d-s-l)}px`,o.firstElementChild.style.width=`${je(e,a+d+f-s-l)}px`}function XB(n,t){const e=hn(n),{paddingLeft:o}=Ns(e);if(ot(t,"fixed")){const i=Oe(n).getBoundingClientRect();t.style.left=`${je(n,i.left+o)}px`}else t.style.left=`${je(n,o)}px`}function ei(n,t){var E;const e=n.getParentScrollContainer(),o=JB(e),r=t.getBoundingClientRect(),i=ti(t),s=i.getBoundingClientRect(),l=Nc(n,Oe(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=hn(t),{paddingTop:d,paddingBottom:f}=Ns(a),{scrollWidth:m,clientWidth:p}=Xr(t),A=document.documentElement.clientHeight-c,k=o.top+Xr(e).clientHeight-A,y=A+Math.min(0,k);if(m>p&&r.top+d<y-s.height&&r.bottom>y-s.height+f&&!((E=l==null?void 0:l.isSetScale)!=null&&E.call(l))){M(i,Oc.FIXED);const L=k>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+KB+L}px`}else j(i,Oc.FIXED),i.style.bottom=`${je(t,f-s.height)}px`;XB(t,i)}class tE{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Oe(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;ei(this.scrollCore,e);const o=hn(e);$c(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 ar=w("container-scroll-shadow");function Q5(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=Ns(e);o.style.top=`${je(t,i.top-r.top+s)}px`,o.style.bottom=`${je(t,r.bottom-i.bottom+l)}px`}function Y5(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function eE(n){const t=Os(n);u(ar,t,"no container tools");let e=t.querySelector(`.${He.LEFT}`);if(!e){const l=hn(n),c=[He.COMMON,He.LEFT];e=b("div",c,t),u(ar,e instanceof HTMLDivElement,"invalid child for container tools"),Q5(e,n,l)}u(ar,e instanceof HTMLElement,"invalid child for container tools");const r=Oe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${je(n,i.left-r.left)}px`;const s=Xr(n).scrollLeft;u(ar,e instanceof HTMLDivElement,"invalid child for container tools"),Y5(e,s),M(e,He.ACTIVE)}function nE(n){const t=Os(n);let e=t.querySelector(`.${He.RIGHT}`);if(!e){const d=hn(n),f=[He.COMMON,He.RIGHT];e=b("div",f,t),u(ar,e instanceof HTMLDivElement,"no div, create shadow failed"),Q5(e,n,d)}u(ar,e instanceof HTMLElement,"");const r=Oe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${je(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Xr(n),a=s-l-c;u(ar,e instanceof HTMLDivElement,"no shadow element"),Y5(e,a),M(e,He.ACTIVE)}function oE(n){const e=Os(n).querySelector(`.${He.LEFT}`);e&&j(e,He.ACTIVE)}function rE(n){const e=Os(n).querySelector(`.${He.RIGHT}`);e&&j(e,He.ACTIVE)}function Ps(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Xr(n),r=hn(n),{paddingLeft:i,paddingRight:s}=Ns(r),l=ZB(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?rE(n):nE(n),r&&t>=l+i?eE(n):oE(n)}class iE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=hn(e);Ps(e),$c(this.scrollCore,o),ei(this.scrollCore,e),this.callback(e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Oe(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 J5=w("container-scroll-observer");class sE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;u(J5,e instanceof Element,"invalid target for scroll event");const o=ti(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),Ps(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;u(J5,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=GB(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),Ps(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",te.default(this.bindContentScrollCore,300));h(this,"bind",te.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=ti(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 lE{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{ei(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 cE=w("scroll-wrap-resize-observer");class aE{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Oe(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;u(cE,e instanceof HTMLElement,"invalid target for observer entry");const o=G5(e);$c(this.scrollCore,e),Ps(o),ei(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 uE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=hn(e);Ps(e),$c(this.scrollCore,o),ei(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=Oe(t),o=(r=Nc(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=Oe(t),o=(i=Nc(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 nV="";class dE 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=hn(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=>{ei(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new iE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new sE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new lE(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new aE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new uE(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,d;const r=ti(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),(d=this.locatingContainerResizeObserver)==null||d.unbind(e)}bindCore(e,o){var i,s,l,c,a,d;if(this.unbindCore(e,o),!e.closest("body"))return;const r=ti(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),(d=this.locatingContainerResizeObserver)==null||d.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new tE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=hn(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 K5=w("scroll-container"),_c=new Map;class hE 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",[xo.CONTAINER],e.parentElement);xt.isMac&&M(o,xo.MAC);const r=b("div",[xo.SCROLL_CONTAINER],o),i=b("div",[xo.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=_c.get(s),this.scrollListener||(this.scrollListener=new dE(s),_c.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 u(K5,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),hn(this.scrollContainerElement)}get scrollOptions(){return u(K5,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=Oe(this.contentElement);e&&_c.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),_c.delete(i))})}}function fE(){return new hE}const Fc=100,mE=40,Gh=w("column-width");function gE(n,t,e){vB(n,t).style.width=`${e}px`}function pE(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const o=nt.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)}),Gh.debug(`cellRightOffsets1: ${r.join()}`);for(let c=0;c<r.length;c++){const a=r[c];if(a===-1||c===0)continue;let d=c-1;for(;r[d]===-1&&(d--,d!==-1););const f=d===-1?0:r[d],p=(a-f)/(c-d);for(let A=d+1;A<c;A++)r[A]=f+p*(A-d)}Gh.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 Gh.debug(`widths: ${s.join()}`),s}function $s(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const CE=w("table-resize-gripper"),X5=7,Zh=(X5-1)/2,AE=3;function bE(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(),d=Math.round(a.right);if(Math.abs(t-d)<=Zh&&a.top<=e&&e<=a.bottom)return c}}return null}function vE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Qh(n,t){return Tn(n,t).querySelector(".table-resize-gripper")}function t4(n,t){const e=Qh(n,t);u(CE,!e,"resize gripper has already exists");const o=Tn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function e4(n,t,e){let o=Qh(n,t);o||(o=t4(n,t));const i=jt(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(Io(t)).contentElement.getBoundingClientRect(),d=s.right-a.left;o.style.left=`${d-Zh-Fh-Ms}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${X5}px`}function Yh(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function yE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function kE(n,t,e,o){const r=t,i=nt.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=$s(e);let a=o;const d=(m,p)=>{const A=p+1,k=m.col+m.colSpan;return c.slice(A,k).reduce((T,E)=>T+E,0)},f=new Set;for(let m=0;m<i.rowCount;m++){const p=i.getCell({row:m,col:l});if(f.has(p.cell))continue;f.add(p.cell);const A=p.cell,k=A.getBoundingClientRect();let y=o-k.left+Zh-AE;const T=Ds(A),E=_u(n,T)||mE*p.colSpan,L=d(p,l),R=E-L;y<R&&(y=R);const _=k.left+y;a=Math.max(a,_)}return a}const wE=w("table-resize-drag-drop");class BE{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,d=kE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;u(wE,c,"no dragging cell");const m=nt.fromTable(s).getCellByCellElement(c),p=m.col+m.colSpan-1,k=$s(s).slice(0,p).reduce((T,E)=>T+E,0),y=d-k;gE(s,p,y),e4(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=$s(t.data.table);yE(this.editor,t.data.block,s),Yh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function EE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=U(e);return!o||!n.contains(o)||!Zt(o)?null:o}w("table-resize");class IE{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=EE(t,i);if(!s||!D5(s)){Yh(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=bE(r,e,o);if(i){if(!Qh(this.editor,t)){if(vE(this.editor))return;const l=t4(this.editor,t),c={block:t,table:r,draggingRefCell:i};gu(new BE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}e4(this.editor,t,i)}else Yh(this.editor)}}function n4(n){n.addCustom("table-mouse-event-handler",t=>new IE(t))}const o4=w("table-insert-column");function r4(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.colCount;u(o4,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 p=s[m],A=p[e-1],k=p[e];if(e===0||e===p.length||A!==k){const y=wn(n.doc);p.splice(e,0,y)}else p.splice(e,0,A),l.add(A)}n.doc.endBatchUpdate();const c=Q.default(n.getBlockData(t));l.forEach(m=>{const p=`${m}_colSpan`,A=c[p];u(o4,typeof A=="number"&&A>1,`no colSpan for containerId ${m}, ${A}`),c[p]=A+1});const a=c.colsWidth.concat();a.splice(e,0,Fc);const d=nt.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:d,colsWidth:a};lr(f),n.updateBlockData(t,f)})}const Hc=w("table-insert-row");function i4(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.rowCount;u(Hc,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 p=e>0&&s[e-1][m],A=e<r.rowCount&&s[e][m];if(u(Hc,p||A,"no top and bottom cell"),e===0||e===r.rowCount||p!==A){const k=wn(n.doc);c.push(k)}else u(Hc,p,"no top cell"),c.push(p),l.add(p)}n.doc.endBatchUpdate(),s.splice(e,0,c);const a=Q.default(n.getBlockData(t));l.forEach(m=>{const p=`${m}_rowSpan`,A=a[p];u(Hc,typeof A=="number"&&A>1,`no rowSpan for containerId ${m}, ${A}`),a[p]=A+1});const d=nt.virtualCellContainersGridToChildren(s),f={...a,rows:a.rows+1,children:d};lr(f),n.updateBlockData(t,f)})}const Jh=w("paste-table-in-table-block");function xE(n,t,e,o){let r=nt.fromBlock(e);const i=t.blocks.root[0];u(Jh,i,"no table data"),u(Jh,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,d=l.col,f=l.row,m=d+c,p=f+a,A=[];for(let k=d;k<m&&k<r.colCount;k++)for(let y=f;y<p&&y<r.rowCount;y++){const T=r.getCell({col:k,row:y});T.virtual?T.virtual&&A.push({col:k,row:y}):(T.colSpan>1||T.rowSpan>1)&&A.push({col:k,row:y})}n.undoManager.runInGroup(()=>{if(A.forEach(E=>{const L=nt.fromBlock(e).getCell(E);(L.colSpan>1||L.rowSpan>1)&&Nh(n,e,E)}),m>r.colCount)for(let E=r.colCount;E<m;E++)r4(n,e,E);if(p>r.rowCount)for(let E=r.rowCount;E<p;E++)i4(n,e,E);r=nt.fromBlock(e);const k=new Dc(s);let y;for(let E=0;E<k.colCount;E++)for(let L=0;L<k.rowCount;L++){const R=k.getCell({col:E,row:L});if(!R.virtual){const _=Td(n.editorBlocks,t,R.containerId),W=d+E,it=f+L,lt={col:W,row:it},gt=r.getCellContainer(lt);r0(n,gt,_),y=gt}}u(Jh,y,"no last container");const T=Jt(y);n.selection.selectBlock(T,G(n,T))})}const s4=w("paste-in-table-block");class TE{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(Ct(i)||!Fu(t,i))return!1;const s=U(i);if(u(s4,s,"no parent block"),!Zt(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;s4.debug("paste child table in table");const a=nt.fromBlock(s).getCellByContainerId(V(i)).cell;return xE(t,e,s,a),!0}}function l4(n){n.addCustom("table-block-paste-event",t=>new TE(t))}const Kh=w("table-select-columns");function SE(n,t,e,o,r){u(Kh,Zt(t),"is not a table block");const i=nt.fromBlock(t);u(Kh,e>=0&&e<i.colCount,"invalid from"),u(Kh,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 Xh=w("table-select-columns");function DE(n,t,e,o,r){u(Xh,Zt(t),"is not a table block");const i=nt.fromBlock(t);u(Xh,e>=0&&e<i.rowCount,"invalid from"),u(Xh,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 oV="",c4=w("get-toolbar-reference-client");function LE(n,t){const e=n.selection.range;if(!e.isSimple()){u(c4,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);u(c4,ut(n,s),"not a complex block");const l=vt(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=uo(n,t.block,r);if(i.length!==0)return i[0]}function ME(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 jc(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=lu.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=jc(r),ME(s))}),e}function zc(n){return n.getCustom("toolbar-handler")}const rV="";class RE{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(x.t("link.urlPlaceholder")),new Error(x.t("link.urlPlaceholder"))}editLink(t){var d,f;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Es(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=(d=this.linkPopup)==null?void 0:d.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=Eh(o,{label:x.t("link.textLabel"),required:!1,placeholder:x.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Eh(o,{className:"link-popup-gap",label:x.t("link.urlLabel"),required:!0,placeholder:x.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,x.t("link.cancelText"));const i=b("button",["submit-button"],r,x.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 _s(n,t){n.addCustom("link-editor",()=>new RE).editLink(t)}const OE=w("link-popup");function NE(n){return ot(n,"link")}function Uc(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function PE(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&Pe(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(zi(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&&$(n,t)&&NE(e)?[{id:"link-text",name:Uc(e),disableTooltip:!0,element:b("span",["link-href-button"],null,Uc(e))},{id:"edit-link",name:"Edit",icon:wh},{id:"remove-link",name:"Remove link",icon:Sw}]:Sg(n,t,"hovering-toolbar")}function $E(n,t,e){var c;const o=go(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=Uc(e);_s(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,d)=>{try{const f=n.getBlockText(t),m=nd(f,o.start,o.end-o.start),p=Co(m,o.start,a,{link:d});n.setBlockText(t,p),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){OE.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function _E(n,t,e){const o=go(t,e),r=n.getBlockText(t),i=Uc(e),s=Or(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function FE(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&Pe(e)){const d=e,f=(l=(s=n.editorBoxes.getBoxClass(zi(d))).getBoxProperties)==null?void 0:l.call(s,n,d);if(f!=null&&f.boxCommands){f.boxCommands["hovering-toolbar"].executeCommand(n,t,d,o);return}return}const a=zc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?$E(n,t,e):o.id==="remove-link"&&_E(n,t,e);return}const r=Tg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function Vc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const HE=[fh,mh,gh,ph,Ch,Ah,bh,vh];class jE{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Vc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if($(t,e)){const r=z(e),i=rt(e),s=Je(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:x.t("commands.heading",{name:`${f+1}`}),icon:HE[f],states:c===f+1?["checked"]:[],value:`${f+1}`});const d=f=>{var p;const m=b("span",["toolbar-item-name-container"],null);for(const A of f.children)if((p=A.states)!=null&&p.includes("checked"))return m.innerHTML=A.icon||Sc,m;return m.innerHTML=Sc,m};return[{id:"turn-into",name:x.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:d,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:x.t("commands.text"),icon:Sc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if($(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 qc(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function zE(n,t){let e;const o=qc(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 a4(n,t){const e=qc(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 t1(n){return n.readonly||!n.isWritable()}function UE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&zE(n,o)}),!0}function VE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&a4(n,o)}),!0}function qE(n){return t1(n)?!1:n.undoManager.runInGroup(()=>(UE(n),!0))}function WE(n){return t1(n)?!1:n.undoManager.runInGroup(()=>(VE(n),!0))}function GE(n){if(t1(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!$(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!qc(t)))return a4(n,t),!0}class ZE{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const iV="",QE={Tab:qE,"Shift+Tab":WE,Backspace:GE},Wc=w("list-block");function at(n){return rt(n)==="list"}function zt(n){u(Wc,at(n),"not a list block")}function ze(n){zt(n);const t=n.getAttribute("data-list-type");return u(Wc,t,"no list type"),t}function Gc(n){return at(n)&&ze(n)==="text-only"}function fn(n){var t,e;return zt(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function Ae(n){var t,e;return zt(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function ni(n){zt(n);const t=n.getAttribute("data-list-group-id");return u(Wc,t,"no group id"),t}function To(n){var i,s,l,c,a;zt(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 u(Wc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function e1(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 Jn(n){zt(n);const{level:t,groupId:e,type:o}=To(n);let r=pt(n);for(;r;){if(!at(r))return null;const{level:i,groupId:s,type:l}=To(r);if(i<t)return null;if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;r=pt(r)}return null}function ur(n){zt(n);const{level:t,groupId:e,type:o}=To(n);let r=dt(n);for(;r;){if(at(r)){const{level:i,groupId:s,type:l}=To(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 u4(n){zt(n);const t=[];let e=Jn(n);for(;e;)t.unshift(e),e=Jn(e);return t}function Fs(n){zt(n);const t=[];let e=ur(n);for(;e;)t.push(e),e=ur(e);return t}function Hs(n){zt(n);let t=Jn(n);for(;t;){const e=Jn(t);if(!e)return t;t=e}return n}function YE(n){zt(n);let t=ur(n);for(;t;){const e=ur(t);if(!e)return t;t=e}return null}function d4(n,t){const e=u4(n),o=Fs(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function js(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:P();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 n1(n,t,e,o){const r=d4(t,{withSelf:!0});r.length!==0&&js(n,r,e,o)}function JE(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 KE="abcdefghijklmnopqrstuvwxyz";function h4(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=KE[t];return e?h4(e)+o:o}function XE(n){return`${n}`}const f4=[XE,h4,JE];function tI(n,t){const e=f4[(n-1)%f4.length];return e(t)}function eI(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class dr{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=Hs(e),i=fn(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||n1(this.editor,this.listBrother,this.listStart,this.options)}}function nI(n,t,e=1){if(!t)return null;let o=pt(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return at(o)?o:null}o=pt(o)}return null}function oI(n,t){const e=n.getAttribute("data-style-heading"),o=nI(n,e);if(o)return o;const r=pt(n);if(r&&at(r)&&ze(r)===t)return r;const i=dt(n);return i&&at(i)&&ze(i)===t?i:null}function rI(n,t,e){var k,y,T;const o=(k=e.data)!=null?k:{};let r=1;if(at(t))r=Ae(t);else{const E=qc(t);E&&(r=E+1),r>8&&(r=8)}const i=(y=o.listType)!=null?y:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(T=s.text)!=null?T:[],a=bt(l);const d=e.offset||0;d<=me(l)&&(l=ve(l,d).right,a=a.substring(0,d));let f=1;i==="ordered"&&(f=Number.parseInt(a,10)||1);let m=P();const p=oI(t,i);if(p){if(K(t)>K(p))f=fn(p)+1;else{const E=fn(p);E>1&&(f=E-1)}m=ni(p)}const A={id:P(),type:"list",level:r,start:f,groupId:m,ordered:!1,text:l};return s.quoted&&(A.quoted=!0),s.heading&&(A.heading=s.heading),i==="ordered"?A.ordered=!0:(i==="checked"||i==="unchecked")&&(A.checkbox=i),{blockData:A,onConverted:(E,L)=>{new dr(E,L).fix()}}}function oi(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function iI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${tI(t,(o=n.start)!=null?o:1)}.`:eI(t)}function Zc(n){return n==="checked"||n==="unchecked"}function m4(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=oi(r),a=oi(l);return c!==a&&(!Zc(c)||!Zc(a))||r.level>l.level}function g4(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=oi(r),a=oi(l);return c!==a&&(!Zc(c)||!Zc(a))||r.level>l.level}function sI(n,t,e,o,r){var s,l,c;const i=t;if(o==="text"){let a=((s=ye.convertTo)==null?void 0:s.call(ye,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 d=i.level||0;return a=(d>0?" ".repeat(d-1):"")+a,a}if(o==="markdown"){let a=((l=ye.convertTo)==null?void 0:l.call(ye,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 d=i.level||0;return a=(d>0?" ".repeat(d-1):"")+a,m4(n,t,e,r)&&(a=`${a}`),g4(n,t,e,r)&&(a=`${a}`,d<=1&&(a+=`
|
|
341
|
+
</svg>`;function tB(n,t){var e;if(M(t,"menu-item"),!n.element){if(n.type==="section"){const o=b("div",["section-name"],null,n.name);t.appendChild(o)}else if(n.type!=="separator"){if(n.icon){const 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=p5,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=Ow,t.appendChild(r)}}}}class sr extends Tc{constructor(t,e,o){super(t,e,{autoClose:!0,disablePageScroll:!0,...o})}manualShow(t,e){const o={theme:"menu",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"menu")}initItemElement(t,e){tB(t,e)}}function eB(n,t,e){var o;return new sr((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class Ts extends Tc{constructor(t,e,o){super(t,e,{itemElementTag:"button",tippyArrow:!1,...o})}getSubBarOptions(t){var r,i;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),a=s.getBoundingClientRect();return new DOMRect(a.left,c.top,a.width,c.height)};return{placement:(r=t.childrenPlacement)!=null?r:"top",getReferenceClientRect:e,offset:(i=t.childrenOffset)!=null?i:[0,4]}}manualShow(t,e){const o={theme:"toolbar",...e};super.manualShow(t,o)}initCommandBarElement(t){M(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),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=hh}t.states&&(t.states.indexOf("checked")!==-1&&M(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function nB(n,t,e){var o;return new Ts((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const KU="";Gr.registerManualCommandBar("menu",eB),Gr.registerManualCommandBar("toolbar",nB);const XU="",E5=w("ui-base");class Ss extends Tc{constructor(e,o){super(Ss.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){M(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];u(E5,e,"no dialog item");const o=e.element;return u(E5,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${P()}`,name:"",element:e}]}}const oB=[-1,6,0,1,2,3,4,5],rB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],I5=w("color-palette");function x5(n,t,e,o){u(I5,n>0,"no color in palette");const r=t||1;u(I5,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 d=e(l*i+a);c.appendChild(d)}}return s}function iB(n){const t=b("button",["color-button"],null),e=oB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=g5,t}function sB(n){const t=b("button",["background-color-button"],null),e=rB[n];return t.setAttribute("data-color-index",`${e}`),t}function lB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=x.t("colorPalette.reset"),n}function cB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.colorDesc")),t.appendChild(x5(8,1,iB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.backgroundDesc")),t.appendChild(x5(16,2,sB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(lB()),t}function aB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&j(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&M(i,"selected")}const tV="",uB={};class dB extends Yt.TypedEmitter{constructor(e=uB){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(ot(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)||(ot(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=cB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){aB(this.root,e,o)}}class T5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new dB(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function hB(){const n=b("button",["color-button"],null);return n.innerHTML=g5,n}function Bh(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 fB extends Yt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name",x.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],Bh(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new T5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=hB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Bh(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Bh(this.element,this.latestColors)}}const eV="";function Eh(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&M(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&M(o,"required");const r=b("div",["editor-input-container"],e),i=b("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=b("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),j(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{M(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function Ih(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 mB=w("ui-base");class gB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{Ih(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new sr([],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,d;if(((d=(a=this.options).onShow)==null?void 0:d.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)||G(this.editor,r)<o)return;const i=uo(this.editor,r,Ot(this.editor,r,o));if(i.length===0)return;const s=i[0],l=mo(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:x.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 We.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{We.release(e)}}highlightText(t){mB.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 d=0;for(d=0;d<=i.length-c;d){let f=i.substring(d,d+c);if(f.toLocaleLowerCase()===a){d+=c;const m=i.charAt(d);let p=!1;f.endsWith(" ")&&(p=!0,f=f.trimEnd()),l+=`<span class="highlight">${f}${m===" "||p?" ":""}</span>`}else l+=i.charAt(d),d++}return d<i.length&&(l+=i.substring(d)),l},r=i=>{if(ot(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 xh=w("auto-suggest-menu");class Th{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(bt(ve(ge(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=bt(oc(t,i,r));if(u(xh,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 gB(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)||Au(e.key)?!1:_m(e)&&!Vo(e)?(setTimeout(()=>{this.resetItems()}),!1):bu(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:z(t),offset:e,leftText:o,trigger:r};const i=V(H(t)),s=K(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var d;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(z(a)!==l)return!1;if((d=this.menu)!=null&&d.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=bt(oc(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 z(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=bt(oc(t,i,r));if(u(xh,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);xh.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 pB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const CB={"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"},...pB()};function Ce(n){var t;return(t=CB[n])==null?void 0:t.shortcut}function AB(n){var t;return(t=n.subText)!=null?t:""}const xn=w("table-dom");function Io(n){return`${z(n)}_scroll`}function jt(n){const t=n.querySelector("div[data-type=table-content] >table");return u(xn,t instanceof HTMLTableElement,"invalid table"),t}function Tn(n,t){const o=n.getCustom(Io(t)).contentElement.firstElementChild;u(xn,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")),u(xn,r,"no table tools"),r}function S5(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function Ds(n){const t=n.querySelector(":scope div[data-type=editor-container]");return u(xn,t,"no child container in cell"),t}function bB(n){const o=S5(n).map(r=>{const i=Ds(r),s=V(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return wr.default(o)}function Zt(n){return rt(n)==="table"}function Sh(n){const t=H(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?t:Sh(e)}function Qn(n){if(Zt(n))return n;const t=H(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?e:Qn(e)}function vB(n,t){const e=n.querySelector("colgroup");u(xn,e,"no colgroup");const o=e.children[t];return u(xn,o,"no col"),u(xn,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function D5(n){try{return jt(n),!0}catch{return!1}}function yB(n){return Rt(n).querySelector(":scope > .block-helper")}function L5(n){const t=U(n.contentElement);u(xn,t,"no block");const e=yB(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 kB{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){u(Re,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){u(Re,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return u(Re,e,"get cell, no cell"),e}getCellAllowEmpty(t){return u(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 Dc{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 kB(this.colCount));this.fillGrid(),u(Re,t.colsWidth,"no colsWidth"),u(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;u(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 d=0;d<s;d++)this._rows[o+a].setCell(e+d,{col:e,row:o,containerId:r,virtual:d!==0||a!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,o);c?(e=c.col,o=c.row):u(Re,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{u(Re,i,"no cell"),u(Re,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];u(Re,r,`get cell, no row: ${o}`);const i=r.getCell(e);return u(Re,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return u(Re,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Lc=w("table-data");function wB(n){const t=n.firstElementChild;return u(Lc,t,"no child element for cell"),u(Lc,vn(t),"cell first child is not a container"),u(Lc,Ye(t),"cell first child is not a container"),t}function BB(n){const t=U(n);u(Lc,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=wB(c),d=V(a);e.push(d),(c.colSpan>1||c.rowSpan>1)&&(o[`${d}_colSpan`]=c.colSpan,o[`${d}_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:z(t),type:rt(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function lr(n){return new Dc(n)}function EB(n){return lr(BB(n))}const Qt=w("table-grid"),IB=60;class xB{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 u(Qt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);u(Qt,t.length===1,"containers !== 1"),u(Qt,vn(t[0]),"not a container");const e=t[0];return u(Qt,Ye(e),"not a child container"),e}}class TB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new xB(t,o))})}get cells(){return this._cells}getCell(t){return u(Qt,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const zf=class{constructor(t){h(this,"_rows",[]);this.table=t,EB(t).forEach(r=>{this._rows.push(new TB(t,r))});const o=this.colCount;this._rows.forEach(r=>{u(Qt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(u(Qt,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return u(Qt,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){u(Qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,o=[];for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});o.push(i)}return o}toRealCells(t){const e=[];return t.forEach(o=>{const r=this.getRealCell(o);e.findIndex(i=>i.containerId===r.containerId)===-1&&e.push(r)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){u(Qt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let o=0;o<e;o++){const r=this.getCell({row:o,col:t});if(r.virtual||r.colSpan>1||r.rowSpan>1)return r}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const o=this.getCellById(e.containerId);return u(Qt,!o.virtual,"found a virtual cell"),o}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.col,o),r=Math.max(i.col+i.colSpan-1,r)}),u(Qt,o<=r,"min > max"),u(Qt,o>=0,"min < 0"),u(Qt,r<this.colCount,"max >= colCount"),[o,r]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.row,o),r=Math.max(i.row+i.rowSpan-1,r)}),u(Qt,o<=r,"min > max"),u(Qt,o>=0,"min < 0"),u(Qt,r<this.rowCount,"max >= rowCount"),[o,r]}getSpannedRange(t,e){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),i=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let p=o;p<=r;p++)for(let A=i;A<=s;A++)l.push(this.getCell({row:p,col:A}));const c=this.toRealCells(l);let a=1e4,d=1e4,f=-1,m=-1;return c.forEach(p=>{d=Math.min(p.col,d),a=Math.min(p.row,a),m=Math.max(p.col+p.colSpan-1,m),f=Math.max(p.row+p.rowSpan-1,f)}),[{row:a,col:d},{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),d=Math.max(i.col,s.col);for(let f=l;f<=c;f++)for(let m=a;m<=d;m++){const p=this.getCell({row:f,col:m});p.virtual||o.push(p)}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 u(Qt,o,"cell not found"),o}getCellByCellElement(t){const e=Ds(t);return this.getCellByContainerId(V(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=bB(t),o=this.caches.getSync(e,()=>(Qt.debug("create table grid"),new zf(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let nt=zf;h(nt,"caches",new pm(IB));function Mc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const SB=w("table-selection-range");function dn(n,t,e){var E,L,R,_;const o=nt.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),c=r.custom,a=i.custom,d=(E=c==null?void 0:c.rowIndex)!=null?E:s.row,f=(L=c==null?void 0:c.colIndex)!=null?L:s.col,m=(R=a==null?void 0:a.rowIndex)!=null?R:l.row+l.rowSpan-1,p=(_=a==null?void 0:a.colIndex)!=null?_:l.col+l.colSpan-1,A=Math.min(d,m),k=Math.max(d,m),y=Math.min(f,p),T=Math.max(f,p);return{fromRow:A,toRow:k,fromCol:y,toCol:T}}function Dh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===z(t)){const i=nt.fromBlock(t),{start:s,end:l}=r;u(SB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:d,toRow:f}=dn(t,s,l);if(d===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=d;m<=f;m++)e.add(m)}return{selectedRows:e,selectedColumns:o}}function Lh(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const o=n.getBlockById(t.start.blockId);if(Zt(o)){const r=H(o),i=U(r);i&&(e=Qn(i))}else e=Qn(o)}else{const o=n.getBlockById(t.start.blockId),r=Qn(o),i=n.getBlockById(t.end.blockId),s=Qn(i);r===s&&(e=r)}return e}const Zr=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}=dn(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.rowCount-1}function Mh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var L;const e=t.getBlockById(n.start.blockId);if(!M5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=dn(e,n.start,n.end),i=nt.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 W=o;W<=r;W++){const it=_[W];s.add(it)}_.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(R=>!c.has(R))),d=r-o+1,f=new Map,m=new Map;s.forEach(R=>{if(a.has(R))return;const _=i.getCellByContainerId(R);if(u(Zr,_.colSpan>1,"invalid effected cell, colSpan === 1"),_.col<o){u(Zr,c.has(R),"invalid effected cell, not exists");let kt=_.col+_.colSpan-1;kt>r&&(kt=r);const ue=kt-o+1,ro=_.colSpan-ue;f.set(R,ro);return}u(Zr,_.col<=r,"invalid effected cell, col > endCol");const W=_.col,it=_.col+_.colSpan-1,lt=_.col-o,gt=it-W+1-d+lt;u(Zr,gt>0,"invalid effected cell, newSpanned <= 0");const ht=wn(t.doc);m.set(R,{newContainerId:ht,colSpan:gt})});for(let R=0;R<l.length;R++){const _=l[R];for(let W=o;W<_.length;W++){const it=_[W],lt=m.get(it);lt&&(_[W]=lt.newContainerId)}}const p=Q.default(t.getBlockData(e));p.colsWidth.splice(o,r-o+1),a.forEach(R=>{Mc(p,R)}),f.forEach((R,_)=>{u(Zr,R>=1,"invalid modified colSpan, colSpan < 1"),R===1?p[`${_}_colSpan`]=void 0:p[`${_}_colSpan`]=R}),m.forEach((R,_)=>{Mc(p,_);const{newContainerId:W,colSpan:it}=R;u(Zr,it>=1,"invalid newContainerData, colSpan < 1"),it>1&&(p[`${W}_colSpan`]=it);const lt=i.getCellByContainerId(_).rowSpan;lt>1&&(p[`${W}_rowSpan`]=lt)});const k=(L=l[0][o])!=null?L:l[0][o-1],y=t.getChildContainerData(k)[0],T=nt.virtualCellContainersGridToChildren(l),E={...p,cols:p.cols-d,children:T};lr(E),t.updateBlockData(e,E,Ot(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Qr=w("delete-rows");function R5(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}=dn(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.colCount-1}function Rh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!R5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=dn(e,n.start,n.end),i=nt.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(E=>E.containerId);for(let E=r;E>=o;E--)l[E].forEach(R=>s.add(R)),l.splice(E,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(E=>!c.has(E))),d=r-o+1,f=new Map,m=new Map;s.forEach(E=>{if(a.has(E))return;const L=i.getCellByContainerId(E);if(u(Qr,L.rowSpan>1,"invalid effected cell, rowSpan === 1"),L.row<o){u(Qr,c.has(E),"invalid effected cell, not exists");let gt=L.row+L.rowSpan-1;gt>r&&(gt=r);const ht=gt-o+1,kt=L.rowSpan-ht;f.set(E,kt);return}u(Qr,L.row<=r,"invalid effected cell, col > endCol");const R=L.row,_=L.row+L.rowSpan-1,W=L.row-o,it=_-R+1-d+W;u(Qr,it>0,"invalid effected cell, newSpanned <= 0");const lt=wn(t.doc);m.set(E,{newContainerId:lt,rowSpan:it})});for(let E=o;E<l.length;E++){const L=l[E];for(let R=0;R<L.length;R++){const _=L[R],W=m.get(_);W&&(L[R]=W.newContainerId)}}const p=Q.default(t.getBlockData(e));a.forEach(E=>{Mc(p,E)}),f.forEach((E,L)=>{u(Qr,E>=1,"invalid modified rowSpan, rowSpan < 1"),E===1?delete p[`${L}_rowSpan`]:p[`${L}_rowSpan`]=E}),m.forEach((E,L)=>{Mc(p,L);const{newContainerId:R,rowSpan:_}=E;u(Qr,_>=1,"invalid newContainerData, rowSpan < 1"),_>1&&(p[`${R}_rowSpan`]=_);const W=i.getCellByContainerId(L).colSpan;W>1&&(p[`${R}_colSpan`]=W)});const A=l[o]?l[o][0]:l[o-1][0],k=t.getChildContainerData(A)[0],y=nt.virtualCellContainersGridToChildren(l),T={...p,rows:p.rows-d,children:y};lr(T),t.updateBlockData(e,T,Ot(t,k.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Ls=w("table-range");function Rc(n){u(Ls,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;u(Ls,!t.isSimple(),"invalid start pos type"),u(Ls,!e.isSimple(),"invalid end pos type");const o=n.getEditor();u(Ls,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);u(Ls,rt(r)==="table","invalid block type, not a table block");const i=jt(r),s=nt.fromTable(i),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),a=Math.min(l.row,c.row),d=Math.max(l.row,c.row),f=Math.min(l.col,c.col),m=Math.max(l.col,c.col),p=s.getCell({row:a,col:f}),A=s.getCell({row:d,col:m});return{editor:o,block:r,table:i,startCell:p,endCell:A,startRow:a,startCol:f,endRow:d,endCol:m}}const Oh=w("split-cell");function Nh(n,t,e){n.undoManager.runInGroup(()=>{const o=nt.fromBlock(t),r=o.getRealCell(e);u(Oh,!r.virtual,"should not split virtual cell"),u(Oh,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 p=f+r.row,A=m+r.col,k=wn(n.doc);i[p][A]=k}const s=n.getBlockData(t),l=Q.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=nt.virtualCellContainersGridToChildren(i);const a=n.getChildContainerData(r.containerId)[0];u(Oh,a,"no child block");const d=Ot(n,a.id,0);lr(l),n.updateBlockData(t,l,d)})}function DB(n,t,e){e.forEach(o=>{const r=nt.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Nh(n,t,o)})}function O5(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}=Rc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function Ph(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Rc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return DB(t,e,l),!0}const Yr=w("merge-cells");function N5(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}=Rc(e);return s.cell!==l.cell}function P5(n){const t=Rc(n),e=t.editor;e.undoManager.runInGroup(()=>{const o=t.endCell,r=o.row+o.rowSpan-1,i=o.col+o.colSpan-1,s=z(t.block);Ph(n);const l=e.getBlockById(s),c=jt(l),{startRow:a,startCol:d}=t,f=Q.default(e.getBlockData(l));u(Yr,f.children,"no table children");const m=nt.fromTable(c),p=[];for(let gt=a;gt<=r;gt++)for(let ht=d;ht<=i;ht++){const kt=m.getCell({row:gt,col:ht});u(Yr,!kt.virtual,"cell is virtual"),p.push(kt)}u(Yr,p.length>0,"no selected cells");const A=p[0],k=p.slice(1),y=m.getCellByContainerId(A.containerId).container,T=[];k.forEach(gt=>{const ht=m.getCellByContainerId(gt.containerId).container,kt=V(ht);if(!Fu(e,ht)){const ue=Y0(e,kt);e.insertDocAt(y,Ze(y),ue)}T.push(kt)});const E=V(y),L=i-d+1,R=r-a+1;f[`${E}_colSpan`]=L,f[`${E}_rowSpan`]=R,T.forEach(gt=>{u(Yr,f.children,"no table children");const ht=f.children.indexOf(gt);u(Yr,ht>0,"no deleted container"),f.children.splice(ht,1)});const _=f,it=e.getChildContainerData(E)[0];u(Yr,it,"no child block");const lt=Ot(e,it.id,0);lr(_),e.updateBlockData(l,_,lt),e.deleteChildContainers(T)})}const $h=10,LB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class _h{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(rt(e)!=="table")return[];const r={blockId:z(e),blockKind:Je(t,e),blockType:rt(e)},i=[];N5(t,e,o)&&i.push({id:"table/merge-cells",name:x.t("table.mergeCell"),icon:Aw,groupIndex:$h,...r}),O5(t,e,o)&&i.push({id:"table/split-cell",name:x.t("table.splitCell"),icon:bw,groupIndex:$h,...r});const s=M5(t,e,o),l=R5(t,e,o);return s&&l&&i.push({id:"table/delete",name:x.t("table.deleteTable"),icon:vw,groupIndex:$h,...r}),i}executeCommand(t,e,o,r,i,s){return rt(e)!=="table"||!new Set(LB).has(r.id)?!1:r.id==="table/merge-cells"?(P5(o),!0):r.id==="table/split-cell"?(Ph(o),!0):r.id==="table/delete-columns"?(Mh(o),!0):r.id==="table/delete-rows"?(Rh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var $5=(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))($5||{});const Fh=6,Ms=20,Hh="table-cell-menu-btn";function MB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function RB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function OB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function NB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function PB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function $B(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function _B(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const jh=w("get-selected-containers");function zh(n,t,e,o){u(jh,e.blockId===o.blockId,"only allow select in single table block"),u(jh,z(t)===e.blockId,"only allow select in single table block");const r=nt.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:d}=dn(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:d,col:c}).forEach(A=>{A.forEach(k=>{const y=r.getCellByContainerId(k.containerId);y.col<l||y.row<a||y.col+y.colSpan-1>c||y.row+y.rowSpan-1>d||f.has(k.containerId)||(f.add(k.containerId),m.push(y.container))})}),m}function FB(n,t,e){u(jh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return zh(n,o,t,e)}const cr=w("table-cell-dom");function HB(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");u(cr,r,"no parent cell");const i=U(r);if(u(cr,i,"no parent block"),i===t)return r;o=i}return u(cr,!1,"filed to get cell by child block id"),null}function Yn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return u(cr,e.childContainerId,"block position must have childContainerId attribute"),e;const r=HB(n,t,e.blockId),i=V(Ds(r));return wt(t,i)}function Uh(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return dn(t,o,r)}function _5(n,t,e,o){u(cr,Zt(t),"invalid table block");const r=Tn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");u(cr,l,"no top border bar container"),l.querySelectorAll(".table-border-bar-cell.top").forEach(a=>{const d=parseInt(a.getAttribute("data-top-index")||"0",10);o.includes(d)?M(a,"danger"):j(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");u(cr,l,"no left border bar container"),l.querySelectorAll(".table-border-bar-cell.left").forEach(a=>{const d=parseInt(a.getAttribute("data-left-index")||"0",10);e.includes(d)?M(a,"danger"):j(a,"danger")})};i(),s()}function Jr(n,t,e=!0,o){const i=nt.fromBlock(t).map(d=>d),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Uh(n,t);for(let d=0;d<i.length;d++){const f=i[d];for(let m=0;m<f.length;m++){const p=f[m],A=o?m>=s&&m+p.colSpan-1<=l:d>=c&&d+p.rowSpan-1<=a;e&&A?p.virtual||M(p.cell,"danger"):p.virtual||j(p.cell,"danger")}}}function Kr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){_5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Uh(n,t);if(o)for(let d=s;d<=l;d++)i.add(d);else for(let d=c;d<=a;d++)r.add(d);_5(n,t,Array.from(r),Array.from(i))}function F5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Uh(n,t),l=nt.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 jB(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return zh(n,t,o,r)}const H5=["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 j5(n){return`style-bg-color-${n}`}function Rs(n){return`${n}_background`}function zB(n,t,e){const o=jt(n),s=(e!=null?e:nt.fromTable(o)).getCell(t).cell;for(let l=0;l<H5.length;l++){const c=H5[l];if(ot(s,c))return c}}function z5(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Q.default(n.getBlockData(t))},s=Yn(n,t,o.start),l=Yn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[Rs(c)]=void 0:i[Rs(c)]=j5(e)}else{const c=nt.fromBlock(t),a=dn(t,s,l),d=new Set;for(let f=a.fromRow;f<=a.toRow;f++)for(let m=a.fromCol;m<=a.toCol;m++){const p=c.getCell({row:f,col:m});!d.has(p.containerId)&&p.col>=a.fromCol&&p.row>=a.fromRow&&p.col+p.colSpan-1<=a.toCol&&p.row+p.rowSpan-1<=a.toRow&&(d.add(p.containerId),e===-1?i[Rs(p.containerId)]=void 0:i[Rs(p.containerId)]=j5(e))}}n.updateBlockData(t,i)}function UB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const U5=w("table-chart");function VB(n,t){const e=Tn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function qB(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){VB(n,t);return}const r=[],i=nt.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 k=1;k<i.colCount;k++)c.push(i.getCell({row:0,col:k}).container.innerText);for(let k=1;k<i.rowCount;k++){const y=i.getCell({row:k,col:0}),E=y.container.innerText,L=[];for(let ue=1;ue<i.colCount;ue++){const ro=i.getCell({row:k,col:ue}).container.innerText,oe=Number.parseFloat(ro)||0;L.push(oe)}let R;const _=zB(t,y,i);_?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${_}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[W,it,lt,gt]=R?iu.fromString(R).toRgbaArray():[];if(!W&&!it&&!lt&&!gt){const ue=(k-1)%n.options.colors.length;R=n.options.colors[ue],[W,it,lt,gt]=iu.fromString(R).toRgbaArray()}const ht=R,kt=iu.fromRgba([W,it,lt,gt/3]).toHexString();r.push({label:E,data:L,borderColor:ht,backgroundColor:kt,borderWidth:2})}const a=Tn(n,t);let d=null,f=a.querySelector(".editor-table-chart");f?d=f.chartObject:f=b("div",["editor-table-chart"],a);const m=f;u(U5,m,"no chart container");const p=n.getComponentOptions("table"),A=(p==null?void 0:p.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await zo(A,"editor-chartjs"),d&&l!==d.config.type&&(d.destroy(),d=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(T=>{T.remove()}));const k=su.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(d)su.default(d.config,k),d.update();else{const T=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");d=new window.Chart(T,k),f.chartObject=d}}catch(k){U5.error(`failed to resolve chart cdn: ${JSON.stringify(k)}`)}}async function V5(n,t){await We.lock("updateTableChart");try{await qB(n,t)}finally{We.release("updateTableChart")}}const q5=te.default(V5,1e3);let W5=null;function Vh(n,t,e){if(W5!==t&&(q5.flush(),W5=t),e.updateNow){V5(n,t);return}q5(n,t)}function qh(n,t){Zt(t)&&Vh(n,t,{updateNow:!1})}function WB(n,t){Zt(t)&&Vh(n,t,{updateNow:!0})}const He={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"},Oc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},xo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Nc(n,t){return n.containers.get(t)}function G5(n){return n.closest(`.${xo.SCROLL_CONTAINER}`)}function hn(n){return n.firstElementChild}function Oe(n){return n.closest(`.${xo.CONTAINER}`)}function Os(n){const t=Oe(n);let e=t.querySelector(`:scope >.${xo.TOOL}`);return e||(e=b("div",[xo.TOOL],t)),e}function GB(n){return Oe(n).firstElementChild}function Pc(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}function je(n,t){const e=Pc(n);return t/e}function Ns(n){const t=window.getComputedStyle(n),e=Pc(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Xr(n){const t=Pc(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function ZB(n,t){const e=Pc(n);return n[t]*e}function Wh(n,t){const e=Oe(t),o=Nc(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 d=Math.floor(c.left-l.left-i);d<0&&(d=0);let f=l.right;f-=r;let m=f-c.right;return m<0&&(m=0),d=Math.round(d),m=Math.round(m),{originWidth:a,maxLeft:d,maxRight:m}}function QB(n,t){const e=Wh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${je(t,0-o)}px`,t.style.paddingLeft=`${je(t,o)}px`}function YB(n,t){const e=Wh(n,t);t.style.marginRight=`${je(t,0-e.maxRight)}px`}function JB(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 Z5=w("scroll-bar-handle"),KB=2;function ti(n){const t=Os(n);let e=t.querySelector(`.${Oc.SCROLL_BAR}`);return e||(e=b("div",[Oc.SCROLL_BAR],t)),u(Z5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function $c(n,t){const e=G5(t),o=ti(e),{scrollWidth:r,clientWidth:i}=Xr(e),{paddingLeft:s,paddingRight:l}=Ns(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const c=Wh(n,e),{originWidth:a,maxRight:d}=c;YB(n,e),QB(n,e);const f=r-i;u(Z5,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${je(e,a+d-s-l)}px`,o.firstElementChild.style.width=`${je(e,a+d+f-s-l)}px`}function XB(n,t){const e=hn(n),{paddingLeft:o}=Ns(e);if(ot(t,"fixed")){const i=Oe(n).getBoundingClientRect();t.style.left=`${je(n,i.left+o)}px`}else t.style.left=`${je(n,o)}px`}function ei(n,t){var E;const e=n.getParentScrollContainer(),o=JB(e),r=t.getBoundingClientRect(),i=ti(t),s=i.getBoundingClientRect(),l=Nc(n,Oe(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=hn(t),{paddingTop:d,paddingBottom:f}=Ns(a),{scrollWidth:m,clientWidth:p}=Xr(t),A=document.documentElement.clientHeight-c,k=o.top+Xr(e).clientHeight-A,y=A+Math.min(0,k);if(m>p&&r.top+d<y-s.height&&r.bottom>y-s.height+f&&!((E=l==null?void 0:l.isSetScale)!=null&&E.call(l))){M(i,Oc.FIXED);const L=k>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+KB+L}px`}else j(i,Oc.FIXED),i.style.bottom=`${je(t,f-s.height)}px`;XB(t,i)}class tE{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Oe(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;ei(this.scrollCore,e);const o=hn(e);$c(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 ar=w("container-scroll-shadow");function Q5(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=Ns(e);o.style.top=`${je(t,i.top-r.top+s)}px`,o.style.bottom=`${je(t,r.bottom-i.bottom+l)}px`}function Y5(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function eE(n){const t=Os(n);u(ar,t,"no container tools");let e=t.querySelector(`.${He.LEFT}`);if(!e){const l=hn(n),c=[He.COMMON,He.LEFT];e=b("div",c,t),u(ar,e instanceof HTMLDivElement,"invalid child for container tools"),Q5(e,n,l)}u(ar,e instanceof HTMLElement,"invalid child for container tools");const r=Oe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${je(n,i.left-r.left)}px`;const s=Xr(n).scrollLeft;u(ar,e instanceof HTMLDivElement,"invalid child for container tools"),Y5(e,s),M(e,He.ACTIVE)}function nE(n){const t=Os(n);let e=t.querySelector(`.${He.RIGHT}`);if(!e){const d=hn(n),f=[He.COMMON,He.RIGHT];e=b("div",f,t),u(ar,e instanceof HTMLDivElement,"no div, create shadow failed"),Q5(e,n,d)}u(ar,e instanceof HTMLElement,"");const r=Oe(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${je(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Xr(n),a=s-l-c;u(ar,e instanceof HTMLDivElement,"no shadow element"),Y5(e,a),M(e,He.ACTIVE)}function oE(n){const e=Os(n).querySelector(`.${He.LEFT}`);e&&j(e,He.ACTIVE)}function rE(n){const e=Os(n).querySelector(`.${He.RIGHT}`);e&&j(e,He.ACTIVE)}function Ps(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Xr(n),r=hn(n),{paddingLeft:i,paddingRight:s}=Ns(r),l=ZB(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?rE(n):nE(n),r&&t>=l+i?eE(n):oE(n)}class iE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=hn(e);Ps(e),$c(this.scrollCore,o),ei(this.scrollCore,e),this.callback(e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Oe(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 J5=w("container-scroll-observer");class sE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;u(J5,e instanceof Element,"invalid target for scroll event");const o=ti(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),Ps(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;u(J5,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=GB(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),Ps(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",te.default(this.bindContentScrollCore,300));h(this,"bind",te.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=ti(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 lE{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{ei(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 cE=w("scroll-wrap-resize-observer");class aE{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Oe(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;u(cE,e instanceof HTMLElement,"invalid target for observer entry");const o=G5(e);$c(this.scrollCore,e),Ps(o),ei(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 uE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=hn(e);Ps(e),$c(this.scrollCore,o),ei(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=Oe(t),o=(r=Nc(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=Oe(t),o=(i=Nc(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 nV="";class dE 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=hn(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=>{ei(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new iE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new sE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new lE(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new aE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new uE(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,d;const r=ti(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),(d=this.locatingContainerResizeObserver)==null||d.unbind(e)}bindCore(e,o){var i,s,l,c,a,d;if(this.unbindCore(e,o),!e.closest("body"))return;const r=ti(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),(d=this.locatingContainerResizeObserver)==null||d.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new tE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=hn(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 K5=w("scroll-container"),_c=new Map;class hE 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",[xo.CONTAINER],e.parentElement);xt.isMac&&M(o,xo.MAC);const r=b("div",[xo.SCROLL_CONTAINER],o),i=b("div",[xo.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=_c.get(s),this.scrollListener||(this.scrollListener=new dE(s),_c.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 u(K5,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),hn(this.scrollContainerElement)}get scrollOptions(){return u(K5,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=Oe(this.contentElement);e&&_c.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),_c.delete(i))})}}function fE(){return new hE}const Fc=100,mE=40,Gh=w("column-width");function gE(n,t,e){vB(n,t).style.width=`${e}px`}function pE(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const o=nt.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)}),Gh.debug(`cellRightOffsets1: ${r.join()}`);for(let c=0;c<r.length;c++){const a=r[c];if(a===-1||c===0)continue;let d=c-1;for(;r[d]===-1&&(d--,d!==-1););const f=d===-1?0:r[d],p=(a-f)/(c-d);for(let A=d+1;A<c;A++)r[A]=f+p*(A-d)}Gh.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 Gh.debug(`widths: ${s.join()}`),s}function $s(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const CE=w("table-resize-gripper"),X5=7,Zh=(X5-1)/2,AE=3;function bE(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(),d=Math.round(a.right);if(Math.abs(t-d)<=Zh&&a.top<=e&&e<=a.bottom)return c}}return null}function vE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Qh(n,t){return Tn(n,t).querySelector(".table-resize-gripper")}function t4(n,t){const e=Qh(n,t);u(CE,!e,"resize gripper has already exists");const o=Tn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function e4(n,t,e){let o=Qh(n,t);o||(o=t4(n,t));const i=jt(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(Io(t)).contentElement.getBoundingClientRect(),d=s.right-a.left;o.style.left=`${d-Zh-Fh-Ms}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${X5}px`}function Yh(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function yE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function kE(n,t,e,o){const r=t,i=nt.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=$s(e);let a=o;const d=(m,p)=>{const A=p+1,k=m.col+m.colSpan;return c.slice(A,k).reduce((T,E)=>T+E,0)},f=new Set;for(let m=0;m<i.rowCount;m++){const p=i.getCell({row:m,col:l});if(f.has(p.cell))continue;f.add(p.cell);const A=p.cell,k=A.getBoundingClientRect();let y=o-k.left+Zh-AE;const T=Ds(A),E=_u(n,T)||mE*p.colSpan,L=d(p,l),R=E-L;y<R&&(y=R);const _=k.left+y;a=Math.max(a,_)}return a}const wE=w("table-resize-drag-drop");class BE{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,d=kE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;u(wE,c,"no dragging cell");const m=nt.fromTable(s).getCellByCellElement(c),p=m.col+m.colSpan-1,k=$s(s).slice(0,p).reduce((T,E)=>T+E,0),y=d-k;gE(s,p,y),e4(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=$s(t.data.table);yE(this.editor,t.data.block,s),Yh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function EE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=U(e);return!o||!n.contains(o)||!Zt(o)?null:o}w("table-resize");class IE{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=EE(t,i);if(!s||!D5(s)){Yh(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=bE(r,e,o);if(i){if(!Qh(this.editor,t)){if(vE(this.editor))return;const l=t4(this.editor,t),c={block:t,table:r,draggingRefCell:i};gu(new BE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}e4(this.editor,t,i)}else Yh(this.editor)}}function n4(n){n.addCustom("table-mouse-event-handler",t=>new IE(t))}const o4=w("table-insert-column");function r4(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.colCount;u(o4,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 p=s[m],A=p[e-1],k=p[e];if(e===0||e===p.length||A!==k){const y=wn(n.doc);p.splice(e,0,y)}else p.splice(e,0,A),l.add(A)}n.doc.endBatchUpdate();const c=Q.default(n.getBlockData(t));l.forEach(m=>{const p=`${m}_colSpan`,A=c[p];u(o4,typeof A=="number"&&A>1,`no colSpan for containerId ${m}, ${A}`),c[p]=A+1});const a=c.colsWidth.concat();a.splice(e,0,Fc);const d=nt.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:d,colsWidth:a};lr(f),n.updateBlockData(t,f)})}const Hc=w("table-insert-row");function i4(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.rowCount;u(Hc,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 p=e>0&&s[e-1][m],A=e<r.rowCount&&s[e][m];if(u(Hc,p||A,"no top and bottom cell"),e===0||e===r.rowCount||p!==A){const k=wn(n.doc);c.push(k)}else u(Hc,p,"no top cell"),c.push(p),l.add(p)}n.doc.endBatchUpdate(),s.splice(e,0,c);const a=Q.default(n.getBlockData(t));l.forEach(m=>{const p=`${m}_rowSpan`,A=a[p];u(Hc,typeof A=="number"&&A>1,`no rowSpan for containerId ${m}, ${A}`),a[p]=A+1});const d=nt.virtualCellContainersGridToChildren(s),f={...a,rows:a.rows+1,children:d};lr(f),n.updateBlockData(t,f)})}const Jh=w("paste-table-in-table-block");function xE(n,t,e,o){let r=nt.fromBlock(e);const i=t.blocks.root[0];u(Jh,i,"no table data"),u(Jh,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,d=l.col,f=l.row,m=d+c,p=f+a,A=[];for(let k=d;k<m&&k<r.colCount;k++)for(let y=f;y<p&&y<r.rowCount;y++){const T=r.getCell({col:k,row:y});T.virtual?T.virtual&&A.push({col:k,row:y}):(T.colSpan>1||T.rowSpan>1)&&A.push({col:k,row:y})}n.undoManager.runInGroup(()=>{if(A.forEach(E=>{const L=nt.fromBlock(e).getCell(E);(L.colSpan>1||L.rowSpan>1)&&Nh(n,e,E)}),m>r.colCount)for(let E=r.colCount;E<m;E++)r4(n,e,E);if(p>r.rowCount)for(let E=r.rowCount;E<p;E++)i4(n,e,E);r=nt.fromBlock(e);const k=new Dc(s);let y;for(let E=0;E<k.colCount;E++)for(let L=0;L<k.rowCount;L++){const R=k.getCell({col:E,row:L});if(!R.virtual){const _=Td(n.editorBlocks,t,R.containerId),W=d+E,it=f+L,lt={col:W,row:it},gt=r.getCellContainer(lt);r0(n,gt,_),y=gt}}u(Jh,y,"no last container");const T=Jt(y);n.selection.selectBlock(T,G(n,T))})}const s4=w("paste-in-table-block");class TE{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(Ct(i)||!Fu(t,i))return!1;const s=U(i);if(u(s4,s,"no parent block"),!Zt(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;s4.debug("paste child table in table");const a=nt.fromBlock(s).getCellByContainerId(V(i)).cell;return xE(t,e,s,a),!0}}function l4(n){n.addCustom("table-block-paste-event",t=>new TE(t))}const Kh=w("table-select-columns");function SE(n,t,e,o,r){u(Kh,Zt(t),"is not a table block");const i=nt.fromBlock(t);u(Kh,e>=0&&e<i.colCount,"invalid from"),u(Kh,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 Xh=w("table-select-columns");function DE(n,t,e,o,r){u(Xh,Zt(t),"is not a table block");const i=nt.fromBlock(t);u(Xh,e>=0&&e<i.rowCount,"invalid from"),u(Xh,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 oV="",c4=w("get-toolbar-reference-client");function LE(n,t){const e=n.selection.range;if(!e.isSimple()){u(c4,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);u(c4,ut(n,s),"not a complex block");const l=vt(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=uo(n,t.block,r);if(i.length!==0)return i[0]}function ME(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 jc(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=lu.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=jc(r),ME(s))}),e}function zc(n){return n.getCustom("toolbar-handler")}const rV="";class RE{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(x.t("link.urlPlaceholder")),new Error(x.t("link.urlPlaceholder"))}editLink(t){var d,f;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Es(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=(d=this.linkPopup)==null?void 0:d.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=Eh(o,{label:x.t("link.textLabel"),required:!1,placeholder:x.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Eh(o,{className:"link-popup-gap",label:x.t("link.urlLabel"),required:!0,placeholder:x.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,x.t("link.cancelText"));const i=b("button",["submit-button"],r,x.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 _s(n,t){n.addCustom("link-editor",()=>new RE).editLink(t)}const OE=w("link-popup");function NE(n){return ot(n,"link")}function Uc(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function PE(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&Pe(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(zi(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&&$(n,t)&&NE(e)?[{id:"link-text",name:Uc(e),disableTooltip:!0,element:b("span",["link-href-button"],null,Uc(e))},{id:"edit-link",name:"Edit",icon:wh},{id:"remove-link",name:"Remove link",icon:Sw}]:Sg(n,t,"hovering-toolbar")}function $E(n,t,e){var c;const o=go(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=Uc(e);_s(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,d)=>{try{const f=n.getBlockText(t),m=nd(f,o.start,o.end-o.start),p=Co(m,o.start,a,{link:d});n.setBlockText(t,p),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){OE.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function _E(n,t,e){const o=go(t,e),r=n.getBlockText(t),i=Uc(e),s=Or(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function FE(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&Pe(e)){const d=e,f=(l=(s=n.editorBoxes.getBoxClass(zi(d))).getBoxProperties)==null?void 0:l.call(s,n,d);if(f!=null&&f.boxCommands){f.boxCommands["hovering-toolbar"].executeCommand(n,t,d,o);return}return}const a=zc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?$E(n,t,e):o.id==="remove-link"&&_E(n,t,e);return}const r=Tg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function Vc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const HE=[fh,mh,gh,ph,Ch,Ah,bh,vh];class jE{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Vc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if($(t,e)){const r=z(e),i=rt(e),s=Je(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:x.t("commands.heading",{name:`${f+1}`}),icon:HE[f],states:c===f+1?["checked"]:[],value:`${f+1}`});const d=f=>{var p;const m=b("span",["toolbar-item-name-container"],null);for(const A of f.children)if((p=A.states)!=null&&p.includes("checked"))return m.innerHTML=A.icon||Sc,m;return m.innerHTML=Sc,m};return[{id:"turn-into",name:x.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:d,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:x.t("commands.text"),icon:Sc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if($(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 qc(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function zE(n,t){let e;const o=qc(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 a4(n,t){const e=qc(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 t1(n){return n.readonly||!n.isWritable()}function UE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&zE(n,o)}),!0}function VE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&a4(n,o)}),!0}function qE(n){return t1(n)?!1:n.undoManager.runInGroup(()=>(UE(n),!0))}function WE(n){return t1(n)?!1:n.undoManager.runInGroup(()=>(VE(n),!0))}function GE(n){if(t1(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!$(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!qc(t)))return a4(n,t),!0}class ZE{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const iV="",QE={Tab:qE,"Shift+Tab":WE,Backspace:GE},Wc=w("list-block");function at(n){return rt(n)==="list"}function zt(n){u(Wc,at(n),"not a list block")}function ze(n){zt(n);const t=n.getAttribute("data-list-type");return u(Wc,t,"no list type"),t}function Gc(n){return at(n)&&ze(n)==="text-only"}function fn(n){var t,e;return zt(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function Ae(n){var t,e;return zt(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function ni(n){zt(n);const t=n.getAttribute("data-list-group-id");return u(Wc,t,"no group id"),t}function To(n){var i,s,l,c,a;zt(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 u(Wc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function e1(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 Jn(n){zt(n);const{level:t,groupId:e,type:o}=To(n);let r=pt(n);for(;r;){if(!at(r))return null;const{level:i,groupId:s,type:l}=To(r);if(i<t)return null;if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;r=pt(r)}return null}function ur(n){zt(n);const{level:t,groupId:e,type:o}=To(n);let r=dt(n);for(;r;){if(at(r)){const{level:i,groupId:s,type:l}=To(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 u4(n){zt(n);const t=[];let e=Jn(n);for(;e;)t.unshift(e),e=Jn(e);return t}function Fs(n){zt(n);const t=[];let e=ur(n);for(;e;)t.push(e),e=ur(e);return t}function Hs(n){zt(n);let t=Jn(n);for(;t;){const e=Jn(t);if(!e)return t;t=e}return n}function YE(n){zt(n);let t=ur(n);for(;t;){const e=ur(t);if(!e)return t;t=e}return null}function d4(n,t){const e=u4(n),o=Fs(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function js(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:P();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 n1(n,t,e,o){const r=d4(t,{withSelf:!0});r.length!==0&&js(n,r,e,o)}function JE(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 KE="abcdefghijklmnopqrstuvwxyz";function h4(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=KE[t];return e?h4(e)+o:o}function XE(n){return`${n}`}const f4=[XE,h4,JE];function tI(n,t){const e=f4[(n-1)%f4.length];return e(t)}function eI(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class dr{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=Hs(e),i=fn(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||n1(this.editor,this.listBrother,this.listStart,this.options)}}function nI(n,t,e=1){if(!t)return null;let o=pt(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return at(o)?o:null}o=pt(o)}return null}function oI(n,t){const e=n.getAttribute("data-style-heading"),o=nI(n,e);if(o)return o;const r=pt(n);if(r&&at(r)&&ze(r)===t)return r;const i=dt(n);return i&&at(i)&&ze(i)===t?i:null}function rI(n,t,e){var k,y,T;const o=(k=e.data)!=null?k:{};let r=1;if(at(t))r=Ae(t);else{const E=qc(t);E&&(r=E+1),r>8&&(r=8)}const i=(y=o.listType)!=null?y:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(T=s.text)!=null?T:[],a=bt(l);const d=e.offset||0;d<=me(l)&&(l=ve(l,d).right,a=a.substring(0,d));let f=1;i==="ordered"&&(f=Number.parseInt(a,10)||1);let m=P();const p=oI(t,i);if(p){if(K(t)>K(p))f=fn(p)+1;else{const E=fn(p);E>1&&(f=E-1)}m=ni(p)}const A={id:P(),type:"list",level:r,start:f,groupId:m,ordered:!1,text:l};return s.quoted&&(A.quoted=!0),s.heading&&(A.heading=s.heading),i==="ordered"?A.ordered=!0:(i==="checked"||i==="unchecked")&&(A.checkbox=i),{blockData:A,onConverted:(E,L)=>{new dr(E,L).fix()}}}function oi(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function iI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${tI(t,(o=n.start)!=null?o:1)}.`:eI(t)}function Zc(n){return n==="checked"||n==="unchecked"}function m4(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=oi(r),a=oi(l);return c!==a&&(!Zc(c)||!Zc(a))||r.level>l.level}function g4(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=oi(r),a=oi(l);return c!==a&&(!Zc(c)||!Zc(a))||r.level>l.level}function sI(n,t,e,o,r){var s,l,c;const i=t;if(o==="text"){let a=((s=ye.convertTo)==null?void 0:s.call(ye,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 d=i.level||0;return a=(d>0?" ".repeat(d-1):"")+a,a}if(o==="markdown"){let a=((l=ye.convertTo)==null?void 0:l.call(ye,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 d=i.level||0;return a=(d>0?" ".repeat(d-1):"")+a,m4(n,t,e,r)&&(a=`${a}`),g4(n,t,e,r)&&(a=`${a}`,d<=1&&(a+=`
|
|
342
342
|
`)),a}if(o==="html"){let a=((c=ye.convertTo)==null?void 0:c.call(ye,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 d="ul";return i.ordered?(a=`<li value="${i.start}">${a}</li>`,d="ol"):a=`<li>${a}</li>`,m4(n,t,e,r)&&(a=`<${d}>${a}`),g4(n,t,e,r)&&(a=`${a}</${d}>`),a}return""}const lI=8,Nt=w("list-block");class Qc{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,Gc(e))return;const o=Hs(e),r=fn(o);this.listStart=r,o===e?this.listBrother=ur(o):this.listBrother=o}fix(){!this.listBrother||n1(this.editor,this.listBrother,this.listStart)}}function cI(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function o1(n,t,e,o){if(Nt.debug("drag a block on a list block"),!$(n,t))return!1;u(Nt,at(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=To(e),c=o==="after"?i+1:i,a=n.getBlockData(t),d={id:P(),type:"list",groupId:l,level:s,start:c,text:a.text,...e1(r)};cI(n,e,d);let f=K(e);const m=H(e);o==="after"&&(f+=1);let p=null;at(t)&&(p=new Qc(n,t));const A=n.insertBlock(V(m),f,d,ec(d.id,0));return n.deleteBlock(t),new dr(n,A).fix(),p==null||p.fix(),!0}function aI(n,t,e,o){if(Nt.debug("drag a list between text blocks"),o==="after"){const a=dt(e);if(a&&at(a))return o1(n,t,a,"before")}if(o==="before"){const a=pt(e);if(a&&at(a))return o1(n,t,a,"after")}const i={...n.getBlockData(t),groupId:P(),start:1,level:1};let s=K(e);const l=H(e);o==="after"&&(s+=1),n.insertBlock(V(l),s,i,ec(i.id,0));const c=new Qc(n,t);return n.deleteBlock(t),c.fix(),!0}function uI(n,t,e,o,r){if(Rl(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);u(Nt,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=r;return!l&&c?(u(Nt,t===c,"block !== target block"),u(Nt,at(c),"target is not a list block"),o1(n,s,c,o)):aI(n,s,c,o)}const dI=`<?xml version="1.0" ?>
|
|
343
343
|
<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">
|
|
344
344
|
<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>
|
|
@@ -368,7 +368,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
368
368
|
</svg>
|
|
369
369
|
`;function sx(n){const t=b("div",["list-to-mindmap-wrap"],null),e=Bo("list-to-mindmap",x.t("mindmap.viewAsMindMap"),ix,[],n.clientId);return t.appendChild(e),t}const sV="";class Yc{constructor(t){h(this,"toMindmapButton");h(this,"currentBlock",null);h(this,"handleHoveringBlock",t=>{!this.editor.isWritable()||(t&&at(t)&&ze(t)!=="unchecked"&&ze(t)!=="checked"?Rt(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove())});h(this,"handleMouseEnter",()=>{const t=U(this.toMindmapButton);u(Nt,t&&at(t),"no parent list"),l1(this.editor,t,!0),this.currentBlock=t});h(this,"handleMouseLeave",()=>{this.currentBlock&&(l1(this.editor,this.currentBlock,!1),this.currentBlock=null)});h(this,"handleClick",()=>{const t=U(this.toMindmapButton);u(Nt,t&&at(t),"no parent list"),c1(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:y4})});this.editor=t,$t.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=sx(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(Yc)}destroy(){$t.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}const lx={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"}},cx={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"}};x.mergeLang({"zh-CN":lx,"en-US":cx});const lV="";function ax(n,t,e){var o;t==="beginDrag"&&((o=Yc.get(n))==null||o.hide())}const S4={...ye,blockType:"list",createBlockContent:rx,convertFrom:rI,convertTo:sI,handleDrop:uI,notify:ax},d1=w("paragraph");class ux{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":[x.t("commands.unordered"),xt.isMac?x.t("commandDesc.mac.unordered"):x.t("commandDesc.window.unordered"),kw],"ordered-list":[x.t("commands.ordered"),xt.isMac?x.t("commandDesc.mac.ordered"):x.t("commandDesc.window.ordered"),yw],"check-list":[x.t("commands.check"),void 0,ww],link:[x.t("commands.link"),xt.isMac?x.t("commandDesc.mac.link"):x.t("commandDesc.window.link"),v5],quoted:[x.t("commands.quote"),void 0,Bw]};if($(t,e)){const i=z(e),s=rt(e),l=Je(t,e),c=t.getBlockData(e);Object.entries(r).forEach(([a,[d,f,m]])=>{const p=[];if(this.isChecked(c,a)&&p.push("checked"),a==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&p.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:a,name:d,desc:f,states:p,icon:m,groupIndex:600})})}return o}convertLink(t,e,o){u(d1,ho(e.start),""),u(d1,ho(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(p,A)=>{t.undoManager.runInGroup(()=>{try{let k=Jl(t.getBlockText(o),i,s,p);k=Ji(i,p.length,k,"link",A),t.setBlockText(o,k),t.selection.selectBlock(o,i+p.length),t.focus()}catch(k){d1.error(k)}})},c=()=>{t.focus()},a=uo(t,o,e)[0];if(!a)return;const d=mo(t,o,"link-button-anchor",a),f=t.getBlockText(o),m=Yl(f,i);_s(t,{target:d,linkText:t.getSelectedText(),linkUrl:(m==null?void 0:m.link)||"",onFinished:l,onClose:c,placement:r})}convertToList(t,e,o){const r=Fl(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=K(e),s=H(e);t.insertBlock(V(s),i,r.blockData),t.deleteBlock(e)})}executeCommand(t,e,o,r){var c;if(!$(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?ii(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?ii(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?ii(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const d=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:d?void 0:!0}),l=!0}if(i==="link"){const a=zc(t);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const dx={left:Is,right:yh,center:kh};class hx{constructor(t){h(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(dx).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if($(t,e)){const r=z(e),i=rt(e),s=Je(t,e),l=t.getBlockData(e),c=a=>{var f;const d=b("span",["toolbar-item-name-container"],null);for(const m of a.children)if((f=m.states)!=null&&f.includes("checked"))return d.innerHTML=m.icon||Is,d;return d.innerHTML=Is,d};return[{id:"align",name:x.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:x.t("commands.alignLeft"),icon:Is,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:x.t("commands.alignCenter"),icon:kh,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:x.t("commands.alignRight"),icon:yh,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(!$(t,e))return!1;if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),!0}return!1}}function fx(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 Xi(n,o,e.start.offset).charType==="box"}const mx=w("toolbar-handler"),gx={id:"",name:"",type:"separator"};class si{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&&FE(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});h(this,"handleClose",()=>{Ih(this.editor)&&this.editor.focus()});h(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const o=km(e);if(this.hoveringBlock===o)return!1}return!0});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",te.default(t=>{if(u(mx,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"&&this.editor.selection.focusedBlock===this.hoveringBlock)return;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 Ts([],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.toolbar.on("closing",this.handleClosing),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),$t.get(t).addListener("childChange",this.handleHoveringBlockChildChange),$t.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new jE(t)),t.editorCommandProviders.registerCommandProvider(new ux(t)),t.editorCommandProviders.registerCommandProvider(new hx(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),$t.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(fx(this.editor))return;if(H(r.block)===this.editor.rootContainer&&K(r.block)===0){this.toolbar.close();return}const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(d=>{const f=d.groupIndex,m=s.get(f);m?m.push(d):s.set(f,[d])});const l=[[]],c=Array.from(s.entries()).sort((d,f)=>d[0]-f[0]);for(let d=0;d<c.length;d++){const[,f]=c[d];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(...jc(f))}if(l.length===0){this.toolbar.close();return}this.toolbarType="text";const a=[];if(l.forEach((d,f)=>{const m=d.sort((p,A)=>{var k,y;return((k=p.order)!=null?k:0)-((y=A.order)!=null?y:0)});a.push(...m),f!==l.length-1&&a.push(gx)}),a.length===0){this.toolbar.close();return}if(this.toolbar.updateItems(a),!this.toolbar.isVisible){const d=o[o.length-1],f=!this.editor.selection.range.isReverse()&&d!==r,m=f?d:r,p=LE(this.editor,m),A=mo(this.editor,m.block,"editor-quick-menu",p);this.toolbar.manualShow(A,{placement:f?"bottom":"top"})}}showObjectToolbar(){var r,i;if(!this.hoveringBlock)return;const t=this.hoveringBlock,e=this.hoveringTextChild,o=PE(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||st(t),{placement:e?"bottom":"top"})}static register(t){return t.addCustom("toolbar-handler",e=>new si(e))}static get(t){return t.getCustom("toolbar-handler")}}function Jc(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function D4(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function h1(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function f1(n,t){return!!(n[t]||n.level&&(n.ordered===!0&&!n.checkbox&&t==="ordered-list"||n.ordered===!1&&!n.checkbox&&t==="unordered-list")||t==="check-list"&&n.checkbox)}function m1(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=f1(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=f1(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=f1(r,"check-list")?void 0:"unchecked";break}if(i){const s=Fl(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=K(t),c=H(t);n.deleteBlock(t),n.insertBlock(V(c),l,s.blockData)})}else ii(n,t)}const px=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:Jc,applyAlignStyle:D4,applyQuoteStyle:h1,applyList:m1},Symbol.toStringTag,{value:"Module"})),Cx=[fh,mh,gh,ph,Ch,Ah,bh,vh],Ax={Unordered:w5,Ordered:B5,Checkbox:y5,Quote:k5};function L4(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>L4(o,t))}function g1(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=Vc();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:Cx[o-1],name:x.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:Ce(i)}),o++}return t}function bx(){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:x.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:Ax[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:Ce(r)})}),n}class M4{getCommands(){const t=g1(),e=bx();return[...t.insertBlockCommandItems||[],...e.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?Jc(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?m1(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&h1(t,o),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=V(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}}const vx={basics:100,system:200,common:300,thirdParty:400};class p1{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 yx=w("mathjax-converter"),kx="MathJax-script";async function wx(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 zo(e,kx)}function Bx(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function R4(n,t){const e="mathjax2Svg";try{await We.lock(e),Bx(),await wx(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 yx.error(o),o}finally{We.release(e)}}async function O4(n,t){const e=await R4(n,t);return e?await ku(e,"image/svg+xml"):""}async function C1(n,t){const o=await R4(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const N4=w("edit-mathjax");class Ex{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,!0))}});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",te.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new Es(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(){u(N4,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return u(N4,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 Ex).editMathjax(t,e.trim(),o)}function $4(){return{insert:" ",attributes:{id:P(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function Kc(n,t){const e=n.getBoxData(t),o=U(t);if(!o)return;const r=go(o,t);n.selection.selectBlock(o,r.start,r.end);const i=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await We.lock("convertAndUploadMathjax");const c=await C1(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const a=n.getBoxData(t);n.addCustom(`mathjax-box-${a.id}`,()=>new p1).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{We.release("convertAndUploadMathjax"),l&&n.focus()}};P4(n,t,e.tex,i)}const Ix=w("mathjax-box");function A1(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,A1)}async function xx(n,t,e){try{if(!t.tex.trim())return;const o=await O4(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=Lu(r);i.innerHTML="";const s=b("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",A1)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");M(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function Tx(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new p1);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",A1);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=x.t("mathjax.emptyText"),b("span",s,e,l),xx(n,r,i)}function Sx(n,t){const e={id:P(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return C1(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{Ix.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function Dx(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 Lx(n,t,e){Kc(n,t)}const Xc={boxType:"math",updateBoxContent:Tx,convertFrom:Sx,convertTo:Dx,handleClickBox:Lx};async function Mx(n,t,e){try{const o=t.embedData,r=await O4(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=st(i);s.innerHTML="";const l=b("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function Rx(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=U(t.target);if(!e||!Te(e)||Ne(e)!=="math")return;const o=st(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 C1(n,l),a={mathjaxText:l,src:c};n.updateEmbedData(e,a)})}function Ox(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new p1);if(n.domEvents.addEventListener(t,"click",Rx),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),Mx(n,e,r)}function Nx(n,t,e){if(!$(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=pu(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:P(),type:"embed",embedType:"math",embedData:i}}}function Px(n){return{name:"Mathjax"}}function $x(n,t){const e=st(t);n.domEvents.removeAllListeners(e)}function _x(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
|
|
370
370
|
$$${r.mathjaxText}$$
|
|
371
|
-
`:r.mathjaxText}const b1={embedType:"math",createEmbedContent:Ox,getOptions:Px,convertFrom:Nx,handleDeleteBlock:$x,convertTo:_x},cV="",Fx={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},Hx={mathjax:{emptyText:"Empty Tex",abstract:"TeX"}};x.mergeLang({"zh-CN":Fx,"en-US":Hx});function jx(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=ve(i,o);if(!bt(s).endsWith("$$$$"))return!1;const c=o-4,a=o,d={id:P(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c),n.insertBoxToBlock(r,c,d),setTimeout(()=>{const f=n.getBoxById(d.id);Kc(n,f)})}),!0}class zx{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&jx(t,e,o,r))}}const li=w("inline-box-items");function Ux(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=$4();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return u(li,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);Kc(n,l)},100),o})}function Vx(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return Tt(n,o)||(r="top-start"),_s(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}),d=_e(" ",null),f=[a,d];n.insertTextToBlock(o,0,f),n.selection.selectBlock(o,me(f)),n.focus()}catch(a){li.error(a)}})},onClose:()=>{n.focus()},placement:r}),o}function qx(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;u(li,ho(r.start),"invalid block position");const i=$4();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return u(li,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);Kc(n,c)},100),o})}function Wx(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;u(li,ho(r.start),"invalid block position");const i=uo(n,o,r);if(i.length===0)return;const s=i[0],l=mo(n,o,"quick-menu-inline-link",s);_s(n,{target:l,linkText:"",linkUrl:"",onFinished:(d,f)=>{n.undoManager.runInGroup(()=>{try{const m=n.getBlockText(o),p=Co(m,r.start.offset,d,{link:f});n.setBlockText(o,p),n.selection.selectBlock(o,r.start.offset+d.length),n.focus()}catch(m){li.error(m)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class Gx{getCommands(){return[{id:"insert-math",name:x.t("quickMenu.inlineBox.math"),icon:Dw,order:900,group:"common",subText:Ce("insert-math")},{id:"insert-link",name:x.t("quickMenu.inlineBox.link"),icon:v5,order:400,group:"common",subText:Ce("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return qx(t,e.containerId,e.blockIndex);case"insert-link":return Wx(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return Ux(t,e.containerId,e.blockIndex);case"insert-link":return Vx(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=V(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}}function Zx(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 M4,new Gx].forEach(i=>{const s=i.getCommands(n);e.push(...s.map(l=>({...l,itemType:"insert-block",commandProvider:i})))}),e}function Qx(n){const t=[];return n.editorBlocks.forEach(e=>{if(!e.getOptions)return;const o=e.getOptions(n);!o.insertBlockCommandItems||(o.insertBlockCommandItems.forEach(r=>{L4(r,o)}),t.push(...o.insertBlockCommandItems))}),t.push(...Zx(n)),t}function v1(n){const t=Qx(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||vx[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=x.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 Yx(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=V(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 _4=w("quick-menu"),Jx={id:"quick-menu",trigger:["/"]};class ta{constructor(t,e=Jx){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(!Wn(i)){const s=U(H(i));if(s&&rt(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(u(_4,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),u(_4,this.suggest.anchor,"invalid suggest, no anchor"),Yx(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=Vc(),this.suggest=new Th(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=v1(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=Vc();if(o!==this.maxHeading){const r=new M4,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 y1{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=ru.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=te.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 Kx={"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 Xx(n,t){const e=new Set(Object.keys(Kx)),o=t.filter(i=>e.has(i.id));return jc(o)}function ea(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=Xx(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),si.get(n).update("selectionChange"),!0):!1}const k1={"CtrlOrCmd+B":n=>ea(n,"style-bold"),"CtrlOrCmd+I":n=>ea(n,"style-italic"),"CtrlOrCmd+U":n=>ea(n,"style-underline"),"CtrlOrCmd+D":n=>ea(n,"style-strikethrough")},tT={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"}}},eT={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"}}};x.mergeLang({"zh-CN":tT,"en-US":eT});const aV="";function hr(n,...t){const e=Bo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function F4(n){zc(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function nT(n){return b("div",["insert-column-button","drop-marker"],n)}const oT=w("row-height");function H4(n){const t=nt.fromTable(n),e=n.rows;u(oT,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 o}const So=w("table-border-bar-dom");function ci(n,t){u(So,Zt(t),"invalid table block");const e=jt(t),o=Tn(n,t),r=(a,d,f)=>{const m=b("div",["button-root",d],a),p=b("div",["button-container",d],m);m.setAttribute(`data-${d}-index`,`${f}`),p.setAttribute(`data-editor-tooltip-${n.clientId}`,d==="left"?x.t("table.insertRow"):x.t("table.insertCol")),b("span",["insert-indicator"],p),nT(p)},{selectedRows:i,selectedColumns:s}=Dh(n,t),l=()=>{const a=o.querySelector(".table-border-bar-container.top");u(So,a,"no top border bar container");const d=b("div",["table-border-bar-container","top"],null),f=b("div",["table-border-bar","top"],d),m=pE(e);b("span",["table-border-bar-cell","corner"],f);const A=nt.fromTable(e).colCount;n.selection.range.isSimple()&&r(f,"top",0);for(let k=0;k<A;k++){const y=k===A-1?m[k]+2:m[k],T=b("span",["table-border-bar-cell","top"],f);s.has(k)&&T.classList.add("selected"),T.setAttribute("data-top-index",`${k}`),T.style.width=`${y}px`,n.selection.range.isSimple()&&r(f,"top",k+1)}ji(a,d)},c=()=>{const a=o.querySelector(".table-border-bar-container.left");u(So,a,"no left border bar container");const d=b("div",["table-border-bar-container","left"],null),f=b("div",["table-border-bar","left"],d),m=H4(e);n.selection.range.isSimple()&&r(f,"left",0),Array.from(e.rows).forEach((p,A,k)=>{const y=b("span",["table-border-bar-cell","left"],f);i.has(A)&&y.classList.add("selected"),y.setAttribute("data-left-index",`${A}`);const T=A===k.length-1?m[A]+2:m[A];y.style.height=`${T}px`,n.selection.range.isSimple()&&r(f,"left",A+1)}),ji(a,d)};l(),c()}function j4(n,t){const e=t.target;if(!(e instanceof Element))return;const o=U(e);u(So,o&&Zt(o),"invalid table block"),ci(n,o),n.selection.caret.update()}function w1(n,t){const e=t.target;if(!(e instanceof Element))return;const o=U(e);u(So,o&&Zt(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);r4(n,o,i),ci(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);i4(n,o,i),ci(n,o)}}}function B1(n,t){var s;F4(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=U(l.target),d=l.target.closest(".table-border-bar");if(a===e&&d){const f=parseInt((c=l.target.getAttribute(`data-${o}-index`))!=null?c:"0",10),m=Math.min(r,f),p=Math.abs(r-f)+1;ot(l.target,"top")&&o==="top"?SE(n,a,m,p,{reverse:!0}):ot(l.target,"left")&&o==="left"&&DE(n,a,m,p,{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&&ot(t.target,"table-border-bar-cell")&&(e=U(t.target),ot(t.target,"top")?o="top":ot(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 z4(n){const t=n.selection.range,e=Lh(n,t);e&&ci(n,e)}function rT(n,t){u(So,Zt(t),"invalid table block");const e=Tn(n,t),o=b("div",["table-border-bar-container","top"],e),r=b("div",["table-border-bar-container","left"],e);ci(n,t),n.domEvents.addEventListener(st(t),"scroll",j4),n.domEvents.addEventListener(o,"click",w1),n.domEvents.addEventListener(r,"click",w1),n.domEvents.addEventListener(o,"mousedown",B1),n.domEvents.addEventListener(r,"mousedown",B1),n.addListener("afterClearSelection",z4)}function U4(n,t){if(!n.isWritable())return;if(Tn(n,t).querySelector(".table-border-bar-container")){ci(n,t);return}rT(n,t)}function V4(n,t){u(So,Zt(t),"invalid table block"),Tn(n,t).querySelectorAll(".table-border-bar-container").forEach(r=>{n.domEvents.removeEventListener(r,"click",w1),n.domEvents.removeEventListener(r,"mousedown",B1),r.remove()}),n.domEvents.removeEventListener(st(t),"scroll",j4),n.removeListener("afterClearSelection",z4)}function iT(n,t){u(So,Zt(t),"invalid table block");const o=Tn(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class sT{constructor(t,e){h(this,"toolbar");h(this,"handleSelectionChange",(t,e)=>{e==="delete-columns"?(Jr(this.editor,this.tableBlock,!0,!0),Kr(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Jr(this.editor,this.tableBlock,!0,!1),Kr(this.editor,this.tableBlock,!0,!1)):(Jr(this.editor,this.tableBlock,!1),Kr(this.editor,this.tableBlock,!1))});h(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?Mh(this.editor.selection.range):e.id==="delete-rows"&&Rh(this.editor.selection.range)});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new Ts([],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}=Dh(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=uo(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:x.t("table.deleteCol"),icon:Cw};this.toolbar.updateItems([r]);const i=mo(this.editor,this.tableBlock,"editor-quick-menu",o);this.toolbar.manualShow(i,{placement:"top"})}else{const r={id:"delete-rows",name:x.t("table.deleteRow"),icon:pw};this.toolbar.updateItems([r]);const i=new DOMRect(o.left-15,o.top,o.width,o.height),s=mo(this.editor,this.tableBlock,"editor-quick-menu",i);this.toolbar.manualShow(s,{placement:"left"})}}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const E1=w("table-border-bar");class lT{constructor(t,e){h(this,"toolbar");h(this,"resizeObserver");h(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():V4(this.editor,this.tableBlock)});h(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(z(this.tableBlock));this.resizeObserver.observe(jt(t))})});h(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,u(E1,this.tableBlock,"no table block"),E1.debug("create table border bar"),U4(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(jt(this.tableBlock)),this.toolbar=new sT(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){E1.debug("destroy table border bar"),this.resizeObserver.disconnect(),V4(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){U4(this.editor,this.tableBlock),this.toolbar.update()}}const cT=w("table-border-bar");class aT{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,o=Lh(t,e);((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 lT(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(u(cT,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function q4(n,t){const e=n.addCustom("table-border-bar",o=>new aT(o));t==="update"&&e.update()}const Be=w("table-cell-menu"),uT="style-bg-color-";class dT{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,o=Lh(t,e);if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=nt.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;e.isCollapsed()?s=this.getCellByChildBlockId(r,i.blockId):i instanceof Xe&&(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,x.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=p5,t});h(this,"handleCommand",t=>{var r;u(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":Rh(F5(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":Mh(F5(this.editor,this.activeTableBlock,!0));break;case"merge-cell":P5(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":_B(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":UB(this.editor,this.activeTableBlock,o==="show-chart"),Vh(this.editor,this.activeTableBlock,{updateNow:!0});break}});h(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(u(Be,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Jr(this.editor,this.activeTableBlock,!0,!1),Kr(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Jr(this.editor,this.activeTableBlock,!0,!0),Kr(this.editor,this.activeTableBlock,!0,!0)):(Jr(this.editor,this.activeTableBlock,!1),Kr(this.editor,this.activeTableBlock,!1)))});h(this,"handleClick",()=>{var t;u(Be,this.activeTableBlock,"no target table block"),u(Be,this.targetButton,"no target button"),F4(this.editor),ot(this.targetButton,"active")?(j(this.targetButton,"active"),(t=this.manualMenu)==null||t.close()):(M(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new sr(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&&j(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&&(j(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");u(Be,r,"no parent cell");const i=U(r);if(u(Be,i,"no parent block"),jt(i)===t.table)return t.getCellByCellElement(r);o=i}return u(Be,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${Hh}`)||t.appendChild(this.targetButton):(this.targetButton=b("button",[Hh],t),this.targetButton.innerHTML=hh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),u(Be,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=nt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Nh(this.editor,this.activeTableBlock,{col:o,row:r})}else Ph(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;u(Be,this.activeTableBlock,"no target table block");const t=jB(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=V(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(uT.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){u(Be,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=N5(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const d=Yn(this.editor,this.activeTableBlock,o.start);o=Wt(this.editor,{anchor:d,focus:d})}const r=O5(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,a=t.chart;return this.colorPaletteItem=new T5("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(d,f)=>{var m;switch(u(Be,this.activeTableBlock,"no target table block"),d){case"clearColor":z5(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":z5(this.editor,this.activeTableBlock,f);break}(m=this.manualMenu)==null||m.close()}),[{id:"cell-background-color",name:x.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:x.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:x.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:x.t("table.deleteSelectRow")},{id:"delete-select-col",name:x.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:x.t("table.tableConfigKey"),children:[{id:"row-title",name:x.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:x.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:x.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?x.t("table.tableConfig.showBorder"):x.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:a?x.t("table.tableConfig.hideChart"):x.t("table.tableConfig.showChart"),value:a?"hide-chart":"show-chart"}]}]}handleRowTitle(t){u(Be,this.activeTableBlock,"no target table block"),t?NB(this.editor,this.activeTableBlock):OB(this.editor,this.activeTableBlock)}handleColTitle(t){u(Be,this.activeTableBlock,"no target table block"),t?RB(this.editor,this.activeTableBlock):MB(this.editor,this.activeTableBlock)}handleStripeStyle(t){u(Be,this.activeTableBlock,"no target table block"),t?$B(this.editor,this.activeTableBlock):PB(this.editor,this.activeTableBlock)}}function W4(n){n.addCustom("table-cell-menu",t=>new dT(t))}const na=w("table-container");function I1(n){const t=n.closest("td");return u(na,t,"no parent cell for a table cell container"),t}function G4(n){const t=jt(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function x1(n,t,e,o){const r=nt.fromBlock(n),i=r.getCellByContainerId(V(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(u(na,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(V(c)).row!==i.row?null:c}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(u(na,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(V(c)).row!==i.row?null:c}u(na,!1,`invalid navigation type: ${e}`)}const hT=12,fT=90,oa=23,Z4=2;class mT{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=U(e);if(o&&It(this.editor.rootContainer,o)){const r=Qn(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});h(this,"handleAutoScroll",n8.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Io(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=Qn(o);if(r){const i=t.getCustom(Io(r)),s=i.rootElement.getBoundingClientRect(),l=Ke(t,o,e.start);if(s.left>l.left){const c=e.start.offset===0?hT:Z4;i.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?fT:Z4;i.rootElement.scrollLeft+=l.right-s.right+c}}}else{const o=t.getBlockById(e.start.blockId),r=Qn(o),i=t.getBlockById(e.end.blockId),s=Qn(i);if(r&&r===s){const l=t.getCustom(Io(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 d=I1(Dr(t,e.start.childContainerId)),f=I1(Dr(t,e.end.childContainerId));a=e.isReverse()?d.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=>{L5(t),this.editor.selection.caret.update()});h(this,"handleReset",t=>{L5(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(Io(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),d=Math.max(c.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=oa,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=oa,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=oa,(r.scrollTop>=r.scrollHeight-s||i.bottom<=a)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=oa,(r.scrollTop<=0||i.top>=d)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Q4(n){return n.addCustom("table-scroll-events",t=>new mT(t))}const Sn=w("create-content");function Y4(n,t,e){const o=new Dc(e),r=e.rows,i=e.cols;u(Sn,r>=1,`invalid rows: ${r}`),u(Sn,i>=1,`invalid cols: ${i}`),u(Sn,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]||Fc}px`}const a=b("tbody",[],s);let d=0;for(let f=0;f<r;f++){const m=b("tr",[],a);for(let p=0;p<i;p++){const A=o.getCell({col:p,row:f});if(A.virtual)u(Sn,A.colSpan>1||A.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const k=e.children[d],y=b("td",[],m);A.colSpan>1&&(y.colSpan=A.colSpan),A.rowSpan>1&&(y.rowSpan=A.rowSpan);const T=e[Rs(k)];T&&M(y,T),p===0&&e.hasColTitle&&M(y,$5.COL_TITLE_ITEM),n.createChildContainer(t,y,k),d+=1}}}return u(Sn,d===e.children.length,"container count mismatch"),e.noBorder&&M(s,"no-border"),e.chart&&M(s,"editor-table-chart"),e.isStripeStyle&&M(s,"stripe"),e.hasRowTitle&&M(s,"row-title"),e.hasColTitle&&M(s,"col-title"),s}function gT(n,t,e,o,r){u(Sn,r.type==="table","not table data"),u(Sn,V(e)===t[t.length-1].containerId,"invalid path");const i=r,s=co(o,"div");try{const l=b("div",[],null);l.setAttribute("data-type","table-content");const c=Y4(n,t,i);c.classList.add("drag-preview-element"),l.appendChild(c),n4(n),l4(n),q4(n,"create"),W4(n),rw(n,qh);const a=n.getComponentOptions("table"),d=n.addCustom(Io(o),()=>fE());d.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Ct(e)?n.scrollContainer:e,locatingContainer:Ct(e)?(a==null?void 0:a.locatingContainer)||n.parent:e,paddingLeft:Fh+Ms,paddingTop:Fh+Ms,paddingBottom:Ms/2,paddingRight:Ms/2,barFloatWindowBottom:a==null?void 0:a.barFloatWindowBottom,isSetScale:a==null?void 0:a.isSetScale});const f=Q4(n);d.on("scroll",f.handleReset),d.on("resize",f.handleReset),setTimeout(()=>{WB(n,o)})}catch{const c=`invalid table data: ${JSON.stringify(i)}`;Sn.error(c);const a=b("div",["error"],s);a.innerText=c}return s}function pT(n,t,e){u(Sn,e.type==="table","not table data");const o=e,r=st(t);try{const i=jt(t),s=ao(t),l=Y4(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),n4(n),l4(n),q4(n,"update"),W4(n),qh(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;Sn.error(s);const l=b("div",["error"],r);l.innerText=s}}function CT(n,t){let e,o,r=!1;if([...t].every(m=>m==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=pu(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let m=0;m<3;m++)e.forEach(p=>{l.push(wn(n.doc,m===0?p:""))});const c=Array(s).fill(Fc),a=l[r?0:s],d=n.doc.getContainerBlocks(a)[0].id;return{blockData:{id:P(),type:"table",rows:i,cols:s,children:l,colsWidth:c},focusBlockId:d}}function AT(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 d=0;d<o;d++)r.push(wn(n.doc));const i=Array(o).fill(Fc),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:P(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const J4=w("table-selection-to-doc");function bT(n,t){const{start:e,end:o,block:r}=t,i=rt(r);u(J4,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return bo(n.editorBlocks,n.doc.toJSON(),s);u(J4,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=nt.fromBlock(r),{fromCol:c,toCol:a,fromRow:d,toRow:f}=dn(r,e,o),m={},p=[],A=n.doc.toJSON();let k={};l.sub({row:d,col:c},{row:f,col:a}).forEach((W,it)=>{W.forEach((lt,gt)=>{const ht=lt.containerId;if(p.indexOf(ht)!==-1)return;p.push(ht);let kt;if(lt.virtual){const oe=l.getCellByContainerId(lt.containerId),Ve=c+gt;let Oo=oe.col+oe.colSpan-1;Oo>a&&(Oo=a);const vr=Oo-Ve+1;vr>1&&(m[`${ht}_colSpan`]=vr);const yr=d+it;let No=oe.row+oe.rowSpan-1;No>f&&(No=f);const Oa=No-yr+1;Oa>1&&(m[`${ht}_rowSpan`]=Oa),kt=er()}else{if(kt=Td(n.editorBlocks,A,ht),lt.col+lt.colSpan>a+1){const oe=a-lt.col+1;oe>1&&(m[`${ht}_colSpan`]=oe)}else lt.colSpan>1&&(m[`${ht}_colSpan`]=lt.colSpan);if(lt.row+lt.rowSpan>f+1){const oe=f-lt.row+1;oe>1&&(m[`${ht}_rowSpan`]=oe)}else lt.rowSpan>1&&(m[`${ht}_rowSpan`]=lt.rowSpan)}const{root:ue,...ro}=kt.blocks;k={...k,...ro,[ht]:ue}})});const T=$s(jt(r)).slice(c,a+1);return{blocks:{root:[{id:P(),type:i,children:p,colsWidth:T,rows:f-d+1,cols:a-c+1,...m}],...k},meta:{},comments:{}}}function vT(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 yT(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 kT(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 wT(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 BT(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,!vT(n,l)){l.top--,c=!0;continue}if(!yT(n,l)){l.left--,c=!0;continue}if(!kT(n,l)){l.bottom++,c=!0;continue}if(!wT(n,l)){l.right++,c=!0;continue}}while(c);return l}function ET(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=nt.fromBlock(t),i=r.map(L=>L.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),d=Math.min(s.col,l.col),f=Math.max(s.col,l.col),m=BT(i,{row:c,col:d},{row:a,col:f}),p=r.getCell({row:m.top,col:m.left}),A=r.getCell({row:m.bottom,col:m.right}),k=r.getCell({row:m.top,col:m.right}),y=r.getCell({row:m.bottom,col:m.left});let T,E;return s.row<=l.row?s.col<=l.col?(T=p,E=A):(T=k,E=y):s.col<l.col?(T=y,E=k):(T=A,E=p),console.log(`move ${T.col}, ${T.row}, -> ${E.col}, ${E.row}`),{anchor:wt(t,T.containerId),focus:wt(t,E.containerId)}}function K4(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}=dn(t,e.start,e.end),a=$s(o),d=a.slice(0,i).reduce((k,y)=>k+y,0),f=d+a.slice(i,l+1).reduce((k,y)=>k+y,0),m=H4(o);let p=m.slice(0,s).reduce((k,y)=>k+y,0);const A=p+m.slice(s,c+1).reduce((k,y)=>k+y,0);if(s===0){const k=iT(n,t);p-=k}return[new DOMRect(r.left+d,r.top+p,f-d,A-p)]}w("table-size");const IT=40;function ra(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 xT(n,t,e){const o=_u(n,e.container);return o!==void 0?o+ra(t):IT*e.colSpan-ra(t)}function TT(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=xT(n,t,l);const a=xg(l.container,{withPadding:!0});a&&a>c&&(c=a),r+=c+ra(t)}return r}function ST(n,t){const e=jt(t),o=nt.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,TT(n,e,o,s));const i=ra(e);return r+=i,r}const Kn=w("table-creator");async function DT(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=AT(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,Ot(n,l,0))})}class LT{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,p;t.preventDefault(),t.stopPropagation();const e=t.target;u(Kn,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");u(Kn,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;u(Kn,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const a=s.substring(l.length).split("-");u(Kn,a.length===2,"invalid cell id");const d=Number.parseInt(a[0],10)+1,f=Number.parseInt(a[1],10)+1;Kn.debug(`${d}, ${f}`),this.colCount=f,this.rowCount=d,(m=this.closeable)==null||m.click(this,this.element),(p=this.closeable)==null||p.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&&j(r,"active")}});h(this,"handleTableCreatorCellEnter",t=>{const e=t.target;u(Kn,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";u(Kn,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");u(Kn,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 d=0;d<9;d++){const f=this.getTableCreatorCellId(a,d),m=document.getElementById(f);u(Kn,m,"no cell"),a<=l&&d<=c?M(m,"active"):j(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 MT(){return new LT}function RT(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function X4(n){const t=RT(n);return n.length+t}function OT(n,t){const e=X4(n),o=t-e;return o>0?n+" ".repeat(o):n}function NT(n,t,e,o,r){const i=t,s=new Dc(i);if(o==="markdown"||o==="text"){const l=y=>e.blocks[y].map((L,R)=>o==="markdown"?Ad(n,L,e,[...r,{containerId:y,blockIndex:R}]):ic(n,L,e,[...r,{containerId:y,blockIndex:R}])),c=y=>l(y).join(" ").replace(/\n/g," ").trim(),a=new Map,d=new Map;for(let y=0;y<s.colCount;y++){let T=0;for(let E=0;E<s.rowCount;E++){const L=s.getCell({row:E,col:y});let R="";L.virtual||(R=c(L.containerId)),a.set(`${E},${y}`,R),T=Math.max(T,X4(R))}d.set(y,T)}const f=y=>{const T=a.get(`${y.row},${y.col}`)||"",E=d.get(y.col)||0;return OT(T,E)},m=[];let p="|",A="|";for(let y=0;y<s.colCount;y++){const T=f({row:0,col:y});p+=` ${T} |`;const E="-".repeat((d.get(y)||0)+2);A+=`${E}|`}m.push(p),m.push(A);for(let y=1;y<s.rowCount;y++){let T="|";for(let E=0;E<s.colCount;E++){const L=f({row:y,col:E});T+=` ${L} |`}m.push(T)}return`${m.join(`
|
|
371
|
+
`:r.mathjaxText}const b1={embedType:"math",createEmbedContent:Ox,getOptions:Px,convertFrom:Nx,handleDeleteBlock:$x,convertTo:_x},cV="",Fx={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},Hx={mathjax:{emptyText:"Empty Tex",abstract:"TeX"}};x.mergeLang({"zh-CN":Fx,"en-US":Hx});function jx(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=ve(i,o);if(!bt(s).endsWith("$$$$"))return!1;const c=o-4,a=o,d={id:P(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c),n.insertBoxToBlock(r,c,d),setTimeout(()=>{const f=n.getBoxById(d.id);Kc(n,f)})}),!0}class zx{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&jx(t,e,o,r))}}const li=w("inline-box-items");function Ux(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=$4();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return u(li,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);Kc(n,l)},100),o})}function Vx(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return Tt(n,o)||(r="top-start"),_s(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}),d=_e(" ",null),f=[a,d];n.insertTextToBlock(o,0,f),n.selection.selectBlock(o,me(f)),n.focus()}catch(a){li.error(a)}})},onClose:()=>{n.focus()},placement:r}),o}function qx(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;u(li,ho(r.start),"invalid block position");const i=$4();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return u(li,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);Kc(n,c)},100),o})}function Wx(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;u(li,ho(r.start),"invalid block position");const i=uo(n,o,r);if(i.length===0)return;const s=i[0],l=mo(n,o,"quick-menu-inline-link",s);_s(n,{target:l,linkText:"",linkUrl:"",onFinished:(d,f)=>{n.undoManager.runInGroup(()=>{try{const m=n.getBlockText(o),p=Co(m,r.start.offset,d,{link:f});n.setBlockText(o,p),n.selection.selectBlock(o,r.start.offset+d.length),n.focus()}catch(m){li.error(m)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class Gx{getCommands(){return[{id:"insert-math",name:x.t("quickMenu.inlineBox.math"),icon:Dw,order:900,group:"common",subText:Ce("insert-math")},{id:"insert-link",name:x.t("quickMenu.inlineBox.link"),icon:v5,order:400,group:"common",subText:Ce("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return qx(t,e.containerId,e.blockIndex);case"insert-link":return Wx(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return Ux(t,e.containerId,e.blockIndex);case"insert-link":return Vx(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=V(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}}function Zx(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 M4,new Gx].forEach(i=>{const s=i.getCommands(n);e.push(...s.map(l=>({...l,itemType:"insert-block",commandProvider:i})))}),e}function Qx(n){const t=[];return n.editorBlocks.forEach(e=>{if(!e.getOptions)return;const o=e.getOptions(n);!o.insertBlockCommandItems||(o.insertBlockCommandItems.forEach(r=>{L4(r,o)}),t.push(...o.insertBlockCommandItems))}),t.push(...Zx(n)),t}function v1(n){const t=Qx(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||vx[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=x.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 Yx(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=V(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 _4=w("quick-menu"),Jx={id:"quick-menu",trigger:["/"]};class ta{constructor(t,e=Jx){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(!Wn(i)){const s=U(H(i));if(s&&rt(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(u(_4,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),u(_4,this.suggest.anchor,"invalid suggest, no anchor"),Yx(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=Vc(),this.suggest=new Th(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=v1(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=Vc();if(o!==this.maxHeading){const r=new M4,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 y1{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=ru.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=te.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 Kx={"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 Xx(n,t){const e=new Set(Object.keys(Kx)),o=t.filter(i=>e.has(i.id));return jc(o)}function ea(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=Xx(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),si.get(n).update("selectionChange"),!0):!1}const k1={"CtrlOrCmd+B":n=>ea(n,"style-bold"),"CtrlOrCmd+I":n=>ea(n,"style-italic"),"CtrlOrCmd+U":n=>ea(n,"style-underline"),"CtrlOrCmd+D":n=>ea(n,"style-strikethrough")},tT={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"}}},eT={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"}}};x.mergeLang({"zh-CN":tT,"en-US":eT});const aV="";function hr(n,...t){const e=Bo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function F4(n){zc(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function nT(n){return b("div",["insert-column-button","drop-marker"],n)}const oT=w("row-height");function H4(n){const t=nt.fromTable(n),e=n.rows;u(oT,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 o}const So=w("table-border-bar-dom");function ci(n,t){u(So,Zt(t),"invalid table block");const e=jt(t),o=Tn(n,t),r=(a,d,f)=>{const m=b("div",["button-root",d],a),p=b("div",["button-container",d],m);m.setAttribute(`data-${d}-index`,`${f}`),p.setAttribute(`data-editor-tooltip-${n.clientId}`,d==="left"?x.t("table.insertRow"):x.t("table.insertCol")),b("span",["insert-indicator"],p),nT(p)},{selectedRows:i,selectedColumns:s}=Dh(n,t),l=()=>{const a=o.querySelector(".table-border-bar-container.top");u(So,a,"no top border bar container");const d=b("div",["table-border-bar-container","top"],null),f=b("div",["table-border-bar","top"],d),m=pE(e);b("span",["table-border-bar-cell","corner"],f);const A=nt.fromTable(e).colCount;n.selection.range.isSimple()&&r(f,"top",0);for(let k=0;k<A;k++){const y=k===A-1?m[k]+2:m[k],T=b("span",["table-border-bar-cell","top"],f);s.has(k)&&T.classList.add("selected"),T.setAttribute("data-top-index",`${k}`),T.style.width=`${y}px`,n.selection.range.isSimple()&&r(f,"top",k+1)}ji(a,d)},c=()=>{const a=o.querySelector(".table-border-bar-container.left");u(So,a,"no left border bar container");const d=b("div",["table-border-bar-container","left"],null),f=b("div",["table-border-bar","left"],d),m=H4(e);n.selection.range.isSimple()&&r(f,"left",0),Array.from(e.rows).forEach((p,A,k)=>{const y=b("span",["table-border-bar-cell","left"],f);i.has(A)&&y.classList.add("selected"),y.setAttribute("data-left-index",`${A}`);const T=A===k.length-1?m[A]+2:m[A];y.style.height=`${T}px`,n.selection.range.isSimple()&&r(f,"left",A+1)}),ji(a,d)};l(),c()}function j4(n,t){const e=t.target;if(!(e instanceof Element))return;const o=U(e);u(So,o&&Zt(o),"invalid table block"),ci(n,o),n.selection.caret.update()}function w1(n,t){const e=t.target;if(!(e instanceof Element))return;const o=U(e);u(So,o&&Zt(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);r4(n,o,i),ci(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);i4(n,o,i),ci(n,o)}}}function B1(n,t){var s;F4(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=U(l.target),d=l.target.closest(".table-border-bar");if(a===e&&d){const f=parseInt((c=l.target.getAttribute(`data-${o}-index`))!=null?c:"0",10),m=Math.min(r,f),p=Math.abs(r-f)+1;ot(l.target,"top")&&o==="top"?SE(n,a,m,p,{reverse:!0}):ot(l.target,"left")&&o==="left"&&DE(n,a,m,p,{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&&ot(t.target,"table-border-bar-cell")&&(e=U(t.target),ot(t.target,"top")?o="top":ot(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 z4(n){const t=n.selection.range,e=Lh(n,t);e&&ci(n,e)}function rT(n,t){u(So,Zt(t),"invalid table block");const e=Tn(n,t),o=b("div",["table-border-bar-container","top"],e),r=b("div",["table-border-bar-container","left"],e);ci(n,t),n.domEvents.addEventListener(st(t),"scroll",j4),n.domEvents.addEventListener(o,"click",w1),n.domEvents.addEventListener(r,"click",w1),n.domEvents.addEventListener(o,"mousedown",B1),n.domEvents.addEventListener(r,"mousedown",B1),n.addListener("afterClearSelection",z4)}function U4(n,t){if(!n.isWritable())return;if(Tn(n,t).querySelector(".table-border-bar-container")){ci(n,t);return}rT(n,t)}function V4(n,t){u(So,Zt(t),"invalid table block"),Tn(n,t).querySelectorAll(".table-border-bar-container").forEach(r=>{n.domEvents.removeEventListener(r,"click",w1),n.domEvents.removeEventListener(r,"mousedown",B1),r.remove()}),n.domEvents.removeEventListener(st(t),"scroll",j4),n.removeListener("afterClearSelection",z4)}function iT(n,t){u(So,Zt(t),"invalid table block");const o=Tn(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class sT{constructor(t,e){h(this,"toolbar");h(this,"handleSelectionChange",(t,e)=>{e==="delete-columns"?(Jr(this.editor,this.tableBlock,!0,!0),Kr(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Jr(this.editor,this.tableBlock,!0,!1),Kr(this.editor,this.tableBlock,!0,!1)):(Jr(this.editor,this.tableBlock,!1),Kr(this.editor,this.tableBlock,!1))});h(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?Mh(this.editor.selection.range):e.id==="delete-rows"&&Rh(this.editor.selection.range)});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new Ts([],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}=Dh(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=uo(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:x.t("table.deleteCol"),icon:Cw};this.toolbar.updateItems([r]);const i=mo(this.editor,this.tableBlock,"editor-quick-menu",o);this.toolbar.manualShow(i,{placement:"top"})}else{const r={id:"delete-rows",name:x.t("table.deleteRow"),icon:pw};this.toolbar.updateItems([r]);const i=new DOMRect(o.left-15,o.top,o.width,o.height),s=mo(this.editor,this.tableBlock,"editor-quick-menu",i);this.toolbar.manualShow(s,{placement:"left"})}}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const E1=w("table-border-bar");class lT{constructor(t,e){h(this,"toolbar");h(this,"resizeObserver");h(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():V4(this.editor,this.tableBlock)});h(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(z(this.tableBlock));this.resizeObserver.observe(jt(t))})});h(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,u(E1,this.tableBlock,"no table block"),E1.debug("create table border bar"),U4(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(jt(this.tableBlock)),this.toolbar=new sT(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){E1.debug("destroy table border bar"),this.resizeObserver.disconnect(),V4(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){U4(this.editor,this.tableBlock),this.toolbar.update()}}const cT=w("table-border-bar");class aT{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,o=Lh(t,e);((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 lT(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(u(cT,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function q4(n,t){const e=n.addCustom("table-border-bar",o=>new aT(o));t==="update"&&e.update()}const Be=w("table-cell-menu"),uT="style-bg-color-";class dT{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,o=Lh(t,e);if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=nt.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;e.isCollapsed()?s=this.getCellByChildBlockId(r,i.blockId):i instanceof Xe&&(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,x.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=p5,t});h(this,"handleCommand",t=>{var r;u(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":Rh(F5(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":Mh(F5(this.editor,this.activeTableBlock,!0));break;case"merge-cell":P5(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":_B(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":UB(this.editor,this.activeTableBlock,o==="show-chart"),Vh(this.editor,this.activeTableBlock,{updateNow:!0});break}});h(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(u(Be,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Jr(this.editor,this.activeTableBlock,!0,!1),Kr(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Jr(this.editor,this.activeTableBlock,!0,!0),Kr(this.editor,this.activeTableBlock,!0,!0)):(Jr(this.editor,this.activeTableBlock,!1),Kr(this.editor,this.activeTableBlock,!1)))});h(this,"handleClick",()=>{var t;u(Be,this.activeTableBlock,"no target table block"),u(Be,this.targetButton,"no target button"),F4(this.editor),ot(this.targetButton,"active")?(j(this.targetButton,"active"),(t=this.manualMenu)==null||t.close()):(M(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new sr(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&&j(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&&(j(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");u(Be,r,"no parent cell");const i=U(r);if(u(Be,i,"no parent block"),jt(i)===t.table)return t.getCellByCellElement(r);o=i}return u(Be,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${Hh}`)||t.appendChild(this.targetButton):(this.targetButton=b("button",[Hh],t),this.targetButton.innerHTML=hh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),u(Be,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=nt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Nh(this.editor,this.activeTableBlock,{col:o,row:r})}else Ph(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;u(Be,this.activeTableBlock,"no target table block");const t=jB(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=V(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(uT.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){u(Be,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=N5(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const d=Yn(this.editor,this.activeTableBlock,o.start);o=Wt(this.editor,{anchor:d,focus:d})}const r=O5(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,a=t.chart;return this.colorPaletteItem=new T5("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(d,f)=>{var m;switch(u(Be,this.activeTableBlock,"no target table block"),d){case"clearColor":z5(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":z5(this.editor,this.activeTableBlock,f);break}(m=this.manualMenu)==null||m.close()}),[{id:"cell-background-color",name:x.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:x.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:x.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:x.t("table.deleteSelectRow")},{id:"delete-select-col",name:x.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:x.t("table.tableConfigKey"),children:[{id:"row-title",name:x.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:x.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:x.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?x.t("table.tableConfig.showBorder"):x.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:a?x.t("table.tableConfig.hideChart"):x.t("table.tableConfig.showChart"),value:a?"hide-chart":"show-chart"}]}]}handleRowTitle(t){u(Be,this.activeTableBlock,"no target table block"),t?NB(this.editor,this.activeTableBlock):OB(this.editor,this.activeTableBlock)}handleColTitle(t){u(Be,this.activeTableBlock,"no target table block"),t?RB(this.editor,this.activeTableBlock):MB(this.editor,this.activeTableBlock)}handleStripeStyle(t){u(Be,this.activeTableBlock,"no target table block"),t?$B(this.editor,this.activeTableBlock):PB(this.editor,this.activeTableBlock)}}function W4(n){n.addCustom("table-cell-menu",t=>new dT(t))}const na=w("table-container");function I1(n){const t=n.closest("td");return u(na,t,"no parent cell for a table cell container"),t}function G4(n){const t=jt(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function x1(n,t,e,o){const r=nt.fromBlock(n),i=r.getCellByContainerId(V(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(u(na,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(V(c)).row!==i.row?null:c}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(u(na,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(V(c)).row!==i.row?null:c}u(na,!1,`invalid navigation type: ${e}`)}const hT=12,fT=90,oa=23,Z4=2;class mT{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=U(e);if(o&&It(this.editor.rootContainer,o)){const r=Qn(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});h(this,"handleAutoScroll",n8.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Io(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=Qn(o);if(r){const i=t.getCustom(Io(r)),s=i.rootElement.getBoundingClientRect(),l=Ke(t,o,e.start);if(s.left>l.left){const c=e.start.offset===0?hT:Z4;i.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?fT:Z4;i.rootElement.scrollLeft+=l.right-s.right+c}}}else{const o=t.getBlockById(e.start.blockId),r=Qn(o),i=t.getBlockById(e.end.blockId),s=Qn(i);if(r&&r===s){const l=t.getCustom(Io(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 d=I1(Dr(t,e.start.childContainerId)),f=I1(Dr(t,e.end.childContainerId));a=e.isReverse()?d.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=>{L5(t),this.editor.selection.caret.update()});h(this,"handleReset",t=>{L5(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(Io(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),d=Math.max(c.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=oa,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=oa,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=oa,(r.scrollTop>=r.scrollHeight-s||i.bottom<=a)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=oa,(r.scrollTop<=0||i.top>=d)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Q4(n){return n.addCustom("table-scroll-events",t=>new mT(t))}const Sn=w("create-content");function Y4(n,t,e){const o=new Dc(e),r=e.rows,i=e.cols;u(Sn,r>=1,`invalid rows: ${r}`),u(Sn,i>=1,`invalid cols: ${i}`),u(Sn,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]||Fc}px`}const a=b("tbody",[],s);let d=0;for(let f=0;f<r;f++){const m=b("tr",[],a);for(let p=0;p<i;p++){const A=o.getCell({col:p,row:f});if(A.virtual)u(Sn,A.colSpan>1||A.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const k=e.children[d],y=b("td",[],m);A.colSpan>1&&(y.colSpan=A.colSpan),A.rowSpan>1&&(y.rowSpan=A.rowSpan);const T=e[Rs(k)];T&&M(y,T),p===0&&e.hasColTitle&&M(y,$5.COL_TITLE_ITEM),n.createChildContainer(t,y,k),d+=1}}}return u(Sn,d===e.children.length,"container count mismatch"),e.noBorder&&M(s,"no-border"),e.chart&&M(s,"editor-table-chart"),e.isStripeStyle&&M(s,"stripe"),e.hasRowTitle&&M(s,"row-title"),e.hasColTitle&&M(s,"col-title"),s}function gT(n,t,e,o,r){u(Sn,r.type==="table","not table data"),u(Sn,V(e)===t[t.length-1].containerId,"invalid path");const i=r,s=co(o,"div");try{const l=b("div",[],null);l.setAttribute("data-type","table-content");const c=Y4(n,t,i);c.classList.add("drag-preview-element"),l.appendChild(c),n4(n),l4(n),q4(n,"create"),W4(n),rw(n,qh);const a=n.getComponentOptions("table"),d=n.addCustom(Io(o),()=>fE());d.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Ct(e)?n.scrollContainer:e,locatingContainer:Ct(e)?(a==null?void 0:a.locatingContainer)||n.parent:e,paddingLeft:Fh+Ms,paddingTop:Fh+Ms,paddingBottom:Ms/2,paddingRight:Ms/2,barFloatWindowBottom:a==null?void 0:a.barFloatWindowBottom,isSetScale:a==null?void 0:a.isSetScale});const f=Q4(n);d.on("scroll",f.handleReset),d.on("resize",f.handleReset),setTimeout(()=>{WB(n,o)})}catch{const c=`invalid table data: ${JSON.stringify(i)}`;Sn.error(c);const a=b("div",["error"],s);a.innerText=c}return s}function pT(n,t,e){u(Sn,e.type==="table","not table data");const o=e,r=st(t);try{const i=jt(t),s=ao(t),l=Y4(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),n4(n),l4(n),q4(n,"update"),W4(n),qh(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;Sn.error(s);const l=b("div",["error"],r);l.innerText=s}}function CT(n,t){let e,o,r=!1;if([...t].every(m=>m==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=pu(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let m=0;m<3;m++)e.forEach(p=>{l.push(wn(n.doc,m===0?p:""))});const c=Array(s).fill(Fc),a=l[r?0:s],d=n.doc.getContainerBlocks(a)[0].id;return{blockData:{id:P(),type:"table",rows:i,cols:s,children:l,colsWidth:c},focusBlockId:d}}function AT(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 d=0;d<o;d++)r.push(wn(n.doc));const i=Array(o).fill(Fc),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:P(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const J4=w("table-selection-to-doc");function bT(n,t){const{start:e,end:o,block:r}=t,i=rt(r);u(J4,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return bo(n.editorBlocks,n.doc.toJSON(),s);u(J4,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=nt.fromBlock(r),{fromCol:c,toCol:a,fromRow:d,toRow:f}=dn(r,e,o),m={},p=[],A=n.doc.toJSON();let k={};l.sub({row:d,col:c},{row:f,col:a}).forEach((W,it)=>{W.forEach((lt,gt)=>{const ht=lt.containerId;if(p.indexOf(ht)!==-1)return;p.push(ht);let kt;if(lt.virtual){const oe=l.getCellByContainerId(lt.containerId),Ve=c+gt;let Oo=oe.col+oe.colSpan-1;Oo>a&&(Oo=a);const vr=Oo-Ve+1;vr>1&&(m[`${ht}_colSpan`]=vr);const yr=d+it;let No=oe.row+oe.rowSpan-1;No>f&&(No=f);const Oa=No-yr+1;Oa>1&&(m[`${ht}_rowSpan`]=Oa),kt=er()}else{if(kt=Td(n.editorBlocks,A,ht),lt.col+lt.colSpan>a+1){const oe=a-lt.col+1;oe>1&&(m[`${ht}_colSpan`]=oe)}else lt.colSpan>1&&(m[`${ht}_colSpan`]=lt.colSpan);if(lt.row+lt.rowSpan>f+1){const oe=f-lt.row+1;oe>1&&(m[`${ht}_rowSpan`]=oe)}else lt.rowSpan>1&&(m[`${ht}_rowSpan`]=lt.rowSpan)}const{root:ue,...ro}=kt.blocks;k={...k,...ro,[ht]:ue}})});const T=$s(jt(r)).slice(c,a+1);return{blocks:{root:[{id:P(),type:i,children:p,colsWidth:T,rows:f-d+1,cols:a-c+1,...m}],...k},meta:{},comments:{}}}function vT(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 yT(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 kT(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 wT(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 BT(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,!vT(n,l)){l.top--,c=!0;continue}if(!yT(n,l)){l.left--,c=!0;continue}if(!kT(n,l)){l.bottom++,c=!0;continue}if(!wT(n,l)){l.right++,c=!0;continue}}while(c);return l}function ET(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=nt.fromBlock(t),i=r.map(L=>L.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),d=Math.min(s.col,l.col),f=Math.max(s.col,l.col),m=BT(i,{row:c,col:d},{row:a,col:f}),p=r.getCell({row:m.top,col:m.left}),A=r.getCell({row:m.bottom,col:m.right}),k=r.getCell({row:m.top,col:m.right}),y=r.getCell({row:m.bottom,col:m.left});let T,E;return s.row<=l.row?s.col<=l.col?(T=p,E=A):(T=k,E=y):s.col<l.col?(T=y,E=k):(T=A,E=p),console.log(`move ${T.col}, ${T.row}, -> ${E.col}, ${E.row}`),{anchor:wt(t,T.containerId),focus:wt(t,E.containerId)}}function K4(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}=dn(t,e.start,e.end),a=$s(o),d=a.slice(0,i).reduce((k,y)=>k+y,0),f=d+a.slice(i,l+1).reduce((k,y)=>k+y,0),m=H4(o);let p=m.slice(0,s).reduce((k,y)=>k+y,0);const A=p+m.slice(s,c+1).reduce((k,y)=>k+y,0);if(s===0){const k=iT(n,t);p-=k}return[new DOMRect(r.left+d,r.top+p,f-d,A-p)]}w("table-size");const IT=40;function ra(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 xT(n,t,e){const o=_u(n,e.container);return o!==void 0?o+ra(t):IT*e.colSpan-ra(t)}function TT(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=xT(n,t,l);const a=xg(l.container,{withPadding:!0});a&&a>c&&(c=a),r+=c+ra(t)}return r}function ST(n,t){const e=jt(t),o=nt.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,TT(n,e,o,s));const i=ra(e);return r+=i,r}const Kn=w("table-creator");async function DT(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=AT(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,Ot(n,l,0))})}class LT{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,p;t.preventDefault(),t.stopPropagation();const e=t.target;u(Kn,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");u(Kn,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;u(Kn,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const a=s.substring(l.length).split("-");u(Kn,a.length===2,"invalid cell id");const d=Number.parseInt(a[0],10)+1,f=Number.parseInt(a[1],10)+1;Kn.debug(`${d}, ${f}`),this.colCount=f,this.rowCount=d,(m=this.closeable)==null||m.click(this,this.element),(p=this.closeable)==null||p.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&&j(r,"active")}});h(this,"handleTableCreatorCellEnter",t=>{const e=t.target;u(Kn,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";u(Kn,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");u(Kn,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 d=0;d<9;d++){const f=this.getTableCreatorCellId(a,d),m=document.getElementById(f);u(Kn,m,"no cell"),a<=l&&d<=c?M(m,"active"):j(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 MT(){return new LT}function RT(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function X4(n){const t=RT(n);return n.length+t}function OT(n,t){const e=X4(n),o=t-e;return o>0?n+" ".repeat(o):n}function NT(n,t,e,o,r){const i=t,s=new Dc(i);if(o==="markdown"||o==="text"){const l=y=>e.blocks[y].map((L,R)=>o==="markdown"?Ad(n,L,e,[...r,{containerId:y,blockIndex:R}]):ic(n,L,e,[...r,{containerId:y,blockIndex:R}])),c=y=>l(y).join(" ").replace(/\n/g," ").trim(),a=new Map,d=new Map;for(let y=0;y<s.colCount;y++){let T=0;for(let E=0;E<s.rowCount;E++){const L=s.getCell({row:E,col:y});let R="";L.virtual||(R=c(L.containerId)),a.set(`${E},${y}`,R),T=Math.max(T,X4(R))}d.set(y,T)}const f=y=>{const T=a.get(`${y.row},${y.col}`)||"",E=d.get(y.col)||0;return OT(T,E)},m=[];let p="|",A="|";for(let y=0;y<s.colCount;y++){const T=f({row:0,col:y});p+=` ${T} |`;const E="-".repeat((d.get(y)||0)+2);A+=`${E}|`}m.push(p),m.push(A);for(let y=1;y<s.rowCount;y++){let T="|";for(let E=0;E<s.colCount;E++){const L=f({row:y,col:E});T+=` ${L} |`}m.push(T)}return`${m.join(`
|
|
372
372
|
`)}
|
|
373
373
|
`}if(o==="html"){const l=a=>e.blocks[a].map((m,p)=>Cd(n,m,e,[...r,{containerId:a,blockIndex:p}])).join(`
|
|
374
374
|
`),c=[];c.push("<table>");for(let a=0;a<s.rowCount;a++){let d="<tr>";for(let f=0;f<s.colCount;f++){const m=s.getCell({row:a,col:f});if(m.virtual)d+="<td></td>";else{const p=l(m.containerId);d+=`<td colSpan="${m.colSpan}" rowSpan="${m.rowSpan}">${p}</td>`}}d+="</tr>",c.push(d)}return c.push("</table>"),c.join(`
|
|
@@ -377,7 +377,7 @@ $$${r.mathjaxText}$$
|
|
|
377
377
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 7.61719C11.4477 7.61719 11 7.16947 11 6.61719V3.61719C11 3.0649 11.4477 2.61719 12 2.61719C12.5523 2.61719 13 3.0649 13 3.61719V6.61719C13 7.16947 12.5523 7.61719 12 7.61719ZM4.92893 5.54612C5.31946 5.15559 5.95262 5.1556 6.34315 5.54612L8.46447 7.66744C8.85499 8.05796 8.85499 8.69113 8.46447 9.08165C8.07394 9.47218 7.44078 9.47218 7.05025 9.08165L4.92893 6.96033C4.53841 6.56981 4.53841 5.93664 4.92893 5.54612ZM15.5355 9.08165C15.145 8.69113 15.145 8.05796 15.5355 7.66744L17.6569 5.54612C18.0474 5.1556 18.6805 5.1556 19.0711 5.54612C19.4616 5.93664 19.4616 6.56981 19.0711 6.96033L16.9497 9.08165C16.5592 9.47218 15.9261 9.47218 15.5355 9.08165ZM2 12.6172C2 12.0649 2.44772 11.6172 3 11.6172L6 11.6172C6.55229 11.6172 7 12.0649 7 12.6172C7 13.1695 6.55228 13.6172 6 13.6172L3 13.6172C2.44772 13.6172 2 13.1695 2 12.6172ZM17 12.6172C17 12.0649 17.4477 11.6172 18 11.6172L21 11.6172C21.5523 11.6172 22 12.0649 22 12.6172C22 13.1695 21.5523 13.6172 21 13.6172L18 13.6172C17.4477 13.6172 17 13.1695 17 12.6172ZM15.5355 16.1527C15.9261 15.7622 16.5592 15.7622 16.9497 16.1527L19.0711 18.274C19.4616 18.6646 19.4616 19.2977 19.0711 19.6883C18.6805 20.0788 18.0474 20.0788 17.6569 19.6883L15.5355 17.5669C15.145 17.1764 15.145 16.5432 15.5355 16.1527ZM4.92893 19.6883C4.53841 19.2977 4.53841 18.6646 4.92893 18.274L7.05025 16.1527C7.44078 15.7622 8.07394 15.7622 8.46447 16.1527C8.85499 16.5432 8.85499 17.1764 8.46447 17.5669L6.34315 19.6883C5.95262 20.0788 5.31946 20.0788 4.92893 19.6883ZM12 22.6172C11.4477 22.6172 11 22.1695 11 21.6172V18.6172C11 18.0649 11.4477 17.6172 12 17.6172C12.5523 17.6172 13 18.0649 13 18.6172V21.6172C13 22.1695 12.5523 22.6172 12 22.6172Z" fill="#5587F0"/>
|
|
378
378
|
<animateTransform attributeType="xml" attributeName="transform" type="rotate" values="0 12 12.5;360 12 12.5" dur="2s" repeatCount="indefinite" />
|
|
379
379
|
</g>
|
|
380
|
-
</svg>`,S1=w("webpage");class nS{constructor(t,e){h(this,"currentSrc","");h(this,"loading",null);h(this,"handleMaskMouseMove",(t,e)=>{if(!window.isDragging){if(e.target&&e.target instanceof Element){const o=e.target.closest("webpage-mask");o&&(o.style.display="none")}t.domEvents.addEventListener(document,"mousemove",this.handleDocumentMouseMove)}});h(this,"handleDocumentMouseMove",(t,e)=>{if(!e.target||!(e.target instanceof Element))return;const o=this.editor.findBlockById(this.blockData.id);if(o){const r=this.getExistsMask(o);if(r){if(It(o,e.target)){r.style.display="none";return}r.style.display=""}}});this.editor=t,this.blockData=e}create(t,e,o,r){const i=e.src,s=b("div",["editor-embed"],null),l=b("iframe",["editor-preview-iframe"],s);this.loading=this.createLoading(s);const c=()=>{u(S1,this.loading,"not created"),this.loading.hide(),this.currentSrc=i};t.domEvents.addEventListener(l,"load",c),l.src=i,this.loading.show(),o.append(s),this.createMask(t,r)}update(t,e,o){if(u(S1,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");u(S1,r,"no exists iframe"),this.loading.show(),r.src=o.src,this.createMask(t,e)}createLoading(t){const e=b("div",["editor-preview-iframe-loading"],null),o=b("span",[],e);return o.innerHTML=eS,{show(){t.append(e)},hide(){const r=t.querySelector(":scope > .editor-preview-iframe-loading");!r||r.remove()}}}getExistsMask(t){return Rt(t).querySelector(".webpage-mask")}createMask(t,e){const o=Rt(e);let r=this.getExistsMask(e);if(r){r.style.display="";return}r=b("div",["webpage-mask"],o),t.domEvents.addEventListener(r,"mousemove",this.handleMaskMouseMove)}destroy(){const t=this.editor.findBlockById(this.blockData.id);if(t){const e=this.getExistsMask(t);e&&(this.editor.domEvents.removeEventListener(e,"mousemove",this.handleMaskMouseMove),this.editor.domEvents.removeEventListener(document,"mousemove",this.handleDocumentMouseMove))}}}function oS(n,t){b("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function D1(n){return Rt(n).querySelector(".block-resizer")}function rS(n){const t=D1(n);t&&j(t,"active")}function r6(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function iS(n,t,e,o){const r=D1(n);if(r)return M(r,"active"),r6(n,t,r),r;const i=Rt(n),s=b("div",["block-resizer"],i);return r6(n,t,s),e.resize.forEach(l=>{oS(s,l)}),s.addEventListener("mousedown",o),M(s,"active"),s}function i6(n,t){const e=D1(n);if(!e)return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const hV="",sS=w("block-resizer");class ia extends Yt.TypedEmitter{constructor(e,o){super();h(this,"resizableElement");h(this,"block",null);h(this,"startRect",null);h(this,"startPos",null);h(this,"resizeType",null);h(this,"enabled",!1);h(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,Hi(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});h(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType)return;const o=this.getResizableElement();if(!o||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:a,bottom:d}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(d+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(a+=r);const f=a>c?a-c:0,m=d>l?d-l:0,p=new DOMRect(c,l,f,m);this.emit("resizing",this,p),i6(this.block,o)});h(this,"handleMouseUp",e=>{if(e.button!==0)return;Hi(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||i6(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(rS(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?st(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(u(sS,It(this.block,e),"not a block child element"),iS(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}function s6(n){return n&&Te(n)&&Ne(n)==="webpage"}const lS=1e3,cS=100;class aS{constructor(t){h(this,"currentBlockElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&s6(e)&&this.disableBlockResize(e),t&&s6(t)&&this.enableBlockResize(t))});h(this,"handleResizing",(t,e)=>{this.resizing=!0;const o=t.getBlock();if(!o)return;const r=Math.max(Math.min(e.height,lS),cS);o.style.height=`${r}px`,M(o,"resizing")});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;j(e,"resizing");const o=this.editor.getBlockData(e),r=e.getBoundingClientRect().height;this.editor.updateBlockData(e,{...o,height:r})});this.editor=t,$t.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentBlockElement=null,$t.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disableBlockResize(t){const e=this.editor.findCustom(`${z(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${z(t)}-resizer`,()=>new ia(this.editor,{resize:["bottom"]}));e.enableResize(t),e.removeListener("resizing",this.handleResizing),e.removeListener("resized",this.handleResized),e.addListener("resizing",this.handleResizing),e.addListener("resized",this.handleResized),this.currentBlockElement=t}}const fV="",uS=w("editor-dialog");function dS(n,t){const e=b("div",["editor-dialog-container"],null),o=b("div",["dialog-header"],e);b("span",["dialog-header-title"],o,t.title);const r=b("span",["close-icon"],o);r.innerHTML=f5,b("div",["dialog-content"],e).appendChild(n);const s=b("div",["dialog-footer"],e);return b("button",["cancel-button"],s,"Cancel"),b("button",["submit-button"],s,"Ok"),e}class hS extends Ss{constructor(e,o){super(dS(e,o),o);h(this,"_options");h(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();u(uS,r,"no command bar root");const{width:i,height:s}=r.getBoundingClientRect();return new DOMRect(Math.max(o-i/2,0),Math.max(e-s/2,0),0,0)});h(this,"handleOk",async()=>{var e,o;try{await((o=(e=this._options).onOk)==null?void 0:o.call(e)),this.destroy()}catch{}});h(this,"handleClose",()=>{var e,o;(o=(e=this._options).onClose)==null||o.call(e),this.destroy()});const r=this.content.querySelector(".submit-button"),i=this.content.querySelector(".cancel-button"),s=this.content.querySelector(".close-icon");r==null||r.addEventListener("click",this.handleOk),s==null||s.addEventListener("click",this.handleClose),i==null||i.addEventListener("click",this.handleClose),this._options=o}show(){super.show(document.documentElement,{getReferenceClientRect:this.getReferenceClientRect})}destroy(){const e=this.content.querySelector(".submit-button"),o=this.content.querySelector(".cancel-button"),r=this.content.querySelector(".close-icon");e==null||e.removeEventListener("click",this.handleOk),o==null||o.removeEventListener("click",this.handleClose),r==null||r.removeEventListener("click",this.handleClose),super.destroy()}}const l6=()=>[{name:x.t("webpage.bilibili"),id:"insert-bilibili",icon:Nw,group:"thirdParty",subText:Ce("insert-bilibili")},{name:x.t("webpage.youku"),id:"insert-youku",icon:Pw,group:"thirdParty",subText:Ce("insert-youku")},{name:x.t("webpage.figma"),id:"insert-figma",icon:$w,group:"thirdParty",subText:Ce("insert-figma")},{name:x.t("webpage.modao"),id:"insert-modao",icon:_w,group:"thirdParty",subText:Ce("insert-modao")},{name:x.t("webpage.tencent"),id:"insert-tencent",icon:Fw,group:"thirdParty",subText:Ce("insert-tencent")},{id:"insert-webPage",name:x.t("webpage.title"),icon:Hw,group:"common",order:1e3,subText:Ce("insert-webPage")}];function L1(n){return n==="insert-webPage"}async function fS(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function mS(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`//${n}`:n}async function gS(n){if(!n)throw new Error(x.t("webpage.dialog.errorEnterUrl"));let t=n;t.startsWith("//")&&(t=`http:${t}`);try{new URL(t)}catch{throw new Error(x.t("webpage.dialog.unsupportedUrl"))}}async function pS(n,t){const e=t.item.id,o=l6().find(a=>a.id===e),r=b("div",["webpage-content"],null);if(L1(e)){const a=b("div",["help-container"],r),d=b("div",["help-content"],a),f=b("span",["help-icon"],d);f.innerHTML=C5,b("span",[],d,x.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:c}=Eh(r,{required:!0,label:x.t("webpage.dialog.label"),placeholder:x.t("webpage.dialog.placeholder")});if(!L1(e)){const a=b("div",["help-link-container"],r),d=b("a",["help-link-content"],a);b("span",[],d,x.t("webpage.dialog.helpLink"));const f=b("span",["help-link-icon"],d);f.innerHTML=b5;const m=n.getComponentOptions("webpage");d.href=(m==null?void 0:m.helpLink)||"",d.target="_blank"}try{const a=await new Promise((m,p)=>{const A=new hS(r,{title:x.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var T;const y=mS(i());try{await gS(y);const E=await fS(n,y);m((E==null?void 0:E.url)||"")}catch(E){if(((T=E==null?void 0:E.responseData)==null?void 0:T.statusCode)===415)if(L1(e))m(y);else throw s(x.t("webpage.dialog.unsupportedUrl")),E;else throw s(E.message||""),E}},onClose(){n.focus(),p()}});A.addListener("show",l),A.show(),c().addEventListener("keydown",async y=>{if(!y.isComposing){if(y.key==="Enter"){await A.handleOk(),y.preventDefault();return}y.key==="Escape"&&A.handleClose()}})}),d={id:P(),type:"embed",embedType:"webpage",embedData:{src:a}},f=n.insertBlock(t.containerId,t.blockIndex,d);return n.focus(),f}catch{return null}}const c6=w("embed-block-properties");function sa(n,t){var e;for(const o of n.blockHooks){const r=(e=o.commands)==null?void 0:e.call(o,n,t);if(!!r&&r.group==="block-comment-actions")return r.executeCommand(n,t,r.commands[0]),!0}return!1}class M1{constructor(t,e,o){h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:wh},{id:"add-comment",name:"Add Comment",icon:xs}]);this.editor=t,this.block=e,this.properties=o}get commands(){var o,r,i;if(this.editor.readonly)return[];const t=this._commands;t.forEach(s=>{(s.id==="add-comment"||s.id==="edit")&&(s.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});const e=(o=this.properties)!=null&&o.presetIds?t.filter(s=>{var l,c;return(c=(l=this.properties)==null?void 0:l.presetIds)==null?void 0:c.includes(s.id)}):[...t];return(i=(r=this.properties)==null?void 0:r.extCommands)!=null&&i.length&&(e.push({id:P(),type:"separator",name:""}),e.push(...this.properties.extCommands)),e}executeCommand(t,e,o){var r,i;if(!((i=(r=this.properties)==null?void 0:r.handleExecuteCommand)!=null&&i.call(r,t,e,o))){if(o.id==="add-comment"){sa(t,e)||c6.error("failed to add comment to block");return}c6.error(`unknown command: ${JSON.stringify(o)}`)}}}function R1(n,t,e){return{blockCommands:{"hovering-toolbar":new M1(n,t,e)}}}function CS(n){const t=n.querySelector(".editor-preview-iframe"),e=t.src;t.src="about:blank";const o=setTimeout(()=>{t.src=e,clearTimeout(o)},300);return!0}function AS(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function bS(n,t){const e=R1(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:"Refresh page",icon:Mw},{id:"open-page",name:"Open the original page",icon:b5}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return CS(i);case"open-page":return AS(r,i)}return!1}}),o=`[${x.t("webpage.abstract")}]`;return{...e,abstract:o}}const vS=w("webpage-embed");function yS(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:c}=s,a=n.addCustom(`webpage-${l}`,()=>new nS(n,e));u(vS,c,"The src from blockData is invalid "),a.create(n,s,t,i),n.addCustom("webpage-resizer",()=>new aS(n)),e.height&&(i.style.height=`${e.height}px`)}function kS(n,t,e){const{embedData:o,id:r}=e;return n.getCustom(`webpage-${r}`).update(n,t,o),e.height&&(t.style.height=`${e.height}px`),!0}function wS(){return{name:"WebPage",insertEmbedCommandItems:l6(),handleInsertEmptyEmbed:pS}}function BS(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const O1={embedType:"webpage",createEmbedContent:yS,getBlockProperties:bS,getOptions:wS,handleUpdateBlock:kS,convertTo:BS},ES={webpage:{title:"\u7F51\u9875",youku:"\u4F18\u9177\u89C6\u9891",modao:"\u58A8\u5200",tencent:"\u817E\u8BAF\u89C6\u9891",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u56E0\u76EE\u6807\u7F51\u9875\u7684\u9650\u5236\uFF0C\u90E8\u5206\u7F51\u9875\u53EF\u80FD\u65E0\u6CD5\u6210\u529F\u9884\u89C8\u3002",helpLink:"\u5982\u4F55\u83B7\u53D6\u94FE\u63A5",label:"\u7F51\u9875\u5730\u5740",placeholder:"\u8BF7\u8F93\u5165",title:"\u63D2\u5165{name}",errorEnterUrl:"\u8BF7\u8F93\u5165\u7F51\u9875\u5730\u5740",unsupportedUrl:"\u6682\u4E0D\u652F\u6301\u63D2\u5165\u8BE5\u94FE\u63A5\u5185\u5BB9"},abstract:"\u7F51\u9875"}},IS={webpage:{title:"Webpage",youku:"Youku",modao:"Modao",tencent:"Tencent Video",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"Due to the limitation of the landing page, some pages may not be previewed successfully.",helpLink:"How to get the URL link",label:"Please enter webpage address",placeholder:"Please enter url",title:"Insert {name}",errorEnterUrl:"Please enter the webpage address",unsupportedUrl:"Unsupported url"},abstract:"Webpage"}};x.mergeLang({"zh-CN":ES,"en-US":IS});const mV="";function xS(n,t,e,o){var f;const r=n.getBlockByIndex(t,e);if(G(n,r)!==o)return!1;const i=bt(n.getBlockText(r));if(![...i].every(m=>m==="|")||i.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,r,{offset:o});if(!l)return!1;const{blockData:c,focusBlockId:a}=l;if(!c)return!1;const d=n.insertBlock(t,e,c,Ot(n,a!=null?a:c.id,0));return n.deleteBlock(r),(f=l.onConverted)==null||f.call(l,n,d),!0}const TS={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},SS={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function a6(n,t,e,o,r){if(r==="enter"&&xS(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=bt(ve(n.getBlockText(i),o).left).trim(),l=r==="enter"?TS:SS;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var A;const d=Fl(n,i,c.blockType,{offset:o,data:c.data});if(!d)return null;const{blockData:f,focusBlockId:m}=d;if(!f)return null;const p=n.insertBlock(t,e,f,Ot(n,m!=null?m:f.id,0));return n.deleteBlock(i),(A=d.onConverted)==null||A.call(d,n,p),{newBlock:p,focusBlockId:m}})}return!1}function DS(n,t,e,o){const r=n.getBlockByIndex(t,e);return n.getBlockString(r,{boxReplacement:" "}).substring(0,o)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{quoted:!0},Ot(n,r,0))}),!0)}const LS={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function MS(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=LS[i];if(!s)return!1;const l=n.getBlockData(r).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{heading:s},Ot(n,r,0))}),!0}function RS(n,t,e,o){return!!(MS(n,t,e,o)||DS(n,t,e,o))}const OS=w("match-text-style");function NS(n){let t="";for(let e=n.length-1;e>=0;e--){const o=n[e];if(!o.attributes||Object.keys(o.attributes).length===0){t+=o.insert;continue}break}return t}function PS(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),o=e.lastIndexOf(t);return o===-1?-1:o===0?0:e.substring(o-1).startsWith(t)?-1:o}const $S={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function _S(n,t,e,o){var d,f;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=ve(i,o),l=NS(s),c=me(s)-l.length,a=Object.entries($S);for(const[m,p]of a){const A=PS(l,m);if(A===-1)continue;const k=c+A,y=o,T=m.length,E=bt(Gt(i,k+T,y-k-T*2).middle);if(p.type==="style"){const L={};p.styles.forEach(_=>{L[_]=!0});const R=tr(E,L);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,k,y-k),n.insertTextToBlock(r,k,R)})}else if(p.type==="box")try{const L=(f=(d=n.editorBoxes.getBoxClass(p.boxType)).convertFrom)==null?void 0:f.call(d,n,E);if(!L)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,k,y-k),n.insertBoxToBlock(r,k,L)})}catch(L){OS.warn(`failed to convert to box, ${L.message}`);continue}return!0}return!1}class la{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&(RS(t,e,o,r)||_S(t,e,o,r)))}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if($(t,t.getBlockByIndex(r,i))){if(Hn(e,"Enter")){if(a6(t,r,i,s,"enter"))return!0}else if(Hn(e,"Space")&&a6(t,r,i,s,"space"))return!0}return!1}}const FS={"en-US":{placeholder:{default:"Type \u2018/\u2019 for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks @mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}}};x.mergeLang(FS);function Vs(n,t){const e=Ao(n,t);return!!(e.text&&me(e.text)===0&&!t.querySelector(".inputting-insertion"))}function u6(n,t){var o;st(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function ca(n,t,e){var r;if(!Vs(n,t)){u6(n,t);return}const o=st(t);if(typeof e=="string")o.setAttribute("data-content-placeholder",e);else{const i=Rt(t),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:b("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(e)}}function HS(n){const t=n.getAttribute("data-style-heading");return t?x.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?x.t("placeholder.quote"):null}function jS(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?x.t("placeholder.list"):x.t("placeholder.mention"):null}function d6(n){switch(rt(n)){case"text":return HS(n);case"list":return jS(n);default:return null}}function zS(n){if(Wn(n))return!1;const t=U(H(n));return t?rt(t)==="code":!1}function US(n){if(Wn(n))return!1;const t=U(H(n));return t?rt(t)==="table":!1}function VS(n,t){var d,f;const e=n.selection.focusedBlock,o=rt(e),r=t.contentPlaceholder||x.t("placeholder.default");let i=r;if(o&&Vi(n,o)&&e){if(zS(e))return;US(e)?i=x.t("placeholder.common.contentInTable"):i=(d=d6(e))!=null?d:i}const s=n.getFirstBlock(),l=dt(s);if(!l)return;const c=dt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c){Vs(n,l)&&ca(n,l,(f=d6(l))!=null?f:r);return}const a=n.getFocusedBlock();!Vs(n,a)||a!==s&&ca(n,a,i)}function qS(n,t){var r,i;const e=n.getFirstBlock(),o=st(e);Vs(n,e)?(o.setAttribute("data-title-placeholder",(r=t.titlePlaceholder)!=null?r:x.t("placeholder.title")),o.setAttribute("data-title-placeholder-readonly",(i=t.readonlyTitlePlaceholder)!=null?i:"")):(o.removeAttribute("data-title-placeholder"),o.removeAttribute("data-title-placeholder-readonly"))}function WS(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function GS(n,t){WS(n),n.selection.range.isCollapsed()&&(qS(n,t),VS(n,t))}const CV="",ZS=w("enforce-title");class qs{constructor(t,e={headingLevel:1}){h(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(!qs.isDocumentTitleBlock(r,i)||!Hn(e,"Enter"))return!1;let l=!1,c=null;Ze(t.rootContainer)===2&&(c=xr(t.rootContainer,1),G(t,c)===0&&(l=!0));const a=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(a,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e;try{const o=t.doc.getContainerBlocks(V(t.rootContainer));u(ZS,o.length>0,"root container is empty");const r=o[0];if(r.type!=="text"||r.heading!==this.options.headingLevel){const i=Vn("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(V(t.rootContainer),0,i);return}if(o.length>1)return;t.insertTextBlock("",V(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,o;!((e=this.options)!=null&&e.titlePlaceholder)&&!((o=this.options)!=null&&o.contentPlaceholder)||GS(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const h6=w("code-dom");function Do(n){return rt(n)==="code"}function f6(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?j(t,"wrap"):M(t,"wrap")}function N1(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return u(h6,t,"no parent code block"),u(h6,Do(t),"not a code block"),t}const aa={plain:{name:"Plain Text",aliases:["txt","text"]},abap:{name:"ABAP",aliases:["abap"]},arduino:{name:"Arduino",aliases:["ino"]},bash:{name:"Bash",aliases:["sh","shell"]},basic:{name:"BASIC",aliases:["bas"]},c:{name:"C",aliases:["c"]},clojure:{name:"Clojure",aliases:["clj"]},cofeescript:{name:"CoffeeScript",aliases:["coffee"]},cpp:{name:"C++",aliases:["cpp","cxx"]},csharp:{name:"C#",aliases:["cs"]},css:{name:"CSS",aliases:["css"]},dart:{name:"Dart",aliases:["dart"]},diff:{name:"Diff",aliases:["diff","patch"]},docker:{name:"Docker",aliases:["dockerfile"]},elixir:{name:"Elixir",aliases:["ex","exs"]},elm:{name:"Elm",aliases:["elm"]},erlang:{name:"Erlang",aliases:["erl"]},flow:{name:"Flow",aliases:["flow"]},fortran:{name:"Fortran",aliases:["f","for","f77","f90"]},fsharp:{name:"F#",aliases:["fsharp"]},gherkin:{name:"Gherkin",aliases:["feature"]},glsl:{name:"GLSL",aliases:["glsl"]},go:{name:"Go",aliases:["go"]},graphql:{name:"GraphQL",aliases:["graphql"]},groovy:{name:"Groovy",aliases:["groovy"]},haskell:{name:"Haskell",aliases:["hs"]},java:{name:"Java",aliases:["java"]},js:{name:"JavaScript",aliases:["js","jsx"]},json:{name:"JSON",aliases:["json"]},julia:{name:"Julia",aliases:["jl"]},kotlin:{name:"Kotlin",aliases:["kt","ktm","kts"]},latex:{name:"LaTeX",aliases:["tex"]},less:{name:"LESS",aliases:["less"]},lisp:{name:"Lisp",aliases:["lisp"]},livescript:{name:"LiveScript",aliases:["ls"]},lua:{name:"Lua",aliases:["lua"]},makefile:{name:"Makefile",aliases:["mk","mak"]},markdown:{name:"Markdown",aliases:["md","mkdown","mkd"]},markup:{name:"HTML / XML",aliases:["html","htm","xml","xsd","xsl","xslt","wsdl"]},matlab:{name:"MATLAB",aliases:["matlab"]},mermaid:{name:"Mermaid",aliases:["mermaid"]},nix:{name:"Nix",aliases:["nix"]},objectivec:{name:"Objective-C",aliases:["m","mm"]},ocaml:{name:"OCaml",aliases:["ml"]},pascal:{name:"Pascal",aliases:["pas"]},perl:{name:"Perl",aliases:["pl","pm"]},php:{name:"PHP",aliases:["php"]},powershell:{name:"PowerShell",aliases:["ps","ps1"]},prolog:{name:"Prolog",aliases:["plg"]},protobuf:{name:"Protocol Buffers",aliases:["proto"]},python:{name:"Python",aliases:["py"]},r:{name:"R",aliases:["r"]},reason:{name:"Reason",aliases:["re","rei"]},ruby:{name:"Ruby",aliases:["rb"]},rust:{name:"Rust",aliases:["rs"]},sass:{name:"Sass",aliases:["sass"]},scala:{name:"Scala",aliases:["scala"]},scheme:{name:"Scheme",aliases:["scm","sm"]},scss:{name:"SCSS",aliases:["scss"]},solidity:{name:"Solidity",aliases:["sol"]},sql:{name:"SQL",aliases:["sql"]},swift:{name:"Swift",aliases:["swift"]},typescript:{name:"TypeScript",aliases:["ts","tsx"]},vbnet:{name:"VB.Net",aliases:["vbnet"]},verilog:{name:"Verilog",aliases:["v"]},vhdl:{name:"VHDL",aliases:["vhdl"]},"visual-basic":{name:"Visual Basic",aliases:["vb","vba"]},wasm:{name:"WebAssembly",aliases:["wasm"]},yaml:{name:"YAML",aliases:["yaml"]}};function QS(n){const t=n.toLocaleLowerCase();let e="";return Object.entries(aa).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}function m6(n){const t=n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}function YS(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const JS=w("convert-to-code");function KS(n,t){if(!$(n,t))return null;const e={id:P(),type:"text",text:[]},o=P();n.doc.localInsertChildContainer(o,[e]);const r=n.getBlockData(t).text;u(JS,r,"no text");let i=bt(r);i.startsWith("```")&&(i=i.substring(3));const s=QS(i)||m6(n)||"plain";return{blockData:{id:P(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const AV="",P1=w("code-block-child-container");function ai(n){u(P1,Do(n),"not a code block");const e=st(n).querySelector(":scope > div.editor-code-root > div.code-text-root [data-type=editor-container].child");return u(P1,e,"no code text container"),e}function ui(n){u(P1,Do(n),"not a code block");const e=st(n).querySelector(":scope > div.editor-code-root > div.code-caption-root [data-type=editor-container].child");return e||null}function ua(n){const t=[ai(n)],e=ui(n);return e&&t.push(e),t}function di(n,t){if(!$(n,t))return!1;const e=H(t),o=U(e);return o?Do(o)?e===ai(o):rt(t)==="code":!1}const $1=w("code-caption");function XS(n,t){if(n.readonly)return;const e=ui(t);if(e){const c=Ft(e);n.selection.selectBlock(c,0);return}const o=wn(n.doc),r=n.getBlockData(t);u($1,r.children.length===1,"code block should have only one child");const i={...r,children:[r.children[0],o]};n.updateBlockData(t,i);const s=n.getContainerById(o),l=Ft(s);n.selection.selectBlock(l,0)}function g6(n,t){const e=H(t);if(Ct(e))return!1;const o=U(e);if(u($1,o,"no parent block"),!Do(o))return!1;const i=ui(o);return e===i}function tD(n,t){if(n.readonly||!ui(t))return;const o=ai(t),r=Jt(o);n.selection.selectBlock(r,G(n,r));const i=n.getBlockData(t);u($1,i.children.length===2,"code block should have only one child");const s=i.children[1],l={...i,children:[i.children[0]]};n.updateBlockData(t,l),n.deleteChildContainers([s])}const eD=w("paste-in-table-block");class nD{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePaste(t,e,o){if(!t.selection.range.isSimple())return!1;const r=t.selection.range.start,i=t.getBlockById(r.blockId),s=H(i);if(Ct(s))return!1;const l=U(s);if(u(eD,l,"no parent block"),!Do(l)||g6(t,i))return!1;const c=o["text/plain"];return c&&t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,c)}),!0}}function oD(n){n.addCustom("code-block-paste-event",t=>new nD(t))}class rD{constructor(t){h(this,"id","CodeBlockCommandProvider");setTimeout(()=>{t.editorCommandProviders.registerCommandProvider(this)})}destroy(){}getAvailableCommands(){return[]}executeCommand(){return!1}filterCommands(t,e,o,r){if(di(t,e))return[]}beforeExecuteCommand(t,e,o,r,i){return!!di(t,e)}}function iD(n){n.addCustom("code-block-command-provider",t=>new rD(t))}const sD=w("code-caption-input-handler");function _1(n){if(!n.selection.range.isSimple())return null;const t=n.selection.range.start;if(!t.isSimple())return null;const e=n.getBlockById(t.blockId);return g6(n,e)?e:null}function lD(n){const t=_1(n);if(!t)return!1;const e=N1(t),o=dt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",V(H(e)),K(e)+1),!0)}function cD(n){const t=_1(n);if(!t)return!1;if(Tt(n,t)){const e=N1(t);return tD(n,e),!0}return!1}class F1{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?lD(t):e.key==="Backspace"?cD(t):!1}async handleBeforePaste(t,e,o){const r=_1(t);if(!r)return!1;const i=o["text/plain"];if(!i)return!0;const s=sc(t,i);return s&&t.undoManager.runInGroup(()=>{t.clearSelectedContents();const l=t.selection.range.start;u(sD,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new F1(e))}}const aD=`
|
|
380
|
+
</svg>`,S1=w("webpage");class nS{constructor(t,e){h(this,"currentSrc","");h(this,"loading",null);h(this,"handleMaskMouseMove",(t,e)=>{if(!window.isDragging){if(e.target&&e.target instanceof Element){const o=e.target.closest("webpage-mask");o&&(o.style.display="none")}t.domEvents.addEventListener(document,"mousemove",this.handleDocumentMouseMove)}});h(this,"handleDocumentMouseMove",(t,e)=>{if(!e.target||!(e.target instanceof Element))return;const o=this.editor.findBlockById(this.blockData.id);if(o){const r=this.getExistsMask(o);if(r){if(It(o,e.target)){r.style.display="none";return}r.style.display=""}}});this.editor=t,this.blockData=e}create(t,e,o,r){const i=e.src,s=b("div",["editor-embed"],null),l=b("iframe",["editor-preview-iframe"],s);this.loading=this.createLoading(s);const c=()=>{u(S1,this.loading,"not created"),this.loading.hide(),this.currentSrc=i};t.domEvents.addEventListener(l,"load",c),l.src=i,this.loading.show(),o.append(s),this.createMask(t,r)}update(t,e,o){if(u(S1,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");u(S1,r,"no exists iframe"),this.loading.show(),r.src=o.src,this.createMask(t,e)}createLoading(t){const e=b("div",["editor-preview-iframe-loading"],null),o=b("span",[],e);return o.innerHTML=eS,{show(){t.append(e)},hide(){const r=t.querySelector(":scope > .editor-preview-iframe-loading");!r||r.remove()}}}getExistsMask(t){return Rt(t).querySelector(".webpage-mask")}createMask(t,e){const o=Rt(e);let r=this.getExistsMask(e);if(r){r.style.display="";return}r=b("div",["webpage-mask"],o),t.domEvents.addEventListener(r,"mousemove",this.handleMaskMouseMove)}destroy(){const t=this.editor.findBlockById(this.blockData.id);if(t){const e=this.getExistsMask(t);e&&(this.editor.domEvents.removeEventListener(e,"mousemove",this.handleMaskMouseMove),this.editor.domEvents.removeEventListener(document,"mousemove",this.handleDocumentMouseMove))}}}function oS(n,t){b("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function D1(n){return Rt(n).querySelector(".block-resizer")}function rS(n){const t=D1(n);t&&j(t,"active")}function r6(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function iS(n,t,e,o){const r=D1(n);if(r)return M(r,"active"),r6(n,t,r),r;const i=Rt(n),s=b("div",["block-resizer"],i);return r6(n,t,s),e.resize.forEach(l=>{oS(s,l)}),s.addEventListener("mousedown",o),M(s,"active"),s}function i6(n,t){const e=D1(n);if(!e)return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const hV="",sS=w("block-resizer");class ia extends Yt.TypedEmitter{constructor(e,o){super();h(this,"resizableElement");h(this,"block",null);h(this,"startRect",null);h(this,"startPos",null);h(this,"resizeType",null);h(this,"enabled",!1);h(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,Hi(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});h(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType)return;const o=this.getResizableElement();if(!o||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:a,bottom:d}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(d+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(a+=r);const f=a>c?a-c:0,m=d>l?d-l:0,p=new DOMRect(c,l,f,m);this.emit("resizing",this,p),i6(this.block,o)});h(this,"handleMouseUp",e=>{if(e.button!==0)return;Hi(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||i6(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(rS(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?st(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(u(sS,It(this.block,e),"not a block child element"),iS(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}function s6(n){return n&&Te(n)&&Ne(n)==="webpage"}const lS=1e3,cS=100;class aS{constructor(t){h(this,"currentBlockElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&s6(e)&&this.disableBlockResize(e),t&&s6(t)&&this.enableBlockResize(t))});h(this,"handleResizing",(t,e)=>{this.resizing=!0;const o=t.getBlock();if(!o)return;const r=Math.max(Math.min(e.height,lS),cS);o.style.height=`${r}px`,M(o,"resizing")});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;j(e,"resizing");const o=this.editor.getBlockData(e),r=e.getBoundingClientRect().height;this.editor.updateBlockData(e,{...o,height:r})});this.editor=t,$t.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentBlockElement=null,$t.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disableBlockResize(t){const e=this.editor.findCustom(`${z(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${z(t)}-resizer`,()=>new ia(this.editor,{resize:["bottom"]}));e.enableResize(t),e.removeListener("resizing",this.handleResizing),e.removeListener("resized",this.handleResized),e.addListener("resizing",this.handleResizing),e.addListener("resized",this.handleResized),this.currentBlockElement=t}}const fV="",uS=w("editor-dialog");function dS(n,t){const e=b("div",["editor-dialog-container"],null),o=b("div",["dialog-header"],e);b("span",["dialog-header-title"],o,t.title);const r=b("span",["close-icon"],o);r.innerHTML=f5,b("div",["dialog-content"],e).appendChild(n);const s=b("div",["dialog-footer"],e);return b("button",["cancel-button"],s,"Cancel"),b("button",["submit-button"],s,"Ok"),e}class hS extends Ss{constructor(e,o){super(dS(e,o),o);h(this,"_options");h(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();u(uS,r,"no command bar root");const{width:i,height:s}=r.getBoundingClientRect();return new DOMRect(Math.max(o-i/2,0),Math.max(e-s/2,0),0,0)});h(this,"handleOk",async()=>{var e,o;try{await((o=(e=this._options).onOk)==null?void 0:o.call(e)),this.destroy()}catch{}});h(this,"handleClose",()=>{var e,o;(o=(e=this._options).onClose)==null||o.call(e),this.destroy()});const r=this.content.querySelector(".submit-button"),i=this.content.querySelector(".cancel-button"),s=this.content.querySelector(".close-icon");r==null||r.addEventListener("click",this.handleOk),s==null||s.addEventListener("click",this.handleClose),i==null||i.addEventListener("click",this.handleClose),this._options=o}show(){super.show(document.documentElement,{getReferenceClientRect:this.getReferenceClientRect})}destroy(){const e=this.content.querySelector(".submit-button"),o=this.content.querySelector(".cancel-button"),r=this.content.querySelector(".close-icon");e==null||e.removeEventListener("click",this.handleOk),o==null||o.removeEventListener("click",this.handleClose),r==null||r.removeEventListener("click",this.handleClose),super.destroy()}}const l6=()=>[{name:x.t("webpage.bilibili"),id:"insert-bilibili",icon:Nw,group:"thirdParty",subText:Ce("insert-bilibili")},{name:x.t("webpage.youku"),id:"insert-youku",icon:Pw,group:"thirdParty",subText:Ce("insert-youku")},{name:x.t("webpage.figma"),id:"insert-figma",icon:$w,group:"thirdParty",subText:Ce("insert-figma")},{name:x.t("webpage.modao"),id:"insert-modao",icon:_w,group:"thirdParty",subText:Ce("insert-modao")},{name:x.t("webpage.tencent"),id:"insert-tencent",icon:Fw,group:"thirdParty",subText:Ce("insert-tencent")},{id:"insert-webPage",name:x.t("webpage.title"),icon:Hw,group:"common",order:1e3,subText:Ce("insert-webPage")}];function L1(n){return n==="insert-webPage"}async function fS(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function mS(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`//${n}`:n}async function gS(n){if(!n)throw new Error(x.t("webpage.dialog.errorEnterUrl"));let t=n;t.startsWith("//")&&(t=`${window.location.protocol}${t}`);try{new URL(t)}catch{throw new Error(x.t("webpage.dialog.unsupportedUrl"))}}async function pS(n,t){const e=t.item.id,o=l6().find(a=>a.id===e),r=b("div",["webpage-content"],null);if(L1(e)){const a=b("div",["help-container"],r),d=b("div",["help-content"],a),f=b("span",["help-icon"],d);f.innerHTML=C5,b("span",[],d,x.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:c}=Eh(r,{required:!0,label:x.t("webpage.dialog.label"),placeholder:x.t("webpage.dialog.placeholder")});if(!L1(e)){const a=b("div",["help-link-container"],r),d=b("a",["help-link-content"],a);b("span",[],d,x.t("webpage.dialog.helpLink"));const f=b("span",["help-link-icon"],d);f.innerHTML=b5;const m=n.getComponentOptions("webpage");d.href=(m==null?void 0:m.helpLink)||"",d.target="_blank"}try{const a=await new Promise((m,p)=>{const A=new hS(r,{title:x.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var T;const y=mS(i());try{await gS(y);const E=await fS(n,y);m((E==null?void 0:E.url)||"")}catch(E){if(((T=E==null?void 0:E.responseData)==null?void 0:T.statusCode)===415)if(L1(e))m(y);else throw s(x.t("webpage.dialog.unsupportedUrl")),E;else throw s(E.message||""),E}},onClose(){n.focus(),p()}});A.addListener("show",l),A.show(),c().addEventListener("keydown",async y=>{if(!y.isComposing){if(y.key==="Enter"){await A.handleOk(),y.preventDefault();return}y.key==="Escape"&&A.handleClose()}})}),d={id:P(),type:"embed",embedType:"webpage",embedData:{src:a}},f=n.insertBlock(t.containerId,t.blockIndex,d);return n.focus(),f}catch{return null}}const c6=w("embed-block-properties");function sa(n,t){var e;for(const o of n.blockHooks){const r=(e=o.commands)==null?void 0:e.call(o,n,t);if(!!r&&r.group==="block-comment-actions")return r.executeCommand(n,t,r.commands[0]),!0}return!1}class M1{constructor(t,e,o){h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:wh},{id:"add-comment",name:"Add Comment",icon:xs}]);this.editor=t,this.block=e,this.properties=o}get commands(){var o,r,i;if(this.editor.readonly)return[];const t=this._commands;t.forEach(s=>{(s.id==="add-comment"||s.id==="edit")&&(s.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});const e=(o=this.properties)!=null&&o.presetIds?t.filter(s=>{var l,c;return(c=(l=this.properties)==null?void 0:l.presetIds)==null?void 0:c.includes(s.id)}):[...t];return(i=(r=this.properties)==null?void 0:r.extCommands)!=null&&i.length&&(e.push({id:P(),type:"separator",name:""}),e.push(...this.properties.extCommands)),e}executeCommand(t,e,o){var r,i;if(!((i=(r=this.properties)==null?void 0:r.handleExecuteCommand)!=null&&i.call(r,t,e,o))){if(o.id==="add-comment"){sa(t,e)||c6.error("failed to add comment to block");return}c6.error(`unknown command: ${JSON.stringify(o)}`)}}}function R1(n,t,e){return{blockCommands:{"hovering-toolbar":new M1(n,t,e)}}}function CS(n){const t=n.querySelector(".editor-preview-iframe"),e=t.src;t.src="about:blank";const o=setTimeout(()=>{t.src=e,clearTimeout(o)},300);return!0}function AS(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function bS(n,t){const e=R1(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:"Refresh page",icon:Mw},{id:"open-page",name:"Open the original page",icon:b5}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return CS(i);case"open-page":return AS(r,i)}return!1}}),o=`[${x.t("webpage.abstract")}]`;return{...e,abstract:o}}const vS=w("webpage-embed");function yS(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:c}=s,a=n.addCustom(`webpage-${l}`,()=>new nS(n,e));u(vS,c,"The src from blockData is invalid "),a.create(n,s,t,i),n.addCustom("webpage-resizer",()=>new aS(n)),e.height&&(i.style.height=`${e.height}px`)}function kS(n,t,e){const{embedData:o,id:r}=e;return n.getCustom(`webpage-${r}`).update(n,t,o),e.height&&(t.style.height=`${e.height}px`),!0}function wS(){return{name:"WebPage",insertEmbedCommandItems:l6(),handleInsertEmptyEmbed:pS}}function BS(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const O1={embedType:"webpage",createEmbedContent:yS,getBlockProperties:bS,getOptions:wS,handleUpdateBlock:kS,convertTo:BS},ES={webpage:{title:"\u7F51\u9875",youku:"\u4F18\u9177\u89C6\u9891",modao:"\u58A8\u5200",tencent:"\u817E\u8BAF\u89C6\u9891",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u56E0\u76EE\u6807\u7F51\u9875\u7684\u9650\u5236\uFF0C\u90E8\u5206\u7F51\u9875\u53EF\u80FD\u65E0\u6CD5\u6210\u529F\u9884\u89C8\u3002",helpLink:"\u5982\u4F55\u83B7\u53D6\u94FE\u63A5",label:"\u7F51\u9875\u5730\u5740",placeholder:"\u8BF7\u8F93\u5165",title:"\u63D2\u5165{name}",errorEnterUrl:"\u8BF7\u8F93\u5165\u7F51\u9875\u5730\u5740",unsupportedUrl:"\u6682\u4E0D\u652F\u6301\u63D2\u5165\u8BE5\u94FE\u63A5\u5185\u5BB9"},abstract:"\u7F51\u9875"}},IS={webpage:{title:"Webpage",youku:"Youku",modao:"Modao",tencent:"Tencent Video",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"Due to the limitation of the landing page, some pages may not be previewed successfully.",helpLink:"How to get the URL link",label:"Please enter webpage address",placeholder:"Please enter url",title:"Insert {name}",errorEnterUrl:"Please enter the webpage address",unsupportedUrl:"Unsupported url"},abstract:"Webpage"}};x.mergeLang({"zh-CN":ES,"en-US":IS});const mV="";function xS(n,t,e,o){var f;const r=n.getBlockByIndex(t,e);if(G(n,r)!==o)return!1;const i=bt(n.getBlockText(r));if(![...i].every(m=>m==="|")||i.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,r,{offset:o});if(!l)return!1;const{blockData:c,focusBlockId:a}=l;if(!c)return!1;const d=n.insertBlock(t,e,c,Ot(n,a!=null?a:c.id,0));return n.deleteBlock(r),(f=l.onConverted)==null||f.call(l,n,d),!0}const TS={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},SS={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function a6(n,t,e,o,r){if(r==="enter"&&xS(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=bt(ve(n.getBlockText(i),o).left).trim(),l=r==="enter"?TS:SS;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var A;const d=Fl(n,i,c.blockType,{offset:o,data:c.data});if(!d)return null;const{blockData:f,focusBlockId:m}=d;if(!f)return null;const p=n.insertBlock(t,e,f,Ot(n,m!=null?m:f.id,0));return n.deleteBlock(i),(A=d.onConverted)==null||A.call(d,n,p),{newBlock:p,focusBlockId:m}})}return!1}function DS(n,t,e,o){const r=n.getBlockByIndex(t,e);return n.getBlockString(r,{boxReplacement:" "}).substring(0,o)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{quoted:!0},Ot(n,r,0))}),!0)}const LS={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function MS(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=LS[i];if(!s)return!1;const l=n.getBlockData(r).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{heading:s},Ot(n,r,0))}),!0}function RS(n,t,e,o){return!!(MS(n,t,e,o)||DS(n,t,e,o))}const OS=w("match-text-style");function NS(n){let t="";for(let e=n.length-1;e>=0;e--){const o=n[e];if(!o.attributes||Object.keys(o.attributes).length===0){t+=o.insert;continue}break}return t}function PS(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),o=e.lastIndexOf(t);return o===-1?-1:o===0?0:e.substring(o-1).startsWith(t)?-1:o}const $S={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function _S(n,t,e,o){var d,f;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=ve(i,o),l=NS(s),c=me(s)-l.length,a=Object.entries($S);for(const[m,p]of a){const A=PS(l,m);if(A===-1)continue;const k=c+A,y=o,T=m.length,E=bt(Gt(i,k+T,y-k-T*2).middle);if(p.type==="style"){const L={};p.styles.forEach(_=>{L[_]=!0});const R=tr(E,L);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,k,y-k),n.insertTextToBlock(r,k,R)})}else if(p.type==="box")try{const L=(f=(d=n.editorBoxes.getBoxClass(p.boxType)).convertFrom)==null?void 0:f.call(d,n,E);if(!L)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,k,y-k),n.insertBoxToBlock(r,k,L)})}catch(L){OS.warn(`failed to convert to box, ${L.message}`);continue}return!0}return!1}class la{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&(RS(t,e,o,r)||_S(t,e,o,r)))}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if($(t,t.getBlockByIndex(r,i))){if(Hn(e,"Enter")){if(a6(t,r,i,s,"enter"))return!0}else if(Hn(e,"Space")&&a6(t,r,i,s,"space"))return!0}return!1}}const FS={"en-US":{placeholder:{default:"Type \u2018/\u2019 for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks @mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}}};x.mergeLang(FS);function Vs(n,t){const e=Ao(n,t);return!!(e.text&&me(e.text)===0&&!t.querySelector(".inputting-insertion"))}function u6(n,t){var o;st(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function ca(n,t,e){var r;if(!Vs(n,t)){u6(n,t);return}const o=st(t);if(typeof e=="string")o.setAttribute("data-content-placeholder",e);else{const i=Rt(t),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:b("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(e)}}function HS(n){const t=n.getAttribute("data-style-heading");return t?x.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?x.t("placeholder.quote"):null}function jS(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?x.t("placeholder.list"):x.t("placeholder.mention"):null}function d6(n){switch(rt(n)){case"text":return HS(n);case"list":return jS(n);default:return null}}function zS(n){if(Wn(n))return!1;const t=U(H(n));return t?rt(t)==="code":!1}function US(n){if(Wn(n))return!1;const t=U(H(n));return t?rt(t)==="table":!1}function VS(n,t){var d,f;const e=n.selection.focusedBlock,o=rt(e),r=t.contentPlaceholder||x.t("placeholder.default");let i=r;if(o&&Vi(n,o)&&e){if(zS(e))return;US(e)?i=x.t("placeholder.common.contentInTable"):i=(d=d6(e))!=null?d:i}const s=n.getFirstBlock(),l=dt(s);if(!l)return;const c=dt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c){Vs(n,l)&&ca(n,l,(f=d6(l))!=null?f:r);return}const a=n.getFocusedBlock();!Vs(n,a)||a!==s&&ca(n,a,i)}function qS(n,t){var r,i;const e=n.getFirstBlock(),o=st(e);Vs(n,e)?(o.setAttribute("data-title-placeholder",(r=t.titlePlaceholder)!=null?r:x.t("placeholder.title")),o.setAttribute("data-title-placeholder-readonly",(i=t.readonlyTitlePlaceholder)!=null?i:"")):(o.removeAttribute("data-title-placeholder"),o.removeAttribute("data-title-placeholder-readonly"))}function WS(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function GS(n,t){WS(n),n.selection.range.isCollapsed()&&(qS(n,t),VS(n,t))}const CV="",ZS=w("enforce-title");class qs{constructor(t,e={headingLevel:1}){h(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(!qs.isDocumentTitleBlock(r,i)||!Hn(e,"Enter"))return!1;let l=!1,c=null;Ze(t.rootContainer)===2&&(c=xr(t.rootContainer,1),G(t,c)===0&&(l=!0));const a=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(a,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e;try{const o=t.doc.getContainerBlocks(V(t.rootContainer));u(ZS,o.length>0,"root container is empty");const r=o[0];if(r.type!=="text"||r.heading!==this.options.headingLevel){const i=Vn("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(V(t.rootContainer),0,i);return}if(o.length>1)return;t.insertTextBlock("",V(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,o;!((e=this.options)!=null&&e.titlePlaceholder)&&!((o=this.options)!=null&&o.contentPlaceholder)||GS(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const h6=w("code-dom");function Do(n){return rt(n)==="code"}function f6(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?j(t,"wrap"):M(t,"wrap")}function N1(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return u(h6,t,"no parent code block"),u(h6,Do(t),"not a code block"),t}const aa={plain:{name:"Plain Text",aliases:["txt","text"]},abap:{name:"ABAP",aliases:["abap"]},arduino:{name:"Arduino",aliases:["ino"]},bash:{name:"Bash",aliases:["sh","shell"]},basic:{name:"BASIC",aliases:["bas"]},c:{name:"C",aliases:["c"]},clojure:{name:"Clojure",aliases:["clj"]},cofeescript:{name:"CoffeeScript",aliases:["coffee"]},cpp:{name:"C++",aliases:["cpp","cxx"]},csharp:{name:"C#",aliases:["cs"]},css:{name:"CSS",aliases:["css"]},dart:{name:"Dart",aliases:["dart"]},diff:{name:"Diff",aliases:["diff","patch"]},docker:{name:"Docker",aliases:["dockerfile"]},elixir:{name:"Elixir",aliases:["ex","exs"]},elm:{name:"Elm",aliases:["elm"]},erlang:{name:"Erlang",aliases:["erl"]},flow:{name:"Flow",aliases:["flow"]},fortran:{name:"Fortran",aliases:["f","for","f77","f90"]},fsharp:{name:"F#",aliases:["fsharp"]},gherkin:{name:"Gherkin",aliases:["feature"]},glsl:{name:"GLSL",aliases:["glsl"]},go:{name:"Go",aliases:["go"]},graphql:{name:"GraphQL",aliases:["graphql"]},groovy:{name:"Groovy",aliases:["groovy"]},haskell:{name:"Haskell",aliases:["hs"]},java:{name:"Java",aliases:["java"]},js:{name:"JavaScript",aliases:["js","jsx"]},json:{name:"JSON",aliases:["json"]},julia:{name:"Julia",aliases:["jl"]},kotlin:{name:"Kotlin",aliases:["kt","ktm","kts"]},latex:{name:"LaTeX",aliases:["tex"]},less:{name:"LESS",aliases:["less"]},lisp:{name:"Lisp",aliases:["lisp"]},livescript:{name:"LiveScript",aliases:["ls"]},lua:{name:"Lua",aliases:["lua"]},makefile:{name:"Makefile",aliases:["mk","mak"]},markdown:{name:"Markdown",aliases:["md","mkdown","mkd"]},markup:{name:"HTML / XML",aliases:["html","htm","xml","xsd","xsl","xslt","wsdl"]},matlab:{name:"MATLAB",aliases:["matlab"]},mermaid:{name:"Mermaid",aliases:["mermaid"]},nix:{name:"Nix",aliases:["nix"]},objectivec:{name:"Objective-C",aliases:["m","mm"]},ocaml:{name:"OCaml",aliases:["ml"]},pascal:{name:"Pascal",aliases:["pas"]},perl:{name:"Perl",aliases:["pl","pm"]},php:{name:"PHP",aliases:["php"]},powershell:{name:"PowerShell",aliases:["ps","ps1"]},prolog:{name:"Prolog",aliases:["plg"]},protobuf:{name:"Protocol Buffers",aliases:["proto"]},python:{name:"Python",aliases:["py"]},r:{name:"R",aliases:["r"]},reason:{name:"Reason",aliases:["re","rei"]},ruby:{name:"Ruby",aliases:["rb"]},rust:{name:"Rust",aliases:["rs"]},sass:{name:"Sass",aliases:["sass"]},scala:{name:"Scala",aliases:["scala"]},scheme:{name:"Scheme",aliases:["scm","sm"]},scss:{name:"SCSS",aliases:["scss"]},solidity:{name:"Solidity",aliases:["sol"]},sql:{name:"SQL",aliases:["sql"]},swift:{name:"Swift",aliases:["swift"]},typescript:{name:"TypeScript",aliases:["ts","tsx"]},vbnet:{name:"VB.Net",aliases:["vbnet"]},verilog:{name:"Verilog",aliases:["v"]},vhdl:{name:"VHDL",aliases:["vhdl"]},"visual-basic":{name:"Visual Basic",aliases:["vb","vba"]},wasm:{name:"WebAssembly",aliases:["wasm"]},yaml:{name:"YAML",aliases:["yaml"]}};function QS(n){const t=n.toLocaleLowerCase();let e="";return Object.entries(aa).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}function m6(n){const t=n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}function YS(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const JS=w("convert-to-code");function KS(n,t){if(!$(n,t))return null;const e={id:P(),type:"text",text:[]},o=P();n.doc.localInsertChildContainer(o,[e]);const r=n.getBlockData(t).text;u(JS,r,"no text");let i=bt(r);i.startsWith("```")&&(i=i.substring(3));const s=QS(i)||m6(n)||"plain";return{blockData:{id:P(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const AV="",P1=w("code-block-child-container");function ai(n){u(P1,Do(n),"not a code block");const e=st(n).querySelector(":scope > div.editor-code-root > div.code-text-root [data-type=editor-container].child");return u(P1,e,"no code text container"),e}function ui(n){u(P1,Do(n),"not a code block");const e=st(n).querySelector(":scope > div.editor-code-root > div.code-caption-root [data-type=editor-container].child");return e||null}function ua(n){const t=[ai(n)],e=ui(n);return e&&t.push(e),t}function di(n,t){if(!$(n,t))return!1;const e=H(t),o=U(e);return o?Do(o)?e===ai(o):rt(t)==="code":!1}const $1=w("code-caption");function XS(n,t){if(n.readonly)return;const e=ui(t);if(e){const c=Ft(e);n.selection.selectBlock(c,0);return}const o=wn(n.doc),r=n.getBlockData(t);u($1,r.children.length===1,"code block should have only one child");const i={...r,children:[r.children[0],o]};n.updateBlockData(t,i);const s=n.getContainerById(o),l=Ft(s);n.selection.selectBlock(l,0)}function g6(n,t){const e=H(t);if(Ct(e))return!1;const o=U(e);if(u($1,o,"no parent block"),!Do(o))return!1;const i=ui(o);return e===i}function tD(n,t){if(n.readonly||!ui(t))return;const o=ai(t),r=Jt(o);n.selection.selectBlock(r,G(n,r));const i=n.getBlockData(t);u($1,i.children.length===2,"code block should have only one child");const s=i.children[1],l={...i,children:[i.children[0]]};n.updateBlockData(t,l),n.deleteChildContainers([s])}const eD=w("paste-in-table-block");class nD{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePaste(t,e,o){if(!t.selection.range.isSimple())return!1;const r=t.selection.range.start,i=t.getBlockById(r.blockId),s=H(i);if(Ct(s))return!1;const l=U(s);if(u(eD,l,"no parent block"),!Do(l)||g6(t,i))return!1;const c=o["text/plain"];return c&&t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,c)}),!0}}function oD(n){n.addCustom("code-block-paste-event",t=>new nD(t))}class rD{constructor(t){h(this,"id","CodeBlockCommandProvider");setTimeout(()=>{t.editorCommandProviders.registerCommandProvider(this)})}destroy(){}getAvailableCommands(){return[]}executeCommand(){return!1}filterCommands(t,e,o,r){if(di(t,e))return[]}beforeExecuteCommand(t,e,o,r,i){return!!di(t,e)}}function iD(n){n.addCustom("code-block-command-provider",t=>new rD(t))}const sD=w("code-caption-input-handler");function _1(n){if(!n.selection.range.isSimple())return null;const t=n.selection.range.start;if(!t.isSimple())return null;const e=n.getBlockById(t.blockId);return g6(n,e)?e:null}function lD(n){const t=_1(n);if(!t)return!1;const e=N1(t),o=dt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",V(H(e)),K(e)+1),!0)}function cD(n){const t=_1(n);if(!t)return!1;if(Tt(n,t)){const e=N1(t);return tD(n,e),!0}return!1}class F1{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?lD(t):e.key==="Backspace"?cD(t):!1}async handleBeforePaste(t,e,o){const r=_1(t);if(!r)return!1;const i=o["text/plain"];if(!i)return!0;const s=sc(t,i);return s&&t.undoManager.runInGroup(()=>{t.clearSelectedContents();const l=t.selection.range.start;u(sD,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new F1(e))}}const aD=`
|
|
381
381
|
<svg fill="currentColor" focusable="false" viewBox="0 0 24 24" aria-hidden="true" tabindex="-1">
|
|
382
382
|
<path d="M8.12 9.29 12 13.17l3.88-3.88c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41l-4.59 4.59c-.39.39-1.02.39-1.41 0L6.7 10.7a.9959.9959 0 0 1 0-1.41c.39-.38 1.03-.39 1.42 0z"></path>
|
|
383
383
|
</svg>`,uD=`
|