@ones-editor/editor 0.0.3-beta.201 → 0.0.3-beta.202

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
@@ -394,7 +394,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
394
394
  <path d="M1 10.0039H5.99738L5.99608 15" stroke="currentColor" stroke-width="2"/>
395
395
  <path d="M14.9971 5.99611H9.99969L10.001 1" stroke="currentColor" stroke-width="2"/>
396
396
  </svg>`;async function oO(n,t,e){const o=te(t),r=o.querySelector('[data-button-id="mindmap-fullscreen"]');g(we,r,"no full screen button");const i=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{ot(o,"fullscreen"),r.innerHTML=c9,Qb(r,"Full screen",n.clientId),u9(t)&&setTimeout(()=>{i()},300)};if(document.fullscreenElement===o){try{await a9()}catch(l){we.error(l)}s()}else{try{W(o,"fullscreen"),await tO(o),i()}catch(l){we.error(l)}r.innerHTML=nO,Qb(r,R.t("mindmap.exitFullscreen"),n.clientId)}o.onfullscreenchange=()=>{document.fullscreenElement||s()}}function c0(n,t,e,o,r){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=uo(e,o,r,[],n.clientId);return W(s,"mindmap-button"),t.appendChild(s),s}function a0(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function rO(n){return a0(n,"mindmap-fullscreen")}function iO(n){return a0(n,"mindmap-fit")}function sO(n){return a0(n,"mindmap-close")}function lO(n,t,e,o){const r=c0(n,t,"mindmap-close",R.t("mindmap.close"),KR);!r||n.domEvents.addEventListener(r,"click",()=>{o.closeMindmap(n,e)})}function cO(n,t,e,o){const r=c0(n,t,"mindmap-fit",R.t("mindmap.autoFit"),XR);!r||n.domEvents.addEventListener(r,"click",()=>{o.fitMindmap(n,e)})}function aO(n,t,e,o){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const i=c0(n,t,"mindmap-fullscreen",R.t("mindmap.fullScreen"),c9);!i||n.domEvents.addEventListener(i,"click",()=>{oO(n,e,o)})}function uO(n,t){const e=Xd(t);if(!e)return;const o=iO(e);o&&(o.remove(),n.domEvents.removeAllListeners(o));const r=sO(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=rO(e);i&&(i.remove(),n.domEvents.removeAllListeners(i))}const dc=new Map;function u0(n,t,e){const o=(s,l)=>{s.forEach(a=>{l?W(a.block,"to-mindmap-highlight"):ot(a.block,"to-mindmap-highlight"),o(a.children,l)})},r=l9(n,t);if(r.length===0)return;const i=r[0].block;if(e){const s=dc.get(i);s&&(s.forEach(l=>l.cancel()),dc.delete(i)),o(r,!0)}else{const s=setTimeout(()=>{o(r,!1),dc.delete(i)},300),l=()=>{clearTimeout(s),dc.delete(i)},a=dc.get(i);a?a.push({cancel:l}):dc.set(i,[{cancel:l}])}}const{Markmap:dO}=NB;function hO(n,t){Fe(t);const e=l9(n,t),o=e[0].block,r=d=>({t:"text",v:Lt(d.block).textContent,d:1,c:d.children.length>0?d.children.map(p=>r(p)):void 0});let i=null;e.length>1?i={t:"root",v:"root",d:0,c:e.length>0?e.map(d=>r(d)):void 0}:i=r(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},a=l(e);return{root:i,block:o,nodes:e,last:a}}function df(n,t,e,o){const{root:r,block:i,last:s}=hO(n,t);o.selectBlock&&n.selection.selectBlock(i,0,0),u0(n,i,!1),o.saveData&&n.updateBlockData(i,{viewAsMindmap:!0});const l=te(i);let a=l.querySelector(".editor-mindmap-svg");if(o.reset&&(a&&a.remove(),a=null),a)a.innerHTML="";else{const _="http://www.w3.org/2000/svg",M=l.getBoundingClientRect(),H=document.fullscreenElement===l,z=H?`${M.width}`:`${t.getBoundingClientRect().width}`,q=H?`${M.height}`:"600",rt=document.createElementNS(_,"svg");rt.setAttributeNS(null,"viewBox",`0 0 ${z} ${q}`),rt.setAttributeNS(null,"width","100%"),rt.setAttributeNS(null,"height",q),rt.style.display="block",rt.style.width="100%",rt.style.height=`${q}px`,rt.classList.add("editor-mindmap-svg"),l.appendChild(rt),a=rt}const d=i,p=`editor-mindmap-root-${it(i)}`;W(d,"editor-in-mindmap-first",p,"readonly"),d.contentEditable="false";const A=Zt(i);A&&bt(A)<=bt(s.block)&&eO(A,s.block,["block-hidden",p]);const v=(_,M)=>{if(M.length>0){const H=M[0].parentElement;H&&(H.style.width="100vw",H.style.maxWidth="200px")}M.forEach(H=>{W(H,"editor-mindmap-node")})},B=new dO(a,{...e,autoFit:!0});B.viewHooks.transformHtml.tap(v),B.setData(r),B.fit();const D=te(i);let x=D.querySelector(".mindmap-toolbar");x||(x=w("div",["mindmap-toolbar"],D)),cO(n,x,d,o.mindmapTools),aO(n,x,d,o.mindmapTools),lO(n,x,d,o.mindmapTools),n.domEvents.addEventListener(a,"click",()=>{n.selection.selectBlock(i,0),n.input.focus()}),d.mindMap=B}function fO(n){const t=w("div",["list-to-mindmap-wrap"],null),e=uo("list-to-mindmap",R.t("mindmap.viewAsMindMap"),UR,[],n.clientId);return t.appendChild(e),t}async function d9(n,t){const e=`editor-mindmap-root-${t.id}`,o=nt(t);fe(o).forEach(l=>{xt(l,e)&&ot(l,e,"editor-in-mindmap-first","block-hidden")});const i=te(t);document.fullscreenElement===i&&await a9();const s=i.querySelector(".editor-mindmap-svg");!s||(g(we,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),uO(n,t))}function mO(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(r=>{if(r.startsWith(e))return r})}async function h9(n,t){!mO(t)||(n.updateBlockData(t,{viewAsMindmap:null}),d9(n,t),n.selection.selectBlock(t,0))}function gO(n,t){const e=t.mindMap;e&&e.fit()}const d0={toMindmap:df,closeMindmap:h9,fitMindmap:gO},Ent="";class hf{constructor(t){m(this,"toMindmapButton");m(this,"currentBlock",null);m(this,"handleHoveringBlock",t=>{!this.editor.isWritable()||(t&&Ht(t)&&Zn(t)!=="unchecked"&&Zn(t)!=="checked"?te(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove())});m(this,"handleMouseEnter",()=>{const t=et(this.toMindmapButton);g(we,t&&Ht(t),"no parent list"),u0(this.editor,t,!0),this.currentBlock=t});m(this,"handleMouseLeave",()=>{this.currentBlock&&(u0(this.editor,this.currentBlock,!1),this.currentBlock=null)});m(this,"handleClick",()=>{const t=et(this.toMindmapButton);g(we,t&&Ht(t),"no parent list"),df(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:d0})});this.editor=t,Ce.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=fO(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(hf)}destroy(){Ce.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}function pO(n,t,e){var o;t==="beginDrag"&&((o=hf.get(n))==null||o.hide())}function hc(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:K();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(o==null?void 0:o.resetGroupId)){const a={...l,start:e};o!=null&&o.resetGroupId&&(a.groupId=r),n.updateBlockData(s,a)}l.textOnly||(e+=1)})}function h0(n,t,e,o){const r=s9(t,{withSelf:!0});r.length!==0&&hc(n,r,e,o)}class ff{constructor(t,e){m(this,"listStart",0);m(this,"listBrother",null);if(this.editor=t,uf(e))return;const o=Cu(e),r=mo(o);this.listStart=r,o===e?this.listBrother=qs(o):this.listBrother=o}fix(){!this.listBrother||h0(this.editor,this.listBrother,this.listStart)}}class Gs{constructor(t,e,o){m(this,"listStart");m(this,"listBrother",null);this.editor=t,this.options=o;const r=Cu(e),i=mo(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||h0(this.editor,this.listBrother,this.listStart,this.options)}}class CO{constructor(t,e,o){m(this,"listStart");m(this,"listNextBrothers",[]);this.editor=t,this.listNextBrothers=uc(e);const{start:r,resetStart:i}=o||{};this.listStart=i?1:r!=null?r:1}fix(){!this.listNextBrothers.length||hc(this.editor,this.listNextBrothers,this.listStart)}}function AO(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function f0(n,t,e,o){if(we.debug("drag a block on a list block"),!tt(n,t))return!1;g(we,Ht(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=qi(e),a=o==="after"?i+1:i,d=n.getBlockData(t),h={id:K(),type:"list",groupId:l,level:s,start:a,text:d.text,...s0(r)};AO(n,e,h);let p=bt(e);const A=nt(e);o==="after"&&(p+=1);let v=null;Ht(t)&&(v=new ff(n,t));const B=n.insertBlock(ct(A),p,h,ph(h.id,0));return n.deleteBlock(t),new Gs(n,B).fix(),v==null||v.fix(),!0}function bO(n,t,e,o){if(we.debug("drag a list between text blocks"),o==="after"){const d=Zt(e);if(d&&Ht(d))return f0(n,t,d,"before")}if(o==="before"){const d=ce(e);if(d&&Ht(d))return f0(n,t,d,"after")}const i={...n.getBlockData(t),groupId:K(),start:1,level:1};let s=bt(e);const l=nt(e);o==="after"&&(s+=1),n.insertBlock(ct(l),s,i,ph(i.id,0));const a=new ff(n,t);return n.deleteBlock(t),a.fix(),!0}function vO(n,t,e,o,r){if(Gd(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);g(we,s,"no dragged block");const{isSourceBlock:l,targetBlock:a}=r;return!l&&a?(g(we,t===a,"block !== target block"),g(we,Ht(a),"target is not a list block"),f0(n,s,a,o)):bO(n,s,a,o)}function mf(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function yO(n,t){let e;const o=mf(t);if(!o)e=1;else{if(o>=12)return e=12,!1;e=o+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function f9(n,t){const e=mf(t);if(!e)return!1;const o=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...o,padding:e-1}),!0):(n.updateBlockData(t,{...o,padding:null}),!0)}function m0(n){return n.readonly||!n.isWritable()}function kO(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;tt(n,o)&&yO(n,o)}),!0}function wO(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;tt(n,o)&&f9(n,o)}),!0}function BO(n){return m0(n)?!1:n.undoManager.runInGroup(()=>(kO(n),!0))}function EO(n){return m0(n)?!1:n.undoManager.runInGroup(()=>(wO(n),!0))}function xO(n){if(m0(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!tt(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!mf(t)))return f9(n,t),!0}class g0{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const xnt="",IO={Tab:BO,"Shift+Tab":EO,Backspace:xO};function TO(n,t,e=1){if(!t)return null;let o=ce(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return Ht(o)?o:null}o=ce(o)}return null}function DO(n,t){const e=n.getAttribute("data-style-heading"),o=TO(n,e);if(o)return o;const r=ce(n);if(r&&Ht(r)&&Zn(r)===t)return r;const i=Zt(n);return i&&Ht(i)&&Zn(i)===t?i:null}function SO(n,t,e){var D,x,_;const o=(D=e.data)!=null?D:{};let r=1;if(Ht(t))r=vn(t);else{const M=mf(t);M&&(r=M+1),r>8&&(r=8)}const i=(x=o.listType)!=null?x:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(_=s.text)!=null?_:[],d=ie(l);const h=e.offset||0;h<=rn(l)&&(l=Tn(l,h).right,d=d.substring(0,h));let p=1;i==="ordered"&&(p=Number.parseInt(d,10)||1);let A=K();const v=DO(t,i);if(v){if(bt(t)>bt(v))p=mo(v)+1;else{const H=mo(v);H>1&&(p=H-1)}A=ac(v),new CO(n,v,{start:p+1}).fix()}const B={id:K(),type:"list",level:r,start:p,groupId:A,ordered:!1,text:l};return s.quoted&&(B.quoted=!0),s.heading&&(B.heading=s.heading),i==="ordered"?B.ordered=!0:(i==="checked"||i==="unchecked")&&(B.checkbox=i),{blockData:B,onConverted:(M,H)=>{new Gs(M,H).fix()}}}function fc(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function LO(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${GR(t,(o=n.start)!=null?o:1)}.`:ZR(t)}function gf(n){return n==="checked"||n==="unchecked"}function m9(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===0)return!0;const l=e.blocks[i][s-1];if(l.type!=="list")return!0;const a=fc(r),d=fc(l);return a!==d&&(!gf(a)||!gf(d))||r.level>l.level}function g9(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===e.blocks[i].length-1)return!0;const l=e.blocks[i][s+1];if(l.type!=="list")return!0;const a=fc(r),d=fc(l);return a!==d&&(!gf(a)||!gf(d))||r.level>l.level}function MO(n,t,e,o,r){var s,l,a;const i=t;if(o==="text")return((s=Dn.convertTo)==null?void 0:s.call(Dn,n,t,e,"text",r))||"";if(o==="markdown"){let d=((l=Dn.convertTo)==null?void 0:l.call(Dn,n,t,e,"markdown",r))||"";i.checkbox==="checked"?d=`[x] ${d}`:i.checkbox==="unchecked"&&(d=`[ ] ${d}`),i.ordered?d=`${i.start}. ${d}`:d=`- ${d}`;const h=i.level||0;return d=(h>0?" ".repeat(h-1):"")+d,m9(n,t,e,r)&&(d=`${d}`),g9(n,t,e,r)&&(d=`${d}`,h<=1&&(d+=`
397
- `)),d}if(o==="html"){let d=((a=Dn.convertTo)==null?void 0:a.call(Dn,n,t,e,"html",r))||"";d=d.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:i.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul";return i.ordered?(d=`<li value="${i.start}">${d}</li>`,h="ol"):d=`<li>${d}</li>`,m9(n,t,e,r)&&(d=`<${h}>${d}`),g9(n,t,e,r)&&(d=`${d}</${h}>`),d}return""}function p9(n){const t=w("label",["editor-check-list-wrapper"],null);n&&W(t,"editor-check-list-wrapper-checked");const e=w("span",["editor-check-box"],t);return w("span",["editor-check-box-inner"],e),t}function RO(n,t){const e=fc(t);if(e!=="text-only"){if(e==="checked"){n.append(p9(!0));return}if(e==="unchecked"){n.append(p9(!1));return}n.innerText=LO(t)}}function OO(n){const t=w("div",["list-container"],null),e=w("button",["list-marker"],t);return RO(e,n),t}function C9(n){let t=Zt(n);if(!t)return null;const e=qs(n);for(;t!==e;){if(g(we,t,"no next block"),Ht(t))return vn(t)>vn(n)?t:null;if(t=Zt(t),!t)return null}return null}function p0(n){const t=[];let e=C9(n);if(!e)return t;for(;e;){const o=qs(e);t.push({block:e,children:p0(e)}),e=o}return t}function _O(n){const t=(o,r)=>{r.push(o.block),o.children.forEach(i=>t(i,r))},e=[];return n.forEach(o=>t(o,e)),e}function A9(n,t){return vn(t)!==1}function b9(n,t,e){t.forEach(o=>{const r=n.getBlockData(o.block);n.updateBlockData(o.block,{...r,groupId:e,level:r.level-1}),o.children.length&&b9(n,o.children,r.groupId)})}function C0(n,t){if(!A9(n,t))return!1;const e=vn(t);if(e===1)return!1;let o=K(),r=1,i=Zn(t);const s=e-1,l=l0(t);l&&(o=ac(l),r=mo(l)+1,i!=="text-only"&&(i=Zn(l)));const a=p0(t),d=n.getBlockData(t),h={...d,groupId:o,level:s,start:r,...s0(i)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),b9(n,a,d.groupId),n.doc.endBatchUpdate(),new Gs(n,t).fix();const A=C9(t);return A&&new Gs(n,A,{resetStart:!0,resetGroupId:!0}).fix(),!0}function mc(n,t){Fe(t);const e=n.getBlockData(t),o={id:K(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new ff(n,t),i=nt(t),s=bt(t);n.deleteBlock(t);const l=ph(o.id,0);if(wa(n,i)&&!Yt(i)){n.insertBlock(ct(i),s,o,l);const a=ye(i);n.deleteBlock(a)}else n.insertBlock(ct(i),s,o,l);r.fix()}function FO(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:vn(t)===1?(mc(n,t),!0):(C0(n,t),!0)}const PO=S("list-block");function NO(n,t,e){g(PO,Ht(t),"not a list block");const o={...n.getBlockData(t),id:K()};return e!=null&&e.level&&(o.level=e.level),e!=null&&e.start&&(o.start=e.start),e!=null&&e.keepText||delete o.text,(o==null?void 0:o.checkbox)==="checked"&&(o.checkbox="unchecked"),o}function $O(n){if(Fe(n),!uf(n))return n;let t=Gi(n);for(;t;){if(!uf(t))return t;t=Gi(t)}return null}function HO(n,t,e,o){const r=new Gs(n,o),i=mo(o)+1;Ql(n,t,e,{forceInsertAfter:!0,newBlockData:NO(n,o,{start:i})}),r.fix()}function jO(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Ht(l)&&ut(n,l)===0)return mc(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===ut(n,t)?$O(t):t)!=null?s:t;return HO(n,t,o,i),!0}function v9(n){g(we,Ht(n),"not a list block");const{level:t}=qi(n);let e=ce(n);for(;e;){if(Ht(e)){const{level:o}=qi(e);if(t===o)return e;if(o<t)return null}e=ce(e)}return null}function y9(n,t){return Fe(t),v9(t)?vn(t)<zR:!1}function UO(n,t,e){let o=ce(t);g(we,o,"no prev brother");const r=vn(e);for(;o;){if(o===e)return null;if(Ht(o)&&vn(o)===r+1)return o;o=ce(o)}return null}function k9(n,t){if(!y9(n,t))return!1;Fe(t);const e=v9(t);g(we,e,"no list prev brother");const o=e,r=UO(n,t,o),i=vn(o)+1;let s=K(),l=1,a=Zn(t);r&&(s=ac(r),l=mo(r)+1,a=Zn(r));const d=p0(t),p={...n.getBlockData(t),groupId:s,level:i,start:l,...s0(a)};return n.updateBlockData(t,p),n.doc.beginBatchUpdate(),_O(d).forEach(v=>{const B=n.getBlockData(v);n.updateBlockData(v,{...B,level:B.level+1})}),n.doc.endBatchUpdate(),!0}function zO(n,t,e){return t.length===0||!t.every(o=>Ht(o.block))?!1:e==="increase"?y9(n,t[0].block):A9(n,t[0].block)}function w9(n,t,e){if(!zO(n,t,e))return!1;const o=t[0].block,r=vn(o),i=t.filter(d=>vn(d.block)<=r),s=s9(o,{withSelf:!1}),l=new Set(i.map(d=>d.block)),a=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;a.length>0&&(d=new Gs(n,a[0])),i.forEach(h=>{e==="increase"?k9(n,h.block):C0(n,h.block)}),d==null||d.fix()}),!0}function VO(n,t){return k9(n,t)}function WO(n,t){return C0(n,t)}function qO(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return w9(n,t,"increase"),!0;const e=t[0].block;if(!Ht(e))return!1;const o=new ff(n,e);return VO(n,e)&&(o.fix(),new Gs(n,e).fix()),!0}function GO(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return w9(n,t,"decrease"),!0;const e=t[0].block;return Ht(e)?(WO(n,e),!0):!1}class ZO{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>Ht(i.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!Ht(e.block)||or(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>jO(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>FO(this.editor))}handleTab(t){return or(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>GO(this.editor)):this.editor.undoManager.runInGroup(()=>qO(this.editor))}}class QO{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(r=>{const i=r.block;Ht(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var a;const i=Cu(r),{start:s}=qi(i);o.set(it(i),s);const l=(a=QR(r))!=null?a:r;o.set(it(l),s)}),this.effectedBlockIds=o});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||h0(this.editor,o,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const YO=S("customize-list-start-menu");class JO{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");g(YO,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});m(this,"createDialogContent",()=>{const t=w("div",["customize-start-panel"],null);w("span",["customize-start-panel-title"],t,R.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const o=w("button",["customize-start-panel-button"],t,R.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});m(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,o=e.querySelector("button.customize-start-panel-button"),r=e.querySelector("input.customize-start-panel-input"),i=mo(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});m(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),o=this.block;if(!o)return;const r=Number(e.value);!r||(this.editor.undoManager.runInGroup(()=>{hc(this.editor,[o,...uc(o)],r,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||(o.key==="Escape"?this.popup.close("cancelBar"):o.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new Xa(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=w("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const r=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),i=parseInt(r,10);i<=0||Number.isNaN(i)?t.value="":t.value=r};return this.editor.domEvents.addEventListener(t,"input",e),t}}function KO(n,t){return ac(n)===ac(t)}function XO(n,t){const e=r9(t);return e?KO(e,t)?mo(e)!==mo(t)-1:!0:!1}function t_(n,t){return Gi(t)?!0:mo(t)!==1}function e_(n,t){return Fe(t),[{id:"continue-numbering",name:R.t("list.continueList"),states:XO(n,t)?[]:["disabled"]},{id:"start-new-list",name:R.t("list.restartList"),states:t_(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:R.t("list.changeNumber")}]}function n_(n,t,e){var o,r;if(Fe(t),e.id==="continue-numbering"){const i=r9(t);i&&hc(n,[t,...uc(t)],mo(i)+1,{resetGroupId:!0,groupId:ac(i)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{hc(n,[t,...uc(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const i=(o=n.options.componentsOptions)==null?void 0:o.list;if((r=i==null?void 0:i.onChangeStart)!=null&&r.call(i,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new JO(n)).show(n,t)}}class o_{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const o=Hl(e,"div.list-container");if(o&&this.editor.isWritable()){const r=et(o);g(we,r,"no parent block"),Fe(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}if(Zn(r)==="unordered")return;this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!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 r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=et(o);i&&n_(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new Us([]),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 e_(this.editor,t)}activeList(t,e){const o=et(t);!o||(e?(W(t,"active"),W(o,"active")):(ot(t,"active"),ot(o,"active")))}}class r_{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0)return!1;const r=o[0].block;if(!Ht(r)||!u9(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=Is(r);return i&&t.selection.selectBlock(i,ut(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Ts(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&h9(t,r),!0}}function i_(n,t,e,o,r){tp(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new r_(n)),n.input.addHandler(new ZO(n)),n.addCustom("list-clear-selection-handler",()=>new QO(n)),n.addCustom("list-marker-menu",()=>new o_(n))})});const i=Dn.createBlockContent(n,t,e,o,r),s=r,{level:l,start:a,groupId:d}=s,h=fc(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${a||1}`),o.setAttribute("data-list-group-id",`${d}`),o.setAttribute("data-list-type",h);const p=OO(s);return o.insertBefore(p,i),s.viewAsMindmap?setTimeout(()=>{const A=n.getBlockById(r.id);A&&df(n,A,{},{mindmapTools:d0,saveData:!1})}):setTimeout(()=>{const A=n.getBlockById(r.id);A&&d9(n,A)}),i}const s_={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"}},l_={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"}},c_={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"}};R.mergeLang({"zh-CN":s_,"en-US":l_,"ja-JP":c_});const Int="",B9={...Dn,blockType:"list",createBlockContent:i_,convertFrom:SO,convertTo:MO,handleDrop:vO,notify:pO},A0=S("paragraph");class a_{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 o=[],r={"unordered-list":[R.t("commands.unordered"),xo("CtrlOrCmd+Shift+L"),CL],"ordered-list":[R.t("commands.ordered"),xo("CtrlOrCmd+Shift+U"),pL],"check-list":[R.t("commands.check"),void 0,AL],link:[R.t("commands.link"),xo("CtrlOrCmd+K"),av],quoted:[R.t("commands.quote"),void 0,bL]};if(tt(t,e)){const i=it(e),s=Dt(e),l=Do(t,e),a=t.getBlockData(e);Object.entries(r).forEach(([d,[h,p,A]])=>{const v=[];if(this.isChecked(a,d)&&v.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&v.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:d,name:h,desc:p,states:v,icon:A,groupIndex:600})})}return o}convertLink(t,e,o){g(A0,Ur(e.start),""),g(A0,Ur(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(v,B)=>{t.undoManager.runInGroup(()=>{try{const D=t.selection.range.isCollapsed();let x;if(D){x=Vr(t.getBlockText(o),s,v,{link:B}),t.setBlockText(o,x);return}x=fh(t.getBlockText(o),i,s,v),x=Ia(i,v.length,x,"link",B),t.setBlockText(o,x),t.selection.selectBlock(o,i+v.length),t.focus()}catch(D){A0.error(D)}})},a=()=>{t.selection.selectBlock(o,s),t.focus()},d=Nr(t,o,e)[0];if(!d)return;const h=zr(t,o,"link-button-anchor",d),p=t.getBlockText(o),A=Ta(p,i);gu(t,{target:h,linkText:t.getSelectedText(),linkUrl:(A==null?void 0:A.link)||"",onFinished:l,onClose:a,placement:r})}convertToList(t,e,o){const r=th(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=bt(e),s=nt(e);t.insertBlock(ct(s),i,r.blockData),t.deleteBlock(e),t.focus()})}executeCommand(t,e,o,r){var a;if(!tt(t,e))return!1;const i=r.id,s=(a=r.states)==null?void 0:a.includes("checked");let l=!1;if(i==="unordered-list"&&(s?mc(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?mc(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?mc(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),t.focus(),l=!0}if(i==="link"){const d=lf(t);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const u_={left:tu,right:Ip,center:Tp};class d_{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(u_).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(tt(t,e)){const r=it(e),i=Dt(e),s=Do(t,e),l=t.getBlockData(e),a=d=>{var p;const h=w("span",["toolbar-item-name-container"],null);for(const A of d.children)if((p=A.states)!=null&&p.includes("checked"))return h.innerHTML=A.icon||tu,h;return h.innerHTML=tu,h};return[{id:"align",name:R.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:a,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:R.t("commands.alignLeft"),icon:tu,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:R.t("commands.alignCenter"),icon:Tp,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:R.t("commands.alignRight"),icon:Ip,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(!tt(t,e))return!1;if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),this.editor.focus(),!0}return!1}}function h_(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const o=n.getBlockById(e.start.blockId);return Sa(n,o,e.start.offset).charType==="box"}const f_=S("toolbar-handler"),m_={id:"",name:"",type:"separator"};class gc{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,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&$R(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const o=oC(e);if(this.hoveringBlock===o)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,o,r)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close("fromHover");return}this.showObjectToolbar(r)}});m(this,"handleSelectionChange",Le.default(t=>{var o;if(g(f_,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const r=(o=this.toolbar.tippyInstance)==null?void 0:o.reference,i=this.editor.selection.focusedBlock;if(r&&Xt(r,i))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 ou([],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),Ce.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Ce.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new jR(t)),t.editorCommandProviders.registerCommandProvider(new a_(t)),t.editorCommandProviders.registerCommandProvider(new d_(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),Ce.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&Xt(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){var D,x;if(this._disableTextToolbar||!this.editor.isWritable())return;const o=this.editor.selection.range.getSelectedBlocks();if(o.length===0)return;const r=o[0];if(!r)return;if(o.length===1&&Me(r.block)){t==="click"&&this.showObjectToolbar(null);return}if(h_(this.editor))return;if(nt(r.block)===this.editor.rootContainer&&bt(r.block)===0){this.toolbar.close("selectionChange");return}const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(_=>{const M=_.groupIndex,H=s.get(M);H?H.push(_):s.set(M,[_])});const l=[[]],a=Array.from(s.entries()).sort((_,M)=>_[0]-M[0]);for(let _=0;_<a.length;_++){const[,M]=a[_];if(M.length===0)continue;let H=l[l.length-1];H.length>0&&H[H.length-1].groupIndex!==M[M.length-1].groupIndex&&(H=[],l.push(H)),H.push(...sf(M))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((_,M)=>{const H=_.sort((z,q)=>{var rt,ft;return((rt=z.order)!=null?rt:0)-((ft=q.order)!=null?ft:0)});d.push(...H),M!==l.length-1&&d.push(m_)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=o[o.length-1],p=!this.editor.selection.range.isReverse()&&h!==r,A=p?h:r,v=LR(this.editor,A),B=zr(this.editor,A.block,"editor-quick-menu",v);this.toolbar.manualShow(B,{placement:p?"bottom":"top",offset:[0,p?5:10]}),(x=(D=this.toolbar.tippyInstance)==null?void 0:D.popperInstance)==null||x.update()}showObjectToolbar(t){var l,a,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,o=this.hoveringTextChild,{commands:r,element:i}=FR(this.editor,e,o);if(!r.length||!i){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((a=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:a.reference)!==i&&this.toolbar.close("fromHover");const s=()=>{let h;const p=i.getClientRects();if(p.length>1){if(h=o?p[p.length-1]:p[0],t)for(let A=0;A<p.length;A++){const v=p[A],B=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(B.x<t.clientX&&t.clientX<B.right&&B.y<t.clientY&&t.clientY<B.bottom){h=v;break}}}else{if(h=i.getBoundingClientRect(),o){const A=o.getBoundingClientRect();return new DOMRect(A.x,A.y,A.width,A.height)}return new DOMRect(p[0].x,p[0].y,p[0].width,p[0].height)}if(t){const A=h.y,v=t.clientX;return new DOMRect(v,A,10,h.height)}return h};this.toolbar.updateItems(r),this.toolbar.isVisible||(this.toolbar.manualShow(i,{placement:o?"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 gc(e))}static get(t){return t.getCustom("toolbar-handler")}}function pf(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function E9(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function b0(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function v0(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 y0(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=v0(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=v0(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=v0(r,"check-list")?void 0:"unchecked";break}if(i){const s=th(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=bt(t),a=nt(t);n.deleteBlock(t),n.insertBlock(ct(a),l,s.blockData)})}else mc(n,t)}const g_=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:pf,applyAlignStyle:E9,applyQuoteStyle:b0,applyList:y0},Symbol.toStringTag,{value:"Module"})),p_=[bp,vp,yp,kp,wp,Bp,Ep,xp],C_={Unordered:hv,Ordered:fv,Checkbox:uv,Quote:dv};function x9(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>x9(o,t))}function A_(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:nu,name:R.t("commands.text"),order:0,group:"basics",value:"text"}]}}function k0(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=cf();e<=4?e=5:e<8&&(e+=1);let o=n;for(;o<=e;){const i=`heading-${o}`;(r=t.insertBlockCommandItems)==null||r.push({id:i,icon:p_[o-1],name:R.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:An(i)}),o++}return t}function b_(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,o)=>{var i;const r=`insert-${e.toLocaleLowerCase()}`;(i=n.insertBlockCommandItems)==null||i.push({id:r,name:R.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:C_[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:An(r)})}),n}class I9{constructor(t){this.withPlainText=t}getCommands(){const t=A_(),e=k0(),o=b_();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...o.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?pf(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?y0(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&b0(t,o),null}async handleUpdateBlockCore(t,e){const o=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,o,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:o,blockIndex:r}=e,i=t.insertTextBlock(void 0,o,r);return this.updateBlock(t,e.containerId,i,e.item)}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=ct(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else o.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex})),t.focus());return null}}const T9={basics:100,system:200,common:300,thirdParty:400};class w0{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 v_=S("mathjax-converter"),y_="MathJax-script";async function k_(n){var o;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((o=t==null?void 0:t.cdn)==null?void 0:o.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await bs(e,y_)}function w_(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function D9(n,t){const e="mathjax2Svg";try{await Eo.lock(e),w_(),await k_(n);const o=await window.MathJax.tex2svgPromise(t),r=o.querySelector("merror");if(r)throw new Error(r.textContent);return o.querySelector("svg").outerHTML}catch(o){throw v_.error(o),o}finally{Eo.release(e)}}async function S9(n,t){const e=await D9(n,t);return e?await Im(e,"image/svg+xml"):""}async function B0(n,t){const o=await D9(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const L9=S("edit-mathjax");class B_{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"observer",null);m(this,"handleClose",t=>{var o;const e=t.content.querySelector("textarea");if(e){const r=e.value;r!==this.tex&&((o=this.onChange)==null||o.call(this,r,!0))}});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",Le.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new Xa(this.createPopupContent(e));else{const r=this.getTextarea();r.value=e}this.tex=e,this.editMathjaxPopup.manualShow(t,{theme:"light"}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=o}createPopupContent(t){const e=w("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 r;(r=this.editMathjaxPopup)!=null&&r.isVisible&&t.focus()};const o=()=>{setTimeout(()=>{t.focus()})};this.observer=new IntersectionObserver(o,{}),this.observer.observe(t)}getTextarea(){g(L9,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return g(L9,t,"no textarea"),t}destroy(){var t,e;this.onChange=null,(t=this.observer)==null||t.disconnect(),(e=this.editMathjaxPopup)==null||e.removeAllListeners()}}function M9(n,t,e,o){n.addCustom("mathjax-editor",()=>new B_).editMathjax(t,e.trim(),o)}function R9(){return{insert:" ",attributes:{id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function Cf(n,t){const e=n.getBoxData(t),o=et(t);if(!o)return;const r=Os(o,t);n.selection.selectBlock(o,r.start,r.end);const i=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await Eo.lock("convertAndUploadMathjax");const a=await B0(n,s);n.updateBoxData({...e,tex:s,src:a})}catch(a){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new w0).setError(a),n.updateBoxData({...e,tex:s,src:""})}finally{Eo.release("convertAndUploadMathjax"),l&&n.focus()}};M9(n,t,e.tex,i)}const O9=S("mathjax-box");function E0(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,E0)}async function E_(n,t,e){try{if(!t.tex.trim())return;const o=await S9(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=Pm(r);i.innerHTML="";const s=w("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",E0)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");W(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function x_(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new w0);if(r.src||i.dataUrl){const a=w("img",["mathjax"],e);a.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(a,"load",E0);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=R.t("mathjax.emptyText"),w("span",s,e,l),E_(n,r,i)}function I_(n,t){const e={id:K(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return B0(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{O9.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function T_(n,t,e,o){const r=t;return o==="text"?r.tex:o==="markdown"?` $${r.tex}$ `:r.src?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:`<code>$${r.tex}$</code>`}function D_(n,t,e){const o=et(t);g(O9,o,"failed to get block"),!(n.readonly||!n.isBlockWritable(o))&&Cf(n,t)}function S_(){return{abstract:R.t("mathjax.abstract")}}const _9={boxType:"math",updateBoxContent:x_,convertFrom:I_,convertTo:T_,handleClickBox:D_,getBoxProperties:S_};async function L_(n,t,e){try{const o=t.embedData,r=await S9(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=Lt(i);s.innerHTML="";const l=w("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function M_(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=et(t.target);if(!e||!Me(e)||fn(e)!=="math")return;const o=Lt(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!Xt(r,t.target))return;const s=n.getBlockData(e).embedData;M9(n,r,s.mathjaxText,async l=>{const a=await B0(n,l),d={mathjaxText:l,src:a};n.updateEmbedData(e,d)})}function R_(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new w0);if(n.domEvents.addEventListener(t,"click",M_),!o.mathjaxText.trim()){w("span",["mathjax-tex-text"],t,R.t("mathjax.emptyText"));return}if(o.src||r.dataUrl){const i=w("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,w("span",["mathjax-tex-text"],t,o.mathjaxText),L_(n,e,r)}function O_(n,t,e){if(!tt(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=km(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:K(),type:"embed",embedType:"math",embedData:i}}}function __(n){return{name:"Mathjax"}}function F_(n,t){var o;const e=Lt(t);n.domEvents.removeAllListeners(e),n.findCustom("mathjax-editor")&&((o=n.getCustom("mathjax-editor").editMathjaxPopup)==null||o.close("cancelBar"))}function P_(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
397
+ `)),d}if(o==="html"){let d=((a=Dn.convertTo)==null?void 0:a.call(Dn,n,t,e,"html",r))||"";d=d.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:i.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul";return i.ordered?(d=`<li value="${i.start}">${d}</li>`,h="ol"):d=`<li>${d}</li>`,m9(n,t,e,r)&&(d=`<${h}>${d}`),g9(n,t,e,r)&&(d=`${d}</${h}>`),d}return""}function p9(n){const t=w("label",["editor-check-list-wrapper"],null);n&&W(t,"editor-check-list-wrapper-checked");const e=w("span",["editor-check-box"],t);return w("span",["editor-check-box-inner"],e),t}function RO(n,t){const e=fc(t);if(e!=="text-only"){if(e==="checked"){n.append(p9(!0));return}if(e==="unchecked"){n.append(p9(!1));return}n.innerText=LO(t)}}function OO(n){const t=w("div",["list-container"],null),e=w("button",["list-marker"],t);return RO(e,n),t}function C9(n){let t=Zt(n);if(!t)return null;const e=qs(n);for(;t!==e;){if(g(we,t,"no next block"),Ht(t))return vn(t)>vn(n)?t:null;if(t=Zt(t),!t)return null}return null}function p0(n){const t=[];let e=C9(n);if(!e)return t;for(;e;){const o=qs(e);t.push({block:e,children:p0(e)}),e=o}return t}function _O(n){const t=(o,r)=>{r.push(o.block),o.children.forEach(i=>t(i,r))},e=[];return n.forEach(o=>t(o,e)),e}function A9(n,t){return vn(t)!==1}function b9(n,t,e){t.forEach(o=>{const r=n.getBlockData(o.block);n.updateBlockData(o.block,{...r,groupId:e,level:r.level-1}),o.children.length&&b9(n,o.children,r.groupId)})}function C0(n,t){if(!A9(n,t))return!1;const e=vn(t);if(e===1)return!1;let o=K(),r=1,i=Zn(t);const s=e-1,l=l0(t);l&&(o=ac(l),r=mo(l)+1,i!=="text-only"&&(i=Zn(l)));const a=p0(t),d=n.getBlockData(t),h={...d,groupId:o,level:s,start:r,...s0(i)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),b9(n,a,d.groupId),n.doc.endBatchUpdate(),new Gs(n,t).fix();const A=C9(t);return A&&new Gs(n,A,{resetStart:!0,resetGroupId:!0}).fix(),!0}function mc(n,t){Fe(t);const e=n.getBlockData(t),o={id:K(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new ff(n,t),i=nt(t),s=bt(t);n.deleteBlock(t);const l=ph(o.id,0);if(wa(n,i)&&!Yt(i)){const a=ye(i);n.insertBlock(ct(i),s,o,l),n.deleteBlock(a)}else n.insertBlock(ct(i),s,o,l);r.fix()}function FO(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:vn(t)===1?(mc(n,t),!0):(C0(n,t),!0)}const PO=S("list-block");function NO(n,t,e){g(PO,Ht(t),"not a list block");const o={...n.getBlockData(t),id:K()};return e!=null&&e.level&&(o.level=e.level),e!=null&&e.start&&(o.start=e.start),e!=null&&e.keepText||delete o.text,(o==null?void 0:o.checkbox)==="checked"&&(o.checkbox="unchecked"),o}function $O(n){if(Fe(n),!uf(n))return n;let t=Gi(n);for(;t;){if(!uf(t))return t;t=Gi(t)}return null}function HO(n,t,e,o){const r=new Gs(n,o),i=mo(o)+1;Ql(n,t,e,{forceInsertAfter:!0,newBlockData:NO(n,o,{start:i})}),r.fix()}function jO(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Ht(l)&&ut(n,l)===0)return mc(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===ut(n,t)?$O(t):t)!=null?s:t;return HO(n,t,o,i),!0}function v9(n){g(we,Ht(n),"not a list block");const{level:t}=qi(n);let e=ce(n);for(;e;){if(Ht(e)){const{level:o}=qi(e);if(t===o)return e;if(o<t)return null}e=ce(e)}return null}function y9(n,t){return Fe(t),v9(t)?vn(t)<zR:!1}function UO(n,t,e){let o=ce(t);g(we,o,"no prev brother");const r=vn(e);for(;o;){if(o===e)return null;if(Ht(o)&&vn(o)===r+1)return o;o=ce(o)}return null}function k9(n,t){if(!y9(n,t))return!1;Fe(t);const e=v9(t);g(we,e,"no list prev brother");const o=e,r=UO(n,t,o),i=vn(o)+1;let s=K(),l=1,a=Zn(t);r&&(s=ac(r),l=mo(r)+1,a=Zn(r));const d=p0(t),p={...n.getBlockData(t),groupId:s,level:i,start:l,...s0(a)};return n.updateBlockData(t,p),n.doc.beginBatchUpdate(),_O(d).forEach(v=>{const B=n.getBlockData(v);n.updateBlockData(v,{...B,level:B.level+1})}),n.doc.endBatchUpdate(),!0}function zO(n,t,e){return t.length===0||!t.every(o=>Ht(o.block))?!1:e==="increase"?y9(n,t[0].block):A9(n,t[0].block)}function w9(n,t,e){if(!zO(n,t,e))return!1;const o=t[0].block,r=vn(o),i=t.filter(d=>vn(d.block)<=r),s=s9(o,{withSelf:!1}),l=new Set(i.map(d=>d.block)),a=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;a.length>0&&(d=new Gs(n,a[0])),i.forEach(h=>{e==="increase"?k9(n,h.block):C0(n,h.block)}),d==null||d.fix()}),!0}function VO(n,t){return k9(n,t)}function WO(n,t){return C0(n,t)}function qO(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return w9(n,t,"increase"),!0;const e=t[0].block;if(!Ht(e))return!1;const o=new ff(n,e);return VO(n,e)&&(o.fix(),new Gs(n,e).fix()),!0}function GO(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return w9(n,t,"decrease"),!0;const e=t[0].block;return Ht(e)?(WO(n,e),!0):!1}class ZO{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>Ht(i.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!Ht(e.block)||or(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>jO(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>FO(this.editor))}handleTab(t){return or(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>GO(this.editor)):this.editor.undoManager.runInGroup(()=>qO(this.editor))}}class QO{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(r=>{const i=r.block;Ht(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var a;const i=Cu(r),{start:s}=qi(i);o.set(it(i),s);const l=(a=QR(r))!=null?a:r;o.set(it(l),s)}),this.effectedBlockIds=o});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||h0(this.editor,o,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const YO=S("customize-list-start-menu");class JO{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");g(YO,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});m(this,"createDialogContent",()=>{const t=w("div",["customize-start-panel"],null);w("span",["customize-start-panel-title"],t,R.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const o=w("button",["customize-start-panel-button"],t,R.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});m(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,o=e.querySelector("button.customize-start-panel-button"),r=e.querySelector("input.customize-start-panel-input"),i=mo(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});m(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),o=this.block;if(!o)return;const r=Number(e.value);!r||(this.editor.undoManager.runInGroup(()=>{hc(this.editor,[o,...uc(o)],r,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||(o.key==="Escape"?this.popup.close("cancelBar"):o.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new Xa(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=w("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const r=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),i=parseInt(r,10);i<=0||Number.isNaN(i)?t.value="":t.value=r};return this.editor.domEvents.addEventListener(t,"input",e),t}}function KO(n,t){return ac(n)===ac(t)}function XO(n,t){const e=r9(t);return e?KO(e,t)?mo(e)!==mo(t)-1:!0:!1}function t_(n,t){return Gi(t)?!0:mo(t)!==1}function e_(n,t){return Fe(t),[{id:"continue-numbering",name:R.t("list.continueList"),states:XO(n,t)?[]:["disabled"]},{id:"start-new-list",name:R.t("list.restartList"),states:t_(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:R.t("list.changeNumber")}]}function n_(n,t,e){var o,r;if(Fe(t),e.id==="continue-numbering"){const i=r9(t);i&&hc(n,[t,...uc(t)],mo(i)+1,{resetGroupId:!0,groupId:ac(i)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{hc(n,[t,...uc(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const i=(o=n.options.componentsOptions)==null?void 0:o.list;if((r=i==null?void 0:i.onChangeStart)!=null&&r.call(i,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new JO(n)).show(n,t)}}class o_{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const o=Hl(e,"div.list-container");if(o&&this.editor.isWritable()){const r=et(o);g(we,r,"no parent block"),Fe(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}if(Zn(r)==="unordered")return;this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!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 r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=et(o);i&&n_(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new Us([]),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 e_(this.editor,t)}activeList(t,e){const o=et(t);!o||(e?(W(t,"active"),W(o,"active")):(ot(t,"active"),ot(o,"active")))}}class r_{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0)return!1;const r=o[0].block;if(!Ht(r)||!u9(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=Is(r);return i&&t.selection.selectBlock(i,ut(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Ts(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&h9(t,r),!0}}function i_(n,t,e,o,r){tp(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new r_(n)),n.input.addHandler(new ZO(n)),n.addCustom("list-clear-selection-handler",()=>new QO(n)),n.addCustom("list-marker-menu",()=>new o_(n))})});const i=Dn.createBlockContent(n,t,e,o,r),s=r,{level:l,start:a,groupId:d}=s,h=fc(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${a||1}`),o.setAttribute("data-list-group-id",`${d}`),o.setAttribute("data-list-type",h);const p=OO(s);return o.insertBefore(p,i),s.viewAsMindmap?setTimeout(()=>{const A=n.getBlockById(r.id);A&&df(n,A,{},{mindmapTools:d0,saveData:!1})}):setTimeout(()=>{const A=n.getBlockById(r.id);A&&d9(n,A)}),i}const s_={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"}},l_={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"}},c_={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"}};R.mergeLang({"zh-CN":s_,"en-US":l_,"ja-JP":c_});const Int="",B9={...Dn,blockType:"list",createBlockContent:i_,convertFrom:SO,convertTo:MO,handleDrop:vO,notify:pO},A0=S("paragraph");class a_{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 o=[],r={"unordered-list":[R.t("commands.unordered"),xo("CtrlOrCmd+Shift+L"),CL],"ordered-list":[R.t("commands.ordered"),xo("CtrlOrCmd+Shift+U"),pL],"check-list":[R.t("commands.check"),void 0,AL],link:[R.t("commands.link"),xo("CtrlOrCmd+K"),av],quoted:[R.t("commands.quote"),void 0,bL]};if(tt(t,e)){const i=it(e),s=Dt(e),l=Do(t,e),a=t.getBlockData(e);Object.entries(r).forEach(([d,[h,p,A]])=>{const v=[];if(this.isChecked(a,d)&&v.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&v.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:d,name:h,desc:p,states:v,icon:A,groupIndex:600})})}return o}convertLink(t,e,o){g(A0,Ur(e.start),""),g(A0,Ur(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(v,B)=>{t.undoManager.runInGroup(()=>{try{const D=t.selection.range.isCollapsed();let x;if(D){x=Vr(t.getBlockText(o),s,v,{link:B}),t.setBlockText(o,x);return}x=fh(t.getBlockText(o),i,s,v),x=Ia(i,v.length,x,"link",B),t.setBlockText(o,x),t.selection.selectBlock(o,i+v.length),t.focus()}catch(D){A0.error(D)}})},a=()=>{t.selection.selectBlock(o,s),t.focus()},d=Nr(t,o,e)[0];if(!d)return;const h=zr(t,o,"link-button-anchor",d),p=t.getBlockText(o),A=Ta(p,i);gu(t,{target:h,linkText:t.getSelectedText(),linkUrl:(A==null?void 0:A.link)||"",onFinished:l,onClose:a,placement:r})}convertToList(t,e,o){const r=th(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=bt(e),s=nt(e);t.insertBlock(ct(s),i,r.blockData),t.deleteBlock(e),t.focus()})}executeCommand(t,e,o,r){var a;if(!tt(t,e))return!1;const i=r.id,s=(a=r.states)==null?void 0:a.includes("checked");let l=!1;if(i==="unordered-list"&&(s?mc(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?mc(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?mc(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),t.focus(),l=!0}if(i==="link"){const d=lf(t);d==null||d.disableTextToolbar(),d==null||d.hide(),setTimeout(()=>{d==null||d.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const u_={left:tu,right:Ip,center:Tp};class d_{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(u_).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(tt(t,e)){const r=it(e),i=Dt(e),s=Do(t,e),l=t.getBlockData(e),a=d=>{var p;const h=w("span",["toolbar-item-name-container"],null);for(const A of d.children)if((p=A.states)!=null&&p.includes("checked"))return h.innerHTML=A.icon||tu,h;return h.innerHTML=tu,h};return[{id:"align",name:R.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:a,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:R.t("commands.alignLeft"),icon:tu,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:R.t("commands.alignCenter"),icon:Tp,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:R.t("commands.alignRight"),icon:Ip,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(!tt(t,e))return!1;if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),this.editor.focus(),!0}return!1}}function h_(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const o=n.getBlockById(e.start.blockId);return Sa(n,o,e.start.offset).charType==="box"}const f_=S("toolbar-handler"),m_={id:"",name:"",type:"separator"};class gc{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,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&$R(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const o=oC(e);if(this.hoveringBlock===o)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,o,r)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close("fromHover");return}this.showObjectToolbar(r)}});m(this,"handleSelectionChange",Le.default(t=>{var o;if(g(f_,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const r=(o=this.toolbar.tippyInstance)==null?void 0:o.reference,i=this.editor.selection.focusedBlock;if(r&&Xt(r,i))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 ou([],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),Ce.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Ce.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new jR(t)),t.editorCommandProviders.registerCommandProvider(new a_(t)),t.editorCommandProviders.registerCommandProvider(new d_(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),Ce.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&Xt(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){var D,x;if(this._disableTextToolbar||!this.editor.isWritable())return;const o=this.editor.selection.range.getSelectedBlocks();if(o.length===0)return;const r=o[0];if(!r)return;if(o.length===1&&Me(r.block)){t==="click"&&this.showObjectToolbar(null);return}if(h_(this.editor))return;if(nt(r.block)===this.editor.rootContainer&&bt(r.block)===0){this.toolbar.close("selectionChange");return}const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(_=>{const M=_.groupIndex,H=s.get(M);H?H.push(_):s.set(M,[_])});const l=[[]],a=Array.from(s.entries()).sort((_,M)=>_[0]-M[0]);for(let _=0;_<a.length;_++){const[,M]=a[_];if(M.length===0)continue;let H=l[l.length-1];H.length>0&&H[H.length-1].groupIndex!==M[M.length-1].groupIndex&&(H=[],l.push(H)),H.push(...sf(M))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((_,M)=>{const H=_.sort((z,q)=>{var rt,ft;return((rt=z.order)!=null?rt:0)-((ft=q.order)!=null?ft:0)});d.push(...H),M!==l.length-1&&d.push(m_)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=o[o.length-1],p=!this.editor.selection.range.isReverse()&&h!==r,A=p?h:r,v=LR(this.editor,A),B=zr(this.editor,A.block,"editor-quick-menu",v);this.toolbar.manualShow(B,{placement:p?"bottom":"top",offset:[0,p?5:10]}),(x=(D=this.toolbar.tippyInstance)==null?void 0:D.popperInstance)==null||x.update()}showObjectToolbar(t){var l,a,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,o=this.hoveringTextChild,{commands:r,element:i}=FR(this.editor,e,o);if(!r.length||!i){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((a=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:a.reference)!==i&&this.toolbar.close("fromHover");const s=()=>{let h;const p=i.getClientRects();if(p.length>1){if(h=o?p[p.length-1]:p[0],t)for(let A=0;A<p.length;A++){const v=p[A],B=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(B.x<t.clientX&&t.clientX<B.right&&B.y<t.clientY&&t.clientY<B.bottom){h=v;break}}}else{if(h=i.getBoundingClientRect(),o){const A=o.getBoundingClientRect();return new DOMRect(A.x,A.y,A.width,A.height)}return new DOMRect(p[0].x,p[0].y,p[0].width,p[0].height)}if(t){const A=h.y,v=t.clientX;return new DOMRect(v,A,10,h.height)}return h};this.toolbar.updateItems(r),this.toolbar.isVisible||(this.toolbar.manualShow(i,{placement:o?"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 gc(e))}static get(t){return t.getCustom("toolbar-handler")}}function pf(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function E9(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function b0(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function v0(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 y0(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=v0(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=v0(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=v0(r,"check-list")?void 0:"unchecked";break}if(i){const s=th(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=bt(t),a=nt(t);n.deleteBlock(t),n.insertBlock(ct(a),l,s.blockData)})}else mc(n,t)}const g_=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:pf,applyAlignStyle:E9,applyQuoteStyle:b0,applyList:y0},Symbol.toStringTag,{value:"Module"})),p_=[bp,vp,yp,kp,wp,Bp,Ep,xp],C_={Unordered:hv,Ordered:fv,Checkbox:uv,Quote:dv};function x9(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>x9(o,t))}function A_(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:nu,name:R.t("commands.text"),order:0,group:"basics",value:"text"}]}}function k0(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=cf();e<=4?e=5:e<8&&(e+=1);let o=n;for(;o<=e;){const i=`heading-${o}`;(r=t.insertBlockCommandItems)==null||r.push({id:i,icon:p_[o-1],name:R.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:An(i)}),o++}return t}function b_(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,o)=>{var i;const r=`insert-${e.toLocaleLowerCase()}`;(i=n.insertBlockCommandItems)==null||i.push({id:r,name:R.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:C_[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:An(r)})}),n}class I9{constructor(t){this.withPlainText=t}getCommands(){const t=A_(),e=k0(),o=b_();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...o.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?pf(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?y0(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&b0(t,o),null}async handleUpdateBlockCore(t,e){const o=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,o,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:o,blockIndex:r}=e,i=t.insertTextBlock(void 0,o,r);return this.updateBlock(t,e.containerId,i,e.item)}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=ct(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else o.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex})),t.focus());return null}}const T9={basics:100,system:200,common:300,thirdParty:400};class w0{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 v_=S("mathjax-converter"),y_="MathJax-script";async function k_(n){var o;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((o=t==null?void 0:t.cdn)==null?void 0:o.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await bs(e,y_)}function w_(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function D9(n,t){const e="mathjax2Svg";try{await Eo.lock(e),w_(),await k_(n);const o=await window.MathJax.tex2svgPromise(t),r=o.querySelector("merror");if(r)throw new Error(r.textContent);return o.querySelector("svg").outerHTML}catch(o){throw v_.error(o),o}finally{Eo.release(e)}}async function S9(n,t){const e=await D9(n,t);return e?await Im(e,"image/svg+xml"):""}async function B0(n,t){const o=await D9(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const L9=S("edit-mathjax");class B_{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"observer",null);m(this,"handleClose",t=>{var o;const e=t.content.querySelector("textarea");if(e){const r=e.value;r!==this.tex&&((o=this.onChange)==null||o.call(this,r,!0))}});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",Le.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new Xa(this.createPopupContent(e));else{const r=this.getTextarea();r.value=e}this.tex=e,this.editMathjaxPopup.manualShow(t,{theme:"light"}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=o}createPopupContent(t){const e=w("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 r;(r=this.editMathjaxPopup)!=null&&r.isVisible&&t.focus()};const o=()=>{setTimeout(()=>{t.focus()})};this.observer=new IntersectionObserver(o,{}),this.observer.observe(t)}getTextarea(){g(L9,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return g(L9,t,"no textarea"),t}destroy(){var t,e;this.onChange=null,(t=this.observer)==null||t.disconnect(),(e=this.editMathjaxPopup)==null||e.removeAllListeners()}}function M9(n,t,e,o){n.addCustom("mathjax-editor",()=>new B_).editMathjax(t,e.trim(),o)}function R9(){return{insert:" ",attributes:{id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function Cf(n,t){const e=n.getBoxData(t),o=et(t);if(!o)return;const r=Os(o,t);n.selection.selectBlock(o,r.start,r.end);const i=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await Eo.lock("convertAndUploadMathjax");const a=await B0(n,s);n.updateBoxData({...e,tex:s,src:a})}catch(a){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new w0).setError(a),n.updateBoxData({...e,tex:s,src:""})}finally{Eo.release("convertAndUploadMathjax"),l&&n.focus()}};M9(n,t,e.tex,i)}const O9=S("mathjax-box");function E0(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,E0)}async function E_(n,t,e){try{if(!t.tex.trim())return;const o=await S9(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=Pm(r);i.innerHTML="";const s=w("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",E0)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");W(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function x_(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new w0);if(r.src||i.dataUrl){const a=w("img",["mathjax"],e);a.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(a,"load",E0);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=R.t("mathjax.emptyText"),w("span",s,e,l),E_(n,r,i)}function I_(n,t){const e={id:K(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return B0(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{O9.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function T_(n,t,e,o){const r=t;return o==="text"?r.tex:o==="markdown"?` $${r.tex}$ `:r.src?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:`<code>$${r.tex}$</code>`}function D_(n,t,e){const o=et(t);g(O9,o,"failed to get block"),!(n.readonly||!n.isBlockWritable(o))&&Cf(n,t)}function S_(){return{abstract:R.t("mathjax.abstract")}}const _9={boxType:"math",updateBoxContent:x_,convertFrom:I_,convertTo:T_,handleClickBox:D_,getBoxProperties:S_};async function L_(n,t,e){try{const o=t.embedData,r=await S9(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=Lt(i);s.innerHTML="";const l=w("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function M_(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=et(t.target);if(!e||!Me(e)||fn(e)!=="math")return;const o=Lt(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!Xt(r,t.target))return;const s=n.getBlockData(e).embedData;M9(n,r,s.mathjaxText,async l=>{const a=await B0(n,l),d={mathjaxText:l,src:a};n.updateEmbedData(e,d)})}function R_(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new w0);if(n.domEvents.addEventListener(t,"click",M_),!o.mathjaxText.trim()){w("span",["mathjax-tex-text"],t,R.t("mathjax.emptyText"));return}if(o.src||r.dataUrl){const i=w("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,w("span",["mathjax-tex-text"],t,o.mathjaxText),L_(n,e,r)}function O_(n,t,e){if(!tt(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=km(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:K(),type:"embed",embedType:"math",embedData:i}}}function __(n){return{name:"Mathjax"}}function F_(n,t){var o;const e=Lt(t);n.domEvents.removeAllListeners(e),n.findCustom("mathjax-editor")&&((o=n.getCustom("mathjax-editor").editMathjaxPopup)==null||o.close("cancelBar"))}function P_(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
398
398
  $$${r.mathjaxText}$$
399
399
  `:r.mathjaxText}function N_(){return{abstract:R.t("mathjax.abstract")}}const $_={embedType:"math",createEmbedContent:R_,getOptions:__,convertFrom:O_,handleDeleteBlock:F_,convertTo:P_,getBlockProperties:N_},Tnt="",H_={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},j_={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},U_={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};R.mergeLang({"zh-CN":H_,"en-US":j_,"ja-JP":U_});function z_(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=Tn(i,o);if(!ie(s).endsWith("$$$$"))return!1;const a=o-4,d=o,h={id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a),n.insertBoxToBlock(r,a,h),setTimeout(()=>{const p=n.getBoxById(h.id);Cf(n,p)})}),!0}class V_{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&z_(t,e,o,r))}}const pc=S("inline-box-items");function W_(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);ae(n,o)||(o=n.insertTextBlock([],t,e));const r=R9();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return g(pc,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);Cf(n,l)},100),o})}function q_(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return ae(n,o)||(r="top-start"),gu(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,a)=>{n.undoManager.runInGroup(()=>{try{ae(n,o)||(o=n.insertTextBlock([],t,e));const d=co(l,{link:a}),h=co(" ",null),p=[d,h];n.insertTextToBlock(o,0,p),n.selection.selectBlock(o,rn(p)),n.focus()}catch(d){pc.error(d)}})},onClose:()=>{n.focus()},placement:r}),o}function G_(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;g(pc,Ur(r.start),"invalid block position");const i=R9();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return g(pc,s,"mathjax box id is empty"),setTimeout(()=>{const a=n.getBoxById(s);Cf(n,a)},100),o})}function Z_(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;g(pc,Ur(r.start),"invalid block position");const i=Nr(n,o,r);if(i.length===0)return;const s=i[0],l=zr(n,o,"quick-menu-inline-link",s);gu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,p)=>{n.undoManager.runInGroup(()=>{try{const A=n.getBlockText(o),v=Vr(A,r.start.offset,h,{link:p});n.setBlockText(o,v),n.selection.selectBlock(o,r.start.offset+h.length),n.focus()}catch(A){pc.error(A)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class F9{getCommands(){return[{id:"insert-math",name:R.t("quickMenu.inlineBox.math"),icon:EL,order:900,group:"common",subText:An("insert-math")},{id:"insert-link",name:R.t("quickMenu.inlineBox.link"),icon:av,order:400,group:"common",subText:An("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return G_(t,e.containerId,e.blockIndex);case"insert-link":return Z_(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return W_(t,e.containerId,e.blockIndex);case"insert-link":return q_(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=ct(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else o.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex}));return null}}function Q_(n,t={withPlainText:!1}){var i,s;const{withPlainText:e}=t,o=(s=(i=n.options.componentsOptions)==null?void 0:i.quickMenu)==null?void 0:s.commandProviders;if(!o)return[];const r=[];return[...o,new I9(e),new F9].forEach(l=>{const a=l.getCommands(n);r.push(...a.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),r}function Y_(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(o=>{if(!o.getOptions)return;const r=o.getOptions(n);!r.insertBlockCommandItems||(r.insertBlockCommandItems.forEach(i=>{x9(i,r)}),e.push(...r.insertBlockCommandItems))}),e.push(...Q_(n,t)),e}function x0(n,t={withPlainText:!1}){const e=Y_(n,t),o=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let a=o.get(l);a?a.items.push(s):(a={group:l,order:s.groupOrder||T9[l]||1e3,items:[s]},o.set(l,a))});const r=Array.from(o.values());r.sort((s,l)=>s.order-l.order),r.forEach(s=>{s.items.sort((l,a)=>{var d,h;return((d=l.order)!=null?d:0)-((h=a.order)!=null?h:0)})});const i=[];return r.forEach((s,l)=>{const a=`blockMenu.section.${s.group||"common"}`,d=R.t(a),h=d===a?s.group:d;i.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),i.push(...s.items.map(p=>({...p})))}),i}function J_(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=ct(r);let l=n.getBlockIndex(o);if(ae(n,o)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:i,blockIndex:l,item:t})}const P9=S("quick-menu"),K_={id:"quick-menu",trigger:["/"]},X_=5;class Af{constructor(t,e=K_){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 o=new Set,r=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,""),i=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(r)!==-1||pM(s).toLocaleLowerCase().indexOf(r)!==-1)return o.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,a=R.t(l),d=a===l?s.group:a;return(d==null?void 0:d.toLocaleLowerCase().indexOf(r))!==-1?(o.add(s.group),!0):!1}).filter(s=>s.type==="section"?o.has(s.group):!0);return i.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),i}return this.items});m(this,"onClose",()=>{this.firstEmptyOffset=-1});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!io(i)){const s=et(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(g(P9,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),g(P9,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),J_(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=cf(),this.suggest=new Fp(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=x0(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=cf();if(o!==this.maxHeading){const r=new I9,s=r.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:r}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=o}}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>X_&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class bf{constructor(t){m(this,"instance");m(this,"mousedown",!1);m(this,"currentInstance",null);m(this,"attributeName",[]);m(this,"attributeDesc","");m(this,"observer",null);m(this,"observerCallback",null);m(this,"createContent",t=>{let e="",o=0;for(;o<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[o])&&(e=t.getAttribute(this.attributeName[o])||""),o++;const r=t.getAttribute(this.attributeDesc);if(!r)return e;const i=w("div",[],null);return w("span",[],i,e),r&&w("span",["editor-tooltip-desc"],i,r),i});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 r;const e=t.reference;if(!e||!Xt(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);if(o&&Date.now()-o<1e3)return!1;if(t.reference){const i={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(i.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 s=t.reference.getAttribute("data-editor-tooltip-offset-x"),l=t.reference.getAttribute("data-editor-tooltip-offset-y");i.offset=[s?Number.parseInt(s,10):0,l?Number.parseInt(l,10):0]}if(t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(i.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(i.allowHTML=!0),Object.keys(i).length&&t.setProps(i),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const s=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(s||"")}}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=am.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(o=>`[${o}]`).join(","),content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Le.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,o={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,o)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}}const tF={"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"};function eF(n,t){const e=new Set(Object.keys(tF)),o=t.filter(i=>e.has(i.id));return sf(o)}function vf(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=eF(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),gc.get(n).update("selectionChange"),!0):!1}const I0={"CtrlOrCmd+B":n=>vf(n,"style-bold"),"CtrlOrCmd+I":n=>vf(n,"style-italic"),"CtrlOrCmd+U":n=>vf(n,"style-underline"),"CtrlOrCmd+D":n=>vf(n,"style-strikethrough")},nF={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u4E8B\u9879",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88",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"}},oF={quickMenu:{basic:{heading:{title:"Title {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:"Title {name}",headingGroup:"Text style",text:"Text"}},rF={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"}};R.mergeLang({"zh-CN":nF,"en-US":oF,"ja-JP":rF});const Dnt="";function Zs(n,...t){const e=uo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function N9(n){const t=lf(n);t==null||t.hide();const e=n.findCustom("table-border-bar");e==null||e.closeToolbar()}function iF(n){return w("div",["insert-column-button","drop-marker"],n)}const sF=S("row-height");function $9(n){const t=Tt.fromTable(n),e=n.rows;g(sF,e.length===t.rowCount,"row count mismatch");const o=Array(t.rowCount).fill(0);for(let r=0;r<e.length;){let i=1,l=e[r].getBoundingClientRect().height,a=r+1;for(;a<e.length;){const d=e[a];if(d.cells.length!==0)break;i++,a++,l+=d.getBoundingClientRect().height}for(let d=0;d<i;d++)o[r+d]=l/i;r=a}return o}const lF=S("table-border-bar-dom");function H9(n){var a;const t=et(n.contentElement);g(lF,t,"no block");const o=te(t).querySelector(".table-border-bar-container.left"),i=Lt(t).offsetLeft-ic,s=((a=n.scrollOptions.paddingLeft)!=null?a:0)+i,l=Math.min(n.contentElement.offsetLeft-i,n.rootElement.scrollLeft-s);o&&(o.style.left=`${-l}px`)}const Zi=S("table-border-bar-dom");function Cc(n,t){g(Zi,Ve(t),"invalid table block");const e=_e(t),o=gr(n,t),r=te(t),i=(p,A,v)=>{const B=w("div",["button-root",A],p),D=w("div",["button-container",A],B);B.setAttribute(`data-${A}-index`,`${v}`),D.setAttribute(`data-editor-tooltip-${n.clientId}`,A==="left"?R.t("table.insertRow"):R.t("table.insertCol")),w("span",["insert-indicator"],D),iF(D)},{selectedRows:s,selectedColumns:l}=Np(n,t),a=()=>{const p=o.querySelector(".table-border-bar-container.top");g(Zi,p,"no top border bar container");const A=w("div",["table-border-bar-container","top"],null),v=w("div",["table-border-bar","top"],A),B=gR(e),x=Tt.fromTable(e).colCount;n.selection.range.isSimple()&&i(v,"top",0);for(let _=0;_<x;_++){const M=_===x-1?B[_]+2:B[_],H=w("span",["table-border-bar-cell","top"],v);l.has(_)&&H.classList.add("selected"),H.setAttribute("data-top-index",`${_}`),H.style.width=`${M}px`,n.selection.range.isSimple()&&i(v,"top",_+1)}pa(p,A)},d=()=>{const p=r.querySelector(".table-border-bar-container.left");g(Zi,p,"no left border bar container");const A=w("div",["table-border-bar-container","left"],null),v=w("div",["table-border-bar","left"],A);w("span",["table-border-bar-cell","corner"],v);const B=$9(e);n.selection.range.isSimple()&&i(v,"left",0),Array.from(e.rows).forEach((D,x,_)=>{const M=w("span",["table-border-bar-cell","left"],v);s.has(x)&&M.classList.add("selected"),M.setAttribute("data-left-index",`${x}`);const H=x===_.length-1?B[x]+2:B[x];M.style.height=`${H}px`,n.selection.range.isSimple()&&i(v,"left",x+1)}),pa(p,A)};a(),d();const h=n.findCustom(mr(t));h&&H9(h)}function j9(n,t){const e=t.target;if(!(e instanceof Element))return;const o=et(e);g(Zi,o&&Ve(o),"invalid table block"),Cc(n,o),n.selection.caret.update()}function yf(n,t){const e=t.target;if(!(e instanceof Element))return;const o=et(e);g(Zi,o&&Ve(o),"invalid table block");const r=e.closest(".button-root");if(r){if(r.classList.contains("top")){const i=parseInt(r.getAttribute("data-top-index")||"0",10);Yv(n,o,i),Cc(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);Jv(n,o,i),Cc(n,o)}}}function kf(n,t){var s;N9(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var a;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const d=et(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const p=parseInt((a=l.target.getAttribute(`data-${o}-index`))!=null?a:"0",10),A=Math.min(r,p),v=Math.abs(r-p)+1;xt(l.target,"top")&&o==="top"?DR(n,d,A,v,{reverse:!0}):xt(l.target,"left")&&o==="left"&&SR(n,d,A,v,{reverse:!0})}}l.type==="mouseup"&&(e=null,r=void 0,o=void 0,document.body.removeEventListener("mousemove",i),document.body.removeEventListener("mouseup",i))};t.target instanceof HTMLElement&&xt(t.target,"table-border-bar-cell")&&(e=et(t.target),xt(t.target,"top")?o="top":xt(t.target,"left")&&(o="left"),o&&e&&(r=parseInt((s=t.target.getAttribute(`data-${o}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",i),document.body.addEventListener("mouseup",i)))}function U9(n){const t=n.selection.range,e=su(n,t);e&&Cc(n,e)}function cF(n,t){g(Zi,Ve(t),"invalid table block");const e=gr(n,t),o=te(t),r=w("div",["table-border-bar-container","top"],e),i=w("div",["table-border-bar-container","left"],o);Cc(n,t),n.domEvents.addEventListener(Lt(t),"scroll",j9),n.domEvents.addEventListener(r,"click",yf),n.domEvents.addEventListener(i,"click",yf),n.domEvents.addEventListener(r,"mousedown",kf),n.domEvents.addEventListener(i,"mousedown",kf),n.addListener("afterClearSelection",U9)}function z9(n,t){if(!n.isWritable())return;if(gr(n,t).querySelector(".table-border-bar-container")){Cc(n,t);return}cF(n,t)}function V9(n,t){g(Zi,Ve(t),"invalid table block");const e=gr(n,t),o=te(t),r=e.querySelectorAll(".table-border-bar-container"),i=o.querySelectorAll(".table-border-bar-container");r.forEach(s=>{n.domEvents.removeEventListener(s,"click",yf),n.domEvents.removeEventListener(s,"mousedown",kf),s.remove()}),i.forEach(s=>{n.domEvents.removeEventListener(s,"click",yf),n.domEvents.removeEventListener(s,"mousedown",kf),s.remove()}),n.domEvents.removeEventListener(Lt(t),"scroll",j9),n.addListener("afterClearSelection",U9)}function aF(n,t){g(Zi,Ve(t),"invalid table block");const o=gr(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class uF{constructor(t,e){m(this,"toolbar");m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(zi(this.editor,this.tableBlock,!0,!0),Vi(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(zi(this.editor,this.tableBlock,!0,!1),Vi(this.editor,this.tableBlock,!0,!1)):(zi(this.editor,this.tableBlock,!1),Vi(this.editor,this.tableBlock,!1)))});m(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?$p(this.editor.selection.range):e.id==="delete-rows"&&Hp(this.editor.selection.range)});m(this,"handleToolbarClose",()=>{this.tableBlock&&su(this.editor,this.editor.selection.range)===this.tableBlock&&(zi(this.editor,this.tableBlock,!1),Vi(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ou([],void 0,{id:"table-row-column-toolbar",overflowBoundary:o==null?void 0:o.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var r,i,s;const{selectedColumns:t,selectedRows:e}=Np(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 o=Nr(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:R.t("table.deleteCol"),icon:hL};this.toolbar.updateItems([l]);const a=zr(this.editor,this.tableBlock,"table-row-column-delete",o);this.toolbar.manualShow(a,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:R.t("table.deleteRow"),icon:dL};this.toolbar.updateItems([l]);const h=te(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),p=new DOMRect(Math.max(h.left,o.left-ic),o.top,ic,o.height),A=zr(this.editor,this.tableBlock,"table-row-column-delete",p);this.toolbar.manualShow(A,{placement:"left",offset:[0,5]});const v=this.editor.options.componentsOptions.popover;(r=this.toolbar.tippyInstance)==null||r.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:v==null?void 0:v.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(i=this.toolbar.tippyInstance)==null?void 0:i.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const T0=S("table-border-bar");class dF{constructor(t,e){m(this,"toolbar");m(this,"resizeObserver");m(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():V9(this.editor,this.tableBlock)});m(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(it(this.tableBlock));this.resizeObserver.observe(_e(t))})});m(this,"handleScroll",()=>{var t;(t=this.toolbar)==null||t.update()});m(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,g(T0,this.tableBlock,"no table block"),T0.debug("create table border bar"),z9(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(_e(this.tableBlock));const o=t.getComponentOptions("table");o!=null&&o.hideToolbar||(this.toolbar=new uF(this.editor,this.tableBlock)),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){var t;(t=this.toolbar)==null||t.close()}destroy(){var t;T0.debug("destroy table border bar"),this.resizeObserver.disconnect(),V9(this.editor,this.tableBlock),(t=this.toolbar)==null||t.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){var t;z9(this.editor,this.tableBlock),(t=this.toolbar)==null||t.update()}}const hF=S("table-border-bar");class fF{constructor(t){m(this,"activeTableBar",null);m(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||Xt(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});m(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range,o=su(t,e);((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});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(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new dF(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(g(hF,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function W9(n,t){const e=n.addCustom("table-border-bar",o=>new fF(o));t==="update"&&e.update()}const Mn=S("table-cell-menu"),mF="style-bg-color-";class gF{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,o=su(t,e);if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=Tt.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;i instanceof Mo?t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId):i.blockId!==this.activeTableBlock.id&&(s=this.getCellByChildBlockId(r,i.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=w("div",["cell-background-color-item"],null);w("span",[],t,R.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();w("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=w("span",["item-sub-indicator"],t);return r.innerHTML=rv,t});m(this,"handleCommand",t=>{var r;g(Mn,this.activeTableBlock,"no target table block");const e=((r=t.states)==null?void 0:r.includes("checked"))||!1,o=t.value;switch(t.id){case"delete-select-row":Hp(Lv(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":$p(Lv(this.editor,this.activeTableBlock,!0));break;case"merge-cell":Tv(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":PM(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":UM(this.editor,this.activeTableBlock,o==="show-chart"),Qp(this.editor,this.activeTableBlock,{updateNow:!0});break}});m(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&su(this.editor,this.editor.selection.range)===this.activeTableBlock&&(zi(this.editor,this.activeTableBlock,!1),Vi(this.editor,this.activeTableBlock,!1)),this.editor.focus()});m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(g(Mn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(zi(this.editor,this.activeTableBlock,!0,!1),Vi(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(zi(this.editor,this.activeTableBlock,!0,!0),Vi(this.editor,this.activeTableBlock,!0,!0)):(zi(this.editor,this.activeTableBlock,!1),Vi(this.editor,this.activeTableBlock,!1)))});m(this,"handleClick",(t,e)=>{var o;g(Mn,this.activeTableBlock,"no target table block"),g(Mn,this.targetButton,"no target button"),N9(this.editor),xt(this.targetButton,"active")?(ot(this.targetButton,"active"),(o=this.manualMenu)==null||o.close("clickItem")):(W(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new Us(this.createCommandMenu()),this.manualMenu.on("click",(r,i)=>{var s;this.handleCommand(i),(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 o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");g(Mn,r,"no parent cell");const i=et(r);if(g(Mn,i,"no parent block"),_e(i)===t.table)return t.getCellByCellElement(r);o=i}return g(Mn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${Wp}`)||t.appendChild(this.targetButton):(this.targetButton=w("button",[Wp],t),this.targetButton.innerHTML=Qh,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),g(Mn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=Tt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Up(this.editor,this.activeTableBlock,{col:o,row:r})}else zp(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;g(Mn,this.activeTableBlock,"no target table block");const t=HM(this.editor,this.activeTableBlock),e=this.editor.getBlockData(this.activeTableBlock),o=new Set;for(const i of t){if(o.size>1)break;const s=ct(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(mF.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){g(Mn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=Iv(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const h=Jr(this.editor,this.activeTableBlock,o.start);o=Ue(this.editor,{anchor:h,focus:h})}const r=xv(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,a=t.noBorder,d=t.chart;return this.colorPaletteItem=new vv("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,p)=>{var A;switch(g(Mn,this.activeTableBlock,"no target table block"),h){case"clearColor":Ov(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":Ov(this.editor,this.activeTableBlock,p);break}(A=this.manualMenu)==null||A.close("clickItem")}),[{id:"cell-background-color",name:R.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:R.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:R.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:R.t("table.deleteSelectRow")},{id:"delete-select-col",name:R.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:R.t("table.tableConfigKey"),children:[{id:"row-title",name:R.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:R.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:R.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:a?R.t("table.tableConfig.showBorder"):R.t("table.tableConfig.hideBorder"),value:a?"show-border":"hide-border"},{id:"show-chart",name:d?R.t("table.tableConfig.hideChart"):R.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){g(Mn,this.activeTableBlock,"no target table block"),t?OM(this.editor,this.activeTableBlock):RM(this.editor,this.activeTableBlock)}handleColTitle(t){g(Mn,this.activeTableBlock,"no target table block"),t?MM(this.editor,this.activeTableBlock):LM(this.editor,this.activeTableBlock)}handleStripeStyle(t){g(Mn,this.activeTableBlock,"no target table block"),t?FM(this.editor,this.activeTableBlock):_M(this.editor,this.activeTableBlock)}}function q9(n){n.addCustom("table-cell-menu",t=>new gF(t))}const wf=S("table-container");function D0(n){const t=n.closest("td");return g(wf,t,"no parent cell for a table cell container"),t}function G9(n){const t=_e(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function S0(n,t,e,o){const r=Tt.fromBlock(n),i=r.getCellByContainerId(ct(t));if(e==="ArrowDown"){const s=r.getBottomCell(i);return s?s.container:null}if(e==="ArrowUp"){const s=r.getTopCell(i);return s?s.container:null}if(e==="ArrowLeft"){const s=r.getAllContainers(),l=s.indexOf(t);if(g(wf,l>=0,"not a valid child container"),l===0)return null;const a=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(ct(a)).row!==i.row?null:a}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(g(wf,l>=0,"not a valid child container"),l===s.length-1)return null;const a=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(ct(a)).row!==i.row?null:a}g(wf,!1,`invalid navigation type: ${e}`)}const pF=12,CF=90,Bf=23,Z9=2;class AF{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 o=et(e);if(o&&Xt(this.editor.rootContainer,o)){const r=Yr(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});m(this,"handleAutoScroll",$B.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(mr(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=r.getBoundingClientRect(),a=Math.min(l.bottom,s),d=Math.max(l.top,0);i.bottom>a&&t.clientY>=a?this.setAutoScroll("bottom"):i.top<d&&t.clientY<=d?this.setAutoScroll("top"):o.scrollLeft>0&&t.clientX<i.left?this.setAutoScroll("left"):o.scrollLeft<o.scrollWidth-o.offsetWidth&&t.clientX>i.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));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 o=t.getBlockById(e.start.blockId),r=Yr(o);if(r){const i=t.getCustom(mr(r)),s=i.rootElement.getBoundingClientRect(),l=So(t,o,e.start);if(s.left>l.left){const a=e.start.offset===0?pF:Z9;i.rootElement.scrollLeft-=s.left-l.left+a}else if(l.right>s.right){const a=e.start.offset===0?CF:Z9;i.rootElement.scrollLeft+=l.right-s.right+a}}}else{const o=t.getBlockById(e.start.blockId),r=Yr(o),i=t.getBlockById(e.end.blockId),s=Yr(i);if(r&&r===s){const l=t.getCustom(mr(r)),a=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?So(t,o,e.start):So(t,i,e.end);else{const h=D0(jr(t,e.start.childContainerId)),p=D0(jr(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():p.getBoundingClientRect()}a.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=a.left-d.left:a.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-a.right)}}});m(this,"handleScroll",t=>{wv(t),this.editor.selection.caret.update()});m(this,"handleReset",t=>{wv(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),H9(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(mr(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),a=r.getBoundingClientRect(),d=Math.min(a.bottom,l),h=Math.max(a.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=Bf,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=Bf,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=Bf,(r.scrollTop>=r.scrollHeight-s||i.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=Bf,(r.scrollTop<=0||i.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function Q9(n){return n.addCustom("table-scroll-events",t=>new AF(t))}const pr=S("create-content");function Y9(n,t,e){const o=new Yh(e),r=e.rows,i=e.cols;g(pr,r>=1,`invalid rows: ${r}`),g(pr,i>=1,`invalid cols: ${i}`),g(pr,e.children,"no table children");const s=w("table",[],null),l=e.colsWidth,a=w("colgroup",[],s);for(let p=0;p<o.colCount;p++){const A=w("col",[],a);l[p]&&(A.style.width=`${l[p]}px`)}const d=w("tbody",[],s);let h=0;for(let p=0;p<r;p++){const A=w("tr",[],d);for(let v=0;v<i;v++){const B=o.getCell({col:v,row:p});if(B.virtual)g(pr,B.colSpan>1||B.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const D=e.children[h],x=w("td",[],A);B.colSpan>1&&(x.colSpan=B.colSpan),B.rowSpan>1&&(x.rowSpan=B.rowSpan);const _=e[au(D)];_&&W(x,_),v===0&&e.hasColTitle&&W(x,Dv.COL_TITLE_ITEM),n.createChildContainer(t,x,D),h+=1}}}return g(pr,h===e.children.length,"container count mismatch"),e.noBorder&&W(s,"no-border"),e.chart&&W(s,"editor-table-chart"),e.isStripeStyle&&W(s,"stripe"),e.hasRowTitle&&W(s,"row-title"),e.hasColTitle&&W(s,"col-title"),s}function bF(n,t,e,o,r){g(pr,r.type==="table","not table data"),g(pr,ct(e)===t[t.length-1].containerId,"invalid path");const i=r,s=xs(o,"div");try{const l=w("div",[],null);l.setAttribute("data-type","table-content");const a=Y9(n,t,i);a.classList.add("drag-preview-element"),l.appendChild(a);const d=n.getComponentOptions("table");Zv(n),Xv(n),W9(n,"create"),d!=null&&d.hideCellMenu||q9(n),XS(n,Yp);const h=n.addCustom(mr(o),()=>fR());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Yt(e)?n.scrollContainer:e,locatingContainer:Yt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:ic+cu,paddingTop:ic+cu,paddingBottom:cu/2,paddingRight:cu/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,allowScrollBarFixed:d==null?void 0:d.allowScrollBarFixed,isSetScale:d==null?void 0:d.isSetScale});const p=Q9(n);h.on("scroll",p.handleReset),h.on("resize",p.handleReset),setTimeout(()=>{WM(n,o)})}catch{const a=`invalid table data: ${JSON.stringify(i)}`;pr.error(a);const d=w("div",["error"],s);d.innerText=a}return s}function vF(n,t,e){g(pr,e.type==="table","not table data");const o=e,r=Lt(t);try{const i=_e(t),s=Li(t),l=Y9(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove();const a=n.getComponentOptions("table");Zv(n),Xv(n),W9(n,"update"),a!=null&&a.hideCellMenu||q9(n),Yp(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;pr.error(s);const l=w("div",["error"],r);l.innerText=s}}function yF(n,t){let e,o,r=!1;if([...t].every(A=>A==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=km(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let A=0;A<3;A++)e.forEach(v=>{l.push(qr(n.doc,A===0?v:""))});const a=Array(s).fill(Xp),d=l[r?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:K(),type:"table",rows:i,cols:s,children:l,colsWidth:a},focusBlockId:h}}function kF(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let d=0;d<e;d++)for(let h=0;h<o;h++)r.push(qr(n.doc));const i=Array(o).fill(Xp),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:K(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const J9=S("table-selection-to-doc");function wF(n,t){const{start:e,end:o,block:r}=t,i=Dt(r);g(J9,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return Fi(n.editorBlocks,n.doc.toJSON(),s);g(J9,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=Tt.fromBlock(r),{fromCol:a,toCol:d,fromRow:h,toRow:p}=Uo(r,e,o),A={},v=[],B=n.doc.toJSON();let D={};l.sub({row:h,col:a},{row:p,col:d}).forEach((rt,ft)=>{rt.forEach((Bt,jt)=>{const Ut=Bt.containerId;if(v.indexOf(Ut)!==-1)return;v.push(Ut);let ne;if(Bt.virtual){const $e=l.getCellByContainerId(Bt.containerId),Rn=a+jt;let wr=$e.col+$e.colSpan-1;wr>d&&(wr=d);const kn=wr-Rn+1;kn>1&&(A[`${Ut}_colSpan`]=kn);const an=h+ft;let Br=$e.row+$e.rowSpan-1;Br>p&&(Br=p);const oi=Br-an+1;oi>1&&(A[`${Ut}_rowSpan`]=oi),ne=Wr()}else{if(ne=Og(n.editorBlocks,B,Ut),Bt.col+Bt.colSpan>d+1){const $e=d-Bt.col+1;$e>1&&(A[`${Ut}_colSpan`]=$e)}else Bt.colSpan>1&&(A[`${Ut}_colSpan`]=Bt.colSpan);if(Bt.row+Bt.rowSpan>p+1){const $e=p-Bt.row+1;$e>1&&(A[`${Ut}_rowSpan`]=$e)}else Bt.rowSpan>1&&(A[`${Ut}_rowSpan`]=Bt.rowSpan)}const{root:qe,...Yn}=ne.blocks;D={...D,...Yn,[Ut]:qe}})});const _=mu(_e(r)).slice(a,d+1);return{blocks:{root:[{id:K(),type:i,children:v,colsWidth:_,rows:p-h+1,cols:d-a+1,...A}],...D},meta:{},comments:{}}}function BF(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 EF(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 xF(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 IF(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 TF(n,t,e){const o=t.col,r=t.row,i=e.col,s=e.row,l={left:o,top:r,right:i,bottom:s};let a=!1;do{if(a=!1,!BF(n,l)){l.top--,a=!0;continue}if(!EF(n,l)){l.left--,a=!0;continue}if(!xF(n,l)){l.bottom++,a=!0;continue}if(!IF(n,l)){l.right++,a=!0;continue}}while(a);return l}function DF(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=Tt.fromBlock(t),i=r.map(H=>H.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),a=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),p=Math.max(s.col,l.col),A=TF(i,{row:a,col:h},{row:d,col:p}),v=r.getCell({row:A.top,col:A.left}),B=r.getCell({row:A.bottom,col:A.right}),D=r.getCell({row:A.top,col:A.right}),x=r.getCell({row:A.bottom,col:A.left});let _,M;return s.row<=l.row?s.col<=l.col?(_=v,M=B):(_=D,M=x):s.col<l.col?(_=x,M=D):(_=B,M=v),console.log(`move ${_.col}, ${_.row}, -> ${M.col}, ${M.row}`),{anchor:me(t,_.containerId),focus:me(t,M.containerId)}}function K9(n,t,e){if(e.isSimple())return[_e(t).getBoundingClientRect()];const o=_e(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:a}=Uo(t,e.start,e.end),d=mu(o),h=d.slice(0,i).reduce((D,x)=>D+x,0),p=h+d.slice(i,l+1).reduce((D,x)=>D+x,0),A=$9(o);let v=A.slice(0,s).reduce((D,x)=>D+x,0);const B=v+A.slice(s,a+1).reduce((D,x)=>D+x,0);if(s===0){const D=aF(n,t);v-=D}return[new DOMRect(r.left+h,r.top+v,p-h,B-v)]}S("table-size");const SF=40;function Ef(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),o=Number.parseInt(e.borderLeft,10),r=Number.parseInt(e.borderRight,10);return(o+r)/2}function LF(n,t,e){const o=qm(n,e.container);return o!==void 0?o+Ef(t):SF*e.colSpan-Ef(t)}function MF(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getCell({col:s,row:o});if(l.virtual)continue;let a=LF(n,t,l);const d=A4(l.container,{withPadding:!0});d&&d>a&&(a=d),r+=a+Ef(t)}return r}function RF(n,t){const e=_e(t),o=Tt.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,MF(n,e,o,s));const i=Ef(e);return r+=i,r}const Kr=S("table-creator");async function OF(n,t){return n.undoManager.runInGroup(()=>{var a,d;const e=t.item,o=(a=e.colCount)!=null?a:5,r=(d=e.rowCount)!=null?d:3,i=kF(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,ke(n,l,0))})}class _F{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 A,v;t.preventDefault(),t.stopPropagation();const e=t.target;g(Kr,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");g(Kr,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;g(Kr,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");g(Kr,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,p=Number.parseInt(d[1],10)+1;Kr.debug(`${h}, ${p}`),this.colCount=p,this.rowCount=h,(A=this.closeable)==null||A.click(this,this.element),(v=this.closeable)==null||v.close("clickItem"),this.handleTableCreatorLeave()});m(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const o=this.getTableCreatorCellId(t,e),r=document.getElementById(o);r&&ot(r,"active")}});m(this,"handleTableCreatorCellEnter",t=>{const e=t.target;g(Kr,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";g(Kr,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");g(Kr,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),a=Number.parseInt(s[1],10);l===0&&a===0&&(l=-1,a=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const p=this.getTableCreatorCellId(d,h),A=document.getElementById(p);g(Kr,A,"no cell"),d<=l&&h<=a?W(A,"active"):ot(A,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=w("div",["table-creator"],null),e=(o,r,i)=>{const s=w("div",["table-creator-cell"],o);return s.id=this.getTableCreatorCellId(r,i),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let o=0;o<9;o++){const r=w("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function FF(){return new _F}function PF(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function X9(n){const t=PF(n);return n.length+t}function NF(n,t){const e=X9(n),o=t-e;return o>0?n+" ".repeat(o):n}function $F(n,t,e,o,r){const i=t,s=new Yh(i);if(o==="markdown"||o==="text"){const l=x=>e.blocks[x].map((H,z)=>o==="markdown"?Bg(n,H,e,[...r,{containerId:x,blockIndex:z}]):vh(n,H,e,[...r,{containerId:x,blockIndex:z}])),a=x=>l(x).join(" ").replace(/\n/g," ").trim(),d=new Map,h=new Map;for(let x=0;x<s.colCount;x++){let _=0;for(let M=0;M<s.rowCount;M++){const H=s.getCell({row:M,col:x});let z="";H.virtual||(z=a(H.containerId)),d.set(`${M},${x}`,z),_=Math.max(_,X9(z))}h.set(x,_)}const p=x=>{const _=d.get(`${x.row},${x.col}`)||"",M=h.get(x.col)||0;return NF(_,M)},A=[];let v="|",B="|";for(let x=0;x<s.colCount;x++){const _=p({row:0,col:x});v+=` ${_} |`;const M="-".repeat((h.get(x)||0)+2);B+=`${M}|`}A.push(v),A.push(B);for(let x=1;x<s.rowCount;x++){let _="|";for(let M=0;M<s.colCount;M++){const H=p({row:x,col:M});_+=` ${H} |`}A.push(_)}return`${A.join(`
400
400
  `)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.3-beta.201",
3
+ "version": "0.0.3-beta.202",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",