@ones-editor/editor 1.1.7-beta.7 → 1.1.7-beta.9
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
|
@@ -602,7 +602,7 @@ ${t}
|
|
|
602
602
|
`,tP=Object.freeze(Object.defineProperty({__proto__:null,ClearIcon:X2,CloseIcon:zh,PrevIcon:f2,NextIcon:d2,MoreIcon:jp,TextColorIcon:zp,ArrowDownIcon:Gh,ArrowUpIcon:NN,ArrowLeftIcon:PN,ArrowRightIcon:Gp,DeleteRowIcon:h2,DeleteColIcon:m2,MergeCellIcon:g2,SplitCellIcon:p2,DeleteTableIcon:C2,Heading1Icon:Wh,Heading2Icon:qh,Heading3Icon:Xh,Heading4Icon:Yh,Heading5Icon:Qh,Heading6Icon:Jh,Heading7Icon:Zh,Heading8Icon:t0,HeadingNIcon:FN,OrderedListIcon:E2,UnorderedListIcon:A2,CheckListIcon:x2,BlockquoteIcon:b2,AlignCenterIcon:n0,AlignLeftIcon:Na,AlignRightIcon:e0,ImageIcon:v2,ImageMenuIcon:B2,ImageErrorIcon:qp,ImageEmptyIcon:y2,LinkIcon:Jp,LinkOffIcon:k2,WarningIcon:Wp,PasteSpecialIcon:T2,LaunchIcon:Xp,CodeIcon:K2,AudioIcon:O2,GraphIcon:KN,VideoIcon:N2,FileIcon:VN,MathIcon:HN,MathMenuIcon:R2,TableIcon:jN,TableMenuIcon:w2,BilibiliIcon:L2,YoukuIcon:I2,ModaoIcon:_2,FigmaIcon:D2,EditIcon:r0,CommentIcon:ol,RefreshIcon:S2,HelpIcon:Yp,CheckMarkIcon:Qp,TextIcon:Pa,RightArrowIcon:$N,TencentVideoIcon:M2,WebPageIcon:U2,UmlIcon:P2,DividingLineIcon:F2,HeadingH1Icon:zN,HeadingH2Icon:GN,HeadingH3Icon:WN,HeadingH4Icon:qN,HeadingH5Icon:XN,HeadingH6Icon:YN,HeadingH7Icon:QN,HeadingH8Icon:JN,CheckboxIcon:Zp,QuoteIcon:tC,LinkHrefIcon:ZN,OrderedIcon:nC,UnorderedIcon:eC,CopyIcon:V2,CutIcon:$2,DeleteIcon:H2,LockBlockIcon:j2,UnLockBlockIcon:z2,InsertBeforeIcon:G2,InsertAfterIcon:W2,MentionIcon:q2,CircleAddIcon:Y2,LoadingIcon:Q2,DragIcon:rC,UmlBrandIcon:i0,OnesLoadingIcon:J2,BoldIcon:Z2,ItalicIcon:ty,UnderlineIcon:ey,LineThroughIcon:ny,SubscriptIcon:iy,SuperscriptIcon:oy,InlineCodeIcon:ry,ToMindMapIcon:sy,FitIcon:ly,FullScreenIcon:iC,ExitFullScreenIcon:ay,CaretDownIcon:cy},Symbol.toStringTag,{value:"Module"}));function uy(){const n=B("span",["editor-loading-icon"],null);return n.innerHTML=J2,n}const zat="";function eP(n,t){const e=B("button",["editor-checkbox-wrapper"],null);e.setAttribute("data-button-id",n),t!=null&&t.includes("checked")&&z(e,"checked"),t!=null&&t.includes("disabled")&&(e.disabled=!0);const r=B("span",["editor-checkbox"],e);return B("span",["editor-checkbox-inner"],r),e}const Gat="",Fa=I("ui-command-bar-base"),nP={itemElementTag:"div",tippyArrow:!1},BA=class extends Be.TypedEmitter{constructor(e,r,i){var o,s;super();m(this,"content");m(this,"items");m(this,"subBar",null);m(this,"parentItem",null);m(this,"closeable",null);m(this,"closeReason",null);m(this,"options");m(this,"id");m(this,"header",null);m(this,"footer",null);m(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing&&!zs(e.target)){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close("cancelBar");return}if(e.key==="ArrowUp"){const r=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[r].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const r=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[r].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const r=this.getSelectedItem();r&&r.children&&this.showSubCommandBar(r.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const r=this.getSelectedItemIndex();if(r===-1)return;const i=this.items[r],o=this.getItemElementById(i.id);o&&this.emit("click",this,i,o)}}}});m(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const r=this.listeners("closing");for(let i=0;i<r.length;i++)if(r[i](this,e)===!1)return;this.close("clickBackground")}});m(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),Fg(this.id)});m(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&z(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&Pg(this.id)});m(this,"lastEnterPauseTime",0);m(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});m(this,"handleItemMouseEnter",e=>{if(Date.now()-this.lastEnterPauseTime<100)return;const r=this.getParentCommandItemElement(e.target);if(!r)return;const i=this.getItemElementId(r),o=this.getItemById(i);if(this.selectItem(i),o.manualShowChildren)return;const s=o.childrenMenuId||"";this.showSubCommandBar(s)});m(this,"handleItemMouseLeave",e=>{var i,o;const r=this.getParentCommandItemElement(e.target);!r||((o=(i=this.subBar)==null?void 0:i.parentItem)==null?void 0:o.id)!==this.getItemElementId(r)&&(ot(r,"selected"),this.emit("selectionChange",this,""))});m(this,"handleItemClick",e=>{const r=this.getParentCommandItemElement(e.target);if(!r)return;const i=this.getItemElementId(r),o=this.items.find(s=>s.id===i);if(!!o&&!(o.states&&o.states.indexOf("disabled")!==-1)){if(o.children&&o.children.length>0&&o.manualShowChildren){this.showSubCommandBar(o.childrenMenuId);return}o.element||(this.emit("click",this,o,r),this.options.autoClose&&this.close("clickItem"))}});m(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const r=e.target;if(!r||!(r instanceof Node))return;const i=r instanceof HTMLElement?r:r.parentElement;if(!i)return;const o=Ge(i);if(!re(this.content,o)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?o.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&o.scrollTop+o.clientHeight>=o.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(o=i==null?void 0:i.id)!=null?o:tt(),this.options={...nP,...i},this.items=e,this.parentItem=(s=i==null?void 0:i.parentItem)!=null?s:null,this.closeable=r!=null?r:null,this.content=this.createCommandBarContent(e)}close(e){this.closeReason=e,this.subBar&&this.subBar.close(e),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}click(e,r){this.emit("click",this,e,r)}createPopperOptions(){var i,o;const e={modifiers:[]},r=this.options.overflowBoundary;return r&&((i=e==null?void 0:e.modifiers)==null||i.push({name:"flip",options:{boundary:r,fallbackPlacements:["top","bottom"]}})),this.options.padding&&((o=e==null?void 0:e.modifiers)==null||o.push({name:"preventOverflow",options:{padding:this.options.padding}})),e}destroy(){var e;this.close(null),this.removeAllListeners(),(e=this.subBar)==null||e.destroy(),this.subBar=null,this.closeable=null,this.content.removeEventListener("wheel",this.handleWheel)}get isSubCommandBar(){return!!this.parentItem}updateItems(e){var i;this.subBar&&e.findIndex(s=>{var l,c;return s.id===((c=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:c.id)})===-1&&((i=this.subBar)==null||i.destroy(),this.subBar=null),this.items=e;const r=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(r.children).forEach(o=>{this.content.appendChild(o)})}get popper(){return this.content.closest("[data-tippy-root]")}getSelectedItemIndex(){const e=this.getSelectedItem();return e?this.items.indexOf(e):-1}getPrevItemIndex(e){if(e<=0)return this.items.length-1;let r=e-1;for(;;){const i=this.items[r],o=i.type,l=!(i.states&&i.states.indexOf("disabled")!==-1);if(o!=="separator"&&o!=="section"&&l)return r;if(r-=1,r<0)return this.items.length-1}}getNextItemIndex(e){let r=e+1;for(;;){if(!this.items[r])return this.getNextItemIndex(-1);const i=this.items[r],o=i.type,l=!(i.states&&i.states.indexOf("disabled")!==-1);if(o!=="separator"&&o!=="section"&&l)return r;if(r+=1,r>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const r=this.getItemElementById(e.id);r&&ot(r,"selected")}selectItem(e){const r=this.getSelectedItem();if(r){if(r.id===e)return;const o=r.id,s=this.getItemElementById(o);s&&ot(s,"selected")}const i=this.getItemElementById(e);i?(z(i,"selected"),this.emit("selectionChange",this,i.getAttribute("data-id")||""),this.options.disableSelectedScroll||i.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l,c,d;const r=this.getSelectedItem();if(!r||!r.children&&((l=(s=this.subBar)==null?void 0:s.parentItem)==null?void 0:l.manualShowChildren))return;if(this.subBar){if(((c=this.subBar.parentItem)==null?void 0:c.id)===r.id){r.manualShowChildren&&this.subBar.close("switchItem");return}this.subBar.destroy(),this.subBar=null}if(!r.children)return;const i=this.getItemElementById(r.id);if(!i)return;const o=BA.createSubCommandBar(r,(d=this.closeable)!=null?d:this,e?{id:e}:{});this.subBar=o,this.subBar.on("click",(h,C,E)=>{this.emit("click",h,C,E)}),this.subBar.on("close",()=>{var h;(h=this.subBar)==null||h.destroy(),this.subBar=null,ot(i,"active")}),r.beforePopup&&r.beforePopup(o),this.subBar.manualShow(i,this.getSubBarOptions(r)),z(i,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const r=this.getCommandBarRoot();return r&&re(r,e)||re(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var o,s,l,c;let r=(o=this.options.itemElementTag)!=null?o:"div";e.element&&(r="div");const i=B(r,["command-item"],null);return i.setAttribute("data-id",e.id),e.type==="separator"?i.classList.add("separator"):e.type==="section"?(i.classList.add("section","text"),e.element&&(typeof e.element=="function"?i.appendChild(e.element(e)):i.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&i.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&i.classList.add("checked"),(c=e.states)!=null&&c.includes("disabled")&&i.classList.add("disabled"),i.onclick=this.handleItemClick,i.onmouseenter=this.handleItemMouseEnter,i.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?i.appendChild(e.element(e)):i.appendChild(e.element):i.classList.add("standard")),this.initItemElement(e,i),i}getItemById(e){const r=this.items.find(i=>i.id===e);return p(Fa,r,`can not find command item for id: ${e}`),r}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const r=this.getItemElementId(e),i=this.items.find(o=>o.id===r);return p(Fa,i,`can not find command item for id: ${r}`),i}return null}getItemElementId(e){const r=e.getAttribute("data-id");return p(Fa,r,"no data-id attribute"),r}getItemElementById(e){const r=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return p(Fa,r,`no exists command item, id=${e}`),r}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(wt(e,"command-item"))return e;const r=e.closest(".command-item");return r||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const r=B("div",["editor-command-bar-root"],null);if(this.options.header){const o=B("div",["editor-command-bar-header"],null);if(this.options.header instanceof Function){const s=this.options.header();s&&o.appendChild(s)}else o.appendChild(this.options.header);this.header=o,this.header&&r.appendChild(this.header)}const i=B("div",["editor-command-bar"],r);if(e.forEach(o=>{var l;const s=this.createCommandItem(o);i.appendChild(s),o.element&&o.setCloseable&&o.setCloseable((l=this.closeable)!=null?l:this)}),this.options.footer){const o=B("div",["menu-item","editor-command-bar","footer"],null);if(this.options.footer instanceof Function){const s=this.options.footer();s&&o.appendChild(s)}else o.appendChild(this.options.footer);this.footer=o,this.footer&&r.appendChild(this.footer)}return(this.options.header||this.options.footer)&&z(r,"scrollable-bar"),this.initCommandBarElement(i),r.addEventListener("wheel",this.handleWheel,{passive:!1}),r}getSubBarOptions(e){var r;return{placement:(r=e.childrenPlacement)!=null?r:"right-start",offset:e.childrenOffset,arrow:e.childArrow}}static registerManualCommandBar(e,r){this.commandBarCreators.set(e,r)}static createSubCommandBar(e,r,i){var l;p(Fa,e.children&&e.children.length>0,"no item children");const o=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(o);return p(Fa,s,`no creator for command type: ${o}`),s(e,r,i)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let sl=BA;m(sl,"commandBarCreators",new Map),I("ui-command-bar");class o0 extends sl{constructor(){super(...arguments);m(this,"tippyInstance",null)}manualShow(e,r){var i,o,s;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=W6.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(i=r==null?void 0:r.placement)!=null?i:"bottom-start",maxWidth:650,arrow:(o=r==null?void 0:r.arrow)!=null?o:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:r==null?void 0:r.theme,getReferenceClientRect:r==null?void 0:r.getReferenceClientRect,offset:(s=r==null?void 0:r.offset)!=null?s:[0,0],popperOptions:this.createPopperOptions()}),r!=null&&r.point){const{x:l,y:c}=r.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(l,c,0,0)})}this.clearSelectedItem(),this.tippyInstance.show(),this.parentItem||(document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)),this.popper&&this.options.id&&this.popper.setAttribute("data-command-bar-id",this.options.id)}}close(e){var r;super.close(e),this.isVisible&&((r=this.tippyInstance)==null||r.hide())}destroy(){var e;(e=this.tippyInstance)==null||e.destroy(),this.tippyInstance=null,super.destroy()}getCommandBarRoot(){return this.content.closest("[data-tippy-root]")}get isVisible(){var e,r;return(r=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?r:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const fy=I("ui-base");class Nu extends o0{constructor(t,e){var o;const i=[{id:(o=e==null?void 0:e.id)!=null?o:`popup-${tt()}`,name:"",element:t}];super(i,void 0,{disablePageScroll:!0})}initCommandBarElement(t){z(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];p(fy,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return p(fy,e,"no item element"),e}}const oo=I("filterable-list");function dy(n){var e,r;const t=B("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(B("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&(z(t,"selected"),_s(Qp,["list-item-selected-icon"],t)),(r=n.states)!=null&&r.includes("disabled")&&z(t,"disabled"),t}function hy(n){const t=B("div",["list-root"],null);return n.forEach(e=>{t.appendChild(dy(e))}),n.length||t.appendChild(dy({id:"placeholder",states:["disabled"],name:D.t("search.emptyTips")})),t}function my(n,t){return n.map(e=>({...e,states:t===e.id?["selected"]:[]}))}function rP(n,t){const e=B("div",["filterable-list"],null),r=B("div",["filter"],e),i=B("div",["filter-container"],r),o=B("input",["filter-input"],i);t&&t.placeholder&&(o.placeholder=t.placeholder);const s=B("div",["list"],e),l=hy(my(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function gy(n,t,e){const r=n.querySelector(".list");p(oo,r,"no list root");const i=hy(my(t,e)),o=r.querySelector(".list-root");if(p(oo,o,"no exists menu"),Yc(o,i),e){const s=r.querySelector(".list-item.selected");s&&(p(oo,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class iP{constructor(t,e){m(this,"root");m(this,"visibleItems");m(this,"selectedId");m(this,"filter","");m(this,"onSelected",null);m(this,"handleKeydown",t=>{this.processKeyDown(t)});m(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");p(oo,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});m(this,"handleClick",t=>{this.processClick(t)});var r;this.items=t,this.options=e,this.root=rP(t,e),this.bindEvents(),this.selectedId=(r=e==null?void 0:e.initialSelectedId)!=null?r:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");p(oo,t,"no input"),t.addEventListener("keyup",this.handleInputChanged),t.addEventListener("keydown",this.handleKeydown),this.root.addEventListener("click",this.handleClick)}unbindEvents(){const t=this.root.querySelector(".filter-input");p(oo,t,"no input"),t.removeEventListener("keyup",this.handleInputChanged),t.removeEventListener("keydown",this.handleKeydown),this.root.removeEventListener("click",this.handleClick)}destroy(){this.unbindEvents(),this.onSelected=null}getSelectedIndex(){return this.selectedId?this.visibleItems.findIndex(t=>t.id===this.selectedId):-1}setSelectedId(t){this.selectedId=t,gy(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");p(oo,t,"no input"),t.focus()}moveSelectedItemIntoView(){const t=this.root.querySelector(".list-item.selected");t&&(p(oo,t,"no selected menu item"),t.scrollIntoView({block:"nearest"}))}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");p(oo,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),gy(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const r=e.closest(".list-item");if(!r)return;const i=(s=r.getAttribute("data-id"))!=null?s:"",o=(l=this.visibleItems.find(c=>c.id===i))!=null?l:null;this.onSelected&&this.onSelected(this,o)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let r=this.getSelectedIndex();r===-1?r=this.visibleItems.length-1:r>0&&(r-=1);let i="";r!==-1&&(i=this.visibleItems[r].id),this.setSelectedId(i);return}if(t.key==="ArrowDown"){let r=this.getSelectedIndex();r===-1?r=0:r<this.visibleItems.length-1&&(r+=1);let i="";r!==-1&&(i=this.visibleItems[r].id),this.setSelectedId(i);return}if(t.key==="Enter"){const r=(e=this.visibleItems.find(i=>i.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,r)}}}class oP extends iP{constructor(e,r,i){super(e,i);m(this,"popup");m(this,"onShow",null);m(this,"onHide",null);m(this,"custom",null);m(this,"handleShow",()=>{this.onShow&&this.onShow(this)});m(this,"handleHide",()=>{this.onHide&&this.onHide(this)});m(this,"handleShown",()=>{this.focus()});this.popup=new Nu(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus(),this.moveSelectedItemIntoView()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close("cancelBar")}processClick(e){super.processClick(e);const r=e.target;!(r instanceof HTMLElement)||!r.closest(".list-item")||this.popup.close("clickItem")}}const Wat="",qat="";function sP(n,t){const e=document.createElement("div");e.classList.add("toast","show"),t!=null&&t.theme&&e.setAttribute("data-theme",t.theme),t!=null&&t.id&&e.setAttribute("data-id",t.id),t!=null&&t.html?e.innerHTML=n:e.textContent=n,t!=null&&t.position&&(e.style.left=`${t.position.x}px`,e.style.top=`${t.position.y}px`,e.classList.add("positioned")),document.body.appendChild(e),setTimeout(()=>{e.classList.remove("show"),setTimeout(()=>{e.remove()},500)},(t==null?void 0:t.duration)||3e3)}function lP(n,t){var e,r;if(z(t,"menu-item"),!n.element){if(n.type==="section"){const i=B("div",["section-name"],null,n.name);t.appendChild(i)}else if(n.type!=="separator"){if(n.icon){const o=B("div",["menu-item-icon"],null);n.icon&&(o.innerHTML=n.icon),t.appendChild(o)}const i=B("div",["menu-item-name","text"],null);if(B("span",[],i,n.name),n.ellipsisTooltip&&(t.setAttribute("data-editor-tooltip-allow-markdown","true"),t.setAttribute("data-editor-tooltip-offset-y","25"),t.setAttribute("data-editor-tooltip-placement","right"),t.setAttribute("data-editor-tooltip-common",`<div style="word-break: break-word;">${n.ellipsisTooltip}</div>`)),((e=n.states)==null?void 0:e.includes("disabled"))&&n.disableReason&&(t.setAttribute("data-editor-tooltip-maxwidth","800"),t.setAttribute("data-editor-tooltip-placement","right"),t.setAttribute("data-editor-tooltip-common",n.disableReason)),t.appendChild(i),n.subText&&B("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const o=B("div",["menu-item-sub-indicator"],null);o.innerHTML=Gp,t.appendChild(o)}if((r=n.states)!=null&&r.includes("checked")){const o=B("div",["menu-item-checked-icon"],null);o.innerHTML=Qp,t.appendChild(o)}}}}class Qo extends o0{constructor(t,e,r){super(t,e,{autoClose:!0,disablePageScroll:!0,...r})}manualShow(t,e){const r={theme:"menu",...e};super.manualShow(t,r)}initCommandBarElement(t){z(t,"menu")}initItemElement(t,e){lP(t,e)}}function aP(n,t,e){var r;return new Qo((r=n.children)!=null?r:[],t,{...e,parentItem:n})}function py(n,t,e){t.setAttribute("data-button-id",n.id),e.tooltipId&&n.name&&!n.disableTooltip&&(t.setAttribute(`data-editor-tooltip-${e.tooltipId}`,n.name),n.desc&&t.setAttribute(`data-editor-tooltip-desc-${e.tooltipId}`,n.desc));const r=t;if(!n.element)if(n.icon){const i=B("span",["toolbar-item-icon-container"],r);n.icon.trim().startsWith("<")?i.innerHTML=n.icon:i.innerText=n.icon}else{const i=B("span",["toolbar-item-name-container"],r);i.innerText=n.name}if(n.dropdown){t.setAttribute("data-dropdown","true");const i=B("span",["toolbar-item-dropdown-container"],r);i.innerHTML=Gh}n.states&&(n.states.indexOf("checked")!==-1&&z(r,"checked"),n.states.indexOf("disabled")!==-1&&(r.disabled=!0))}class Pu extends o0{constructor(t,e,r){super(t,e,{itemElementTag:"button",tippyArrow:!1,...r})}getSubBarOptions(t){var i,o;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),d=s.getBoundingClientRect();return new DOMRect(d.left,c.top,d.width,c.height)};return{placement:(i=t.childrenPlacement)!=null?i:"top",getReferenceClientRect:e,offset:(o=t.childrenOffset)!=null?o:[0,4]}}manualShow(t,e){const r={theme:"toolbar",...e};super.manualShow(t,r)}initCommandBarElement(t){z(t,"toolbar")}initItemElement(t,e){py(t,e,this.options)}}function cP(n,t,e){var r;return new Pu((r=n.children)!=null?r:[],t,{...e,parentItem:n})}class uP extends sl{constructor(t,e,r){super(e,void 0,r),t.appendChild(this.content),document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)}initCommandBarElement(t){z(t,"toolbar","fixed")}initItemElement(t,e){py(t,e,this.options)}close(){this.clearSelectedItem(),this.subBar&&(this.subBar.close("cancelBar"),this.subBar=null)}destroy(){this.content.remove(),super.destroy(),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}getCommandBarRoot(){return this.content.parentElement}get isVisible(){return!0}}const Xat="";sl.registerManualCommandBar("menu",aP),sl.registerManualCommandBar("toolbar",cP);const Yat="",Cy=I("ui-base");class Fu extends o0{constructor(e,r){super(Fu.getCommandItems(e,r),void 0,{disablePageScroll:!0,...r});m(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){z(e,"dialog","manual")}initItemElement(e,r){}show(e,r){this.manualShow(e,{...r,theme:"light"})}get dialogContent(){const e=this.items[0];p(Cy,e,"no dialog item");const r=e.element;return p(Cy,r,"no item element"),r}static getCommandItems(e,r){var s;return[{id:(s=r==null?void 0:r.id)!=null?s:`manual-dialog-${tt()}`,name:"",element:e}]}}const Qat="",fP=I("ui-base");class Ey{constructor(t){m(this,"menu");m(this,"currentText","");m(this,"handleSearchText");m(this,"handleClick",Me.default((t,e)=>{this.options.onClickItem(this,e)},300,{leading:!0,trailing:!1}));m(this,"handleShow",t=>{});m(this,"handleClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.options=t,this.menu=new Qo([],void 0,{id:t.id,header:t.header,footer:t.footer,disableSelectedScroll:t.disableSelectedScroll}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose),this.menu.addListener("show",this.handleShow),this.options.wait?this.handleSearchText=Me.default(async e=>{this.handleSearchTextPure(e)},this.options.wait):this.handleSearchText=this.handleSearchTextPure}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(r=>r.type!=="section"&&r.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e){var i,o;if(!(e!=null&&e.noEvent)&&((o=(i=this.options).onShow)==null?void 0:o.call(i,this))===!1)return;this.menu.manualShow(t),this.options.placeholder&&this.showPlaceholder();const r=await this.options.queryItems(this,"");this.highlightText("",r),this.setItems(r)}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:this.options.emptyPlaceholder||D.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close("cancelBar")}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close("cancelBar"),this.menu.removeAllListeners(),this.menu.destroy()}isInCommandBar(t){return this.menu.isInCommandBar(t)}async handleSearchTextPure(t){this.currentText=t;const e="auto-suggest";try{await wr.lock(e),this.showLoading();const r=this.currentText,i=await this.options.queryItems(this,t);if(this.currentText===r&&(this.currentText=""),i.length===0){this.showNoResultMessage(t);return}this.setItems(i),this.options.highlight&&this.highlightText(r.replace(/^\s+|\s+$/g,""),i)}finally{wr.release(e)}}highlightText(t,e){fP.debug(`highlight menu text: ${t}`);const r=this.menu.content,i=(s,l)=>{if(!l)return s;let c="";const d=l.length,h=l.toLocaleLowerCase();let C=0;for(C=0;C<=s.length-d;C){let E=s.substring(C,C+d);if(E.toLocaleLowerCase()===h){C+=d;const x=s.charAt(C);let v=!1;E.endsWith(" ")&&(v=!0,E=E.trimEnd()),c+=`<span class="highlight">${E}${x===" "||v?" ":""}</span>`}else c+=s.charAt(C),C++}return C<s.length&&(c+=s.substring(C)),c},o=s=>{if(wt(s,"text")){const l=e==null?void 0:e.find(h=>h.id===s.getAttribute("data-id"));if(l&&l.element)return;const c=s.textContent;if(!c)return;const d=i(c,t);s.innerHTML=d;return}Array.from(s.children).forEach(o)};o(r)}}class oC{constructor(t,e){m(this,"root");m(this,"input");m(this,"text");m(this,"dropdownIcon");m(this,"clearIcon");m(this,"autoSuggest");m(this,"labels");m(this,"items",[]);m(this,"handleClick",()=>{this.autoSuggest.popup(this.root),this.input.focus()});m(this,"handleClickItem",(t,e)=>{var r,i;(i=(r=this.options)==null?void 0:r.onClickItem)==null||i.call(r,e)});m(this,"handleInput",()=>{this.autoSuggest.handleSearchText(this.input.value),this.updatePlaceholder()});m(this,"handleClear",t=>{var e,r;this.clear(),this.autoSuggest.handleSearchText(""),t.preventDefault(),t.stopPropagation(),(r=(e=this.options)==null?void 0:e.onClear)==null||r.call(e)});m(this,"handleQueryItems",async(t,e)=>this.items.filter(i=>{var o;return(o=this.options)!=null&&o.filter?this.options.filter(i,e):!0}));m(this,"handleShow",()=>{z(this.root,"active"),this.input.focus()});m(this,"handleClose",()=>{var t,e;(e=(t=this.options)==null?void 0:t.onClose)==null||e.call(t),ot(this.root,"active")});var c,d,h,C,E;this.options=e,this.labels=(d=(c=this.options)==null?void 0:c.labels)!=null?d:[];const{root:r,input:i,text:o,clearIcon:s,dropdownIcon:l}=oC.createDropdown(t,this.labels);this.root=r,this.input=i,this.text=o,this.clearIcon=s,this.dropdownIcon=l,this.autoSuggest=new Ey({id:(e==null?void 0:e.popupId)||"dropdown-auto-suggest",header:(h=this.options)==null?void 0:h.header,onClickItem:this.handleClickItem,queryItems:this.handleQueryItems,onClose:this.handleClose,onShow:this.handleShow,highlight:e==null?void 0:e.highlight,emptyPlaceholder:e==null?void 0:e.emptyPlaceholder,disableSelectedScroll:e==null?void 0:e.disableSelectedScroll}),this.items=(E=(C=this.options)==null?void 0:C.items)!=null?E:[],this.root.addEventListener("click",this.handleClick),this.input.addEventListener("input",this.handleInput),this.clearIcon.addEventListener("click",this.handleClear)}close(){this.autoSuggest.close()}destroy(){this.input.removeEventListener("input",this.handleInput),this.root.removeEventListener("click",this.handleClick),this.clearIcon.removeEventListener("click",this.handleClear),this.autoSuggest.destroy()}updateItems(t){this.items=t,this.autoSuggest.handleSearchText("")}setText(t){this.text.innerText=t,this.input.value=t,this.updatePlaceholder()}clear(){this.setText(""),this.setLabels([])}setLabels(t){this.labels=t,this.updateLabels()}static createDropdown(t,e){const r=B("div",["editor-dropdown","empty"],t),i=B("input",["dropdown-input"],r),o=B("div",["dropdown-text"],r),s=B("div",["dropdown-labels"],r);for(let d=0;d<e.length;d+=1){const h=e[d];B("span",["dropdown-label"],s,h)}const l=B("div",["dropdown-clear-icon"],r);l.innerHTML=X2;const c=B("div",["dropdown-icon"],r);return c.innerHTML=Gh,{root:r,input:i,text:o,clearIcon:l,dropdownIcon:c}}updateLabels(){const t=this.root.querySelector(".dropdown-labels");if(t){t.innerHTML="";for(let e=0;e<this.labels.length;e+=1){const r=this.labels[e];B("span",["dropdown-label"],t,r)}}}updatePlaceholder(){var t;if(this.input.value===""){const e=(t=this.options)==null?void 0:t.placeholder;e&&(this.input.placeholder=e,this.text.textContent=e),z(this.root,"empty")}else ot(this.root,"empty")}}const dP=[-1,6,0,1,2,3,4,5],hP=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],Ay=I("color-palette");function xy(n,t,e,r){p(Ay,n>0,"no color in palette");const i=t||1;p(Ay,i>0,`invalid palette rows: ${i}`);const o=n/i,s=B("div",["palette-container",r],null);for(let l=0;l<i;l++){const c=B("div",["palette-container-row"],s);for(let d=0;d<o;d++){const h=e(l*o+d);c.appendChild(h)}}return s}function mP(n){const t=B("button",["color-button"],null),e=dP[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=zp,t}function gP(n){const t=B("button",["background-color-button"],null),e=hP[n];return t.setAttribute("data-color-index",`${e}`),t}function pP(){const n=B("div",["clear-button-container"],null),t=B("button",["clear-button"],n);return t.innerText=D.t("colorPalette.reset"),n}function CP(n){const t=B("div",["color-palette"],null);return n.color!==!1&&(B("div",["bar-desc"],t,D.t("colorPalette.colorDesc")),t.appendChild(xy(8,1,mP,"color"))),n.backgroundColor!==!1&&(B("div",["bar-desc"],t,D.t("colorPalette.backgroundDesc")),t.appendChild(xy(16,2,gP,"background-color"))),n.clearColorButton!==!1&&t.appendChild(pP()),t}function EP(n,t,e){const r=t==="color"?"color":"background-color",i=n.querySelector(`.${r} button.selected`);i&&ot(i,"selected"),e===null&&(e=-1);const o=n.querySelector(`.${r} button[data-color-index="${e}"]`);o&&z(o,"selected")}const Jat="",AP={};class xP extends Be.TypedEmitter{constructor(e=AP){super();m(this,"root");m(this,"handleClick",e=>{const r=e.target;if(!r||!(r instanceof Element))return;const i=r.closest("button");if(!i)return;if(wt(i,"clear-button")){this.setColor("backgroundColor",null),this.setColor("color",null),this.emit("onClick","clearColor",0);return}const o=i.getAttribute("data-color-index");if(!o)return;const s=Number.parseInt(o,10);Number.isNaN(s)||(wt(i,"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=CP(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,r){EP(this.root,e,r)}}class by{constructor(t,e){m(this,"name","Color Palette");m(this,"element");m(this,"palette");m(this,"closeable",null);this.id=t,this.palette=new xP(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function bP(){const n=B("button",["color-button"],null);return n.innerHTML=zp,n}function sC(n,t){const[e,r]=t;e===null?n.removeAttribute("data-color"):n.setAttribute("data-color",`${e}`),r===null?n.removeAttribute("data-background-color"):n.setAttribute("data-background-color",`${r}`)}class vy extends Be.TypedEmitter{constructor(e){super();m(this,"id","text-color-item");m(this,"name",D.t("colorPalette.name"));m(this,"dropdown",!0);m(this,"manualShowChildren",!0);m(this,"children",[]);m(this,"element");m(this,"colorPaletteItem");m(this,"latestColors",[null,null]);m(this,"handlePaletteClick",(e,r)=>{this.emit("onClick",e,r)});m(this,"setLatestColors",(e,r)=>{e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=r:this.latestColors[1]=r:this.latestColors=[null,null],sC(this.element,this.latestColors)});m(this,"beforePopup",()=>{this.updatePaletteColor(this.latestColors),this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new by("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=bP()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,sC(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,sC(this.element,this.latestColors)}}const Zat="";function lC(n,t){const e=B("div",["editor-input-wrap"],n);t!=null&&t.className&&z(e,t==null?void 0:t.className);const r=B("div",["editor-input-label"],e);B("span",[],r,t.label),t.required&&z(r,"required");const i=B("div",["editor-input-container"],e),o=B("input",["editor-input"],i);t.placeholder&&(o.placeholder=t.placeholder),t.defaultValue&&(o.value=t.defaultValue);const s=B("div",["editor-input-error"],e);return o.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),ot(e,"error")}),o.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>o,getInputValue:()=>o.value,setFieldError:l=>{z(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{o.focus()})}}}function aC(n){const t=document.getSelection();if(!t)return!0;const e=t.focusNode;if(!e)return!0;const r=t.focusOffset,i=e.childNodes[r];if(!i)return!0;if(i instanceof HTMLElement){const o=i.tagName.toLowerCase();if(i===n.input.inputElement)return!0;if(o==="input"||o==="textarea")return!1}return!0}class vP extends Ey{constructor(e,r){super(r);m(this,"handleClose",()=>{var e,r;aC(this.editor)&&this.editor.focus(),(r=(e=this.options).onClose)==null||r.call(e)});this.editor=e,this.editorOptions=r}async popupInEditor(e,r,i){var d,h;if(((h=(d=this.editorOptions).onShow)==null?void 0:h.call(d,this,e,r,i))===!1)return;this.options.showLoading&&this.showLoading();const o=this.editor.getBlockByIndex(e,r);if(!re(this.editor.rootContainer,o)||dt(this.editor,o)<i)return;const s=ji(this.editor,o,ye(this.editor,o,i));if(s.length===0)return;const l=s[0],c=Wi(this.editor,o,"editor-auto-suggest-menu",l);super.popup(c,{noEvent:!0})}}const cC=I("auto-suggest-menu");class uC{constructor(t,e){m(this,"order",100);m(this,"menu");m(this,"anchor",null);m(this,"close",()=>{this.menu.close()});m(this,"handleSelectionChanged",t=>{var r,i;if(!((r=this.menu)!=null&&r.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((i=this.anchor)==null?void 0:i.blockId)&&e.offset>=this.anchor.offset){const o=t.getBlockById(e.blockId);if(fe(Dn(Bn(t,o),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});m(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:r,offset:i}=e,o=t.getBlockById(r),s=fe(mh(t,o,i));if(p(cC,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,c=i-l;return t.selection.selectBlock(o,l),c&&(t.deleteTextFromBlock(o,l,c),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});m(this,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"onShow",(t,e,r,i)=>{var o;if((o=this.options)!=null&&o.onShow)return this.options.onShow(this,e,r,i)});m(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});m(this,"queryItems",(t,e)=>this.options.queryItems(this,e));m(this,"renderMenuItem",(t,e)=>{var i,o;return(o=(i=this.options).renderMenuItem)==null?void 0:o.call(i,this,e)});m(this,"hasExistsMenuThemeCommandBar",()=>!!document.querySelector('div.tippy-box[data-theme="menu"]'));this.editor=t,this.options=e,this.menu=new vP(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,header:e.header,footer:e.footer,wait:e.wait,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 r;return!((r=this.menu)!=null&&r.isVisible)||_g(e.key)?!1:Jb(e)&&!Ns(e)?(setTimeout(()=>{this.resetItems()}),!1):Mg(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,r,i){this.anchor={blockId:lt(t),offset:e,leftText:r,trigger:i};const o=ut(it(t)),s=Bt(t);this.menu.popupInEditor(o,s,e)}handleAfterInsertText(t,e,r,i,o){var h,C;const s=t.selection.range.start;if(!s.isSimple())return!1;const l=t.getBlockByIndex(e,r);if($i(l))return!1;const{blockId:c,offset:d}=s;if(lt(l)!==c)return!1;if((h=this.menu)!=null&&h.isVisible)this.resetItems();else if(this.options.trigger.indexOf(o)!==-1){if(i>0&&this.options.needSpaceBeforeTrigger&&(((C=t.getBlockData(l).text)==null?void 0:C.reduce((R,L)=>R+L.insert,""))||"")[i-1].trim().length!==0||this.hasExistsMenuThemeCommandBar())return!1;const E=fe(mh(t,l,d));this.popup(l,d,E,o)}return!1}handleUpdateCompositionText(t,e,r,i,o){var d;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,r);return lt(c)!==l||(d=this.menu)!=null&&d.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:r,offset:i}=e,o=t.getBlockById(r),s=fe(mh(t,o,i));if(p(cC,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);cC.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 BP(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const TP={"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"},...BP()};function Tn(n){var t;return(t=TP[n])==null?void 0:t.shortcut}function yP(n){var t;return(t=n.subText)!=null?t:""}const Ei=I("table-dom");function Ai(n){return`${lt(n)}_scroll`}function Ve(n){const t=n.querySelector("div[data-type=table-content] >table");return p(Ei,t instanceof HTMLTableElement,"invalid table"),t}function xi(n,t){const r=n.getCustom(Ai(t)).contentElement.firstElementChild;p(Ei,r instanceof HTMLElement,"invalid table content");let i=r.querySelector(":scope >div[data-type=table-tools]");return i||(i=B("div",[],r),i.setAttribute("data-type","table-tools"),n.domEvents.addEventListener(i,"dblclick",(o,s)=>s.stopPropagation()),n.domEvents.addEventListener(i,"click",(o,s)=>{s.detail===3&&s.stopPropagation()})),p(Ei,i,"no table tools"),i}function kP(n,t){return n.findCustom(Ai(t))?xi(n,t):null}function By(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function Ku(n){const t=n.querySelector(":scope div[data-type=editor-container]");return p(Ei,t,"no child container in cell"),t}function RP(n){const r=By(n).map(i=>{const o=Ku(i),s=ut(o),l=i.colSpan,c=i.rowSpan;return`${s}/${l}/${c}`}).join();return kd.default(r)}function $e(n){return Dt(n)==="table"}function fC(n){const t=it(n);if(Xt(t))return null;const e=J(t);return p(Ei,e,"no parent block"),$e(e)?t:fC(e)}function so(n){if($e(n))return n;const t=it(n);if(Xt(t))return null;const e=J(t);return p(Ei,e,"no parent block"),$e(e)?e:so(e)}function wP(n,t){const e=n.querySelector("colgroup");p(Ei,e,"no colgroup");const r=e.children[t];return p(Ei,r,"no col"),p(Ei,r instanceof HTMLTableColElement,`invalid col: ${r.tagName}`),r}function Ty(n){try{return Ve(n),!0}catch{return!1}}function SP(n){return ie(n).querySelector(":scope > .block-helper")}function yy(n){const t=J(n.contentElement);p(Ei,t,"no block");const e=SP(t);if(e){const o=Math.min(n.contentElement.offsetLeft+29,n.rootElement.scrollLeft),s=t.getBoundingClientRect().width;e.style.right=`${o+s+5}px`}}const Hr=I("doc-table-grid");class LP{constructor(t){m(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){p(Hr,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){p(Hr,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return p(Hr,e,"get cell, no cell"),e}getCellAllowEmpty(t){return p(Hr,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 s0{constructor(t){m(this,"_data");m(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new LP(this.colCount));this.fillGrid()}get rowCount(){return this._data.rows}get colCount(){return this._data.cols}getNextEmptyCell(t,e){let r=t,i=e;for(;;){if(r+=1,r===this.colCount&&(r=0,i+=1),i>=this.rowCount)return null;if(this._rows[i].getCellAllowEmpty(r)===void 0)return{col:r,row:i}}}fillGrid(){const t=this._data.children;p(Hr,t,"no children");let e=0,r=0;t.forEach((i,o)=>{const s=this._data[`${i}_colSpan`]||1,l=this._data[`${i}_rowSpan`]||1;for(let d=0;d<l;d++)for(let h=0;h<s;h++)this._rows[r+d].setCell(e+h,{col:e,row:r,containerId:i,virtual:h!==0||d!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,r);c?(e=c.col,r=c.row):p(Hr,o===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(i=>{i.forEach(o=>{p(Hr,o,"no cell"),p(Hr,o.containerId,"no containerId")})})}getCell(t){const{col:e,row:r}=t,i=this._rows[r];p(Hr,i,`get cell, no row: ${r}`);const o=i.getCell(e);return p(Hr,o,`get cell, no cell: ${e}`),o}getRow(t){const e=this._rows[t];return p(Hr,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const l0=I("table-data");function IP(n){const t=n.firstElementChild;return p(l0,t,"no child element for cell"),p(l0,Hi(t),"cell first child is not a container"),p(l0,_r(t),"cell first child is not a container"),t}function DP(n){const t=J(n);p(l0,t,"no parent block for table");const e=[],r={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const d=IP(c),h=ut(d);e.push(h),(c.colSpan>1||c.rowSpan>1)&&(r[`${h}_colSpan`]=c.colSpan,r[`${h}_rowSpan`]=c.rowSpan)})});const i=n.rows.length,o=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,c)=>l+c,0);return{id:lt(t),type:Dt(t),rows:i,cols:o,children:e,colsWidth:Array(o).fill(100),...r}}function ll(n){return new s0(n)}function _P(n){return ll(DP(n))}const Qe=I("table-grid"),MP=60;class UP{constructor(t,e){m(this,"containerId");m(this,"row");m(this,"col");m(this,"colSpan");m(this,"rowSpan");m(this,"virtual");m(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 p(Qe,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);p(Qe,t.length===1,"containers !== 1"),p(Qe,Hi(t[0]),"not a container");const e=t[0];return p(Qe,_r(e),"not a child container"),e}}class OP{constructor(t,e){m(this,"_cells",[]);e.forEach(r=>{this._cells.push(new UP(t,r))})}get cells(){return this._cells}getCell(t){return p(Qe,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 TA=class{constructor(t){m(this,"_rows",[]);this.table=t,_P(t).forEach(i=>{this._rows.push(new OP(t,i))});const r=this.colCount;this._rows.forEach(i=>{p(Qe,i.cells.length===r,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(p(Qe,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 p(Qe,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){p(Qe,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,r=[];for(let i=0;i<e;i++){const o=this.getCell({row:i,col:t});r.push(o)}return r}toRealCells(t){const e=[];return t.forEach(r=>{const i=this.getRealCell(r);e.findIndex(o=>o.containerId===i.containerId)===-1&&e.push(i)}),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){p(Qe,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});if(i.virtual||i.colSpan>1||i.rowSpan>1)return i}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const r=this.getCellById(e.containerId);return p(Qe,!r.virtual,"found a virtual cell"),r}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let r=1e5,i=-1;return e.forEach(o=>{r=Math.min(o.col,r),i=Math.max(o.col+o.colSpan-1,i)}),p(Qe,r<=i,"min > max"),p(Qe,r>=0,"min < 0"),p(Qe,i<this.colCount,"max >= colCount"),[r,i]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let r=1e5,i=-1;return e.forEach(o=>{r=Math.min(o.row,r),i=Math.max(o.row+o.rowSpan-1,i)}),p(Qe,r<=i,"min > max"),p(Qe,r>=0,"min < 0"),p(Qe,i<this.rowCount,"max >= rowCount"),[r,i]}getSpannedRange(t,e){const r=Math.min(t.row,e.row),i=Math.max(t.row,e.row),o=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let x=r;x<=i;x++)for(let v=o;v<=s;v++)l.push(this.getCell({row:x,col:v}));const c=this.toRealCells(l);let d=1e4,h=1e4,C=-1,E=-1;return c.forEach(x=>{h=Math.min(x.col,h),d=Math.min(x.row,d),E=Math.max(x.col+x.colSpan-1,E),C=Math.max(x.row+x.rowSpan-1,C)}),[{row:d,col:h},{row:C,col:E}]}getAllCells(){return this.getCells({col:0,row:0},{col:this.colCount-1,row:this.rowCount-1})}sub(t,e){const r=[];for(let i=t.row;i<=e.row;i++){const o=[];for(let s=t.col;s<=e.col;s++){const l=this.getCell({row:i,col:s});o.push(l)}r.push(o)}return r}getAllContainers(){return this.getAllCells().map(e=>e.container)}getCells(t,e){const r=[],i=this.getSpannedRange(t,e),o=i[0],s=i[1],l=Math.min(o.row,s.row),c=Math.max(o.row,s.row),d=Math.min(o.col,s.col),h=Math.max(o.col,s.col);for(let C=l;C<=c;C++)for(let E=d;E<=h;E++){const x=this.getCell({row:C,col:E});x.virtual||r.push(x)}return r}map(t){const e=[];for(let r=0;r<this.rowCount;r++){const i=[];for(let o=0;o<this.colCount;o++){const s=this.getCell({row:r,col:o});i.push(t(s))}e.push(i)}return e}getBottomCell(t){const e=this.rowCount;let r=t,i=t.row;for(;r.containerId===t.containerId;){if(i+=1,i>=e)return null;r=this.getCell({row:i,col:t.col})}return this.getRealCell(r)}getTopCell(t){let e=t,r=t.row;for(;e.containerId===t.containerId;){if(r-=1,r<0)return null;e=this.getCell({row:r,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,r=[];return e.forEach(i=>{i.forEach(o=>{r.indexOf(o)===-1&&r.push(o)})}),r}getCellById(t){const r=this.cells.find(i=>i.containerId===t);return p(Qe,r,"cell not found"),r}getCellByCellElement(t){const e=Ku(t);return this.getCellByContainerId(ut(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=RP(t),r=this.caches.getSync(e,()=>(Qe.debug("create table grid"),new TA(t)));return r.table!==t?(this.caches.delete(e),this.fromTable(t)):r}static fromBlock(t){return this.fromTable(Ve(t))}};let It=TA;m(It,"caches",new _b(MP));function a0(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const NP=I("table-selection-range");function jr(n,t,e){var U,F,G,W;const r=It.fromBlock(n),i=t,o=e,s=r.getCellByContainerId(i.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=i.custom,d=o.custom,h=(U=c==null?void 0:c.rowIndex)!=null?U:s.row,C=(F=c==null?void 0:c.colIndex)!=null?F:s.col,E=(G=d==null?void 0:d.rowIndex)!=null?G:l.row+l.rowSpan-1,x=(W=d==null?void 0:d.colIndex)!=null?W:l.col+l.colSpan-1,v=Math.min(h,E),R=Math.max(h,E),L=Math.min(C,x),M=Math.max(C,x);return{fromRow:v,toRow:R,fromCol:L,toCol:M}}function dC(n,t){const e=new Set,r=new Set,i=n.selection.range;if(!i.isSimple()&&i.start.blockId===lt(t)){const o=It.fromBlock(t),{start:s,end:l}=i;p(NP,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:d,fromRow:h,toRow:C}=jr(t,s,l);if(h===0&&C===o.rowCount-1)for(let E=c;E<=d;E++)r.add(E);if(c===0&&d===o.colCount-1)for(let E=h;E<=C;E++)e.add(E)}return{selectedRows:e,selectedColumns:r}}function Vu(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const r=n.getBlockById(t.start.blockId);if($e(r)){const i=it(r),o=J(i);o&&(e=so(o))}else e=so(r)}else{const r=n.getBlockById(t.start.blockId),i=so(r),o=n.getBlockById(t.end.blockId),s=so(o);i===s&&(e=i)}return e}const Ka=I("delete-columns");function ky(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||Dt(t)!=="table")return!1;const{fromRow:s,toRow:l}=jr(t,e.start,e.end),c=It.fromBlock(t);return s===0&&l===c.rowCount-1}function hC(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var F,G;const e=t.getBlockById(n.start.blockId);if(!ky(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:r,toCol:i}=jr(e,n.start,n.end),o=It.fromBlock(e);if(r===0&&i===o.colCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(W=>W.containerId);for(let W=0;W<l.length;W++){const rt=l[W];for(let st=r;st<=i;st++){const Et=rt[st];s.add(Et)}rt.splice(r,i-r+1)}const c=new Set(l.flat()),d=new Set(Array.from(s).filter(W=>!c.has(W))),h=i-r+1,C=new Map,E=new Map;s.forEach(W=>{if(d.has(W))return;const rt=o.getCellByContainerId(W);if(p(Ka,rt.colSpan>1,"invalid effected cell, colSpan === 1"),rt.col<r){p(Ka,c.has(W),"invalid effected cell, not exists");let Yt=rt.col+rt.colSpan-1;Yt>i&&(Yt=i);const an=Yt-r+1,be=rt.colSpan-an;C.set(W,be);return}p(Ka,rt.col<=i,"invalid effected cell, col > endCol");const st=rt.col,Et=rt.col+rt.colSpan-1,vt=rt.col-r,xt=Et-st+1-h+vt;p(Ka,xt>0,"invalid effected cell, newSpanned <= 0");const Gt=Ji(t.doc);E.set(W,{newContainerId:Gt,colSpan:xt})});for(let W=0;W<l.length;W++){const rt=l[W];for(let st=r;st<rt.length;st++){const Et=rt[st],vt=E.get(Et);vt&&(rt[st]=vt.newContainerId)}}const x=mt.default(t.getBlockData(e));((F=x.colsWidth)!=null?F:new Array(x.cols).fill(0)).splice(r,i-r+1),d.forEach(W=>{a0(x,W)}),C.forEach((W,rt)=>{p(Ka,W>=1,"invalid modified colSpan, colSpan < 1"),W===1?x[`${rt}_colSpan`]=void 0:x[`${rt}_colSpan`]=W}),E.forEach((W,rt)=>{a0(x,rt);const{newContainerId:st,colSpan:Et}=W;p(Ka,Et>=1,"invalid newContainerData, colSpan < 1"),Et>1&&(x[`${st}_colSpan`]=Et);const vt=o.getCellByContainerId(rt).rowSpan;vt>1&&(x[`${st}_rowSpan`]=vt)});const R=(G=l[0][r])!=null?G:l[0][r-1],L=t.getChildContainerData(R)[0],M=It.virtualCellContainersGridToChildren(l),U={...x,cols:x.cols-h,children:M};ll(U),t.updateBlockData(e,U,ye(t,L.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const Va=I("delete-rows");function Ry(n,t,e){const{start:r,end:i}=e;if(r.blockId!==i.blockId||e.isSimple()||n.getBlockById(r.blockId)!==t||Dt(t)!=="table")return!1;const{fromCol:s,toCol:l}=jr(t,e.start,e.end),c=It.fromBlock(t);return s===0&&l===c.colCount-1}function mC(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!Ry(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:r,toRow:i}=jr(e,n.start,n.end),o=It.fromBlock(e);if(r===0&&i===o.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=o.map(U=>U.containerId);for(let U=i;U>=r;U--)l[U].forEach(G=>s.add(G)),l.splice(U,1);const c=new Set(l.flat()),d=new Set(Array.from(s).filter(U=>!c.has(U))),h=i-r+1,C=new Map,E=new Map;s.forEach(U=>{if(d.has(U))return;const F=o.getCellByContainerId(U);if(p(Va,F.rowSpan>1,"invalid effected cell, rowSpan === 1"),F.row<r){p(Va,c.has(U),"invalid effected cell, not exists");let vt=F.row+F.rowSpan-1;vt>i&&(vt=i);const xt=vt-r+1,Gt=F.rowSpan-xt;C.set(U,Gt);return}p(Va,F.row<=i,"invalid effected cell, col > endCol");const G=F.row,W=F.row+F.rowSpan-1,rt=F.row-r,st=W-G+1-h+rt;p(Va,st>0,"invalid effected cell, newSpanned <= 0");const Et=Ji(t.doc);E.set(U,{newContainerId:Et,rowSpan:st})});for(let U=r;U<l.length;U++){const F=l[U];for(let G=0;G<F.length;G++){const W=F[G],rt=E.get(W);rt&&(F[G]=rt.newContainerId)}}const x=mt.default(t.getBlockData(e));d.forEach(U=>{a0(x,U)}),C.forEach((U,F)=>{p(Va,U>=1,"invalid modified rowSpan, rowSpan < 1"),U===1?x[`${F}_rowSpan`]=void 0:x[`${F}_rowSpan`]=U}),E.forEach((U,F)=>{a0(x,F);const{newContainerId:G,rowSpan:W}=U;p(Va,W>=1,"invalid newContainerData, rowSpan < 1"),W>1&&(x[`${G}_rowSpan`]=W);const rt=o.getCellByContainerId(F).colSpan;rt>1&&(x[`${G}_colSpan`]=rt)});const v=l[r]?l[r][0]:l[r-1][0],R=t.getChildContainerData(v)[0],L=It.virtualCellContainersGridToChildren(l),M={...x,rows:x.rows-h,children:L};ll(M),t.updateBlockData(e,M,ye(t,R.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(E.keys()))})}const $u=I("table-range");function c0(n){p($u,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;p($u,!t.isSimple(),"invalid start pos type"),p($u,!e.isSimple(),"invalid end pos type");const r=n.getEditor();p($u,t.blockId===e.blockId,"invalid range, not same block");const i=r.getBlockById(t.blockId);p($u,Dt(i)==="table","invalid block type, not a table block");const o=Ve(i),s=It.fromTable(o),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),d=Math.min(l.row,c.row),h=Math.max(l.row,c.row),C=Math.min(l.col,c.col),E=Math.max(l.col,c.col),x=s.getCell({row:d,col:C}),v=s.getCell({row:h,col:E});return{editor:r,block:i,table:o,startCell:x,endCell:v,startRow:d,startCol:C,endRow:h,endCol:E}}const gC=I("split-cell");function pC(n,t,e){n.undoManager.runInGroup(()=>{const r=It.fromBlock(t),i=r.getRealCell(e);p(gC,!i.virtual,"should not split virtual cell"),p(gC,i.colSpan>1||i.rowSpan>1,"cell does not has span data");const o=r.getVirtualCellContainersGrid();for(let C=0;C<i.rowSpan;C++)for(let E=0;E<i.colSpan;E++){if(C===0&&E===0)continue;const x=C+i.row,v=E+i.col,R=Ji(n.doc);o[x][v]=R}const s=n.getBlockData(t),l=mt.default(s);l[`${i.containerId}_colSpan`]=null,l[`${i.containerId}_rowSpan`]=null,l.children=It.virtualCellContainersGridToChildren(o);const d=n.getChildContainerData(i.containerId)[0];p(gC,d,"no child block");const h=ye(n,d.id,0);ll(l),n.updateBlockData(t,l,h)})}function PP(n,t,e){e.forEach(r=>{const i=It.fromBlock(t).getCell(r);(i.virtual||i.colSpan>1||i.rowSpan>1)&&pC(n,t,r)})}function wy(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||Dt(t)!=="table")return!1;const{startCell:s,endCell:l}=c0(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function CC(n){const{editor:t,block:e,startRow:r,startCol:i,endRow:o,endCol:s}=c0(n),l=[];for(let c=r;c<=o;c++)for(let d=i;d<=s;d++)l.push({row:c,col:d});return PP(t,e,l),!0}const $a=I("merge-cells");function Sy(n,t,e){if(e.isSimple())return!1;const{start:r,end:i}=e;if(r.blockId!==i.blockId||n.getBlockById(r.blockId)!==t||Dt(t)!=="table")return!1;const{startCell:s,endCell:l}=c0(e);return s.cell!==l.cell}function Ly(n){const t=c0(n),e=t.editor;e.undoManager.runInGroup(()=>{const r=t.endCell,i=r.row+r.rowSpan-1,o=r.col+r.colSpan-1,s=lt(t.block);CC(n);const l=e.getBlockById(s),c=Ve(l),{startRow:d,startCol:h}=t,C=mt.default(e.getBlockData(l));p($a,C.children,"no table children");const E=It.fromTable(c),x=[];for(let vt=d;vt<=i;vt++)for(let xt=h;xt<=o;xt++){const Gt=E.getCell({row:vt,col:xt});p($a,!Gt.virtual,"cell is virtual"),x.push(Gt)}p($a,x.length>0,"no selected cells");const v=x[0],R=x.slice(1),L=E.getCellByContainerId(v.containerId).container,M=[];R.forEach(vt=>{const xt=E.getCellByContainerId(vt.containerId).container,Gt=ut(xt);if(!lu(e,xt)){const Yt=z5(e,Gt);if(lu(e,L)){const an=ce(L)[0];e.insertDocAt(L,0,Yt),e.deleteBlock(an)}else e.insertDocAt(L,Lr(L),Yt)}M.push(Gt)});const U=ut(L),F=o-h+1,G=i-d+1;C[`${U}_colSpan`]=F,C[`${U}_rowSpan`]=G,M.forEach(vt=>{p($a,C.children,"no table children");const xt=C.children.indexOf(vt);p($a,xt>0,"no deleted container"),C.children.splice(xt,1)});const W=C,st=e.getChildContainerData(U)[0];p($a,st,"no child block");const Et=ye(e,st.id,0);ll(W),e.updateBlockData(l,W,Et),e.deleteChildContainers(M)})}const EC=10,FP=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class u0{constructor(){m(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,r){if(Dt(e)!=="table")return[];const i={blockId:lt(e),blockKind:Ir(t,e),blockType:Dt(e)},o=[];Sy(t,e,r)&&o.push({id:"table/merge-cells",name:D.t("table.mergeCell"),icon:g2,groupIndex:EC,...i}),wy(t,e,r)&&o.push({id:"table/split-cell",name:D.t("table.splitCell"),icon:p2,groupIndex:EC,...i});const s=ky(t,e,r),l=Ry(t,e,r);return s&&l&&o.push({id:"table/delete",name:D.t("table.deleteTable"),icon:C2,groupIndex:EC,...i}),o}executeCommand(t,e,r,i,o,s){return Dt(e)!=="table"||!new Set(FP).has(i.id)?!1:i.id==="table/merge-cells"?(Ly(r),!0):i.id==="table/split-cell"?(CC(r),!0):i.id==="table/delete-columns"?(hC(r),!0):i.id==="table/delete-rows"?(mC(r),!0):i.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var Iy=(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))(Iy||{});const Ha=6,Hu=20,AC="table-cell-menu-btn";function KP(n,t){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,r)}function VP(n,t){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,r)}function $P(n,t){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,r)}function HP(n,t){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,r)}function jP(n,t){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,r)}function zP(n,t){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,r)}function GP(n,t,e){if(!n.isBlockWritable(t))return;const i={...mt.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,i)}const al=I("table-cell-dom");function WP(n,t,e){let r=n.getBlockById(e);for(;r;){const i=r.closest("td");p(al,i,"no parent cell");const o=J(i);if(p(al,o,"no parent block"),o===t)return i;r=o}return p(al,!1,"filed to get cell by child block id"),null}function Jo(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return p(al,e.childContainerId,"block position must have childContainerId attribute"),e;const i=WP(n,t,e.blockId),o=ut(Ku(i));return Ee(t,o)}function xC(n,t){const e=n.selection.range,r=Jo(n,t,e.start),i=Jo(n,t,e.end);return jr(t,r,i)}function Dy(n,t,e,r){p(al,$e(t),"invalid table block");const i=xi(n,t),o=ie(t),s=()=>{const c=i.querySelector(".table-border-bar-container.top");p(al,c,"no top border bar container"),c.querySelectorAll(".table-border-bar-cell.top").forEach(h=>{const C=parseInt(h.getAttribute("data-top-index")||"0",10);r.includes(C)?z(h,"danger"):ot(h,"danger")})},l=()=>{const c=o.querySelector(".table-border-bar-container.left");p(al,c,"no left border bar container"),c.querySelectorAll(".table-border-bar-cell.left").forEach(h=>{const C=parseInt(h.getAttribute("data-left-index")||"0",10);e.includes(C)?z(h,"danger"):ot(h,"danger")})};s(),l()}function Zo(n,t,e=!0,r){const o=It.fromBlock(t).map(h=>h),{fromCol:s,toCol:l,fromRow:c,toRow:d}=xC(n,t);for(let h=0;h<o.length;h++){const C=o[h];for(let E=0;E<C.length;E++){const x=C[E],v=r?E>=s&&E+x.colSpan-1<=l:h>=c&&h+x.rowSpan-1<=d;e&&v?x.virtual||z(x.cell,"danger"):x.virtual||ot(x.cell,"danger")}}}function ts(n,t,e=!0,r){const i=new Set,o=new Set;if(!e){Dy(n,t,Array.from(i),Array.from(o));return}const{fromCol:s,toCol:l,fromRow:c,toRow:d}=xC(n,t);if(r)for(let h=s;h<=l;h++)o.add(h);else for(let h=c;h<=d;h++)i.add(h);Dy(n,t,Array.from(i),Array.from(o))}function _y(n,t,e){const{fromCol:r,toCol:i,fromRow:o,toRow:s}=xC(n,t),l=It.fromBlock(t);let c=null,d=null;return e?(c=l.getCell({col:r,row:0}),d=l.getCell({col:i,row:l.rowCount-1}),Xe(n,{anchor:Ee(t,c.containerId,{colIndex:r,rowIndex:0}),focus:Ee(t,d.containerId,{colIndex:i,rowIndex:l.rowCount-1})})):(c=l.getCell({col:0,row:o}),d=l.getCell({col:l.colCount-1,row:s}),Xe(n,{anchor:Ee(t,c.containerId,{colIndex:0,rowIndex:o}),focus:Ee(t,d.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}const My=["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 Uy(n){return`style-bg-color-${n}`}function ju(n){return`${n}_background`}function qP(n,t,e){const r=Ve(n),s=(e!=null?e:It.fromTable(r)).getCell(t).cell;for(let l=0;l<My.length;l++){const c=My[l];if(wt(s,c))return c}}function Oy(n,t,e){if(!n.isBlockWritable(t))return;const r=n.selection.range,o={...mt.default(n.getBlockData(t))},s=Jo(n,t,r.start),l=Jo(n,t,r.end);if(r.isSimple()){const c=s.childContainerId;e===-1?o[ju(c)]=void 0:o[ju(c)]=Uy(e)}else{const c=It.fromBlock(t),d=jr(t,s,l),h=new Set;for(let C=d.fromRow;C<=d.toRow;C++)for(let E=d.fromCol;E<=d.toCol;E++){const x=c.getCell({row:C,col:E});!h.has(x.containerId)&&x.col>=d.fromCol&&x.row>=d.fromRow&&x.col+x.colSpan-1<=d.toCol&&x.row+x.rowSpan-1<=d.toRow&&(h.add(x.containerId),e===-1?o[ju(x.containerId)]=void 0:o[ju(x.containerId)]=Uy(e))}}n.updateBlockData(t,o)}function XP(n,t,e){if(!n.isBlockWritable(t))return;const i={...mt.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,i)}const Ny=I("table-chart");function YP(n,t){const e=kP(n,t);if(e){const r=e.querySelector(".editor-table-chart");if(r){const i=r.chartObject;i&&i.destroy(),r.remove()}}}async function QP(n,t){if(!n.contains(t)||!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){YP(n,t);return}const i=[],o=It.fromBlock(t),s=["line","bar","pie","radar"];let l=o.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let R=1;R<o.colCount;R++)c.push(o.getCell({row:0,col:R}).container.innerText);for(let R=1;R<o.rowCount;R++){const L=o.getCell({row:R,col:0}),U=L.container.innerText,F=[];for(let Yt=1;Yt<o.colCount;Yt++){const an=o.getCell({row:R,col:Yt}).container.innerText,be=Number.parseFloat(an)||0;F.push(be)}let G;const W=qP(t,L,o);W?G=window.getComputedStyle(n.rootElement).getPropertyValue(`--${W}`).trim():G=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[rt,st,Et,vt]=G?Ag.fromString(G).toRgbaArray():[];if(!rt&&!st&&!Et&&!vt){const Yt=(R-1)%n.options.colors.length;G=n.options.colors[Yt],[rt,st,Et,vt]=Ag.fromString(G).toRgbaArray()}const xt=G,Gt=Ag.fromRgba([rt,st,Et,vt/3]).toHexString();i.push({label:U,data:F,borderColor:xt,backgroundColor:Gt,borderWidth:2})}const d=xi(n,t);let h=null,C=d.querySelector(".editor-table-chart");C?h=C.chartObject:C=B("div",["editor-table-chart"],d);const E=C;p(Ny,E,"no chart container");const x=n.getComponentOptions("table"),v=(x==null?void 0:x.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await Us(v,"editor-chartjs");let R=!1;(h&&h.config.data.datasets.length>i.length||h&&h.config.data.datasets[0].data.length>i[0].data.length)&&(R=!0),h&&(l!==h.config.type||R)&&(h.destroy(),h=null,Array.from(C.querySelectorAll(".editor-chartjs-canvas")).forEach(U=>{U.remove()}));const L=bg.default({},{type:l,data:{datasets:i,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(h)bg.default(h.config,L),h.update();else{const U=B("canvas",["editor-chartjs-canvas"],E).getContext("2d");h=new window.Chart(U,L),C.chartObject=h}}catch(R){Ny.error(`failed to resolve chart cdn: ${JSON.stringify(R)}`)}}async function Py(n,t){await wr.lock("updateTableChart");try{await QP(n,t)}finally{wr.release("updateTableChart")}}const Fy=Me.default(Py,1e3);let Ky=null;function bC(n,t,e){if(Ky!==t&&(Fy.flush(),Ky=t),e.updateNow){Py(n,t);return}Fy(n,t)}function vC(n,t,e){e&&$e(e)&&bC(n,e,{updateNow:!1})}function JP(n,t){$e(t)&&bC(n,t,{updateNow:!0})}const Cr={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"},f0={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},es={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function zu(n,t){return n.containers.get(t)}function Vy(n){return n.closest(`.${es.SCROLL_CONTAINER}`)}function zr(n){return n.firstElementChild}function yn(n){return n.closest(`.${es.CONTAINER}`)}function Gu(n){const t=yn(n);let e=t.querySelector(`:scope >.${es.TOOL}`);return e||(e=B("div",[es.TOOL],t)),e}function ZP(n){return yn(n).firstElementChild}function tF(n,t){const e=zu(n,yn(t));return e!=null&&e.barFloatWindowBottom?typeof e.barFloatWindowBottom=="function"?e.barFloatWindowBottom():e.barFloatWindowBottom:0}function Er(n,t){const e=ur(n);return t/e}function Wu(n){const t=window.getComputedStyle(n),e=ur(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function ja(n){const t=ur(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function eF(n,t){const e=ur(n);return n[t]*e}function BC(n,t){const e=yn(t),r=zu(n,e),i=(r==null?void 0:r.safeRightSpace)||0,o=(r==null?void 0:r.safeLeftSpace)||0,l=(r==null?void 0:r.locatingContainer).getBoundingClientRect(),c=e.getBoundingClientRect(),d=c.width;let h=Math.floor(c.left-l.left-o);h<0&&(h=0);let C=l.right;C-=i;let E=C-c.right;return E<0&&(E=0),h=Math.round(h),E=Math.round(E),{originWidth:d,maxLeft:h,maxRight:E}}function nF(n,t){const e=BC(n,t),{maxLeft:r}=e;t.style.marginLeft=`${Er(t,0-r)}px`,t.style.paddingLeft=`${Er(t,r)}px`}function rF(n,t){const e=BC(n,t);t.style.marginRight=`${Er(t,0-e.maxRight)}px`}function iF(n){if(n!==document.documentElement&&n!==document.body)return n.getBoundingClientRect();const t=0,e=0,r=document.documentElement.clientWidth,i=document.documentElement.clientHeight;return new DOMRect(t,e,r,i)}const $y=I("scroll-bar-handle"),oF=2;function za(n){const t=Gu(n);let e=t.querySelector(`.${f0.SCROLL_BAR}`);return e||(e=B("div",[f0.SCROLL_BAR],t)),p($y,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||B("div",[],e),e}function d0(n,t){const e=Vy(t),r=za(e),{scrollWidth:i,clientWidth:o}=ja(e),{paddingLeft:s,paddingRight:l}=Wu(t),c=BC(n,e),{originWidth:d,maxRight:h}=c;rF(n,e),nF(n,e);const C=i-o;p($y,r.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),r.style.width=`${Er(e,d+h-s-l)}px`,r.firstElementChild.style.width=`${Er(e,d+h+C-s-l)}px`}function sF(n,t){const e=zr(n),{paddingLeft:r}=Wu(e);if(wt(t,"fixed")){const o=yn(n).getBoundingClientRect();t.style.left=`${Er(n,o.left+r)}px`}else t.style.left=`${Er(n,r)}px`}function Ga(n,t){var U;const e=n.getParentScrollContainer(),r=iF(e),i=t.getBoundingClientRect(),o=za(t),s=o.getBoundingClientRect(),l=zu(n,yn(t)),c=tF(n,t),d=zr(t),{paddingTop:h,paddingBottom:C}=Wu(d),{scrollWidth:E,clientWidth:x}=ja(t),v=document.documentElement.clientHeight-c,R=r.top+ja(e).clientHeight-v,L=v+Math.min(0,R);if(E>x&&i.top+h<L-s.height&&i.bottom>L-s.height+C&&!((U=l==null?void 0:l.isSetScale)!=null&&U.call(l))){l!=null&&l.allowScrollBarFixed&&z(o,f0.FIXED);const F=R>0?c:0;o.style.bottom=`${Math.max(document.documentElement.clientHeight-r.bottom,0)+oF+F}px`}else ot(o,f0.FIXED),o.style.bottom=`${Er(t,C-s.height)}px`;sF(t,o)}class lF{constructor(t,e){m(this,"intersectionObserver");m(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(yn(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});m(this,"handleIntersectionEntry",t=>{const e=t.target;Ga(this.scrollCore,e);const r=zr(e);d0(this.scrollCore,r)});this.scrollCore=t,this.callback=e;const i={root:this.scrollCore.getParentScrollContainer(),rootMargin:"20px",threshold:0};this.intersectionObserver=new IntersectionObserver(this.handleIntersection,i)}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 cl=I("container-scroll-shadow");function Hy(n,t,e){const r=n,i=t.getBoundingClientRect(),o=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=Wu(e);r.style.top=`${Er(t,o.top-i.top+s)}px`,r.style.bottom=`${Er(t,i.bottom-o.bottom+l)}px`}function jy(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function aF(n){const t=Gu(n);p(cl,t,"no container tools");let e=t.querySelector(`.${Cr.LEFT}`);if(!e){const l=zr(n),c=[Cr.COMMON,Cr.LEFT];e=B("div",c,t),p(cl,e instanceof HTMLDivElement,"invalid child for container tools"),Hy(e,n,l)}p(cl,e instanceof HTMLElement,"invalid child for container tools");const i=yn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.left=`${Er(n,o.left-i.left)}px`;const s=ja(n).scrollLeft;p(cl,e instanceof HTMLDivElement,"invalid child for container tools"),jy(e,s),z(e,Cr.ACTIVE)}function cF(n){const t=Gu(n);let e=t.querySelector(`.${Cr.RIGHT}`);if(!e){const h=zr(n),C=[Cr.COMMON,Cr.RIGHT];e=B("div",C,t),p(cl,e instanceof HTMLDivElement,"no div, create shadow failed"),Hy(e,n,h)}p(cl,e instanceof HTMLElement,"");const i=yn(n).getBoundingClientRect(),o=n.getBoundingClientRect();e.style.right=`${Er(n,i.right-o.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=ja(n),d=s-l-c;p(cl,e instanceof HTMLDivElement,"no shadow element"),jy(e,d),z(e,Cr.ACTIVE)}function uF(n){const e=Gu(n).querySelector(`.${Cr.LEFT}`);e&&ot(e,Cr.ACTIVE)}function fF(n){const e=Gu(n).querySelector(`.${Cr.RIGHT}`);e&&ot(e,Cr.ACTIVE)}function qu(n){const{scrollLeft:t,scrollWidth:e,clientWidth:r}=ja(n),i=zr(n),{paddingLeft:o,paddingRight:s}=Wu(i),l=eF(i,"offsetLeft");e-o<=r-s||e-o<=t+r-s?fF(n):cF(n),i&&t>=l+o?aF(n):uF(n)}class dF{constructor(t,e){m(this,"resizeObserver");m(this,"handleResizeEntry",t=>{const e=t.target,r=zr(e);qu(e),d0(this.scrollCore,r),Ga(this.scrollCore,e),this.callback(e)});m(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(yn(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new Ds(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 zy=I("container-scroll-observer");class hF{constructor(t,e){m(this,"handleContentScroll",t=>{const e=t.target;p(zy,e instanceof Element,"invalid target for scroll event");const r=za(e);r.removeEventListener("scroll",this.handleScroll);const i=!0;this.fixScrollXPos(e,e.scrollLeft,i),this.bind(r),qu(e),this.callback(e)});m(this,"handleScroll",t=>{const e=t.target;p(zy,e instanceof HTMLElement,"");const r=e.scrollLeft,i=!1,o=ZP(e);this.unbindContentScroll(o),this.fixScrollXPos(o,r,i),this.bindContentScroll(o),qu(o),this.callback(o)});m(this,"handlePrevent",t=>{t.stopPropagation()});m(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});m(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});m(this,"bindContentScroll",Me.default(this.bindContentScrollCore,300));m(this,"bind",Me.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,r){const i=za(t);r||(t.scrollLeft=e),r&&i.scrollLeft!==e&&(i.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 mF{constructor(t){m(this,"scrollContainers",new Set);m(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Ga(this.scrollCore,t)})});m(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});m(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 gF=I("scroll-wrap-resize-observer");class pF{constructor(t){m(this,"resizeObserver");m(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(yn(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});m(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;p(gF,e instanceof HTMLElement,"invalid target for observer entry");const r=Vy(e);d0(this.scrollCore,e),qu(r),Ga(this.scrollCore,r)});this.scrollCore=t,this.resizeObserver=new Ds(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 CF{constructor(t,e){m(this,"resizeObserver");m(this,"scrollContainersMap",new Map);m(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const r=zr(e);qu(e),d0(this.scrollCore,r),Ga(this.scrollCore,e),this.callback(e)})});m(this,"handleResize",t=>{t.forEach(e=>{const r=this.scrollContainersMap.get(e.target);r!=null&&r.length&&this.handleResizeEntry(r)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new Ds(this.handleResize)}bind(t){var i,o;const e=yn(t),r=(i=zu(this.scrollCore,e))==null?void 0:i.locatingContainer;this.scrollContainersMap.has(r)?(o=this.scrollContainersMap.get(r))==null||o.push(t):(this.scrollContainersMap.set(r,[t]),this.resizeObserver.observe(r))}unbind(t){var o,s;const e=yn(t),r=(o=zu(this.scrollCore,e))==null?void 0:o.locatingContainer;if(!r)return;const i=this.scrollContainersMap.get(r);this.scrollContainersMap.set(r,(i==null?void 0:i.filter(l=>l!==t))||[]),(s=this.scrollContainersMap.get(r))!=null&&s.length||(this.resizeObserver.unobserve(r),this.scrollContainersMap.delete(r))}destroy(){this.scrollContainersMap.clear(),this.resizeObserver.disconnect()}}const tct="";class EF extends Be.TypedEmitter{constructor(e){super();m(this,"containerIntersectionObserver",null);m(this,"containerResizeObserver",null);m(this,"containerScrollObserver",null);m(this,"parentContainerScrollObserver",null);m(this,"scrollWrapResizeObserve",null);m(this,"locatingContainerResizeObserver",null);m(this,"isWindowEventBind",!1);m(this,"containers",new Map);m(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});m(this,"handleResize",e=>{this.emit("resize",this,e)});m(this,"handleIntersection",e=>{const r=e.target,i=zr(r);e.isIntersecting?(this.load(),this.bindCore(r,i)):this.unbindCore(r,i)});m(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(r=>{Ga(this,r)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new dF(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new hF(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new mF(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new pF(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new CF(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,r){var o,s,l,c,d,h;const i=za(e);(o=this.containerScrollObserver)==null||o.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(i),(l=this.scrollWrapResizeObserve)==null||l.unbind(r),(c=this.containerResizeObserver)==null||c.unbind(e),(d=this.parentContainerScrollObserver)==null||d.unbindScrollContainer(e),(h=this.locatingContainerResizeObserver)==null||h.unbind(e)}bindCore(e,r){var s,l,c,d,h,C;if(this.unbindCore(e,r),!e.closest("body"))return;const i=za(e);(s=this.containerScrollObserver)==null||s.bindContentScrollCore(e),(l=this.containerScrollObserver)==null||l.bindCore(i),(c=this.scrollWrapResizeObserve)==null||c.bind(r),(d=this.containerResizeObserver)==null||d.bind(e);const o=this.containers.get(yn(e));o!=null&&o.allowScrollBarFixed&&((h=this.parentContainerScrollObserver)==null||h.bindScrollContainer(e)),(C=this.locatingContainerResizeObserver)==null||C.bind(e)}bind(e,r){this.containers.set(e,r);const i=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new lF(this,this.handleIntersection)),this.containerIntersectionObserver.bind(i)}unbind(e){var o;const r=e.firstElementChild,i=zr(r);this.unbindCore(r,i),this.containers.delete(e),(o=this.containerIntersectionObserver)==null||o.unbind(r),this.containers.size||this.destroy()}destroy(){var e,r,i,o,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(r=this.containerIntersectionObserver)==null||r.destroy(),(i=this.containerResizeObserver)==null||i.destroy(),(o=this.scrollWrapResizeObserve)==null||o.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const Gy=I("scroll-container"),h0=new Map;class AF extends Be.TypedEmitter{constructor(){super(...arguments);m(this,"scrollListener");m(this,"options");m(this,"scrollContainerElement");m(this,"init",e=>{this.options=e;const r=B("div",[es.CONTAINER],e.parentElement);me.isMac&&z(r,es.MAC);const i=B("div",[es.SCROLL_CONTAINER],r),o=B("div",[es.SCROLL_AREA],i);o.style.paddingLeft=e.paddingLeft?`${e.paddingLeft}px`:"",o.style.paddingTop=e.paddingTop?`${e.paddingTop}px`:"",o.style.paddingBottom=e.paddingBottom?`${e.paddingBottom}px`:"",o.style.paddingRight=e.paddingRight?`${e.paddingRight}px`:"",o.appendChild(e.childElement);const s=e.parentContainer;this.scrollListener=h0.get(s),this.scrollListener||(this.scrollListener=new EF(s),h0.set(s,this.scrollListener)),this.scrollListener.unbind(r),this.scrollListener.bind(r,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollListener.on("resize",this.handleResize),this.scrollContainerElement=i});m(this,"handleContainerScroll",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)});m(this,"handleResize",(e,r)=>{r===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return p(Gy,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),zr(this.scrollContainerElement)}get scrollOptions(){return p(Gy,this.options,"options cannot be undefined"),{...this.options}}handleBaseListenerDestroy(e){e.destroy()}destroy(){var r;(r=this.scrollListener)==null||r.off("scroll",this.handleContainerScroll);const e=yn(this.contentElement);e&&h0.forEach((i,o)=>{i.unbind(e),i.containers.size===0&&(this.handleBaseListenerDestroy(i),h0.delete(o))})}}function xF(){return new AF}const TC=I("column-width");function bF(n,t,e){wP(n,t).style.width=`${e}px`}function vF(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const r=It.fromTable(n),i=Array(r.colCount).fill(-1),o=n.getBoundingClientRect().left;r.toRealCells(r.cells).forEach(c=>{const d=c.col+c.colSpan-1;i[d]===-1&&(i[d]=c.cell.getBoundingClientRect().right-o)}),TC.debug(`cellRightOffsets1: ${i.join()}`);for(let c=0;c<i.length;c++){const d=i[c];if(d===-1||c===0)continue;let h=c-1;for(;i[h]===-1&&(h--,h!==-1););const C=h===-1?0:i[h],x=(d-C)/(c-h);for(let v=h+1;v<c;v++)i[v]=C+x*(v-h)}TC.debug(`cellRightOffsets2: ${i.join()}`);const s=[];let l=0;for(let c=0;c<i.length;c++){const d=i[c];s.push(d-l),l=d}return TC.debug(`widths: ${s.join()}`),s}function Xu(n){return Array.from(n.querySelector("colgroup").children).map(r=>r.getBoundingClientRect().width||Number.parseInt(r.style.width,10))}const yC=200,BF=40,TF=I("table-resize-gripper"),Wy=7,kC=(Wy-1)/2,yF=3;function kF(n,t,e){const{rows:r}=n;for(let i=0;i<r.length;i++){const o=r[i],s=Array.from(o.cells);for(let l=0;l<s.length;l++){const c=s[l],d=c.getBoundingClientRect(),h=Math.round(d.right);if(Math.abs(t-h)<=kC&&d.top<=e&&e<=d.bottom)return c}}return null}function RF(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function RC(n,t){return xi(n,t).querySelector(".table-resize-gripper")}function qy(n,t){const e=RC(n,t);p(TF,!e,"resize gripper has already exists");const r=xi(n,t),i=B("div",["table-resize-gripper","table-indicator"],r);return B("div",["table-resize-gripper-indicator"],i),i}function Xy(n,t,e){let r=RC(n,t);r||(r=qy(n,t));const o=Ve(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=o.height,d=n.getCustom(Ai(t)).contentElement.getBoundingClientRect(),h=s.right-d.left;r.style.left=`${h-kC-Ha-Hu}px`,r.style.top=`${l}px`,r.style.height=`${c}px`,r.style.width=`${Wy}px`}function wC(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function wF(n,t,e){const i={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,i)}function SF(n,t,e,r){const i=t,o=It.fromTable(e),s=o.getCellByCellElement(i),l=s.col+s.colSpan-1,c=Xu(e);let d=r;const h=(E,x)=>{const v=x+1,R=E.col+E.colSpan;return c.slice(v,R).reduce((M,U)=>M+U,0)},C=new Set;for(let E=0;E<o.rowCount;E++){const x=o.getCell({row:E,col:l});if(C.has(x.cell))continue;C.add(x.cell);const v=x.cell,R=v.getBoundingClientRect();let L=r-R.left+kC-yF;const M=Ku(v),U=r1(n,M)||BF*x.colSpan,F=h(x,l),G=U-F;L<G&&(L=G);const W=R.left+L;d=Math.max(d,W)}return d}const LF=I("table-resize-drag-drop");class IF{constructor(t,e,r,i){m(this,"cursor","col-resize");this.editor=t,this.elem=e,this.data=r,this.onEnd=i}onDragStart(t,e,r){}onDragging(t,e,r,i,o){const{table:s,block:l,draggingRefCell:c}=t.data,h=SF(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;p(LF,c,"no dragging cell");const E=It.fromTable(s).getCellByCellElement(c),x=E.col+E.colSpan-1,v=Xu(s),R=v.slice(0,x).reduce((M,U)=>M+U,0),L=h-R;if(bF(s,x,L),L){const M=parseFloat(s.style.minWidth);s.style.minWidth=`${M+(L-v[x])}px`}Xy(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,r,i,o){const s=Xu(t.data.table);wF(this.editor,t.data.block,s),wC(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function DF(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const r=J(e);return!r||!n.contains(r)||!$e(r)?null:r}I("table-resize");class _F{constructor(t){m(this,"draggingRefCell",null);m(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const r=e.target;if(!(r instanceof Element)||r.closest(".table-indicator"))return;const o=e,s=DF(t,o);if(!s||!Ty(s)||!t.isBlockWritable(s)){wC(t);return}this.updateGripper(s,o.x,o.y)});this.editor=t,t.domEvents.addEventListener(document,"mousemove",this.handleMouseMove)}destroy(){this.editor.domEvents.removeEventListener(document,"mousemove",this.handleMouseMove)}updateGripper(t,e,r){const i=Ve(t),o=kF(i,e,r);if(o){if(!RC(this.editor,t)){if(RF(this.editor))return;const l=qy(this.editor,t),c={block:t,table:i,draggingRefCell:o};Ig(new IF(this.editor,l,c,d=>{this.updateGripper(t,d.x,d.y)}))}Xy(this.editor,t,o)}else wC(this.editor)}}function Yy(n){n.addCustom("table-mouse-event-handler",t=>new _F(t))}const Qy=I("table-insert-column");function Jy(n,t,e){n.undoManager.runInGroup(()=>{var E;const r=Ve(t),i=It.fromTable(r),o=i.colCount;p(Qy,e>=0&&e<=o,`insert index ${e} is out of range [0, ${o}]`);const s=i.map(x=>x.containerId),l=new Set;n.doc.beginBatchUpdate();for(let x=0;x<s.length;x++){const v=s[x],R=v[e-1],L=v[e];if(e===0||e===v.length||R!==L){const M=Ji(n.doc);v.splice(e,0,M)}else v.splice(e,0,R),l.add(R)}n.doc.endBatchUpdate();const c=mt.default(n.getBlockData(t));l.forEach(x=>{const v=`${x}_colSpan`,R=c[v];p(Qy,typeof R=="number"&&R>1,`no colSpan for containerId ${x}, ${R}`),c[v]=R+1});const d=((E=c.colsWidth)==null?void 0:E.concat())||new Array(c.cols).fill(0);d.splice(e,0,yC);const h=It.virtualCellContainersGridToChildren(s),C={...c,cols:c.cols+1,children:h,colsWidth:d};ll(C),n.updateBlockData(t,C)})}const m0=I("table-insert-row");function SC(n,t,e){n.undoManager.runInGroup(()=>{const r=Ve(t),i=It.fromTable(r),o=i.rowCount;p(m0,e>=0&&e<=o,`insert index ${e} is out of range [0, ${o}]`);const s=i.map(E=>E.containerId),l=new Set;n.doc.beginBatchUpdate();const c=[];for(let E=0;E<i.colCount;E++){const x=e>0&&s[e-1][E],v=e<i.rowCount&&s[e][E];if(p(m0,x||v,"no top and bottom cell"),e===0||e===i.rowCount||x!==v){const R=Ji(n.doc);c.push(R)}else p(m0,x,"no top cell"),c.push(x),l.add(x)}n.doc.endBatchUpdate(),s.splice(e,0,c);const d=mt.default(n.getBlockData(t));l.forEach(E=>{const x=`${E}_rowSpan`,v=d[x];p(m0,typeof v=="number"&&v>1,`no rowSpan for containerId ${E}, ${v}`),d[x]=v+1});const h=It.virtualCellContainersGridToChildren(s),C={...d,rows:d.rows+1,children:h};ll(C),n.updateBlockData(t,C)})}const LC=I("paste-table-in-table-block");function MF(n,t,e,r,i){let o=It.fromBlock(e);const s=t.blocks.root[0];p(LC,s,"no table data"),p(LC,s.type==="table",`table data type is not table, but ${s.type}`);const l=s,c=o.getCellByCellElement(r),d=l.cols,h=l.rows,C=c.col,E=c.row,x=C+d,v=E+h,R=[];for(let L=C;L<x&&L<o.colCount;L++)for(let M=E;M<v&&M<o.rowCount;M++){const U=o.getCell({col:L,row:M});U.virtual?U.virtual&&R.push({col:L,row:M}):(U.colSpan>1||U.rowSpan>1)&&R.push({col:L,row:M})}n.undoManager.runInGroup(()=>{if(n.doc.beginBatchUpdate(),R.forEach(F=>{const G=It.fromBlock(e).getCell(F);(G.colSpan>1||G.rowSpan>1)&&pC(n,e,F)}),x>o.colCount)for(let F=o.colCount;F<x;F++)Jy(n,e,F);if(v>o.rowCount)for(let F=o.rowCount;F<v;F++)SC(n,e,F);o=It.fromBlock(e);const L=new s0(l);let M;for(let F=0;F<L.colCount;F++)for(let G=0;G<L.rowCount;G++){const W=L.getCell({col:F,row:G});if(!W.virtual){const rt=np(n.editorBlocks,t,W.containerId,i),st=C+F,Et=E+G,vt={col:st,row:Et},xt=o.getCellContainer(vt);ZB(n,xt,rt,i),M=xt}}n.doc.endBatchUpdate(),p(LC,M,"no last container");const U=tn(M);n.selection.selectBlock(U,dt(n,U))})}const IC=I("paste-in-table-block");class UF{constructor(t){m(this,"pasteData");this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){this.pasteData=void 0}async handleBeforePaste(t,e,r,i){return this.pasteData={doc:r,files:i,event:e},!1}async handleBeforePasteDoc(t,e){var E,x,v,R;if(!t.selection.range.isSimple())return this.pasteData=void 0,!1;if(t.selection.range.start.offset!==0)return this.pasteData=void 0,!1;const i=t.selection.startBlock,o=it(i);if(Xt(o))return this.pasteData=void 0,!1;if(!lu(t,o))return this.pasteData=void 0,!1;const s=J(o);if(p(IC,s,"no parent block"),!$e(s))return this.pasteData=void 0,!1;if(e.blocks.root.length!==1)return this.pasteData=void 0,!1;if(e.blocks.root[0].type!=="table")return this.pasteData=void 0,!1;IC.debug("paste child table in table");const d=It.fromBlock(s).getCellByContainerId(ut(o)).cell;xp(t,e);const h={blockIdMap:new Map,containerIdMap:new Map};MF(t,e,s,d,h),p(IC,this.pasteData,"invalid paste data");const C=[];t.input.forEach(L=>{C.push(L)});for(let L=0;L<C.length&&!await((x=(E=C[L]).handleAfterPasteDoc)==null?void 0:x.call(E,t,e,h));L++);for(let L=0;L<C.length&&!await((R=(v=C[L]).handleAfterPaste)==null?void 0:R.call(v,t,this.pasteData.event,this.pasteData.doc));L++);return this.pasteData=void 0,!0}}function Zy(n){n.addCustom("table-block-paste-event",t=>new UF(t))}const DC=I("table-select-columns");function OF(n,t,e,r,i){p(DC,$e(t),"is not a table block");const o=It.fromBlock(t);p(DC,e>=0&&e<o.colCount,"invalid from"),p(DC,r>0&&e+r<=o.colCount,"invalid count");const s=o.getCell({row:0,col:e}),l=o.getCell({row:o.rowCount-1,col:e+r-1}),c=Ee(t,s.containerId,{colIndex:e,rowIndex:0}),d=Ee(t,l.containerId,{colIndex:e+r-1,rowIndex:o.rowCount-1});i!=null&&i.reverse?n.selection.setSelection(d,c):n.selection.setSelection(c,d)}const _C=I("table-select-columns");function NF(n,t,e,r,i){p(_C,$e(t),"is not a table block");const o=It.fromBlock(t);p(_C,e>=0&&e<o.rowCount,"invalid from"),p(_C,r>0&&e+r<=o.rowCount,"invalid count");const s=o.getCell({row:e,col:0}),l=o.getCell({row:e+r-1,col:o.colCount-1}),c=Ee(t,s.containerId,{rowIndex:e,colIndex:0}),d=Ee(t,l.containerId,{rowIndex:e+r-1,colIndex:o.colCount-1});i!=null&&i.reverse?n.selection.setSelection(d,c):n.selection.setSelection(c,d)}const ect="",tk=I("get-toolbar-reference-client");function ek(n,t){const e=n.selection.range;if(!e.isSimple()){p(tk,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);p(tk,Mt(n,s),"not a complex block");const l=Qt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const r=e.isReverse()?t.start:t.end,i=Xe(n,{anchor:r,focus:r}),o=ji(n,t.block,i);if(o.length!==0)return o[0]}function PF(n){var t,e;if(n.children){let r=!1;const i=[];for(const o of n.children){if((t=o.states)!=null&&t.includes("checked")){r=!0;break}(e=n.defaultCheckedChildren)!=null&&e.includes(o.id)&&i.push(o)}if(!r&&(i==null?void 0:i.length))for(const o of i)Array.isArray(o.states)?o.states.push("checked"):o.states=["checked"]}}function g0(n){const t=(i,o)=>{const s=i.findIndex(c=>c.id===o.id);if(s===-1){i.push(o);return}const l=i[s];if(l.value!==o.value&&delete l.value,!!l.states){if(!o.states){l.states=[];return}l.states=vg.default(l.states,o.states)}},e=[],r=new Map;return n.forEach(i=>{var o,s;(o=i.children)!=null&&o.length&&(r.has(i.id)?(s=r.get(i.id))==null||s.push(...i.children):r.set(i.id,[...i.children])),t(e,i)}),r.forEach((i,o)=>{const s=e.find(l=>l.id===o);s&&(s.children=g0(i),PF(s))}),e}function p0(n){return n.findCustom("toolbar-handler")}const nct="";class FF{constructor(){m(this,"linkPopup",null);m(this,"form",{});m(this,"onFinished",null);m(this,"onClose",null);m(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:r}=this.form,i=this.formatUrl(r.getInputValue());(t=this.onFinished)==null||t.call(this,e.getInputValue()||i,i),this._destroy()}catch{}});m(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});m(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});m(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector('[data-button-id="submit-button"]');t.disabled=!1});m(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()}});m(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(D.t("link.urlPlaceholder")),new Error(D.t("link.urlPlaceholder"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}editLink(t){var h,C;const{target:e,linkText:r,linkUrl:i,onFinished:o,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Nu(this.createPopupContent(r,i)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=o,s&&(this.onClose=s);const c=(h=this.linkPopup)==null?void 0:h.content.querySelector('[data-button-id="submit-button"]'),d=(C=this.linkPopup)==null?void 0:C.content.querySelector('[data-button-id="cancel-button"]');c==null||c.addEventListener("click",this.handleOk),d==null||d.addEventListener("click",this.handleClose)}createPopupContent(t,e){const r=B("div",["link-popup-content"],null);this.form.linkText=lC(r,{label:D.t("link.textLabel"),required:!1,placeholder:D.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=lC(r,{className:"link-popup-gap",label:D.t("link.urlLabel"),required:!0,placeholder:D.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const i=B("div",["link-popup-footer"],r),o=pr("cancel-button",D.t("link.cancelText"));i.appendChild(o);const s=pr("submit-button",D.t("link.submitText"),void 0,["disabled","primary"]);return i.appendChild(s),r}_destroy(){var r,i,o,s;const t=(r=this.linkPopup)==null?void 0:r.content.querySelector('[data-button-id="submit-button"]'),e=(i=this.linkPopup)==null?void 0:i.content.querySelector('[data-button-id="cancel-button"]');t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(o=this.linkPopup)==null||o.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function Yu(n,t){n.addCustom("link-editor",()=>new FF).editLink(t)}const KF=I("link-popup");function VF(n){return wt(n,"link")}function Qu(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function $F(n,t,e){var i,o,s,l;if(n.isBlockWritable(t)&&e&&Xn(e)){const c=e,d=(o=(i=n.editorBoxes.getBoxClass(ru(c))).getBoxProperties)==null?void 0:o.call(i,n,c);if(d!=null&&d.boxCommands){const h=(l=(s=d.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[];return{element:e,commands:h}}return{element:null,commands:[]}}if(n.isWritable()&&e&&nt(n,t)&&VF(e)){const c=B("a",["link-href-button"],null,Qu(e));c.href=Qu(e),c.target="_blank",c.rel="noopener noreferrer";const d=[{id:"link-text",name:Qu(e),disableTooltip:!0,element:c},{id:"edit-link",name:D.t("link.edit"),icon:r0},{id:"remove-link",name:D.t("link.remove"),icon:k2}];return{element:e,commands:d}}return Vv(n,t,"hovering-toolbar")}function nk(n,t,e){var l;const r=Ys(t,e),i=n.getBlockText(t),o={start:0,end:0};let s=(l=e.textContent)!=null?l:"";for(let c=0;c<i.length;c++){const d=i[c];if(o.end+d.insert.length>=r.end){o.end+=d.insert.length,s=d.insert;break}o.start<r.start&&(o.start+=d.insert.length,o.end=o.start)}return[o,s]}function HF(n,t,e){const[r,i]=nk(n,t,e);n.selection.selectBlock(t,r.start,r.end);const o=Qu(e),s=(h,C)=>{try{const E=n.getBlockText(t),x=O1(E,r.start,r.end-r.start),v=Yi(x,r.start,h,{link:C});n.setBlockText(t,v),n.selection.selectBlock(t,r.start+h.length),n.focus()}catch(E){KF.error(E)}},l=()=>{n.selection.selectBlock(t,r.end),n.focus()},c=ji(n,t,n.selection.range)[0];if(!c)return;const d=Wi(n,t,"link-button-anchor",c);Yu(n,{target:d,linkText:i,linkUrl:o,onFinished:s,onClose:l})}function jF(n,t,e){const[r]=nk(n,t,e),i=n.getBlockText(t),o=Qu(e),s=Aa(r.start,r.end-r.start,i,"link",o);n.setBlockText(t,s),n.selection.selectBlock(t,r.end)}function zF(n,t,e,r){var s,l,c;if(e){if(n.isBlockWritable(t)&&Xn(e)){const h=e,C=(l=(s=n.editorBoxes.getBoxClass(ru(h))).getBoxProperties)==null?void 0:l.call(s,n,h);if(C!=null&&C.boxCommands){C.boxCommands["hovering-toolbar"].executeCommand(n,t,h,r);return}return}const d=p0(n);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},400),r.id==="edit-link"?HF(n,t,e):r.id==="remove-link"&&jF(n,t,e);return}const i=Kv(n,t);if(!i)return;const o=(c=i.blockCommands)==null?void 0:c["hovering-toolbar"];!o||o.executeCommand(n,t,r)}function C0(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const GF=[Wh,qh,Xh,Yh,Qh,Jh,Zh,t0];class WF{constructor(t){m(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=C0();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,r){if(nt(t,e)){const i=lt(e),o=Dt(e),s=Ir(t,e),c=t.getBlockData(e).heading,d=[];for(let C=0;C<this.getHeadingIndex();C++)d.push({id:`heading-${C+1}`,name:D.t("commands.heading",{name:`${C+1}`}),icon:GF[C],states:c===C+1?["checked"]:[],value:`${C+1}`});const h=C=>{var x;const E=B("span",["toolbar-item-name-container"],null);for(const v of C.children)if((x=v.states)!=null&&x.includes("checked"))return E.innerHTML=v.icon||Pa,E;return E.innerHTML=Pa,E};return[{id:"turn-into",name:D.t("commands.headingGroup"),blockId:i,blockType:o,blockKind:s,element:h,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:D.t("commands.text"),icon:Pa,states:c?[]:["checked"]},...d],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,r){t.updateBlockData(e,{heading:r})}executeCommand(t,e,r,i){if(nt(t,e)&&(i.id.startsWith("heading-")||i.id==="text")){const o=i.value?Number(i.value):null;return this.applyHeadingStyle(t,e,o),!0}return!1}}const qF=8,Se=I("list-block"),E0=I("list-block");function Kt(n){return Dt(n)==="list"}function Ue(n){p(E0,Kt(n),"not a list block")}function Zn(n){Ue(n);const t=n.getAttribute("data-list-type");return p(E0,t,"no list type"),t}function A0(n){return Kt(n)&&Zn(n)==="text-only"}function tr(n){var t,e;return Ue(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function sn(n){var t,e;return Ue(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Wa(n){Ue(n);const t=n.getAttribute("data-list-group-id");return p(E0,t,"no group id"),t}function ns(n){var o,s,l,c,d;Ue(n);const t=(o=n.getAttribute("data-list-type"))!=null?o:"ordered",e=(l=Number.parseInt((s=n.getAttribute("data-list-start"))!=null?s:"1",10))!=null?l:1,r=(d=Number.parseInt((c=n.getAttribute("data-list-level"))!=null?c:"1",10))!=null?d:1,i=n.getAttribute("data-list-group-id");return p(E0,i,"no group id"),{type:t,start:e,level:r,groupId:i}}function MC(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 XF(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="",r=n;return Object.entries(t).forEach(([i,o])=>{for(;r>=o;)e+=i,r-=o}),e.toLowerCase()}const YF="abcdefghijklmnopqrstuvwxyz";function rk(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),r=YF[t];return e?rk(e)+r:r}function QF(n){return`${n}`}const ik=[QF,rk,XF];function JF(n,t){const e=ik[(n-1)%ik.length];return e(t)}function ZF(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}function rs(n,t){Ue(n);const{level:e,groupId:r,type:i}=ns(n);let o=Ae(n);for(;o;){if(!Kt(o))return null;const{level:s,groupId:l,type:c}=ns(o);if(s<e)return null;if(e===s&&((t==null?void 0:t.ignoreGroupId)||r===l)&&(c==="text-only"||i==="text-only"||i===c))return o;o=Ae(o)}return null}function ok(n){return rs(n,{ignoreGroupId:!0})}function ul(n){Ue(n);const{level:t,groupId:e,type:r}=ns(n);let i=Zt(n);for(;i;){if(Kt(i)){const{level:o,groupId:s,type:l}=ns(i);if(t===o&&e===s&&(l==="text-only"||r==="text-only"||r===l))return i;if(o<t)return null}i=Zt(i)}return null}function sk(n){Ue(n);const t=[];let e=rs(n);for(;e;)t.unshift(e),e=rs(e);return t}function qa(n){Ue(n);const t=[];let e=ul(n);for(;e;)t.push(e),e=ul(e);return t}function Ju(n){Ue(n);let t=rs(n);for(;t;){const e=rs(t);if(!e)return t;t=e}return n}function tK(n){Ue(n);let t=ul(n);for(;t;){const e=ul(t);if(!e)return t;t=e}return null}function lk(n,t){const e=sk(n),r=qa(n);return t.withSelf?[...e,n,...r]:[...e,...r]}function x0(n){Ue(n);let t=n;const e=sk(n);e.length>0&&(t=e[0]);const r=Ae(t);return!r||!Kt(r)?null:sn(r)<sn(t)?r:null}function eK(n,t){Ue(n);let e=n;for(;e;){const r=sn(e);if(r===t)return e;if(r>t)e=x0(e);else if(r<t)return null}return null}function nK(n){let t=Ju(n);for(;;){const e=x0(t);if(!e)return t;t=Ju(e)}}class rK{constructor(){m(this,"nodeMap",new Map);m(this,"rootNodes",[])}addNode(t,e){const r={block:e,children:[]};if(this.nodeMap.set(e,r),t){const i=this.nodeMap.get(t);p(Se,i,"no parent node"),i.children.push(r)}else this.rootNodes.push(r)}}function ak(n,t){const e=nK(t),r=new rK;r.addNode(null,e);let i=Zt(e);for(;i&&Kt(i);){if(A0(i)){r.addNode(null,i),i=Zt(i);continue}if(sn(i)===0&&Zn(i)!==Zn(e))break;const s=x0(i);r.addNode(s,i),i=Zt(i)}return r.rootNodes}function iK(n){const t=document.fullscreenEnabled||document.mozFullScreenEnabled||document.documentElement.webkitRequestFullScreen,e=r=>{if(r.requestFullscreen)return r.requestFullscreen();if(r.mozRequestFullScreen)return r.mozRequestFullScreen();if(r.webkitRequestFullScreen){try{document.fullscreenElement=n}catch{}return r.webkitRequestFullScreen()}return Promise.resolve(0)};return t?e(n):Promise.resolve(0)}function ck(){const e=(document.exitFullscreen||document.webkitExitFullscreen).bind(document)();try{document.fullscreenElement=null}catch{}return e}function UC(n){return wt(n,"editor-in-mindmap-first")}function OC(n){if(p(Se,Kt(n),"not a list block"),wt(n,"editor-in-mindmap-first")||!nu(n))return!0;const t=n.classList,e="editor-mindmap-root-";return!!Array.from(t).find(i=>{if(i.startsWith(e))return i})}function oK(n,t,e){const r=it(n);if(t){const s=it(t);p(Se,r===s,"invalid block container")}const i=Bt(n);if(t){const s=Bt(t);p(Se,i<=s,"invalid block index")}if(z(n,...e),!t||t===n)return;let o=Zt(n);for(;o!==t;)p(Se,o,"no next button"),z(o,...e),o=Zt(o);o&&z(o,...e)}function sK(n){const t=`editor-mindmap-root-${n.id}`,r=it(n).querySelectorAll(`.${t}`);return r[r.length-1]}async function lK(n,t,e){const r=ie(t),i=r.querySelector('[data-button-id="mindmap-fullscreen"]');p(Se,i,"no full screen button");const o=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{ot(r,"fullscreen"),i.innerHTML=iC,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,D.t("mindmap.fullScreen")),OC(t)&&setTimeout(()=>{o()},300)};if(document.fullscreenElement===r){try{await ck()}catch(l){Se.error(l)}s()}else{try{z(r,"fullscreen"),await iK(r),o()}catch(l){Se.error(l)}i.innerHTML=ay,i.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,D.t("mindmap.exitFullscreen"))}r.onfullscreenchange=()=>{document.fullscreenElement||s()}}function NC(n,t,e,r,i){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=pr(e,r,i,[]);return s.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,r),z(s,"mindmap-button"),t.appendChild(s),s}function PC(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function aK(n){return PC(n,"mindmap-fullscreen")}function cK(n){return PC(n,"mindmap-fit")}function uK(n){return PC(n,"mindmap-close")}function fK(n,t,e,r){const i=NC(n,t,"mindmap-close",D.t("mindmap.close"),zh);!i||n.domEvents.addEventListener(i,"click",()=>{r.closeMindmap(n,e)})}function dK(n,t,e,r){const i=NC(n,t,"mindmap-fit",D.t("mindmap.autoFit"),ly);!i||n.domEvents.addEventListener(i,"click",()=>{r.fitMindmap(n,e)})}function hK(n,t,e,r){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const o=NC(n,t,"mindmap-fullscreen",D.t("mindmap.fullScreen"),iC);!o||n.domEvents.addEventListener(o,"click",()=>{lK(n,e,r)})}function mK(n,t){const e=jd(t);if(!e)return;const r=cK(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=uK(e);i&&(i.remove(),n.domEvents.removeAllListeners(i));const o=aK(e);o&&(o.remove(),n.domEvents.removeAllListeners(o))}const Xa=new Map;function FC(n,t,e){const r=(s,l)=>{s.forEach(c=>{l?z(c.block,"to-mindmap-highlight"):ot(c.block,"to-mindmap-highlight"),r(c.children,l)})},i=ak(n,t);if(i.length===0)return;const o=i[0].block;if(e){const s=Xa.get(o);s&&(s.forEach(l=>l.cancel()),Xa.delete(o)),r(i,!0)}else{const s=setTimeout(()=>{r(i,!1),Xa.delete(o)},300),l=()=>{clearTimeout(s),Xa.delete(o)},c=Xa.get(o);c?c.push({cancel:l}):Xa.set(o,[{cancel:l}])}}const{Markmap:gK}=X6;function pK(n,t){Ue(t);const e=ak(n,t),r=e[0].block,i=d=>({t:"text",v:Ot(d.block).textContent,d:1,c:d.children.length>0?d.children.map(C=>i(C)):void 0});let o=null;e.length>1?o={t:"root",v:"root",d:0,c:e.length>0?e.map(d=>i(d)):void 0}:o=i(e[0]);const l=d=>{if(d.length===0)return null;const h=d[d.length-1];return h.children&&h.children.length>0?l(h.children):h},c=l(e);return{root:o,block:r,nodes:e,last:c}}function b0(n,t,e,r){const{root:i,block:o,last:s}=pK(n,t);r.selectBlock&&n.selection.selectBlock(o,0,0),FC(n,o,!1),r.saveData&&n.updateBlockData(o,{viewAsMindmap:!0});const l=ie(o);let c=l.querySelector(".editor-mindmap-svg");if(r.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const M="http://www.w3.org/2000/svg",U=l.getBoundingClientRect(),F=document.fullscreenElement===l,G=F?`${U.width}`:`${t.getBoundingClientRect().width}`,W=F?`${U.height}`:"600",rt=document.createElementNS(M,"svg");rt.setAttributeNS(null,"viewBox",`0 0 ${G} ${W}`),rt.setAttributeNS(null,"width","100%"),rt.setAttributeNS(null,"height",W),rt.style.display="block",rt.style.width="100%",rt.style.height=`${W}px`,rt.classList.add("editor-mindmap-svg"),l.appendChild(rt),c=rt}const d=o,C=`editor-mindmap-root-${lt(o)}`;z(d,"editor-in-mindmap-first",C,"readonly"),d.contentEditable="false";const E=Zt(o);E&&Bt(E)<=Bt(s.block)&&oK(E,s.block,["block-hidden",C]);const x=(M,U)=>{if(U.length>0){const F=U[0].parentElement;F&&(F.style.width="100vw",F.style.maxWidth="200px")}U.forEach(F=>{z(F,"editor-mindmap-node")})},v=new gK(c,{...e,autoFit:!0});v.viewHooks.transformHtml.tap(x),v.setData(i),v.fit();const R=ie(o);let L=R.querySelector(".mindmap-toolbar");L||(L=B("div",["mindmap-toolbar"],R)),dK(n,L,d,r.mindmapTools),hK(n,L,d,r.mindmapTools),fK(n,L,d,r.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(o,0),n.input.focus()}),d.mindMap=v}function CK(n){const t=B("div",["list-to-mindmap-wrap"],null),e=pr("list-to-mindmap",D.t("mindmap.viewAsMindMap"),sy,[],n.clientId);return t.appendChild(e),t}async function uk(n,t){const e=`editor-mindmap-root-${t.id}`,r=it(t);ce(r).forEach(l=>{wt(l,e)&&ot(l,e,"editor-in-mindmap-first","block-hidden")});const o=ie(t);document.fullscreenElement===o&&await ck();const s=o.querySelector(".editor-mindmap-svg");!s||(p(Se,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),mK(n,t))}function EK(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(i=>{if(i.startsWith(e))return i})}async function fk(n,t){!EK(t)||(n.updateBlockData(t,{viewAsMindmap:null}),uk(n,t),n.selection.selectBlock(t,0))}function AK(n,t){const e=t.mindMap;e&&e.fit()}const v0={toMindmap:b0,closeMindmap:fk,fitMindmap:AK},rct="";class B0{constructor(t){m(this,"toMindmapButton");m(this,"currentBlock",null);m(this,"handleHoveringBlock",t=>{t&&Kt(t)&&Zn(t)!=="unchecked"&&Zn(t)!=="checked"&&this.editor.isWritable()?ie(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove()});m(this,"handleMouseEnter",()=>{const t=J(this.toMindmapButton);p(Se,t&&Kt(t),"no parent list"),FC(this.editor,t,!0),this.currentBlock=t});m(this,"handleMouseLeave",()=>{this.currentBlock&&(FC(this.editor,this.currentBlock,!1),this.currentBlock=null)});m(this,"handleClick",()=>{const t=J(this.toMindmapButton);p(Se,t&&Kt(t),"no parent list"),b0(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:v0})});this.editor=t,Te.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=CK(t),t.domEvents.addEventListener(this.toMindmapButton,"mouseenter",this.handleMouseEnter),t.domEvents.addEventListener(this.toMindmapButton,"mouseleave",this.handleMouseLeave),t.domEvents.addEventListener(this.toMindmapButton,"click",this.handleClick)}static get(t){return t.findCustomByType(B0)}destroy(){Te.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}function xK(n,t,e){var r;t==="beginDrag"&&((r=B0.get(n))==null||r.hide())}function Ya(n,t,e,r){var o;const i=(o=r==null?void 0:r.groupId)!=null?o:tt();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(r==null?void 0:r.resetGroupId)){const c={...l,start:e};r!=null&&r.resetGroupId&&(c.groupId=i),n.updateBlockData(s,c)}l.textOnly||(e+=1)})}function KC(n,t,e,r){const i=lk(t,{withSelf:!0});i.length!==0&&Ya(n,i,e,r)}class T0{constructor(t,e){m(this,"listStart",0);m(this,"listBrother",null);if(this.editor=t,A0(e))return;const r=Ju(e),i=tr(r);this.listStart=i,r===e?this.listBrother=ul(r):this.listBrother=r}fix(){!this.listBrother||KC(this.editor,this.listBrother,this.listStart)}}class fl{constructor(t,e,r){m(this,"listStart");m(this,"listBrother",null);this.editor=t,this.options=r;const i=Ju(e),o=tr(i);this.listStart=o,this.listBrother=i,r!=null&&r.resetStart&&(this.listStart=1)}fix(){!this.listBrother||KC(this.editor,this.listBrother,this.listStart,this.options)}}class dk{constructor(t,e,r){m(this,"listStart");m(this,"listNextBrothers",[]);this.editor=t,this.listNextBrothers=qa(e);const{start:i,resetStart:o}=r||{};this.listStart=o?1:i!=null?i:1}fix(){!this.listNextBrothers.length||Ya(this.editor,this.listNextBrothers,this.listStart)}}function bK(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function VC(n,t,e,r){if(Se.debug("drag a block on a list block"),!nt(n,t))return!1;p(Se,Kt(e),"target is not a list block");const{type:i,start:o,level:s,groupId:l}=ns(e),c=r==="after"?o+1:o,d=n.getBlockData(t),h={id:tt(),type:"list",groupId:l,level:s,start:c,text:d.text,...MC(i)};bK(n,e,h);let C=Bt(e);const E=it(e);r==="after"&&(C+=1);let x=null;Kt(t)&&(x=new T0(n,t));const v=n.insertBlock(ut(E),C,h,dh(h.id,0));return n.deleteBlock(t),new fl(n,v).fix(),x==null||x.fix(),!0}function vK(n,t,e,r){if(Se.debug("drag a list between text blocks"),r==="after"){const d=Zt(e);if(d&&Kt(d))return VC(n,t,d,"before")}if(r==="before"){const d=Ae(e);if(d&&Kt(d))return VC(n,t,d,"after")}const o={...n.getBlockData(t),groupId:tt(),start:1,level:1};let s=Bt(e);const l=it(e);r==="after"&&(s+=1),n.insertBlock(ut(l),s,o,dh(o.id,0));const c=new T0(n,t);return n.deleteBlock(t),c.fix(),!0}function BK(n,t,e,r,i){if(Fd(e))return!1;const{blockId:o}=e,s=n.getBlockById(o);p(Se,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=i;return!l&&c?(p(Se,t===c,"block !== target block"),p(Se,Kt(c),"target is not a list block"),VC(n,s,c,r)):vK(n,s,c,r)}function hk(n,t){if(!n.isWritable())return!1;const e=n.selection.range,i=n.editorCommandProviders.getCommands(e).find(o=>o.id===t);return i?(n.editorCommandProviders.executeCommand(e,i,{}),!0):!1}const TK={"Shift+CtrlOrCmd+L":n=>hk(n,"ordered-list"),"Shift+CtrlOrCmd+U":n=>hk(n,"unordered-list")};function y0(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function yK(n,t){let e;const r=y0(t);if(!r)e=1;else{if(r>=12)return e=12,!1;e=r+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function mk(n,t){const e=y0(t);if(!e)return!1;const r=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...r,padding:e-1}),!0):(n.updateBlockData(t,{...r,padding:null}),!0)}function $C(n){return n.readonly||!n.isWritable()}function kK(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;nt(n,r)&&yK(n,r)}),!0}function RK(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const r=e.block;nt(n,r)&&mk(n,r)}),!0}function wK(n){return $C(n)?!1:n.undoManager.runInGroup(()=>(kK(n),!0))}function SK(n){return $C(n)?!1:n.undoManager.runInGroup(()=>(RK(n),!0))}function LK(n){if($C(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!nt(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!y0(t)))return mk(n,t),!0}class HC{renderBlock(t,e,r){const{padding:i}=r;return i?{attributes:{"block-padding-level":i}}:{}}}const ict="",IK={Tab:wK,"Shift+Tab":SK,Backspace:LK};function DK(n,t,e=1){if(!t)return null;let r=Ae(n);for(;r;){const i=r.getAttribute("data-style-heading"),o=Number(r.getAttribute("data-list-level"));if(i){if(i<t)return null;if(i===t&&o===e)return Kt(r)?r:null}r=Ae(r)}return null}function _K(n,t){const e=n.getAttribute("data-style-heading"),r=DK(n,e);if(r)return r;const i=Ae(n);if(i&&Kt(i)&&Zn(i)===t)return i;const o=Zt(n);return o&&Kt(o)&&Zn(o)===t?o:null}function MK(n,t,e){var R,L,M;const r=(R=e.data)!=null?R:{};let i=1;if(Kt(t))i=sn(t);else{const U=y0(t);U&&(i=U+1),i>8&&(i=8)}const o=(L=r.listType)!=null?L:"ordered";if(o==="text-only")return null;const s=n.getBlockData(t);let l=(M=s.text)!=null?M:[],d=fe(l);const h=e.offset||0;h<=dn(l)&&(l=Dn(l,h).right,d=d.substring(0,h));let C=1;o==="ordered"&&(C=Number.parseInt(d,10)||1);let E=tt();const x=_K(t,o);if(x)if(sn(x)===i){if(Bt(t)>Bt(x))C=tr(x)+1;else{const U=tr(x);U>1&&(C=U-1),new dk(n,x,{start:C+1}).fix()}E=Wa(x)}else{const U=eK(x,i);U&&(C=tr(U)+1)}else Kt(t)&&new dk(n,t,{start:1}).fix();const v={id:tt(),type:"list",level:i,start:C,groupId:E,ordered:!1,text:l};return s.quoted&&(v.quoted=!0),s.heading&&(v.heading=s.heading),o==="ordered"?v.ordered=!0:(o==="checked"||o==="unchecked")&&(v.checkbox=o),{blockData:v,onConverted:(U,F)=>{new fl(U,F).fix()}}}function Qa(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function UK(n){var e,r;if(n.checkbox)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${JF(t,(r=n.start)!=null?r:1)}.`:ZF(t)}function k0(n){return n==="checked"||n==="unchecked"}function gk(n,t,e,r){const i=t,{containerId:o,blockIndex:s}=r[r.length-1];if(s===0)return!0;const l=e.blocks[o][s-1];if(l.type!=="list")return!0;const c=Qa(i),d=Qa(l);return c!==d&&(!k0(c)||!k0(d))||(i.level||1)>(l.level||1)}function pk(n,t,e,r){const i=t,{containerId:o,blockIndex:s}=r[r.length-1];if(s===e.blocks[o].length-1)return!0;const l=e.blocks[o][s+1];if(l.type!=="list")return!0;const c=Qa(i),d=Qa(l);return c!==d&&(!k0(c)||!k0(d))||(i.level||1)>(l.level||1)}function OK(n,t,e,r,i){var s,l,c;const o=t;if(r==="text")return((s=Un.convertTo)==null?void 0:s.call(Un,n,t,e,"text",i))||"";if(r==="markdown"){let d=((l=Un.convertTo)==null?void 0:l.call(Un,n,t,e,"markdown",i))||"";o.checkbox==="checked"?d=`[x] ${d}`:o.checkbox==="unchecked"&&(d=`[ ] ${d}`),o.ordered?d=`${o.start}. ${d}`:d=`- ${d}`;const h=o.level||0;return d=(h>0?" ".repeat(h-1):"")+d,gk(n,t,e,i)&&(d=`${d}`),pk(n,t,e,i)&&(d=`${d}`,h<=1&&(d+=`
|
|
603
603
|
`)),d}if(r==="html"){let d=((c=Un.convertTo)==null?void 0:c.call(Un,n,t,e,"html",i))||"";d=d.replace("<p>","").replace("</p>",""),o.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:o.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul",C="";if(o.ordered)switch(d=`<li value="${o.start}">${d}</li>`,h="ol",o.level){case 2:case 5:case 8:C="list-style-type: lower-alpha;";break;case 3:case 6:C="list-style-type: lower-roman;";break}else d=`<li>${d}</li>`;return gk(n,t,e,i)&&(d=`<${h}${C?` style="${C}"`:""}>${d}`),pk(n,t,e,i)&&(d=`${d}</${h}>`),d}return""}function Ck(n){const t=B("label",["editor-check-list-wrapper"],null);n&&z(t,"editor-check-list-wrapper-checked");const e=B("span",["editor-check-box"],t);return B("span",["editor-check-box-inner"],e),t}function NK(n,t){const e=Qa(t);if(e!=="text-only"){if(e==="checked"){n.append(Ck(!0));return}if(e==="unchecked"){n.append(Ck(!1));return}n.innerText=UK(t)}}function PK(n){const t=B("div",["list-container"],null),e=B("button",["list-marker"],t);return NK(e,n),t}function Ja(n,t){Ue(t);const e=n.getBlockData(t),r={id:tt(),type:"text",text:e.text};e.heading&&(r.heading=e.heading),e.heading&&(r.heading=e.heading);const i=new T0(n,t),o=it(t),s=Bt(t);n.deleteBlock(t);const l=dh(r.id,0);if(lu(n,o)&&!Xt(o)){const c=we(o);n.insertBlock(ut(o),s,r,l),n.deleteBlock(c)}else n.insertBlock(ut(o),s,r,l);i.fix()}function FK(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Kt(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:(Ja(n,t),!0)}function Ek(n){let t=Zt(n);if(!t)return null;const e=ul(n);for(;t!==e;){if(p(Se,t,"no next block"),Kt(t))return sn(t)>sn(n)?t:null;if(t=Zt(t),!t)return null}return null}function jC(n){const t=[];let e=Ek(n);if(!e)return t;for(;e;){const r=ul(e);t.push({block:e,children:jC(e)}),e=r}return t}function KK(n){const t=(r,i)=>{i.push(r.block),r.children.forEach(o=>t(o,i))},e=[];return n.forEach(r=>t(r,e)),e}function Ak(n,t){return sn(t)!==1}function xk(n,t,e){t.forEach(r=>{const i=n.getBlockData(r.block);n.updateBlockData(r.block,{...i,groupId:e,level:(i.level||1)-1}),r.children.length&&xk(n,r.children,i.groupId)})}function zC(n,t){if(!Ak(n,t))return!1;const e=sn(t);if(e===1)return!1;let r=tt(),i=1,o=Zn(t);const s=e-1,l=x0(t);l&&(r=Wa(l),i=tr(l)+1,o!=="text-only"&&(o=Zn(l)));const c=jC(t),d=n.getBlockData(t),h={...d,groupId:r,level:s,start:i,...MC(o)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),xk(n,c,d.groupId),n.doc.endBatchUpdate(),new fl(n,t).fix();const E=Ek(t);return E&&new fl(n,E,{resetStart:!0,resetGroupId:!0}).fix(),!0}const VK=I("list-block");function $K(n,t,e){p(VK,Kt(t),"not a list block");const r={...n.getBlockData(t),id:tt()};return e!=null&&e.level&&(r.level=e.level),e!=null&&e.start&&(r.start=e.start),e!=null&&e.keepText||delete r.text,(r==null?void 0:r.checkbox)==="checked"&&(r.checkbox="unchecked"),r}function HK(n){if(Ue(n),!A0(n))return n;let t=rs(n);for(;t;){if(!A0(t))return t;t=rs(t)}return null}function jK(n,t,e,r){const i=new fl(n,r),o=tr(r)+1;ka(n,t,e,{forceInsertAfter:!0,newBlockData:$K(n,r,{start:o})}),i.fix()}function zK(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Kt(l)&&dt(n,l)===0)return sn(l)===1?Ja(n,l):zC(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Kt(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const r=e.offset,o=(s=r===dt(n,t)?HK(t):t)!=null?s:t;return jK(n,t,r,o),!0}function bk(n){p(Se,Kt(n),"not a list block");const{level:t}=ns(n);let e=Ae(n);for(;e;){if(Kt(e)){const{level:r}=ns(e);if(t===r)return e;if(r<t)return null}e=Ae(e)}return null}function vk(n,t){return Ue(t),bk(t)?sn(t)<qF:!1}function GK(n,t,e){let r=Ae(t);p(Se,r,"no prev brother");const i=sn(e);for(;r;){if(r===e)return null;if(Kt(r)&&sn(r)===i+1)return r;r=Ae(r)}return null}function Bk(n,t){if(!vk(n,t))return!1;Ue(t);const e=bk(t);p(Se,e,"no list prev brother");const r=e,i=GK(n,t,r),o=sn(r)+1;let s=tt(),l=1,c=Zn(t);i&&(s=Wa(i),l=tr(i)+1,c=Zn(i));const d=jC(t),C={...n.getBlockData(t),groupId:s,level:o,start:l,...MC(c)};return n.updateBlockData(t,C),n.doc.beginBatchUpdate(),KK(d).forEach(x=>{const v=n.getBlockData(x);n.updateBlockData(x,{...v,level:(v.level||1)+1})}),n.doc.endBatchUpdate(),!0}function WK(n,t,e){return t.length===0||!t.every(r=>Kt(r.block))?!1:e==="increase"?vk(n,t[0].block):Ak(n,t[0].block)}function Tk(n,t,e){if(!WK(n,t,e))return!1;const r=t[0].block,i=sn(r),o=t.filter(d=>sn(d.block)<=i),s=lk(r,{withSelf:!1}),l=new Set(o.map(d=>d.block)),c=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;c.length>0&&(d=new fl(n,c[0])),o.forEach(h=>{e==="increase"?Bk(n,h.block):zC(n,h.block)}),d==null||d.fix()}),!0}function qK(n,t){return Bk(n,t)}function XK(n,t){return zC(n,t)}function YK(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return Tk(n,t,"increase"),!0;const e=t[0].block;if(!Kt(e))return!1;const r=new T0(n,e);return qK(n,e)&&(r.fix(),new fl(n,e).fix()),!0}function QK(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return Tk(n,t,"decrease"),!0;const e=t[0].block;return Kt(e)?(XK(n,e),!0):!1}class JK{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0||!r.some(o=>Kt(o.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||!Kt(e.block)||si(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>zK(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>FK(this.editor))}handleTab(t){return si(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>QK(this.editor)):this.editor.undoManager.runInGroup(()=>YK(this.editor))}}class ZK{constructor(t){m(this,"effectedBlockIds",new Map);m(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(i=>{const o=i.block;Kt(o)&&e.add(o)});const r=new Map;Array.from(e.values()).forEach(i=>{var c;const o=Ju(i),{start:s}=ns(o);r.set(lt(o),s);const l=(c=tK(i))!=null?c:i;r.set(lt(l),s)}),this.effectedBlockIds=r});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const r=this.editor.findBlockById(t);!r||KC(this.editor,r,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 tV=I("customize-list-start-menu");class eV{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const r=e.querySelector("div.list-container");p(tV,r,"list-block mark does not exist"),this.block=e,this.popup.manualShow(r,{theme:"light"})});m(this,"createDialogContent",()=>{const t=B("div",["customize-start-panel"],null);B("span",["customize-start-panel-title"],t,D.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const r=B("button",["customize-start-panel-button"],t,D.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(r,"click",this.handleOk),t});m(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,r=e.querySelector("button.customize-start-panel-button"),i=e.querySelector("input.customize-start-panel-input"),o=tr(t);!r||!i||requestAnimationFrame(()=>{i.focus(),i.value=String(o)})});m(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),r=this.block;if(!r)return;const i=Number(e.value);!i||(this.editor.undoManager.runInGroup(()=>{Ya(this.editor,[r,...qa(r)],i,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const r=e;r.isComposing||(r.key==="Escape"?this.popup.close("cancelBar"):r.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new Nu(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=B("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const i=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),o=parseInt(i,10);o<=0||Number.isNaN(o)?t.value="":t.value=i};return this.editor.domEvents.addEventListener(t,"input",e),t}}function nV(n,t){return Wa(n)===Wa(t)}function rV(n,t){const e=ok(t);return e?nV(e,t)?tr(e)!==tr(t)-1:!0:!1}function iV(n,t){return rs(t)?!0:tr(t)!==1}function oV(n,t){return Ue(t),[{id:"continue-numbering",name:D.t("list.continueList"),states:rV(n,t)?[]:["disabled"]},{id:"start-new-list",name:D.t("list.restartList"),states:iV(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:D.t("list.changeNumber")}]}function sV(n,t,e){var r,i;if(Ue(t),e.id==="continue-numbering"){const o=ok(t);o&&Ya(n,[t,...qa(t)],tr(o)+1,{resetGroupId:!0,groupId:Wa(o)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{Ya(n,[t,...qa(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const o=(r=n.options.componentsOptions)==null?void 0:r.list;if((i=o==null?void 0:o.onChangeStart)!=null&&i.call(o,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new eV(n)).show(n,t)}}class lV{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const r=ca(e,"div.list-container");if(r&&this.editor.isWritable()){const i=J(r);p(Se,i,"no parent block"),Ue(i);const o=t.getBlockData(i);if(o&&o.checkbox){t.updateBlockData(i,{...o,checkbox:o.checkbox==="checked"?"unchecked":"checked"});return}if(Zn(i)==="unordered")return;this.menu.updateItems(this.getCommandItems(i)),this.menu.manualShow(r),this.activeList(r,!0)}});m(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});m(this,"handleMenuClick",(t,e)=>{var i;const r=(i=this.menu.tippyInstance)==null?void 0:i.reference;if(r){const o=J(r);o&&sV(this.editor,o,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new Qo([]),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 oV(this.editor,t)}activeList(t,e){const r=J(t);!r||(e?(z(t,"active"),z(r,"active")):(ot(t,"active"),ot(r,"active")))}}class aV{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const r=t.selection.range.getSelectedBlocks();if(r.length===0)return!1;const i=r[0].block;if(!Kt(i)||!OC(i))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const o=Hs(i);return o&&t.selection.selectBlock(o,dt(t,o)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const o=js(i);return o&&t.selection.selectBlock(o,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&fk(t,i),!0}}function cV(n,t,e,r,i){vp(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new aV(n)),n.input.addHandler(new JK(n)),n.addCustom("list-clear-selection-handler",()=>new ZK(n)),n.addCustom("list-marker-menu",()=>new lV(n))})});const o=Un.createBlockContent(n,t,e,r,i),s=i,{level:l,start:c,groupId:d}=s,h=Qa(s);r.setAttribute("data-list-level",`${l||1}`),r.setAttribute("data-list-start",`${c||1}`),r.setAttribute("data-list-group-id",`${d}`),r.setAttribute("data-list-type",h);const C=PK(s);return r.insertBefore(C,o),s.viewAsMindmap?setTimeout(()=>{const E=n.getBlockById(i.id);E&&b0(n,E,{},{mindmapTools:v0,saveData:!1})}):setTimeout(()=>{const E=n.getBlockById(i.id);E&&uk(n,E)}),o}const uV={list:{confirm:"\u786E\u5B9A",setStart:"\u8BBE\u7F6E\u7F16\u53F7",continueList:"\u7EE7\u7EED\u7F16\u53F7",restartList:"\u5F00\u59CB\u65B0\u5217\u8868",changeNumber:"\u4FEE\u6539\u7F16\u53F7\u503C",numberLabel:"\u7F16\u53F7\u987A\u5E8F",mention:{tooltip:"\u63D0\u53CA\u4EBA\u5458\u5E76\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u663E\u793A\u4E3A\u8111\u56FE",autoFit:"\u81EA\u52A8\u7F29\u653E",fullScreen:"\u5168\u5C4F\u67E5\u770B",close:"\u5173\u95ED",exitFullscreen:"\u9000\u51FA\u5168\u5C4F"}},fV={list:{confirm:"Confirm",setStart:"Set number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"Mention and notify users"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto zoom",fullScreen:"Full screen",close:"Close",exitFullscreen:"Exit full screen"}},dV={list:{confirm:"OK",setStart:"\u756A\u53F7\u3092\u8A2D\u5B9A",continueList:"\u9023\u756A\u3092\u8A2D\u5B9A",restartList:"\u65B0\u3057\u3044\u30EA\u30B9\u30C8\u3092\u4F5C\u6210",changeNumber:"\u756A\u53F7\u3092\u7DE8\u96C6",numberLabel:"\u756A\u53F7",mention:{tooltip:"\u30E1\u30F3\u30B7\u30E7\u30F3\u304A\u3088\u3073\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7\u3067\u8868\u793A",autoFit:"\u81EA\u52D5\u30D5\u30A3\u30C3\u30C8",fullScreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30F3",close:"\u9589\u3058\u308B",exitFullscreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30D5"}};D.mergeLang({"zh-CN":uV,"en-US":fV,"ja-JP":dV});const oct="",yk={...Un,blockType:"list",createBlockContent:cV,convertFrom:MK,convertTo:OK,handleDrop:BK,notify:xK},GC=I("paragraph");class hV{constructor(t){m(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){const r=[],i={"unordered-list":[D.t("commands.unordered"),ze("CtrlOrCmd+Shift+U"),A2],"ordered-list":[D.t("commands.ordered"),ze("CtrlOrCmd+Shift+L"),E2],"check-list":[D.t("commands.check"),void 0,x2],link:[D.t("commands.link"),ze("CtrlOrCmd+K"),Jp],quoted:[D.t("commands.quote"),void 0,b2]};if(nt(t,e)){const o=lt(e),s=Dt(e),l=Ir(t,e),c=t.getBlockData(e);Object.entries(i).forEach(([d,[h,C,E]])=>{const x=[];if(this.isChecked(c,d)&&x.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&x.push("disabled")}r.push({blockId:o,blockType:s,blockKind:l,id:d,name:h,desc:C,states:x,icon:E,groupIndex:600})})}return r}convertLink(t,e,r){p(GC,ci(e.start),""),p(GC,ci(e.start),"");const i="bottom-start",o=e.start.offset,s=e.end.offset,l=(x,v)=>{t.undoManager.runInGroup(()=>{try{const R=t.selection.range.isCollapsed();let L;if(R){L=Yi(t.getBlockText(r),s,x,{link:v}),t.setBlockText(r,L);return}L=ch(t.getBlockText(r),o,s,x),L=du(o,x.length,L,"link",v),t.setBlockText(r,L),t.selection.selectBlock(r,o+x.length),t.focus()}catch(R){GC.error(R)}})},c=()=>{t.selection.selectBlock(r,s),t.focus()},d=ji(t,r,e)[0];if(!d)return;const h=Wi(t,r,"link-button-anchor",d),C=t.getBlockText(r),E=xa(C,o);Yu(t,{target:h,linkText:t.getSelectedText(),linkUrl:(E==null?void 0:E.link)||"",onFinished:l,onClose:c,placement:i})}convertToList(t,e,r){const i=Gd(t,e,"list",{offset:0,data:{listType:r}});i&&t.undoManager.runInGroup(()=>{const o=Bt(e),s=it(e);t.insertBlock(ut(s),o,i.blockData),t.deleteBlock(e)})}executeCommand(t,e,r,i){var c;if(!nt(t,e))return!1;const o=i.id,s=(c=i.states)==null?void 0:c.includes("checked");let l=!1;if(o==="unordered-list"&&(s?Ja(t,e):this.convertToList(t,e,"unordered"),l=!0),o==="ordered-list"&&(s?Ja(t,e):this.convertToList(t,e,"ordered"),l=!0),o==="check-list"&&(s?Ja(t,e):this.convertToList(t,e,"unchecked"),l=!0),o==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),l=!0}if(o==="link"){const d=p0(t);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},1e3),this.convertLink(t,r,e),l=!0}return l}}const mV={left:Na,right:e0,center:n0};class gV{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,r){Object.keys(mV).includes(r)?t.updateBlockData(e,{align:r}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,r){if(nt(t,e)){const i=lt(e),o=Dt(e),s=Ir(t,e),l=t.getBlockData(e),c=d=>{var C;const h=B("span",["toolbar-item-name-container"],null);for(const E of d.children)if((C=E.states)!=null&&C.includes("checked"))return h.innerHTML=E.icon||Na,h;return h.innerHTML=Na,h};return[{id:"align",name:D.t("commands.alignGroup"),blockId:i,blockType:o,blockKind:s,groupIndex:700,dropdown:!0,element:c,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:D.t("commands.alignLeft"),icon:Na,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:D.t("commands.alignCenter"),icon:n0,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:D.t("commands.alignRight"),icon:e0,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,r,i){if(!nt(t,e))return!1;if(i.id.startsWith("align")){const o=i.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,o),!0}return!1}}function kk(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const r=n.getBlockById(e.start.blockId);return pu(n,r,e.start.offset).charType==="box"}const pV=I("toolbar-handler"),CV={id:"",name:"",type:"separator"};class Za{constructor(t){m(this,"toolbar");m(this,"toolbarType","object");m(this,"mouseDown",!1);m(this,"oldRange",null);m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"_disableTextToolbar",!1);m(this,"isInToolbar",t=>this.toolbar.isInCommandBar(t.target));m(this,"handleButtonClick",(t,e)=>{const r=this.editor.getCustom("editor-tooltip");r.lastClickButtonId=e.id,this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.editor.isWritable()&&this.showTextToolbar("click")):this.hoveringBlock&&zF(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});m(this,"handleClose",()=>{aC(this.editor)&&this.editor.focus()});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const r=Pb(e);if(this.hoveringBlock===r)return!1}return!0});m(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});m(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});m(this,"handleHoveringBlockChildChange",(t,e,r,i)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close("fromHover");return}this.showObjectToolbar(i)}});m(this,"handleSelectionChange",Me.default(t=>{var r;if(p(pV,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const i=(r=this.toolbar.tippyInstance)==null?void 0:r.reference,o=this.editor.selection.focusedBlock;if(i&&re(i,o))return}this.toolbar.close("selectionChange"),this.oldRange=null;return}if(!this.editor.isWritable()){this.toolbar.close("selectionChange"),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close("selectionChange"),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new Pu([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0,padding:20}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.toolbar.on("closing",this.handleClosing),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),Te.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Te.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new WF(t)),t.editorCommandProviders.registerCommandProvider(new hV(t)),t.editorCommandProviders.registerCommandProvider(new gV(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close("selectionChange")}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),Te.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&re(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){!this.editor.isWritable()||this.showTextToolbar(t)}showTextToolbar(t){var R,L;if(this._disableTextToolbar)return;const e=this.editor.selection.range,r=e.getSelectedBlocks();if(r.length===0)return;const i=r[0];if(!i)return;if(r.length===1){if(ge(i.block)){t==="click"&&this.showObjectToolbar(null);return}if(Mt(this.editor,i.block)&&e.isSimple())return}if(kk(this.editor))return;if($i(i.block)){this.toolbar.close("selectionChange");return}const o=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;o.forEach(M=>{const U=M.groupIndex,F=s.get(U);F?F.push(M):s.set(U,[M])});const l=[[]],c=Array.from(s.entries()).sort((M,U)=>M[0]-U[0]);for(let M=0;M<c.length;M++){const[,U]=c[M];if(U.length===0)continue;let F=l[l.length-1];F.length>0&&F[F.length-1].groupIndex!==U[U.length-1].groupIndex&&(F=[],l.push(F)),F.push(...g0(U))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((M,U)=>{const F=M.sort((G,W)=>{var rt,st;return((rt=G.order)!=null?rt:0)-((st=W.order)!=null?st:0)});d.push(...F),U!==l.length-1&&d.push(CV)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=r[r.length-1],C=!this.editor.selection.range.isReverse()&&h!==i,E=C?h:i,x=ek(this.editor,E),v=Wi(this.editor,E.block,"editor-quick-menu",x);this.toolbar.manualShow(v,{placement:C?"bottom":"top",offset:[0,C?5:10]}),(L=(R=this.toolbar.tippyInstance)==null?void 0:R.popperInstance)==null||L.update()}showObjectToolbar(t){var l,c,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,r=this.hoveringTextChild,{commands:i,element:o}=$F(this.editor,e,r);if(!i.length||!o){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((c=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:c.reference)!==o&&this.toolbar.close("fromHover");const s=()=>{let h;const C=o.getClientRects(),E=[];if(Array.from(C).forEach(x=>{const{y:v}=x;E.includes(v)||E.push(v)}),E.length>1){if(h=r?C[C.length-1]:C[0],t)for(let x=0;x<C.length;x++){const v=C[x],R=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(R.x<t.clientX&&t.clientX<R.right&&R.y<t.clientY&&t.clientY<R.bottom){h=v;break}}}else{if(h=o.getBoundingClientRect(),r){const x=r.getBoundingClientRect();return new DOMRect(x.x,x.y,x.width,x.height)}return new DOMRect(C[0].x,C[0].y,C[0].width,C[0].height)}if(t){const x=h.y,v=t.clientX;return new DOMRect(v,x,10,h.height)}return h};this.toolbar.updateItems(i),this.toolbar.isVisible||(this.toolbar.manualShow(o,{placement:r?"bottom":"top",getReferenceClientRect:s}),(d=this.toolbar.tippyInstance)!=null&&d.popper&&(this.toolbar.tippyInstance.popper.style.paddingTop="10px",this.toolbar.tippyInstance.popper.style.paddingBottom="5px"))}static register(t){return t.addCustom("toolbar-handler",e=>new Za(e))}static get(t){return t.getCustom("toolbar-handler")}}function R0(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function Rk(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function WC(n,t){const r=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:r?void 0:!0})}function qC(n,t){return!!(n[t]||n.level&&(n.ordered===!0&&!n.checkbox&&t==="ordered-list"||n.ordered===!1&&!n.checkbox&&t==="unordered-list")||t==="check-list"&&n.checkbox)}function XC(n,t,e){if(!n.selection.range.focus.isSimple())return;const i=n.getBlockData(t);let o;switch(e){case"unordered-list":o=qC(i,"unordered-list")?void 0:"unordered";break;case"ordered-list":o=qC(i,"ordered-list")?void 0:"ordered";break;case"check-list":o=qC(i,"check-list")?void 0:"unchecked";break}if(o){const s=Gd(n,t,"list",{offset:0,data:{listType:o}});s&&n.undoManager.runInGroup(()=>{const l=Bt(t),c=it(t);n.deleteBlock(t);const d=n.insertBlock(ut(c),l,s.blockData);s.onConverted&&s.onConverted(n,d)})}else Ja(n,t)}const EV=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:R0,applyAlignStyle:Rk,applyQuoteStyle:WC,applyList:XC},Symbol.toStringTag,{value:"Module"})),AV=[Wh,qh,Xh,Yh,Qh,Jh,Zh,t0],xV={Unordered:eC,Ordered:nC,Checkbox:Zp,Quote:tC};function wk(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(r=>wk(r,t))}function bV(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:Pa,name:D.t("commands.text"),order:0,group:"basics",value:"text"}]}}function YC(n=1){var i;const t={name:"basic",insertBlockCommandItems:[]};let e=C0();e<=4?e=5:e<8&&(e+=1);let r=n;for(;r<=e;){const o=`heading-${r}`;(i=t.insertBlockCommandItems)==null||i.push({id:o,icon:AV[r-1],name:D.t("quickMenu.basic.heading.title",{heading:String(r)}),order:r,group:"basics",value:String(r),subText:Tn(o)}),r++}return t}function vV(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,r)=>{var o;const i=`insert-${e.toLocaleLowerCase()}`;(o=n.insertBlockCommandItems)==null||o.push({id:i,name:D.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:xV[e],value:e.toLocaleLowerCase(),group:"basics",order:10+r,subText:Tn(i)})}),n}class Sk{constructor(t){this.withPlainText=t}getCommands(){const t=bV(),e=YC(),r=vV();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...r.insertBlockCommandItems||[]]}updateBlock(t,e,r,i){const{value:o,id:s}=i;return s.startsWith("heading-")?R0(t,r,Number.parseInt(o!=null?o:"1",10)||1):o==="ordered"||o==="unordered"||o==="checkbox"?XC(t,r,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[o]):o==="quote"&&WC(t,r),null}async handleUpdateBlockCore(t,e){const r=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,r,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:r,blockIndex:i}=e,o=t.insertTextBlock(void 0,r,i);return this.updateBlock(t,e.containerId,o,e.item)}async executeCommand(t,e,r){if(r.from==="quick-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=ut(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else r.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex})),t.focus());return null}}const Lk={basics:100,system:200,common:300,thirdParty:400};class QC{constructor(){m(this,"dataUrl","");m(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const BV=I("mathjax-converter"),TV="MathJax-script",yV=30,Ik=8;async function kV(n){var r;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((r=t==null?void 0:t.cdn)==null?void 0:r.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await Us(e,TV)}function RV(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function JC(n,t){const e="mathjax2Svg";try{await wr.lock(e),RV(),await kV(n);const r=await window.MathJax.tex2svgPromise(t),i=r.querySelector("merror");if(i)throw new Error(i.textContent);return r.querySelector("svg").outerHTML}catch(r){throw BV.error(r),r}finally{wr.release(e)}}function wV(n){const t=new DOMParser().parseFromString(n,"image/svg+xml"),e={width:0,height:0};if(t&&t.firstChild){const r=t.firstChild,i=r.getAttribute("height"),o=r.style.minWidth;i&&(e.width=parseInt(o,10)*Ik+yV,e.height=parseInt(i,10)*Ik)}return e}async function Dk(n,t){const e=await JC(n,t);return e?await Ng(e,"image/svg+xml"):""}async function _k(n,t){const r=await JC(n,t),i=new File([r],"math.svg");return(await n.doc.uploadResource(i)).resourceId}async function SV(n,t){const e=await JC(n,t),r=wV(e),i=e,o=new File([i],"math.svg");return{resourceId:(await n.doc.uploadResource(o)).resourceId,...r}}const Mk=I("edit-mathjax");class LV{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"observer",null);m(this,"handleClose",t=>{var r;const e=t.content.querySelector("textarea");if(e){const i=e.value;i!==this.tex&&((r=this.onChange)==null||r.call(this,i,!0))}});m(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close("cancelBar")),this.handleChange(t.target.value))});m(this,"handleChange",Me.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,r,i){if(!this.editMathjaxPopup)this.editMathjaxPopup=new Nu(this.createPopupContent(e),{id:"mathjax-popover"});else{const o=this.getTextarea();o.value=e}this.tex=e,this.editMathjaxPopup.manualShow(t,{theme:"light",placement:i==null?void 0:i.placement}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=r}createPopupContent(t){const e=B("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),this.textareaWatcher(e),e}textareaWatcher(t){const e=t;e.onblur=()=>{var i;(i=this.editMathjaxPopup)!=null&&i.isVisible&&t.focus()};const r=()=>{setTimeout(()=>{t.focus()})};this.observer=new IntersectionObserver(r,{}),this.observer.observe(t)}getTextarea(){p(Mk,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return p(Mk,t,"no textarea"),t}destroy(){var t,e;this.onChange=null,(t=this.observer)==null||t.disconnect(),(e=this.editMathjaxPopup)==null||e.removeAllListeners()}}function Uk(n,t,e,r,i){n.addCustom("mathjax-editor",()=>new LV).editMathjax(t,e.trim(),r,i)}function Ok(){return{insert:" ",attributes:{id:tt(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function w0(n,t){const e=n.getBoxData(t),r=J(t);if(!r)return;const i=Ys(r,t);n.selection.selectBlock(r,i.start,i.end);const o=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await wr.lock("convertAndUploadMathjax");const c=await _k(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new QC).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{wr.release("convertAndUploadMathjax"),l&&n.focus()}};Uk(n,t,e.tex,o)}const Nk=I("mathjax-box");function ZC(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,ZC)}async function IV(n,t,e){try{if(!t.tex.trim())return;const r=await Dk(n,t.tex),i=n.findBoxById(t.id);if(!i)return;const o=Xg(i);o.innerHTML="";const s=B("img",["mathjax"],o);s.src=r,e.setDataUrl(r),n.domEvents.addEventListener(s,"load",ZC)}catch(r){e.setError(r);const i=n.findBoxById(t.id);if(!i)return;const o=i.querySelector(".mathjax-tex-text");z(o,"mathjax-error"),o.innerText=r.message,n.selection.updateSelection(null)}}function DV(n,t,e,r){const i=r,o=n.addCustom(`mathjax-box-${i.id}`,()=>new QC);if(i.src||o.dataUrl){const c=B("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(i.src||o.dataUrl,{syncNewResources:async(d,h)=>{var E,x;await n.doc.addResources([d]);const C=(x=(E=n.doc).getServerMeta)==null?void 0:x.call(E).appId;if(i.src&&i.src!==h&&C&&i.src.includes(C)){const v=J(e),R=mt.default(i);v&&n.isBlockWritable(v)&&!n.readonly&&(R.src=d,n.updateBoxData(R))}}}),n.domEvents.addEventListener(c,"load",ZC);return}const s=["mathjax-tex-text"];let l=i.tex;l.trim()?o.error&&(l=o.error.message,s.push("mathjax-error")):l=D.t("mathjax.emptyText"),B("span",s,e,l),IV(n,i,o)}function _V(n,t){const e={id:tt(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return _k(n,t).then(r=>{if(!n.findBoxById(e.id))return;const o={...e,src:r};n.updateBoxData(o)}).catch(r=>{Nk.error(`failed to convert and upload mathjax: ${JSON.stringify(r)}`)}),e}function MV(n,t,e,r){const i=t;return r==="text"?i.tex:r==="markdown"?` $${i.tex}$ `:i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:`<code>$${i.tex}$</code>`}function UV(n,t,e){const r=J(t);p(Nk,r,"failed to get block"),!(n.readonly||!n.isBlockWritable(r))&&w0(n,t)}function OV(){return{abstract:D.t("mathjax.abstract")}}const Pk={boxType:"math",updateBoxContent:DV,convertFrom:_V,convertTo:MV,handleClickBox:UV,getBoxProperties:OV};async function NV(n,t,e){try{const r=t.embedData,i=await Dk(n,r.mathjaxText),o=n.findBlockById(t.id);if(!o)return;const s=Ot(o);s.innerHTML="";const l=B("img",["mathjax"],s);l.src=i,e.setDataUrl(i)}catch(r){e.setError(r)}}function PV(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=J(t.target);if(!e||!ge(e)||We(e)!=="math")return;const r=Ot(e),i=r.querySelector("img")||r.querySelector("span.mathjax-tex-text");if(!i||!re(i,t.target))return;const s=n.getBlockData(e).embedData;Uk(n,i,s.mathjaxText,async l=>{const{resourceId:c,width:d,height:h}=await SV(n,l),C={mathjaxText:l,src:c,width:d,height:h};n.updateEmbedData(e,C)},{placement:"bottom"})}function FV(n,t,e){const r=e.embedData,{src:i,width:o}=r,s=n.addCustom(`mathjax-block-${e.id}`,()=>new QC);if(n.domEvents.addEventListener(t,"click",PV),!r.mathjaxText.trim()){B("span",["mathjax-tex-text"],t,D.t("mathjax.emptyText"));return}if(i||s.dataUrl){const l=B("img",["mathjax"],t);l.src=n.doc.buildResourceUrl(i||s.dataUrl,{syncNewResources:async(c,d)=>{var h,C;if(i){await n.doc.addResources([c]);const E=(C=(h=n.doc).getServerMeta)==null?void 0:C.call(h).appId;if(i&&d!==i&&E&&i.includes(E)){const x=J(t);setTimeout(()=>{if(x&&!n.readonly&&n.isBlockWritable(x)){const v=mt.default(e);v.embedData.src=c,n.updateBlockData(x,v)}})}}}}),o&&(l.style.minWidth=`${o}px`,setTimeout(()=>{const c=t.getBoundingClientRect().width;o>c?(z(t,"mathjax-overflow"),t.style.overflow="auto",t.style.setProperty("--mathjax-width",`${o}px`)):(ot(t,"mathjax-overflow"),t.removeAttribute("data-mathjax-width"),t.style.removeProperty("--mathjax-width"))}));return}s.error,B("span",["mathjax-tex-text"],t,r.mathjaxText),NV(n,e,s)}function KV(n,t,e){if(!nt(n,t))return null;const r=n.getBlockString(t).trim();if(!r||!r.startsWith("$$")||!r.endsWith("$$"))return null;const i=Dg(r,"$");if(!i)return null;const o={mathjaxText:i,src:""};return{blockData:{id:tt(),type:"embed",embedType:"math",embedData:o}}}function VV(n){return{name:"Mathjax"}}function $V(n,t){var r;const e=Ot(t);n.domEvents.removeAllListeners(e),n.findCustom("mathjax-editor")&&((r=n.getCustom("mathjax-editor").editMathjaxPopup)==null||r.close("cancelBar"))}function HV(n,t,e,r){const i=t.embedData;return r==="html"?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:r==="markdown"?`
|
|
604
604
|
$$${i.mathjaxText}$$
|
|
605
|
-
`:i.mathjaxText}function jV(){return{abstract:D.t("mathjax.abstract")}}const zV={embedType:"math",createEmbedContent:FV,getOptions:VV,convertFrom:KV,handleDeleteBlock:$V,convertTo:HV,getBlockProperties:jV},sct="",GV={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},WV={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},qV={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};D.mergeLang({"zh-CN":GV,"en-US":WV,"ja-JP":qV});function XV(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r);if(!fe(s).endsWith("$$$$"))return!1;const c=r-4,d=r,h={id:tt(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c),n.insertBoxToBlock(i,c,h),setTimeout(()=>{const C=n.getBoxById(h.id);w0(n,C)})}),!0}class YV{handleAfterInsertText(t,e,r,i,o){return!!(o===" "&&XV(t,e,r,i))}}const dl=I("inline-box-items");function QV(n,t,e){return n.undoManager.runInGroup(()=>{var s;let r=n.findBlockByIndex(t,e);(!r||!ue(n,r))&&(r=n.insertTextBlock([],t,e));const i=Ok();n.setBlockText(r,[i]);const o=(s=i.attributes)==null?void 0:s.id;return p(dl,o,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(o);w0(n,l)},100),r})}function JV(n,t,e){let r=n.findBlockByIndex(t,e),i="bottom-start";return(!r||!ue(n,r))&&(i="top-start",r=n.insertTextBlock([],t,e)),Yu(n,{target:r,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{p(dl,r,"block not found"),ue(n,r)||(r=n.insertTextBlock([],t,e));const d=mr(l,{link:c}),h=mr(" ",null),C=[d,h];n.insertTextToBlock(r,0,C),n.selection.selectBlock(r,dn(C)),n.focus()}catch(d){dl.error(d)}})},onClose:()=>{n.focus()},placement:i}),r}function ZV(n,t,e){return n.undoManager.runInGroup(()=>{var l;const r=n.getBlockByIndex(t,e),i=n.selection.range;p(dl,ci(i.start),"invalid block position");const o=Ok();n.insertBoxToBlock(r,i.start.offset,o.attributes);const s=(l=o.attributes)==null?void 0:l.id;return p(dl,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);w0(n,c)},100),r})}function t$(n,t,e){const r=n.getBlockByIndex(t,e),i=n.selection.range;p(dl,ci(i.start),"invalid block position");const o=ji(n,r,i);if(o.length===0)return;const s=o[0],l=Wi(n,r,"quick-menu-inline-link",s);Yu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,C)=>{n.undoManager.runInGroup(()=>{try{const E=n.getBlockText(r),x=Yi(E,i.start.offset,h,{link:C});n.setBlockText(r,x),n.selection.selectBlock(r,i.start.offset+h.length),n.focus()}catch(E){dl.error(E)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class Fk{getCommands(){return[{id:"insert-math",name:D.t("quickMenu.inlineBox.math"),icon:R2,order:900,group:"common",subText:Tn("insert-math")},{id:"insert-link",name:D.t("quickMenu.inlineBox.link"),icon:Jp,order:400,group:"common",subText:Tn("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return ZV(t,e.containerId,e.blockIndex);case"insert-link":return t$(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return QV(t,e.containerId,e.blockIndex);case"insert-link":return JV(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,r){if(r.from==="quick-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=ut(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else r.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex}));return null}}function e$(n,t={withPlainText:!1}){var o,s;const{withPlainText:e}=t,r=(s=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:s.commandProviders;if(!r)return[];const i=[];return[...r,new Sk(e),new Fk].forEach(l=>{const c=l.getCommands(n);i.push(...c.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),i}function n$(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(r=>{if(!r.getOptions)return;const i=r.getOptions(n);!i.insertBlockCommandItems||(i.insertBlockCommandItems.forEach(o=>{wk(o,i)}),e.push(...i.insertBlockCommandItems))}),e.push(...e$(n,t)),e}function tE(n,t={withPlainText:!1}){const e=n$(n,t),r=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let c=r.get(l);c?c.items.push(s):(c={group:l,order:s.groupOrder||Lk[l]||1e3,items:[s]},r.set(l,c))});const i=Array.from(r.values());i.sort((s,l)=>s.order-l.order),i.forEach(s=>{s.items.sort((l,c)=>{var d,h;return((d=l.order)!=null?d:0)-((h=c.order)!=null?h:0)})});const o=[];return i.forEach((s,l)=>{const c=`blockMenu.section.${s.group||"common"}`,d=D.t(c),h=d===c?s.group:d;o.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),o.push(...s.items.map(C=>({...C})))}),o}function r$(n,t,e){const r=n.getFocusedBlock();if(!r)return;const i=n.getParentContainer(r),o=ut(i);let l=n.getBlockIndex(r);if(ue(n,r)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:o,blockIndex:l,item:t})}const Kk=I("quick-menu"),i$={id:"quick-menu",trigger:["/"]},o$=5;class S0{constructor(t,e=i$){m(this,"suggest");m(this,"items");m(this,"maxHeading");m(this,"firstEmptyOffset",-1);m(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const r=new Set,i=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,""),o=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(i)!==-1||yP(s).toLocaleLowerCase().indexOf(i)!==-1)return r.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,c=D.t(l),d=c===l?s.group:c;return(d==null?void 0:d.toLocaleLowerCase().indexOf(i))!==-1?(r.add(s.group),!0):!1}).filter(s=>s.type==="section"?r.has(s.group):!0);return o.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),o}return this.items});m(this,"onClose",()=>{this.firstEmptyOffset=-1});m(this,"onShow",(t,e,r,i)=>{const o=this.editor.getBlockByIndex(e,r);if(!dr(o)){const s=J(it(o));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e)=>{const r=e;r.itemType==="insert-block"&&(p(Kk,r.blockOptions||r.commandProvider,"invalid quick item, no block options or command provider"),p(Kk,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),r$(this.editor,r,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=C0(),this.suggest=new uC(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=tE(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const r=C0();if(r!==this.maxHeading){const i=new Sk,s=i.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:i}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=r}}handleEmptySearch(){const t=this.editor.selection.getFocusedPos();if(this.firstEmptyOffset===-1){if(t.isSimple()){const{offset:e}=t;this.firstEmptyOffset=e-1}}else if(t.isSimple()){const{offset:e}=t;e-this.firstEmptyOffset>o$&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class L0{constructor(t){m(this,"instance");m(this,"mousedown",!1);m(this,"currentInstance",null);m(this,"attributeName",[]);m(this,"attributeDesc","");m(this,"_lastClickButtonId","");m(this,"observer",null);m(this,"observerCallback",null);m(this,"createContent",t=>{let e="",r=0;for(;r<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[r])&&(e=t.getAttribute(this.attributeName[r])||""),r++;const i=t.getAttribute(this.attributeDesc);if(!i)return e;const o=B("div",[],null);return B("span",[],o,e),i&&B("span",["editor-tooltip-desc"],o,i),o});m(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});m(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});m(this,"handleShow",t=>{var i;const e=t.reference;if(!e||!re(document.body,e)||window.isDragging||this.mousedown)return!1;const r=Number.parseInt((i=e.getAttribute("data-tooltip-hide-at"))!=null?i:"",10);if(r&&Date.now()-r<1e3)return!1;if(this._lastClickButtonId===e.getAttribute("data-button-id"))return this._lastClickButtonId="",!1;if(t.reference){const o={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(o.placement=t.reference.getAttribute("data-editor-tooltip-placement")||"top"),t.reference.hasAttribute("data-editor-tooltip-offset-x")||t.reference.hasAttribute("data-editor-tooltip-offset-y")){const l=t.reference.getAttribute("data-editor-tooltip-offset-x"),c=t.reference.getAttribute("data-editor-tooltip-offset-y");o.offset=[l?Number.parseInt(l,10):0,c?Number.parseInt(c,10):0]}t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(o.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(o.allowHTML=!0);const s=document.body;if(o.appendTo=this.fixContainerForFullscreen(s),Object.keys(o).length&&t.setProps(o),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const l=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(l||"")}}return!0});this.editor=t;const e=t.clientId;this.attributeName=[`data-editor-tooltip-${e}`,`data-editor-tooltip-${e}-dynamic`,"data-editor-tooltip-common"],this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=Eg.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(r=>`[${r}]`).join(","),content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden,hideOnClick:!1}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}set lastClickButtonId(t){this._lastClickButtonId=t,t&&setTimeout(()=>{this._lastClickButtonId===t&&(this._lastClickButtonId="")},500)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Me.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,r={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,r)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}fixContainerForFullscreen(t){return t.closest("body")&&document.fullscreenElement&&!document.fullscreenElement.contains(t)?document.fullscreenElement:t}}const s$={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-sub":"subscript","text/style-super":"superscript",link:"link"};function l$(n,t){const e=new Set(Object.keys(s$)),r=t.filter(o=>e.has(o.id));return g0(r)}function Zu(n,t){if(!n.isWritable())return!1;const e=n.selection.range,r=n.editorCommandProviders.getCommands(e),o=l$(n,r).find(s=>s.id===`text/${t}`||s.id==="link");return o?(n.editorCommandProviders.executeCommand(e,o,{}),Za.get(n).update("selectionChange"),!0):!1}function a$(n,t){const e=n.selection.focusedBlock;if(!n.isWritable()||!nt(n,e))return!1;const r=n.getBlockData(e).heading,i={id:`heading-${t}`,source:"BlockTurnIntoCommandProvider",value:String(t)};return Number(r)===t&&(i.id="text",i.value=null),n.editorCommandProviders.executeCommand(n.selection.range,i,{}),!0}const eE={"CtrlOrCmd+B":n=>Zu(n,"style-bold"),"CtrlOrCmd+I":n=>Zu(n,"style-italic"),"CtrlOrCmd+U":n=>Zu(n,"style-underline"),"CtrlOrCmd+D":n=>Zu(n,"style-strikethrough"),"CtrlOrCmd+K":n=>Zu(n,"link"),...(()=>{const n={};for(let t=1;t<=8;t++)n[`CtrlOrCmd+${t}`]=e=>a$(e,t);return n})()},c$={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u5217\u8868",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",edit:"\u7F16\u8F91",remove:"\u53D6\u6D88\u94FE\u63A5"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"}},u$={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"To-do list",quote:"Quote"},inlineBox:{math:"Formula",link:"Link"}},link:{textLabel:"Text",urlLabel:"Link address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter link",submitText:"Confirm",cancelText:"Cancel",edit:"Edit",remove:"Remove link"},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"To-do list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Center text",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"}},f$={quickMenu:{basic:{heading:{title:"\u898B\u51FA\u3057{heading}",space:"{markdown}\u30B9\u30DA\u30FC\u30B9"},unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",checkbox:"\u30D0\u30C3\u30AF\u30ED\u30B0",quote:"\u5F15\u7528"},inlineBox:{math:"\u6570\u5F0F",link:"URL"}},link:{textLabel:"\u30C6\u30AD\u30B9\u30C8",urlLabel:"URL",textPlaceholder:"\u30C6\u30AD\u30B9\u30C8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",urlPlaceholder:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",submitText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB",edit:"\u7DE8\u96C6",remove:"\u30EA\u30F3\u30AF\u3092\u89E3\u9664"},commands:{unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",check:"\u30D0\u30C3\u30AF\u30ED\u30B0",link:"URL",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u63C3\u3048",alignRight:"\u53F3\u63C3\u3048",alignCenter:"\u4E2D\u592E\u63C3\u3048",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u898B\u51FA\u3057{name}",headingGroup:"\u30BF\u30A4\u30C8\u30EB\u30B9\u30BF\u30A4\u30EB",text:"\u672C\u6587"}};D.mergeLang({"zh-CN":c$,"en-US":u$,"ja-JP":f$});const act="";function hl(n,...t){const e=pr(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function Vk(n){const t=p0(n);t==null||t.hide();const e=n.findCustom("table-border-bar");e==null||e.closeToolbar()}function d$(n){return B("div",["insert-column-button","drop-marker"],n)}const h$=I("row-height");function $k(n){const t=It.fromTable(n),e=n.rows;p(h$,e.length===t.rowCount,"row count mismatch");const r=Array(t.rowCount).fill(0);for(let i=0;i<e.length;){let o=1,l=e[i].getBoundingClientRect().height,c=i+1;for(;c<e.length;){const d=e[c];if(d.cells.length!==0)break;o++,c++,l+=d.getBoundingClientRect().height}for(let d=0;d<o;d++)r[i+d]=l/o;i=c}return r}const m$=I("table-border-bar-dom");function Hk(n){var c;const t=J(n.contentElement);p(m$,t,"no block");const r=ie(t).querySelector(".table-border-bar-container.left"),o=Ot(t).offsetLeft-Ha,s=((c=n.scrollOptions.paddingLeft)!=null?c:0)+o,l=Math.min(n.contentElement.offsetLeft-o,n.rootElement.scrollLeft-s);r&&(r.style.left=`${-l}px`)}const is=I("table-border-bar-dom");function tc(n,t){p(is,$e(t),"invalid table block");const e=Ve(t),r=xi(n,t),i=ie(t),o=(C,E,x)=>{const v=B("div",["button-root",E],C),R=B("div",["button-container",E],v);v.setAttribute(`data-${E}-index`,`${x}`),R.setAttribute(`data-editor-tooltip-${n.clientId}`,E==="left"?D.t("table.insertRow"):D.t("table.insertCol")),B("span",["insert-indicator"],R),d$(R)},{selectedRows:s,selectedColumns:l}=dC(n,t),c=()=>{const C=r.querySelector(".table-border-bar-container.top");p(is,C,"no top border bar container");const E=B("div",["table-border-bar-container","top"],null),x=B("div",["table-border-bar","top"],E),v=vF(e),L=It.fromTable(e).colCount;n.selection.range.isSimple()&&o(x,"top",0);for(let M=0;M<L;M++){const U=M===L-1?v[M]+2:v[M],F=B("span",["table-border-bar-cell","top"],x);l.has(M)&&F.classList.add("selected"),F.setAttribute("data-top-index",`${M}`),F.style.width=`${U}px`,n.selection.range.isSimple()&&o(x,"top",M+1)}Yc(C,E)},d=()=>{const C=i.querySelector(".table-border-bar-container.left");p(is,C,"no left border bar container");const E=B("div",["table-border-bar-container","left"],null),x=B("div",["table-border-bar","left"],E);B("span",["table-border-bar-cell","corner"],x);const v=$k(e);n.selection.range.isSimple()&&o(x,"left",0),Array.from(e.rows).forEach((R,L,M)=>{const U=B("span",["table-border-bar-cell","left"],x);s.has(L)&&U.classList.add("selected"),U.setAttribute("data-left-index",`${L}`);const F=L===M.length-1?v[L]+2:v[L];U.style.height=`${F}px`,n.selection.range.isSimple()&&o(x,"left",L+1)}),Yc(C,E)};c(),d();const h=n.findCustom(Ai(t));h&&Hk(h)}function jk(n,t){const e=t.target;if(!(e instanceof Element))return;const r=J(e);p(is,r&&$e(r),"invalid table block"),tc(n,r),n.selection.caret.update()}function I0(n,t){const e=t.target;if(!(e instanceof Element))return;const r=J(e);p(is,r&&$e(r),"invalid table block");const i=e.closest(".button-root");if(i){if(i.classList.contains("top")){const o=parseInt(i.getAttribute("data-top-index")||"0",10);Jy(n,r,o),tc(n,r)}else if(i.classList.contains("left")){const o=parseInt(i.getAttribute("data-left-index")||"0",10);SC(n,r,o),tc(n,r)}}}function D0(n,t){var s;Vk(n),t.preventDefault(),t.stopPropagation();let e=null,r,i;const o=l=>{var c;if(l.target instanceof HTMLElement&&r&&e&&i!==void 0){const d=J(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const C=parseInt((c=l.target.getAttribute(`data-${r}-index`))!=null?c:"0",10),E=Math.min(i,C),x=Math.abs(i-C)+1;wt(l.target,"top")&&r==="top"?OF(n,d,E,x,{reverse:!0}):wt(l.target,"left")&&r==="left"&&NF(n,d,E,x,{reverse:!0})}}l.type==="mouseup"&&(e=null,i=void 0,r=void 0,document.body.removeEventListener("mousemove",o),document.body.removeEventListener("mouseup",o))};t.target instanceof HTMLElement&&wt(t.target,"table-border-bar-cell")&&(e=J(t.target),wt(t.target,"top")?r="top":wt(t.target,"left")&&(r="left"),r&&e&&(i=parseInt((s=t.target.getAttribute(`data-${r}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",o),document.body.addEventListener("mouseup",o)))}function zk(n){const t=n.selection.range,e=Vu(n,t);e&&tc(n,e)}function g$(n,t){p(is,$e(t),"invalid table block");const e=xi(n,t),r=ie(t),i=B("div",["table-border-bar-container","top"],e),o=B("div",["table-border-bar-container","left"],r);tc(n,t),n.domEvents.addEventListener(Ot(t),"scroll",jk),n.domEvents.addEventListener(i,"click",I0),n.domEvents.addEventListener(o,"click",I0),n.domEvents.addEventListener(i,"mousedown",D0),n.domEvents.addEventListener(o,"mousedown",D0),n.addListener("afterClearSelection",zk)}function Gk(n,t){if(!n.isWritable())return;if(xi(n,t).querySelector(".table-border-bar-container")){tc(n,t);return}g$(n,t)}function Wk(n,t){p(is,$e(t),"invalid table block");const e=xi(n,t),r=ie(t),i=e.querySelectorAll(".table-border-bar-container"),o=r.querySelectorAll(".table-border-bar-container");i.forEach(s=>{n.domEvents.removeEventListener(s,"click",I0),n.domEvents.removeEventListener(s,"mousedown",D0),s.remove()}),o.forEach(s=>{n.domEvents.removeEventListener(s,"click",I0),n.domEvents.removeEventListener(s,"mousedown",D0),s.remove()}),n.domEvents.removeEventListener(Ot(t),"scroll",jk),n.addListener("afterClearSelection",zk)}function p$(n,t){p(is,$e(t),"invalid table block");const r=xi(n,t).querySelector(".table-border-bar-container.top");return r?r.getBoundingClientRect().height:0}class C${constructor(t,e){m(this,"toolbar");m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(Zo(this.editor,this.tableBlock,!0,!0),ts(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Zo(this.editor,this.tableBlock,!0,!1),ts(this.editor,this.tableBlock,!0,!1)):(Zo(this.editor,this.tableBlock,!1),ts(this.editor,this.tableBlock,!1)))});m(this,"handleClick",(t,e,r)=>{e.id==="delete-columns"?hC(this.editor.selection.range):e.id==="delete-rows"&&mC(this.editor.selection.range)});m(this,"handleToolbarClose",()=>{this.tableBlock&&Vu(this.editor,this.editor.selection.range)===this.tableBlock&&(Zo(this.editor,this.tableBlock,!1),ts(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const r=t.options.componentsOptions.popover;this.toolbar=new Pu([],void 0,{id:"table-row-column-toolbar",overflowBoundary:r==null?void 0:r.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var i,o,s;const{selectedColumns:t,selectedRows:e}=dC(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close("cancelBar");return}if(t.size===0&&e.size===0){this.toolbar.close("cancelBar");return}const r=ji(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!r){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:D.t("table.deleteSelectCol"),icon:m2};this.toolbar.updateItems([l]);const c=Wi(this.editor,this.tableBlock,"table-row-column-delete",r);this.toolbar.manualShow(c,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:D.t("table.deleteSelectRow"),icon:h2};this.toolbar.updateItems([l]);const h=ie(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),C=new DOMRect(Math.max(h.left,r.left-Ha),r.top,Ha,r.height),E=Wi(this.editor,this.tableBlock,"table-row-column-delete",C);this.toolbar.manualShow(E,{placement:"left",offset:[0,5]});const x=this.editor.options.componentsOptions.popover;(i=this.toolbar.tippyInstance)==null||i.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:x==null?void 0:x.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(o=this.toolbar.tippyInstance)==null?void 0:o.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const nE=I("table-border-bar");class E${constructor(t,e){m(this,"toolbar");m(this,"resizeObserver",null);m(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():Wk(this.editor,this.tableBlock)});m(this,"handleBlockUpdated",()=>{var t;(t=this.resizeObserver)==null||t.disconnect(),setTimeout(()=>{var r;const e=this.editor.getBlockById(lt(this.tableBlock));(r=this.resizeObserver)==null||r.observe(Ve(e))})});m(this,"handleScroll",()=>{var t;(t=this.toolbar)==null||t.update()});m(this,"handleTableResize",()=>{!this.editor.isWritable()||this.update()});this.editor=t,this.tableBlock=e,p(nE,this.tableBlock,"no table block"),nE.debug("create table border bar"),Gk(this.editor,this.tableBlock),this.resizeObserver=new Ds(this.handleTableResize),this.resizeObserver.observe(Ve(this.tableBlock));const r=t.getComponentOptions("table");r!=null&&r.hideToolbar||(this.toolbar=new C$(this.editor,this.tableBlock)),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){var t;(t=this.toolbar)==null||t.close()}destroy(){var t,e;nE.debug("destroy table border bar"),(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,Wk(this.editor,this.tableBlock),(e=this.toolbar)==null||e.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){var t;Gk(this.editor,this.tableBlock),(t=this.toolbar)==null||t.update()}}const A$=I("table-border-bar");class x${constructor(t){m(this,"activeTableBar",null);m(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||re(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});m(this,"handleSelectionChanged",t=>{setTimeout(()=>{var i;const e=t.selection.range,r=Vu(t,e);((i=this.activeTableBar)==null?void 0:i.tableBlock)!==r&&this.activeTableBar&&this.hide(),r&&this.show(r)})});m(this,"handleScroll",()=>{var t;(t=this.activeTableBar)==null||t.handleScroll()});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){var t;this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.activeTableBar)==null||t.destroy()}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new E$(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(p(A$,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function qk(n,t){const e=n.addCustom("table-border-bar",r=>new x$(r));t==="update"&&e.update()}const Pn=I("table-cell-menu"),b$="style-bg-color-";class v${constructor(t){m(this,"activeTableBlock",null);m(this,"targetButton",null);m(this,"manualMenu",null);m(this,"colorPaletteItem",null);m(this,"handlePrevent",(t,e)=>{e.stopPropagation()});m(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});m(this,"handleSelectionChanged",t=>{const e=t.selection.range,r=Vu(t,e);if(this.hide(),this.activeTableBlock!==r&&(this.activeTableBlock=r),this.activeTableBlock){const i=It.fromBlock(this.activeTableBlock),o=e.isReverse()?e.start:e.end;let s=null;o instanceof Mr?t.getBlockById(o.blockId)===this.activeTableBlock?s=i.getCellByContainerId(o.childContainerId):s=this.getCellByChildBlockId(i,o.blockId):o.blockId!==this.activeTableBlock.id&&(s=this.getCellByChildBlockId(i,o.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});m(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});m(this,"createBkgColorItem",()=>{const t=B("div",["cell-background-color-item"],null);B("span",[],t,D.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();B("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const i=B("span",["item-sub-indicator"],t);return i.innerHTML=Gp,t});m(this,"handleCommand",t=>{var i;p(Pn,this.activeTableBlock,"no target table block");const e=((i=t.states)==null?void 0:i.includes("checked"))||!1,r=t.value;switch(t.id){case"delete-select-row":mC(_y(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":hC(_y(this.editor,this.activeTableBlock,!0));break;case"merge-cell":Ly(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":GP(this.editor,this.activeTableBlock,r==="show-border");break;case"show-chart":XP(this.editor,this.activeTableBlock,r==="show-chart"),bC(this.editor,this.activeTableBlock,{updateNow:!0});break}});m(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&Vu(this.editor,this.editor.selection.range)===this.activeTableBlock&&(Zo(this.editor,this.activeTableBlock,!1),ts(this.editor,this.activeTableBlock,!1)),this.editor.focus()});m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(p(Pn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Zo(this.editor,this.activeTableBlock,!0,!1),ts(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Zo(this.editor,this.activeTableBlock,!0,!0),ts(this.editor,this.activeTableBlock,!0,!0)):(Zo(this.editor,this.activeTableBlock,!1),ts(this.editor,this.activeTableBlock,!1)))});m(this,"handleClick",(t,e)=>{var r;p(Pn,this.activeTableBlock,"no target table block"),p(Pn,this.targetButton,"no target button"),Vk(this.editor),wt(this.targetButton,"active")?(ot(this.targetButton,"active"),(r=this.manualMenu)==null||r.close("clickItem")):(z(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new Qo(this.createCommandMenu(),void 0,{id:"table-cell-menu"}),this.manualMenu.on("click",(i,o)=>{var s;this.handleCommand(o),(s=this.manualMenu)==null||s.close("clickItem")}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",this.handleToolbarClose)),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"})),e.stopPropagation()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close("cancelBar"),this.targetButton&&(ot(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let r=this.editor.getBlockById(e);for(;r;){const i=r.closest("td");p(Pn,i,"no parent cell");const o=J(i);if(p(Pn,o,"no parent block"),Ve(o)===t.table)return t.getCellByCellElement(i);r=o}return p(Pn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${AC}`)||t.appendChild(this.targetButton):(this.targetButton=B("button",[AC],t),this.targetButton.innerHTML=Gh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent),this.editor.domEvents.addEventListener(this.targetButton,"dblclick",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),p(Pn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=It.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:r,row:i}=this.getCellByChildBlockId(t,e.start.blockId);pC(this.editor,this.activeTableBlock,{col:r,row:i})}else CC(this.editor.selection.range)}}getSelectedBkgColorIndex(){var s;p(Pn,this.activeTableBlock,"no target table block");const t=this.editor.selection.range,e=Jo(this.editor,this.activeTableBlock,t.focus),r=this.editor.getBlockData(this.activeTableBlock),i=e.childContainerId,o=r[`${i}_background`];return o?Number.parseInt((s=o.substring(b$.length))!=null?s:"0",10):-1}createCommandMenu(){p(Pn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=Sy(this.editor,this.activeTableBlock,this.editor.selection.range);let r=this.editor.selection.range;if(r.isSimple()){const h=Jo(this.editor,this.activeTableBlock,r.start);r=Xe(this.editor,{anchor:h,focus:h})}const i=wy(this.editor,this.activeTableBlock,r),o=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,d=t.chart;return this.colorPaletteItem=new by("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,C)=>{var E;switch(p(Pn,this.activeTableBlock,"no target table block"),h){case"clearColor":Oy(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":Oy(this.editor,this.activeTableBlock,C);break}(E=this.manualMenu)==null||E.close("clickItem")}),[{id:"cell-background-color",name:D.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:D.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:D.t("table.splitCell"),states:i?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:D.t("table.deleteSelectRow")},{id:"delete-select-col",name:D.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:D.t("table.tableConfigKey"),children:[{id:"row-title",name:D.t("table.tableConfig.rowTitle"),states:o?["checked"]:[]},{id:"col-title",name:D.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:D.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?D.t("table.tableConfig.showBorder"):D.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:d?D.t("table.tableConfig.hideChart"):D.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){p(Pn,this.activeTableBlock,"no target table block"),t?HP(this.editor,this.activeTableBlock):$P(this.editor,this.activeTableBlock)}handleColTitle(t){p(Pn,this.activeTableBlock,"no target table block"),t?VP(this.editor,this.activeTableBlock):KP(this.editor,this.activeTableBlock)}handleStripeStyle(t){p(Pn,this.activeTableBlock,"no target table block"),t?zP(this.editor,this.activeTableBlock):jP(this.editor,this.activeTableBlock)}}function Xk(n){n.addCustom("table-cell-menu",t=>new v$(t))}const _0=I("table-container");function rE(n){const t=n.closest("td");return p(_0,t,"no parent cell for a table cell container"),t}function Yk(n){const t=Ve(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function iE(n,t,e,r){const i=It.fromBlock(n),o=i.getCellByContainerId(ut(t));if(e==="ArrowDown"){const s=i.getBottomCell(o);return s?s.container:null}if(e==="ArrowUp"){const s=i.getTopCell(o);return s?s.container:null}if(e==="ArrowLeft"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(_0,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return r!=null&&r.noWrap&&i.getCellByContainerId(ut(c)).row!==o.row?null:c}if(e==="ArrowRight"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(_0,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return r!=null&&r.noWrap&&i.getCellByContainerId(ut(c)).row!==o.row?null:c}p(_0,!1,`invalid navigation type: ${e}`)}const B$=12,T$=90,M0=23,Qk=2;class y${constructor(t){m(this,"scrollTableBlock",null);m(this,"autoScrollDir",null);m(this,"autoScrollTimer",null);m(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const r=J(e);if(r&&re(this.editor.rootContainer,r)){const i=so(r);i&&(this.scrollTableBlock=i,document.addEventListener("mousemove",this.handleAutoScroll))}}});m(this,"handleAutoScroll",Y6.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=i.getBoundingClientRect(),c=Math.min(l.bottom,s),d=Math.max(l.top,0);o.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):o.top<d&&t.clientY<=d?this.setAutoScroll("top"):r.scrollLeft>0&&t.clientX<o.left?this.setAutoScroll("left"):r.scrollLeft<r.scrollWidth-r.offsetWidth&&t.clientX>o.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));m(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});m(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId),i=so(r);if(i){const o=t.getCustom(Ai(i)),s=o.rootElement.getBoundingClientRect(),l=Fo(t,r,e.start);if(s.left>l.left){const c=e.start.offset===0?B$:Qk;o.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?T$:Qk;o.rootElement.scrollLeft+=l.right-s.right+c}}}else{const r=t.getBlockById(e.start.blockId),i=so(r),o=t.getBlockById(e.end.blockId),s=so(o);if(i&&i===s){const l=t.getCustom(Ai(i)),c=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?Fo(t,r,e.start):Fo(t,o,e.end);else{const h=rE(Sr(t,e.start.childContainerId)),C=rE(Sr(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():C.getBoundingClientRect()}c.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-d.left:c.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-c.right)}}});m(this,"handleScroll",t=>{yy(t),this.editor.selection.caret.update()});m(this,"handleReset",t=>{yy(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),Hk(t)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}getBarFloatWindowBottom(t){return t.scrollOptions.barFloatWindowBottom?typeof t.scrollOptions.barFloatWindowBottom=="number"?t.scrollOptions.barFloatWindowBottom:t.scrollOptions.barFloatWindowBottom():0}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=i===document.documentElement?window.innerHeight:i.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),c=i.getBoundingClientRect(),d=Math.min(c.bottom,l),h=Math.max(c.top,0);this.autoScrollDir==="left"&&(r.scrollLeft-=M0,r.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(r.scrollLeft+=M0,r.scrollLeft>=r.scrollWidth-r.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(i.scrollTop+=M0,(i.scrollTop>=i.scrollHeight-s||o.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(i.scrollTop-=M0,(i.scrollTop<=0||o.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Jk(n){return n.addCustom("table-scroll-events",t=>new y$(t))}const k$=I("table-doc-change-handler");class R${constructor(t){this.editor=t,this.editor.addListener("docChanged",this.handleDocChanged)}handleDocChanged(t,e){if(!e){const{start:r,end:i}=t.selection.range;if(!t.findBlockById(r.blockId)||!t.findBlockById(i.blockId)){t.selection.selectBlock(t.getBlockByIndex("root",0),0);return}if(ma(r)){const o=t.getBlockById(r.blockId);if(!$e(o))return;if(p(k$,ma(i),"invalid range"),!Zc(t,r.childContainerId)||!Zc(t,i.childContainerId)){t.selection.selectBlock(o,0);return}let s=null,l=null;const c=(d,h)=>{const C=h.getCellById(d.childContainerId),{colIndex:E=0,rowIndex:x=0}=d.custom;let v=-1,R=-1;return(C.col>E||C.col+C.colSpan-1<E)&&(v=C.col),(C.row>x||C.row+C.rowSpan-1<x)&&(R=C.row),v!==-1||R!==-1?Ee(o,d.childContainerId,{colIndex:v===-1?E:v,rowIndex:R===-1?x:R}):null};if(r.custom){const d=It.fromBlock(o);s=c(r,d),l=c(i,d)}(s!==null||l!==null)&&(t.selection.range.isReverse()?t.selection.setSelection(l!=null?l:i,s!=null?s:r):t.selection.setSelection(s!=null?s:r,l!=null?l:i))}}}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged)}}function Zk(n){n.addCustom("table-doc-change-handler",t=>new R$(t))}const bi=I("create-content");function tR(n,t,e){var C;const r=new s0(e),i=e.rows,o=e.cols;p(bi,i>=1,`invalid rows: ${i}`),p(bi,o>=1,`invalid cols: ${o}`),p(bi,e.children,"no table children");const s=B("table",[],null),l=(C=e.colsWidth)!=null?C:new Array(e.cols).fill(0),c=B("colgroup",[],s);for(let E=0;E<r.colCount;E++){const x=B("col",[],c);l[E]&&(x.style.width=`${l[E]}px`)}const d=B("tbody",[],s);let h=0;for(let E=0;E<i;E++){const x=B("tr",[],d);for(let v=0;v<o;v++){const R=r.getCell({col:v,row:E});if(R.virtual)p(bi,R.colSpan>1||R.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const L=e.children[h],M=B("td",[],x);R.colSpan>1&&(M.colSpan=R.colSpan),R.rowSpan>1&&(M.rowSpan=R.rowSpan);const U=e[ju(L)];U&&z(M,U),v===0&&e.hasColTitle&&z(M,Iy.COL_TITLE_ITEM),n.createChildContainer(t,M,L),h+=1}}}return p(bi,h===e.children.length,"container count mismatch"),s.style.minWidth=`${l.reduce((E,x)=>x+E,0)}px`,e.noBorder&&z(s,"no-border"),e.chart&&z(s,"editor-table-chart"),e.isStripeStyle&&z(s,"stripe"),e.hasRowTitle&&z(s,"row-title"),e.hasColTitle&&z(s,"col-title"),s}function w$(n,t,e,r,i){p(bi,i.type==="table","not table data"),p(bi,ut(e)===t[t.length-1].containerId,"invalid path");const o=i,s=$s(r,"div");try{const l=B("div",[],null);l.setAttribute("data-type","table-content");const c=tR(n,t,o);c.classList.add("drag-preview-element"),l.appendChild(c);const d=n.getComponentOptions("table");Yy(n),Zy(n),qk(n,"create"),Zk(n),d!=null&&d.hideCellMenu||Xk(n),c2(n,vC);const h=n.addCustom(Ai(r),()=>xF());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Xt(e)?n.scrollContainer:e,locatingContainer:Xt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:Ha+Hu,paddingTop:Ha+Hu,paddingBottom:Hu/2,paddingRight:Hu/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,allowScrollBarFixed:d==null?void 0:d.allowScrollBarFixed,isSetScale:d==null?void 0:d.isSetScale});const C=Jk(n);h.on("scroll",C.handleReset),h.on("resize",C.handleReset),setTimeout(()=>{JP(n,r)})}catch{const c=`invalid table data: ${JSON.stringify(o)}`;bi.error(c);const d=B("div",["error"],s);d.innerText=c}return s}function S$(n,t,e){p(bi,e.type==="table","not table data");const r=e,i=Ot(t);try{const o=Ve(t),s=Ko(t),l=tR(n,s,r);l.classList.add("drag-preview-element"),o.insertAdjacentElement("afterend",l),o.remove();const c=n.getComponentOptions("table");Yy(n),Zy(n),qk(n,"update"),Zk(n),c!=null&&c.hideCellMenu||Xk(n),vC(n,void 0,t)}catch{const s=`invalid table data: ${JSON.stringify(r)}`;bi.error(s);const l=B("div",["error"],i);l.innerText=s}}function L$(n,t){let e,r,i=!1;if([...t].every(E=>E==="|")?(r=t.length,e=Array(r).fill(""),i=!0):(e=Dg(t,"|").split("|"),r=e.length),r<2)return null;const o=3,s=r,l=[];for(let E=0;E<3;E++)e.forEach(x=>{l.push(Ji(n.doc,E===0?x:""))});const c=Array(s).fill(yC),d=l[i?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:tt(),type:"table",rows:o,cols:s,children:l,colsWidth:c},focusBlockId:h}}function I$(n,t){const e=t.rows,r=t.cols;if(e<1||r<1)return null;const i=[];for(let d=0;d<e;d++)for(let h=0;h<r;h++)i.push(Ji(n.doc));const o=Array(r).fill(yC),s=i[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:tt(),type:"table",rows:e,cols:r,children:i,colsWidth:o},focusBlockId:l}}const oE=I("get-selected-containers");function eR(n,t,e,r){p(oE,e.blockId===r.blockId,"only allow select in single table block"),p(oE,lt(t)===e.blockId,"only allow select in single table block");const i=It.fromBlock(t),o=i.getCellByContainerId(e.childContainerId),s=i.getCellByContainerId(r.childContainerId);if(e.custom===void 0||r.custom===void 0)return i.getCells(o,s).map(L=>i.getCellContainer(L));const{fromCol:l,toCol:c,fromRow:d,toRow:h}=jr(t,e,r),C=new Set,E=[];return i.sub({row:d,col:l},{row:h,col:c}).forEach(v=>{v.forEach(R=>{const L=i.getCellByContainerId(R.containerId);L.col<l||L.row<d||L.col+L.colSpan-1>c||L.row+L.rowSpan-1>h||C.has(R.containerId)||(C.add(R.containerId),E.push(L.container))})}),E}function D$(n,t,e){p(oE,t.blockId===e.blockId,"only allow select in single table block");const r=n.getBlockById(t.blockId);return eR(n,r,t,e)}const nR=I("table-selection-to-doc");function _$(n,t){const{start:e,end:r,block:i}=t,o=Dt(i);p(nR,o==="table",`invalid block type: ${o}`);const s=n.getBlockData(i);if(e.isSimple()&&r.isSimple())return Go(n.editorBlocks,n.doc.toJSON(),s);p(nR,!e.isSimple()&&!r.isSimple(),"invalid block pos type");const l=It.fromBlock(i),{fromCol:c,toCol:d,fromRow:h,toRow:C}=jr(i,e,r),E={},x=[],v=n.doc.toJSON();let R={};l.sub({row:h,col:c},{row:C,col:d}).forEach((rt,st)=>{rt.forEach((Et,vt)=>{const xt=Et.containerId;if(x.indexOf(xt)!==-1)return;x.push(xt);let Gt;if(Et.virtual){const be=l.getCellByContainerId(Et.containerId),Fn=c+vt;let wi=be.col+be.colSpan-1;wi>d&&(wi=d);const kn=wi-Fn+1;kn>1&&(E[`${xt}_colSpan`]=kn);const Cn=h+st;let Si=be.row+be.rowSpan-1;Si>C&&(Si=C);const uo=Si-Cn+1;uo>1&&(E[`${xt}_rowSpan`]=uo),Gt=Qi()}else{if(Gt=np(n.editorBlocks,v,xt),Et.col+Et.colSpan>d+1){const be=d-Et.col+1;be>1&&(E[`${xt}_colSpan`]=be)}else Et.colSpan>1&&(E[`${xt}_colSpan`]=Et.colSpan);if(Et.row+Et.rowSpan>C+1){const be=C-Et.row+1;be>1&&(E[`${xt}_rowSpan`]=be)}else Et.rowSpan>1&&(E[`${xt}_rowSpan`]=Et.rowSpan)}const{root:Yt,...an}=Gt.blocks;R={...R,...an,[xt]:Yt}})});const M=Xu(Ve(i)).slice(c,d+1);return{blocks:{root:[{id:tt(),type:o,children:x,colsWidth:M,rows:C-h+1,cols:d-c+1,...E}],...R},meta:{},comments:{}}}const M$=I("ajust-selection-pos");function U$(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function O$(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function N$(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function P$(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function F$(n,t,e){const r=t.col,i=t.row,o=e.col,s=e.row,l={left:r,top:i,right:o,bottom:s};let c=!1;do{if(c=!1,!U$(n,l)){l.top--,c=!0;continue}if(!O$(n,l)){l.left--,c=!0;continue}if(!N$(n,l)){l.bottom++,c=!0;continue}if(!P$(n,l)){l.right++,c=!0;continue}}while(c);return l}function K$(n,t,e,r){if(e.custom!==void 0||r.custom!==void 0)return{anchor:e,focus:r};const i=It.fromBlock(t),o=i.map(F=>F.containerId),s=i.getCellByContainerId(e.childContainerId),l=i.getCellByContainerId(r.childContainerId),c=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),C=Math.max(s.col,l.col),E=F$(o,{row:c,col:h},{row:d,col:C}),x=i.getCell({row:E.top,col:E.left}),v=i.getCell({row:E.bottom,col:E.right}),R=i.getCell({row:E.top,col:E.right}),L=i.getCell({row:E.bottom,col:E.left});let M,U;return s.row<=l.row?s.col<=l.col?(M=x,U=v):(M=R,U=L):s.col<l.col?(M=L,U=R):(M=v,U=x),M$.debug(`move ${M.col}, ${M.row}, -> ${U.col}, ${U.row}`),{anchor:Ee(t,M.containerId),focus:Ee(t,U.containerId)}}function rR(n,t,e){if(e.isSimple())return[Ve(t).getBoundingClientRect()];const r=Ve(t),i=r.getBoundingClientRect(),{fromCol:o,fromRow:s,toCol:l,toRow:c}=jr(t,e.start,e.end),d=Xu(r),h=d.slice(0,o).reduce((R,L)=>R+L,0),C=h+d.slice(o,l+1).reduce((R,L)=>R+L,0),E=$k(r);let x=E.slice(0,s).reduce((R,L)=>R+L,0);const v=x+E.slice(s,c+1).reduce((R,L)=>R+L,0);if(s===0){const R=p$(n,t);x-=R}return[new DOMRect(i.left+h,i.top+x,C-h,v-x)]}I("table-size");const V$=40;function U0(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),r=Number.parseInt(e.borderLeft,10),i=Number.parseInt(e.borderRight,10);return(r+i)/2}function $$(n,t,e){const r=r1(n,e.container);return r!==void 0?r+U0(t):V$*e.colSpan-U0(t)}function H$(n,t,e,r){let i=0;const o=e.colCount;for(let s=0;s<o;s++){const l=e.getCell({col:s,row:r});if(l.virtual)continue;let c=$$(n,t,l);const d=Qv(l.container,{withPadding:!0});d&&d>c&&(c=d),i+=c+U0(t)}return i}function j$(n,t){const e=Ve(t),r=It.fromTable(e);let i=0;for(let s=0;s<r.rowCount;s++)i=Math.max(i,H$(n,e,r,s));const o=U0(e);return i+=o,i}const lo=I("table-creator");async function z$(n,t){return n.undoManager.runInGroup(()=>{var c,d;const e=t.item,r=(c=e.colCount)!=null?c:5,i=(d=e.rowCount)!=null?d:3,o=I$(n,{cols:r,rows:i});if(!o)return null;const{blockData:s,focusBlockId:l}=o;return n.insertBlock(t.containerId,t.blockIndex,s,ye(n,l,0))})}class G${constructor(){m(this,"id","insert-table");m(this,"name","Create table");m(this,"element");m(this,"closeable",null);m(this,"colCount");m(this,"rowCount");m(this,"setCloseable",t=>{this.closeable=t});m(this,"destroy",()=>{this.closeable=null});m(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);m(this,"handleTableCreatorClick",t=>{var E,x;t.preventDefault(),t.stopPropagation();const e=t.target;p(lo,e instanceof HTMLElement,"invalid event target");const r=e.closest(".table-creator");p(lo,r,"no table creator");const i=r.querySelectorAll(".active");if(i.length===0)return;const s=i[i.length-1].id;p(lo,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");p(lo,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,C=Number.parseInt(d[1],10)+1;lo.debug(`${h}, ${C}`),this.colCount=C,this.rowCount=h,(E=this.closeable)==null||E.click(this,this.element),(x=this.closeable)==null||x.close("clickItem"),this.handleTableCreatorLeave()});m(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const r=this.getTableCreatorCellId(t,e),i=document.getElementById(r);i&&ot(i,"active")}});m(this,"handleTableCreatorCellEnter",t=>{const e=t.target;p(lo,e instanceof HTMLElement,"invalid event target");const r=e.id,i="table-creator-cell-";p(lo,r.startsWith(i),"invalid cell id");const s=r.substring(i.length).split("-");p(lo,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const C=this.getTableCreatorCellId(d,h),E=document.getElementById(C);p(lo,E,"no cell"),d<=l&&h<=c?z(E,"active"):ot(E,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=B("div",["table-creator"],null),e=(r,i,o)=>{const s=B("div",["table-creator-cell"],r);return s.id=this.getTableCreatorCellId(i,o),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let r=0;r<9;r++){const i=B("div",["table-creator-row"],t);for(let o=0;o<9;o++)e(i,r,o).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function W$(){return new G$}function q$(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function iR(n){const t=q$(n);return n.length+t}function X$(n,t,e=[]){let r=0;if(!e||e.length===0)return r;for(let i=n;i<n+t;i+=1)r+=e[i]||0;return r}function Y$(n,t){const e=iR(n),r=t-e;return r>0?n+" ".repeat(r):n}function Q$(n,t,e,r,i){var l;const o=t,s=new s0(o);if(r==="markdown"||r==="text"){const c=M=>e.blocks[M].map((G,W)=>r==="markdown"?Ah(n,G,e,[...i,{containerId:M,blockIndex:W}]):Eh(n,G,e,[...i,{containerId:M,blockIndex:W}])),d=M=>c(M).join(" ").replace(/\n/g," ").trim(),h=new Map,C=new Map;for(let M=0;M<s.colCount;M++){let U=0;for(let F=0;F<s.rowCount;F++){const G=s.getCell({row:F,col:M});let W="";G.virtual||(W=d(G.containerId)),h.set(`${F},${M}`,W),U=Math.max(U,iR(W))}C.set(M,U)}const E=M=>{const U=h.get(`${M.row},${M.col}`)||"",F=C.get(M.col)||0;return Y$(U,F)};if(r==="text"){const M=[];for(let U=0;U<s.colCount;U++){const F=E({row:0,col:U});M.push(F)}for(let U=1;U<s.rowCount;U++)for(let F=0;F<s.colCount;F++){const G=E({row:U,col:F});M.push(G)}return M.join(`
|
|
605
|
+
`:i.mathjaxText}function jV(){return{abstract:D.t("mathjax.abstract")}}const zV={embedType:"math",createEmbedContent:FV,getOptions:VV,convertFrom:KV,handleDeleteBlock:$V,convertTo:HV,getBlockProperties:jV},sct="",GV={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},WV={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},qV={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};D.mergeLang({"zh-CN":GV,"en-US":WV,"ja-JP":qV});function XV(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r);if(!fe(s).endsWith("$$$$"))return!1;const c=r-4,d=r,h={id:tt(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c),n.insertBoxToBlock(i,c,h),setTimeout(()=>{const C=n.getBoxById(h.id);w0(n,C)})}),!0}class YV{handleAfterInsertText(t,e,r,i,o){return!!(o===" "&&XV(t,e,r,i))}}const dl=I("inline-box-items");function QV(n,t,e){return n.undoManager.runInGroup(()=>{var s;let r=n.findBlockByIndex(t,e);(!r||!ue(n,r))&&(r=n.insertTextBlock([],t,e));const i=Ok();n.setBlockText(r,[i]);const o=(s=i.attributes)==null?void 0:s.id;return p(dl,o,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(o);w0(n,l)},100),r})}function JV(n,t,e){let r=n.findBlockByIndex(t,e),i="bottom-start";return(!r||!ue(n,r))&&(i="top-start",r=n.insertTextBlock([],t,e)),Yu(n,{target:r,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{p(dl,r,"block not found"),ue(n,r)||(r=n.insertTextBlock([],t,e));const d=mr(l,{link:c}),h=mr(" ",null),C=[d,h];n.insertTextToBlock(r,0,C),n.selection.selectBlock(r,dn(C)),n.focus()}catch(d){dl.error(d)}})},onClose:()=>{n.focus()},placement:i}),r}function ZV(n,t,e){return n.undoManager.runInGroup(()=>{var l;const r=n.getBlockByIndex(t,e),i=n.selection.range;p(dl,ci(i.start),"invalid block position");const o=Ok();n.insertBoxToBlock(r,i.start.offset,o.attributes);const s=(l=o.attributes)==null?void 0:l.id;return p(dl,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);w0(n,c)},100),r})}function t$(n,t,e){const r=n.getBlockByIndex(t,e),i=n.selection.range;p(dl,ci(i.start),"invalid block position");const o=ji(n,r,i);if(o.length===0)return;const s=o[0],l=Wi(n,r,"quick-menu-inline-link",s);Yu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,C)=>{n.undoManager.runInGroup(()=>{try{const E=n.getBlockText(r),x=Yi(E,i.start.offset,h,{link:C});n.setBlockText(r,x),n.selection.selectBlock(r,i.start.offset+h.length),n.focus()}catch(E){dl.error(E)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class Fk{getCommands(){return[{id:"insert-math",name:D.t("quickMenu.inlineBox.math"),icon:R2,order:900,group:"common",subText:Tn("insert-math")},{id:"insert-link",name:D.t("quickMenu.inlineBox.link"),icon:Jp,order:400,group:"common",subText:Tn("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return ZV(t,e.containerId,e.blockIndex);case"insert-link":return t$(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return QV(t,e.containerId,e.blockIndex);case"insert-link":return JV(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,r){if(r.from==="quick-menu"){const i=t.getBlockById(r.blockId),o=t.getParentContainer(i),s=ut(o),l=t.getBlockIndex(i);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else r.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:r.containerId,blockIndex:r.blockIndex}));return null}}function e$(n,t={withPlainText:!1}){var o,s;const{withPlainText:e}=t,r=(s=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:s.commandProviders;if(!r)return[];const i=[];return[...r,new Sk(e),new Fk].forEach(l=>{const c=l.getCommands(n);i.push(...c.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),i}function n$(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(r=>{if(!r.getOptions)return;const i=r.getOptions(n);!i.insertBlockCommandItems||(i.insertBlockCommandItems.forEach(o=>{wk(o,i)}),e.push(...i.insertBlockCommandItems))}),e.push(...e$(n,t)),e}function tE(n,t={withPlainText:!1}){const e=n$(n,t),r=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let c=r.get(l);c?c.items.push(s):(c={group:l,order:s.groupOrder||Lk[l]||1e3,items:[s]},r.set(l,c))});const i=Array.from(r.values());i.sort((s,l)=>s.order-l.order),i.forEach(s=>{s.items.sort((l,c)=>{var d,h;return((d=l.order)!=null?d:0)-((h=c.order)!=null?h:0)})});const o=[];return i.forEach((s,l)=>{const c=`blockMenu.section.${s.group||"common"}`,d=D.t(c),h=d===c?s.group:d;o.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),o.push(...s.items.map(C=>({...C})))}),o}function r$(n,t,e){const r=n.getFocusedBlock();if(!r)return;const i=n.getParentContainer(r),o=ut(i);let l=n.getBlockIndex(r);if(ue(n,r)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:o,blockIndex:l,item:t,from:"quick-menu"})}const Kk=I("quick-menu"),i$={id:"quick-menu",trigger:["/"]},o$=5;class S0{constructor(t,e=i$){m(this,"suggest");m(this,"items");m(this,"maxHeading");m(this,"firstEmptyOffset",-1);m(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const r=new Set,i=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,""),o=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(i)!==-1||yP(s).toLocaleLowerCase().indexOf(i)!==-1)return r.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,c=D.t(l),d=c===l?s.group:c;return(d==null?void 0:d.toLocaleLowerCase().indexOf(i))!==-1?(r.add(s.group),!0):!1}).filter(s=>s.type==="section"?r.has(s.group):!0);return o.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),o}return this.items});m(this,"onClose",()=>{this.firstEmptyOffset=-1});m(this,"onShow",(t,e,r,i)=>{const o=this.editor.getBlockByIndex(e,r);if(!dr(o)){const s=J(it(o));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e)=>{const r=e;r.itemType==="insert-block"&&(p(Kk,r.blockOptions||r.commandProvider,"invalid quick item, no block options or command provider"),p(Kk,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),r$(this.editor,r,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=C0(),this.suggest=new uC(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=tE(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const r=C0();if(r!==this.maxHeading){const i=new Sk,s=i.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:i}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=r}}handleEmptySearch(){const t=this.editor.selection.getFocusedPos();if(this.firstEmptyOffset===-1){if(t.isSimple()){const{offset:e}=t;this.firstEmptyOffset=e-1}}else if(t.isSimple()){const{offset:e}=t;e-this.firstEmptyOffset>o$&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class L0{constructor(t){m(this,"instance");m(this,"mousedown",!1);m(this,"currentInstance",null);m(this,"attributeName",[]);m(this,"attributeDesc","");m(this,"_lastClickButtonId","");m(this,"observer",null);m(this,"observerCallback",null);m(this,"createContent",t=>{let e="",r=0;for(;r<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[r])&&(e=t.getAttribute(this.attributeName[r])||""),r++;const i=t.getAttribute(this.attributeDesc);if(!i)return e;const o=B("div",[],null);return B("span",[],o,e),i&&B("span",["editor-tooltip-desc"],o,i),o});m(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});m(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});m(this,"handleShow",t=>{var i;const e=t.reference;if(!e||!re(document.body,e)||window.isDragging||this.mousedown)return!1;const r=Number.parseInt((i=e.getAttribute("data-tooltip-hide-at"))!=null?i:"",10);if(r&&Date.now()-r<1e3)return!1;if(this._lastClickButtonId===e.getAttribute("data-button-id"))return this._lastClickButtonId="",!1;if(t.reference){const o={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(o.placement=t.reference.getAttribute("data-editor-tooltip-placement")||"top"),t.reference.hasAttribute("data-editor-tooltip-offset-x")||t.reference.hasAttribute("data-editor-tooltip-offset-y")){const l=t.reference.getAttribute("data-editor-tooltip-offset-x"),c=t.reference.getAttribute("data-editor-tooltip-offset-y");o.offset=[l?Number.parseInt(l,10):0,c?Number.parseInt(c,10):0]}t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(o.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(o.allowHTML=!0);const s=document.body;if(o.appendTo=this.fixContainerForFullscreen(s),Object.keys(o).length&&t.setProps(o),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const l=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(l||"")}}return!0});this.editor=t;const e=t.clientId;this.attributeName=[`data-editor-tooltip-${e}`,`data-editor-tooltip-${e}-dynamic`,"data-editor-tooltip-common"],this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=Eg.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(r=>`[${r}]`).join(","),content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden,hideOnClick:!1}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}set lastClickButtonId(t){this._lastClickButtonId=t,t&&setTimeout(()=>{this._lastClickButtonId===t&&(this._lastClickButtonId="")},500)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Me.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,r={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,r)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}fixContainerForFullscreen(t){return t.closest("body")&&document.fullscreenElement&&!document.fullscreenElement.contains(t)?document.fullscreenElement:t}}const s$={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-sub":"subscript","text/style-super":"superscript",link:"link"};function l$(n,t){const e=new Set(Object.keys(s$)),r=t.filter(o=>e.has(o.id));return g0(r)}function Zu(n,t){if(!n.isWritable())return!1;const e=n.selection.range,r=n.editorCommandProviders.getCommands(e),o=l$(n,r).find(s=>s.id===`text/${t}`||s.id==="link");return o?(n.editorCommandProviders.executeCommand(e,o,{}),Za.get(n).update("selectionChange"),!0):!1}function a$(n,t){const e=n.selection.focusedBlock;if(!n.isWritable()||!nt(n,e))return!1;const r=n.getBlockData(e).heading,i={id:`heading-${t}`,source:"BlockTurnIntoCommandProvider",value:String(t)};return Number(r)===t&&(i.id="text",i.value=null),n.editorCommandProviders.executeCommand(n.selection.range,i,{}),!0}const eE={"CtrlOrCmd+B":n=>Zu(n,"style-bold"),"CtrlOrCmd+I":n=>Zu(n,"style-italic"),"CtrlOrCmd+U":n=>Zu(n,"style-underline"),"CtrlOrCmd+D":n=>Zu(n,"style-strikethrough"),"CtrlOrCmd+K":n=>Zu(n,"link"),...(()=>{const n={};for(let t=1;t<=8;t++)n[`CtrlOrCmd+${t}`]=e=>a$(e,t);return n})()},c$={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u5217\u8868",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",edit:"\u7F16\u8F91",remove:"\u53D6\u6D88\u94FE\u63A5"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"}},u$={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"To-do list",quote:"Quote"},inlineBox:{math:"Formula",link:"Link"}},link:{textLabel:"Text",urlLabel:"Link address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter link",submitText:"Confirm",cancelText:"Cancel",edit:"Edit",remove:"Remove link"},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"To-do list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Center text",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"}},f$={quickMenu:{basic:{heading:{title:"\u898B\u51FA\u3057{heading}",space:"{markdown}\u30B9\u30DA\u30FC\u30B9"},unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",checkbox:"\u30D0\u30C3\u30AF\u30ED\u30B0",quote:"\u5F15\u7528"},inlineBox:{math:"\u6570\u5F0F",link:"URL"}},link:{textLabel:"\u30C6\u30AD\u30B9\u30C8",urlLabel:"URL",textPlaceholder:"\u30C6\u30AD\u30B9\u30C8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",urlPlaceholder:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",submitText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB",edit:"\u7DE8\u96C6",remove:"\u30EA\u30F3\u30AF\u3092\u89E3\u9664"},commands:{unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",check:"\u30D0\u30C3\u30AF\u30ED\u30B0",link:"URL",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u63C3\u3048",alignRight:"\u53F3\u63C3\u3048",alignCenter:"\u4E2D\u592E\u63C3\u3048",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u898B\u51FA\u3057{name}",headingGroup:"\u30BF\u30A4\u30C8\u30EB\u30B9\u30BF\u30A4\u30EB",text:"\u672C\u6587"}};D.mergeLang({"zh-CN":c$,"en-US":u$,"ja-JP":f$});const act="";function hl(n,...t){const e=pr(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function Vk(n){const t=p0(n);t==null||t.hide();const e=n.findCustom("table-border-bar");e==null||e.closeToolbar()}function d$(n){return B("div",["insert-column-button","drop-marker"],n)}const h$=I("row-height");function $k(n){const t=It.fromTable(n),e=n.rows;p(h$,e.length===t.rowCount,"row count mismatch");const r=Array(t.rowCount).fill(0);for(let i=0;i<e.length;){let o=1,l=e[i].getBoundingClientRect().height,c=i+1;for(;c<e.length;){const d=e[c];if(d.cells.length!==0)break;o++,c++,l+=d.getBoundingClientRect().height}for(let d=0;d<o;d++)r[i+d]=l/o;i=c}return r}const m$=I("table-border-bar-dom");function Hk(n){var c;const t=J(n.contentElement);p(m$,t,"no block");const r=ie(t).querySelector(".table-border-bar-container.left"),o=Ot(t).offsetLeft-Ha,s=((c=n.scrollOptions.paddingLeft)!=null?c:0)+o,l=Math.min(n.contentElement.offsetLeft-o,n.rootElement.scrollLeft-s);r&&(r.style.left=`${-l}px`)}const is=I("table-border-bar-dom");function tc(n,t){p(is,$e(t),"invalid table block");const e=Ve(t),r=xi(n,t),i=ie(t),o=(C,E,x)=>{const v=B("div",["button-root",E],C),R=B("div",["button-container",E],v);v.setAttribute(`data-${E}-index`,`${x}`),R.setAttribute(`data-editor-tooltip-${n.clientId}`,E==="left"?D.t("table.insertRow"):D.t("table.insertCol")),B("span",["insert-indicator"],R),d$(R)},{selectedRows:s,selectedColumns:l}=dC(n,t),c=()=>{const C=r.querySelector(".table-border-bar-container.top");p(is,C,"no top border bar container");const E=B("div",["table-border-bar-container","top"],null),x=B("div",["table-border-bar","top"],E),v=vF(e),L=It.fromTable(e).colCount;n.selection.range.isSimple()&&o(x,"top",0);for(let M=0;M<L;M++){const U=M===L-1?v[M]+2:v[M],F=B("span",["table-border-bar-cell","top"],x);l.has(M)&&F.classList.add("selected"),F.setAttribute("data-top-index",`${M}`),F.style.width=`${U}px`,n.selection.range.isSimple()&&o(x,"top",M+1)}Yc(C,E)},d=()=>{const C=i.querySelector(".table-border-bar-container.left");p(is,C,"no left border bar container");const E=B("div",["table-border-bar-container","left"],null),x=B("div",["table-border-bar","left"],E);B("span",["table-border-bar-cell","corner"],x);const v=$k(e);n.selection.range.isSimple()&&o(x,"left",0),Array.from(e.rows).forEach((R,L,M)=>{const U=B("span",["table-border-bar-cell","left"],x);s.has(L)&&U.classList.add("selected"),U.setAttribute("data-left-index",`${L}`);const F=L===M.length-1?v[L]+2:v[L];U.style.height=`${F}px`,n.selection.range.isSimple()&&o(x,"left",L+1)}),Yc(C,E)};c(),d();const h=n.findCustom(Ai(t));h&&Hk(h)}function jk(n,t){const e=t.target;if(!(e instanceof Element))return;const r=J(e);p(is,r&&$e(r),"invalid table block"),tc(n,r),n.selection.caret.update()}function I0(n,t){const e=t.target;if(!(e instanceof Element))return;const r=J(e);p(is,r&&$e(r),"invalid table block");const i=e.closest(".button-root");if(i){if(i.classList.contains("top")){const o=parseInt(i.getAttribute("data-top-index")||"0",10);Jy(n,r,o),tc(n,r)}else if(i.classList.contains("left")){const o=parseInt(i.getAttribute("data-left-index")||"0",10);SC(n,r,o),tc(n,r)}}}function D0(n,t){var s;Vk(n),t.preventDefault(),t.stopPropagation();let e=null,r,i;const o=l=>{var c;if(l.target instanceof HTMLElement&&r&&e&&i!==void 0){const d=J(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const C=parseInt((c=l.target.getAttribute(`data-${r}-index`))!=null?c:"0",10),E=Math.min(i,C),x=Math.abs(i-C)+1;wt(l.target,"top")&&r==="top"?OF(n,d,E,x,{reverse:!0}):wt(l.target,"left")&&r==="left"&&NF(n,d,E,x,{reverse:!0})}}l.type==="mouseup"&&(e=null,i=void 0,r=void 0,document.body.removeEventListener("mousemove",o),document.body.removeEventListener("mouseup",o))};t.target instanceof HTMLElement&&wt(t.target,"table-border-bar-cell")&&(e=J(t.target),wt(t.target,"top")?r="top":wt(t.target,"left")&&(r="left"),r&&e&&(i=parseInt((s=t.target.getAttribute(`data-${r}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",o),document.body.addEventListener("mouseup",o)))}function zk(n){const t=n.selection.range,e=Vu(n,t);e&&tc(n,e)}function g$(n,t){p(is,$e(t),"invalid table block");const e=xi(n,t),r=ie(t),i=B("div",["table-border-bar-container","top"],e),o=B("div",["table-border-bar-container","left"],r);tc(n,t),n.domEvents.addEventListener(Ot(t),"scroll",jk),n.domEvents.addEventListener(i,"click",I0),n.domEvents.addEventListener(o,"click",I0),n.domEvents.addEventListener(i,"mousedown",D0),n.domEvents.addEventListener(o,"mousedown",D0),n.addListener("afterClearSelection",zk)}function Gk(n,t){if(!n.isWritable())return;if(xi(n,t).querySelector(".table-border-bar-container")){tc(n,t);return}g$(n,t)}function Wk(n,t){p(is,$e(t),"invalid table block");const e=xi(n,t),r=ie(t),i=e.querySelectorAll(".table-border-bar-container"),o=r.querySelectorAll(".table-border-bar-container");i.forEach(s=>{n.domEvents.removeEventListener(s,"click",I0),n.domEvents.removeEventListener(s,"mousedown",D0),s.remove()}),o.forEach(s=>{n.domEvents.removeEventListener(s,"click",I0),n.domEvents.removeEventListener(s,"mousedown",D0),s.remove()}),n.domEvents.removeEventListener(Ot(t),"scroll",jk),n.addListener("afterClearSelection",zk)}function p$(n,t){p(is,$e(t),"invalid table block");const r=xi(n,t).querySelector(".table-border-bar-container.top");return r?r.getBoundingClientRect().height:0}class C${constructor(t,e){m(this,"toolbar");m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(Zo(this.editor,this.tableBlock,!0,!0),ts(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Zo(this.editor,this.tableBlock,!0,!1),ts(this.editor,this.tableBlock,!0,!1)):(Zo(this.editor,this.tableBlock,!1),ts(this.editor,this.tableBlock,!1)))});m(this,"handleClick",(t,e,r)=>{e.id==="delete-columns"?hC(this.editor.selection.range):e.id==="delete-rows"&&mC(this.editor.selection.range)});m(this,"handleToolbarClose",()=>{this.tableBlock&&Vu(this.editor,this.editor.selection.range)===this.tableBlock&&(Zo(this.editor,this.tableBlock,!1),ts(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const r=t.options.componentsOptions.popover;this.toolbar=new Pu([],void 0,{id:"table-row-column-toolbar",overflowBoundary:r==null?void 0:r.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var i,o,s;const{selectedColumns:t,selectedRows:e}=dC(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close("cancelBar");return}if(t.size===0&&e.size===0){this.toolbar.close("cancelBar");return}const r=ji(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!r){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:D.t("table.deleteSelectCol"),icon:m2};this.toolbar.updateItems([l]);const c=Wi(this.editor,this.tableBlock,"table-row-column-delete",r);this.toolbar.manualShow(c,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:D.t("table.deleteSelectRow"),icon:h2};this.toolbar.updateItems([l]);const h=ie(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),C=new DOMRect(Math.max(h.left,r.left-Ha),r.top,Ha,r.height),E=Wi(this.editor,this.tableBlock,"table-row-column-delete",C);this.toolbar.manualShow(E,{placement:"left",offset:[0,5]});const x=this.editor.options.componentsOptions.popover;(i=this.toolbar.tippyInstance)==null||i.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:x==null?void 0:x.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(o=this.toolbar.tippyInstance)==null?void 0:o.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const nE=I("table-border-bar");class E${constructor(t,e){m(this,"toolbar");m(this,"resizeObserver",null);m(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():Wk(this.editor,this.tableBlock)});m(this,"handleBlockUpdated",()=>{var t;(t=this.resizeObserver)==null||t.disconnect(),setTimeout(()=>{var r;const e=this.editor.getBlockById(lt(this.tableBlock));(r=this.resizeObserver)==null||r.observe(Ve(e))})});m(this,"handleScroll",()=>{var t;(t=this.toolbar)==null||t.update()});m(this,"handleTableResize",()=>{!this.editor.isWritable()||this.update()});this.editor=t,this.tableBlock=e,p(nE,this.tableBlock,"no table block"),nE.debug("create table border bar"),Gk(this.editor,this.tableBlock),this.resizeObserver=new Ds(this.handleTableResize),this.resizeObserver.observe(Ve(this.tableBlock));const r=t.getComponentOptions("table");r!=null&&r.hideToolbar||(this.toolbar=new C$(this.editor,this.tableBlock)),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){var t;(t=this.toolbar)==null||t.close()}destroy(){var t,e;nE.debug("destroy table border bar"),(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,Wk(this.editor,this.tableBlock),(e=this.toolbar)==null||e.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){var t;Gk(this.editor,this.tableBlock),(t=this.toolbar)==null||t.update()}}const A$=I("table-border-bar");class x${constructor(t){m(this,"activeTableBar",null);m(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||re(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});m(this,"handleSelectionChanged",t=>{setTimeout(()=>{var i;const e=t.selection.range,r=Vu(t,e);((i=this.activeTableBar)==null?void 0:i.tableBlock)!==r&&this.activeTableBar&&this.hide(),r&&this.show(r)})});m(this,"handleScroll",()=>{var t;(t=this.activeTableBar)==null||t.handleScroll()});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){var t;this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.activeTableBar)==null||t.destroy()}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new E$(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(p(A$,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function qk(n,t){const e=n.addCustom("table-border-bar",r=>new x$(r));t==="update"&&e.update()}const Pn=I("table-cell-menu"),b$="style-bg-color-";class v${constructor(t){m(this,"activeTableBlock",null);m(this,"targetButton",null);m(this,"manualMenu",null);m(this,"colorPaletteItem",null);m(this,"handlePrevent",(t,e)=>{e.stopPropagation()});m(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});m(this,"handleSelectionChanged",t=>{const e=t.selection.range,r=Vu(t,e);if(this.hide(),this.activeTableBlock!==r&&(this.activeTableBlock=r),this.activeTableBlock){const i=It.fromBlock(this.activeTableBlock),o=e.isReverse()?e.start:e.end;let s=null;o instanceof Mr?t.getBlockById(o.blockId)===this.activeTableBlock?s=i.getCellByContainerId(o.childContainerId):s=this.getCellByChildBlockId(i,o.blockId):o.blockId!==this.activeTableBlock.id&&(s=this.getCellByChildBlockId(i,o.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});m(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});m(this,"createBkgColorItem",()=>{const t=B("div",["cell-background-color-item"],null);B("span",[],t,D.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();B("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const i=B("span",["item-sub-indicator"],t);return i.innerHTML=Gp,t});m(this,"handleCommand",t=>{var i;p(Pn,this.activeTableBlock,"no target table block");const e=((i=t.states)==null?void 0:i.includes("checked"))||!1,r=t.value;switch(t.id){case"delete-select-row":mC(_y(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":hC(_y(this.editor,this.activeTableBlock,!0));break;case"merge-cell":Ly(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":GP(this.editor,this.activeTableBlock,r==="show-border");break;case"show-chart":XP(this.editor,this.activeTableBlock,r==="show-chart"),bC(this.editor,this.activeTableBlock,{updateNow:!0});break}});m(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&Vu(this.editor,this.editor.selection.range)===this.activeTableBlock&&(Zo(this.editor,this.activeTableBlock,!1),ts(this.editor,this.activeTableBlock,!1)),this.editor.focus()});m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(p(Pn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Zo(this.editor,this.activeTableBlock,!0,!1),ts(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Zo(this.editor,this.activeTableBlock,!0,!0),ts(this.editor,this.activeTableBlock,!0,!0)):(Zo(this.editor,this.activeTableBlock,!1),ts(this.editor,this.activeTableBlock,!1)))});m(this,"handleClick",(t,e)=>{var r;p(Pn,this.activeTableBlock,"no target table block"),p(Pn,this.targetButton,"no target button"),Vk(this.editor),wt(this.targetButton,"active")?(ot(this.targetButton,"active"),(r=this.manualMenu)==null||r.close("clickItem")):(z(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new Qo(this.createCommandMenu(),void 0,{id:"table-cell-menu"}),this.manualMenu.on("click",(i,o)=>{var s;this.handleCommand(o),(s=this.manualMenu)==null||s.close("clickItem")}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",this.handleToolbarClose)),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"})),e.stopPropagation()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close("cancelBar"),this.targetButton&&(ot(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let r=this.editor.getBlockById(e);for(;r;){const i=r.closest("td");p(Pn,i,"no parent cell");const o=J(i);if(p(Pn,o,"no parent block"),Ve(o)===t.table)return t.getCellByCellElement(i);r=o}return p(Pn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${AC}`)||t.appendChild(this.targetButton):(this.targetButton=B("button",[AC],t),this.targetButton.innerHTML=Gh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent),this.editor.domEvents.addEventListener(this.targetButton,"dblclick",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),p(Pn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=It.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:r,row:i}=this.getCellByChildBlockId(t,e.start.blockId);pC(this.editor,this.activeTableBlock,{col:r,row:i})}else CC(this.editor.selection.range)}}getSelectedBkgColorIndex(){var s;p(Pn,this.activeTableBlock,"no target table block");const t=this.editor.selection.range,e=Jo(this.editor,this.activeTableBlock,t.focus),r=this.editor.getBlockData(this.activeTableBlock),i=e.childContainerId,o=r[`${i}_background`];return o?Number.parseInt((s=o.substring(b$.length))!=null?s:"0",10):-1}createCommandMenu(){p(Pn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=Sy(this.editor,this.activeTableBlock,this.editor.selection.range);let r=this.editor.selection.range;if(r.isSimple()){const h=Jo(this.editor,this.activeTableBlock,r.start);r=Xe(this.editor,{anchor:h,focus:h})}const i=wy(this.editor,this.activeTableBlock,r),o=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,d=t.chart;return this.colorPaletteItem=new by("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,C)=>{var E;switch(p(Pn,this.activeTableBlock,"no target table block"),h){case"clearColor":Oy(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":Oy(this.editor,this.activeTableBlock,C);break}(E=this.manualMenu)==null||E.close("clickItem")}),[{id:"cell-background-color",name:D.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:D.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:D.t("table.splitCell"),states:i?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:D.t("table.deleteSelectRow")},{id:"delete-select-col",name:D.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:D.t("table.tableConfigKey"),children:[{id:"row-title",name:D.t("table.tableConfig.rowTitle"),states:o?["checked"]:[]},{id:"col-title",name:D.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:D.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?D.t("table.tableConfig.showBorder"):D.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:d?D.t("table.tableConfig.hideChart"):D.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){p(Pn,this.activeTableBlock,"no target table block"),t?HP(this.editor,this.activeTableBlock):$P(this.editor,this.activeTableBlock)}handleColTitle(t){p(Pn,this.activeTableBlock,"no target table block"),t?VP(this.editor,this.activeTableBlock):KP(this.editor,this.activeTableBlock)}handleStripeStyle(t){p(Pn,this.activeTableBlock,"no target table block"),t?zP(this.editor,this.activeTableBlock):jP(this.editor,this.activeTableBlock)}}function Xk(n){n.addCustom("table-cell-menu",t=>new v$(t))}const _0=I("table-container");function rE(n){const t=n.closest("td");return p(_0,t,"no parent cell for a table cell container"),t}function Yk(n){const t=Ve(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function iE(n,t,e,r){const i=It.fromBlock(n),o=i.getCellByContainerId(ut(t));if(e==="ArrowDown"){const s=i.getBottomCell(o);return s?s.container:null}if(e==="ArrowUp"){const s=i.getTopCell(o);return s?s.container:null}if(e==="ArrowLeft"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(_0,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return r!=null&&r.noWrap&&i.getCellByContainerId(ut(c)).row!==o.row?null:c}if(e==="ArrowRight"){const s=i.getAllContainers(),l=s.indexOf(t);if(p(_0,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return r!=null&&r.noWrap&&i.getCellByContainerId(ut(c)).row!==o.row?null:c}p(_0,!1,`invalid navigation type: ${e}`)}const B$=12,T$=90,M0=23,Qk=2;class y${constructor(t){m(this,"scrollTableBlock",null);m(this,"autoScrollDir",null);m(this,"autoScrollTimer",null);m(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const r=J(e);if(r&&re(this.editor.rootContainer,r)){const i=so(r);i&&(this.scrollTableBlock=i,document.addEventListener("mousemove",this.handleAutoScroll))}}});m(this,"handleAutoScroll",Y6.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=i.getBoundingClientRect(),c=Math.min(l.bottom,s),d=Math.max(l.top,0);o.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):o.top<d&&t.clientY<=d?this.setAutoScroll("top"):r.scrollLeft>0&&t.clientX<o.left?this.setAutoScroll("left"):r.scrollLeft<r.scrollWidth-r.offsetWidth&&t.clientX>o.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));m(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});m(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId),i=so(r);if(i){const o=t.getCustom(Ai(i)),s=o.rootElement.getBoundingClientRect(),l=Fo(t,r,e.start);if(s.left>l.left){const c=e.start.offset===0?B$:Qk;o.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?T$:Qk;o.rootElement.scrollLeft+=l.right-s.right+c}}}else{const r=t.getBlockById(e.start.blockId),i=so(r),o=t.getBlockById(e.end.blockId),s=so(o);if(i&&i===s){const l=t.getCustom(Ai(i)),c=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?Fo(t,r,e.start):Fo(t,o,e.end);else{const h=rE(Sr(t,e.start.childContainerId)),C=rE(Sr(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():C.getBoundingClientRect()}c.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-d.left:c.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-c.right)}}});m(this,"handleScroll",t=>{yy(t),this.editor.selection.caret.update()});m(this,"handleReset",t=>{yy(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),Hk(t)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}getBarFloatWindowBottom(t){return t.scrollOptions.barFloatWindowBottom?typeof t.scrollOptions.barFloatWindowBottom=="number"?t.scrollOptions.barFloatWindowBottom:t.scrollOptions.barFloatWindowBottom():0}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Ai(this.scrollTableBlock)),r=e.rootElement,i=e.scrollOptions.parentContainer,o=r.getBoundingClientRect(),s=i===document.documentElement?window.innerHeight:i.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),c=i.getBoundingClientRect(),d=Math.min(c.bottom,l),h=Math.max(c.top,0);this.autoScrollDir==="left"&&(r.scrollLeft-=M0,r.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(r.scrollLeft+=M0,r.scrollLeft>=r.scrollWidth-r.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(i.scrollTop+=M0,(i.scrollTop>=i.scrollHeight-s||o.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(i.scrollTop-=M0,(i.scrollTop<=0||o.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Jk(n){return n.addCustom("table-scroll-events",t=>new y$(t))}const k$=I("table-doc-change-handler");class R${constructor(t){this.editor=t,this.editor.addListener("docChanged",this.handleDocChanged)}handleDocChanged(t,e){if(!e){const{start:r,end:i}=t.selection.range;if(!t.findBlockById(r.blockId)||!t.findBlockById(i.blockId)){t.selection.selectBlock(t.getBlockByIndex("root",0),0);return}if(ma(r)){const o=t.getBlockById(r.blockId);if(!$e(o))return;if(p(k$,ma(i),"invalid range"),!Zc(t,r.childContainerId)||!Zc(t,i.childContainerId)){t.selection.selectBlock(o,0);return}let s=null,l=null;const c=(d,h)=>{const C=h.getCellById(d.childContainerId),{colIndex:E=0,rowIndex:x=0}=d.custom;let v=-1,R=-1;return(C.col>E||C.col+C.colSpan-1<E)&&(v=C.col),(C.row>x||C.row+C.rowSpan-1<x)&&(R=C.row),v!==-1||R!==-1?Ee(o,d.childContainerId,{colIndex:v===-1?E:v,rowIndex:R===-1?x:R}):null};if(r.custom){const d=It.fromBlock(o);s=c(r,d),l=c(i,d)}(s!==null||l!==null)&&(t.selection.range.isReverse()?t.selection.setSelection(l!=null?l:i,s!=null?s:r):t.selection.setSelection(s!=null?s:r,l!=null?l:i))}}}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged)}}function Zk(n){n.addCustom("table-doc-change-handler",t=>new R$(t))}const bi=I("create-content");function tR(n,t,e){var C;const r=new s0(e),i=e.rows,o=e.cols;p(bi,i>=1,`invalid rows: ${i}`),p(bi,o>=1,`invalid cols: ${o}`),p(bi,e.children,"no table children");const s=B("table",[],null),l=(C=e.colsWidth)!=null?C:new Array(e.cols).fill(0),c=B("colgroup",[],s);for(let E=0;E<r.colCount;E++){const x=B("col",[],c);l[E]&&(x.style.width=`${l[E]}px`)}const d=B("tbody",[],s);let h=0;for(let E=0;E<i;E++){const x=B("tr",[],d);for(let v=0;v<o;v++){const R=r.getCell({col:v,row:E});if(R.virtual)p(bi,R.colSpan>1||R.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const L=e.children[h],M=B("td",[],x);R.colSpan>1&&(M.colSpan=R.colSpan),R.rowSpan>1&&(M.rowSpan=R.rowSpan);const U=e[ju(L)];U&&z(M,U),v===0&&e.hasColTitle&&z(M,Iy.COL_TITLE_ITEM),n.createChildContainer(t,M,L),h+=1}}}return p(bi,h===e.children.length,"container count mismatch"),s.style.minWidth=`${l.reduce((E,x)=>x+E,0)}px`,e.noBorder&&z(s,"no-border"),e.chart&&z(s,"editor-table-chart"),e.isStripeStyle&&z(s,"stripe"),e.hasRowTitle&&z(s,"row-title"),e.hasColTitle&&z(s,"col-title"),s}function w$(n,t,e,r,i){p(bi,i.type==="table","not table data"),p(bi,ut(e)===t[t.length-1].containerId,"invalid path");const o=i,s=$s(r,"div");try{const l=B("div",[],null);l.setAttribute("data-type","table-content");const c=tR(n,t,o);c.classList.add("drag-preview-element"),l.appendChild(c);const d=n.getComponentOptions("table");Yy(n),Zy(n),qk(n,"create"),Zk(n),d!=null&&d.hideCellMenu||Xk(n),c2(n,vC);const h=n.addCustom(Ai(r),()=>xF());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Xt(e)?n.scrollContainer:e,locatingContainer:Xt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:Ha+Hu,paddingTop:Ha+Hu,paddingBottom:Hu/2,paddingRight:Hu/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,allowScrollBarFixed:d==null?void 0:d.allowScrollBarFixed,isSetScale:d==null?void 0:d.isSetScale});const C=Jk(n);h.on("scroll",C.handleReset),h.on("resize",C.handleReset),setTimeout(()=>{JP(n,r)})}catch{const c=`invalid table data: ${JSON.stringify(o)}`;bi.error(c);const d=B("div",["error"],s);d.innerText=c}return s}function S$(n,t,e){p(bi,e.type==="table","not table data");const r=e,i=Ot(t);try{const o=Ve(t),s=Ko(t),l=tR(n,s,r);l.classList.add("drag-preview-element"),o.insertAdjacentElement("afterend",l),o.remove();const c=n.getComponentOptions("table");Yy(n),Zy(n),qk(n,"update"),Zk(n),c!=null&&c.hideCellMenu||Xk(n),vC(n,void 0,t)}catch{const s=`invalid table data: ${JSON.stringify(r)}`;bi.error(s);const l=B("div",["error"],i);l.innerText=s}}function L$(n,t){let e,r,i=!1;if([...t].every(E=>E==="|")?(r=t.length,e=Array(r).fill(""),i=!0):(e=Dg(t,"|").split("|"),r=e.length),r<2)return null;const o=3,s=r,l=[];for(let E=0;E<3;E++)e.forEach(x=>{l.push(Ji(n.doc,E===0?x:""))});const c=Array(s).fill(yC),d=l[i?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:tt(),type:"table",rows:o,cols:s,children:l,colsWidth:c},focusBlockId:h}}function I$(n,t){const e=t.rows,r=t.cols;if(e<1||r<1)return null;const i=[];for(let d=0;d<e;d++)for(let h=0;h<r;h++)i.push(Ji(n.doc));const o=Array(r).fill(yC),s=i[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:tt(),type:"table",rows:e,cols:r,children:i,colsWidth:o},focusBlockId:l}}const oE=I("get-selected-containers");function eR(n,t,e,r){p(oE,e.blockId===r.blockId,"only allow select in single table block"),p(oE,lt(t)===e.blockId,"only allow select in single table block");const i=It.fromBlock(t),o=i.getCellByContainerId(e.childContainerId),s=i.getCellByContainerId(r.childContainerId);if(e.custom===void 0||r.custom===void 0)return i.getCells(o,s).map(L=>i.getCellContainer(L));const{fromCol:l,toCol:c,fromRow:d,toRow:h}=jr(t,e,r),C=new Set,E=[];return i.sub({row:d,col:l},{row:h,col:c}).forEach(v=>{v.forEach(R=>{const L=i.getCellByContainerId(R.containerId);L.col<l||L.row<d||L.col+L.colSpan-1>c||L.row+L.rowSpan-1>h||C.has(R.containerId)||(C.add(R.containerId),E.push(L.container))})}),E}function D$(n,t,e){p(oE,t.blockId===e.blockId,"only allow select in single table block");const r=n.getBlockById(t.blockId);return eR(n,r,t,e)}const nR=I("table-selection-to-doc");function _$(n,t){const{start:e,end:r,block:i}=t,o=Dt(i);p(nR,o==="table",`invalid block type: ${o}`);const s=n.getBlockData(i);if(e.isSimple()&&r.isSimple())return Go(n.editorBlocks,n.doc.toJSON(),s);p(nR,!e.isSimple()&&!r.isSimple(),"invalid block pos type");const l=It.fromBlock(i),{fromCol:c,toCol:d,fromRow:h,toRow:C}=jr(i,e,r),E={},x=[],v=n.doc.toJSON();let R={};l.sub({row:h,col:c},{row:C,col:d}).forEach((rt,st)=>{rt.forEach((Et,vt)=>{const xt=Et.containerId;if(x.indexOf(xt)!==-1)return;x.push(xt);let Gt;if(Et.virtual){const be=l.getCellByContainerId(Et.containerId),Fn=c+vt;let wi=be.col+be.colSpan-1;wi>d&&(wi=d);const kn=wi-Fn+1;kn>1&&(E[`${xt}_colSpan`]=kn);const Cn=h+st;let Si=be.row+be.rowSpan-1;Si>C&&(Si=C);const uo=Si-Cn+1;uo>1&&(E[`${xt}_rowSpan`]=uo),Gt=Qi()}else{if(Gt=np(n.editorBlocks,v,xt),Et.col+Et.colSpan>d+1){const be=d-Et.col+1;be>1&&(E[`${xt}_colSpan`]=be)}else Et.colSpan>1&&(E[`${xt}_colSpan`]=Et.colSpan);if(Et.row+Et.rowSpan>C+1){const be=C-Et.row+1;be>1&&(E[`${xt}_rowSpan`]=be)}else Et.rowSpan>1&&(E[`${xt}_rowSpan`]=Et.rowSpan)}const{root:Yt,...an}=Gt.blocks;R={...R,...an,[xt]:Yt}})});const M=Xu(Ve(i)).slice(c,d+1);return{blocks:{root:[{id:tt(),type:o,children:x,colsWidth:M,rows:C-h+1,cols:d-c+1,...E}],...R},meta:{},comments:{}}}const M$=I("ajust-selection-pos");function U$(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function O$(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function N$(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function P$(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function F$(n,t,e){const r=t.col,i=t.row,o=e.col,s=e.row,l={left:r,top:i,right:o,bottom:s};let c=!1;do{if(c=!1,!U$(n,l)){l.top--,c=!0;continue}if(!O$(n,l)){l.left--,c=!0;continue}if(!N$(n,l)){l.bottom++,c=!0;continue}if(!P$(n,l)){l.right++,c=!0;continue}}while(c);return l}function K$(n,t,e,r){if(e.custom!==void 0||r.custom!==void 0)return{anchor:e,focus:r};const i=It.fromBlock(t),o=i.map(F=>F.containerId),s=i.getCellByContainerId(e.childContainerId),l=i.getCellByContainerId(r.childContainerId),c=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),C=Math.max(s.col,l.col),E=F$(o,{row:c,col:h},{row:d,col:C}),x=i.getCell({row:E.top,col:E.left}),v=i.getCell({row:E.bottom,col:E.right}),R=i.getCell({row:E.top,col:E.right}),L=i.getCell({row:E.bottom,col:E.left});let M,U;return s.row<=l.row?s.col<=l.col?(M=x,U=v):(M=R,U=L):s.col<l.col?(M=L,U=R):(M=v,U=x),M$.debug(`move ${M.col}, ${M.row}, -> ${U.col}, ${U.row}`),{anchor:Ee(t,M.containerId),focus:Ee(t,U.containerId)}}function rR(n,t,e){if(e.isSimple())return[Ve(t).getBoundingClientRect()];const r=Ve(t),i=r.getBoundingClientRect(),{fromCol:o,fromRow:s,toCol:l,toRow:c}=jr(t,e.start,e.end),d=Xu(r),h=d.slice(0,o).reduce((R,L)=>R+L,0),C=h+d.slice(o,l+1).reduce((R,L)=>R+L,0),E=$k(r);let x=E.slice(0,s).reduce((R,L)=>R+L,0);const v=x+E.slice(s,c+1).reduce((R,L)=>R+L,0);if(s===0){const R=p$(n,t);x-=R}return[new DOMRect(i.left+h,i.top+x,C-h,v-x)]}I("table-size");const V$=40;function U0(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),r=Number.parseInt(e.borderLeft,10),i=Number.parseInt(e.borderRight,10);return(r+i)/2}function $$(n,t,e){const r=r1(n,e.container);return r!==void 0?r+U0(t):V$*e.colSpan-U0(t)}function H$(n,t,e,r){let i=0;const o=e.colCount;for(let s=0;s<o;s++){const l=e.getCell({col:s,row:r});if(l.virtual)continue;let c=$$(n,t,l);const d=Qv(l.container,{withPadding:!0});d&&d>c&&(c=d),i+=c+U0(t)}return i}function j$(n,t){const e=Ve(t),r=It.fromTable(e);let i=0;for(let s=0;s<r.rowCount;s++)i=Math.max(i,H$(n,e,r,s));const o=U0(e);return i+=o,i}const lo=I("table-creator");async function z$(n,t){return n.undoManager.runInGroup(()=>{var c,d;const e=t.item,r=(c=e.colCount)!=null?c:5,i=(d=e.rowCount)!=null?d:3,o=I$(n,{cols:r,rows:i});if(!o)return null;const{blockData:s,focusBlockId:l}=o;return n.insertBlock(t.containerId,t.blockIndex,s,ye(n,l,0))})}class G${constructor(){m(this,"id","insert-table");m(this,"name","Create table");m(this,"element");m(this,"closeable",null);m(this,"colCount");m(this,"rowCount");m(this,"setCloseable",t=>{this.closeable=t});m(this,"destroy",()=>{this.closeable=null});m(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);m(this,"handleTableCreatorClick",t=>{var E,x;t.preventDefault(),t.stopPropagation();const e=t.target;p(lo,e instanceof HTMLElement,"invalid event target");const r=e.closest(".table-creator");p(lo,r,"no table creator");const i=r.querySelectorAll(".active");if(i.length===0)return;const s=i[i.length-1].id;p(lo,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");p(lo,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,C=Number.parseInt(d[1],10)+1;lo.debug(`${h}, ${C}`),this.colCount=C,this.rowCount=h,(E=this.closeable)==null||E.click(this,this.element),(x=this.closeable)==null||x.close("clickItem"),this.handleTableCreatorLeave()});m(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const r=this.getTableCreatorCellId(t,e),i=document.getElementById(r);i&&ot(i,"active")}});m(this,"handleTableCreatorCellEnter",t=>{const e=t.target;p(lo,e instanceof HTMLElement,"invalid event target");const r=e.id,i="table-creator-cell-";p(lo,r.startsWith(i),"invalid cell id");const s=r.substring(i.length).split("-");p(lo,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const C=this.getTableCreatorCellId(d,h),E=document.getElementById(C);p(lo,E,"no cell"),d<=l&&h<=c?z(E,"active"):ot(E,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=B("div",["table-creator"],null),e=(r,i,o)=>{const s=B("div",["table-creator-cell"],r);return s.id=this.getTableCreatorCellId(i,o),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let r=0;r<9;r++){const i=B("div",["table-creator-row"],t);for(let o=0;o<9;o++)e(i,r,o).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function W$(){return new G$}function q$(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function iR(n){const t=q$(n);return n.length+t}function X$(n,t,e=[]){let r=0;if(!e||e.length===0)return r;for(let i=n;i<n+t;i+=1)r+=e[i]||0;return r}function Y$(n,t){const e=iR(n),r=t-e;return r>0?n+" ".repeat(r):n}function Q$(n,t,e,r,i){var l;const o=t,s=new s0(o);if(r==="markdown"||r==="text"){const c=M=>e.blocks[M].map((G,W)=>r==="markdown"?Ah(n,G,e,[...i,{containerId:M,blockIndex:W}]):Eh(n,G,e,[...i,{containerId:M,blockIndex:W}])),d=M=>c(M).join(" ").replace(/\n/g," ").trim(),h=new Map,C=new Map;for(let M=0;M<s.colCount;M++){let U=0;for(let F=0;F<s.rowCount;F++){const G=s.getCell({row:F,col:M});let W="";G.virtual||(W=d(G.containerId)),h.set(`${F},${M}`,W),U=Math.max(U,iR(W))}C.set(M,U)}const E=M=>{const U=h.get(`${M.row},${M.col}`)||"",F=C.get(M.col)||0;return Y$(U,F)};if(r==="text"){const M=[];for(let U=0;U<s.colCount;U++){const F=E({row:0,col:U});M.push(F)}for(let U=1;U<s.rowCount;U++)for(let F=0;F<s.colCount;F++){const G=E({row:U,col:F});M.push(G)}return M.join(`
|
|
606
606
|
`)}const x=[];let v="|",R="|";for(let M=0;M<s.colCount;M++){const U=E({row:0,col:M});v+=` ${U} |`;const F="-".repeat((C.get(M)||0)+2);R+=`${F}|`}x.push(v),x.push(R);for(let M=1;M<s.rowCount;M++){let U="|";for(let F=0;F<s.colCount;F++){const G=E({row:M,col:F});U+=` ${G} |`}x.push(U)}return`${x.join(`
|
|
607
607
|
`)}
|
|
608
608
|
`}if(r==="html"){const c=C=>e.blocks[C].map((v,R)=>G1(n,v,e,[...i,{containerId:C,blockIndex:R}])).join(`
|
|
@@ -624,7 +624,7 @@ ${l}`:r==="markdown"?`\`\`\`${i.language}
|
|
|
624
624
|
${s}
|
|
625
625
|
\`\`\`
|
|
626
626
|
${l}`:`<p><pre><code>${Ud(s)}</code></pre></p>
|
|
627
|
-
<p>${Ud(l)}</p>`}function cj(n,t){u2(n,CR)}const hE={blockType:"code",blockKind:"complex",createBlockContent:qH,getBlockTextLength:XH,getRangeFromPoint:YH,moveCaret:QH,getCaretRect:JH,updateSelection:ZH,clearSelection:tj,getChildContainers:ej,getNextContainer:nj,getSelectedContainers:rj,convertFrom:xH,handleBlockElementUpdated:ij,getOptions:sj,getBlockProperties:lj,convertTo:aj,handleDeleteBlock:cj},mE={...Un,blockType:"code-line"};class uj{constructor(t){m(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!ef(this.editor,e))return;const r=e,i=t.range.focus.offset,o=a3(this.editor,r,i,"code-caret");o.scrollIntoView({block:"nearest"}),setTimeout(()=>{o.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function fj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!ef(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{fi(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function dj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!ef(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{fi(n).forEach(i=>{const o=fe(n.getBlockText(i.block));for(let s=0;s<e.length;s++){const l=e[s];if(o.startsWith(l)){n.deleteTextFromBlock(i.block,0,l.length);break}}})}),!0}function hj(n){const t=n.getFocusedBlock(),e=it(t);if(Xt(e))return;const r=J(e);if(!r||Dt(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!V5(e,i))return wh(n,e),!0}const mj={Tab:fj,"Shift+Tab":dj,"CtrlOrCmd+A":hj},nf=I("code-text-decorate");class N0{decorateText(t,e,r){if(p(nf,e.length>0,"invalid path"),e.length===1)return{};const i=e[e.length-2];if(t.doc.getBlockData(i.containerId,i.blockIndex).type!=="code")return{};const s=r;if(s.length===0)return{};const l=fe(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(R=>{if(!R)return oa.default.languages.plain;const L=R.replace(/\s/g,"").toLocaleLowerCase();return oa.default.languages[L]||oa.default.languages.plain})(c.language),C=oa.default.tokenize(l,h),E=(R,L)=>{if(p(nf,R,"no token"),typeof R=="string")return[{insert:R,attributes:mt.default(L)}];p(nf,R instanceof oa.default.Token,"invalid token type");const M=R.content,U=mt.default(L);return U[`style-code-${R.type}`]=!0,typeof M=="string"?[{insert:M,attributes:U}]:Array.isArray(M)?M.filter(W=>W.length).map(W=>E(W,U)).flat():(p(nf,M instanceof oa.default.Token,"invalid token"),E(M,U))},v=C.map(R=>E(R,{})).flat();return p(nf,dn(v)===dn(s),"failed to highlight code, text length mismatch"),{text:v}}}const gj={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},pj={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},Cj={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":gj,"en-US":pj,"ja-JP":Cj});function Ej(n,t,e,r){const i=n.getBlockByIndex(t,e);if(dt(n,i)!==r)return!1;const o=fe(n.getBlockText(i));if(![...o].every(h=>h==="|")||o.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,i,{offset:r});if(!l)return!1;const{blockData:c,focusBlockId:d}=l;return c?(n.undoManager.runInGroup(()=>{var C;const h=n.insertBlock(t,e,c,ye(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const Aj={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\]/i,data:{embedType:"toc"}}},xj={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 P0(n,t,e,r,i){const o=n.getContainerById(t);if(!Xt(o)){const s=J(o);if(s&&Gr(s))return!0}return!1}function ER(n,t,e,r,i){if(P0(n,t))return!1;if(i==="enter"&&Ej(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=fe(Dn(n.getBlockText(o),r).left),l=i==="enter"?Aj:xj;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var v;const h=Gd(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const x=n.insertBlock(t,e,C,ye(n,E!=null?E:C.id,0));return n.deleteBlock(o),(v=h.onConverted)==null||v.call(h,n,x),{newBlock:x,focusBlockId:E}})}return!1}function bj(n,t,e,r){const i=n.getBlockByIndex(t,e);return n.getBlockString(i,{boxReplacement:" "}).substring(0,r)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{quoted:!0},ye(n,i,0))}),!0)}const vj={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function Bj(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=vj[o];if(!s)return!1;const l=n.getBlockData(i).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{heading:s},ye(n,i,0))}),!0}function Tj(n,t,e,r){return!!(Bj(n,t,e,r)||bj(n,t,e,r))}const yj=I("match-text-style");function kj(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),r=e.lastIndexOf(t);return r===-1?-1:r===0?0:e.substring(r-1).startsWith(t)?-1:r}const Rj={"*":{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 wj(n,t,e,r){var E,x;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r),l=P1(s),c=dn(s)-l.length,d=Object.entries(Rj);for(const[v,R]of d){const L=kj(l,v);if(L===-1)continue;const M=c+L,U=r,F=v.length,G=fe(Ye(o,M+F,U-M-F*2).middle);if(R.type==="style"){const W={};R.styles.forEach(st=>{W[st]=!0});const rt=Zs(G,W);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,rt)})}else if(R.type==="box")try{const W=(x=(E=n.editorBoxes.getBoxClass(R.boxType)).convertFrom)==null?void 0:x.call(E,n,G);if(!W)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertBoxToBlock(i,M,W)})}catch(W){yj.warn(`failed to convert to box, ${W.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const v=C.index,R=C[1],L=C[2],M=v,U=r,G={...xa(o,M),link:L};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,Zs(R,G))}),!0}return!1}class F0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(P0(t,e))return!1;if(Tj(t,e,r,i)||wj(t,e,r,i))return!0}return!1}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(nt(t,t.getBlockByIndex(i,o))){if(si(e,"Enter")){if(ER(t,i,o,s,"enter"))return!0}else if(si(e,"Space")&&ER(t,i,o,s,"space"))return!0}return!1}}const Sj={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to 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"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};D.mergeLang(Sj);function rf(n,t){const e=zo(n,t);return!!(nt(n,t)&&e.text&&dn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function AR(n,t){var r;Ot(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function of(n,t,e){var i;if(AR(n,t),!rf(n,t))return;const r=Ot(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=ie(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function Lj(n){const t=n.getAttribute("data-style-heading");return t?D.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?D.t("placeholder.quote"):null}function Ij(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?D.t("placeholder.list"):D.t("placeholder.mention"):null}function xR(n){switch(Dt(n)){case"text":return Lj(n);case"list":return Ij(n);default:return null}}function Dj(n){if(dr(n))return!1;const t=J(it(n));return t?Dt(t)==="code":!1}function _j(n){return!dr(n)}function Mj(n,t){var h,C;const e=n.selection.focusedBlock,r=Dt(e),i=t.contentPlaceholder||D.t("placeholder.default");let o=i;if(r&&eu(n,r)&&e){if(!n.isBlockWritable(e)||Dj(e))return;_j(e)&&(o=D.t("placeholder.common.contentInTable")),o=(h=xR(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:Zt(s);if(!l)return;const c=Zt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&rf(n,l)){of(n,l,(C=xR(l))!=null?C:i);return}const d=n.getFocusedBlock();!rf(n,d)||d===s&&!t.hideTitle||of(n,d,o)}function Uj(n,t){var i,o;const e=n.getFirstBlock(),r=Ot(e);rf(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:D.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function Oj(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 Nj(n,t){Oj(n),n.selection.range.isCollapsed()&&(t.hideTitle||Uj(n,t),Mj(n,t))}const gct="";function Pj(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const bR=I("enforce-title");class gE{constructor(t,e={headingLevel:1}){m(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});m(this,"reload",t=>{this.handleChanged(t),this.applyPlaceholder(t)});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange),setTimeout(()=>{t.addListener("load",this.reload)})}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange),t.removeListener("load",this.reload)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(!this.isDocumentTitleBlock(i,o)||!si(e,"Enter"))return!1;let l=!1,c=null;Lr(t.rootContainer)===2&&(c=Vi(t.rootContainer,1),dt(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ut(t.rootContainer));p(bR,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=mi("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ut(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(bR,o.text,"invalid text block");const s=t.getBlockById(o.id);if(Pj(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=mi(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ut(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=ye(t,c.id,dt(t,C))),vh(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ut(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,r;!((e=this.options)!=null&&e.titlePlaceholder)&&!((r=this.options)!=null&&r.contentPlaceholder)||Nj(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}function Wr(n){return Dt(n)==="embed"&&We(n)==="image"}async function vR(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function Fj(n){const t=await fa(n);return vR(t)}function os(n){return typeof n=="number"}const Kj=I("image-data"),sf=1e3,BR=400,Vj=10;function nc(n){return n.src.startsWith("empty:")||!n.src}function $j(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function TR(n){return`${kd.default(n)}_width`}function yR(n){return`${kd.default(n)}_height`}function kR(n){return`${n}_flex`}function RR(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function rc(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?sf:i.width,s=i.height==="auto"?o/t:i.height/t;return o/s}).reduce((i,o)=>i+o,0);n.forEach(i=>{const o=i.width==="auto"?sf:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function ic(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=TR(i),l=yR(i),c=kR(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),{src:i,width:d!=null?d:"auto",height:h!=null?h:"auto",flex:C,virtualSize:!d||!h}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),rc(e),e}function qr(n){const t=n.embedData;return ic(n.embedData).length>1?100:t.widthPercent}function Hj(n,t,e,r){const i=ic(t.embedData);if(i.length>1||r)return"100%";const o=qr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=RR(e);return`${Math.min(s*o/100,l)}px`}return os(i[0].width)?`${i[0].width}px`:"auto"}function gn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{const s=i.src||`empty:${o}`,l=TR(s);l&&os(i.width)&&(r[l]=i.width);const c=yR(s);c&&os(i.height)&&(r[c]=i.height),p(Kj,i.flex,"no image flex");const d=kR(o);r[d]=i.flex}),r}function jj(n,t,e,r){const i=ic(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${BR}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=qr(t);if(!s){if(i.length!==1||os(i[0].width))return"";const C=i[0].height;return C==="auto"?"auto":`${C}px`}let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,RR(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?sf:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*Vj;const c=i.reduce((h,C)=>h+C.flex,0);let d=0;for(const h of i){const C=l*h.flex/c,E=h.width==="auto"?sf:h.width,x=C/E*h.height;d=Math.max(x,d)}return`${d}px`}function zj(n){return n.reduce((e,r)=>e+r.flex,0)}function Gj(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function pE(n){return ie(n).querySelector(".block-resizer")}function Wj(n){const t=pE(n);t&&ot(t,"active")}function wR(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function qj(n,t,e,r){const i=pE(n);if(i)return z(i,"active"),wR(n,t,i),i;const o=ie(n),s=B("div",["block-resizer"],o);return wR(n,t,s),e.resize.forEach(l=>{Gj(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function CE(n,t){const e=pE(n);if(!e||!re(n,t))return;const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const pct="",Xj=I("block-resizer");class lf extends Be.TypedEmitter{constructor(e,r){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const r=this.getResizableElement();if(!r||e.button!==0)return;const i=e.target;if(!i||!(i instanceof HTMLElement))return;const o=i.getAttribute("data-resize-type");!o||(this.bindEvents(),this.startRect=r.getBoundingClientRect(),this.startPos=e,this.resizeType=o,Wc(window.getComputedStyle(i).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const i=e.x-this.startPos.x,o=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=o),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=o),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=i),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=i);const C=d>c?d-c:0,E=h>l?h-l:0,x=new DOMRect(c,l,C,E);this.emit("resizing",this,x);const v=this.getResizableElement();v&&CE(this.block,v)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;Wc(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||CE(this.block,r)});this.editor=e,this.options=r}enableResize(e,r){this.block=e,this.resizableElement=r,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(Wj(this.block),this.enabled=!1)}update(e,r){this.block=e,this.resizableElement=r,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&CE(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Ot(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(Xj,re(this.block,e),"not a block child element"),qj(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)}}const Yj=I("image-dom");function SR(n){return n.querySelector(".uploading-progress-mask")}function Qj(n){const t=SR(n);if(t)return t;const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e);return B("div",["uploading-progress-bar-value"],r),r}function Jj(n){const e=Qj(n).querySelector(".uploading-progress-bar-value");return p(Yj,e,"no progress value"),e}function LR(n,t){const e=Jj(n);e.style.width=`${t}%`}function Zj(n){var t;(t=SR(n))==null||t.remove()}function af(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||it(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=Hj(n,t,o,s),c=jj(n,t,o,s),d=Ot(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function tz(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function ez(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=tz(t.headers).toLocaleLowerCase();let i="";if(r){const s=Bg.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function ss(n,t){const e=typeof t=="string"?t:lt(t);return n.getCustom(`image-${e}`)}function K0(n,t){if(!t||!(t instanceof Node))return null;const e=J(t);return e?ss(n,e):null}function Bi(n){return Array.from(n.querySelectorAll(".image-container"))}const EE=I("table-resize-drag-drop");class nz{constructor(t,e,r,i){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=r,this.mouseDownEvent=i;const o=this.data.block,l=ss(this.editor,o).getImages(),c=this.data.splitterIndex;p(EE,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Bi(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;ss(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),c=mt.default(l.getImages()),d=this.data.splitterIndex;p(EE,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const R=[...this.initWidths];R[d]+=E,R[d+1]-=E;const L=Bi(s);p(EE,L.length===c.length,"invalid image data");const M=R.reduce((G,W)=>G+W,0);for(let G=0;G<c.length;G++){const W=R[G]/M;c[G].flex=W,L[G].style.flexGrow=`${W}`}const U=mt.default(this.editor.getBlockData(s)),F=gn(c,qr(U));U.embedData=F,af(this.editor,U,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),d=Bi(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function IR(n){var t;return!n||!(n instanceof HTMLElement)?null:wt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function rz(n,t){var s;const e=IR(t.target);if(!e)return;const r=J(e);if(!r)return;ss(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};Ig(new nz(n,e,o,t))}function iz(n,t){t.preventDefault(),t.stopPropagation();const e=IR(t.target);if(!e)return;const r=J(e);!r||ss(n,r).resetFlex()}function oz(n,t,e,r){const i=B("div",["image-splitter"],e);B("div",["image-splitter-indicator"],i),i.setAttribute("data-index",`${r}`),n.domEvents.addEventListener(i,"mousedown",rz),n.domEvents.addEventListener(i,"dblclick",iz)}const sz=I("image-item");function DR(n){return!n||!(n instanceof Node)?null:J(n)}function _R(n){const t=DR(n);return t?Bi(t):[]}function AE(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function cf(n){const t=AE(n);return t?_R(n).indexOf(t):-1}async function lz(n,t){const e=K0(n,t.target);if(!e)return;const r=cf(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(nc(o)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),(o.height==="auto"||o.width==="auto")&&e.fixImageSize(r,i),o.virtualSize&&e.fixImageSize(r,i),!o||!$j(o)||o.downloading))return;o.downloading=!0;const s=await ez(o.src);s?e.replaceImage(r,s):sz.warn(`failed to download image: ${o.src}`)}function az(n,t,e){if(t.querySelector(".load-error"))return;const i=e.src.startsWith("http:")||e.src.startsWith("https:"),o=B("div",["load-error"],t),s=B("div",["error-icon"],o);s.innerHTML=qp;const l=B("div",["error-message"],o);i?(l.innerHTML=D.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=D.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&dz(c,d.target)}))}function xE(n,t){setTimeout(()=>{if(re(n.rootContainer,t)){const e=n.getBlockData(t);af(n,e,null,null)}})}function cz(n,t){const e=K0(n,t.target);if(!e)return;const r=cf(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=AE(t.target);if(!o)return;const s=J(o);let l=!1;n.doc.buildResourceUrl(i.src,{syncNewResources(c,d){var C,E;n.doc.addResources([c]);const h=(E=(C=n.doc).getServerMeta)==null?void 0:E.call(C).appId;if(i.src&&d!==i.src&&h&&i.src.includes(h)&&s&&!n.readonly&&n.isBlockWritable(s)){const x=mt.default(n.getBlockData(s));x.embedData.src=c,n.updateEmbedData(s,x.embedData),l=!0,t.target instanceof HTMLImageElement&&(t.target.src=d)}}}),!l&&(z(o,"error","error-load"),s&&xE(n,s),o.innerHTML="",az(n,o,i))}function uz(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=qp;const s=B("div",["error-message"],i);s.innerHTML=D.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=K0(l,c.target),h=cf(c.target);!d||h===-1||d.replaceImage(h,e)})}function MR(n,t,e,r,i){const o=Bi(t)[e];!o||(z(o,"error","error-upload"),xE(n,t),o.innerHTML="",uz(n,o,i))}function UR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),nc(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=y2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",lz),n.domEvents.addEventListener(c,"error",cz),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=Wp,d.setAttribute(`data-editor-tooltip-${n.clientId}`,D.t("image.load.remote.tooltip"))}return l}function fz(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&oz(n,t,o,l-1),UR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function OR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=UR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),xE(n,t)}function uf(n,t){return Bi(n)[t]}function dz(n,t){const e=DR(t);if(!e)return;const r=cf(t);if(r===-1)return;const i=K0(n,t);if(!i)return;const o=i.getImages()[r];OR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function NR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function PR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=Qc(t.name);if(r&&!r.includes(o.toLowerCase())){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function FR(n){return n.startsWith("image/")}const KR=I("image-object");class Le{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const r=cf(e.target);if(r===-1)return;const i=this.images[r];nc(i)||this.setSelectedIndex(r)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||it(e)===t&&af(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const r=this.editor.findBlockById(this.blockData.id);if(!r)return;this.autoFix||this.setAutoFix(!0);const i=r.querySelector(".images");i.style.height="";const s=this.editor.rootContainer.getBoundingClientRect().width,l=r.getBoundingClientRect();let c=e.width>l.width?l.width:e.width;c<50&&(c=50);const d=c*100/s;this.blockData.embedData.widthPercent=d,af(this.editor,this.blockData,r,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",Me.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new lf(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=ic(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,r){const i=fz(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),_r(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Ds(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),af(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return qr(this.blockData)}isEmpty(){return this.images.length===1&&nc(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const i=uf(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=uf(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=uf(e,t);if(wt(r,"error"))return;const i=NR(this.editor),o=await ha(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=uf(t,0);!this.isEmpty()&&this.images.length===1&&!wt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const r=this.images[t];nc(r)||(os(r.width)&&!os(r.height)?r.height=r.width/e.naturalWidth*e.naturalHeight:os(r.height)&&!os(r.width)?r.width=r.height/e.naturalHeight*e.naturalWidth:(r.width=e.naturalWidth,r.height=e.naturalHeight),r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=mt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,rc(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=gn(r,qr(this.blockData));return this.editor.updateEmbedData(e,i),!0}async replaceImage(t,e){const r=this.editor.findBlockById(this.blockData.id);if(!r)return!1;try{const o=await fa(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await vR(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,rc(this.images);const h=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};OR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return MR(this.editor,r,t,o,e),!1}const i=uf(r,t);if(!i)return!1;z(i,"uploading"),LR(i,0),z(r,"media-block-uploading");try{const o=await this.editor.doc.uploadResource(e,{onProgress:c=>{LR(i,c)}});ot(i,"uploading"),this.images[t].src=o.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=gn(this.images,qr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){KR.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),Zj(i),MR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(KR,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(e,r)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,rc(e);const r=gn(e,qr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=ic(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new Le(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=lt(e),t.getCustom(`image-${r}`)}}const Cct="",Ect="";function V0(n){const t=ie(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function bE(n,t,e){const r=V0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const VR=40,hz=20;class mz{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=J(r);if(c&&re(t.rootContainer,c))return c}let i=e.clientX,o=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;i<s&&s-i<VR&&(i+=VR);let l=document.elementFromPoint(i,o);if(l){const c=J(l);if(c&&re(t.rootContainer,c))return c}if(o-=hz,l=document.elementFromPoint(i,o),l){const c=J(l);if(c&&re(t.rootContainer,c))return c}return null}destroy(){}}class gz extends S0{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const r=this.editor.selection.focusedBlock;this.suggest.popup(r,0,"","")}setBlock(e){this.currentBlock=e}}function pz(n,t,e){const r=t1(n,t);if(!r)return[];const i=[];return Object.values(r).forEach(o=>{e!=null&&e.has(o.group)||i.push(...o.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:o.group})))}),i}function vE(n,t,e={withPlainText:!1}){const r=tE(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function Cz(n,t,e,r=!1){var h,C,E;const i=it(t);let o=t;if(o&&Kt(o)&&OC(o)){if(!r){const x=sK(o);o=(h=Zt(x))!=null?h:x}v0.closeMindmap(n,t)}let l=Bt(o);ue(n,o)||r||(l+=1);const c=ut(i),d=e;return d.commandProvider?d.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:c,blockIndex:l}):(E=(C=d.blockOptions)==null?void 0:C.handleInsertEmptyBlock)==null?void 0:E.call(C,n,{containerId:c,blockIndex:l,item:e})}function Ez(n,t){const e=Ir(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class $R{constructor(t,e,r){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"textStylesTooltips",{});m(this,"createHeadingItemElement",(t,e,r)=>{var o;const i=YC();this.createItem("text",Pa,e,Ez(this.editor,t)),(o=i.insertBlockCommandItems)==null||o.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,r?r===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,r)=>{const{checkbox:i,ordered:o}=r,l=Dt(t)==="list",c=l&&o===!1&&!i,d=l&&o,h=l&&!!i;this.createItem("unordered-list",eC,e,c),this.createItem("ordered-list",nC,e,d),this.createItem("check-list",Zp,e,h)});m(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const r=e.target instanceof Element?e.target:e.target.parentElement;if(!r)return;const i=r.closest(".text-style-item");if(!i)return;const o=i.id,s="heading-";if(o==="text"&&R0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&R0(t,this.block,d)}if(o==="blockquote"&&WC(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");Rk(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&XC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});m(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:D.t("commands.text")},blockquote:{title:D.t("commands.quote")},"align-left":{title:D.t("commands.alignLeft")},"align-center":{title:D.t("commands.alignCenter")},"align-right":{title:D.t("commands.alignRight")},"unordered-list":{title:D.t("commands.unordered")},"ordered-list":{title:D.t("commands.ordered")},"check-list":{title:D.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:D.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",tC,i,!!c)}const s=o.align||"left";return this.createItem("align-left",Na,i,s==="left"),this.createItem("align-center",n0,i,s==="center"),this.createItem("align-right",e0,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=_s(e,o,r);s.id=t;const l=this.textStylesTooltips[t];if(!l)return;const{title:c,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,c),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,ze(d))}}function HR(){return{source:"separator",type:"separator",id:`section-${tt()}`,name:""}}const jR={copy:V2,cut:$2,delete:H2,"lock-block":j2,"unlock-block":z2,comment:ol},Az=["image","video"];function xz(n,t,e){const r=[],i=nt(n,t),o=ge(t)&&Az.includes(We(t)),s=o&&(We(t)!=="image"||We(t)==="image"&&Bi(t).length===1);if(i?r.push(new $R(n,t,e)):o&&s&&r.push(new $R(n,t,{...e,fromEmbed:!0})),!ue(n,t)||UC(t)){(i||o&&s)&&r.push(HR());const l=pz(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in jR&&(c.icon=jR[c.id])}),r.push(...l)}return ue(n,t)&&!UC(t)?r.push(...vE(n,"insert-block")):r.push(HR(),{id:"insert-block-before",icon:G2,name:D.t("blockMenu.command.insertAbove"),children:vE(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:W2,name:D.t("blockMenu.command.insertAfter"),children:vE(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function bz(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;jv(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&Cz(n,t,e,e.source==="insert-block-before")}const vz=I("exclusive-block");function BE(n,t,e,r){var l;z(t,"block-exclusive");const i=Qt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",D.t("exclusive.tips",{editor:r,embedType:s||D.t("exclusive.fallbackAbstract")}))}function zR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function Bz(n,t,e,r,i){vz.debug(`block ${lt(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?BE(n,t,r,i):zR(t)}function ff(n){return n.classList.contains("block-exclusive")}function GR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&Bz(n,r,t.exclusive,t.userId,t.displayName)})}class ls{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(i=>i.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([i,o])=>{if(!e.has(o.userId)){this.remoteExclusiveBlockIds.delete(i);const s={...o,exclusive:!1};GR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;GR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>lt(o)),exclusive:e};this.editor.doc.broadcastMessage(i)}exclusiveBlock(t){this.exclusiveBlockIds.has(lt(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(lt(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(lt(t))||(this.exclusiveBlockIds.delete(lt(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new ls(t))}static register(t){return this.get(t)}}function TE(n,t){ls.get(n).exclusiveBlock(t)}function yE(n,t){ls.get(n).unexclusiveBlock(t)}class WR{writable(t,e){if(Array.isArray(e)){for(const r of e)if(ff(r))return!1;return}if(ff(e))return!1}create(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s&&BE(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s?BE(t,i,s.userId,s.displayName):zR(i)}}const Act="",Tz={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},yz={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},kz={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};D.mergeLang({"zh-CN":Tz,"en-US":yz,"ja-JP":kz});function df(n,t){return n.getBlockData(t).lock}function $0(n,t){return!!df(n,t)}function hf(n,t){const e=df(n,t);return e?e.userId===n.doc.getUser().userId:!1}function kE(n,t){const e=df(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function Rz(n,t){if(n.readonly||!n.isBlockWritable(t)||$0(n,t)&&!hf(n,t))return;const e=n.doc.getUser(),r={userId:e.userId,displayName:e.displayName,locked:Date.now()},o={...n.getBlockData(t),lock:r};n.updateBlockData(t,o)}function wz(n,t){if(!hf(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const Sz=10,Lz=80,Iz=50;class RE{constructor(){m(this,"executeCommand",(t,e,r)=>{const i=r.data;if(!i||!i.blockId)return;const o=t.getBlockById(i.blockId);i.type==="lock"?Rz(t,o):i.type==="unlock"&&wz(t,o)})}create(t,e,r,i,o){const s=o.lock;s&&(s.userId!==t.doc.getUser().userId?z(i,"locked-by-others"):z(i,"locked-by-self"))}update(t,e,r,i,o){const s=o.lock;if(s)if(s.userId!==t.doc.getUser().userId){z(i,"locked-by-others");const l=t.selection.focusedBlock;(l===i||re(i,l))&&(nt(t,i)||Dt(i)==="code")&&t.insertTextBlock("",ut(r),Bt(i)+1)}else z(i,"locked-by-self");else ot(i,"locked-by-others"),ot(i,"locked-by-self")}writable(t,e){let r=[];Array.isArray(e)?r=e:r.push(e);for(const i of r){if(kE(t,i))return!1;if(dr(i))return;let o=Vs(i);for(;o;){if(kE(t,o))return!1;o=Vs(o)}}}commands(t,e){const r=$0(t,e),i=hf(t,e),o=ff(e),s={blockId:lt(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(r)if(i)l.id="unlock-block",l.name=D.t("locker.unlock"),s.type="unlock";else{const c=df(t,e);let d=(c==null?void 0:c.displayName)||"";const h=D.getCurrentLang()==="ja-JP",C=cv(d,Sz,h?Iz:Lz);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=D.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=D.t("locker.lock"),l.states=["disabled"]):l.name=D.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const xct="",Dz={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},_z={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},Mz={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":Dz,"en-US":_z,"ja-JP":Mz});class H0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const Uz=I("standard-block-actions");class Oz{constructor(){m(this,"executeCommand",(t,e,r)=>{const i=r.data;try{const o=t.getBlockById(i);if(r.id==="delete"){t.deleteBlock(o);return}r.id==="copy"&&Ih(t,o),r.id==="cut"&&(Ih(t,o),t.deleteBlock(o))}catch(o){Uz.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=$0(t,e),i=r&&hf(t,e),o=lt(e),s=window.isSecureContext,l=ff(e),c={id:"copy",name:D.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:ze("CtrlOrCmd+C"),operation:D.t("copyCutProperty.copy")})},d={id:"cut",name:D.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:ze("CtrlOrCmd+X"),operation:D.t("copyCutProperty.cut")})},h={id:"delete",name:D.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const qR=I("block-menu");class Nz{constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{p(qR,this.currentBlock,"no target block before show block menu");const t=xz(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{aC(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{p(qR,this.commandBlock,"no command block before show block menu"),bz(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new Qo([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new Oz)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const Pz=1e3;async function Fz(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=Pz?"":(await bb.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const Kz=I("drag-preview-image");class Vz{constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const r=t.target;p(Kz,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=Q2;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),x=this.editor.rootContainer.getBoundingClientRect(),v=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(x.width/2,v.width)}px`,this.dragContainer=s;const L=await Fz(this.editor,e);L?l.src=L:z(s,"drag-placeholder"),wg(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:r}=t;if(e===0&&r===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:i,y:o}=this.startPosition,s=e-i,l=r-o;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const XR="drag-preview-element";function $z(n){if(wt(n,XR))return n;const t=n.querySelector(`.${XR}`);return t||(ge(n)?Ot(n):n)}const j0=I("block-menu-drag-handler");function wE(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class Hz{constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(p(j0,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:r,y:i}=t;this.oldPos={x:r,y:i},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=Ge(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Vd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(j0,r,"no dragged block"),(l=(s=Qt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=wE(t,"dragstart");qz(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=$z(r);this.dragPreview.handleDragStart(t,o),this.autoScroll.active(),z(r,"dragging"),z(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:r,y:i}=t;if(this.oldPos.x===r&&this.oldPos.y===i)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:r,y:i},p(j0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=wE(t,"dragover");this.editor.contentElement.dispatchEvent(o)});m(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(j0,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(i=this.autoScroll)==null||i.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const r=wE(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new Vz(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class mf{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=lt(t),z(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new mf(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class YR{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,r)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const i=this.editor.getCustom("editor-tooltip");if(i&&i.visible()&&(i.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(r.target)||this.buttonElement.remove());return}const o=Zg(t);$i(o)||(this.updateButton(o),bE(o,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const r=this.blockMenu.currentBlock;if(!r)return;this.editor.selection.selectBlock(r,0,void 0,{noScroll:!0}),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{mf.get(this.editor).highlightBlock(r)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0,void 0,{noScroll:!0}),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{of(this.editor,t,D.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;if(this.blockMenu.currentBlock){const r=lt(this.blockMenu.currentBlock);if(!this.editor.findBlockById(r)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const e=ue(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new gz(t),this.blockMenu=new Nz(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new Hz(this.editor,this);const e=Te.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new mz),mf.register(this.editor)}destroy(){Te.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=B("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,D.t("blockMenu.button.tips")),t.innerHTML=rC,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=Y2,this.buttonElement.setAttribute(e,D.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=rC,this.buttonElement.setAttribute(e,D.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),ue(this.editor,t)&&!(Kt(t)&&UC(t))?this.setButtonType("insert"):this.setButtonType("move")}}const jz={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
627
|
+
<p>${Ud(l)}</p>`}function cj(n,t){u2(n,CR)}const hE={blockType:"code",blockKind:"complex",createBlockContent:qH,getBlockTextLength:XH,getRangeFromPoint:YH,moveCaret:QH,getCaretRect:JH,updateSelection:ZH,clearSelection:tj,getChildContainers:ej,getNextContainer:nj,getSelectedContainers:rj,convertFrom:xH,handleBlockElementUpdated:ij,getOptions:sj,getBlockProperties:lj,convertTo:aj,handleDeleteBlock:cj},mE={...Un,blockType:"code-line"};class uj{constructor(t){m(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!ef(this.editor,e))return;const r=e,i=t.range.focus.offset,o=a3(this.editor,r,i,"code-caret");o.scrollIntoView({block:"nearest"}),setTimeout(()=>{o.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function fj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!ef(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{fi(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function dj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!ef(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{fi(n).forEach(i=>{const o=fe(n.getBlockText(i.block));for(let s=0;s<e.length;s++){const l=e[s];if(o.startsWith(l)){n.deleteTextFromBlock(i.block,0,l.length);break}}})}),!0}function hj(n){const t=n.getFocusedBlock(),e=it(t);if(Xt(e))return;const r=J(e);if(!r||Dt(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!V5(e,i))return wh(n,e),!0}const mj={Tab:fj,"Shift+Tab":dj,"CtrlOrCmd+A":hj},nf=I("code-text-decorate");class N0{decorateText(t,e,r){if(p(nf,e.length>0,"invalid path"),e.length===1)return{};const i=e[e.length-2];if(t.doc.getBlockData(i.containerId,i.blockIndex).type!=="code")return{};const s=r;if(s.length===0)return{};const l=fe(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(R=>{if(!R)return oa.default.languages.plain;const L=R.replace(/\s/g,"").toLocaleLowerCase();return oa.default.languages[L]||oa.default.languages.plain})(c.language),C=oa.default.tokenize(l,h),E=(R,L)=>{if(p(nf,R,"no token"),typeof R=="string")return[{insert:R,attributes:mt.default(L)}];p(nf,R instanceof oa.default.Token,"invalid token type");const M=R.content,U=mt.default(L);return U[`style-code-${R.type}`]=!0,typeof M=="string"?[{insert:M,attributes:U}]:Array.isArray(M)?M.filter(W=>W.length).map(W=>E(W,U)).flat():(p(nf,M instanceof oa.default.Token,"invalid token"),E(M,U))},v=C.map(R=>E(R,{})).flat();return p(nf,dn(v)===dn(s),"failed to highlight code, text length mismatch"),{text:v}}}const gj={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},pj={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},Cj={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":gj,"en-US":pj,"ja-JP":Cj});function Ej(n,t,e,r){const i=n.getBlockByIndex(t,e);if(dt(n,i)!==r)return!1;const o=fe(n.getBlockText(i));if(![...o].every(h=>h==="|")||o.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,i,{offset:r});if(!l)return!1;const{blockData:c,focusBlockId:d}=l;return c?(n.undoManager.runInGroup(()=>{var C;const h=n.insertBlock(t,e,c,ye(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const Aj={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\]/i,data:{embedType:"toc"}}},xj={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 P0(n,t,e,r,i){const o=n.getContainerById(t);if(!Xt(o)){const s=J(o);if(s&&Gr(s))return!0}return!1}function ER(n,t,e,r,i){if(P0(n,t))return!1;if(i==="enter"&&Ej(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=fe(Dn(n.getBlockText(o),r).left),l=i==="enter"?Aj:xj;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var v;const h=Gd(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const x=n.insertBlock(t,e,C,ye(n,E!=null?E:C.id,0));return n.deleteBlock(o),(v=h.onConverted)==null||v.call(h,n,x),{newBlock:x,focusBlockId:E}})}return!1}function bj(n,t,e,r){const i=n.getBlockByIndex(t,e);return n.getBlockString(i,{boxReplacement:" "}).substring(0,r)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{quoted:!0},ye(n,i,0))}),!0)}const vj={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function Bj(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=vj[o];if(!s)return!1;const l=n.getBlockData(i).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{heading:s},ye(n,i,0))}),!0}function Tj(n,t,e,r){return!!(Bj(n,t,e,r)||bj(n,t,e,r))}const yj=I("match-text-style");function kj(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),r=e.lastIndexOf(t);return r===-1?-1:r===0?0:e.substring(r-1).startsWith(t)?-1:r}const Rj={"*":{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 wj(n,t,e,r){var E,x;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r),l=P1(s),c=dn(s)-l.length,d=Object.entries(Rj);for(const[v,R]of d){const L=kj(l,v);if(L===-1)continue;const M=c+L,U=r,F=v.length,G=fe(Ye(o,M+F,U-M-F*2).middle);if(R.type==="style"){const W={};R.styles.forEach(st=>{W[st]=!0});const rt=Zs(G,W);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,rt)})}else if(R.type==="box")try{const W=(x=(E=n.editorBoxes.getBoxClass(R.boxType)).convertFrom)==null?void 0:x.call(E,n,G);if(!W)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertBoxToBlock(i,M,W)})}catch(W){yj.warn(`failed to convert to box, ${W.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const v=C.index,R=C[1],L=C[2],M=v,U=r,G={...xa(o,M),link:L};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,M,U-M),n.insertTextToBlock(i,M,Zs(R,G))}),!0}return!1}class F0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(P0(t,e))return!1;if(Tj(t,e,r,i)||wj(t,e,r,i))return!0}return!1}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(nt(t,t.getBlockByIndex(i,o))){if(si(e,"Enter")){if(ER(t,i,o,s,"enter"))return!0}else if(si(e,"Space")&&ER(t,i,o,s,"space"))return!0}return!1}}const Sj={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to 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"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};D.mergeLang(Sj);function rf(n,t){const e=zo(n,t);return!!(nt(n,t)&&e.text&&dn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function AR(n,t){var r;Ot(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function of(n,t,e){var i;if(AR(n,t),!rf(n,t))return;const r=Ot(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=ie(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function Lj(n){const t=n.getAttribute("data-style-heading");return t?D.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?D.t("placeholder.quote"):null}function Ij(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?D.t("placeholder.list"):D.t("placeholder.mention"):null}function xR(n){switch(Dt(n)){case"text":return Lj(n);case"list":return Ij(n);default:return null}}function Dj(n){if(dr(n))return!1;const t=J(it(n));return t?Dt(t)==="code":!1}function _j(n){return!dr(n)}function Mj(n,t){var h,C;const e=n.selection.focusedBlock,r=Dt(e),i=t.contentPlaceholder||D.t("placeholder.default");let o=i;if(r&&eu(n,r)&&e){if(!n.isBlockWritable(e)||Dj(e))return;_j(e)&&(o=D.t("placeholder.common.contentInTable")),o=(h=xR(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:Zt(s);if(!l)return;const c=Zt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&rf(n,l)){of(n,l,(C=xR(l))!=null?C:i);return}const d=n.getFocusedBlock();!rf(n,d)||d===s&&!t.hideTitle||of(n,d,o)}function Uj(n,t){var i,o;const e=n.getFirstBlock(),r=Ot(e);rf(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:D.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function Oj(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 Nj(n,t){Oj(n),n.selection.range.isCollapsed()&&(t.hideTitle||Uj(n,t),Mj(n,t))}const gct="";function Pj(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const bR=I("enforce-title");class gE{constructor(t,e={headingLevel:1}){m(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});m(this,"reload",t=>{this.handleChanged(t),this.applyPlaceholder(t)});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange),setTimeout(()=>{t.addListener("load",this.reload)})}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange),t.removeListener("load",this.reload)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(!this.isDocumentTitleBlock(i,o)||!si(e,"Enter"))return!1;let l=!1,c=null;Lr(t.rootContainer)===2&&(c=Vi(t.rootContainer,1),dt(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ut(t.rootContainer));p(bR,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=mi("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ut(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(bR,o.text,"invalid text block");const s=t.getBlockById(o.id);if(Pj(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=mi(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ut(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=ye(t,c.id,dt(t,C))),vh(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ut(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,r;!((e=this.options)!=null&&e.titlePlaceholder)&&!((r=this.options)!=null&&r.contentPlaceholder)||Nj(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}function Wr(n){return Dt(n)==="embed"&&We(n)==="image"}async function vR(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function Fj(n){const t=await fa(n);return vR(t)}function os(n){return typeof n=="number"}const Kj=I("image-data"),sf=1e3,BR=400,Vj=10;function nc(n){return n.src.startsWith("empty:")||!n.src}function $j(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function TR(n){return`${kd.default(n)}_width`}function yR(n){return`${kd.default(n)}_height`}function kR(n){return`${n}_flex`}function RR(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function rc(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?sf:i.width,s=i.height==="auto"?o/t:i.height/t;return o/s}).reduce((i,o)=>i+o,0);n.forEach(i=>{const o=i.width==="auto"?sf:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function ic(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=TR(i),l=yR(i),c=kR(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),{src:i,width:d!=null?d:"auto",height:h!=null?h:"auto",flex:C,virtualSize:!d||!h}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),rc(e),e}function qr(n){const t=n.embedData;return ic(n.embedData).length>1?100:t.widthPercent}function Hj(n,t,e,r){const i=ic(t.embedData);if(i.length>1||r)return"100%";const o=qr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=RR(e);return`${Math.min(s*o/100,l)}px`}return os(i[0].width)?`${i[0].width}px`:"auto"}function gn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{const s=i.src||`empty:${o}`,l=TR(s);l&&os(i.width)&&(r[l]=i.width);const c=yR(s);c&&os(i.height)&&(r[c]=i.height),p(Kj,i.flex,"no image flex");const d=kR(o);r[d]=i.flex}),r}function jj(n,t,e,r){const i=ic(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${BR}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=qr(t);if(!s){if(i.length!==1||os(i[0].width))return"";const C=i[0].height;return C==="auto"?"auto":`${C}px`}let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,RR(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?sf:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*Vj;const c=i.reduce((h,C)=>h+C.flex,0);let d=0;for(const h of i){const C=l*h.flex/c,E=h.width==="auto"?sf:h.width,x=C/E*h.height;d=Math.max(x,d)}return`${d}px`}function zj(n){return n.reduce((e,r)=>e+r.flex,0)}function Gj(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function pE(n){return ie(n).querySelector(".block-resizer")}function Wj(n){const t=pE(n);t&&ot(t,"active")}function wR(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function qj(n,t,e,r){const i=pE(n);if(i)return z(i,"active"),wR(n,t,i),i;const o=ie(n),s=B("div",["block-resizer"],o);return wR(n,t,s),e.resize.forEach(l=>{Gj(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function CE(n,t){const e=pE(n);if(!e||!re(n,t))return;const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const pct="",Xj=I("block-resizer");class lf extends Be.TypedEmitter{constructor(e,r){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const r=this.getResizableElement();if(!r||e.button!==0)return;const i=e.target;if(!i||!(i instanceof HTMLElement))return;const o=i.getAttribute("data-resize-type");!o||(this.bindEvents(),this.startRect=r.getBoundingClientRect(),this.startPos=e,this.resizeType=o,Wc(window.getComputedStyle(i).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const i=e.x-this.startPos.x,o=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=o),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=o),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=i),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=i);const C=d>c?d-c:0,E=h>l?h-l:0,x=new DOMRect(c,l,C,E);this.emit("resizing",this,x);const v=this.getResizableElement();v&&CE(this.block,v)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;Wc(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||CE(this.block,r)});this.editor=e,this.options=r}enableResize(e,r){this.block=e,this.resizableElement=r,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(Wj(this.block),this.enabled=!1)}update(e,r){this.block=e,this.resizableElement=r,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&CE(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Ot(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(Xj,re(this.block,e),"not a block child element"),qj(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)}}const Yj=I("image-dom");function SR(n){return n.querySelector(".uploading-progress-mask")}function Qj(n){const t=SR(n);if(t)return t;const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e);return B("div",["uploading-progress-bar-value"],r),r}function Jj(n){const e=Qj(n).querySelector(".uploading-progress-bar-value");return p(Yj,e,"no progress value"),e}function LR(n,t){const e=Jj(n);e.style.width=`${t}%`}function Zj(n){var t;(t=SR(n))==null||t.remove()}function af(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||it(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=Hj(n,t,o,s),c=jj(n,t,o,s),d=Ot(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function tz(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function ez(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=tz(t.headers).toLocaleLowerCase();let i="";if(r){const s=Bg.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function ss(n,t){const e=typeof t=="string"?t:lt(t);return n.getCustom(`image-${e}`)}function K0(n,t){if(!t||!(t instanceof Node))return null;const e=J(t);return e?ss(n,e):null}function Bi(n){return Array.from(n.querySelectorAll(".image-container"))}const EE=I("table-resize-drag-drop");class nz{constructor(t,e,r,i){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=r,this.mouseDownEvent=i;const o=this.data.block,l=ss(this.editor,o).getImages(),c=this.data.splitterIndex;p(EE,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Bi(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;ss(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),c=mt.default(l.getImages()),d=this.data.splitterIndex;p(EE,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const R=[...this.initWidths];R[d]+=E,R[d+1]-=E;const L=Bi(s);p(EE,L.length===c.length,"invalid image data");const M=R.reduce((G,W)=>G+W,0);for(let G=0;G<c.length;G++){const W=R[G]/M;c[G].flex=W,L[G].style.flexGrow=`${W}`}const U=mt.default(this.editor.getBlockData(s)),F=gn(c,qr(U));U.embedData=F,af(this.editor,U,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),d=Bi(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function IR(n){var t;return!n||!(n instanceof HTMLElement)?null:wt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function rz(n,t){var s;const e=IR(t.target);if(!e)return;const r=J(e);if(!r)return;ss(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};Ig(new nz(n,e,o,t))}function iz(n,t){t.preventDefault(),t.stopPropagation();const e=IR(t.target);if(!e)return;const r=J(e);!r||ss(n,r).resetFlex()}function oz(n,t,e,r){const i=B("div",["image-splitter"],e);B("div",["image-splitter-indicator"],i),i.setAttribute("data-index",`${r}`),n.domEvents.addEventListener(i,"mousedown",rz),n.domEvents.addEventListener(i,"dblclick",iz)}const sz=I("image-item");function DR(n){return!n||!(n instanceof Node)?null:J(n)}function _R(n){const t=DR(n);return t?Bi(t):[]}function AE(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function cf(n){const t=AE(n);return t?_R(n).indexOf(t):-1}async function lz(n,t){const e=K0(n,t.target);if(!e)return;const r=cf(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(nc(o)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),(o.height==="auto"||o.width==="auto")&&e.fixImageSize(r,i),o.virtualSize&&e.fixImageSize(r,i),!o||!$j(o)||o.downloading))return;o.downloading=!0;const s=await ez(o.src);s?e.replaceImage(r,s):sz.warn(`failed to download image: ${o.src}`)}function az(n,t,e){if(t.querySelector(".load-error"))return;const i=e.src.startsWith("http:")||e.src.startsWith("https:"),o=B("div",["load-error"],t),s=B("div",["error-icon"],o);s.innerHTML=qp;const l=B("div",["error-message"],o);i?(l.innerHTML=D.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=D.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&dz(c,d.target)}))}function xE(n,t){setTimeout(()=>{if(re(n.rootContainer,t)){const e=n.getBlockData(t);af(n,e,null,null)}})}function cz(n,t){const e=K0(n,t.target);if(!e)return;const r=cf(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=AE(t.target);if(!o)return;const s=J(o);let l=!1;n.doc.buildResourceUrl(i.src,{syncNewResources(c,d){var C,E;n.doc.addResources([c]);const h=(E=(C=n.doc).getServerMeta)==null?void 0:E.call(C).appId;if(i.src&&d!==i.src&&h&&i.src.includes(h)&&s&&!n.readonly&&n.isBlockWritable(s)){const x=mt.default(n.getBlockData(s));x.embedData.src=c,n.updateEmbedData(s,x.embedData),l=!0,t.target instanceof HTMLImageElement&&(t.target.src=d)}}}),!l&&(z(o,"error","error-load"),s&&xE(n,s),o.innerHTML="",az(n,o,i))}function uz(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=qp;const s=B("div",["error-message"],i);s.innerHTML=D.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=K0(l,c.target),h=cf(c.target);!d||h===-1||d.replaceImage(h,e)})}function MR(n,t,e,r,i){const o=Bi(t)[e];!o||(z(o,"error","error-upload"),xE(n,t),o.innerHTML="",uz(n,o,i))}function UR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),nc(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=y2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",lz),n.domEvents.addEventListener(c,"error",cz),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=Wp,d.setAttribute(`data-editor-tooltip-${n.clientId}`,D.t("image.load.remote.tooltip"))}return l}function fz(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&oz(n,t,o,l-1),UR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function OR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=UR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),xE(n,t)}function uf(n,t){return Bi(n)[t]}function dz(n,t){const e=DR(t);if(!e)return;const r=cf(t);if(r===-1)return;const i=K0(n,t);if(!i)return;const o=i.getImages()[r];OR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function NR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function PR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=Qc(t.name);if(r&&!r.includes(o.toLowerCase())){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function FR(n){return n.startsWith("image/")}const KR=I("image-object");class Le{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const r=cf(e.target);if(r===-1)return;const i=this.images[r];nc(i)||this.setSelectedIndex(r)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||it(e)===t&&af(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const r=this.editor.findBlockById(this.blockData.id);if(!r)return;this.autoFix||this.setAutoFix(!0);const i=r.querySelector(".images");i.style.height="";const s=this.editor.rootContainer.getBoundingClientRect().width,l=r.getBoundingClientRect();let c=e.width>l.width?l.width:e.width;c<50&&(c=50);const d=c*100/s;this.blockData.embedData.widthPercent=d,af(this.editor,this.blockData,r,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",Me.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new lf(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=ic(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,r){const i=fz(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),_r(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Ds(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),af(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return qr(this.blockData)}isEmpty(){return this.images.length===1&&nc(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const i=uf(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=uf(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=uf(e,t);if(wt(r,"error"))return;const i=NR(this.editor),o=await ha(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=uf(t,0);!this.isEmpty()&&this.images.length===1&&!wt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const r=this.images[t];nc(r)||(os(r.width)&&!os(r.height)?r.height=r.width/e.naturalWidth*e.naturalHeight:os(r.height)&&!os(r.width)?r.width=r.height/e.naturalHeight*e.naturalWidth:(r.width=e.naturalWidth,r.height=e.naturalHeight),r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=mt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,rc(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=gn(r,qr(this.blockData));return this.editor.updateEmbedData(e,i),!0}async replaceImage(t,e){const r=this.editor.findBlockById(this.blockData.id);if(!r)return!1;try{const o=await fa(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await vR(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,rc(this.images);const h=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};OR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return MR(this.editor,r,t,o,e),!1}const i=uf(r,t);if(!i)return!1;z(i,"uploading"),LR(i,0),z(r,"media-block-uploading");try{const o=await this.editor.doc.uploadResource(e,{onProgress:c=>{LR(i,c)}});ot(i,"uploading"),this.images[t].src=o.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=gn(this.images,qr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){KR.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),Zj(i),MR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(KR,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=gn(this.images,qr(this.blockData));this.editor.updateEmbedData(e,r)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,rc(e);const r=gn(e,qr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=ic(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new Le(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=lt(e),t.getCustom(`image-${r}`)}}const Cct="",Ect="";function V0(n){const t=ie(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function bE(n,t,e){const r=V0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const VR=40,hz=20;class mz{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=J(r);if(c&&re(t.rootContainer,c))return c}let i=e.clientX,o=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;i<s&&s-i<VR&&(i+=VR);let l=document.elementFromPoint(i,o);if(l){const c=J(l);if(c&&re(t.rootContainer,c))return c}if(o-=hz,l=document.elementFromPoint(i,o),l){const c=J(l);if(c&&re(t.rootContainer,c))return c}return null}destroy(){}}class gz extends S0{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const r=this.editor.selection.focusedBlock;this.suggest.popup(r,0,"","")}setBlock(e){this.currentBlock=e}}function pz(n,t,e){const r=t1(n,t);if(!r)return[];const i=[];return Object.values(r).forEach(o=>{e!=null&&e.has(o.group)||i.push(...o.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:o.group})))}),i}function vE(n,t,e={withPlainText:!1}){const r=tE(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function Cz(n,t,e,r=!1){var h,C,E;const i=it(t);let o=t;if(o&&Kt(o)&&OC(o)){if(!r){const x=sK(o);o=(h=Zt(x))!=null?h:x}v0.closeMindmap(n,t)}let l=Bt(o);ue(n,o)||r||(l+=1);const c=ut(i),d=e;return d.commandProvider?d.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:c,blockIndex:l}):(E=(C=d.blockOptions)==null?void 0:C.handleInsertEmptyBlock)==null?void 0:E.call(C,n,{containerId:c,blockIndex:l,item:e,from:"block-menu"})}function Ez(n,t){const e=Ir(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class $R{constructor(t,e,r){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"textStylesTooltips",{});m(this,"createHeadingItemElement",(t,e,r)=>{var o;const i=YC();this.createItem("text",Pa,e,Ez(this.editor,t)),(o=i.insertBlockCommandItems)==null||o.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,r?r===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,r)=>{const{checkbox:i,ordered:o}=r,l=Dt(t)==="list",c=l&&o===!1&&!i,d=l&&o,h=l&&!!i;this.createItem("unordered-list",eC,e,c),this.createItem("ordered-list",nC,e,d),this.createItem("check-list",Zp,e,h)});m(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const r=e.target instanceof Element?e.target:e.target.parentElement;if(!r)return;const i=r.closest(".text-style-item");if(!i)return;const o=i.id,s="heading-";if(o==="text"&&R0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&R0(t,this.block,d)}if(o==="blockquote"&&WC(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");Rk(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&XC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});m(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:D.t("commands.text")},blockquote:{title:D.t("commands.quote")},"align-left":{title:D.t("commands.alignLeft")},"align-center":{title:D.t("commands.alignCenter")},"align-right":{title:D.t("commands.alignRight")},"unordered-list":{title:D.t("commands.unordered")},"ordered-list":{title:D.t("commands.ordered")},"check-list":{title:D.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:D.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",tC,i,!!c)}const s=o.align||"left";return this.createItem("align-left",Na,i,s==="left"),this.createItem("align-center",n0,i,s==="center"),this.createItem("align-right",e0,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=_s(e,o,r);s.id=t;const l=this.textStylesTooltips[t];if(!l)return;const{title:c,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,c),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,ze(d))}}function HR(){return{source:"separator",type:"separator",id:`section-${tt()}`,name:""}}const jR={copy:V2,cut:$2,delete:H2,"lock-block":j2,"unlock-block":z2,comment:ol},Az=["image","video"];function xz(n,t,e){const r=[],i=nt(n,t),o=ge(t)&&Az.includes(We(t)),s=o&&(We(t)!=="image"||We(t)==="image"&&Bi(t).length===1);if(i?r.push(new $R(n,t,e)):o&&s&&r.push(new $R(n,t,{...e,fromEmbed:!0})),!ue(n,t)||UC(t)){(i||o&&s)&&r.push(HR());const l=pz(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in jR&&(c.icon=jR[c.id])}),r.push(...l)}return ue(n,t)&&!UC(t)?r.push(...vE(n,"insert-block")):r.push(HR(),{id:"insert-block-before",icon:G2,name:D.t("blockMenu.command.insertAbove"),children:vE(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:W2,name:D.t("blockMenu.command.insertAfter"),children:vE(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function bz(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;jv(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&Cz(n,t,e,e.source==="insert-block-before")}const vz=I("exclusive-block");function BE(n,t,e,r){var l;z(t,"block-exclusive");const i=Qt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",D.t("exclusive.tips",{editor:r,embedType:s||D.t("exclusive.fallbackAbstract")}))}function zR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function Bz(n,t,e,r,i){vz.debug(`block ${lt(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?BE(n,t,r,i):zR(t)}function ff(n){return n.classList.contains("block-exclusive")}function GR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&Bz(n,r,t.exclusive,t.userId,t.displayName)})}class ls{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(i=>i.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([i,o])=>{if(!e.has(o.userId)){this.remoteExclusiveBlockIds.delete(i);const s={...o,exclusive:!1};GR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;GR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>lt(o)),exclusive:e};this.editor.doc.broadcastMessage(i)}exclusiveBlock(t){this.exclusiveBlockIds.has(lt(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(lt(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(lt(t))||(this.exclusiveBlockIds.delete(lt(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new ls(t))}static register(t){return this.get(t)}}function TE(n,t){ls.get(n).exclusiveBlock(t)}function yE(n,t){ls.get(n).unexclusiveBlock(t)}class WR{writable(t,e){if(Array.isArray(e)){for(const r of e)if(ff(r))return!1;return}if(ff(e))return!1}create(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s&&BE(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s?BE(t,i,s.userId,s.displayName):zR(i)}}const Act="",Tz={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},yz={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},kz={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};D.mergeLang({"zh-CN":Tz,"en-US":yz,"ja-JP":kz});function df(n,t){return n.getBlockData(t).lock}function $0(n,t){return!!df(n,t)}function hf(n,t){const e=df(n,t);return e?e.userId===n.doc.getUser().userId:!1}function kE(n,t){const e=df(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function Rz(n,t){if(n.readonly||!n.isBlockWritable(t)||$0(n,t)&&!hf(n,t))return;const e=n.doc.getUser(),r={userId:e.userId,displayName:e.displayName,locked:Date.now()},o={...n.getBlockData(t),lock:r};n.updateBlockData(t,o)}function wz(n,t){if(!hf(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const Sz=10,Lz=80,Iz=50;class RE{constructor(){m(this,"executeCommand",(t,e,r)=>{const i=r.data;if(!i||!i.blockId)return;const o=t.getBlockById(i.blockId);i.type==="lock"?Rz(t,o):i.type==="unlock"&&wz(t,o)})}create(t,e,r,i,o){const s=o.lock;s&&(s.userId!==t.doc.getUser().userId?z(i,"locked-by-others"):z(i,"locked-by-self"))}update(t,e,r,i,o){const s=o.lock;if(s)if(s.userId!==t.doc.getUser().userId){z(i,"locked-by-others");const l=t.selection.focusedBlock;(l===i||re(i,l))&&(nt(t,i)||Dt(i)==="code")&&t.insertTextBlock("",ut(r),Bt(i)+1)}else z(i,"locked-by-self");else ot(i,"locked-by-others"),ot(i,"locked-by-self")}writable(t,e){let r=[];Array.isArray(e)?r=e:r.push(e);for(const i of r){if(kE(t,i))return!1;if(dr(i))return;let o=Vs(i);for(;o;){if(kE(t,o))return!1;o=Vs(o)}}}commands(t,e){const r=$0(t,e),i=hf(t,e),o=ff(e),s={blockId:lt(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(r)if(i)l.id="unlock-block",l.name=D.t("locker.unlock"),s.type="unlock";else{const c=df(t,e);let d=(c==null?void 0:c.displayName)||"";const h=D.getCurrentLang()==="ja-JP",C=cv(d,Sz,h?Iz:Lz);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=D.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=D.t("locker.lock"),l.states=["disabled"]):l.name=D.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const xct="",Dz={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},_z={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},Mz={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":Dz,"en-US":_z,"ja-JP":Mz});class H0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const Uz=I("standard-block-actions");class Oz{constructor(){m(this,"executeCommand",(t,e,r)=>{const i=r.data;try{const o=t.getBlockById(i);if(r.id==="delete"){t.deleteBlock(o);return}r.id==="copy"&&Ih(t,o),r.id==="cut"&&(Ih(t,o),t.deleteBlock(o))}catch(o){Uz.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=$0(t,e),i=r&&hf(t,e),o=lt(e),s=window.isSecureContext,l=ff(e),c={id:"copy",name:D.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:ze("CtrlOrCmd+C"),operation:D.t("copyCutProperty.copy")})},d={id:"cut",name:D.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:ze("CtrlOrCmd+X"),operation:D.t("copyCutProperty.cut")})},h={id:"delete",name:D.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const qR=I("block-menu");class Nz{constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{p(qR,this.currentBlock,"no target block before show block menu");const t=xz(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{aC(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{p(qR,this.commandBlock,"no command block before show block menu"),bz(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new Qo([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new Oz)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const Pz=1e3;async function Fz(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=Pz?"":(await bb.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const Kz=I("drag-preview-image");class Vz{constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const r=t.target;p(Kz,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=Q2;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),x=this.editor.rootContainer.getBoundingClientRect(),v=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(x.width/2,v.width)}px`,this.dragContainer=s;const L=await Fz(this.editor,e);L?l.src=L:z(s,"drag-placeholder"),wg(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:r}=t;if(e===0&&r===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:i,y:o}=this.startPosition,s=e-i,l=r-o;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const XR="drag-preview-element";function $z(n){if(wt(n,XR))return n;const t=n.querySelector(`.${XR}`);return t||(ge(n)?Ot(n):n)}const j0=I("block-menu-drag-handler");function wE(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class Hz{constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(p(j0,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:r,y:i}=t;this.oldPos={x:r,y:i},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=Ge(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Vd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(j0,r,"no dragged block"),(l=(s=Qt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=wE(t,"dragstart");qz(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=$z(r);this.dragPreview.handleDragStart(t,o),this.autoScroll.active(),z(r,"dragging"),z(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:r,y:i}=t;if(this.oldPos.x===r&&this.oldPos.y===i)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:r,y:i},p(j0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=wE(t,"dragover");this.editor.contentElement.dispatchEvent(o)});m(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(j0,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(i=this.autoScroll)==null||i.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const r=wE(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new Vz(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class mf{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=lt(t),z(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new mf(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class YR{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,r)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const i=this.editor.getCustom("editor-tooltip");if(i&&i.visible()&&(i.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(r.target)||this.buttonElement.remove());return}const o=Zg(t);$i(o)||(this.updateButton(o),bE(o,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const r=this.blockMenu.currentBlock;if(!r)return;this.editor.selection.selectBlock(r,0,void 0,{noScroll:!0}),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{mf.get(this.editor).highlightBlock(r)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0,void 0,{noScroll:!0}),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{of(this.editor,t,D.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;if(this.blockMenu.currentBlock){const r=lt(this.blockMenu.currentBlock);if(!this.editor.findBlockById(r)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const e=ue(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new gz(t),this.blockMenu=new Nz(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new Hz(this.editor,this);const e=Te.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new mz),mf.register(this.editor)}destroy(){Te.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=B("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,D.t("blockMenu.button.tips")),t.innerHTML=rC,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=Y2,this.buttonElement.setAttribute(e,D.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=rC,this.buttonElement.setAttribute(e,D.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),ue(this.editor,t)&&!(Kt(t)&&UC(t))?this.setButtonType("insert"):this.setButtonType("move")}}const jz={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
628
628
|
\u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},zz={blockMenu:{section:{basics:"Basic",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert below",copy:"Copy",cut:"Cut",delete:"Delete"},button:{searchPlaceholder:"Search",tips:`Hold to drag
|
|
629
629
|
Click to open the menu`,insertTips:"Click to add block"}}},Gz={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};D.mergeLang({"zh-CN":jz,"en-US":zz,"ja-JP":Gz});const bct="";class Wz{constructor(){m(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function z0(n){return n.addCustom("drag-data",()=>new Wz)}function SE(n,t){if(!t)return null;const e=z0(n).getData();return!e||e.editorId!==n.id?null:e}function QR(n,t){const e=SE(n,t);return e?n.findBlockById(e.blockId):null}function qz(n,t,e){if(!t.dataTransfer)return;const i=it(e),o=ut(i),s=lt(e),l={type:"block",editorId:n.id,containerId:o,blockId:s};z0(n).setData(l)}function Xz(n,t,e,r,i){if(!t.dataTransfer)return;const s=it(e),l=ut(s),c=lt(e),d={type:"custom",customType:r,editorId:n.id,containerId:l,blockId:c,data:i};z0(n).setData(d)}function gf(n){z0(n).clearData()}const Yz=I("drop-indicator"),pf=2;class Qz{constructor(t){m(this,"indicator");m(this,"target",null);this.editor=t,this.indicator=B("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const r=this.getIndicatorRect(t,e),i=this.editor.rootElement.getBoundingClientRect(),o=r.top-i.top,s=r.left-i.left;this.indicator.style.top=`${o}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${r.width}px`,this.indicator.style.height=`${r.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const l=Hs(t);if(!l){p(Yz,_r(it(t)),"block does not in a child container");const C=t.getBoundingClientRect(),E=this.getViewRect(t);return new DOMRect(E.x,C.y,E.width,pf)}const c=l.getBoundingClientRect(),d=t.getBoundingClientRect(),h=this.getViewRect(t);return new DOMRect(h.x,(c.bottom+d.top)/2,h.width,pf)}const r=js(t);if(!r){const l=t.getBoundingClientRect(),c=this.getViewRect(t);return new DOMRect(c.x,l.bottom,c.width,pf)}const i=t.getBoundingClientRect(),o=r.getBoundingClientRect(),s=this.getViewRect(t);return new DOMRect(s.x,(i.bottom+o.top)/2,s.width,pf)}getViewRect(t){const e=Ge(t,{horizontal:!0}),r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),o=Math.max(i.x-r.x,0),s=Math.max(r.right-i.right,0);return new DOMRect(r.x+o,r.y,Math.max(r.width-o-s,0),pf)}}const Jz=I("find-drop-target");function Zz(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(Hi(e)&&_r(e))return e;const r=e.firstElementChild;return r&&Hi(r)&&_r(r)?r:null}function tG(n,t){const s=t,l=n;for(let c=0;c<2;c++){const d=l+c*50;for(let h=0;h<5;h++){const C=s+h*8,E=document.elementFromPoint(d,C);if(E){const R=J(E);if(R)return R}if(h===0)continue;const x=s-h*8,v=document.elementFromPoint(d,x);if(v){const R=J(v);if(R)return R}}}return null}function eG(n,t,e){const r=document.elementFromPoint(t,e);if(r){const h=J(r);if(h&&!Mt(n,h))return h}const i=new Set,o=Zz(t,e);if(o){const h=o.getBoundingClientRect();e<h.top+h.height/2?i.add(we(o)):i.add(tn(o))}const s=tG(t,e);s&&i.add(s);const l=Array.from(i),c=h=>{for(let C=0;C<l.length;C++){const E=l[C];if(h!==E&&re(h,E))return!0}return!1},d=l.filter(h=>!c(h));return d.length>0?d[0]:null}function LE(n,t){if(n.readonly)return!1;const e=it(t);if(Xt(e))return!0;const r=J(e);return p(Jz,r,"no parent block"),n.isBlockWritable(r)?LE(n,r):!1}const nG=I("drop-target");function rG(n,t){let e={};return/image/.test(t.type)?e=n.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=n.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=n.editorEmbeds.getEmbedClass("video")),p(nG,e,`unSupport file type ${t.type}`),e}async function JR(n,t,e,r){var o,s;let i=r;for(const l of t){const c=rG(n,l);c.getOptions&&await((s=(o=c.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(o,n,{containerId:e,blockIndex:i,data:{file:l}}))&&(i+=1)}}class iG{constructor(t){m(this,"handleDrop",(t,e,r,i)=>{if(Array.isArray(e)){const o=e;if(o.length>0){const s=ut(r);return JR(t,o,s,i),!0}}return!1});this.editor=t}}class Cf{constructor(t){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=o=>{var d,h;const s=SE(this.editor,o.dataTransfer),l=QR(this.editor,o.dataTransfer),c=this.findTargetBlock(l,o.x,o.y);if(c&&re(this.editor.rootContainer,c)){const C=this.findInsertPos(l,c,o.x,o.y,(h=s!=null?s:(d=o.dataTransfer)==null?void 0:d.items)!=null?h:null);if(C)return this.indicator.show(c,C),"move"}return this.indicator.hide(),"none"},r=(o,s)=>{o.dataTransfer&&(o.dataTransfer.dropEffect=s),s==="move"&&o.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const o=this.lastDropOverResult.dropEffect;r(t,o);return}const i=e(t);r(t,i),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:i}});m(this,"handleDrop",t=>{var o,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=SE(this.editor,t.dataTransfer),r=Array.from((s=(o=t.dataTransfer)==null?void 0:o.files)!=null?s:[]);if(!e&&r.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none"),gf(this.editor);return}const i=this.indicator.target;if(i){const{block:l,insertPos:c}=i,d=QR(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:r,c,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus(),gf(this.editor);return}if(d){const C=Qt(this.editor,d);if(C.handleDrop&&C.handleDrop(this.editor,d,e!=null?e:r,c,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus(),gf(this.editor);return}}if(typeof c=="string"){const C=it(l);let E=Bt(l);if(c==="after"){E+=1;let x=Zt(l);for(;x&&!nu(x);)E+=1,x=Zt(x)}t.preventDefault();for(let x=0;x<this.handlers.length;x++)if(this.handlers[x].handleDrop(this.editor,d!=null?d:r,C,E)){this.editor.focus(),gf(this.editor);return}if(d){const x=this.editor.getBlockData(d),v=Go(this.editor.editorBlocks,this.editor.doc.toJSON(),x),[R]=this.editor.insertDocAt(C,E,v);this.editor.selection.selectBlock(R,0),mf.get(this.editor).highlightBlock(R),this.editor.deleteBlock(d),this.editor.focus()}}})}gf(this.editor)});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new Qz(this.editor),this.handlers.push(new iG(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new Cf(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||js(e)===t&&t||!LE(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Hs(e)===t&&t||!LE(this.editor,e)||Xt(it(e))&&Bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!re(t,e)}findTargetBlock(t,e,r){let i=eG(this.editor,e,r);if(!i||!re(this.editor.rootContainer,i))return null;const o=it(i),s=J(o);return s&&Dt(s)==="code"&&(i=s),this.canDrop(t,i)?i:null}findInsertPos(t,e,r,i,o){let s=e;for(;s;){const c=Qt(this.editor,s);if(c.handleDropOver){const d=c.handleDropOver(this.editor,s,o,r,i);if(d)return d;if(d===!1)return null}s=Vs(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=i&&i<=l.bottom){if(i<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return i<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<i&&this.canInsertAfter(t,e)?"after":""}}function ZR(n,t,e){const r=Le.getImageObject(n,t),i=mt.default(r.getImages());if(i.length===1){n.deleteBlock(t);return}if(e===-1||e>=i.length)return;const o=zj(i);if(i.splice(e,1),i.length===1){const l=i[0],c=100*(l.flex/o);l.flex=1;const d=gn([l],c);n.updateEmbedData(t,d);return}i[0].flex=NaN,rc(i);const s=gn(i,r.getWidthPercent());n.updateEmbedData(t,s)}function oG(n,t,e,r){if(t.length===0||r==="after"||r==="before")return!1;let i=r.data;const o=Le.getImageObject(n,e),s=mt.default(o.getImages()),l=[],c=[];t.forEach(C=>{FR(C.type)&&s.length+l.length<6?l.push(C):c.push(C)}),l.forEach(C=>{try{PR(n,C)}catch{return}const E={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(i,0,E);const x=gn(s,o.getWidthPercent());n.updateEmbedData(e,x),o.replaceImage(i,C),i+=1});const d=n.getBlockIndex(e)+1,h=ut(it(e));return JR(n,c,h,d),!0}function sG(n,t,e,r,i){var s,l,c;if(Fd(e))return oG(n,e,t,r);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const o=e.data;if(i.isSourceBlock){const d=i.targetBlock,h=it(d);let C=Bt(d);r==="after"&&(C+=1);const x=100*(o.boundingRect.width/n.rootContainer.getBoundingClientRect().width),v=gn([o.image],x),R={id:tt(),type:"embed",embedType:"image",embedData:v},L=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;L&&(R.align=L),n.insertBlock(ut(h),C,R),ZR(n,t,o.index),(c=n.findCustom("drag-handler"))==null||c.handleDragEnd()}else{if(typeof r=="string")return;const d=t;let h=r.data;const C=Le.getImageObject(n,d),E=mt.default(C.getImages());h>E.length&&(h=E.length),n.undoManager.runInGroup(()=>{var v,R;C.setAutoFix(!0);const x=n.getBlockById(e.blockId);if(x===d){const L=o.index,M=h,U=o.image;if(L===M||M===L+1)return;let F=M;L<M?(E.splice(M,0,U),E.splice(L,1),F-=1):(E.splice(L,1),E.splice(M,0,U));const G=gn(E,C.getWidthPercent());n.updateEmbedData(d,G),C.setSelectedIndex(F),(v=n.findCustom("drag-handler"))==null||v.handleDragEnd()}else{E.splice(h,0,o.image),E[0].flex=NaN,rc(E);const L=gn(E,C.getWidthPercent());n.updateEmbedData(d,L),ZR(n,x,o.index),(R=n.findCustom("drag-handler"))==null||R.handleDragEnd(),C.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const lG=2;function G0(n,t,e){const r=Bi(t);if(e<=0){const s=r[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===r.length){const s=r[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const i=r[e-1].getBoundingClientRect(),o=r[e].getBoundingClientRect();return new DOMRect((o.left+i.right)/2-1,i.top,lG,i.height)}function aG(n,t,e,r,i){for(let o=0;o<e.length;o++){const l=e[o].getBoundingClientRect();if(r<=l.right)return r<=l.left+l.width/2?{rect:G0(n,t,o),data:o}:{rect:G0(n,t,o+1),data:o+1}}return r>e[e.length-1].getBoundingClientRect().right?{rect:G0(n,t,e.length),data:e.length}:{rect:G0(n,t,e.length),data:0}}function cG(n,t,e,r,i){const o=Bi(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>FR(s.type))||o.length>=6)return}else{if((e==null?void 0:e.type)==="block"||o.length>=6&&(e==null?void 0:e.blockId)!==lt(t))return;const s=lt(t);if(o.length===1&&s===(e==null?void 0:e.blockId))return}return aG(n,t,o,r)}async function uG(n){return await bb.default.toSvg(n)}function IE(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class fG{constructor(t){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement)||t.button!==0)return;const r=J(e);if(!r||!Wr(r)||!this.editor.isBlockWritable(r)||this.editor.readonly)return;const i=Le.getImageObject(this.editor,r);if(this.imageContainer=AE(t.target),!this.imageContainer)return;const s=_R(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=i.getImages()[s];if(!l)return;const{x:c,y:d}=t;this.startPosition={x:c,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},C=IE(t,"dragstart");Xz(this.editor,C,r,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});m(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=J(this.imageContainer);if(!e)return;const{x:r,y:i}=t,{width:o,height:s}=t.target.getBoundingClientRect(),l=ie(e),c=B("div",["drag-container"],l);c.style.left=`${r-o/4}px`,c.style.top=`${i-s/4}px`,c.style.width=`${Math.max(o/2,16)}px`,c.style.height=`${s/2}px`,this.dragContainer=c,z(this.editor.contentElement,"dragging");const d=Ge(e);this.autoScroll=new Vd({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=B("img",["drag-target"],c),E=await uG(this.imageContainer);E&&(h.src=E)});m(this,"handleDrag",t=>{var o;const{x:e,y:r}=t;if(((o=this.startPosition)==null?void 0:o.x)===e&&this.startPosition.y===r)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(t)),this.startPosition&&this.dragContainer){const{x:s,y:l}=t;if(s===0&&l===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:c,y:d}=this.startPosition,h=s-c,C=l-d;this.dragContainer.style.transform=`translate(${h}px, ${C}px)`,this.dragContainer.style.opacity="0.5"}const i=IE(t,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",t=>{var e;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(e=this.autoScroll)==null||e.inactive(),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const r=IE(t,"drop");this.editor.contentElement.dispatchEvent(r)}});this.editor=t,this.editor.rootContainer.addEventListener("mousedown",this.handleMouseDown),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("mousedown",this.handleMouseDown)}}class dG{constructor(t){m(this,"handleFocusBlockChanged",(t,e,r)=>{const o=this.editor.getFocusedBlock();if(o&&Wr(o)){const s=Le.getImageObject(this.editor,o);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}r&&Wr(r)&&t.findCustom(`image-${r.id}`)&&Le.getImageObject(this.editor,r).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class hG{constructor(t){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(t,e)=>{window.isDragging||(e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t)))});this.editor=t,Te.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){Te.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){Wr(t)&&Le.getImageObject(this.editor,t).disableResizer()}enable(t){if(Wr(t)){const e=Le.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const mG={image:{title:"\u56FE\u7247",upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-3">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},gG={image:{title:"Image",upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>',remote:{failed:'<div class="line-1">Failed to load image</div><div class="line-2">This picture is from an expired external link</div><div class="line-3">Please save the original image to local drives and upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"This picture is from an external link. If the link expires, the picture will not be available. It's recommended to save it to local drives and add it to the page."}},abstract:"Image"}},pG={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};D.mergeLang({"zh-CN":mG,"en-US":gG,"ja-JP":pG});function CG(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r),l=fe(s);let c=r;if(l.endsWith("![]()"))c-=5;else if(l.endsWith("![]"))c-=3;else return!1;const d=r;return ha("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c);let C=e+1;fe(n.getBlockText(i)).trim()?(ka(n,i,c,{forceInsertAfter:!0}),c===0&&(n.deleteBlock(i),C--)):(n.deleteBlock(i),C--),e1(n,"image",t,C,{file:h})})}),!0}class EG{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(P0(t,e))return!1;if(CG(t,e,r,i))return!0}return!1}}const AG=I("copy-image");function xG(n,t,e,r){const i=e.getImages()[r],o=e.getImages().length===1?e.getWidthPercent():i.flex*100,s=gn([i],o),l={id:tt(),type:"embed",embedType:"image",embedData:s},c=n.options.componentsOptions.image;c!=null&&c.defaultAlign&&(l.align=c.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const C=h.getContext("2d");if(!C)return;const E={},x={};try{C.drawImage(t,0,0,h.width,h.height);const F=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),G=Og(F),W=new File([G],`${Date.now()}.png`,{type:"image/png"});E["image/png"]=W}catch(U){AG.error(U)}La(n,d);const R=`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`,L=Sa(R,d),M=new Blob([L],{type:"text/html"});return E["text/html"]=M,x["text/html"]=L,[E,x]}function bG(n,t,e,r,i){const o=xG(n,t,e,r);if(!o)return;const[s,l]=o;if(s){const c=Object.entries(s).map(([d,h])=>({type:d,data:h}));return da(c).then(d=>{if(!d&&i){const h=i.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function W0(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const i=n.getFocusedBlock();if(i&&Wr(i)){const o=Le.getImageObject(n,i);if(o.getImages().length>0){const l=o.getSelectedIndex();if(l!==-1){const d=Bi(i)[l].querySelector("img");if(d)return bG(n,d,o,l,t)}}}}function vG(n){const t=n.getFocusedBlock(),e=js(t);if(e&&Wr(e)){n.selection.selectBlock(e,0);const r=Le.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function BG(n){const t=n.getFocusedBlock(),e=Hs(t);if(e&&Wr(e)){n.selection.selectBlock(e,0);const r=Le.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function TG(n){const e=n.getFocusedBlock();if(e&&Wr(e)){const r=Le.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(i.length-1),!0;if(o>0)return r.setSelectedIndex(o-1),!0}}}function yG(n){const e=n.getFocusedBlock();if(e&&Wr(e)){const r=Le.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(0),!0;if(o<i.length-1)return r.setSelectedIndex(o+1),!0}}}function q0(n){const e=n.getFocusedBlock();if(e&&Wr(e)){const r=Le.getImageObject(n,e);if(r.getImages().length>0){const o=r.getSelectedIndex();if(o!==-1)return r.removeImage(o),!0}}}const kG={ArrowLeft:TG,ArrowRight:yG,ArrowUp:BG,ArrowDown:vG,Delete:q0,Backspace:q0};class RG{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,r){if(!window.isSecureContext)return;if(W0(t,e))return!0}handleBeforeCut(t,e){if(W0(t,e))return q0(t),!0}destroy(){}}class DE{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,r){return Object.values(e.blocks).forEach(i=>{i.forEach(o=>{if(o.type==="embed"&&o.embedType==="image"){const s=o.embedData;if(Array.isArray(s.src))return;let l=r.blockIdMap.get(o.id);for(;l&&r.blockIdMap.get(l);)l=r.blockIdMap.get(l);l&&ss(t,l).setAutoFix(!0)}})}),!1}destroy(){}}const wG=I("image-embed");function SG(n,t,e,r,i,o){Le.create(n,e).createContent(i,o,t),n.addCustom("image-select-handler",()=>new dG(n)),n.addCustom("image-copy-handler",()=>new RG(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new fG(n));const l=n.addCustom("image-resizer",()=>new hG(n)),c=e.embedData;nc(c)?l.disable(o):l.currentResizer===o&&l.enable(o)})}function LG(n,t,e,r){const i=t.embedData,o=ic(i);return r==="html"?o.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):r==="markdown"?`${o.map(l=>`})`).join(`
|
|
630
630
|
`)}
|