@ones-editor/editor 0.0.3-beta.70 → 0.0.3-beta.71
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 oB(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=v5,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=$w,t.appendChild(r)}}}}class cr 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){oB(t,e)}}function rB(n,t,e){var o;return new cr((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=mh}t.states&&(t.states.indexOf("checked")!==-1&&M(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function iB(n,t,e){var o;return new Ts((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const nV="";Qr.registerManualCommandBar("menu",rB),Qr.registerManualCommandBar("toolbar",iB);const oV="",S5=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(S5,e,"no dialog item");const o=e.element;return u(S5,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 sB=[-1,6,0,1,2,3,4,5],lB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],D5=w("color-palette");function L5(n,t,e,o){u(D5,n>0,"no color in palette");const r=t||1;u(D5,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 cB(n){const t=b("button",["color-button"],null),e=sB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=b5,t}function aB(n){const t=b("button",["background-color-button"],null),e=lB[n];return t.setAttribute("data-color-index",`${e}`),t}function uB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=x.t("colorPalette.reset"),n}function dB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.colorDesc")),t.appendChild(L5(8,1,cB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.backgroundDesc")),t.appendChild(L5(16,2,aB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(uB()),t}function hB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&H(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&M(i,"selected")}const rV="",fB={};class mB extends Yt.TypedEmitter{constructor(e=fB){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=dB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){hB(this.root,e,o)}}class M5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new mB(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function gB(){const n=b("button",["color-button"],null);return n.innerHTML=b5,n}function Ih(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 pB 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],Ih(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new M5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=gB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Ih(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Ih(this.element,this.latestColors)}}const iV="";function xh(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),H(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 Th(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 CB=w("ui-base");class AB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{var t,e;Th(this.editor)&&this.editor.focus(),(e=(t=this.options).onClose)==null||e.call(t)});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new cr([],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){CB.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 Sh=w("auto-suggest-menu");class Dh{constructor(t,e){h(this,"menu");h(this,"anchor",null);h(this,"close",()=>{this.menu.close()});h(this,"handleSelectionChanged",t=>{var o,r;if(!((o=this.menu)!=null&&o.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((r=this.anchor)==null?void 0:r.blockId)&&e.offset>=this.anchor.offset){const i=t.getBlockById(e.blockId);if(vt(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=vt(oc(t,i,r));if(u(Sh,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,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});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 AB(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,noResultMessage:e.noResultMessage,highlight:e.highlight,onClose:this.onClose,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)||vu(e.key)?!1:Hm(e)&&!Wo(e)?(setTimeout(()=>{this.resetItems()}),!1):yu(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:j(t),offset:e,leftText:o,trigger:r};const i=V(z(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(j(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=vt(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 j(c)!==l||(a=this.menu)!=null&&a.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=vt(oc(t,i,r));if(u(Sh,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);Sh.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 bB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const vB={"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"},...bB()};function Ce(n){var t;return(t=vB[n])==null?void 0:t.shortcut}function yB(n){var t;return(t=n.subText)!=null?t:""}const xn=w("table-dom");function Io(n){return`${j(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 R5(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 kB(n){const o=R5(n).map(r=>{const i=Ds(r),s=V(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Er.default(o)}function Zt(n){return it(n)==="table"}function Lh(n){const t=z(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?t:Lh(e)}function Qn(n){if(Zt(n))return n;const t=z(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?e:Qn(e)}function wB(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 O5(n){try{return jt(n),!0}catch{return!1}}function BB(n){return Rt(n).querySelector(":scope > .block-helper")}function N5(n){const t=U(n.contentElement);u(xn,t,"no block");const e=BB(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 EB{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 EB(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 IB(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,Qe(t),"cell first child is not a container"),t}function xB(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=IB(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:j(t),type:it(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function ar(n){return new Dc(n)}function TB(n){return ar(xB(n))}const Qt=w("table-grid"),SB=60;class DB{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,Qe(e),"not a child container"),e}}class LB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new DB(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 Vf=class{constructor(t){h(this,"_rows",[]);this.table=t,TB(t).forEach(r=>{this._rows.push(new LB(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=kB(t),o=this.caches.getSync(e,()=>(Qt.debug("create table grid"),new Vf(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let nt=Vf;h(nt,"caches",new Am(SB));function Mc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const MB=w("table-selection-range");function un(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 Mh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===j(t)){const i=nt.fromBlock(t),{start:s,end:l}=r;u(MB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:d,toRow:f}=un(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 Rc(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const o=n.getBlockById(t.start.blockId);if(Zt(o)){const r=z(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 Yr=w("delete-columns");function P5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromRow:s,toRow:l}=un(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.rowCount-1}function Rh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var L;const e=t.getBlockById(n.start.blockId);if(!P5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=un(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 rt=_[W];s.add(rt)}_.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(Yr,_.colSpan>1,"invalid effected cell, colSpan === 1"),_.col<o){u(Yr,c.has(R),"invalid effected cell, not exists");let kt=_.col+_.colSpan-1;kt>r&&(kt=r);const de=kt-o+1,ro=_.colSpan-de;f.set(R,ro);return}u(Yr,_.col<=r,"invalid effected cell, col > endCol");const W=_.col,rt=_.col+_.colSpan-1,lt=_.col-o,gt=rt-W+1-d+lt;u(Yr,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 rt=_[W],lt=m.get(rt);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(Yr,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:rt}=R;u(Yr,rt>=1,"invalid newContainerData, colSpan < 1"),rt>1&&(p[`${W}_colSpan`]=rt);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};ar(E),t.updateBlockData(e,E,Ot(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Jr=w("delete-rows");function $5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromCol:s,toCol:l}=un(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.colCount-1}function Oh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!$5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=un(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(Jr,L.rowSpan>1,"invalid effected cell, rowSpan === 1"),L.row<o){u(Jr,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(Jr,L.row<=r,"invalid effected cell, col > endCol");const R=L.row,_=L.row+L.rowSpan-1,W=L.row-o,rt=_-R+1-d+W;u(Jr,rt>0,"invalid effected cell, newSpanned <= 0");const lt=wn(t.doc);m.set(E,{newContainerId:lt,rowSpan:rt})});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(Jr,E>=1,"invalid modified rowSpan, rowSpan < 1"),E===1?p[`${L}_rowSpan`]=void 0:p[`${L}_rowSpan`]=E}),m.forEach((E,L)=>{Mc(p,L);const{newContainerId:R,rowSpan:_}=E;u(Jr,_>=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};ar(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 Oc(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,it(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 Nh=w("split-cell");function Ph(n,t,e){n.undoManager.runInGroup(()=>{const o=nt.fromBlock(t),r=o.getRealCell(e);u(Nh,!r.virtual,"should not split virtual cell"),u(Nh,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(Nh,a,"no child block");const d=Ot(n,a.id,0);ar(l),n.updateBlockData(t,l,d)})}function RB(n,t,e){e.forEach(o=>{const r=nt.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Ph(n,t,o)})}function _5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=Oc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function $h(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Oc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return RB(t,e,l),!0}const Kr=w("merge-cells");function F5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=Oc(e);return s.cell!==l.cell}function H5(n){const t=Oc(n),e=t.editor;e.undoManager.runInGroup(()=>{const o=t.endCell,r=o.row+o.rowSpan-1,i=o.col+o.colSpan-1,s=j(t.block);$h(n);const l=e.getBlockById(s),c=jt(l),{startRow:a,startCol:d}=t,f=Q.default(e.getBlockData(l));u(Kr,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(Kr,!kt.virtual,"cell is virtual"),p.push(kt)}u(Kr,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(!ju(e,ht)){const de=K0(e,kt);e.insertDocAt(y,Ge(y),de)}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(Kr,f.children,"no table children");const ht=f.children.indexOf(gt);u(Kr,ht>0,"no deleted container"),f.children.splice(ht,1)});const _=f,rt=e.getChildContainerData(E)[0];u(Kr,rt,"no child block");const lt=Ot(e,rt.id,0);ar(_),e.updateBlockData(l,_,lt),e.deleteChildContainers(T)})}const _h=10,OB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Fh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(it(e)!=="table")return[];const r={blockId:j(e),blockKind:Ye(t,e),blockType:it(e)},i=[];F5(t,e,o)&&i.push({id:"table/merge-cells",name:x.t("table.mergeCell"),icon:yw,groupIndex:_h,...r}),_5(t,e,o)&&i.push({id:"table/split-cell",name:x.t("table.splitCell"),icon:kw,groupIndex:_h,...r});const s=P5(t,e,o),l=$5(t,e,o);return s&&l&&i.push({id:"table/delete",name:x.t("table.deleteTable"),icon:ww,groupIndex:_h,...r}),i}executeCommand(t,e,o,r,i,s){return it(e)!=="table"||!new Set(OB).has(r.id)?!1:r.id==="table/merge-cells"?(H5(o),!0):r.id==="table/split-cell"?($h(o),!0):r.id==="table/delete-columns"?(Rh(o),!0):r.id==="table/delete-rows"?(Oh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var j5=(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))(j5||{});const Hh=6,Ms=20,jh="table-cell-menu-btn";function NB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function PB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function $B(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function _B(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function FB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function HB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function jB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const zh=w("get-selected-containers");function Uh(n,t,e,o){u(zh,e.blockId===o.blockId,"only allow select in single table block"),u(zh,j(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}=un(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 zB(n,t,e){u(zh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return Uh(n,o,t,e)}const ur=w("table-cell-dom");function UB(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");u(ur,r,"no parent cell");const i=U(r);if(u(ur,i,"no parent block"),i===t)return r;o=i}return u(ur,!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(ur,e.childContainerId,"block position must have childContainerId attribute"),e;const r=UB(n,t,e.blockId),i=V(Ds(r));return wt(t,i)}function Vh(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return un(t,o,r)}function z5(n,t,e,o){u(ur,Zt(t),"invalid table block");const r=Tn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");u(ur,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"):H(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");u(ur,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"):H(a,"danger")})};i(),s()}function xo(n,t,e=!0,o){const i=nt.fromBlock(t).map(d=>d),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Vh(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||H(p.cell,"danger")}}}function To(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){z5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Vh(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);z5(n,t,Array.from(r),Array.from(i))}function U5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Vh(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 VB(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return Uh(n,t,o,r)}const V5=["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 q5(n){return`style-bg-color-${n}`}function Rs(n){return`${n}_background`}function qB(n,t,e){const o=jt(n),s=(e!=null?e:nt.fromTable(o)).getCell(t).cell;for(let l=0;l<V5.length;l++){const c=V5[l];if(ot(s,c))return c}}function W5(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)]=q5(e)}else{const c=nt.fromBlock(t),a=un(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)]=q5(e))}}n.updateBlockData(t,i)}function WB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const G5=w("table-chart");function GB(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 ZB(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){GB(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 de=1;de<i.colCount;de++){const ro=i.getCell({row:k,col:de}).container.innerText,re=Number.parseFloat(ro)||0;L.push(re)}let R;const _=qB(t,y,i);_?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${_}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[W,rt,lt,gt]=R?su.fromString(R).toRgbaArray():[];if(!W&&!rt&&!lt&&!gt){const de=(k-1)%n.options.colors.length;R=n.options.colors[de],[W,rt,lt,gt]=su.fromString(R).toRgbaArray()}const ht=R,kt=su.fromRgba([W,rt,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(G5,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 Vo(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=lu.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(d)lu.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){G5.error(`failed to resolve chart cdn: ${JSON.stringify(k)}`)}}async function Z5(n,t){await We.lock("updateTableChart");try{await ZB(n,t)}finally{We.release("updateTableChart")}}const Q5=ee.default(Z5,1e3);let Y5=null;function qh(n,t,e){if(Y5!==t&&(Q5.flush(),Y5=t),e.updateNow){Z5(n,t);return}Q5(n,t)}function Wh(n,t){Zt(t)&&qh(n,t,{updateNow:!1})}function QB(n,t){Zt(t)&&qh(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"},Nc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},So={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Pc(n,t){return n.containers.get(t)}function J5(n){return n.closest(`.${So.SCROLL_CONTAINER}`)}function dn(n){return n.firstElementChild}function Oe(n){return n.closest(`.${So.CONTAINER}`)}function Os(n){const t=Oe(n);let e=t.querySelector(`:scope >.${So.TOOL}`);return e||(e=b("div",[So.TOOL],t)),e}function YB(n){return Oe(n).firstElementChild}function $c(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=$c(n);return t/e}function Ns(n){const t=window.getComputedStyle(n),e=$c(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=$c(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function JB(n,t){const e=$c(n);return n[t]*e}function Gh(n,t){const e=Oe(t),o=Pc(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 KB(n,t){const e=Gh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${je(t,0-o)}px`,t.style.paddingLeft=`${je(t,o)}px`}function XB(n,t){const e=Gh(n,t);t.style.marginRight=`${je(t,0-e.maxRight)}px`}function tE(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 K5=w("scroll-bar-handle"),eE=2;function ti(n){const t=Os(n);let e=t.querySelector(`.${Nc.SCROLL_BAR}`);return e||(e=b("div",[Nc.SCROLL_BAR],t)),u(K5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function _c(n,t){const e=J5(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=Gh(n,e),{originWidth:a,maxRight:d}=c;XB(n,e),KB(n,e);const f=r-i;u(K5,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 nE(n,t){const e=dn(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=tE(e),r=t.getBoundingClientRect(),i=ti(t),s=i.getBoundingClientRect(),l=Pc(n,Oe(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=dn(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,Nc.FIXED);const L=k>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+eE+L}px`}else H(i,Nc.FIXED),i.style.bottom=`${je(t,f-s.height)}px`;nE(t,i)}class oE{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=dn(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 dr=w("container-scroll-shadow");function X5(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 tC(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function rE(n){const t=Os(n);u(dr,t,"no container tools");let e=t.querySelector(`.${He.LEFT}`);if(!e){const l=dn(n),c=[He.COMMON,He.LEFT];e=b("div",c,t),u(dr,e instanceof HTMLDivElement,"invalid child for container tools"),X5(e,n,l)}u(dr,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(dr,e instanceof HTMLDivElement,"invalid child for container tools"),tC(e,s),M(e,He.ACTIVE)}function iE(n){const t=Os(n);let e=t.querySelector(`.${He.RIGHT}`);if(!e){const d=dn(n),f=[He.COMMON,He.RIGHT];e=b("div",f,t),u(dr,e instanceof HTMLDivElement,"no div, create shadow failed"),X5(e,n,d)}u(dr,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(dr,e instanceof HTMLDivElement,"no shadow element"),tC(e,a),M(e,He.ACTIVE)}function sE(n){const e=Os(n).querySelector(`.${He.LEFT}`);e&&H(e,He.ACTIVE)}function lE(n){const e=Os(n).querySelector(`.${He.RIGHT}`);e&&H(e,He.ACTIVE)}function Ps(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Xr(n),r=dn(n),{paddingLeft:i,paddingRight:s}=Ns(r),l=JB(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?lE(n):iE(n),r&&t>=l+i?rE(n):sE(n)}class cE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=dn(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 eC=w("container-scroll-observer");class aE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;u(eC,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(eC,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=YB(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",ee.default(this.bindContentScrollCore,300));h(this,"bind",ee.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 uE{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 dE=w("scroll-wrap-resize-observer");class hE{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(dE,e instanceof HTMLElement,"invalid target for observer entry");const o=J5(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 fE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=dn(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=Pc(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=Pc(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 sV="";class mE extends Yt.TypedEmitter{constructor(e){super();h(this,"containerIntersectionObserver",null);h(this,"containerResizeObserver",null);h(this,"containerScrollObserver",null);h(this,"parentContainerScrollObserver",null);h(this,"scrollWrapResizeObserve",null);h(this,"locatingContainerResizeObserver",null);h(this,"isWindowEventBind",!1);h(this,"containers",new Map);h(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});h(this,"handleResize",e=>{this.emit("resize",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=dn(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});h(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{ei(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new cE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new aE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new uE(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new hE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new fE(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 oE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=dn(o);this.unbindCore(o,r),this.containers.delete(e),(i=this.containerIntersectionObserver)==null||i.unbind(o),this.containers.size||this.destroy()}destroy(){var e,o,r,i,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(o=this.containerIntersectionObserver)==null||o.destroy(),(r=this.containerResizeObserver)==null||r.destroy(),(i=this.scrollWrapResizeObserve)==null||i.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const nC=w("scroll-container"),Fc=new Map;class gE 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",[So.CONTAINER],e.parentElement);xt.isMac&&M(o,So.MAC);const r=b("div",[So.SCROLL_CONTAINER],o),i=b("div",[So.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=Fc.get(s),this.scrollListener||(this.scrollListener=new mE(s),Fc.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(nC,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),dn(this.scrollContainerElement)}get scrollOptions(){return u(nC,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&&Fc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),Fc.delete(i))})}}function pE(){return new gE}const Hc=100,CE=40,Zh=w("column-width");function AE(n,t,e){wB(n,t).style.width=`${e}px`}function bE(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)}),Zh.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)}Zh.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 Zh.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 vE=w("table-resize-gripper"),oC=7,Qh=(oC-1)/2,yE=3;function kE(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)<=Qh&&a.top<=e&&e<=a.bottom)return c}}return null}function wE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Yh(n,t){return Tn(n,t).querySelector(".table-resize-gripper")}function rC(n,t){const e=Yh(n,t);u(vE,!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 iC(n,t,e){let o=Yh(n,t);o||(o=rC(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-Qh-Hh-Ms}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${oC}px`}function Jh(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function BE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function EE(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+Qh-yE;const T=Ds(A),E=Hu(n,T)||CE*p.colSpan,L=d(p,l),R=E-L;y<R&&(y=R);const _=k.left+y;a=Math.max(a,_)}return a}const IE=w("table-resize-drag-drop");class xE{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=EE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;u(IE,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;AE(s,p,y),iC(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=$s(t.data.table);BE(this.editor,t.data.block,s),Jh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function TE(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 SE{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=TE(t,i);if(!s||!O5(s)||!t.isBlockWritable(s)){Jh(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=kE(r,e,o);if(i){if(!Yh(this.editor,t)){if(wE(this.editor))return;const l=rC(this.editor,t),c={block:t,table:r,draggingRefCell:i};Cu(new xE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}iC(this.editor,t,i)}else Jh(this.editor)}}function sC(n){n.addCustom("table-mouse-event-handler",t=>new SE(t))}const lC=w("table-insert-column");function cC(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.colCount;u(lC,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(lC,typeof A=="number"&&A>1,`no colSpan for containerId ${m}, ${A}`),c[p]=A+1});const a=c.colsWidth.concat();a.splice(e,0,Hc);const d=nt.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:d,colsWidth:a};ar(f),n.updateBlockData(t,f)})}const jc=w("table-insert-row");function aC(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.rowCount;u(jc,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(jc,p||A,"no top and bottom cell"),e===0||e===r.rowCount||p!==A){const k=wn(n.doc);c.push(k)}else u(jc,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(jc,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};ar(f),n.updateBlockData(t,f)})}const Kh=w("paste-table-in-table-block");function DE(n,t,e,o){let r=nt.fromBlock(e);const i=t.blocks.root[0];u(Kh,i,"no table data"),u(Kh,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)&&Ph(n,e,E)}),m>r.colCount)for(let E=r.colCount;E<m;E++)cC(n,e,E);if(p>r.rowCount)for(let E=r.rowCount;E<p;E++)aC(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 _=Dd(n.editorBlocks,t,R.containerId),W=d+E,rt=f+L,lt={col:W,row:rt},gt=r.getCellContainer(lt);s0(n,gt,_),y=gt}}u(Kh,y,"no last container");const T=Jt(y);n.selection.selectBlock(T,G(n,T))})}const uC=w("paste-in-table-block");class LE{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=z(r);if(Ct(i)||!ju(t,i))return!1;const s=U(i);if(u(uC,s,"no parent block"),!Zt(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;uC.debug("paste child table in table");const a=nt.fromBlock(s).getCellByContainerId(V(i)).cell;return DE(t,e,s,a),!0}}function dC(n){n.addCustom("table-block-paste-event",t=>new LE(t))}const Xh=w("table-select-columns");function ME(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.colCount,"invalid from"),u(Xh,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 t1=w("table-select-columns");function RE(n,t,e,o,r){u(t1,Zt(t),"is not a table block");const i=nt.fromBlock(t);u(t1,e>=0&&e<i.rowCount,"invalid from"),u(t1,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 lV="",hC=w("get-toolbar-reference-client");function OE(n,t){const e=n.selection.range;if(!e.isSimple()){u(hC,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);u(hC,ut(n,s),"not a complex block");const l=At(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 NE(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 zc(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=cu.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=zc(r),NE(s))}),e}function Uc(n){return n.getCustom("toolbar-handler")}const cV="";class PE{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=xh(o,{label:x.t("link.textLabel"),required:!1,placeholder:x.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=xh(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 PE).editLink(t)}const $E=w("link-popup");function _E(n){return ot(n,"link")}function Vc(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function FE(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)&&_E(e)?[{id:"link-text",name:Vc(e),disableTooltip:!0,element:b("span",["link-href-button"],null,Vc(e))},{id:"edit-link",name:"Edit",icon:Eh},{id:"remove-link",name:"Remove link",icon:Mw}]:Lg(n,t,"hovering-toolbar")}function HE(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=Vc(e);_s(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,d)=>{try{const f=n.getBlockText(t),m=rd(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){$E.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function jE(n,t,e){const o=go(t,e),r=n.getBlockText(t),i=Vc(e),s=Pr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function zE(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=Uc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?HE(n,t,e):o.id==="remove-link"&&jE(n,t,e);return}const r=Dg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function qc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const UE=[gh,ph,Ch,Ah,bh,vh,yh,kh];class VE{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=qc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if($(t,e)){const r=j(e),i=it(e),s=Ye(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:UE[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 Wc(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function qE(n,t){let e;const o=Wc(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 fC(n,t){const e=Wc(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 e1(n){return n.readonly||!n.isWritable()}function WE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&qE(n,o)}),!0}function GE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&fC(n,o)}),!0}function ZE(n){return e1(n)?!1:n.undoManager.runInGroup(()=>(WE(n),!0))}function QE(n){return e1(n)?!1:n.undoManager.runInGroup(()=>(GE(n),!0))}function YE(n){if(e1(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||!Wc(t)))return fC(n,t),!0}class JE{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const aV="",KE={Tab:ZE,"Shift+Tab":QE,Backspace:YE},Gc=w("list-block");function at(n){return it(n)==="list"}function zt(n){u(Gc,at(n),"not a list block")}function ze(n){zt(n);const t=n.getAttribute("data-list-type");return u(Gc,t,"no list type"),t}function Zc(n){return at(n)&&ze(n)==="text-only"}function hn(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(Gc,t,"no group id"),t}function Do(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(Gc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function n1(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}=Do(n);let r=pt(n);for(;r;){if(!at(r))return null;const{level:i,groupId:s,type:l}=Do(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 hr(n){zt(n);const{level:t,groupId:e,type:o}=Do(n);let r=dt(n);for(;r;){if(at(r)){const{level:i,groupId:s,type:l}=Do(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 mC(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=hr(n);for(;e;)t.push(e),e=hr(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 XE(n){zt(n);let t=hr(n);for(;t;){const e=hr(t);if(!e)return t;t=e}return null}function gC(n,t){const e=mC(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 o1(n,t,e,o){const r=gC(t,{withSelf:!0});r.length!==0&&js(n,r,e,o)}function tI(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 eI="abcdefghijklmnopqrstuvwxyz";function pC(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=eI[t];return e?pC(e)+o:o}function nI(n){return`${n}`}const CC=[nI,pC,tI];function oI(n,t){const e=CC[(n-1)%CC.length];return e(t)}function rI(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class fr{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=Hs(e),i=hn(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||o1(this.editor,this.listBrother,this.listStart,this.options)}}function iI(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 sI(n,t){const e=n.getAttribute("data-style-heading"),o=iI(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 lI(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=Wc(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=vt(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=sI(t,i);if(p){if(K(t)>K(p))f=hn(p)+1;else{const E=hn(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 fr(E,L).fix()}}}function oi(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function cI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${oI(t,(o=n.start)!=null?o:1)}.`:rI(t)}function Qc(n){return n==="checked"||n==="unchecked"}function AC(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&&(!Qc(c)||!Qc(a))||r.level>l.level}function bC(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&&(!Qc(c)||!Qc(a))||r.level>l.level}function aI(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,AC(n,t,e,r)&&(a=`${a}`),bC(n,t,e,r)&&(a=`${a}`,d<=1&&(a+=`
|
|
341
|
+
</svg>`;function oB(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=v5,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=$w,t.appendChild(r)}}}}class cr 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){oB(t,e)}}function rB(n,t,e){var o;return new cr((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=mh}t.states&&(t.states.indexOf("checked")!==-1&&M(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function iB(n,t,e){var o;return new Ts((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const nV="";Qr.registerManualCommandBar("menu",rB),Qr.registerManualCommandBar("toolbar",iB);const oV="",S5=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(S5,e,"no dialog item");const o=e.element;return u(S5,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 sB=[-1,6,0,1,2,3,4,5],lB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],D5=w("color-palette");function L5(n,t,e,o){u(D5,n>0,"no color in palette");const r=t||1;u(D5,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 cB(n){const t=b("button",["color-button"],null),e=sB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=b5,t}function aB(n){const t=b("button",["background-color-button"],null),e=lB[n];return t.setAttribute("data-color-index",`${e}`),t}function uB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=x.t("colorPalette.reset"),n}function dB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.colorDesc")),t.appendChild(L5(8,1,cB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,x.t("colorPalette.backgroundDesc")),t.appendChild(L5(16,2,aB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(uB()),t}function hB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&H(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&M(i,"selected")}const rV="",fB={};class mB extends Yt.TypedEmitter{constructor(e=fB){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=dB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){hB(this.root,e,o)}}class M5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new mB(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function gB(){const n=b("button",["color-button"],null);return n.innerHTML=b5,n}function Ih(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 pB 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],Ih(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new M5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=gB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Ih(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Ih(this.element,this.latestColors)}}const iV="";function xh(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),H(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 Th(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 CB=w("ui-base");class AB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{var t,e;Th(this.editor)&&this.editor.focus(),(e=(t=this.options).onClose)==null||e.call(t)});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new cr([],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){CB.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 Sh=w("auto-suggest-menu");class Dh{constructor(t,e){h(this,"menu");h(this,"anchor",null);h(this,"close",()=>{this.menu.close()});h(this,"handleSelectionChanged",t=>{var o,r;if(!((o=this.menu)!=null&&o.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((r=this.anchor)==null?void 0:r.blockId)&&e.offset>=this.anchor.offset){const i=t.getBlockById(e.blockId);if(vt(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=vt(oc(t,i,r));if(u(Sh,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,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});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 AB(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,noResultMessage:e.noResultMessage,highlight:e.highlight,onClose:this.onClose,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)||vu(e.key)?!1:Hm(e)&&!Wo(e)?(setTimeout(()=>{this.resetItems()}),!1):yu(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:j(t),offset:e,leftText:o,trigger:r};const i=V(z(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(j(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=vt(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 j(c)!==l||(a=this.menu)!=null&&a.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=vt(oc(t,i,r));if(u(Sh,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);Sh.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 bB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const vB={"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"},...bB()};function Ce(n){var t;return(t=vB[n])==null?void 0:t.shortcut}function yB(n){var t;return(t=n.subText)!=null?t:""}const xn=w("table-dom");function Io(n){return`${j(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 R5(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 kB(n){const o=R5(n).map(r=>{const i=Ds(r),s=V(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Er.default(o)}function Zt(n){return it(n)==="table"}function Lh(n){const t=z(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?t:Lh(e)}function Qn(n){if(Zt(n))return n;const t=z(n);if(Ct(t))return null;const e=U(t);return u(xn,e,"no parent block"),Zt(e)?e:Qn(e)}function wB(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 O5(n){try{return jt(n),!0}catch{return!1}}function BB(n){return Rt(n).querySelector(":scope > .block-helper")}function N5(n){const t=U(n.contentElement);u(xn,t,"no block");const e=BB(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 EB{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 EB(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 IB(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,Qe(t),"cell first child is not a container"),t}function xB(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=IB(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:j(t),type:it(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function ar(n){return new Dc(n)}function TB(n){return ar(xB(n))}const Qt=w("table-grid"),SB=60;class DB{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,Qe(e),"not a child container"),e}}class LB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new DB(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 Vf=class{constructor(t){h(this,"_rows",[]);this.table=t,TB(t).forEach(r=>{this._rows.push(new LB(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=kB(t),o=this.caches.getSync(e,()=>(Qt.debug("create table grid"),new Vf(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let nt=Vf;h(nt,"caches",new Am(SB));function Mc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const MB=w("table-selection-range");function un(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 Mh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===j(t)){const i=nt.fromBlock(t),{start:s,end:l}=r;u(MB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:d,toRow:f}=un(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 Rc(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const o=n.getBlockById(t.start.blockId);if(Zt(o)){const r=z(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 Yr=w("delete-columns");function P5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromRow:s,toRow:l}=un(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.rowCount-1}function Rh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var L;const e=t.getBlockById(n.start.blockId);if(!P5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=un(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 rt=_[W];s.add(rt)}_.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(Yr,_.colSpan>1,"invalid effected cell, colSpan === 1"),_.col<o){u(Yr,c.has(R),"invalid effected cell, not exists");let kt=_.col+_.colSpan-1;kt>r&&(kt=r);const de=kt-o+1,ro=_.colSpan-de;f.set(R,ro);return}u(Yr,_.col<=r,"invalid effected cell, col > endCol");const W=_.col,rt=_.col+_.colSpan-1,lt=_.col-o,gt=rt-W+1-d+lt;u(Yr,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 rt=_[W],lt=m.get(rt);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(Yr,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:rt}=R;u(Yr,rt>=1,"invalid newContainerData, colSpan < 1"),rt>1&&(p[`${W}_colSpan`]=rt);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};ar(E),t.updateBlockData(e,E,Ot(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Jr=w("delete-rows");function $5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{fromCol:s,toCol:l}=un(t,e.start,e.end),c=nt.fromBlock(t);return s===0&&l===c.colCount-1}function Oh(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!$5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=un(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(Jr,L.rowSpan>1,"invalid effected cell, rowSpan === 1"),L.row<o){u(Jr,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(Jr,L.row<=r,"invalid effected cell, col > endCol");const R=L.row,_=L.row+L.rowSpan-1,W=L.row-o,rt=_-R+1-d+W;u(Jr,rt>0,"invalid effected cell, newSpanned <= 0");const lt=wn(t.doc);m.set(E,{newContainerId:lt,rowSpan:rt})});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(Jr,E>=1,"invalid modified rowSpan, rowSpan < 1"),E===1?p[`${L}_rowSpan`]=void 0:p[`${L}_rowSpan`]=E}),m.forEach((E,L)=>{Mc(p,L);const{newContainerId:R,rowSpan:_}=E;u(Jr,_>=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};ar(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 Oc(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,it(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 Nh=w("split-cell");function Ph(n,t,e){n.undoManager.runInGroup(()=>{const o=nt.fromBlock(t),r=o.getRealCell(e);u(Nh,!r.virtual,"should not split virtual cell"),u(Nh,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(Nh,a,"no child block");const d=Ot(n,a.id,0);ar(l),n.updateBlockData(t,l,d)})}function RB(n,t,e){e.forEach(o=>{const r=nt.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Ph(n,t,o)})}function _5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=Oc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function $h(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Oc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return RB(t,e,l),!0}const Kr=w("merge-cells");function F5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||it(t)!=="table")return!1;const{startCell:s,endCell:l}=Oc(e);return s.cell!==l.cell}function H5(n){const t=Oc(n),e=t.editor;e.undoManager.runInGroup(()=>{const o=t.endCell,r=o.row+o.rowSpan-1,i=o.col+o.colSpan-1,s=j(t.block);$h(n);const l=e.getBlockById(s),c=jt(l),{startRow:a,startCol:d}=t,f=Q.default(e.getBlockData(l));u(Kr,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(Kr,!kt.virtual,"cell is virtual"),p.push(kt)}u(Kr,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(!ju(e,ht)){const de=K0(e,kt);e.insertDocAt(y,Ge(y),de)}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(Kr,f.children,"no table children");const ht=f.children.indexOf(gt);u(Kr,ht>0,"no deleted container"),f.children.splice(ht,1)});const _=f,rt=e.getChildContainerData(E)[0];u(Kr,rt,"no child block");const lt=Ot(e,rt.id,0);ar(_),e.updateBlockData(l,_,lt),e.deleteChildContainers(T)})}const _h=10,OB=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Fh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(it(e)!=="table")return[];const r={blockId:j(e),blockKind:Ye(t,e),blockType:it(e)},i=[];F5(t,e,o)&&i.push({id:"table/merge-cells",name:x.t("table.mergeCell"),icon:yw,groupIndex:_h,...r}),_5(t,e,o)&&i.push({id:"table/split-cell",name:x.t("table.splitCell"),icon:kw,groupIndex:_h,...r});const s=P5(t,e,o),l=$5(t,e,o);return s&&l&&i.push({id:"table/delete",name:x.t("table.deleteTable"),icon:ww,groupIndex:_h,...r}),i}executeCommand(t,e,o,r,i,s){return it(e)!=="table"||!new Set(OB).has(r.id)?!1:r.id==="table/merge-cells"?(H5(o),!0):r.id==="table/split-cell"?($h(o),!0):r.id==="table/delete-columns"?(Rh(o),!0):r.id==="table/delete-rows"?(Oh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var j5=(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))(j5||{});const Hh=6,Ms=20,jh="table-cell-menu-btn";function NB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function PB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function $B(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function _B(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function FB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function HB(n,t){if(!n.isBlockWritable(t))return;const o={...Q.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function jB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const zh=w("get-selected-containers");function Uh(n,t,e,o){u(zh,e.blockId===o.blockId,"only allow select in single table block"),u(zh,j(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}=un(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 zB(n,t,e){u(zh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return Uh(n,o,t,e)}const ur=w("table-cell-dom");function UB(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");u(ur,r,"no parent cell");const i=U(r);if(u(ur,i,"no parent block"),i===t)return r;o=i}return u(ur,!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(ur,e.childContainerId,"block position must have childContainerId attribute"),e;const r=UB(n,t,e.blockId),i=V(Ds(r));return wt(t,i)}function Vh(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return un(t,o,r)}function z5(n,t,e,o){u(ur,Zt(t),"invalid table block");const r=Tn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");u(ur,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"):H(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");u(ur,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"):H(a,"danger")})};i(),s()}function xo(n,t,e=!0,o){const i=nt.fromBlock(t).map(d=>d),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Vh(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||H(p.cell,"danger")}}}function To(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){z5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Vh(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);z5(n,t,Array.from(r),Array.from(i))}function U5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Vh(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 VB(n,t){const e=n.selection.range,o=Yn(n,t,e.start),r=Yn(n,t,e.end);return Uh(n,t,o,r)}const V5=["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 q5(n){return`style-bg-color-${n}`}function Rs(n){return`${n}_background`}function qB(n,t,e){const o=jt(n),s=(e!=null?e:nt.fromTable(o)).getCell(t).cell;for(let l=0;l<V5.length;l++){const c=V5[l];if(ot(s,c))return c}}function W5(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)]=q5(e)}else{const c=nt.fromBlock(t),a=un(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)]=q5(e))}}n.updateBlockData(t,i)}function WB(n,t,e){if(!n.isBlockWritable(t))return;const r={...Q.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const G5=w("table-chart");function GB(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 ZB(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){GB(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 de=1;de<i.colCount;de++){const ro=i.getCell({row:k,col:de}).container.innerText,re=Number.parseFloat(ro)||0;L.push(re)}let R;const _=qB(t,y,i);_?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${_}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[W,rt,lt,gt]=R?su.fromString(R).toRgbaArray():[];if(!W&&!rt&&!lt&&!gt){const de=(k-1)%n.options.colors.length;R=n.options.colors[de],[W,rt,lt,gt]=su.fromString(R).toRgbaArray()}const ht=R,kt=su.fromRgba([W,rt,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(G5,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 Vo(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=lu.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(d)lu.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){G5.error(`failed to resolve chart cdn: ${JSON.stringify(k)}`)}}async function Z5(n,t){await We.lock("updateTableChart");try{await ZB(n,t)}finally{We.release("updateTableChart")}}const Q5=ee.default(Z5,1e3);let Y5=null;function qh(n,t,e){if(Y5!==t&&(Q5.flush(),Y5=t),e.updateNow){Z5(n,t);return}Q5(n,t)}function Wh(n,t){Zt(t)&&qh(n,t,{updateNow:!1})}function QB(n,t){Zt(t)&&qh(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"},Nc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},So={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Pc(n,t){return n.containers.get(t)}function J5(n){return n.closest(`.${So.SCROLL_CONTAINER}`)}function dn(n){return n.firstElementChild}function Oe(n){return n.closest(`.${So.CONTAINER}`)}function Os(n){const t=Oe(n);let e=t.querySelector(`:scope >.${So.TOOL}`);return e||(e=b("div",[So.TOOL],t)),e}function YB(n){return Oe(n).firstElementChild}function $c(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=$c(n);return t/e}function Ns(n){const t=window.getComputedStyle(n),e=$c(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=$c(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function JB(n,t){const e=$c(n);return n[t]*e}function Gh(n,t){const e=Oe(t),o=Pc(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 KB(n,t){const e=Gh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${je(t,0-o)}px`,t.style.paddingLeft=`${je(t,o)}px`}function XB(n,t){const e=Gh(n,t);t.style.marginRight=`${je(t,0-e.maxRight)}px`}function tE(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 K5=w("scroll-bar-handle"),eE=2;function ti(n){const t=Os(n);let e=t.querySelector(`.${Nc.SCROLL_BAR}`);return e||(e=b("div",[Nc.SCROLL_BAR],t)),u(K5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function _c(n,t){const e=J5(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=Gh(n,e),{originWidth:a,maxRight:d}=c;XB(n,e),KB(n,e);const f=r-i;u(K5,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 nE(n,t){const e=dn(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=tE(e),r=t.getBoundingClientRect(),i=ti(t),s=i.getBoundingClientRect(),l=Pc(n,Oe(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=dn(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,Nc.FIXED);const L=k>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+eE+L}px`}else H(i,Nc.FIXED),i.style.bottom=`${je(t,f-s.height)}px`;nE(t,i)}class oE{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=dn(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 dr=w("container-scroll-shadow");function X5(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 tC(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function rE(n){const t=Os(n);u(dr,t,"no container tools");let e=t.querySelector(`.${He.LEFT}`);if(!e){const l=dn(n),c=[He.COMMON,He.LEFT];e=b("div",c,t),u(dr,e instanceof HTMLDivElement,"invalid child for container tools"),X5(e,n,l)}u(dr,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(dr,e instanceof HTMLDivElement,"invalid child for container tools"),tC(e,s),M(e,He.ACTIVE)}function iE(n){const t=Os(n);let e=t.querySelector(`.${He.RIGHT}`);if(!e){const d=dn(n),f=[He.COMMON,He.RIGHT];e=b("div",f,t),u(dr,e instanceof HTMLDivElement,"no div, create shadow failed"),X5(e,n,d)}u(dr,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(dr,e instanceof HTMLDivElement,"no shadow element"),tC(e,a),M(e,He.ACTIVE)}function sE(n){const e=Os(n).querySelector(`.${He.LEFT}`);e&&H(e,He.ACTIVE)}function lE(n){const e=Os(n).querySelector(`.${He.RIGHT}`);e&&H(e,He.ACTIVE)}function Ps(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Xr(n),r=dn(n),{paddingLeft:i,paddingRight:s}=Ns(r),l=JB(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?lE(n):iE(n),r&&t>=l+i?rE(n):sE(n)}class cE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=dn(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 eC=w("container-scroll-observer");class aE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;u(eC,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(eC,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=YB(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",ee.default(this.bindContentScrollCore,300));h(this,"bind",ee.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 uE{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 dE=w("scroll-wrap-resize-observer");class hE{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(dE,e instanceof HTMLElement,"invalid target for observer entry");const o=J5(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 fE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=dn(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=Pc(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=Pc(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 sV="";class mE extends Yt.TypedEmitter{constructor(e){super();h(this,"containerIntersectionObserver",null);h(this,"containerResizeObserver",null);h(this,"containerScrollObserver",null);h(this,"parentContainerScrollObserver",null);h(this,"scrollWrapResizeObserve",null);h(this,"locatingContainerResizeObserver",null);h(this,"isWindowEventBind",!1);h(this,"containers",new Map);h(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});h(this,"handleResize",e=>{this.emit("resize",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=dn(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});h(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{ei(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new cE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new aE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new uE(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new hE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new fE(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 oE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=dn(o);this.unbindCore(o,r),this.containers.delete(e),(i=this.containerIntersectionObserver)==null||i.unbind(o),this.containers.size||this.destroy()}destroy(){var e,o,r,i,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(o=this.containerIntersectionObserver)==null||o.destroy(),(r=this.containerResizeObserver)==null||r.destroy(),(i=this.scrollWrapResizeObserve)==null||i.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const nC=w("scroll-container"),Fc=new Map;class gE 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",[So.CONTAINER],e.parentElement);xt.isMac&&M(o,So.MAC);const r=b("div",[So.SCROLL_CONTAINER],o),i=b("div",[So.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=Fc.get(s),this.scrollListener||(this.scrollListener=new mE(s),Fc.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(nC,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),dn(this.scrollContainerElement)}get scrollOptions(){return u(nC,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&&Fc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),Fc.delete(i))})}}function pE(){return new gE}const Hc=100,CE=40,Zh=w("column-width");function AE(n,t,e){wB(n,t).style.width=`${e}px`}function bE(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)}),Zh.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)}Zh.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 Zh.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 vE=w("table-resize-gripper"),oC=7,Qh=(oC-1)/2,yE=3;function kE(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)<=Qh&&a.top<=e&&e<=a.bottom)return c}}return null}function wE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function Yh(n,t){return Tn(n,t).querySelector(".table-resize-gripper")}function rC(n,t){const e=Yh(n,t);u(vE,!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 iC(n,t,e){let o=Yh(n,t);o||(o=rC(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-Qh-Hh-Ms}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${oC}px`}function Jh(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function BE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function EE(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+Qh-yE;const T=Ds(A),E=Hu(n,T)||CE*p.colSpan,L=d(p,l),R=E-L;y<R&&(y=R);const _=k.left+y;a=Math.max(a,_)}return a}const IE=w("table-resize-drag-drop");class xE{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=EE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;u(IE,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;AE(s,p,y),iC(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=$s(t.data.table);BE(this.editor,t.data.block,s),Jh(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function TE(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 SE{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=TE(t,i);if(!s||!O5(s)||!t.isBlockWritable(s)){Jh(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=kE(r,e,o);if(i){if(!Yh(this.editor,t)){if(wE(this.editor))return;const l=rC(this.editor,t),c={block:t,table:r,draggingRefCell:i};Cu(new xE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}iC(this.editor,t,i)}else Jh(this.editor)}}function sC(n){n.addCustom("table-mouse-event-handler",t=>new SE(t))}const lC=w("table-insert-column");function cC(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.colCount;u(lC,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(lC,typeof A=="number"&&A>1,`no colSpan for containerId ${m}, ${A}`),c[p]=A+1});const a=c.colsWidth.concat();a.splice(e,0,Hc);const d=nt.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:d,colsWidth:a};ar(f),n.updateBlockData(t,f)})}const jc=w("table-insert-row");function aC(n,t,e){n.undoManager.runInGroup(()=>{const o=jt(t),r=nt.fromTable(o),i=r.rowCount;u(jc,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(jc,p||A,"no top and bottom cell"),e===0||e===r.rowCount||p!==A){const k=wn(n.doc);c.push(k)}else u(jc,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(jc,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};ar(f),n.updateBlockData(t,f)})}const Kh=w("paste-table-in-table-block");function DE(n,t,e,o){let r=nt.fromBlock(e);const i=t.blocks.root[0];u(Kh,i,"no table data"),u(Kh,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)&&Ph(n,e,E)}),m>r.colCount)for(let E=r.colCount;E<m;E++)cC(n,e,E);if(p>r.rowCount)for(let E=r.rowCount;E<p;E++)aC(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 _=Dd(n.editorBlocks,t,R.containerId),W=d+E,rt=f+L,lt={col:W,row:rt},gt=r.getCellContainer(lt);s0(n,gt,_),y=gt}}u(Kh,y,"no last container");const T=Jt(y);n.selection.selectBlock(T,G(n,T))})}const uC=w("paste-in-table-block");class LE{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=z(r);if(Ct(i)||!ju(t,i))return!1;const s=U(i);if(u(uC,s,"no parent block"),!Zt(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;uC.debug("paste child table in table");const a=nt.fromBlock(s).getCellByContainerId(V(i)).cell;return DE(t,e,s,a),!0}}function dC(n){n.addCustom("table-block-paste-event",t=>new LE(t))}const Xh=w("table-select-columns");function ME(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.colCount,"invalid from"),u(Xh,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 t1=w("table-select-columns");function RE(n,t,e,o,r){u(t1,Zt(t),"is not a table block");const i=nt.fromBlock(t);u(t1,e>=0&&e<i.rowCount,"invalid from"),u(t1,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 lV="",hC=w("get-toolbar-reference-client");function OE(n,t){const e=n.selection.range;if(!e.isSimple()){u(hC,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);u(hC,ut(n,s),"not a complex block");const l=At(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 NE(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 zc(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=cu.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=zc(r),NE(s))}),e}function Uc(n){return n.getCustom("toolbar-handler")}const cV="";class PE{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,r=this.formatUrl(o.getInputValue());(t=this.onFinished)==null||t.call(this,e.getInputValue()||r,r),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"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}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=xh(o,{label:x.t("link.textLabel"),required:!1,placeholder:x.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=xh(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 PE).editLink(t)}const $E=w("link-popup");function _E(n){return ot(n,"link")}function Vc(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function FE(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)&&_E(e)?[{id:"link-text",name:Vc(e),disableTooltip:!0,element:()=>{const c=Vc(e),a=b("span",["link-href-button"],null,c),d=()=>window.open(c);return a.onclick=d,a.addEventListener("unload",()=>{a.removeEventListener("click",d)}),a}},{id:"edit-link",name:"Edit",icon:Eh},{id:"remove-link",name:"Remove link",icon:Mw}]:Lg(n,t,"hovering-toolbar")}function HE(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=Vc(e);_s(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,d)=>{try{const f=n.getBlockText(t),m=rd(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){$E.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function jE(n,t,e){const o=go(t,e),r=n.getBlockText(t),i=Vc(e),s=Pr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function zE(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=Uc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?HE(n,t,e):o.id==="remove-link"&&jE(n,t,e);return}const r=Dg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function qc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const UE=[gh,ph,Ch,Ah,bh,vh,yh,kh];class VE{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=qc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if($(t,e)){const r=j(e),i=it(e),s=Ye(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:UE[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 Wc(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function qE(n,t){let e;const o=Wc(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 fC(n,t){const e=Wc(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 e1(n){return n.readonly||!n.isWritable()}function WE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&qE(n,o)}),!0}function GE(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;$(n,o)&&fC(n,o)}),!0}function ZE(n){return e1(n)?!1:n.undoManager.runInGroup(()=>(WE(n),!0))}function QE(n){return e1(n)?!1:n.undoManager.runInGroup(()=>(GE(n),!0))}function YE(n){if(e1(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||!Wc(t)))return fC(n,t),!0}class JE{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const aV="",KE={Tab:ZE,"Shift+Tab":QE,Backspace:YE},Gc=w("list-block");function at(n){return it(n)==="list"}function zt(n){u(Gc,at(n),"not a list block")}function ze(n){zt(n);const t=n.getAttribute("data-list-type");return u(Gc,t,"no list type"),t}function Zc(n){return at(n)&&ze(n)==="text-only"}function hn(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(Gc,t,"no group id"),t}function Do(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(Gc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function n1(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,t={ignoreGroupId:!1}){zt(n);const{level:e,groupId:o,type:r}=Do(n);let i=pt(n);for(;i;){if(!at(i))return null;const{level:s,groupId:l,type:c}=Do(i);if(s<e)return null;if(e===s&&(t.ignoreGroupId||o===l)&&(c==="text-only"||r==="text-only"||r===c))return i;i=pt(i)}return null}function hr(n){zt(n);const{level:t,groupId:e,type:o}=Do(n);let r=dt(n);for(;r;){if(at(r)){const{level:i,groupId:s,type:l}=Do(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 mC(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=hr(n);for(;e;)t.push(e),e=hr(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 XE(n){zt(n);let t=hr(n);for(;t;){const e=hr(t);if(!e)return t;t=e}return null}function gC(n,t){const e=mC(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 o1(n,t,e,o){const r=gC(t,{withSelf:!0});r.length!==0&&js(n,r,e,o)}function tI(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 eI="abcdefghijklmnopqrstuvwxyz";function pC(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=eI[t];return e?pC(e)+o:o}function nI(n){return`${n}`}const CC=[nI,pC,tI];function oI(n,t){const e=CC[(n-1)%CC.length];return e(t)}function rI(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class fr{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=Hs(e),i=hn(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||o1(this.editor,this.listBrother,this.listStart,this.options)}}function iI(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 sI(n,t){const e=n.getAttribute("data-style-heading"),o=iI(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 lI(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=Wc(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=vt(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=sI(t,i);if(p){if(K(t)>K(p))f=hn(p)+1;else{const E=hn(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 fr(E,L).fix()}}}function oi(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function cI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${oI(t,(o=n.start)!=null?o:1)}.`:rI(t)}function Qc(n){return n==="checked"||n==="unchecked"}function AC(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&&(!Qc(c)||!Qc(a))||r.level>l.level}function bC(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&&(!Qc(c)||!Qc(a))||r.level>l.level}function aI(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,AC(n,t,e,r)&&(a=`${a}`),bC(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>`,AC(n,t,e,r)&&(a=`<${d}>${a}`),bC(n,t,e,r)&&(a=`${a}</${d}>`),a}return""}const uI=8,Nt=w("list-block");class Yc{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,Zc(e))return;const o=Hs(e),r=hn(o);this.listStart=r,o===e?this.listBrother=hr(o):this.listBrother=o}fix(){!this.listBrother||o1(this.editor,this.listBrother,this.listStart)}}function dI(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function r1(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}=Do(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,...n1(r)};dI(n,e,d);let f=K(e);const m=z(e);o==="after"&&(f+=1);let p=null;at(t)&&(p=new Yc(n,t));const A=n.insertBlock(V(m),f,d,ec(d.id,0));return n.deleteBlock(t),new fr(n,A).fix(),p==null||p.fix(),!0}function hI(n,t,e,o){if(Nt.debug("drag a list between text blocks"),o==="after"){const a=dt(e);if(a&&at(a))return r1(n,t,a,"before")}if(o==="before"){const a=pt(e);if(a&&at(a))return r1(n,t,a,"after")}const i={...n.getBlockData(t),groupId:P(),start:1,level:1};let s=K(e);const l=z(e);o==="after"&&(s+=1),n.insertBlock(V(l),s,i,ec(i.id,0));const c=new Yc(n,t);return n.deleteBlock(t),c.fix(),!0}function fI(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"),r1(n,s,c,o)):hI(n,s,c,o)}const mI=`<?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>
|
|
@@ -360,7 +360,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
360
360
|
<path d="M9.99978 5.99611L14.5 1.49609" stroke="currentColor" stroke-width="2"/>
|
|
361
361
|
<path d="M1 10.0039H5.99738L5.99608 15" stroke="currentColor" stroke-width="2"/>
|
|
362
362
|
<path d="M14.9971 5.99611H9.99969L10.001 1" stroke="currentColor" stroke-width="2"/>
|
|
363
|
-
</svg>`;async function EI(n,t,e){const o=Rt(t),r=o.querySelector('[data-button-id="mindmap-fullscreen"]');u(Nt,r,"no full screen button");const i=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{H(o,"fullscreen"),r.innerHTML=yC,h5(r,"Full screen",n.clientId),wC(t)&&setTimeout(()=>{i()},300)};if(document.fullscreenElement===o){try{await kC()}catch(l){Nt.error(l)}s()}else{try{M(o,"fullscreen"),await kI(o),i()}catch(l){Nt.error(l)}r.innerHTML=BI,h5(r,x.t("mindmap.exitFullscreen"),n.clientId)}o.onfullscreenchange=()=>{document.fullscreenElement||s()}}function s1(n,t,e,o,r){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=Bo(e,o,r,[],n.clientId);return M(s,"mindmap-button"),t.appendChild(s),s}function l1(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function II(n){return l1(n,"mindmap-fullscreen")}function xI(n){return l1(n,"mindmap-fit")}function TI(n){return l1(n,"mindmap-close")}function SI(n,t,e,o){const r=s1(n,t,"mindmap-close",x.t("mindmap.close"),vI);!r||n.domEvents.addEventListener(r,"click",()=>{o.closeMindmap(n,e)})}function DI(n,t,e,o){const r=s1(n,t,"mindmap-fit",x.t("mindmap.autoFit"),yI);!r||n.domEvents.addEventListener(r,"click",()=>{o.fitMindmap(n,e)})}function LI(n,t,e,o){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const i=s1(n,t,"mindmap-fullscreen",x.t("mindmap.fullScreen"),yC);!i||n.domEvents.addEventListener(i,"click",()=>{EI(n,e,o)})}function MI(n,t){const e=$l(t);if(!e)return;const o=xI(e);o&&(o.remove(),n.domEvents.removeAllListeners(o));const r=TI(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=II(e);i&&(i.remove(),n.domEvents.removeAllListeners(i))}const ri=new Map;function c1(n,t,e){const o=(s,l)=>{s.forEach(c=>{l?M(c.block,"to-mindmap-highlight"):H(c.block,"to-mindmap-highlight"),o(c.children,l)})},r=vC(n,t);if(r.length===0)return;const i=r[0].block;if(e){const s=ri.get(i);s&&(s.forEach(l=>l.cancel()),ri.delete(i)),o(r,!0)}else{const s=setTimeout(()=>{o(r,!1),ri.delete(i)},300),l=()=>{clearTimeout(s),ri.delete(i)},c=ri.get(i);c?c.push({cancel:l}):ri.set(i,[{cancel:l}])}}const{Markmap:RI}=i8;function OI(n,t){zt(t);const e=vC(n,t),o=e[0].block,r=a=>({t:"text",v:st(a.block).textContent,d:1,c:a.children.length>0?a.children.map(f=>r(f)):void 0});let i=null;e.length>1?i={t:"root",v:"root",d:0,c:e.length>0?e.map(a=>r(a)):void 0}:i=r(e[0]);const l=a=>{if(a.length===0)return null;const d=a[a.length-1];return d.children&&d.children.length>0?l(d.children):d},c=l(e);return{root:i,block:o,nodes:e,last:c}}function a1(n,t,e,o){const{root:r,block:i,last:s}=OI(n,t);o.selectBlock&&n.selection.selectBlock(i,0,0),c1(n,i,!1),o.saveData&&n.updateBlockData(i,{viewAsMindmap:!0});const l=Rt(i);let c=l.querySelector(".editor-mindmap-svg");if(o.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const T="http://www.w3.org/2000/svg",E=l.getBoundingClientRect(),L=document.fullscreenElement===l,R=L?`${E.width}`:`${t.getBoundingClientRect().width}`,_=L?`${E.height}`:"600",W=document.createElementNS(T,"svg");W.setAttributeNS(null,"viewBox",`0 0 ${R} ${_}`),W.setAttributeNS(null,"width","100%"),W.setAttributeNS(null,"height",_),W.style.display="block",W.style.width="100%",W.style.height=`${_}px`,W.classList.add("editor-mindmap-svg"),l.appendChild(W),c=W}const a=i,f=`editor-mindmap-root-${j(i)}`;M(a,"editor-in-mindmap-first",f,"readonly"),a.contentEditable="false";const m=dt(i);m&&K(m)<=K(s.block)&&wI(m,s.block,["block-hidden",f]);const p=(T,E)=>{if(E.length>0){const L=E[0].parentElement;L&&(L.style.width="100vw",L.style.maxWidth="200px")}E.forEach(L=>{M(L,"editor-mindmap-node")})},A=new RI(c,{...e,autoFit:!0});A.viewHooks.transformHtml.tap(p),A.setData(r),A.fit();const k=Rt(i);let y=k.querySelector(".mindmap-toolbar");y||(y=b("div",["mindmap-toolbar"],k)),DI(n,y,a,o.mindmapTools),LI(n,y,a,o.mindmapTools),SI(n,y,a,o.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(i,0),n.input.focus()}),a.mindMap=A}function NI(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(r=>{if(r.startsWith(e))return r})}async function BC(n,t){const e=NI(t);if(!e)return;n.updateBlockData(t,{viewAsMindmap:null});const o=z(t);Mt(o).forEach(l=>{ot(l,e)&&H(l,e,"editor-in-mindmap-first","block-hidden")});const i=Rt(t);document.fullscreenElement===i&&await kC();const s=i.querySelector(".editor-mindmap-svg");u(Nt,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),t.contentEditable="inherit",MI(n,t),n.selection.selectBlock(t,0)}function PI(n,t){const e=t.mindMap;e&&e.fit()}const EC={toMindmap:a1,closeMindmap:BC,fitMindmap:PI};function IC(n){let t=dt(n);if(!t)return null;const e=hr(n);for(;t!==e;){if(u(Nt,t,"no next block"),at(t))return Ae(t)>Ae(n)?t:null;if(t=dt(t),!t)return null}return null}function u1(n){const t=[];let e=IC(n);if(!e)return t;for(;e;){const o=hr(e);t.push({block:e,children:u1(e)}),e=o}return t}function $I(n){const t=(o,r)=>{r.push(o.block),o.children.forEach(i=>t(i,r))},e=[];return n.forEach(o=>t(o,e)),e}function xC(n,t){return Ae(t)!==1}function TC(n,t,e){t.forEach(o=>{const r=n.getBlockData(o.block);n.updateBlockData(o.block,{...r,groupId:e,level:r.level-1}),o.children.length&&TC(n,o.children,r.groupId)})}function d1(n,t){if(!xC(n,t))return!1;const e=Ae(t);if(e===1)return!1;let o=P(),r=1,i=ze(t);const s=e-1,l=i1(t);l&&(o=ni(l),r=hn(l)+1,i!=="text-only"&&(i=ze(l)));const c=u1(t),a=n.getBlockData(t),d={...a,groupId:o,level:s,start:r,...n1(i)};n.updateBlockData(t,d),n.doc.beginBatchUpdate(),TC(n,c,a.groupId),n.doc.endBatchUpdate(),new fr(n,t).fix();const m=IC(t);return m&&new fr(n,m,{resetStart:!0,resetGroupId:!0}).fix(),!0}function ii(n,t){zt(t);const e=n.getBlockData(t),o={id:P(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new Yc(n,t),i=z(t),s=K(t);n.deleteBlock(t);const l=ec(o.id,0);n.insertBlock(V(i),s,o,l),r.fix()}function _I(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!at(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:Ae(t)===1?(ii(n,t),!0):(d1(n,t),!0)}const FI=w("list-block");function HI(n,t,e){u(FI,at(t),"not a list block");const o={...n.getBlockData(t),id:P()};return e!=null&&e.level&&(o.level=e.level),e!=null&&e.start&&(o.start=e.start),e!=null&&e.keepText||delete o.text,o}function jI(n){if(zt(n),!Zc(n))return n;let t=Jn(n);for(;t;){if(!Zc(t))return t;t=Jn(t)}return null}function zI(n,t,e,o){const r=new fr(n,o),i=hn(o)+1;jr(n,t,e,{forceInsertAfter:!0,newBlockData:HI(n,o,{start:i})}),r.fix()}function UI(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(at(l)&&G(n,l)===0)return ii(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!at(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===G(n,t)?jI(t):t)!=null?s:t;return zI(n,t,o,i),!0}function SC(n){u(Nt,at(n),"not a list block");const{level:t}=Do(n);let e=pt(n);for(;e;){if(at(e)){const{level:o}=Do(e);if(t===o)return e;if(o<t)return null}e=pt(e)}return null}function DC(n,t){return zt(t),SC(t)?Ae(t)<uI:!1}function VI(n,t,e){let o=pt(t);u(Nt,o,"no prev brother");const r=Ae(e);for(;o;){if(o===e)return null;if(at(o)&&Ae(o)===r+1)return o;o=pt(o)}return null}function LC(n,t){if(!DC(n,t))return!1;zt(t);const e=SC(t);u(Nt,e,"no list prev brother");const o=e,r=VI(n,t,o),i=Ae(o)+1;let s=P(),l=1,c=ze(t);r&&(s=ni(r),l=hn(r)+1,c=ze(r));const a=u1(t),f={...n.getBlockData(t),groupId:s,level:i,start:l,...n1(c)};return n.updateBlockData(t,f),n.doc.beginBatchUpdate(),$I(a).forEach(p=>{const A=n.getBlockData(p);n.updateBlockData(p,{...A,level:A.level+1})}),n.doc.endBatchUpdate(),!0}function qI(n,t,e){return t.length===0||!t.every(o=>at(o.block))?!1:e==="increase"?DC(n,t[0].block):xC(n,t[0].block)}function MC(n,t,e){if(!qI(n,t,e))return!1;const o=t[0].block,r=Ae(o),i=t.filter(a=>Ae(a.block)<=r),s=gC(o,{withSelf:!1}),l=new Set(i.map(a=>a.block)),c=s.filter(a=>!l.has(a));return n.undoManager.runInGroup(()=>{let a=null;c.length>0&&(a=new fr(n,c[0])),i.forEach(d=>{e==="increase"?LC(n,d.block):d1(n,d.block)}),a==null||a.fix()}),!0}function WI(n,t){return LC(n,t)}function GI(n,t){return d1(n,t)}function ZI(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return MC(n,t,"increase"),!0;const e=t[0].block;if(!at(e))return!1;const o=new Yc(n,e);return WI(n,e)&&(o.fix(),new fr(n,e).fix()),!0}function QI(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return MC(n,t,"decrease"),!0;const e=t[0].block;return at(e)?(GI(n,e),!0):!1}class YI{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>at(i.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!at(e.block)||Hn(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>UI(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>_I(this.editor))}handleTab(t){return Hn(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>QI(this.editor)):this.editor.undoManager.runInGroup(()=>ZI(this.editor))}}class JI{constructor(t){h(this,"effectedBlockIds",new Map);h(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(r=>{const i=r.block;at(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var c;const i=Hs(r),{start:s}=Do(i);o.set(j(i),s);const l=(c=XE(r))!=null?c:r;o.set(j(l),s)}),this.effectedBlockIds=o});h(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||o1(this.editor,o,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const KI=w("customize-list-start-menu");class XI{constructor(t){h(this,"popup");h(this,"block",null);h(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");u(KI,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});h(this,"createDialogContent",()=>{const t=b("div",["customize-start-panel"],null);b("span",["customize-start-panel-title"],t,x.t("list.numberLabel"));const e=b("input",["customize-start-panel-input"],t);e.type="number",e.setAttribute("min","1");const o=b("button",["customize-start-panel-button"],t,x.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});h(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,o=e.querySelector("button.customize-start-panel-button"),r=e.querySelector("input.customize-start-panel-input"),i=hn(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});h(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),o=this.block;if(!o)return;const r=Number(e.value);!r||(this.editor.undoManager.runInGroup(()=>{js(this.editor,[o,...Fs(o)],r,{resetGroupId:!0})}),this.popup.close())});h(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||o.key==="Escape"&&this.popup.close()});this.editor=t,this.popup=new Es(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}}function tx(n,t){return ni(n)===ni(t)}function ex(n,t){const e=Jn(t),o=pt(t);return!e&&!o||!o||!at(o)?!1:at(o)&&tx(o,t)?hn(o)!==hn(t)-1:!0}function nx(n,t){return!!Jn(t)}function ox(n,t){zt(t);const e=[{id:"continue-numbering",name:x.t("list.continueList")},{id:"start-new-list",name:x.t("list.restartList")},{id:"set-numbering-value",name:x.t("list.changeNumber")}];return ex(n,t)||(e[0].states=["disabled"]),nx(n,t)||(e[1].states=["disabled"]),e}function rx(n,t,e){var o,r;if(zt(t),e.id==="continue-numbering"){const i=pt(t),s=Jn(t)||(i&&at(i)?i:null);s&&js(n,[t,...Fs(t)],hn(s)+1,{resetGroupId:!0,groupId:ni(s)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{js(n,[t,...Fs(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const i=(o=n.options.componentsOptions)==null?void 0:o.list;if((r=i==null?void 0:i.onChangeStart)!=null&&r.call(i,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new XI(n)).show(n,t)}}class ix{constructor(t){h(this,"menu");h(this,"handleClick",(t,e)=>{const o=xr(e,"div.list-container");if(o&&this.editor.isWritable()){const r=U(o);u(Nt,r,"no parent block"),zt(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!0)}});h(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});h(this,"handleMenuClick",(t,e)=>{var r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=U(o);i&&rx(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new cr([]),this.menu.addListener("close",this.handleMenuClose),this.menu.addListener("click",this.handleMenuClick)}destroy(){this.editor.removeListener("click",this.handleClick),this.menu.removeListener("close",this.handleMenuClose)}getCommandItems(t){return ox(this.editor,t)}activeList(t,e){const o=U(t);!o||(e?(M(t,"active"),M(o,"active")):(H(t,"active"),H(o,"active")))}}class sx{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0)return!1;const r=o[0].block;if(!at(r)||!wC(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=Dr(r);return i&&t.selection.selectBlock(i,G(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Lr(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&BC(t,r),!0}}function lx(n,t,e,o,r){Qd(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new sx(n)),n.input.addHandler(new YI(n)),n.addCustom("list-clear-selection-handler",()=>new JI(n)),n.addCustom("list-marker-menu",()=>new ix(n))})});const i=ye.createBlockContent(n,t,e,o,r),s=r,{level:l,start:c,groupId:a}=s,d=oi(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${c||1}`),o.setAttribute("data-list-group-id",`${a}`),o.setAttribute("data-list-type",d);const f=CI(s);return o.insertBefore(f,i),s.viewAsMindmap&&setTimeout(()=>{const m=n.getBlockById(r.id);m&&a1(n,m,{},{mindmapTools:EC,saveData:!1})}),i}const cx=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
363
|
+
</svg>`;async function EI(n,t,e){const o=Rt(t),r=o.querySelector('[data-button-id="mindmap-fullscreen"]');u(Nt,r,"no full screen button");const i=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{H(o,"fullscreen"),r.innerHTML=yC,h5(r,"Full screen",n.clientId),wC(t)&&setTimeout(()=>{i()},300)};if(document.fullscreenElement===o){try{await kC()}catch(l){Nt.error(l)}s()}else{try{M(o,"fullscreen"),await kI(o),i()}catch(l){Nt.error(l)}r.innerHTML=BI,h5(r,x.t("mindmap.exitFullscreen"),n.clientId)}o.onfullscreenchange=()=>{document.fullscreenElement||s()}}function s1(n,t,e,o,r){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=Bo(e,o,r,[],n.clientId);return M(s,"mindmap-button"),t.appendChild(s),s}function l1(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function II(n){return l1(n,"mindmap-fullscreen")}function xI(n){return l1(n,"mindmap-fit")}function TI(n){return l1(n,"mindmap-close")}function SI(n,t,e,o){const r=s1(n,t,"mindmap-close",x.t("mindmap.close"),vI);!r||n.domEvents.addEventListener(r,"click",()=>{o.closeMindmap(n,e)})}function DI(n,t,e,o){const r=s1(n,t,"mindmap-fit",x.t("mindmap.autoFit"),yI);!r||n.domEvents.addEventListener(r,"click",()=>{o.fitMindmap(n,e)})}function LI(n,t,e,o){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const i=s1(n,t,"mindmap-fullscreen",x.t("mindmap.fullScreen"),yC);!i||n.domEvents.addEventListener(i,"click",()=>{EI(n,e,o)})}function MI(n,t){const e=$l(t);if(!e)return;const o=xI(e);o&&(o.remove(),n.domEvents.removeAllListeners(o));const r=TI(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=II(e);i&&(i.remove(),n.domEvents.removeAllListeners(i))}const ri=new Map;function c1(n,t,e){const o=(s,l)=>{s.forEach(c=>{l?M(c.block,"to-mindmap-highlight"):H(c.block,"to-mindmap-highlight"),o(c.children,l)})},r=vC(n,t);if(r.length===0)return;const i=r[0].block;if(e){const s=ri.get(i);s&&(s.forEach(l=>l.cancel()),ri.delete(i)),o(r,!0)}else{const s=setTimeout(()=>{o(r,!1),ri.delete(i)},300),l=()=>{clearTimeout(s),ri.delete(i)},c=ri.get(i);c?c.push({cancel:l}):ri.set(i,[{cancel:l}])}}const{Markmap:RI}=i8;function OI(n,t){zt(t);const e=vC(n,t),o=e[0].block,r=a=>({t:"text",v:st(a.block).textContent,d:1,c:a.children.length>0?a.children.map(f=>r(f)):void 0});let i=null;e.length>1?i={t:"root",v:"root",d:0,c:e.length>0?e.map(a=>r(a)):void 0}:i=r(e[0]);const l=a=>{if(a.length===0)return null;const d=a[a.length-1];return d.children&&d.children.length>0?l(d.children):d},c=l(e);return{root:i,block:o,nodes:e,last:c}}function a1(n,t,e,o){const{root:r,block:i,last:s}=OI(n,t);o.selectBlock&&n.selection.selectBlock(i,0,0),c1(n,i,!1),o.saveData&&n.updateBlockData(i,{viewAsMindmap:!0});const l=Rt(i);let c=l.querySelector(".editor-mindmap-svg");if(o.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const T="http://www.w3.org/2000/svg",E=l.getBoundingClientRect(),L=document.fullscreenElement===l,R=L?`${E.width}`:`${t.getBoundingClientRect().width}`,_=L?`${E.height}`:"600",W=document.createElementNS(T,"svg");W.setAttributeNS(null,"viewBox",`0 0 ${R} ${_}`),W.setAttributeNS(null,"width","100%"),W.setAttributeNS(null,"height",_),W.style.display="block",W.style.width="100%",W.style.height=`${_}px`,W.classList.add("editor-mindmap-svg"),l.appendChild(W),c=W}const a=i,f=`editor-mindmap-root-${j(i)}`;M(a,"editor-in-mindmap-first",f,"readonly"),a.contentEditable="false";const m=dt(i);m&&K(m)<=K(s.block)&&wI(m,s.block,["block-hidden",f]);const p=(T,E)=>{if(E.length>0){const L=E[0].parentElement;L&&(L.style.width="100vw",L.style.maxWidth="200px")}E.forEach(L=>{M(L,"editor-mindmap-node")})},A=new RI(c,{...e,autoFit:!0});A.viewHooks.transformHtml.tap(p),A.setData(r),A.fit();const k=Rt(i);let y=k.querySelector(".mindmap-toolbar");y||(y=b("div",["mindmap-toolbar"],k)),DI(n,y,a,o.mindmapTools),LI(n,y,a,o.mindmapTools),SI(n,y,a,o.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(i,0),n.input.focus()}),a.mindMap=A}function NI(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(r=>{if(r.startsWith(e))return r})}async function BC(n,t){const e=NI(t);if(!e)return;n.updateBlockData(t,{viewAsMindmap:null});const o=z(t);Mt(o).forEach(l=>{ot(l,e)&&H(l,e,"editor-in-mindmap-first","block-hidden")});const i=Rt(t);document.fullscreenElement===i&&await kC();const s=i.querySelector(".editor-mindmap-svg");u(Nt,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),t.contentEditable="inherit",MI(n,t),n.selection.selectBlock(t,0)}function PI(n,t){const e=t.mindMap;e&&e.fit()}const EC={toMindmap:a1,closeMindmap:BC,fitMindmap:PI};function IC(n){let t=dt(n);if(!t)return null;const e=hr(n);for(;t!==e;){if(u(Nt,t,"no next block"),at(t))return Ae(t)>Ae(n)?t:null;if(t=dt(t),!t)return null}return null}function u1(n){const t=[];let e=IC(n);if(!e)return t;for(;e;){const o=hr(e);t.push({block:e,children:u1(e)}),e=o}return t}function $I(n){const t=(o,r)=>{r.push(o.block),o.children.forEach(i=>t(i,r))},e=[];return n.forEach(o=>t(o,e)),e}function xC(n,t){return Ae(t)!==1}function TC(n,t,e){t.forEach(o=>{const r=n.getBlockData(o.block);n.updateBlockData(o.block,{...r,groupId:e,level:r.level-1}),o.children.length&&TC(n,o.children,r.groupId)})}function d1(n,t){if(!xC(n,t))return!1;const e=Ae(t);if(e===1)return!1;let o=P(),r=1,i=ze(t);const s=e-1,l=i1(t);l&&(o=ni(l),r=hn(l)+1,i!=="text-only"&&(i=ze(l)));const c=u1(t),a=n.getBlockData(t),d={...a,groupId:o,level:s,start:r,...n1(i)};n.updateBlockData(t,d),n.doc.beginBatchUpdate(),TC(n,c,a.groupId),n.doc.endBatchUpdate(),new fr(n,t).fix();const m=IC(t);return m&&new fr(n,m,{resetStart:!0,resetGroupId:!0}).fix(),!0}function ii(n,t){zt(t);const e=n.getBlockData(t),o={id:P(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new Yc(n,t),i=z(t),s=K(t);n.deleteBlock(t);const l=ec(o.id,0);n.insertBlock(V(i),s,o,l),r.fix()}function _I(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!at(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:Ae(t)===1?(ii(n,t),!0):(d1(n,t),!0)}const FI=w("list-block");function HI(n,t,e){u(FI,at(t),"not a list block");const o={...n.getBlockData(t),id:P()};return e!=null&&e.level&&(o.level=e.level),e!=null&&e.start&&(o.start=e.start),e!=null&&e.keepText||delete o.text,o}function jI(n){if(zt(n),!Zc(n))return n;let t=Jn(n);for(;t;){if(!Zc(t))return t;t=Jn(t)}return null}function zI(n,t,e,o){const r=new fr(n,o),i=hn(o)+1;jr(n,t,e,{forceInsertAfter:!0,newBlockData:HI(n,o,{start:i})}),r.fix()}function UI(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(at(l)&&G(n,l)===0)return ii(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!at(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===G(n,t)?jI(t):t)!=null?s:t;return zI(n,t,o,i),!0}function SC(n){u(Nt,at(n),"not a list block");const{level:t}=Do(n);let e=pt(n);for(;e;){if(at(e)){const{level:o}=Do(e);if(t===o)return e;if(o<t)return null}e=pt(e)}return null}function DC(n,t){return zt(t),SC(t)?Ae(t)<uI:!1}function VI(n,t,e){let o=pt(t);u(Nt,o,"no prev brother");const r=Ae(e);for(;o;){if(o===e)return null;if(at(o)&&Ae(o)===r+1)return o;o=pt(o)}return null}function LC(n,t){if(!DC(n,t))return!1;zt(t);const e=SC(t);u(Nt,e,"no list prev brother");const o=e,r=VI(n,t,o),i=Ae(o)+1;let s=P(),l=1,c=ze(t);r&&(s=ni(r),l=hn(r)+1,c=ze(r));const a=u1(t),f={...n.getBlockData(t),groupId:s,level:i,start:l,...n1(c)};return n.updateBlockData(t,f),n.doc.beginBatchUpdate(),$I(a).forEach(p=>{const A=n.getBlockData(p);n.updateBlockData(p,{...A,level:A.level+1})}),n.doc.endBatchUpdate(),!0}function qI(n,t,e){return t.length===0||!t.every(o=>at(o.block))?!1:e==="increase"?DC(n,t[0].block):xC(n,t[0].block)}function MC(n,t,e){if(!qI(n,t,e))return!1;const o=t[0].block,r=Ae(o),i=t.filter(a=>Ae(a.block)<=r),s=gC(o,{withSelf:!1}),l=new Set(i.map(a=>a.block)),c=s.filter(a=>!l.has(a));return n.undoManager.runInGroup(()=>{let a=null;c.length>0&&(a=new fr(n,c[0])),i.forEach(d=>{e==="increase"?LC(n,d.block):d1(n,d.block)}),a==null||a.fix()}),!0}function WI(n,t){return LC(n,t)}function GI(n,t){return d1(n,t)}function ZI(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return MC(n,t,"increase"),!0;const e=t[0].block;if(!at(e))return!1;const o=new Yc(n,e);return WI(n,e)&&(o.fix(),new fr(n,e).fix()),!0}function QI(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return MC(n,t,"decrease"),!0;const e=t[0].block;return at(e)?(GI(n,e),!0):!1}class YI{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>at(i.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!at(e.block)||Hn(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>UI(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>_I(this.editor))}handleTab(t){return Hn(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>QI(this.editor)):this.editor.undoManager.runInGroup(()=>ZI(this.editor))}}class JI{constructor(t){h(this,"effectedBlockIds",new Map);h(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(r=>{const i=r.block;at(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var c;const i=Hs(r),{start:s}=Do(i);o.set(j(i),s);const l=(c=XE(r))!=null?c:r;o.set(j(l),s)}),this.effectedBlockIds=o});h(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||o1(this.editor,o,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const KI=w("customize-list-start-menu");class XI{constructor(t){h(this,"popup");h(this,"block",null);h(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");u(KI,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});h(this,"createDialogContent",()=>{const t=b("div",["customize-start-panel"],null);b("span",["customize-start-panel-title"],t,x.t("list.numberLabel"));const e=b("input",["customize-start-panel-input"],t);e.type="number",e.setAttribute("min","1");const o=b("button",["customize-start-panel-button"],t,x.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});h(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,o=e.querySelector("button.customize-start-panel-button"),r=e.querySelector("input.customize-start-panel-input"),i=hn(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});h(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),o=this.block;if(!o)return;const r=Number(e.value);!r||(this.editor.undoManager.runInGroup(()=>{js(this.editor,[o,...Fs(o)],r,{resetGroupId:!0})}),this.popup.close())});h(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||o.key==="Escape"&&this.popup.close()});this.editor=t,this.popup=new Es(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}}function tx(n,t){return ni(n)===ni(t)}function ex(n,t){const e=Jn(t),o=pt(t);return!e&&!o||!o||!at(o)?!1:at(o)&&tx(o,t)?hn(o)!==hn(t)-1:!0}function nx(n,t){return!!Jn(t)}function ox(n,t){zt(t);const e=[{id:"continue-numbering",name:x.t("list.continueList")},{id:"start-new-list",name:x.t("list.restartList")},{id:"set-numbering-value",name:x.t("list.changeNumber")}];return ex(n,t)||(e[0].states=["disabled"]),nx(n,t)||(e[1].states=["disabled"]),e}function rx(n,t,e){var o,r;if(zt(t),e.id==="continue-numbering"){const i=pt(t),s=Jn(t,{ignoreGroupId:!0})||(i&&at(i)?i:null);s&&js(n,[t,...Fs(t)],hn(s)+1,{resetGroupId:!0,groupId:ni(s)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{js(n,[t,...Fs(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const i=(o=n.options.componentsOptions)==null?void 0:o.list;if((r=i==null?void 0:i.onChangeStart)!=null&&r.call(i,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new XI(n)).show(n,t)}}class ix{constructor(t){h(this,"menu");h(this,"handleClick",(t,e)=>{const o=xr(e,"div.list-container");if(o&&this.editor.isWritable()){const r=U(o);u(Nt,r,"no parent block"),zt(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!0)}});h(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});h(this,"handleMenuClick",(t,e)=>{var r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=U(o);i&&rx(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new cr([]),this.menu.addListener("close",this.handleMenuClose),this.menu.addListener("click",this.handleMenuClick)}destroy(){this.editor.removeListener("click",this.handleClick),this.menu.removeListener("close",this.handleMenuClose)}getCommandItems(t){return ox(this.editor,t)}activeList(t,e){const o=U(t);!o||(e?(M(t,"active"),M(o,"active")):(H(t,"active"),H(o,"active")))}}class sx{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0)return!1;const r=o[0].block;if(!at(r)||!wC(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=Dr(r);return i&&t.selection.selectBlock(i,G(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Lr(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&BC(t,r),!0}}function lx(n,t,e,o,r){Qd(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new sx(n)),n.input.addHandler(new YI(n)),n.addCustom("list-clear-selection-handler",()=>new JI(n)),n.addCustom("list-marker-menu",()=>new ix(n))})});const i=ye.createBlockContent(n,t,e,o,r),s=r,{level:l,start:c,groupId:a}=s,d=oi(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${c||1}`),o.setAttribute("data-list-group-id",`${a}`),o.setAttribute("data-list-type",d);const f=CI(s);return o.insertBefore(f,i),s.viewAsMindmap&&setTimeout(()=>{const m=n.getBlockById(r.id);m&&a1(n,m,{},{mindmapTools:EC,saveData:!1})}),i}const cx=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
364
364
|
<path d="M8 8H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
|
|
365
365
|
<path d="M8 14H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
|
|
366
366
|
<path d="M8 2H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
|
|
@@ -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>`,D1=w("webpage");class sS{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(D1,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(D1,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");u(D1,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=iS,{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 lS(n,t){b("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function L1(n){return Rt(n).querySelector(".block-resizer")}function cS(n){const t=L1(n);t&&H(t,"active")}function c4(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 aS(n,t,e,o){const r=L1(n);if(r)return M(r,"active"),c4(n,t,r),r;const i=Rt(n),s=b("div",["block-resizer"],i);return c4(n,t,s),e.resize.forEach(l=>{lS(s,l)}),s.addEventListener("mousedown",o),M(s,"active"),s}function a4(n,t){const e=L1(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 pV="",uS=w("block-resizer");class sa 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),a4(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||a4(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||(cS(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(uS,It(this.block,e),"not a block child element"),aS(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 u4(n){return n&&Te(n)&&Ne(n)==="webpage"}const dS=1e3,hS=100;class fS{constructor(t){h(this,"currentBlockElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&u4(e)&&this.disableBlockResize(e),t&&u4(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,dS),hS);o.style.height=`${r}px`,M(o,"resizing")});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;H(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(`${j(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${j(t)}-resizer`,()=>new sa(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 CV="",mS=w("editor-dialog");function gS(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=C5,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 pS extends Ss{constructor(e,o){super(gS(e,o),o);h(this,"_options");h(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();u(mS,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 d4=()=>[{name:x.t("webpage.bilibili"),id:"insert-bilibili",icon:_w,group:"thirdParty",subText:Ce("insert-bilibili")},{name:x.t("webpage.youku"),id:"insert-youku",icon:Fw,group:"thirdParty",subText:Ce("insert-youku")},{name:x.t("webpage.figma"),id:"insert-figma",icon:Hw,group:"thirdParty",subText:Ce("insert-figma")},{name:x.t("webpage.modao"),id:"insert-modao",icon:jw,group:"thirdParty",subText:Ce("insert-modao")},{name:x.t("webpage.tencent"),id:"insert-tencent",icon:zw,group:"thirdParty",subText:Ce("insert-tencent")},{id:"insert-webPage",name:x.t("webpage.title"),icon:Uw,group:"common",order:1e3,subText:Ce("insert-webPage")}];function M1(n){return n==="insert-webPage"}async function CS(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function AS(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`${window.location.protocol}//${n}`:n}async function bS(n){if(!n)throw new Error(x.t("webpage.dialog.errorEnterUrl"));const t=n;try{new URL(t)}catch{throw new Error(x.t("webpage.dialog.unsupportedUrl"))}}async function vS(n,t){const e=t.item.id,o=d4().find(a=>a.id===e),r=b("div",["webpage-content"],null);if(M1(e)){const a=b("div",["help-container"],r),d=b("div",["help-content"],a),f=b("span",["help-icon"],d);f.innerHTML=y5,b("span",[],d,x.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:c}=xh(r,{required:!0,label:x.t("webpage.dialog.label"),placeholder:x.t("webpage.dialog.placeholder")});if(!M1(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=w5;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 pS(r,{title:x.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var T;const y=AS(i());try{await bS(y);const E=await CS(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(M1(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 h4=w("embed-block-properties");function la(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 R1{constructor(t,e,o){h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:Eh},{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"){la(t,e)||h4.error("failed to add comment to block");return}h4.error(`unknown command: ${JSON.stringify(o)}`)}}}function O1(n,t,e){return{blockCommands:{"hovering-toolbar":new R1(n,t,e)}}}function yS(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 kS(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function wS(n,t){const e=O1(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:"Refresh page",icon:Nw},{id:"open-page",name:"Open the original page",icon:w5}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return yS(i);case"open-page":return kS(r,i)}return!1}}),o=`[${x.t("webpage.abstract")}]`;return{...e,abstract:o}}const BS=w("webpage-embed");function ES(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:c}=s,a=n.addCustom(`webpage-${l}`,()=>new sS(n,e));u(BS,c,"The src from blockData is invalid "),a.create(n,s,t,i),n.addCustom("webpage-resizer",()=>new fS(n)),e.height&&(i.style.height=`${e.height}px`)}function IS(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 xS(){return{name:"WebPage",insertEmbedCommandItems:d4(),handleInsertEmptyEmbed:vS}}function TS(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const N1={embedType:"webpage",createEmbedContent:ES,getBlockProperties:wS,getOptions:xS,handleUpdateBlock:IS,convertTo:TS},SS={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"}},DS={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":SS,"en-US":DS});const AV="";function LS(n,t,e,o){var f;const r=n.getBlockByIndex(t,e);if(G(n,r)!==o)return!1;const i=vt(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 MS={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"}}},RS={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 f4(n,t,e,o,r){if(r==="enter"&&LS(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=vt(ve(n.getBlockText(i),o).left).trim(),l=r==="enter"?MS:RS;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 OS(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 NS={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function PS(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=NS[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 $S(n,t,e,o){return!!(PS(n,t,e,o)||OS(n,t,e,o))}const _S=w("match-text-style");function FS(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 HS(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 jS={"*":{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 zS(n,t,e,o){var d,f;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=ve(i,o),l=FS(s),c=me(s)-l.length,a=Object.entries(jS);for(const[m,p]of a){const A=HS(l,m);if(A===-1)continue;const k=c+A,y=o,T=m.length,E=vt(Gt(i,k+T,y-k-T*2).middle);if(p.type==="style"){const L={};p.styles.forEach(_=>{L[_]=!0});const R=nr(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){_S.warn(`failed to convert to box, ${L.message}`);continue}return!0}return!1}class ca{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&($S(t,e,o,r)||zS(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(f4(t,r,i,s,"enter"))return!0}else if(Hn(e,"Space")&&f4(t,r,i,s,"space"))return!0}return!1}}const US={"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(US);function Vs(n,t){const e=Ao(n,t);return!!(e.text&&me(e.text)===0&&!t.querySelector(".inputting-insertion"))}function m4(n,t){var o;st(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function aa(n,t,e){var r;if(!Vs(n,t)){m4(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 VS(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 qS(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?x.t("placeholder.list"):x.t("placeholder.mention"):null}function g4(n){switch(it(n)){case"text":return VS(n);case"list":return qS(n);default:return null}}function WS(n){if(Wn(n))return!1;const t=U(z(n));return t?it(t)==="code":!1}function GS(n){return!Wn(n)}function ZS(n,t){var d,f;const e=n.selection.focusedBlock,o=it(e),r=t.contentPlaceholder||x.t("placeholder.default");let i=r;if(o&&Vi(n,o)&&e){if(!n.isBlockWritable(e)||WS(e))return;GS(e)?i=x.t("placeholder.common.contentInTable"):i=(d=g4(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)&&aa(n,l,(f=g4(l))!=null?f:r);return}const a=n.getFocusedBlock();!Vs(n,a)||a!==s&&aa(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 YS(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 JS(n,t){YS(n),n.selection.range.isCollapsed()&&(QS(n,t),ZS(n,t))}const yV="",KS=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;Ge(t.rootContainer)===2&&(c=Sr(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(KS,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)||JS(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const p4=w("code-dom");function Mo(n){return it(n)==="code"}function C4(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?H(t,"wrap"):M(t,"wrap")}function P1(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return u(p4,t,"no parent code block"),u(p4,Mo(t),"not a code block"),t}const ua={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 XS(n){const t=n.toLocaleLowerCase();let e="";return Object.entries(ua).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}function A4(n){const t=n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}function tD(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const eD=w("convert-to-code");function nD(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(eD,r,"no text");let i=vt(r);i.startsWith("```")&&(i=i.substring(3));const s=XS(i)||A4(n)||"plain";return{blockData:{id:P(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const kV="",$1=w("code-block-child-container");function ai(n){u($1,Mo(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($1,e,"no code text container"),e}function ui(n){u($1,Mo(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 da(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=z(t),o=U(e);return o?Mo(o)?e===ai(o):it(t)==="code":!1}const _1=w("code-caption");function oD(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 b4(n,t){const e=z(t);if(Ct(e))return!1;const o=U(e);if(u(_1,o,"no parent block"),!Mo(o))return!1;const i=ui(o);return e===i}function rD(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 iD=w("paste-in-table-block");class sD{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=z(i);if(Ct(s))return!1;const l=U(s);if(u(iD,l,"no parent block"),!Mo(l)||b4(t,i))return!1;const c=o["text/plain"];return c&&t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,c)}),!0}}function lD(n){n.addCustom("code-block-paste-event",t=>new sD(t))}class cD{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 aD(n){n.addCustom("code-block-command-provider",t=>new cD(t))}const uD=w("code-caption-input-handler");function F1(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 b4(n,e)?e:null}function dD(n){const t=F1(n);if(!t)return!1;const e=P1(t),o=dt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",V(z(e)),K(e)+1),!0)}function hD(n){const t=F1(n);if(!t)return!1;if(Tt(n,t)){const e=P1(t);return rD(n,e),!0}return!1}class H1{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?dD(t):e.key==="Backspace"?hD(t):!1}async handleBeforePaste(t,e,o){const r=F1(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(uD,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new H1(e))}}const fD=`
|
|
380
|
+
</svg>`,D1=w("webpage");class sS{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(D1,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(D1,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");u(D1,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=iS,{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 lS(n,t){b("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function L1(n){return Rt(n).querySelector(".block-resizer")}function cS(n){const t=L1(n);t&&H(t,"active")}function c4(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 aS(n,t,e,o){const r=L1(n);if(r)return M(r,"active"),c4(n,t,r),r;const i=Rt(n),s=b("div",["block-resizer"],i);return c4(n,t,s),e.resize.forEach(l=>{lS(s,l)}),s.addEventListener("mousedown",o),M(s,"active"),s}function a4(n,t){const e=L1(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 pV="",uS=w("block-resizer");class sa 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),a4(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||a4(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||(cS(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(uS,It(this.block,e),"not a block child element"),aS(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 u4(n){return n&&Te(n)&&Ne(n)==="webpage"}const dS=1e3,hS=100;class fS{constructor(t){h(this,"currentBlockElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&u4(e)&&this.disableBlockResize(e),t&&u4(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,dS),hS);o.style.height=`${r}px`,M(o,"resizing")});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;H(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(`${j(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${j(t)}-resizer`,()=>new sa(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 CV="",mS=w("editor-dialog");function gS(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=C5,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 pS extends Ss{constructor(e,o){super(gS(e,o),o);h(this,"_options");h(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();u(mS,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 d4=()=>[{name:x.t("webpage.bilibili"),id:"insert-bilibili",icon:_w,group:"thirdParty",subText:Ce("insert-bilibili")},{name:x.t("webpage.youku"),id:"insert-youku",icon:Fw,group:"thirdParty",subText:Ce("insert-youku")},{name:x.t("webpage.figma"),id:"insert-figma",icon:Hw,group:"thirdParty",subText:Ce("insert-figma")},{name:x.t("webpage.modao"),id:"insert-modao",icon:jw,group:"thirdParty",subText:Ce("insert-modao")},{name:x.t("webpage.tencent"),id:"insert-tencent",icon:zw,group:"thirdParty",subText:Ce("insert-tencent")},{id:"insert-webPage",name:x.t("webpage.title"),icon:Uw,group:"common",order:1e3,subText:Ce("insert-webPage")}];function M1(n){return n==="insert-webPage"}async function CS(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function AS(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`//${n}`:n}async function bS(n){if(!n)throw new Error(x.t("webpage.dialog.errorEnterUrl"));const t=n;try{new URL(t)}catch{throw new Error(x.t("webpage.dialog.unsupportedUrl"))}}async function vS(n,t){const e=t.item.id,o=d4().find(a=>a.id===e),r=b("div",["webpage-content"],null);if(M1(e)){const a=b("div",["help-container"],r),d=b("div",["help-content"],a),f=b("span",["help-icon"],d);f.innerHTML=y5,b("span",[],d,x.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:c}=xh(r,{required:!0,label:x.t("webpage.dialog.label"),placeholder:x.t("webpage.dialog.placeholder")});if(!M1(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=w5;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 pS(r,{title:x.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var T;const y=AS(i());try{await bS(y);const E=await CS(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(M1(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 h4=w("embed-block-properties");function la(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 R1{constructor(t,e,o){h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:Eh},{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"){la(t,e)||h4.error("failed to add comment to block");return}h4.error(`unknown command: ${JSON.stringify(o)}`)}}}function O1(n,t,e){return{blockCommands:{"hovering-toolbar":new R1(n,t,e)}}}function yS(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 kS(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function wS(n,t){const e=O1(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:"Refresh page",icon:Nw},{id:"open-page",name:"Open the original page",icon:w5}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return yS(i);case"open-page":return kS(r,i)}return!1}}),o=`[${x.t("webpage.abstract")}]`;return{...e,abstract:o}}const BS=w("webpage-embed");function ES(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:c}=s,a=n.addCustom(`webpage-${l}`,()=>new sS(n,e));u(BS,c,"The src from blockData is invalid "),a.create(n,s,t,i),n.addCustom("webpage-resizer",()=>new fS(n)),e.height&&(i.style.height=`${e.height}px`)}function IS(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 xS(){return{name:"WebPage",insertEmbedCommandItems:d4(),handleInsertEmptyEmbed:vS}}function TS(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const N1={embedType:"webpage",createEmbedContent:ES,getBlockProperties:wS,getOptions:xS,handleUpdateBlock:IS,convertTo:TS},SS={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"}},DS={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":SS,"en-US":DS});const AV="";function LS(n,t,e,o){var f;const r=n.getBlockByIndex(t,e);if(G(n,r)!==o)return!1;const i=vt(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 MS={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"}}},RS={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 f4(n,t,e,o,r){if(r==="enter"&&LS(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=vt(ve(n.getBlockText(i),o).left).trim(),l=r==="enter"?MS:RS;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 OS(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 NS={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function PS(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=NS[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 $S(n,t,e,o){return!!(PS(n,t,e,o)||OS(n,t,e,o))}const _S=w("match-text-style");function FS(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 HS(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 jS={"*":{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 zS(n,t,e,o){var d,f;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=ve(i,o),l=FS(s),c=me(s)-l.length,a=Object.entries(jS);for(const[m,p]of a){const A=HS(l,m);if(A===-1)continue;const k=c+A,y=o,T=m.length,E=vt(Gt(i,k+T,y-k-T*2).middle);if(p.type==="style"){const L={};p.styles.forEach(_=>{L[_]=!0});const R=nr(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){_S.warn(`failed to convert to box, ${L.message}`);continue}return!0}return!1}class ca{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&($S(t,e,o,r)||zS(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(f4(t,r,i,s,"enter"))return!0}else if(Hn(e,"Space")&&f4(t,r,i,s,"space"))return!0}return!1}}const US={"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(US);function Vs(n,t){const e=Ao(n,t);return!!(e.text&&me(e.text)===0&&!t.querySelector(".inputting-insertion"))}function m4(n,t){var o;st(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function aa(n,t,e){var r;if(!Vs(n,t)){m4(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 VS(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 qS(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?x.t("placeholder.list"):x.t("placeholder.mention"):null}function g4(n){switch(it(n)){case"text":return VS(n);case"list":return qS(n);default:return null}}function WS(n){if(Wn(n))return!1;const t=U(z(n));return t?it(t)==="code":!1}function GS(n){return!Wn(n)}function ZS(n,t){var d,f;const e=n.selection.focusedBlock,o=it(e),r=t.contentPlaceholder||x.t("placeholder.default");let i=r;if(o&&Vi(n,o)&&e){if(!n.isBlockWritable(e)||WS(e))return;GS(e)?i=x.t("placeholder.common.contentInTable"):i=(d=g4(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)&&aa(n,l,(f=g4(l))!=null?f:r);return}const a=n.getFocusedBlock();!Vs(n,a)||a!==s&&aa(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 YS(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 JS(n,t){YS(n),n.selection.range.isCollapsed()&&(QS(n,t),ZS(n,t))}const yV="",KS=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;Ge(t.rootContainer)===2&&(c=Sr(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(KS,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)||JS(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const p4=w("code-dom");function Mo(n){return it(n)==="code"}function C4(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?H(t,"wrap"):M(t,"wrap")}function P1(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return u(p4,t,"no parent code block"),u(p4,Mo(t),"not a code block"),t}const ua={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 XS(n){const t=n.toLocaleLowerCase();let e="";return Object.entries(ua).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}function A4(n){const t=n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}function tD(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const eD=w("convert-to-code");function nD(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(eD,r,"no text");let i=vt(r);i.startsWith("```")&&(i=i.substring(3));const s=XS(i)||A4(n)||"plain";return{blockData:{id:P(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const kV="",$1=w("code-block-child-container");function ai(n){u($1,Mo(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($1,e,"no code text container"),e}function ui(n){u($1,Mo(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 da(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=z(t),o=U(e);return o?Mo(o)?e===ai(o):it(t)==="code":!1}const _1=w("code-caption");function oD(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 b4(n,t){const e=z(t);if(Ct(e))return!1;const o=U(e);if(u(_1,o,"no parent block"),!Mo(o))return!1;const i=ui(o);return e===i}function rD(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 iD=w("paste-in-table-block");class sD{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=z(i);if(Ct(s))return!1;const l=U(s);if(u(iD,l,"no parent block"),!Mo(l)||b4(t,i))return!1;const c=o["text/plain"];return c&&t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,c)}),!0}}function lD(n){n.addCustom("code-block-paste-event",t=>new sD(t))}class cD{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 aD(n){n.addCustom("code-block-command-provider",t=>new cD(t))}const uD=w("code-caption-input-handler");function F1(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 b4(n,e)?e:null}function dD(n){const t=F1(n);if(!t)return!1;const e=P1(t),o=dt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",V(z(e)),K(e)+1),!0)}function hD(n){const t=F1(n);if(!t)return!1;if(Tt(n,t)){const e=P1(t);return rD(n,e),!0}return!1}class H1{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?dD(t):e.key==="Backspace"?hD(t):!1}async handleBeforePaste(t,e,o){const r=F1(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(uD,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new H1(e))}}const fD=`
|
|
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>`,mD=`
|