@ones-editor/editor 0.0.7-beta.17 → 0.0.7-beta.18

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
@@ -619,7 +619,7 @@ ${l}`:r==="markdown"?`\`\`\`${i.language}
619
619
  ${s}
620
620
  \`\`\`
621
621
  ${l}`:`<p><pre><code>${s}</code></pre></p>
622
- <p>${l}</p>`}const RC={blockType:"code",blockKind:"complex",createBlockContent:kF,getBlockTextLength:RF,getRangeFromPoint:yF,moveCaret:wF,getCaretRect:LF,updateSelection:SF,clearSelection:IF,getChildContainers:DF,getNextContainer:_F,getSelectedContainers:MF,convertFrom:XP,handleBlockElementUpdated:UF,getOptions:NF,getBlockProperties:PF,convertTo:FF},yC={...Dn,blockType:"code-line"};class KF{constructor(t){g(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!Mu(this.editor,e))return;const r=e,i=t.range.focus.offset,o=B5(this.editor,r,i,"code-caret");o.scrollIntoView({block:"nearest"}),setTimeout(()=>{o.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function VF(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!Mu(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{ci(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function $F(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!Mu(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{ci(n).forEach(i=>{const o=ae(n.getBlockText(i.block));for(let s=0;s<e.length;s++){const l=e[s];if(o.startsWith(l)){n.deleteTextFromBlock(i.block,0,l.length);break}}})}),!0}function HF(n){const t=n.getFocusedBlock(),e=it(t);if(Qt(e))return;const r=rt(e);if(!r||St(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!TB(e,i))return D1(n,e),!0}const jF={Tab:VF,"Shift+Tab":$F,"CtrlOrCmd+A":HF},Uu=D("code-text-decorate");class d0{decorateText(t,e,r){if(p(Uu,e.length>0,"invalid path"),e.length===1)return{};const i=e[e.length-2];if(t.doc.getBlockData(i.containerId,i.blockIndex).type!=="code")return{};const s=r;if(s.length===0)return{};const l=ae(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(y=>{if(!y)return ql.default.languages.plain;const w=y.replace(/\s/g,"").toLocaleLowerCase();return ql.default.languages[w]||ql.default.languages.plain})(c.language),C=ql.default.tokenize(l,h),E=(y,w)=>{if(p(Uu,y,"no token"),typeof y=="string")return[{insert:y,attributes:gt.default(w)}];p(Uu,y instanceof ql.default.Token,"invalid token type");const O=y.content,I=gt.default(w);return I[`style-code-${y.type}`]=!0,typeof O=="string"?[{insert:O,attributes:I}]:Array.isArray(O)?O.map(q=>E(q,I)).flat():(p(Uu,O instanceof ql.default.Token,"invalid token"),E(O,I))},k=C.map(y=>E(y,{})).flat();return p(Uu,an(k)===an(s),"failed to highlight code, text length mismatch"),{text:k}}}const zF={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},GF={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},WF={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};_.mergeLang({"zh-CN":zF,"en-US":GF,"ja-JP":WF});function qF(n,t,e,r){const i=n.getBlockByIndex(t,e);if(ft(n,i)!==r)return!1;const o=ae(n.getBlockText(i));if(![...o].every(h=>h==="|")||o.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,i,{offset:r});if(!l)return!1;const{blockData:c,focusBlockId:d}=l;return c?(n.undoManager.runInGroup(()=>{var C;const h=n.insertBlock(t,e,c,Ee(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const XF={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},QF={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function h0(n,t,e,r,i){const o=n.getContainerById(t);if(!Qt(o)){const s=rt(o);if(s&&xi(s))return!0}return!1}function Qk(n,t,e,r,i){if(h0(n,t))return!1;if(i==="enter"&&qF(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=ae(Sn(n.getBlockText(o),r).left).trim(),l=i==="enter"?XF:QF;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var k;const h=vd(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const b=n.insertBlock(t,e,C,Ee(n,E!=null?E:C.id,0));return n.deleteBlock(o),(k=h.onConverted)==null||k.call(h,n,b),{newBlock:b,focusBlockId:E}})}return!1}function YF(n,t,e,r){const i=n.getBlockByIndex(t,e);return n.getBlockString(i,{boxReplacement:" "}).substring(0,r)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{quoted:!0},Ee(n,i,0))}),!0)}const ZF={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function JF(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=ZF[o];if(!s)return!1;const l=n.getBlockData(i).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{heading:s},Ee(n,i,0))}),!0}function tK(n,t,e,r){return!!(JF(n,t,e,r)||YF(n,t,e,r))}const eK=D("match-text-style");function nK(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),r=e.lastIndexOf(t);return r===-1?-1:r===0?0:e.substring(r-1).startsWith(t)?-1:r}const rK={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function iK(n,t,e,r){var E,b;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Sn(o,r),l=Zg(s),c=an(s)-l.length,d=Object.entries(rK);for(const[k,y]of d){const w=nK(l,k);if(w===-1)continue;const O=c+w,I=r,V=k.length,G=ae(qe(o,O+V,I-O-V*2).middle);if(y.type==="style"){const q={};y.styles.forEach(ht=>{q[ht]=!0});const J=js(G,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,O,I-O),n.insertTextToBlock(i,O,J)})}else if(y.type==="box")try{const q=(b=(E=n.editorBoxes.getBoxClass(y.boxType)).convertFrom)==null?void 0:b.call(E,n,G);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,O,I-O),n.insertBoxToBlock(i,O,q)})}catch(q){eK.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const k=C.index,y=C[1],w=C[2],O=k,I=r,G={...Wc(o,O),link:w};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,O,I-O),n.insertTextToBlock(i,O,js(y,G))}),!0}return!1}class m0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(h0(t,e))return!1;if(tK(t,e,r,i)||iK(t,e,r,i))return!0}return!1}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(nt(t,t.getBlockByIndex(i,o))){if(oi(e,"Enter")){if(Qk(t,i,o,s,"enter"))return!0}else if(oi(e,"Space")&&Qk(t,i,o,s,"space"))return!0}return!1}}const oK={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};_.mergeLang(oK);function Ou(n,t){const e=Vo(n,t);return!!(e.text&&an(e.text)===0&&!t.querySelector(".inputting-insertion"))}function Yk(n,t){var r;Dt(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function g0(n,t,e){var i;if(!Ou(n,t)){Yk(n,t);return}const r=Dt(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=ne(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function sK(n){const t=n.getAttribute("data-style-heading");return t?_.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?_.t("placeholder.quote"):null}function lK(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?_.t("placeholder.list"):_.t("placeholder.mention"):null}function Zk(n){switch(St(n)){case"text":return sK(n);case"list":return lK(n);default:return null}}function aK(n){if(fr(n))return!1;const t=rt(it(n));return t?St(t)==="code":!1}function cK(n){return!fr(n)}function uK(n,t){var h,C;const e=n.selection.focusedBlock,r=St(e),i=t.contentPlaceholder||_.t("placeholder.default");let o=i;if(r&&Fc(n,r)&&e){if(!n.isBlockWritable(e)||aK(e))return;cK(e)&&(o=_.t("placeholder.common.contentInTable")),o=(h=Zk(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:qt(s);if(!l)return;const c=qt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&Ou(n,l)){g0(n,l,(C=Zk(l))!=null?C:i);return}const d=n.getFocusedBlock();!Ou(n,d)||d===s&&!t.hideTitle||g0(n,d,o)}function fK(n,t){var i,o;const e=n.getFirstBlock(),r=Dt(e);Ou(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:_.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function dK(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function hK(n,t){dK(n),n.selection.range.isCollapsed()&&(t.hideTitle||fK(n,t),uK(n,t))}const Ait="";function mK(n){for(let t=1;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const Jk=D("enforce-title");class wC{constructor(t,e={headingLevel:1}){g(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(!this.isDocumentTitleBlock(i,o)||!oi(e,"Enter"))return!1;let l=!1,c=null;Sr(t.rootContainer)===2&&(c=Vi(t.rootContainer,1),ft(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ut(t.rootContainer));p(Jk,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=di("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ut(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(Jk,o.text,"invalid text block");const s=t.getBlockById(o.id);if(mK(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=di(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ut(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=Ee(t,c.id,ft(t,C))),Xd(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ut(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,r;!((e=this.options)!=null&&e.titlePlaceholder)&&!((r=this.options)!=null&&r.contentPlaceholder)||hK(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}const gK=D("image-data"),Nu=1e3,tR=400,pK=10;function Oa(n){return n.src.startsWith("empty:")||!n.src}function CK(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function eR(n){return`${id.default(n)}_width`}function nR(n){return`${id.default(n)}_height`}function rR(n){return`${n}_flex`}function iR(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function Na(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?Nu:i.width,s=i.height==="auto"?o/t:i.height/t;return o/s}).reduce((i,o)=>i+o,0);n.forEach(i=>{const o=i.width==="auto"?Nu:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function Pa(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=eR(i),l=nR(i),c=rR(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),d&&h?{src:i,width:d,height:h,flex:C,virtualSize:!1}:d&&!h?{src:i,width:d,height:"auto",flex:C,virtualSize:!1}:{src:i,width:"auto",height:"auto",flex:C,virtualSize:!0}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),Na(e),e}function Gr(n){const t=n.embedData;return Pa(n.embedData).length>1?100:t.widthPercent}function EK(n,t,e,r){const i=Pa(t.embedData);if(i.length>1||r)return"100%";const o=Gr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=iR(e);return`${Math.min(s*o/100,l)}px`}return typeof i[0].width=="number"?`${i[0].width}px`:"auto"}function fn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{if(i.width&&i.height&&!i.virtualSize){const l=i.src||`empty:${o}`,c=eR(l);r[c]=i.width;const d=nR(l);i.height!=="auto"&&(r[d]=i.height)}p(gK,i.flex,"no image flex");const s=rR(o);r[s]=i.flex}),r}function AK(n,t,e,r){const i=Pa(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${tR}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=Gr(t);if(!s)return"";let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,iR(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?Nu:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*pK;const c=i.reduce((h,C)=>h+C.flex,0);let d=0;for(const h of i){const C=l*h.flex/c,E=h.width==="auto"?Nu:h.width,b=C/E*h.height;d=Math.max(b,d)}return`${d}px`}function xK(n){return n.reduce((e,r)=>e+r.flex,0)}function bK(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function LC(n){return ne(n).querySelector(".block-resizer")}function BK(n){const t=LC(n);t&&ot(t,"active")}function oR(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function vK(n,t,e,r){const i=LC(n);if(i)return z(i,"active"),oR(n,t,i),i;const o=ne(n),s=B("div",["block-resizer"],o);return oR(n,t,s),e.resize.forEach(l=>{bK(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function SC(n,t){const e=LC(n);if(!e||!ee(n,t))return;const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const xit="",TK=D("block-resizer");class Pu extends Te.TypedEmitter{constructor(e,r){super();g(this,"resizableElement");g(this,"block",null);g(this,"startRect",null);g(this,"startPos",null);g(this,"resizeType",null);g(this,"enabled",!1);g(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const r=this.getResizableElement();if(!r||e.button!==0)return;const i=e.target;if(!i||!(i instanceof HTMLElement))return;const o=i.getAttribute("data-resize-type");!o||(this.bindEvents(),this.startRect=r.getBoundingClientRect(),this.startPos=e,this.resizeType=o,Ic(window.getComputedStyle(i).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});g(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const i=e.x-this.startPos.x,o=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=o),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=o),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=i),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=i);const C=d>c?d-c:0,E=h>l?h-l:0,b=new DOMRect(c,l,C,E);this.emit("resizing",this,b);const k=this.getResizableElement();k&&SC(this.block,k)});g(this,"handleMouseUp",e=>{if(e.button!==0)return;Ic(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||SC(this.block,r)});this.editor=e,this.options=r}enableResize(e,r){this.block=e,this.resizableElement=r,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(BK(this.block),this.enabled=!1)}update(e,r){this.block=e,this.resizableElement=r,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&SC(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Dt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(TK,ee(this.block,e),"not a block child element"),vK(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const kK=D("image-dom");function sR(n){return n.querySelector(".uploading-progress-mask")}function RK(n){const t=sR(n);if(t)return t;const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e);return B("div",["uploading-progress-bar-value"],r),r}function yK(n){const e=RK(n).querySelector(".uploading-progress-bar-value");return p(kK,e,"no progress value"),e}function lR(n,t){const e=yK(n);e.style.width=`${t}%`}function wK(n){var t;(t=sR(n))==null||t.remove()}function Fu(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||it(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=EK(n,t,o,s),c=AK(n,t,o,s),d=Dt(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function LK(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function SK(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=LK(t.headers).toLocaleLowerCase();let i="";if(r){const s=Qm.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function ts(n,t){const e=typeof t=="string"?t:st(t);return n.getCustom(`image-${e}`)}function p0(n,t){if(!t||!(t instanceof Node))return null;const e=rt(t);return e?ts(n,e):null}function Bi(n){return Array.from(n.querySelectorAll(".image-container"))}const IC=D("table-resize-drag-drop");class IK{constructor(t,e,r,i){g(this,"cursor","col-resize");g(this,"initWidths");this.editor=t,this.elem=e,this.data=r,this.mouseDownEvent=i;const o=this.data.block,l=ts(this.editor,o).getImages(),c=this.data.splitterIndex;p(IC,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Bi(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;ts(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=ts(this.editor,s),c=gt.default(l.getImages()),d=this.data.splitterIndex;p(IC,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const y=[...this.initWidths];y[d]+=E,y[d+1]-=E;const w=Bi(s);p(IC,w.length===c.length,"invalid image data");const O=y.reduce((G,q)=>G+q,0);for(let G=0;G<c.length;G++){const q=y[G]/O;c[G].flex=q,w[G].style.flexGrow=`${q}`}const I=gt.default(this.editor.getBlockData(s)),V=fn(c,Gr(I));I.embedData=V,Fu(this.editor,I,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=ts(this.editor,s),d=Bi(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function aR(n){var t;return!n||!(n instanceof HTMLElement)?null:Rt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function DK(n,t){var s;const e=aR(t.target);if(!e)return;const r=rt(e);if(!r)return;ts(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};rg(new IK(n,e,o,t))}function _K(n,t){t.preventDefault(),t.stopPropagation();const e=aR(t.target);if(!e)return;const r=rt(e);!r||ts(n,r).resetFlex()}function MK(n,t,e,r){const i=B("div",["image-splitter"],e);B("div",["image-splitter-indicator"],i),i.setAttribute("data-index",`${r}`),n.domEvents.addEventListener(i,"mousedown",DK),n.domEvents.addEventListener(i,"dblclick",_K)}const UK=D("image-item");function cR(n){return!n||!(n instanceof Node)?null:rt(n)}function uR(n){const t=cR(n);return t?Bi(t):[]}function DC(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function Ku(n){const t=DC(n);return t?uR(n).indexOf(t):-1}async function OK(n,t){const e=p0(n,t.target);if(!e)return;const r=Ku(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(Oa(o)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),(o.height==="auto"||o.width==="auto")&&e.fixImageSize(r,i),o.virtualSize&&e.fixImageSize(r,i),!o||!CK(o)||o.downloading))return;o.downloading=!0;const s=await SK(o.src);s?e.replaceImage(r,s):UK.warn(`failed to download image: ${o.src}`)}function NK(n,t,e){if(t.querySelector(".load-error"))return;const i=e.src.startsWith("http:")||e.src.startsWith("https:"),o=B("div",["load-error"],t),s=B("div",["error-icon"],o);s.innerHTML=lp;const l=B("div",["error-message"],o);i?(l.innerHTML=_.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=_.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&VK(c,d.target)}))}function _C(n,t){setTimeout(()=>{if(ee(n.rootContainer,t)){const e=n.getBlockData(t);Fu(n,e,null,null)}})}function PK(n,t){const e=p0(n,t.target);if(!e)return;const r=Ku(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=DC(t.target);if(!o)return;z(o,"error","error-load");const s=rt(o);s&&_C(n,s),o.innerHTML="",NK(n,o,i)}function FK(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=lp;const s=B("div",["error-message"],i);s.innerHTML=_.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=p0(l,c.target),h=Ku(c.target);!d||h===-1||d.replaceImage(h,e)})}function fR(n,t,e,r,i){const o=Bi(t)[e];!o||(z(o,"error","error-upload"),_C(n,t),o.innerHTML="",FK(n,o,i))}function dR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),Oa(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=r2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",OK),n.domEvents.addEventListener(c,"error",PK),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=sp,d.setAttribute(`data-editor-tooltip-${n.clientId}`,_.t("image.load.remote.tooltip"))}return l}function KK(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&MK(n,t,o,l-1),dR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function hR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=dR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),_C(n,t)}function Vu(n,t){return Bi(n)[t]}function VK(n,t){const e=cR(t);if(!e)return;const r=Ku(t);if(r===-1)return;const i=p0(n,t);if(!i)return;const o=i.getImages()[r];hR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function Wr(n){return St(n)==="embed"&&pn(n)==="image"}async function mR(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function $K(n){const t=await Zl(n);return mR(t)}function gR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function pR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=Uc(t.name);if(r&&!r.includes(o)){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function CR(n){return n.startsWith("image/")}const ER=D("image-object");class _e{constructor(t,e){g(this,"images",[]);g(this,"selectedIndex",-1);g(this,"blockResizer");g(this,"resizing",!1);g(this,"parentContainerResizerObserver",null);g(this,"autoFix",!1);g(this,"handleMouseDown",async(t,e)=>{const r=Ku(e.target);if(r===-1)return;const i=this.images[r];Oa(i)||this.setSelectedIndex(r)});g(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});g(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||it(e)===t&&Fu(this.editor,this.blockData,e,null)});g(this,"handleResizing",(t,e)=>{const r=this.editor.findBlockById(this.blockData.id);if(!r)return;this.autoFix||this.setAutoFix(!0);const o=this.editor.rootContainer.getBoundingClientRect().width,s=r.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const c=l*100/o;this.blockData.embedData.widthPercent=c,Fu(this.editor,this.blockData,r,null)});g(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});g(this,"fixImageSizes",Pe.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new Pu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=Pa(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,r){const i=KK(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Mr(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Bs(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),Fu(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Gr(this.blockData)}isEmpty(){return this.images.length===1&&Oa(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const i=Vu(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=Vu(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=Vu(e,t);if(Rt(r,"error"))return;const i=gR(this.editor),o=await Jl(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Vu(t,0);!this.isEmpty()&&this.images.length===1&&!Rt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const r=this.images[t];Oa(r)||(r.height==="auto"&&(r.height=e.height),r.width==="auto"&&(r.width=e.width),r.width=e.naturalWidth,r.height=e.naturalHeight,r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=gt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,Na(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=fn(r,Gr(this.blockData));return this.editor.updateEmbedData(e,i),!0}async replaceImage(t,e){const r=this.editor.findBlockById(this.blockData.id);if(!r)return!1;try{const o=await Zl(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await mR(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,Na(this.images);const h=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};hR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return fR(this.editor,r,t,o,e),!1}const i=Vu(r,t);if(!i)return!1;z(i,"uploading"),lR(i,0),z(r,"media-block-uploading");try{const o=await this.editor.doc.uploadResource(e,{onProgress:c=>{lR(i,c)}});ot(i,"uploading"),this.images[t].src=o.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=fn(this.images,Gr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){ER.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),wK(i),fR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(ER,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(e,r)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=gt.default(this.images);e[0].flex=NaN,Na(e);const r=fn(e,Gr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=Pa(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new _e(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=st(e),t.getCustom(`image-${r}`)}}const bit="",Bit="";function C0(n){const t=ne(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function MC(n,t,e){const r=C0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const AR=40,HK=20;class jK{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=rt(r);if(c&&ee(t.rootContainer,c))return c}let i=e.clientX,o=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;i<s&&s-i<AR&&(i+=AR);let l=document.elementFromPoint(i,o);if(l){const c=rt(l);if(c&&ee(t.rootContainer,c))return c}if(o-=HK,l=document.elementFromPoint(i,o),l){const c=rt(l);if(c&&ee(t.rootContainer,c))return c}return null}destroy(){}}class zK extends i0{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});g(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const r=this.editor.selection.focusedBlock;this.suggest.popup(r,0,"","")}setBlock(e){this.currentBlock=e}}function GK(n,t,e){const r=Tg(n,t);if(!r)return[];const i=[];return Object.values(r).forEach(o=>{e!=null&&e.has(o.group)||i.push(...o.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:o.group})))}),i}function UC(n,t,e={withPlainText:!1}){const r=fC(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function WK(n,t,e,r=!1){var h,C,E;const i=it(t);let o=t;if(o&&Ft(o)&&Wp(o)){if(!r){const b=FU(o);o=(h=qt(b))!=null?h:b}Yh.closeMindmap(n,t)}let l=bt(o);de(n,o)||r||(l+=1);const c=ut(i),d=e;return d.commandProvider?d.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:c,blockIndex:l}):(E=(C=d.blockOptions)==null?void 0:C.handleInsertEmptyBlock)==null?void 0:E.call(C,n,{containerId:c,blockIndex:l,item:e})}function qK(n,t){const e=Dr(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class xR{constructor(t,e,r){g(this,"source","text-style");g(this,"id","text-style-item");g(this,"name","Text styles");g(this,"element");g(this,"textStylesTooltips",{});g(this,"createHeadingItemElement",(t,e,r)=>{var o;const i=lC();this.createItem("text",pa,e,qK(this.editor,t)),(o=i.insertBlockCommandItems)==null||o.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,r?r===Number(s.value):!1)})});g(this,"createListItemElement",(t,e,r)=>{const{checkbox:i,ordered:o}=r,l=St(t)==="list",c=l&&o===!1&&!i,d=l&&o,h=l&&!!i;this.createItem("unordered-list",mp,e,c),this.createItem("ordered-list",gp,e,d),this.createItem("check-list",dp,e,h)});g(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const r=e.target instanceof Element?e.target:e.target.parentElement;if(!r)return;const i=r.closest(".text-style-item");if(!i)return;const o=i.id,s="heading-";if(o==="text"&&n0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&n0(t,this.block,d)}if(o==="blockquote"&&iC(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");ik(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&sC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});g(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:_.t("commands.text")},blockquote:{title:_.t("commands.quote")},"align-left":{title:_.t("commands.alignLeft")},"align-center":{title:_.t("commands.alignCenter")},"align-right":{title:_.t("commands.alignRight")},"unordered-list":{title:_.t("commands.unordered")},"ordered-list":{title:_.t("commands.ordered")},"check-list":{title:_.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:_.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",hp,i,!!c)}const s=o.align||"left";return this.createItem("align-left",ga,i,s==="left"),this.createItem("align-center",Ih,i,s==="center"),this.createItem("align-right",Sh,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=Ts(e,o,r);s.id=t;const l=this.textStylesTooltips[t];if(!l)return;const{title:c,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,c),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,ur(d))}}function bR(){return{source:"separator",type:"separator",id:`section-${et()}`,name:""}}const BR={copy:A2,cut:x2,delete:b2,"lock-block":B2,"unlock-block":v2,comment:Qs},XK=["image","video"];function QK(n,t,e){const r=[],i=nt(n,t),o=Ie(t)&&XK.includes(pn(t)),s=o&&(pn(t)!=="image"||pn(t)==="image"&&Bi(t).length===1);if(i?r.push(new xR(n,t,e)):o&&s&&r.push(new xR(n,t,{...e,fromEmbed:!0})),!de(n,t)||Gp(t)){(i||o&&s)&&r.push(bR());const l=GK(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in BR&&(c.icon=BR[c.id])}),r.push(...l)}return de(n,t)&&!Gp(t)?r.push(...UC(n,"insert-block")):r.push(bR(),{id:"insert-block-before",icon:T2,name:_.t("blockMenu.command.insertAbove"),children:UC(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:k2,name:_.t("blockMenu.command.insertAfter"),children:UC(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function YK(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;e5(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&WK(n,t,e,e.source==="insert-block-before")}const ZK=D("exclusive-block");function OC(n,t,e,r){var l;z(t,"block-exclusive");const i=Zt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",_.t("exclusive.tips",{editor:r,embedType:s||_.t("exclusive.fallbackAbstract")}))}function vR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function JK(n,t,e,r,i){ZK.debug(`block ${st(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?OC(n,t,r,i):vR(t)}function $u(n){return n.classList.contains("block-exclusive")}function TR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&JK(n,r,t.exclusive,t.userId,t.displayName)})}class es{constructor(t){g(this,"exclusiveBlockIds",new Set);g(this,"exclusiveBlockTimer",0);g(this,"remoteExclusiveBlockIds",new Map);g(this,"handleUserChanged",t=>{const e=new Set(t.map(i=>i.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([i,o])=>{if(!e.has(o.userId)){this.remoteExclusiveBlockIds.delete(i);const s={...o,exclusive:!1};TR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;TR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>st(o)),exclusive:e};this.editor.doc.broadcastMessage(i)}exclusiveBlock(t){this.exclusiveBlockIds.has(st(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(st(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(st(t))||(this.exclusiveBlockIds.delete(st(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new es(t))}static register(t){return this.get(t)}}function NC(n,t){es.get(n).exclusiveBlock(t)}function PC(n,t){es.get(n).unexclusiveBlock(t)}class kR{writable(t,e){if(Array.isArray(e)){for(const r of e)if($u(r))return!1;return}if($u(e))return!1}create(t,e,r,i,o){const s=es.get(t).getExclusiveMessage(o.id);s&&OC(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=es.get(t).getExclusiveMessage(o.id);s?OC(t,i,s.userId,s.displayName):vR(i)}}const vit="",tV={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},eV={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},nV={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};_.mergeLang({"zh-CN":tV,"en-US":eV,"ja-JP":nV});function Hu(n,t){return n.getBlockData(t).lock}function E0(n,t){return!!Hu(n,t)}function ju(n,t){const e=Hu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function FC(n,t){const e=Hu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function rV(n,t){if(n.readonly||!n.isBlockWritable(t)||E0(n,t)&&!ju(n,t))return;const e=n.doc.getUser(),r={userId:e.userId,displayName:e.displayName,locked:Date.now()},o={...n.getBlockData(t),lock:r};n.updateBlockData(t,o)}function iV(n,t){if(!ju(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const oV=10,sV=80,lV=50;class KC{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;if(!i||!i.blockId)return;const o=t.getBlockById(i.blockId);i.type==="lock"?rV(t,o):i.type==="unlock"&&iV(t,o)})}create(t,e,r,i,o){const s=o.lock;s&&(s.userId!==t.doc.getUser().userId?z(i,"locked-by-others"):z(i,"locked-by-self"))}update(t,e,r,i,o){const s=o.lock;if(s)if(s.userId!==t.doc.getUser().userId){z(i,"locked-by-others");const l=t.selection.focusedBlock;(l===i||ee(i,l))&&(nt(t,i)||St(i)==="code")&&t.insertTextBlock("",ut(r),bt(i)+1)}else z(i,"locked-by-self");else ot(i,"locked-by-others"),ot(i,"locked-by-self")}writable(t,e){let r=[];Array.isArray(e)?r=e:r.push(e);for(const i of r){if(FC(t,i))return!1;if(fr(i))return;let o=Is(i);for(;o;){if(FC(t,o))return!1;o=Is(o)}}}commands(t,e){const r=E0(t,e),i=ju(t,e),o=$u(e),s={blockId:st(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(r)if(i)l.id="unlock-block",l.name=_.t("locker.unlock"),s.type="unlock";else{const c=Hu(t,e);let d=(c==null?void 0:c.displayName)||"";const h=_.getCurrentLang()==="ja-JP",C=Tb(d,oV,h?lV:sV);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=_.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=_.t("locker.lock"),l.states=["disabled"]):l.name=_.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Tit="",aV={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},cV={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},uV={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};_.mergeLang({"zh-CN":aV,"en-US":cV,"ja-JP":uV});class A0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const fV=D("standard-block-actions");class dV{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;try{const o=t.getBlockById(i);if(r.id==="delete"){t.deleteBlock(o);return}r.id==="copy"&&sh(t,o),r.id==="cut"&&(sh(t,o),t.deleteBlock(o))}catch(o){fV.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=E0(t,e),i=r&&ju(t,e),o=st(e),s=TC(),l=$u(e),c={id:"copy",name:_.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:_.t("copyCutProperty.unsafeEnvTips",{shortCut:ur("CtrlOrCmd+C"),operation:_.t("copyCutProperty.copy")})},d={id:"cut",name:_.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:_.t("copyCutProperty.unsafeEnvTips",{shortCut:ur("CtrlOrCmd+X"),operation:_.t("copyCutProperty.cut")})},h={id:"delete",name:_.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const RR=D("block-menu");class hV{constructor(t){g(this,"menu");g(this,"currentBlock",null);g(this,"commandBlock",null);g(this,"handleShow",()=>{p(RR,this.currentBlock,"no target block before show block menu");const t=QK(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});g(this,"handleClose",()=>{bp(this.editor)&&this.editor.focus()});g(this,"handleItemClick",(t,e)=>{p(RR,this.commandBlock,"no command block before show block menu"),YK(this.editor,this.commandBlock,e),e.element||this.close()});g(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new Zs([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new dV)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const mV=1e3;async function gV(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=mV?"":(await Dx.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const pV=D("drag-preview-image");class CV{constructor(t){g(this,"startPosition",null);g(this,"dragContainer",null);g(this,"handleDragStart",async(t,e)=>{const r=t.target;p(pV,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=L2;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),b=this.editor.rootContainer.getBoundingClientRect(),k=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(b.width/2,k.width)}px`,this.dragContainer=s;const w=await gV(this.editor,e);w?l.src=w:z(s,"drag-placeholder"),tg(s,{status:"loaded"})});g(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:r}=t;if(e===0&&r===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:i,y:o}=this.startPosition,s=e-i,l=r-o;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});g(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const yR="drag-preview-element";function EV(n){if(Rt(n,yR))return n;const t=n.querySelector(`.${yR}`);return t||(Ie(n)?Dt(n):n)}const x0=D("block-menu-drag-handler");function VC(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class AV{constructor(t,e){g(this,"dragPreview");g(this,"autoScroll");g(this,"oldPos",{x:0,y:0});g(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(p(x0,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:r,y:i}=t;this.oldPos={x:r,y:i},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});g(this,"handleDragStart",t=>{var s,l;const e=Gn(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Ad({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(x0,r,"no dragged block"),(l=(s=Zt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=VC(t,"dragstart");TV(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=EV(r);this.dragPreview.handleDragStart(t,o),this.autoScroll.active(),z(r,"dragging"),z(this.editor.contentElement,"dragging")});g(this,"handleDrag",t=>{const{target:e,x:r,y:i}=t;if(this.oldPos.x===r&&this.oldPos.y===i)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:r,y:i},p(x0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=VC(t,"dragover");this.editor.contentElement.dispatchEvent(o)});g(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(x0,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(i=this.autoScroll)==null||i.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const r=VC(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new CV(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class zu{constructor(t){g(this,"highlightedBlockId","");g(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=st(t),z(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new zu(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class wR{constructor(t){g(this,"buttonElement");g(this,"emptyBlockMenu");g(this,"blockMenu");g(this,"dragHandler");g(this,"handleHoverBlock",(t,e,r)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const i=this.editor.getCustom("editor-tooltip");if(i&&i.visible()&&(i.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(r.target)||this.buttonElement.remove());return}const o=vg(t);Os(o)||(this.updateButton(o),MC(o,this.buttonElement,Number.MAX_SAFE_INTEGER))});g(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const r=this.blockMenu.currentBlock;if(!r)return;this.editor.selection.selectBlock(r,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{zu.get(this.editor).highlightBlock(r)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});g(this,"updatePlaceholder",t=>{Dt(t).setAttribute("data-content-placeholder",_.t("blockMenu.button.searchPlaceholder"))});g(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;if(this.blockMenu.currentBlock){const r=st(this.blockMenu.currentBlock);if(!this.editor.findBlockById(r)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const e=de(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new zK(t),this.blockMenu=new hV(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new AV(this.editor,this);const e=be.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new jK),zu.register(this.editor)}destroy(){be.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=B("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,_.t("blockMenu.button.tips")),t.innerHTML=pp,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=w2,this.buttonElement.setAttribute(e,_.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=pp,this.buttonElement.setAttribute(e,_.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),de(this.editor,t)&&!(Ft(t)&&Gp(t))?this.setButtonType("insert"):this.setButtonType("move")}}const xV={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
622
+ <p>${l}</p>`}const RC={blockType:"code",blockKind:"complex",createBlockContent:kF,getBlockTextLength:RF,getRangeFromPoint:yF,moveCaret:wF,getCaretRect:LF,updateSelection:SF,clearSelection:IF,getChildContainers:DF,getNextContainer:_F,getSelectedContainers:MF,convertFrom:XP,handleBlockElementUpdated:UF,getOptions:NF,getBlockProperties:PF,convertTo:FF},yC={...Dn,blockType:"code-line"};class KF{constructor(t){g(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!Mu(this.editor,e))return;const r=e,i=t.range.focus.offset,o=B5(this.editor,r,i,"code-caret");o.scrollIntoView({block:"nearest"}),setTimeout(()=>{o.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function VF(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!Mu(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{ci(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function $F(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!Mu(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{ci(n).forEach(i=>{const o=ae(n.getBlockText(i.block));for(let s=0;s<e.length;s++){const l=e[s];if(o.startsWith(l)){n.deleteTextFromBlock(i.block,0,l.length);break}}})}),!0}function HF(n){const t=n.getFocusedBlock(),e=it(t);if(Qt(e))return;const r=rt(e);if(!r||St(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!TB(e,i))return D1(n,e),!0}const jF={Tab:VF,"Shift+Tab":$F,"CtrlOrCmd+A":HF},Uu=D("code-text-decorate");class d0{decorateText(t,e,r){if(p(Uu,e.length>0,"invalid path"),e.length===1)return{};const i=e[e.length-2];if(t.doc.getBlockData(i.containerId,i.blockIndex).type!=="code")return{};const s=r;if(s.length===0)return{};const l=ae(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(y=>{if(!y)return ql.default.languages.plain;const w=y.replace(/\s/g,"").toLocaleLowerCase();return ql.default.languages[w]||ql.default.languages.plain})(c.language),C=ql.default.tokenize(l,h),E=(y,w)=>{if(p(Uu,y,"no token"),typeof y=="string")return[{insert:y,attributes:gt.default(w)}];p(Uu,y instanceof ql.default.Token,"invalid token type");const O=y.content,I=gt.default(w);return I[`style-code-${y.type}`]=!0,typeof O=="string"?[{insert:O,attributes:I}]:Array.isArray(O)?O.map(q=>E(q,I)).flat():(p(Uu,O instanceof ql.default.Token,"invalid token"),E(O,I))},k=C.map(y=>E(y,{})).flat();return p(Uu,an(k)===an(s),"failed to highlight code, text length mismatch"),{text:k}}}const zF={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},GF={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},WF={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};_.mergeLang({"zh-CN":zF,"en-US":GF,"ja-JP":WF});function qF(n,t,e,r){const i=n.getBlockByIndex(t,e);if(ft(n,i)!==r)return!1;const o=ae(n.getBlockText(i));if(![...o].every(h=>h==="|")||o.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,i,{offset:r});if(!l)return!1;const{blockData:c,focusBlockId:d}=l;return c?(n.undoManager.runInGroup(()=>{var C;const h=n.insertBlock(t,e,c,Ee(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const XF={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},QF={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function h0(n,t,e,r,i){const o=n.getContainerById(t);if(!Qt(o)){const s=rt(o);if(s&&xi(s))return!0}return!1}function Qk(n,t,e,r,i){if(h0(n,t))return!1;if(i==="enter"&&qF(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=ae(Sn(n.getBlockText(o),r).left).trim(),l=i==="enter"?XF:QF;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var k;const h=vd(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const b=n.insertBlock(t,e,C,Ee(n,E!=null?E:C.id,0));return n.deleteBlock(o),(k=h.onConverted)==null||k.call(h,n,b),{newBlock:b,focusBlockId:E}})}return!1}function YF(n,t,e,r){const i=n.getBlockByIndex(t,e);return n.getBlockString(i,{boxReplacement:" "}).substring(0,r)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{quoted:!0},Ee(n,i,0))}),!0)}const ZF={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function JF(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=ZF[o];if(!s)return!1;const l=n.getBlockData(i).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,0,r+1),n.updateBlockData(i,{heading:s},Ee(n,i,0))}),!0}function tK(n,t,e,r){return!!(JF(n,t,e,r)||YF(n,t,e,r))}const eK=D("match-text-style");function nK(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),r=e.lastIndexOf(t);return r===-1?-1:r===0?0:e.substring(r-1).startsWith(t)?-1:r}const rK={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function iK(n,t,e,r){var E,b;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Sn(o,r),l=Zg(s),c=an(s)-l.length,d=Object.entries(rK);for(const[k,y]of d){const w=nK(l,k);if(w===-1)continue;const O=c+w,I=r,V=k.length,G=ae(qe(o,O+V,I-O-V*2).middle);if(y.type==="style"){const q={};y.styles.forEach(ht=>{q[ht]=!0});const J=js(G,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,O,I-O),n.insertTextToBlock(i,O,J)})}else if(y.type==="box")try{const q=(b=(E=n.editorBoxes.getBoxClass(y.boxType)).convertFrom)==null?void 0:b.call(E,n,G);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,O,I-O),n.insertBoxToBlock(i,O,q)})}catch(q){eK.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const k=C.index,y=C[1],w=C[2],O=k,I=r,G={...Wc(o,O),link:w};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,O,I-O),n.insertTextToBlock(i,O,js(y,G))}),!0}return!1}class m0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(h0(t,e))return!1;if(tK(t,e,r,i)||iK(t,e,r,i))return!0}return!1}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(nt(t,t.getBlockByIndex(i,o))){if(oi(e,"Enter")){if(Qk(t,i,o,s,"enter"))return!0}else if(oi(e,"Space")&&Qk(t,i,o,s,"space"))return!0}return!1}}const oK={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};_.mergeLang(oK);function Ou(n,t){const e=Vo(n,t);return!!(e.text&&an(e.text)===0&&!t.querySelector(".inputting-insertion"))}function Yk(n,t){var r;Dt(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function g0(n,t,e){var i;if(!Ou(n,t)){Yk(n,t);return}const r=Dt(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=ne(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function sK(n){const t=n.getAttribute("data-style-heading");return t?_.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?_.t("placeholder.quote"):null}function lK(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?_.t("placeholder.list"):_.t("placeholder.mention"):null}function Zk(n){switch(St(n)){case"text":return sK(n);case"list":return lK(n);default:return null}}function aK(n){if(fr(n))return!1;const t=rt(it(n));return t?St(t)==="code":!1}function cK(n){return!fr(n)}function uK(n,t){var h,C;const e=n.selection.focusedBlock,r=St(e),i=t.contentPlaceholder||_.t("placeholder.default");let o=i;if(r&&Fc(n,r)&&e){if(!n.isBlockWritable(e)||aK(e))return;cK(e)&&(o=_.t("placeholder.common.contentInTable")),o=(h=Zk(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:qt(s);if(!l)return;const c=qt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&Ou(n,l)){g0(n,l,(C=Zk(l))!=null?C:i);return}const d=n.getFocusedBlock();!Ou(n,d)||d===s&&!t.hideTitle||g0(n,d,o)}function fK(n,t){var i,o;const e=n.getFirstBlock(),r=Dt(e);Ou(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:_.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function dK(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function hK(n,t){dK(n),n.selection.range.isCollapsed()&&(t.hideTitle||fK(n,t),uK(n,t))}const Ait="";function mK(n){for(let t=1;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const Jk=D("enforce-title");class wC{constructor(t,e={headingLevel:1}){g(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});g(this,"reload",t=>{this.handleChanged(t),this.applyPlaceholder(t)});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange),setTimeout(()=>{t.addListener("load",this.reload)})}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange),t.removeListener("load",this.reload)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:i,blockIndex:o,offset:s}=t.getTextPosition();if(!this.isDocumentTitleBlock(i,o)||!oi(e,"Enter"))return!1;let l=!1,c=null;Sr(t.rootContainer)===2&&(c=Vi(t.rootContainer,1),ft(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ut(t.rootContainer));p(Jk,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=di("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ut(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(Jk,o.text,"invalid text block");const s=t.getBlockById(o.id);if(mK(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=di(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ut(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=Ee(t,c.id,ft(t,C))),Xd(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ut(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,r;!((e=this.options)!=null&&e.titlePlaceholder)&&!((r=this.options)!=null&&r.contentPlaceholder)||hK(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}const gK=D("image-data"),Nu=1e3,tR=400,pK=10;function Oa(n){return n.src.startsWith("empty:")||!n.src}function CK(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function eR(n){return`${id.default(n)}_width`}function nR(n){return`${id.default(n)}_height`}function rR(n){return`${n}_flex`}function iR(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function Na(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?Nu:i.width,s=i.height==="auto"?o/t:i.height/t;return o/s}).reduce((i,o)=>i+o,0);n.forEach(i=>{const o=i.width==="auto"?Nu:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function Pa(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=eR(i),l=nR(i),c=rR(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),d&&h?{src:i,width:d,height:h,flex:C,virtualSize:!1}:d&&!h?{src:i,width:d,height:"auto",flex:C,virtualSize:!1}:{src:i,width:"auto",height:"auto",flex:C,virtualSize:!0}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),Na(e),e}function Gr(n){const t=n.embedData;return Pa(n.embedData).length>1?100:t.widthPercent}function EK(n,t,e,r){const i=Pa(t.embedData);if(i.length>1||r)return"100%";const o=Gr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=iR(e);return`${Math.min(s*o/100,l)}px`}return typeof i[0].width=="number"?`${i[0].width}px`:"auto"}function fn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{if(i.width&&i.height&&!i.virtualSize){const l=i.src||`empty:${o}`,c=eR(l);r[c]=i.width;const d=nR(l);i.height!=="auto"&&(r[d]=i.height)}p(gK,i.flex,"no image flex");const s=rR(o);r[s]=i.flex}),r}function AK(n,t,e,r){const i=Pa(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${tR}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=Gr(t);if(!s)return"";let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,iR(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?Nu:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*pK;const c=i.reduce((h,C)=>h+C.flex,0);let d=0;for(const h of i){const C=l*h.flex/c,E=h.width==="auto"?Nu:h.width,b=C/E*h.height;d=Math.max(b,d)}return`${d}px`}function xK(n){return n.reduce((e,r)=>e+r.flex,0)}function bK(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function LC(n){return ne(n).querySelector(".block-resizer")}function BK(n){const t=LC(n);t&&ot(t,"active")}function oR(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function vK(n,t,e,r){const i=LC(n);if(i)return z(i,"active"),oR(n,t,i),i;const o=ne(n),s=B("div",["block-resizer"],o);return oR(n,t,s),e.resize.forEach(l=>{bK(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function SC(n,t){const e=LC(n);if(!e||!ee(n,t))return;const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const xit="",TK=D("block-resizer");class Pu extends Te.TypedEmitter{constructor(e,r){super();g(this,"resizableElement");g(this,"block",null);g(this,"startRect",null);g(this,"startPos",null);g(this,"resizeType",null);g(this,"enabled",!1);g(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const r=this.getResizableElement();if(!r||e.button!==0)return;const i=e.target;if(!i||!(i instanceof HTMLElement))return;const o=i.getAttribute("data-resize-type");!o||(this.bindEvents(),this.startRect=r.getBoundingClientRect(),this.startPos=e,this.resizeType=o,Ic(window.getComputedStyle(i).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});g(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const i=e.x-this.startPos.x,o=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=o),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=o),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=i),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=i);const C=d>c?d-c:0,E=h>l?h-l:0,b=new DOMRect(c,l,C,E);this.emit("resizing",this,b);const k=this.getResizableElement();k&&SC(this.block,k)});g(this,"handleMouseUp",e=>{if(e.button!==0)return;Ic(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||SC(this.block,r)});this.editor=e,this.options=r}enableResize(e,r){this.block=e,this.resizableElement=r,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(BK(this.block),this.enabled=!1)}update(e,r){this.block=e,this.resizableElement=r,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&SC(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Dt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(TK,ee(this.block,e),"not a block child element"),vK(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const kK=D("image-dom");function sR(n){return n.querySelector(".uploading-progress-mask")}function RK(n){const t=sR(n);if(t)return t;const e=B("div",["uploading-progress-mask"],n),r=B("div",["uploading-progress-bar"],e);return B("div",["uploading-progress-bar-value"],r),r}function yK(n){const e=RK(n).querySelector(".uploading-progress-bar-value");return p(kK,e,"no progress value"),e}function lR(n,t){const e=yK(n);e.style.width=`${t}%`}function wK(n){var t;(t=sR(n))==null||t.remove()}function Fu(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||it(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=EK(n,t,o,s),c=AK(n,t,o,s),d=Dt(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function LK(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function SK(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=LK(t.headers).toLocaleLowerCase();let i="";if(r){const s=Qm.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function ts(n,t){const e=typeof t=="string"?t:st(t);return n.getCustom(`image-${e}`)}function p0(n,t){if(!t||!(t instanceof Node))return null;const e=rt(t);return e?ts(n,e):null}function Bi(n){return Array.from(n.querySelectorAll(".image-container"))}const IC=D("table-resize-drag-drop");class IK{constructor(t,e,r,i){g(this,"cursor","col-resize");g(this,"initWidths");this.editor=t,this.elem=e,this.data=r,this.mouseDownEvent=i;const o=this.data.block,l=ts(this.editor,o).getImages(),c=this.data.splitterIndex;p(IC,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Bi(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;ts(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=ts(this.editor,s),c=gt.default(l.getImages()),d=this.data.splitterIndex;p(IC,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const y=[...this.initWidths];y[d]+=E,y[d+1]-=E;const w=Bi(s);p(IC,w.length===c.length,"invalid image data");const O=y.reduce((G,q)=>G+q,0);for(let G=0;G<c.length;G++){const q=y[G]/O;c[G].flex=q,w[G].style.flexGrow=`${q}`}const I=gt.default(this.editor.getBlockData(s)),V=fn(c,Gr(I));I.embedData=V,Fu(this.editor,I,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=ts(this.editor,s),d=Bi(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function aR(n){var t;return!n||!(n instanceof HTMLElement)?null:Rt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function DK(n,t){var s;const e=aR(t.target);if(!e)return;const r=rt(e);if(!r)return;ts(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};rg(new IK(n,e,o,t))}function _K(n,t){t.preventDefault(),t.stopPropagation();const e=aR(t.target);if(!e)return;const r=rt(e);!r||ts(n,r).resetFlex()}function MK(n,t,e,r){const i=B("div",["image-splitter"],e);B("div",["image-splitter-indicator"],i),i.setAttribute("data-index",`${r}`),n.domEvents.addEventListener(i,"mousedown",DK),n.domEvents.addEventListener(i,"dblclick",_K)}const UK=D("image-item");function cR(n){return!n||!(n instanceof Node)?null:rt(n)}function uR(n){const t=cR(n);return t?Bi(t):[]}function DC(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function Ku(n){const t=DC(n);return t?uR(n).indexOf(t):-1}async function OK(n,t){const e=p0(n,t.target);if(!e)return;const r=Ku(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(Oa(o)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),(o.height==="auto"||o.width==="auto")&&e.fixImageSize(r,i),o.virtualSize&&e.fixImageSize(r,i),!o||!CK(o)||o.downloading))return;o.downloading=!0;const s=await SK(o.src);s?e.replaceImage(r,s):UK.warn(`failed to download image: ${o.src}`)}function NK(n,t,e){if(t.querySelector(".load-error"))return;const i=e.src.startsWith("http:")||e.src.startsWith("https:"),o=B("div",["load-error"],t),s=B("div",["error-icon"],o);s.innerHTML=lp;const l=B("div",["error-message"],o);i?(l.innerHTML=_.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=_.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&VK(c,d.target)}))}function _C(n,t){setTimeout(()=>{if(ee(n.rootContainer,t)){const e=n.getBlockData(t);Fu(n,e,null,null)}})}function PK(n,t){const e=p0(n,t.target);if(!e)return;const r=Ku(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=DC(t.target);if(!o)return;z(o,"error","error-load");const s=rt(o);s&&_C(n,s),o.innerHTML="",NK(n,o,i)}function FK(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=lp;const s=B("div",["error-message"],i);s.innerHTML=_.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=p0(l,c.target),h=Ku(c.target);!d||h===-1||d.replaceImage(h,e)})}function fR(n,t,e,r,i){const o=Bi(t)[e];!o||(z(o,"error","error-upload"),_C(n,t),o.innerHTML="",FK(n,o,i))}function dR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),Oa(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=r2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",OK),n.domEvents.addEventListener(c,"error",PK),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=sp,d.setAttribute(`data-editor-tooltip-${n.clientId}`,_.t("image.load.remote.tooltip"))}return l}function KK(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&MK(n,t,o,l-1),dR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function hR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=dR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),_C(n,t)}function Vu(n,t){return Bi(n)[t]}function VK(n,t){const e=cR(t);if(!e)return;const r=Ku(t);if(r===-1)return;const i=p0(n,t);if(!i)return;const o=i.getImages()[r];hR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function Wr(n){return St(n)==="embed"&&pn(n)==="image"}async function mR(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function $K(n){const t=await Zl(n);return mR(t)}function gR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function pR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=Uc(t.name);if(r&&!r.includes(o)){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function CR(n){return n.startsWith("image/")}const ER=D("image-object");class _e{constructor(t,e){g(this,"images",[]);g(this,"selectedIndex",-1);g(this,"blockResizer");g(this,"resizing",!1);g(this,"parentContainerResizerObserver",null);g(this,"autoFix",!1);g(this,"handleMouseDown",async(t,e)=>{const r=Ku(e.target);if(r===-1)return;const i=this.images[r];Oa(i)||this.setSelectedIndex(r)});g(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});g(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||it(e)===t&&Fu(this.editor,this.blockData,e,null)});g(this,"handleResizing",(t,e)=>{const r=this.editor.findBlockById(this.blockData.id);if(!r)return;this.autoFix||this.setAutoFix(!0);const o=this.editor.rootContainer.getBoundingClientRect().width,s=r.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const c=l*100/o;this.blockData.embedData.widthPercent=c,Fu(this.editor,this.blockData,r,null)});g(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});g(this,"fixImageSizes",Pe.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new Pu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=Pa(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,r){const i=KK(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Mr(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Bs(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),Fu(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Gr(this.blockData)}isEmpty(){return this.images.length===1&&Oa(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const i=Vu(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=Vu(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=Vu(e,t);if(Rt(r,"error"))return;const i=gR(this.editor),o=await Jl(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Vu(t,0);!this.isEmpty()&&this.images.length===1&&!Rt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const r=this.images[t];Oa(r)||(r.height==="auto"&&(r.height=e.height),r.width==="auto"&&(r.width=e.width),r.width=e.naturalWidth,r.height=e.naturalHeight,r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=gt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,Na(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=fn(r,Gr(this.blockData));return this.editor.updateEmbedData(e,i),!0}async replaceImage(t,e){const r=this.editor.findBlockById(this.blockData.id);if(!r)return!1;try{const o=await Zl(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await mR(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,Na(this.images);const h=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};hR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return fR(this.editor,r,t,o,e),!1}const i=Vu(r,t);if(!i)return!1;z(i,"uploading"),lR(i,0),z(r,"media-block-uploading");try{const o=await this.editor.doc.uploadResource(e,{onProgress:c=>{lR(i,c)}});ot(i,"uploading"),this.images[t].src=o.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=fn(this.images,Gr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){ER.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),wK(i),fR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(ER,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=fn(this.images,Gr(this.blockData));this.editor.updateEmbedData(e,r)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=gt.default(this.images);e[0].flex=NaN,Na(e);const r=fn(e,Gr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=Pa(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new _e(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=st(e),t.getCustom(`image-${r}`)}}const bit="",Bit="";function C0(n){const t=ne(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function MC(n,t,e){const r=C0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const AR=40,HK=20;class jK{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=rt(r);if(c&&ee(t.rootContainer,c))return c}let i=e.clientX,o=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;i<s&&s-i<AR&&(i+=AR);let l=document.elementFromPoint(i,o);if(l){const c=rt(l);if(c&&ee(t.rootContainer,c))return c}if(o-=HK,l=document.elementFromPoint(i,o),l){const c=rt(l);if(c&&ee(t.rootContainer,c))return c}return null}destroy(){}}class zK extends i0{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});g(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const r=this.editor.selection.focusedBlock;this.suggest.popup(r,0,"","")}setBlock(e){this.currentBlock=e}}function GK(n,t,e){const r=Tg(n,t);if(!r)return[];const i=[];return Object.values(r).forEach(o=>{e!=null&&e.has(o.group)||i.push(...o.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:o.group})))}),i}function UC(n,t,e={withPlainText:!1}){const r=fC(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function WK(n,t,e,r=!1){var h,C,E;const i=it(t);let o=t;if(o&&Ft(o)&&Wp(o)){if(!r){const b=FU(o);o=(h=qt(b))!=null?h:b}Yh.closeMindmap(n,t)}let l=bt(o);de(n,o)||r||(l+=1);const c=ut(i),d=e;return d.commandProvider?d.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:c,blockIndex:l}):(E=(C=d.blockOptions)==null?void 0:C.handleInsertEmptyBlock)==null?void 0:E.call(C,n,{containerId:c,blockIndex:l,item:e})}function qK(n,t){const e=Dr(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class xR{constructor(t,e,r){g(this,"source","text-style");g(this,"id","text-style-item");g(this,"name","Text styles");g(this,"element");g(this,"textStylesTooltips",{});g(this,"createHeadingItemElement",(t,e,r)=>{var o;const i=lC();this.createItem("text",pa,e,qK(this.editor,t)),(o=i.insertBlockCommandItems)==null||o.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,r?r===Number(s.value):!1)})});g(this,"createListItemElement",(t,e,r)=>{const{checkbox:i,ordered:o}=r,l=St(t)==="list",c=l&&o===!1&&!i,d=l&&o,h=l&&!!i;this.createItem("unordered-list",mp,e,c),this.createItem("ordered-list",gp,e,d),this.createItem("check-list",dp,e,h)});g(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const r=e.target instanceof Element?e.target:e.target.parentElement;if(!r)return;const i=r.closest(".text-style-item");if(!i)return;const o=i.id,s="heading-";if(o==="text"&&n0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&n0(t,this.block,d)}if(o==="blockquote"&&iC(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");ik(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&sC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});g(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:_.t("commands.text")},blockquote:{title:_.t("commands.quote")},"align-left":{title:_.t("commands.alignLeft")},"align-center":{title:_.t("commands.alignCenter")},"align-right":{title:_.t("commands.alignRight")},"unordered-list":{title:_.t("commands.unordered")},"ordered-list":{title:_.t("commands.ordered")},"check-list":{title:_.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:_.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",hp,i,!!c)}const s=o.align||"left";return this.createItem("align-left",ga,i,s==="left"),this.createItem("align-center",Ih,i,s==="center"),this.createItem("align-right",Sh,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=Ts(e,o,r);s.id=t;const l=this.textStylesTooltips[t];if(!l)return;const{title:c,shortcut:d}=l;s.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,c),d&&s.setAttribute(`data-editor-tooltip-desc-${this.editor.clientId}`,ur(d))}}function bR(){return{source:"separator",type:"separator",id:`section-${et()}`,name:""}}const BR={copy:A2,cut:x2,delete:b2,"lock-block":B2,"unlock-block":v2,comment:Qs},XK=["image","video"];function QK(n,t,e){const r=[],i=nt(n,t),o=Ie(t)&&XK.includes(pn(t)),s=o&&(pn(t)!=="image"||pn(t)==="image"&&Bi(t).length===1);if(i?r.push(new xR(n,t,e)):o&&s&&r.push(new xR(n,t,{...e,fromEmbed:!0})),!de(n,t)||Gp(t)){(i||o&&s)&&r.push(bR());const l=GK(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in BR&&(c.icon=BR[c.id])}),r.push(...l)}return de(n,t)&&!Gp(t)?r.push(...UC(n,"insert-block")):r.push(bR(),{id:"insert-block-before",icon:T2,name:_.t("blockMenu.command.insertAbove"),children:UC(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:k2,name:_.t("blockMenu.command.insertAfter"),children:UC(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function YK(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;e5(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&WK(n,t,e,e.source==="insert-block-before")}const ZK=D("exclusive-block");function OC(n,t,e,r){var l;z(t,"block-exclusive");const i=Zt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",_.t("exclusive.tips",{editor:r,embedType:s||_.t("exclusive.fallbackAbstract")}))}function vR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function JK(n,t,e,r,i){ZK.debug(`block ${st(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?OC(n,t,r,i):vR(t)}function $u(n){return n.classList.contains("block-exclusive")}function TR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&JK(n,r,t.exclusive,t.userId,t.displayName)})}class es{constructor(t){g(this,"exclusiveBlockIds",new Set);g(this,"exclusiveBlockTimer",0);g(this,"remoteExclusiveBlockIds",new Map);g(this,"handleUserChanged",t=>{const e=new Set(t.map(i=>i.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([i,o])=>{if(!e.has(o.userId)){this.remoteExclusiveBlockIds.delete(i);const s={...o,exclusive:!1};TR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;TR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>st(o)),exclusive:e};this.editor.doc.broadcastMessage(i)}exclusiveBlock(t){this.exclusiveBlockIds.has(st(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(st(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(st(t))||(this.exclusiveBlockIds.delete(st(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new es(t))}static register(t){return this.get(t)}}function NC(n,t){es.get(n).exclusiveBlock(t)}function PC(n,t){es.get(n).unexclusiveBlock(t)}class kR{writable(t,e){if(Array.isArray(e)){for(const r of e)if($u(r))return!1;return}if($u(e))return!1}create(t,e,r,i,o){const s=es.get(t).getExclusiveMessage(o.id);s&&OC(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=es.get(t).getExclusiveMessage(o.id);s?OC(t,i,s.userId,s.displayName):vR(i)}}const vit="",tV={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},eV={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},nV={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};_.mergeLang({"zh-CN":tV,"en-US":eV,"ja-JP":nV});function Hu(n,t){return n.getBlockData(t).lock}function E0(n,t){return!!Hu(n,t)}function ju(n,t){const e=Hu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function FC(n,t){const e=Hu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function rV(n,t){if(n.readonly||!n.isBlockWritable(t)||E0(n,t)&&!ju(n,t))return;const e=n.doc.getUser(),r={userId:e.userId,displayName:e.displayName,locked:Date.now()},o={...n.getBlockData(t),lock:r};n.updateBlockData(t,o)}function iV(n,t){if(!ju(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const oV=10,sV=80,lV=50;class KC{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;if(!i||!i.blockId)return;const o=t.getBlockById(i.blockId);i.type==="lock"?rV(t,o):i.type==="unlock"&&iV(t,o)})}create(t,e,r,i,o){const s=o.lock;s&&(s.userId!==t.doc.getUser().userId?z(i,"locked-by-others"):z(i,"locked-by-self"))}update(t,e,r,i,o){const s=o.lock;if(s)if(s.userId!==t.doc.getUser().userId){z(i,"locked-by-others");const l=t.selection.focusedBlock;(l===i||ee(i,l))&&(nt(t,i)||St(i)==="code")&&t.insertTextBlock("",ut(r),bt(i)+1)}else z(i,"locked-by-self");else ot(i,"locked-by-others"),ot(i,"locked-by-self")}writable(t,e){let r=[];Array.isArray(e)?r=e:r.push(e);for(const i of r){if(FC(t,i))return!1;if(fr(i))return;let o=Is(i);for(;o;){if(FC(t,o))return!1;o=Is(o)}}}commands(t,e){const r=E0(t,e),i=ju(t,e),o=$u(e),s={blockId:st(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(r)if(i)l.id="unlock-block",l.name=_.t("locker.unlock"),s.type="unlock";else{const c=Hu(t,e);let d=(c==null?void 0:c.displayName)||"";const h=_.getCurrentLang()==="ja-JP",C=Tb(d,oV,h?lV:sV);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=_.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=_.t("locker.lock"),l.states=["disabled"]):l.name=_.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Tit="",aV={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},cV={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},uV={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};_.mergeLang({"zh-CN":aV,"en-US":cV,"ja-JP":uV});class A0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const fV=D("standard-block-actions");class dV{constructor(){g(this,"executeCommand",(t,e,r)=>{const i=r.data;try{const o=t.getBlockById(i);if(r.id==="delete"){t.deleteBlock(o);return}r.id==="copy"&&sh(t,o),r.id==="cut"&&(sh(t,o),t.deleteBlock(o))}catch(o){fV.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=E0(t,e),i=r&&ju(t,e),o=st(e),s=TC(),l=$u(e),c={id:"copy",name:_.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:_.t("copyCutProperty.unsafeEnvTips",{shortCut:ur("CtrlOrCmd+C"),operation:_.t("copyCutProperty.copy")})},d={id:"cut",name:_.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:_.t("copyCutProperty.unsafeEnvTips",{shortCut:ur("CtrlOrCmd+X"),operation:_.t("copyCutProperty.cut")})},h={id:"delete",name:_.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const RR=D("block-menu");class hV{constructor(t){g(this,"menu");g(this,"currentBlock",null);g(this,"commandBlock",null);g(this,"handleShow",()=>{p(RR,this.currentBlock,"no target block before show block menu");const t=QK(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});g(this,"handleClose",()=>{bp(this.editor)&&this.editor.focus()});g(this,"handleItemClick",(t,e)=>{p(RR,this.commandBlock,"no command block before show block menu"),YK(this.editor,this.commandBlock,e),e.element||this.close()});g(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new Zs([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new dV)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const mV=1e3;async function gV(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=mV?"":(await Dx.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const pV=D("drag-preview-image");class CV{constructor(t){g(this,"startPosition",null);g(this,"dragContainer",null);g(this,"handleDragStart",async(t,e)=>{const r=t.target;p(pV,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=L2;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),b=this.editor.rootContainer.getBoundingClientRect(),k=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(b.width/2,k.width)}px`,this.dragContainer=s;const w=await gV(this.editor,e);w?l.src=w:z(s,"drag-placeholder"),tg(s,{status:"loaded"})});g(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:r}=t;if(e===0&&r===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:i,y:o}=this.startPosition,s=e-i,l=r-o;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});g(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const yR="drag-preview-element";function EV(n){if(Rt(n,yR))return n;const t=n.querySelector(`.${yR}`);return t||(Ie(n)?Dt(n):n)}const x0=D("block-menu-drag-handler");function VC(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class AV{constructor(t,e){g(this,"dragPreview");g(this,"autoScroll");g(this,"oldPos",{x:0,y:0});g(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(p(x0,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:r,y:i}=t;this.oldPos={x:r,y:i},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});g(this,"handleDragStart",t=>{var s,l;const e=Gn(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Ad({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(x0,r,"no dragged block"),(l=(s=Zt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=VC(t,"dragstart");TV(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=EV(r);this.dragPreview.handleDragStart(t,o),this.autoScroll.active(),z(r,"dragging"),z(this.editor.contentElement,"dragging")});g(this,"handleDrag",t=>{const{target:e,x:r,y:i}=t;if(this.oldPos.x===r&&this.oldPos.y===i)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:r,y:i},p(x0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=VC(t,"dragover");this.editor.contentElement.dispatchEvent(o)});g(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(x0,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(i=this.autoScroll)==null||i.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const r=VC(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new CV(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class zu{constructor(t){g(this,"highlightedBlockId","");g(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=st(t),z(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new zu(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class wR{constructor(t){g(this,"buttonElement");g(this,"emptyBlockMenu");g(this,"blockMenu");g(this,"dragHandler");g(this,"handleHoverBlock",(t,e,r)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const i=this.editor.getCustom("editor-tooltip");if(i&&i.visible()&&(i.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(r.target)||this.buttonElement.remove());return}const o=vg(t);Os(o)||(this.updateButton(o),MC(o,this.buttonElement,Number.MAX_SAFE_INTEGER))});g(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const r=this.blockMenu.currentBlock;if(!r)return;this.editor.selection.selectBlock(r,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{zu.get(this.editor).highlightBlock(r)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});g(this,"updatePlaceholder",t=>{Dt(t).setAttribute("data-content-placeholder",_.t("blockMenu.button.searchPlaceholder"))});g(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;if(this.blockMenu.currentBlock){const r=st(this.blockMenu.currentBlock);if(!this.editor.findBlockById(r)&&this.blockMenu.isVisible){this.blockMenu.close();return}}const e=de(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new zK(t),this.blockMenu=new hV(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new AV(this.editor,this);const e=be.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new jK),zu.register(this.editor)}destroy(){be.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=B("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,_.t("blockMenu.button.tips")),t.innerHTML=pp,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=w2,this.buttonElement.setAttribute(e,_.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=pp,this.buttonElement.setAttribute(e,_.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),de(this.editor,t)&&!(Ft(t)&&Gp(t))?this.setButtonType("insert"):this.setButtonType("move")}}const xV={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
623
623
  \u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},bV={blockMenu:{section:{basics:"Basic",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert below",copy:"Copy",cut:"Cut",delete:"Delete"},button:{searchPlaceholder:"Search",tips:`Hold to drag
624
624
  Click to open the menu`,insertTips:"Click to add block"}}},BV={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};_.mergeLang({"zh-CN":xV,"en-US":bV,"ja-JP":BV});const kit="";class vV{constructor(){g(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function b0(n){return n.addCustom("drag-data",()=>new vV)}function $C(n,t){if(!t)return null;const e=b0(n).getData();return!e||e.editorId!==n.id?null:e}function LR(n,t){const e=$C(n,t);return e?n.findBlockById(e.blockId):null}function TV(n,t,e){if(!t.dataTransfer)return;const i=it(e),o=ut(i),s=st(e),l={type:"block",editorId:n.id,containerId:o,blockId:s};b0(n).setData(l)}function kV(n,t,e,r,i){if(!t.dataTransfer)return;const s=it(e),l=ut(s),c=st(e),d={type:"custom",customType:r,editorId:n.id,containerId:l,blockId:c,data:i};b0(n).setData(d)}function Gu(n){b0(n).clearData()}const RV=D("drop-indicator"),Wu=2;class yV{constructor(t){g(this,"indicator");g(this,"target",null);this.editor=t,this.indicator=B("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const r=this.getIndicatorRect(t,e),i=this.editor.rootElement.getBoundingClientRect(),o=r.top-i.top,s=r.left-i.left;this.indicator.style.top=`${o}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${r.width}px`,this.indicator.style.height=`${r.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const l=_s(t);if(!l){p(RV,Mr(it(t)),"block does not in a child container");const C=t.getBoundingClientRect(),E=this.getViewRect(t);return new DOMRect(E.x,C.y,E.width,Wu)}const c=l.getBoundingClientRect(),d=t.getBoundingClientRect(),h=this.getViewRect(t);return new DOMRect(h.x,(c.bottom+d.top)/2,h.width,Wu)}const r=Ms(t);if(!r){const l=t.getBoundingClientRect(),c=this.getViewRect(t);return new DOMRect(c.x,l.bottom,c.width,Wu)}const i=t.getBoundingClientRect(),o=r.getBoundingClientRect(),s=this.getViewRect(t);return new DOMRect(s.x,(i.bottom+o.top)/2,s.width,Wu)}getViewRect(t){const e=Gn(t,{horizontal:!0}),r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),o=Math.max(i.x-r.x,0),s=Math.max(r.right-i.right,0);return new DOMRect(r.x+o,r.y,Math.max(r.width-o-s,0),Wu)}}const wV=D("find-drop-target");function LV(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if($i(e)&&Mr(e))return e;const r=e.firstElementChild;return r&&$i(r)&&Mr(r)?r:null}function SV(n,t){const s=t,l=n;for(let c=0;c<2;c++){const d=l+c*50;for(let h=0;h<5;h++){const C=s+h*8,E=document.elementFromPoint(d,C);if(E){const y=rt(E);if(y)return y}if(h===0)continue;const b=s-h*8,k=document.elementFromPoint(d,b);if(k){const y=rt(k);if(y)return y}}}return null}function IV(n,t,e){const r=document.elementFromPoint(t,e);if(r){const h=rt(r);if(h&&!_t(n,h))return h}const i=new Set,o=LV(t,e);if(o){const h=o.getBoundingClientRect();e<h.top+h.height/2?i.add(ke(o)):i.add(Ye(o))}const s=SV(t,e);s&&i.add(s);const l=Array.from(i),c=h=>{for(let C=0;C<l.length;C++){const E=l[C];if(h!==E&&ee(h,E))return!0}return!1},d=l.filter(h=>!c(h));return d.length>0?d[0]:null}function HC(n,t){if(n.readonly)return!1;const e=it(t);if(Qt(e))return!0;const r=rt(e);return p(wV,r,"no parent block"),n.isBlockWritable(r)?HC(n,r):!1}const DV=D("drop-target");function _V(n,t){let e={};return/image/.test(t.type)?e=n.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=n.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=n.editorEmbeds.getEmbedClass("video")),p(DV,e,`unSupport file type ${t.type}`),e}async function SR(n,t,e,r){var o,s;let i=r;for(const l of t){const c=_V(n,l);c.getOptions&&await((s=(o=c.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(o,n,{containerId:e,blockIndex:i,data:{file:l}}))&&(i+=1)}}class MV{constructor(t){g(this,"handleDrop",(t,e,r,i)=>{if(Array.isArray(e)){const o=e;if(o.length>0){const s=ut(r);return SR(t,o,s,i),!0}}return!1});this.editor=t}}class qu{constructor(t){g(this,"indicator");g(this,"lastDropOverResult");g(this,"handlers",[]);g(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=o=>{var d,h;const s=$C(this.editor,o.dataTransfer),l=LR(this.editor,o.dataTransfer),c=this.findTargetBlock(l,o.x,o.y);if(c&&ee(this.editor.rootContainer,c)){const C=this.findInsertPos(l,c,o.x,o.y,(h=s!=null?s:(d=o.dataTransfer)==null?void 0:d.items)!=null?h:null);if(C)return this.indicator.show(c,C),"move"}return this.indicator.hide(),"none"},r=(o,s)=>{o.dataTransfer&&(o.dataTransfer.dropEffect=s),s==="move"&&o.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const o=this.lastDropOverResult.dropEffect;r(t,o);return}const i=e(t);r(t,i),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:i}});g(this,"handleDrop",t=>{var o,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=$C(this.editor,t.dataTransfer),r=Array.from((s=(o=t.dataTransfer)==null?void 0:o.files)!=null?s:[]);if(!e&&r.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none"),Gu(this.editor);return}const i=this.indicator.target;if(i){const{block:l,insertPos:c}=i,d=LR(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Zt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:r,c,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus(),Gu(this.editor);return}if(d){const C=Zt(this.editor,d);if(C.handleDrop&&C.handleDrop(this.editor,d,e!=null?e:r,c,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus(),Gu(this.editor);return}}if(typeof c=="string"){const C=it(l);let E=bt(l);if(c==="after"){E+=1;let b=qt(l);for(;b&&!Nc(b);)E+=1,b=qt(b)}t.preventDefault();for(let b=0;b<this.handlers.length;b++)if(this.handlers[b].handleDrop(this.editor,d!=null?d:r,C,E)){this.editor.focus(),Gu(this.editor);return}if(d){const b=this.editor.getBlockData(d),k=$o(this.editor.editorBlocks,this.editor.doc.toJSON(),b),[y]=this.editor.insertDocAt(C,E,k);this.editor.selection.selectBlock(y,0),zu.get(this.editor).highlightBlock(y),this.editor.deleteBlock(d),this.editor.focus()}}})}Gu(this.editor)});g(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new yV(this.editor),this.handlers.push(new MV(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new qu(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||Ms(e)===t&&t||!HC(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||_s(e)===t&&t||!HC(this.editor,e)||Qt(it(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!ee(t,e)}findTargetBlock(t,e,r){let i=IV(this.editor,e,r);if(!i||!ee(this.editor.rootContainer,i))return null;const o=it(i),s=rt(o);return s&&St(s)==="code"&&(i=s),this.canDrop(t,i)?i:null}findInsertPos(t,e,r,i,o){let s=e;for(;s;){const c=Zt(this.editor,s);if(c.handleDropOver){const d=c.handleDropOver(this.editor,s,o,r,i);if(d)return d;if(d===!1)return null}s=Is(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=i&&i<=l.bottom){if(i<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return i<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<i&&this.canInsertAfter(t,e)?"after":""}}function IR(n,t,e){const r=_e.getImageObject(n,t),i=gt.default(r.getImages());if(i.length===1){n.deleteBlock(t);return}if(e===-1||e>=i.length)return;const o=xK(i);if(i.splice(e,1),i.length===1){const l=i[0],c=100*(l.flex/o);l.flex=1;const d=fn([l],c);n.updateEmbedData(t,d);return}i[0].flex=NaN,Na(i);const s=fn(i,r.getWidthPercent());n.updateEmbedData(t,s)}function UV(n,t,e,r){if(t.length===0||r==="after"||r==="before")return!1;let i=r.data;const o=_e.getImageObject(n,e),s=gt.default(o.getImages()),l=[],c=[];t.forEach(C=>{CR(C.type)&&s.length+l.length<6?l.push(C):c.push(C)}),l.forEach(C=>{try{pR(n,C)}catch{return}const E={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(i,0,E);const b=fn(s,o.getWidthPercent());n.updateEmbedData(e,b),o.replaceImage(i,C),i+=1});const d=n.getBlockIndex(e)+1,h=ut(it(e));return SR(n,c,h,d),!0}function OV(n,t,e,r,i){var s,l,c;if(Cd(e))return UV(n,e,t,r);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const o=e.data;if(i.isSourceBlock){const d=i.targetBlock,h=it(d);let C=bt(d);r==="after"&&(C+=1);const b=100*(o.boundingRect.width/n.rootContainer.getBoundingClientRect().width),k=fn([o.image],b),y={id:et(),type:"embed",embedType:"image",embedData:k},w=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;w&&(y.align=w),n.insertBlock(ut(h),C,y),IR(n,t,o.index),(c=n.findCustom("drag-handler"))==null||c.handleDragEnd()}else{if(typeof r=="string")return;const d=t;let h=r.data;const C=_e.getImageObject(n,d),E=gt.default(C.getImages());h>E.length&&(h=E.length),n.undoManager.runInGroup(()=>{var k,y;C.setAutoFix(!0);const b=n.getBlockById(e.blockId);if(b===d){const w=o.index,O=h,I=o.image;if(w===O||O===w+1)return;let V=O;w<O?(E.splice(O,0,I),E.splice(w,1),V-=1):(E.splice(w,1),E.splice(O,0,I));const G=fn(E,C.getWidthPercent());n.updateEmbedData(d,G),C.setSelectedIndex(V),(k=n.findCustom("drag-handler"))==null||k.handleDragEnd()}else{E.splice(h,0,o.image),E[0].flex=NaN,Na(E);const w=fn(E,C.getWidthPercent());n.updateEmbedData(d,w),IR(n,b,o.index),(y=n.findCustom("drag-handler"))==null||y.handleDragEnd(),C.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const NV=2;function B0(n,t,e){const r=Bi(t);if(e<=0){const s=r[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===r.length){const s=r[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const i=r[e-1].getBoundingClientRect(),o=r[e].getBoundingClientRect();return new DOMRect((o.left+i.right)/2-1,i.top,NV,i.height)}function PV(n,t,e,r,i){for(let o=0;o<e.length;o++){const l=e[o].getBoundingClientRect();if(r<=l.right)return r<=l.left+l.width/2?{rect:B0(n,t,o),data:o}:{rect:B0(n,t,o+1),data:o+1}}return r>e[e.length-1].getBoundingClientRect().right?{rect:B0(n,t,e.length),data:e.length}:{rect:B0(n,t,e.length),data:0}}function FV(n,t,e,r,i){const o=Bi(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>CR(s.type))||o.length>=6)return}else{if((e==null?void 0:e.type)==="block"||o.length>=6&&(e==null?void 0:e.blockId)!==st(t))return;const s=st(t);if(o.length===1&&s===(e==null?void 0:e.blockId))return}return PV(n,t,o,r)}async function KV(n){return await Dx.default.toSvg(n)}function jC(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class VV{constructor(t){g(this,"img");g(this,"dragContainer",null);g(this,"autoScroll",null);g(this,"imageContainer",null);g(this,"startPosition",null);g(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement)||t.button!==0)return;const r=rt(e);if(!r||!Wr(r)||!this.editor.isBlockWritable(r)||this.editor.readonly)return;const i=_e.getImageObject(this.editor,r);if(this.imageContainer=DC(t.target),!this.imageContainer)return;const s=uR(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=i.getImages()[s];if(!l)return;const{x:c,y:d}=t;this.startPosition={x:c,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},C=jC(t,"dragstart");kV(this.editor,C,r,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});g(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=rt(this.imageContainer);if(!e)return;const{x:r,y:i}=t,{width:o,height:s}=t.target.getBoundingClientRect(),l=ne(e),c=B("div",["drag-container"],l);c.style.left=`${r-o/4}px`,c.style.top=`${i-s/4}px`,c.style.width=`${Math.max(o/2,16)}px`,c.style.height=`${s/2}px`,this.dragContainer=c,z(this.editor.contentElement,"dragging");const d=Gn(e);this.autoScroll=new Ad({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=B("img",["drag-target"],c),E=await KV(this.imageContainer);E&&(h.src=E)});g(this,"handleDrag",t=>{var o;const{x:e,y:r}=t;if(((o=this.startPosition)==null?void 0:o.x)===e&&this.startPosition.y===r)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(t)),this.startPosition&&this.dragContainer){const{x:s,y:l}=t;if(s===0&&l===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:c,y:d}=this.startPosition,h=s-c,C=l-d;this.dragContainer.style.transform=`translate(${h}px, ${C}px)`,this.dragContainer.style.opacity="0.5"}const i=jC(t,"dragover");this.editor.contentElement.dispatchEvent(i)});g(this,"handleDragEnd",t=>{var e;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(e=this.autoScroll)==null||e.inactive(),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const r=jC(t,"drop");this.editor.contentElement.dispatchEvent(r)}});this.editor=t,this.editor.rootContainer.addEventListener("mousedown",this.handleMouseDown),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("mousedown",this.handleMouseDown)}}class $V{constructor(t){g(this,"handleFocusBlockChanged",(t,e,r)=>{const o=this.editor.getFocusedBlock();if(o&&Wr(o)){const s=_e.getImageObject(this.editor,o);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}r&&Wr(r)&&t.findCustom(`image-${r.id}`)&&_e.getImageObject(this.editor,r).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class HV{constructor(t){g(this,"currentResizer",null);g(this,"handleHoveringBlockChange",(t,e)=>{window.isDragging||(e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t)))});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){Wr(t)&&_e.getImageObject(this.editor,t).disableResizer()}enable(t){if(Wr(t)){const e=_e.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const jV={image:{title:"\u56FE\u7247",upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-3">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},zV={image:{title:"Image",upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>',remote:{failed:'<div class="line-1">Failed to load image</div><div class="line-2">This picture is from an expired external link</div><div class="line-3">Please save the original image to local drives and upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"This picture is from an external link. If the link expires, the picture will not be available. It's recommended to save it to local drives and add it to the page."}},abstract:"Image"}},GV={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};_.mergeLang({"zh-CN":jV,"en-US":zV,"ja-JP":GV});function WV(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Sn(o,r),l=ae(s);let c=r;if(l.endsWith("![]()"))c-=5;else if(l.endsWith("![]"))c-=3;else return!1;const d=r;return Jl("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c);let C=e+1;ae(n.getBlockText(i)).trim()?(aa(n,i,c,{forceInsertAfter:!0}),c===0&&(n.deleteBlock(i),C--)):(n.deleteBlock(i),C--),kg(n,"image",t,C,{file:h})})}),!0}class qV{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(h0(t,e))return!1;if(WV(t,e,r,i))return!0}return!1}}function XV(n){const t=n.getFocusedBlock(),e=Ms(t);if(e&&Wr(e)){n.selection.selectBlock(e,0);const r=_e.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function QV(n){const t=n.getFocusedBlock(),e=_s(t);if(e&&Wr(e)){n.selection.selectBlock(e,0);const r=_e.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function YV(n){const e=n.getFocusedBlock();if(e&&Wr(e)){const r=_e.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(i.length-1),!0;if(o>0)return r.setSelectedIndex(o-1),!0}}}function ZV(n){const e=n.getFocusedBlock();if(e&&Wr(e)){const r=_e.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(0),!0;if(o<i.length-1)return r.setSelectedIndex(o+1),!0}}}function zC(n){const e=n.getFocusedBlock();if(e&&Wr(e)){const r=_e.getImageObject(n,e);if(r.getImages().length>0){const o=r.getSelectedIndex();if(o!==-1)return r.removeImage(o),!0}}}const JV={ArrowLeft:YV,ArrowRight:ZV,ArrowUp:QV,ArrowDown:XV,Delete:zC,Backspace:zC},t$=D("copy-image");function e$(n,t,e,r){const i=e.getImages()[r],o=e.getImages().length===1?e.getWidthPercent():i.flex*100,s=fn([i],o),l={id:et(),type:"embed",embedType:"image",embedData:s},c=n.options.componentsOptions.image;c!=null&&c.defaultAlign&&(l.align=c.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const C=h.getContext("2d");if(!C)return;const E={},b={};try{C.drawImage(t,0,0,h.width,h.height);const V=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),G=ag(V),q=new File([G],`${Date.now()}.png`,{type:"image/png"});E["image/png"]=q}catch(I){t$.error(I)}oh(n,d);const y=`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`,w=ih(y,d),O=new Blob([w],{type:"text/html"});return E["text/html"]=O,b["text/html"]=w,[E,b]}function n$(n,t,e,r,i){const o=e$(n,t,e,r);if(!o)return;const[s,l]=o;if(s){const c=Object.entries(s).map(([d,h])=>({type:d,data:h}));return fg(c).then(d=>{if(!d&&i){const h=i.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function DR(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const i=n.getFocusedBlock();if(i&&Wr(i)){const o=_e.getImageObject(n,i);if(o.getImages().length>0){const l=o.getSelectedIndex();if(l!==-1){const d=Bi(i)[l].querySelector("img");if(d)return n$(n,d,o,l,t)}}}}class r${constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,r){if(!window.isSecureContext)return;if(DR(t,e))return!0}handleBeforeCut(t,e){if(DR(t,e))return zC(t),!0}destroy(){}}class GC{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,r){return Object.values(e.blocks).forEach(i=>{i.forEach(o=>{if(o.type==="embed"&&o.embedType==="image"){const s=o.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=r.blockIdMap.get(o.id);l&&ts(t,l).setAutoFix(!0)}}})}),!1}destroy(){}}const i$=D("image-embed");function o$(n,t,e,r,i,o){_e.create(n,e).createContent(i,o,t),n.addCustom("image-select-handler",()=>new $V(n)),n.addCustom("image-copy-handler",()=>new r$(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new VV(n));const l=n.addCustom("image-resizer",()=>new HV(n)),c=e.embedData;Oa(c)?l.disable(o):l.currentResizer===o&&l.enable(o)})}function s$(n,t,e,r){const i=t.embedData,o=Pa(i);return r==="html"?o.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):r==="markdown"?`${o.map(l=>`![img](${n.doc.buildResourceUrl(l.src,{withToken:!0})})`).join(`
625
625
  `)}
@@ -690,7 +690,7 @@ ${s}
690
690
  <path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
691
691
  </svg>`,Cj=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
692
692
  <path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
693
- </svg>`,Dit="",L0="reply-editor-editing",{t:cE}=_;class Ej{constructor(t,e,r,i){g(this,"root");g(this,"components");g(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});g(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,r=t.getDoc();t1(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{Rt(this.root,L0)||(z(this.root,L0),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!Rt(this.root,L0)||ot(this.root,L0)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,o=r.getDoc(),s=w0({editor:t,commentGroupId:e.groupId});i.localCreateComment(s,o),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{Rt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{ot(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=B("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=il(this.root,Jt.QuickReply,cE("comment.placeholder"));lo(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=B("div",["quick-reply-editor"],this.root),i=Yi(),o=new aE(this.mainEditor,t,i);o.editor.addListener("docChanged",this.handleDocChange),o.editor.addListener("focus",this.handleFocus),o.editor.input.addHandler(new uj(this.groupItem)),r.append(o.root);const s=B("div",["reply-editor-actions"],r),l=pr(Jt.QuickReplyCancel,cE("common.cancel"));lo(l,Jt.QuickReplyCancel);const c=pr(Jt.QuickReplyOk,cE("comment.send"),void 0,["primary","disabled"]);return lo(c,Jt.QuickReplyOk),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:o,replyEditorContainer:r,okButton:c}}}const ao=D("comment-group-item");class Aj extends Te.TypedEmitter{constructor(e,r,i,o){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>B("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=B("div",["comment-children-list-container"],this.root);return new gj({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});g(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));p(ao,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{ot(i,gy)});const r=e[e.length-1];z(r,gy)});g(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),r=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');p(ao,e,"switchUpButton not exist"),p(ao,r,"switchDownButton not exist"),ot(r,"disabled"),ot(e,"disabled"),this.root.previousElementSibling===null&&z(e,"disabled"),this.root.nextElementSibling===null&&z(r,"disabled")});g(this,"handleReadonlyChanged",e=>{e.readonly?z(this.root,"readonly"):ot(this.root,"readonly")});g(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=r,this.comment=i,this.groupList=o,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new Bs(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return Cy(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,o=new Ej(e,r,i,this);return this.root.append(o.root),o}createHeader(){const{comment:e}=this,r=B("div",["comment-item-head"],this.root),i=B("span",["item-head-quote"],r);i.innerText=e.abstract;const o=B("span",["item-head-switch"],r),s=il(o,Jt.SwitchUp,"up",pj),l=il(o,Jt.SwitchDown,"down",Cj);return lo(s,Jt.SwitchUp),lo(l,Jt.SwitchDown),r}createItem(){const e=B("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:o,groupList:s}=this,l=new yy({mainEditor:r,commentsProvider:i,comment:o,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(r=>r.comment.id===e):null}handleCreateComment(e){return p(ao,ll(e),"invalid comment, not a child comment"),p(ao,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){p(ao,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){ao.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(ao,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(ao,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const xj=D("arrange=items"),Ly=20;function Sy(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const r=n.scrollContainer.getBoundingClientRect(),i=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-r.top+i}function Iy(n,t){return Number.parseInt(t.root.style.top,10)}function Dy(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let o=i;o<t.length;o++){const s=t[o],l=s.comment,c=Sy(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),o===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else s.root.style.top=`${c}px`;continue}const d=t[o-1],h=Iy(n,d)+d.root.getBoundingClientRect().height;h>c?s.root.style.top=`${h+Ly}px`:s.root.style.top=`${c}px`}for(let o=i-1;o>=0;o--){const s=t[o],l=s.comment,c=Sy(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const d=s.root.getBoundingClientRect(),h=c+d.height,C=t[o+1];p(xj,C,"no next item");const E=Iy(n,C);E<h?s.root.style.top=`${E-d.height-Ly}px`:s.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const S0=D("comment-group-item-handler");class bj{constructor(t,e){g(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});g(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});g(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});g(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});g(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});g(this,"handleCommentItemReply",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:o}=r,s=i.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:et(),box:!0,created:Date.now(),text:o.displayName,iconUrl:o.avatarUrl,mentionId:o.userId};s.editor.insertBoxToBlock(l,0,c)});g(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});g(this,"handleCommentItemOk",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:o,getCommentEditor:s}=r,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(o,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let o=!1;if((c=i.blocks)!=null&&c.length||(o=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];o=!!h.text&&an(h.text)===0}if(o){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:s}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),s.show()});g(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e;t.getCommentEditor().edit(),r.hide()});g(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e,{comment:i}=t;this.commentsProvider.localDeleteComment(i.id),r.show()});g(this,"execute",(t,e,r,i)=>{const o=nj(t);if(!o||ij(o))return;const s=rj(o);switch(s){case Jt.SwitchUp:this.handleSwitchUp(i);break;case Jt.SwitchDown:this.handleSwitchDown(i);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,r);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,r);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,r);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;S0.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const I0=D("comment-group-list");class Bj extends tf{constructor(e,r,i){super(e,r,i,ns(e,r),{});g(this,"groupItemHandlers");g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const r=e.target.closest(".comment-group-item-root");if(!r)return;const i=ej(e.target),o=this.items.findIndex(s=>s.root===r);if(o!==-1){this.setActiveItem(o);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[o],i,o)}});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=By(this.editor);if(e.length>0){if(((r=this.activeItem)==null?void 0:r.comment.id)&&e.includes(this.activeItem.comment.id))return;const i=e[0],o=this.items.findIndex(s=>s.comment.groupId===i);this.setActiveItem(o),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});g(this,"handleEditorResize",()=>{this.updateItemsLayout()});g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"handleItemResize",()=>{this.updateItemsLayout()});g(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const r=document.elementFromPoint(e.clientX,e.clientY);if(!r||!(r instanceof HTMLElement)||!this.editor.scrollContainer.contains(r))return;const i=this.container.querySelector(".comment-group-item-root");if(!i)return;const o=Number.parseFloat(i.style.top),s=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(o)&&!Number.isNaN(s)&&o<s&&Dy(this.editor,this.items,null,Math.min(o+(0-e.deltaY)*3,s))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(I0,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Pe.default(()=>{const e=ns(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const o=e[i];if(!this.findGroupItem(o.groupId)){this.handleCreateComment(o,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const o=this.items[i];e.findIndex(s=>s.groupId===o.comment.groupId)===-1&&(this.deleteItem(o.comment.id),r=!0)}r&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(o=>o.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new bj(this,r)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){Dy(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,r){const i=new Aj(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{ot(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=ns(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}insertItem(e,r){const i=super.insertItem(e);return i?(r!=null&&r.active&&this.setActiveItem(this.items.indexOf(i)),this.updateItemsLayout(),i.addListener("resize",this.handleItemResize),i):null}setActiveItem(e,r){if(p(I0,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const i=this.container.querySelector(".comment-group-item-root.active");if(i&&ot(i,"active"),e!==-1){const o=this.items[e];z(o.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,r)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(r=>r.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,r){if(ll(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(I0,!i,"comment group item has already exists");const o={children:[],...e};p(I0,o.children,"not a comment group");const s=this.insertItem(o,{active:r});if(!!s&&r){const l=this.items.indexOf(s);this.setActiveItem(l),s.quickReply.hide(),setTimeout(()=>{s.edit()},300)}}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?(this.deleteItem(i.comment.id),this.updateItemsLayout()):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&(this.deleteItem(i.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}}const vj="comment-mini";D("comment-list");class Tj extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"groupsContainer");g(this,"list");g(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});g(this,"updateCommentCount",()=>{var r,i;const e=lj(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var o,s;const i=this.list.activeItem;Ty(this.editor,(s=(o=i==null?void 0:i.comment)==null?void 0:o.groupId)!=null?s:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=Rt(this.root,vj);(i=(r=this.commentOptions)==null?void 0:r.onUpdateLayout)==null||i.call(r,this.editor,{expand:e})});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-web-comment-root"],null),this.groupsContainer=B("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r),this.updateCommentCount()}onDeleteComment(e,r){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}createList(){return new Bj(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var r;if(ot(this.root,"hidden"),e){const i=this.list.findItemIndex(e);this.list.setActiveItem(i)}(r=this.commentOptions)==null||r.controller.showCommentList()}hide(){z(this.root,"hidden")}}class kj extends tf{constructor({editor:t,parent:e,commentsProvider:r,comments:i}){super(t,r,e,i,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:r}=this;return new wy(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const D0=D("mobile-comment-group-item"),Rj=20;class yj extends Te.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>B("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=new wy(r,i,o);return e.append(s.root),s});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=B("div",["mobile-comment-children-list-container"],e);return new kj({editor:r,commentsProvider:i,comments:o.children,parent:s})});g(this,"handleTouchEnd",()=>{var o;const{scroller:e}=this,{pullThreshold:r=Rj}=(o=this.editor.getComponentOptions("comment"))!=null?o:{};let i=null;if(e.y>e.minScrollY+r?(i=this.root.previousElementSibling,i||this.emit("onReachTop")):e.y<e.maxScrollY-r&&(i=this.root.nextElementSibling,i||this.emit("onReachBottom")),i){const s=i.id;this.emit("onSwitchGroup",s,py)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=B("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const o=B("div",["mobile-group-item"],this.root),s=B("div",["mobile-group-item-space"],null),l=B("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=B("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),o.append(s,l,c),this.scroller=new _x.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return Cy(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(D0,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){D0.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(D0,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(D0,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const uE=D("mobile-group-list");class wj extends tf{constructor(e,r,i,o){super(e,r,i,ns(e,r),{});g(this,"scroller");g(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});g(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const r=this.findItemIndex(e);let i=null;return r===0?i=this.items[r+1].root.id:i=this.items[r-1].root.id,super.deleteItem(e)?(this.scrollToGroup(i,py),!0):!1});g(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});g(this,"handleReachBottom",()=>{this.emit("onReachBottom")});g(this,"handleReachTop",()=>{this.emit("onReachTop")});g(this,"scrollToGroup",(e,r=0)=>{const i=this.findGroupItem(e);p(uE,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),Ty(this.editor,i.comment.groupId)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"updateComments",Pe.default(()=>{const e=ns(this.editor,this.commentsProvider);for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1);continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(o=>o.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new _x.default(o),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new yj(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=ns(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(ll(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const i=this.findItem(e.id);p(uE,!i,"comment group item has already exists");const o={children:[],...e};p(uE,o.children,"not a comment group"),this.insertItem(o),this.scroller.refresh()}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?this.deleteItem(i.comment.id):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&this.deleteItem(i.comment.id);return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const Lj=D("mobile-comment-list"),{t:_y}=_;class Sj extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"list");g(this,"mask");g(this,"pullInfoContainer");g(this,"handleRootClick",e=>{const r=e.target;p(Lj,r instanceof Element,"invalid target"),!(r.closest(".mobile-group-item-abstract")||r.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});g(this,"hidePullInfo",Pe.default(()=>{ot(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;ot(this.root,"hidden"),z(document.documentElement,"disabled-scroll"),(r=this.commentOptions)==null||r.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});g(this,"hide",()=>{z(this.root,"hidden"),ot(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mobile-comments-root"],null),this.mask=B("div",["mobile-comment-mask"],this.root);const i=B("div",["mobile-comment-groups-container"],this.root),o=B("div",["mobile-comment-groups-scroll-container"],i);this.list=new wj(this.editor,this.commentsProvider,o,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=B("div",["mobile-comment-pull-info-container"],this.root);return B("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=_y(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=r,z(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function My(n,t){const e=ns(n,t),r=new Map;for(const i of e){const o=Ey(n,i.groupId);if(!!o)if(r.has(o)){const s=r.get(o);oE(i).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=oE(i),l=new Set(s.map(c=>c.id));r.set(o,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,o])=>({blockId:i,...o}))}const Ij=D("mini-group-item");class Dj{constructor(t,e){g(this,"root");g(this,"blockId");g(this,"comment");g(this,"miniCommentItem");g(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=B("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new mj(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return Ey(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);p(Ij,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class _j extends tf{constructor(e,r,i){super(e,r,i,My(e,r),{});g(this,"fixListOps",Pe.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));g(this,"handleDocChanged",Pe.default(()=>{this.updateMiniCommentsGroup()},100));g(this,"updateMiniCommentsGroup",()=>{const e=My(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=r,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new Dj(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,r){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const Mj=D("mini-comments-list");class Uj extends Te.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=B("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new _j(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(Mj,i instanceof HTMLElement,"The target is not a valid html element");const o=i.closest(".mini-comment-item");o&&this.emit("onItemClick",o.id)});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){}show(){ot(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function Uy(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const r=t.block,i=Ee(n,r,t.start.offset,t.end.offset),o=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;P3(n,r,i,o,s)}function Oj(n,t,e){const r=ci(n).map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{ci(n,{simpleBlockOnly:!0}).forEach(c=>{!nt(n,c.block)||Uy(n,c,o)});const l=Yi();e.localCreateComment(o,l)}),o}class Nj{constructor(t,e){g(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,r){const i=t.selection.range;if(nt(t,e)&&!r.isCollapsed()&&i.isSimple()){const o=st(e),s=St(e),l=Dr(t,e);return[{id:"add-comment",name:_.t("comment.command"),blockId:o,blockType:s,blockKind:l,groupIndex:1e3,icon:Qs}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,r,i,o){if(r.id==="add-comment"){this.editorComments.showCommentList();const s=Oj(t,e,this.provider);return o["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class Oy{constructor(t,e){g(this,"commentList",null);g(this,"mobileCommentList",null);g(this,"miniCommentList");g(this,"showComment",(t,e)=>{var r,i;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((r=this.mobileCommentList)==null||r.show(e)),t==="web"&&((i=this.commentList)==null||i.show(e))});g(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});g(this,"handleCommentListClose",()=>{this.showComment("mini")});g(this,"handleOnSelectComment",()=>{this.showComment("web")});g(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new Nj(e,this)),t.blockHooks.push(new ZH(this.provider,this)),this.isMobile?(this.mobileCommentList=new Sj(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new Tj(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new Uj(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new JH)}get commentProvider(){return this.provider}get isMobile(){return ge.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const _it="",Pj={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8",replyPlaceholder:"\u56DE\u590D\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},Fj={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation",replyPlaceholder:"Add annotations or @ others",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},Kj={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u8A8D",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":Pj,"en-US":Fj,"ja-JP":Kj});class Ny{renderText(t,e,r){const i=[],o={};return Object.entries(r).forEach(([s,l])=>{s.startsWith("comment-")&&(i.push("comment"),o[s]=l)}),{classes:i,attributes:o}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const o=["comment"],s={};return i.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:o,attributes:s}}updateBlock(t,e,r,i){const o=i.comments;ot(r,"comment"),Array.from(r.attributes).forEach(s=>{s.name.startsWith("comment-")&&r.removeAttribute(s.name)}),!(!o||o.length===0)&&(z(r,"comment"),o.forEach(s=>{r.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class Vj{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,o)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();g0(t,e,_.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function $j(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const s=new Set(i);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const o=r.text;if(!!o&&nt(n,t)){const s=Qg(o,`comment-${e.toLocaleLowerCase()}`,e);Rc.default(o,s)||n.setBlockText(t,s)}}const Hj=D("editor-comment");function jj(n){const t=n.getCustom("editor-comments");if(p(Hj,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Po(s);if(l.length>=2){const{containerId:c}=l[l.length-1],d=rt(li(n,c));if(d&&St(d)==="code"){rE(n,d,t.commentProvider);return}}rE(n,s,t.commentProvider);return}const e=ci(n,{simpleBlockOnly:!0}),r=e.map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?Uy(n,l,o):my(n,l.block,o)});const s=Yi();t.commentProvider.localCreateComment(o,s)})}const fE=D("text-styles");function zj(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([o])=>!!o.startsWith("style-"));return new Map(i)};if(n.length===0)return new Map;let e=t(n[0]);for(let r=1;r<n.length;r++){const i=t(n[r]);e=new Map(Array.from(e.entries()).filter(([o,s])=>i.get(o)===s))}return e}function Gj(n,t,e,r,i){p(fE,e.isSimple(),"invalid range");const{start:o,end:s}=e;p(fE,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(fE,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=ia(o.offset,s.offset-o.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=ia(o.offset,s.offset-o.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=ia(o.offset,s.offset-o.offset,c,r,void 0,{ignoreValue:!0}):c=Gc(o.offset,s.offset-o.offset,c,r,i),n.setBlockText(t,c),c}const al=D("text-commands");function Py(n){const t={id:"more",name:_.t("commands.more"),icon:rp,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[_.t("commands.bold"),ur("CtrlOrCmd+B"),I2],"style-italic":[_.t("commands.italic"),ur("CtrlOrCmd+I"),D2],"style-underline":[_.t("commands.underline"),ur("CtrlOrCmd+U"),_2],"style-strikethrough":[_.t("commands.strikethrough"),ur("CtrlOrCmd+D"),M2],"style-code":[_.t("commands.code"),void 0,U2]},r={"style-super":[_.t("commands.superscript"),void 0,N2],"style-sub":[_.t("commands.subscript"),void 0,O2]};if(an(n)===0){const l=Object.entries(e).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h}));return t.children=Object.entries(r).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h})),l.concat(t)}const i=zj(n);function o([l,[c,d,h]]){const C=i.get(l);return C!==void 0?{id:l,name:c,value:C,states:C===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:c,icon:h,desc:d}}const s=Object.entries(e).map(o);return t.children=Object.entries(r).map(o),s.concat(t)}function Wj(n,t){const e=st(t),r=St(t),i=Dr(n,t);return Py([]).map(o=>({blockId:e,blockType:r,blockKind:i,...o,groupIndex:500}))}function qj(n,t,e){p(al,e.isSimple(),"nor a simple range");const{start:r,end:i}=e;p(al,r.isSimple(),"is not a simple block position"),p(al,i.isSimple(),"is not a simple block position"),p(al,nt(n,t),"invalid block type, not a text kind block");const o=st(t);p(al,r.blockId===o&&i.blockId===o,"invalid range");const s=n.getBlockText(t);let l=[];r.offset===i.offset?r.offset!==0&&(l=qe(s,r.offset-1,1).middle):l=qe(s,r.offset,i.offset-r.offset).middle;const c=St(t),d=Dr(n,t);return Py(l).map((h,C)=>({blockId:o,blockType:c,blockKind:d,...h,groupIndex:500,order:C*100}))}function Xj(n,t,e,r,i,o){if(!nt(n,t))return!1;if(!r.startsWith("style-"))return al.warn(`unknown command: ${r}`),!1;const s=i==null?void 0:i.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return al.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const c=Gj(n,t,e,r,s);return o.result=c,!0}const Qj=D("text-command-provider");class ki{constructor(t){g(this,"id","TextCommandProvider");g(this,"emptyTextBlockAttributes",new Map);g(this,"colorItem");g(this,"updateButtonColor",t=>{const e=V3(this.editor,t,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(e)});g(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")F3(this.editor,t,e,this.setEmptyTextBlockColor);else{const r=["clearAll","clearColor","clearBackground"];K3(this.editor,r[e],this.setEmptyTextBlockColor)}});g(this,"getEmptyTextBlockColor",(t,e)=>{const r=this.getEmptyBlockTextAttributes(t,e);return Yg(r)});g(this,"setEmptyTextBlockColor",(t,e,r,i)=>{var s;const o=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};z5(o,r,i),this.emptyTextBlockAttributes.set(e,o)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new J_(t)),this.colorItem.addListener("onClick",this.handleChangeColor)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,r){if(!nt(t,e))return[];let i;ft(t,e)===0?i=this.getCommandsOnEmptyText(t,e).map(ki.toTextCommand):i=qj(t,e,r).map(ki.toTextCommand),this.updateButtonColor(r);const s={...this.colorItem,blockId:st(e),blockKind:Dr(t,e),blockType:St(e),groupIndex:500,order:350};return i.push(s),i}executeCommand(t,e,r,i,o,s){if(!nt(t,e))return!1;let l=o.value;l===void 0&&(l=!i.value);const c=ki.fromTextCommandId(i.id);if(c.startsWith("style-")){if(c==="style-font")return this.handleChangeColor(o.type,l),!0;if(ft(t,e)===0)return this.executeCommandOnEmptyText(e,i,{value:l})}return Xj(t,e,r,c,{value:l},s)}executeCommandOnEmptyText(t,e,r){let i=this.emptyTextBlockAttributes.get(st(t));i||(i={},this.emptyTextBlockAttributes.set(st(t),i));const o=ki.fromTextCommandId(e.id),s=r.value;return s==null||s===!1?(delete i[o],!0):(i[o]=r.value,!0)}getCommandsOnEmptyText(t,e){const r=Wj(t,e);return this.setCommandsStates(r,e)}setCommandsStates(t,e){var o;const r=st(e),i=(o=this.emptyTextBlockAttributes.get(r))!=null?o:{};return t.map(s=>{const l=i[s.id],c=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:c}})}getEmptyBlockTextAttributes(t,e){var i;const r=gt.default((i=this.emptyTextBlockAttributes.get(e))!=null?i:{});if(Array.from(Object.entries(r)).forEach(([o,s])=>{s||delete r[o]}),Object.keys(r).length!==0)return r}static toTextCommand(t){return t.children&&(t.children=t.children.map(ki.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return p(Qj,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(ki.toTextCommand)}static fromTextCommands(t){return t.map(ki.fromTextCommand)}}function Fy(n){const t=n.findCustom("toolbar-handler");t==null||t.disableTextToolbar(),t==null||t.hide(),setTimeout(()=>{t==null||t.enableTextToolbar()},300)}function Yj(n){n.undoManager.canUndo()&&Fy(n)}function Zj(n){n.undoManager.canRedo()&&Fy(n)}const Jj={"CtrlOrCmd+Z":Yj,"CtrlOrCmd+Shift+Z":Zj},tz={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},ez={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},nz={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};_.mergeLang({"zh-CN":tz,"en-US":ez,"ja-JP":nz});const rz={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},iz={embedProperties:{edit:"Edit",addComment:"Add annotation"}},oz={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":rz,"en-US":iz,"ja-JP":oz});const Ky=D("embed-block-properties");function ef(n,t){var e;for(const r of n.blockHooks){const i=(e=r.commands)==null?void 0:e.call(r,n,t);if(!!i&&i.group==="block-comment-actions")return i.executeCommand(n,t,i.commands[0]),!0}return!1}class dE{constructor(t,e,r){g(this,"group","hovering-toolbar");g(this,"_commands",[{id:"edit",name:_.t("embedProperties.edit"),icon:Dh},{id:"add-comment",name:_.t("embedProperties.addComment"),icon:Qs}]);this.editor=t,this.block=e,this.properties=r}get commands(){var i,o,s;if(this.editor.readonly)return[];let t=this._commands;const{enableComments:e=!0}=this.editor.options;e||(t=t.filter(l=>l.id!=="add-comment")),t.forEach(l=>{(l.id==="add-comment"||l.id==="edit")&&(l.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});let r=(i=this.properties)!=null&&i.presetIds?t.filter(l=>{var c,d;return(d=(c=this.properties)==null?void 0:c.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(o=this.properties)==null?void 0:o.extCommands)!=null&&s.length&&(r.length&&r.push({id:et(),type:"separator",name:""}),r.push(...this.properties.extCommands)),r.length<=3&&(r=r.filter(l=>l.id!=="separator")),r}executeCommand(t,e,r){var i,o;if(!((o=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&o.call(i,t,e,r))){if(r.id==="add-comment"){ef(t,e)||Ky.error("failed to add comment to block");return}Ky.error(`unknown command: ${JSON.stringify(r)}`)}}}function hE(n,t,e){return{blockCommands:{"hovering-toolbar":new dE(n,t,e)}}}class nf{constructor(t){g(this,"blockResizer");g(this,"handleResizing",(t,e)=>{var i,o;const r=t.getBlock();if(r){if(((o=(i=Zt(this.editor,r)).notify)==null?void 0:o.call(i,this.editor,"resize",{block:r,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(r).embedData,height:s};this.editor.updateEmbedData(r,d)}});g(this,"handleHoveringBlockChange",(t,e)=>{e&&Ie(e)&&Rt(e,"resizable")&&this.disableResizer(),t&&Ie(t)&&Rt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new Pu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}tryEnableResizer(t){this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}static get(t){return t.addCustom("EmbedBlockResizer",()=>new nf(t))}static register(t,e){return z(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new nf(t))}}var Vy=(n=>(n.Card="card",n.Preview="preview",n))(Vy||{});const sz=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="#5587F0">
693
+ </svg>`,Dit="",L0="reply-editor-editing",{t:cE}=_;class Ej{constructor(t,e,r,i){g(this,"root");g(this,"components");g(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});g(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,r=t.getDoc();t1(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{Rt(this.root,L0)||(z(this.root,L0),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!Rt(this.root,L0)||ot(this.root,L0)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,o=r.getDoc(),s=w0({editor:t,commentGroupId:e.groupId});i.localCreateComment(s,o),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{Rt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{ot(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=B("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=il(this.root,Jt.QuickReply,cE("comment.placeholder"));lo(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=B("div",["quick-reply-editor"],this.root),i=Yi(),o=new aE(this.mainEditor,t,i);o.editor.addListener("docChanged",this.handleDocChange),o.editor.addListener("focus",this.handleFocus),o.editor.input.addHandler(new uj(this.groupItem)),r.append(o.root);const s=B("div",["reply-editor-actions"],r),l=pr(Jt.QuickReplyCancel,cE("common.cancel"));lo(l,Jt.QuickReplyCancel);const c=pr(Jt.QuickReplyOk,cE("comment.send"),void 0,["primary","disabled"]);return lo(c,Jt.QuickReplyOk),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:o,replyEditorContainer:r,okButton:c}}}const ao=D("comment-group-item");class Aj extends Te.TypedEmitter{constructor(e,r,i,o){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>B("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=B("div",["comment-children-list-container"],this.root);return new gj({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});g(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));p(ao,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{ot(i,gy)});const r=e[e.length-1];z(r,gy)});g(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),r=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');p(ao,e,"switchUpButton not exist"),p(ao,r,"switchDownButton not exist"),ot(r,"disabled"),ot(e,"disabled"),this.root.previousElementSibling===null&&z(e,"disabled"),this.root.nextElementSibling===null&&z(r,"disabled")});g(this,"handleReadonlyChanged",e=>{e.readonly?z(this.root,"readonly"):ot(this.root,"readonly")});g(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=r,this.comment=i,this.groupList=o,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new Bs(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return Cy(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,o=new Ej(e,r,i,this);return this.root.append(o.root),o}createHeader(){const{comment:e}=this,r=B("div",["comment-item-head"],this.root),i=B("span",["item-head-quote"],r);i.innerText=e.abstract;const o=B("span",["item-head-switch"],r),s=il(o,Jt.SwitchUp,"up",pj),l=il(o,Jt.SwitchDown,"down",Cj);return lo(s,Jt.SwitchUp),lo(l,Jt.SwitchDown),r}createItem(){const e=B("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:o,groupList:s}=this,l=new yy({mainEditor:r,commentsProvider:i,comment:o,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(r=>r.comment.id===e):null}handleCreateComment(e){return p(ao,ll(e),"invalid comment, not a child comment"),p(ao,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){p(ao,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){ao.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(ao,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(ao,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const xj=D("arrange=items"),Ly=20;function Sy(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const r=n.scrollContainer.getBoundingClientRect(),i=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-r.top+i}function Iy(n,t){return Number.parseInt(t.root.style.top,10)}function Dy(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let o=i;o<t.length;o++){const s=t[o],l=s.comment,c=Sy(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),o===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else s.root.style.top=`${c}px`;continue}const d=t[o-1],h=Iy(n,d)+d.root.getBoundingClientRect().height;h>c?s.root.style.top=`${h+Ly}px`:s.root.style.top=`${c}px`}for(let o=i-1;o>=0;o--){const s=t[o],l=s.comment,c=Sy(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const d=s.root.getBoundingClientRect(),h=c+d.height,C=t[o+1];p(xj,C,"no next item");const E=Iy(n,C);E<h?s.root.style.top=`${E-d.height-Ly}px`:s.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const S0=D("comment-group-item-handler");class bj{constructor(t,e){g(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});g(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});g(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});g(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});g(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});g(this,"handleCommentItemReply",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:o}=r,s=i.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:et(),box:!0,created:Date.now(),text:o.displayName,iconUrl:o.avatarUrl,mentionId:o.userId};s.editor.insertBoxToBlock(l,0,c)});g(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});g(this,"handleCommentItemOk",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:o,getCommentEditor:s}=r,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(o,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let o=!1;if((c=i.blocks)!=null&&c.length||(o=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];o=!!h.text&&an(h.text)===0}if(o){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:s}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),s.show()});g(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e;t.getCommentEditor().edit(),r.hide()});g(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e,{comment:i}=t;this.commentsProvider.localDeleteComment(i.id),r.show()});g(this,"execute",(t,e,r,i)=>{const o=nj(t);if(!o||ij(o))return;const s=rj(o);switch(s){case Jt.SwitchUp:this.handleSwitchUp(i);break;case Jt.SwitchDown:this.handleSwitchDown(i);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,r);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,r);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,r);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;S0.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const I0=D("comment-group-list");class Bj extends tf{constructor(e,r,i){super(e,r,i,ns(e,r),{});g(this,"groupItemHandlers");g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const r=e.target.closest(".comment-group-item-root");if(!r)return;const i=ej(e.target),o=this.items.findIndex(s=>s.root===r);if(o!==-1){this.setActiveItem(o);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[o],i,o)}});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=By(this.editor);if(e.length>0){if(((r=this.activeItem)==null?void 0:r.comment.id)&&e.includes(this.activeItem.comment.id))return;const i=e[0],o=this.items.findIndex(s=>s.comment.groupId===i);this.setActiveItem(o),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});g(this,"handleEditorResize",()=>{this.updateItemsLayout()});g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"handleItemResize",()=>{this.updateItemsLayout()});g(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const r=document.elementFromPoint(e.clientX,e.clientY);if(!r||!(r instanceof HTMLElement)||!this.editor.scrollContainer.contains(r))return;const i=this.container.querySelector(".comment-group-item-root");if(!i)return;const o=Number.parseFloat(i.style.top),s=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(o)&&!Number.isNaN(s)&&o<s&&Dy(this.editor,this.items,null,Math.min(o+(0-e.deltaY)*3,s))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(I0,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Pe.default(()=>{const e=ns(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const o=e[i];if(!this.findGroupItem(o.groupId)){this.handleCreateComment(o,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const o=this.items[i];e.findIndex(s=>s.groupId===o.comment.groupId)===-1&&(this.deleteItem(o.comment.id),r=!0)}r&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(o=>o.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new bj(this,r)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){Dy(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,r){const i=new Aj(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{ot(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=ns(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}insertItem(e,r){const i=super.insertItem(e);return i?(r!=null&&r.active&&this.setActiveItem(this.items.indexOf(i)),this.updateItemsLayout(),i.addListener("resize",this.handleItemResize),i):null}setActiveItem(e,r){if(p(I0,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const i=this.container.querySelector(".comment-group-item-root.active");if(i&&ot(i,"active"),e!==-1){const o=this.items[e];z(o.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,r)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(r=>r.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,r){if(ll(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(I0,!i,"comment group item has already exists");const o={children:[],...e};p(I0,o.children,"not a comment group");const s=this.insertItem(o,{active:r});if(!!s&&r){const l=this.items.indexOf(s);this.setActiveItem(l),s.quickReply.hide(),setTimeout(()=>{s.edit()},300)}}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?(this.deleteItem(i.comment.id),this.updateItemsLayout()):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&(this.deleteItem(i.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}}const vj="comment-mini";D("comment-list");class Tj extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"groupsContainer");g(this,"list");g(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});g(this,"updateCommentCount",()=>{var r,i;const e=lj(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var o,s;const i=this.list.activeItem;Ty(this.editor,(s=(o=i==null?void 0:i.comment)==null?void 0:o.groupId)!=null?s:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=Rt(this.root,vj);(i=(r=this.commentOptions)==null?void 0:r.onUpdateLayout)==null||i.call(r,this.editor,{expand:e})});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-web-comment-root"],null),this.groupsContainer=B("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r),this.updateCommentCount()}onDeleteComment(e,r){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}createList(){return new Bj(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var r;if(ot(this.root,"hidden"),e){const i=this.list.findItemIndex(e);this.list.setActiveItem(i)}(r=this.commentOptions)==null||r.controller.showCommentList()}hide(){z(this.root,"hidden")}}class kj extends tf{constructor({editor:t,parent:e,commentsProvider:r,comments:i}){super(t,r,e,i,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:r}=this;return new wy(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const D0=D("mobile-comment-group-item"),Rj=20;class yj extends Te.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>B("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=new wy(r,i,o);return e.append(s.root),s});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=B("div",["mobile-comment-children-list-container"],e);return new kj({editor:r,commentsProvider:i,comments:o.children,parent:s})});g(this,"handleTouchEnd",()=>{var o;const{scroller:e}=this,{pullThreshold:r=Rj}=(o=this.editor.getComponentOptions("comment"))!=null?o:{};let i=null;if(e.y>e.minScrollY+r?(i=this.root.previousElementSibling,i||this.emit("onReachTop")):e.y<e.maxScrollY-r&&(i=this.root.nextElementSibling,i||this.emit("onReachBottom")),i){const s=i.id;this.emit("onSwitchGroup",s,py)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=B("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const o=B("div",["mobile-group-item"],this.root),s=B("div",["mobile-group-item-space"],null),l=B("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=B("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),o.append(s,l,c),this.scroller=new _x.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return Cy(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(D0,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){D0.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(D0,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(D0,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const uE=D("mobile-group-list");class wj extends tf{constructor(e,r,i,o){super(e,r,i,ns(e,r),{});g(this,"scroller");g(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});g(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const r=this.findItemIndex(e);let i=null;return r===0?i=this.items[r+1].root.id:i=this.items[r-1].root.id,super.deleteItem(e)?(this.scrollToGroup(i,py),!0):!1});g(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});g(this,"handleReachBottom",()=>{this.emit("onReachBottom")});g(this,"handleReachTop",()=>{this.emit("onReachTop")});g(this,"scrollToGroup",(e,r=0)=>{const i=this.findGroupItem(e);p(uE,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),Ty(this.editor,i.comment.groupId)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"updateComments",Pe.default(()=>{const e=ns(this.editor,this.commentsProvider);for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1);continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(o=>o.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new _x.default(o),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new yj(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=ns(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(ll(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const i=this.findItem(e.id);p(uE,!i,"comment group item has already exists");const o={children:[],...e};p(uE,o.children,"not a comment group"),this.insertItem(o),this.scroller.refresh()}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?this.deleteItem(i.comment.id):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&this.deleteItem(i.comment.id);return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const Lj=D("mobile-comment-list"),{t:_y}=_;class Sj extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"list");g(this,"mask");g(this,"pullInfoContainer");g(this,"handleRootClick",e=>{const r=e.target;p(Lj,r instanceof Element,"invalid target"),!(r.closest(".mobile-group-item-abstract")||r.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});g(this,"hidePullInfo",Pe.default(()=>{ot(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;ot(this.root,"hidden"),z(document.documentElement,"disabled-scroll"),(r=this.commentOptions)==null||r.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});g(this,"hide",()=>{z(this.root,"hidden"),ot(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mobile-comments-root"],null),this.mask=B("div",["mobile-comment-mask"],this.root);const i=B("div",["mobile-comment-groups-container"],this.root),o=B("div",["mobile-comment-groups-scroll-container"],i);this.list=new wj(this.editor,this.commentsProvider,o,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=B("div",["mobile-comment-pull-info-container"],this.root);return B("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=_y(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=r,z(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function My(n,t){const e=ns(n,t),r=new Map;for(const i of e){const o=Ey(n,i.groupId);if(!!o)if(r.has(o)){const s=r.get(o);oE(i).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=oE(i),l=new Set(s.map(c=>c.id));r.set(o,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,o])=>({blockId:i,...o}))}const Ij=D("mini-group-item");class Dj{constructor(t,e){g(this,"root");g(this,"blockId");g(this,"comment");g(this,"miniCommentItem");g(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=B("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new mj(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return Ey(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);p(Ij,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class _j extends tf{constructor(e,r,i){super(e,r,i,My(e,r),{});g(this,"fixListOps",Pe.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));g(this,"handleDocChanged",Pe.default(()=>{this.updateMiniCommentsGroup()},100));g(this,"updateMiniCommentsGroup",()=>{const e=My(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=r,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new Dj(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,r){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const Mj=D("mini-comments-list");class Uj extends Te.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=B("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new _j(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(Mj,i instanceof HTMLElement,"The target is not a valid html element");const o=i.closest(".mini-comment-item");o&&this.emit("onItemClick",o.id)});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){}show(){ot(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function Uy(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const r=t.block,i=Ee(n,r,t.start.offset,t.end.offset),o=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;P3(n,r,i,o,s)}function Oj(n,t,e){const r=ci(n).map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{ci(n,{simpleBlockOnly:!0}).forEach(c=>{!nt(n,c.block)||Uy(n,c,o)});const l=Yi();e.localCreateComment(o,l)}),o}class Nj{constructor(t,e){g(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,r){const i=t.selection.range;if(nt(t,e)&&!r.isCollapsed()&&i.isSimple()){const o=st(e),s=St(e),l=Dr(t,e);return[{id:"add-comment",name:_.t("comment.command"),blockId:o,blockType:s,blockKind:l,groupIndex:1e3,icon:Qs}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,r,i,o){if(r.id==="add-comment"){this.editorComments.showCommentList();const s=Oj(t,e,this.provider);return o["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class Oy{constructor(t,e){g(this,"commentList",null);g(this,"mobileCommentList",null);g(this,"miniCommentList");g(this,"showComment",(t,e)=>{var r,i;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((r=this.mobileCommentList)==null||r.show(e)),t==="web"&&((i=this.commentList)==null||i.show(e))});g(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});g(this,"handleCommentListClose",()=>{this.showComment("mini")});g(this,"handleOnSelectComment",()=>{this.showComment("web")});g(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new Nj(e,this)),t.blockHooks.push(new ZH(this.provider,this)),this.isMobile?(this.mobileCommentList=new Sj(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new Tj(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new Uj(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new JH)}get commentProvider(){return this.provider}get isMobile(){return ge.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const _it="",Pj={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u6DFB\u52A0\u6279\u6CE8\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},Fj={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotation or mention someone",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},Kj={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u8A8D",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0\u3059\u308B\u304B\u30E1\u30F3\u30D0\u30FC\u3092\u30E1\u30F3\u30B7\u30E7\u30F3",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":Pj,"en-US":Fj,"ja-JP":Kj});class Ny{renderText(t,e,r){const i=[],o={};return Object.entries(r).forEach(([s,l])=>{s.startsWith("comment-")&&(i.push("comment"),o[s]=l)}),{classes:i,attributes:o}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const o=["comment"],s={};return i.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:o,attributes:s}}updateBlock(t,e,r,i){const o=i.comments;ot(r,"comment"),Array.from(r.attributes).forEach(s=>{s.name.startsWith("comment-")&&r.removeAttribute(s.name)}),!(!o||o.length===0)&&(z(r,"comment"),o.forEach(s=>{r.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class Vj{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,o)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();g0(t,e,_.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function $j(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const s=new Set(i);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const o=r.text;if(!!o&&nt(n,t)){const s=Qg(o,`comment-${e.toLocaleLowerCase()}`,e);Rc.default(o,s)||n.setBlockText(t,s)}}const Hj=D("editor-comment");function jj(n){const t=n.getCustom("editor-comments");if(p(Hj,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Po(s);if(l.length>=2){const{containerId:c}=l[l.length-1],d=rt(li(n,c));if(d&&St(d)==="code"){rE(n,d,t.commentProvider);return}}rE(n,s,t.commentProvider);return}const e=ci(n,{simpleBlockOnly:!0}),r=e.map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?Uy(n,l,o):my(n,l.block,o)});const s=Yi();t.commentProvider.localCreateComment(o,s)})}const fE=D("text-styles");function zj(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([o])=>!!o.startsWith("style-"));return new Map(i)};if(n.length===0)return new Map;let e=t(n[0]);for(let r=1;r<n.length;r++){const i=t(n[r]);e=new Map(Array.from(e.entries()).filter(([o,s])=>i.get(o)===s))}return e}function Gj(n,t,e,r,i){p(fE,e.isSimple(),"invalid range");const{start:o,end:s}=e;p(fE,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(fE,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=ia(o.offset,s.offset-o.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=ia(o.offset,s.offset-o.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=ia(o.offset,s.offset-o.offset,c,r,void 0,{ignoreValue:!0}):c=Gc(o.offset,s.offset-o.offset,c,r,i),n.setBlockText(t,c),c}const al=D("text-commands");function Py(n){const t={id:"more",name:_.t("commands.more"),icon:rp,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[_.t("commands.bold"),ur("CtrlOrCmd+B"),I2],"style-italic":[_.t("commands.italic"),ur("CtrlOrCmd+I"),D2],"style-underline":[_.t("commands.underline"),ur("CtrlOrCmd+U"),_2],"style-strikethrough":[_.t("commands.strikethrough"),ur("CtrlOrCmd+D"),M2],"style-code":[_.t("commands.code"),void 0,U2]},r={"style-super":[_.t("commands.superscript"),void 0,N2],"style-sub":[_.t("commands.subscript"),void 0,O2]};if(an(n)===0){const l=Object.entries(e).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h}));return t.children=Object.entries(r).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h})),l.concat(t)}const i=zj(n);function o([l,[c,d,h]]){const C=i.get(l);return C!==void 0?{id:l,name:c,value:C,states:C===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:c,icon:h,desc:d}}const s=Object.entries(e).map(o);return t.children=Object.entries(r).map(o),s.concat(t)}function Wj(n,t){const e=st(t),r=St(t),i=Dr(n,t);return Py([]).map(o=>({blockId:e,blockType:r,blockKind:i,...o,groupIndex:500}))}function qj(n,t,e){p(al,e.isSimple(),"nor a simple range");const{start:r,end:i}=e;p(al,r.isSimple(),"is not a simple block position"),p(al,i.isSimple(),"is not a simple block position"),p(al,nt(n,t),"invalid block type, not a text kind block");const o=st(t);p(al,r.blockId===o&&i.blockId===o,"invalid range");const s=n.getBlockText(t);let l=[];r.offset===i.offset?r.offset!==0&&(l=qe(s,r.offset-1,1).middle):l=qe(s,r.offset,i.offset-r.offset).middle;const c=St(t),d=Dr(n,t);return Py(l).map((h,C)=>({blockId:o,blockType:c,blockKind:d,...h,groupIndex:500,order:C*100}))}function Xj(n,t,e,r,i,o){if(!nt(n,t))return!1;if(!r.startsWith("style-"))return al.warn(`unknown command: ${r}`),!1;const s=i==null?void 0:i.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return al.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const c=Gj(n,t,e,r,s);return o.result=c,!0}const Qj=D("text-command-provider");class ki{constructor(t){g(this,"id","TextCommandProvider");g(this,"emptyTextBlockAttributes",new Map);g(this,"colorItem");g(this,"updateButtonColor",t=>{const e=V3(this.editor,t,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(e)});g(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")F3(this.editor,t,e,this.setEmptyTextBlockColor);else{const r=["clearAll","clearColor","clearBackground"];K3(this.editor,r[e],this.setEmptyTextBlockColor)}});g(this,"getEmptyTextBlockColor",(t,e)=>{const r=this.getEmptyBlockTextAttributes(t,e);return Yg(r)});g(this,"setEmptyTextBlockColor",(t,e,r,i)=>{var s;const o=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};z5(o,r,i),this.emptyTextBlockAttributes.set(e,o)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new J_(t)),this.colorItem.addListener("onClick",this.handleChangeColor)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,r){if(!nt(t,e))return[];let i;ft(t,e)===0?i=this.getCommandsOnEmptyText(t,e).map(ki.toTextCommand):i=qj(t,e,r).map(ki.toTextCommand),this.updateButtonColor(r);const s={...this.colorItem,blockId:st(e),blockKind:Dr(t,e),blockType:St(e),groupIndex:500,order:350};return i.push(s),i}executeCommand(t,e,r,i,o,s){if(!nt(t,e))return!1;let l=o.value;l===void 0&&(l=!i.value);const c=ki.fromTextCommandId(i.id);if(c.startsWith("style-")){if(c==="style-font")return this.handleChangeColor(o.type,l),!0;if(ft(t,e)===0)return this.executeCommandOnEmptyText(e,i,{value:l})}return Xj(t,e,r,c,{value:l},s)}executeCommandOnEmptyText(t,e,r){let i=this.emptyTextBlockAttributes.get(st(t));i||(i={},this.emptyTextBlockAttributes.set(st(t),i));const o=ki.fromTextCommandId(e.id),s=r.value;return s==null||s===!1?(delete i[o],!0):(i[o]=r.value,!0)}getCommandsOnEmptyText(t,e){const r=Wj(t,e);return this.setCommandsStates(r,e)}setCommandsStates(t,e){var o;const r=st(e),i=(o=this.emptyTextBlockAttributes.get(r))!=null?o:{};return t.map(s=>{const l=i[s.id],c=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:c}})}getEmptyBlockTextAttributes(t,e){var i;const r=gt.default((i=this.emptyTextBlockAttributes.get(e))!=null?i:{});if(Array.from(Object.entries(r)).forEach(([o,s])=>{s||delete r[o]}),Object.keys(r).length!==0)return r}static toTextCommand(t){return t.children&&(t.children=t.children.map(ki.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return p(Qj,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(ki.toTextCommand)}static fromTextCommands(t){return t.map(ki.fromTextCommand)}}function Fy(n){const t=n.findCustom("toolbar-handler");t==null||t.disableTextToolbar(),t==null||t.hide(),setTimeout(()=>{t==null||t.enableTextToolbar()},300)}function Yj(n){n.undoManager.canUndo()&&Fy(n)}function Zj(n){n.undoManager.canRedo()&&Fy(n)}const Jj={"CtrlOrCmd+Z":Yj,"CtrlOrCmd+Shift+Z":Zj},tz={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},ez={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},nz={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};_.mergeLang({"zh-CN":tz,"en-US":ez,"ja-JP":nz});const rz={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},iz={embedProperties:{edit:"Edit",addComment:"Add annotation"}},oz={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":rz,"en-US":iz,"ja-JP":oz});const Ky=D("embed-block-properties");function ef(n,t){var e;for(const r of n.blockHooks){const i=(e=r.commands)==null?void 0:e.call(r,n,t);if(!!i&&i.group==="block-comment-actions")return i.executeCommand(n,t,i.commands[0]),!0}return!1}class dE{constructor(t,e,r){g(this,"group","hovering-toolbar");g(this,"_commands",[{id:"edit",name:_.t("embedProperties.edit"),icon:Dh},{id:"add-comment",name:_.t("embedProperties.addComment"),icon:Qs}]);this.editor=t,this.block=e,this.properties=r}get commands(){var i,o,s;if(this.editor.readonly)return[];let t=this._commands;const{enableComments:e=!0}=this.editor.options;e||(t=t.filter(l=>l.id!=="add-comment")),t.forEach(l=>{(l.id==="add-comment"||l.id==="edit")&&(l.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});let r=(i=this.properties)!=null&&i.presetIds?t.filter(l=>{var c,d;return(d=(c=this.properties)==null?void 0:c.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(o=this.properties)==null?void 0:o.extCommands)!=null&&s.length&&(r.length&&r.push({id:et(),type:"separator",name:""}),r.push(...this.properties.extCommands)),r.length<=3&&(r=r.filter(l=>l.id!=="separator")),r}executeCommand(t,e,r){var i,o;if(!((o=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&o.call(i,t,e,r))){if(r.id==="add-comment"){ef(t,e)||Ky.error("failed to add comment to block");return}Ky.error(`unknown command: ${JSON.stringify(r)}`)}}}function hE(n,t,e){return{blockCommands:{"hovering-toolbar":new dE(n,t,e)}}}class nf{constructor(t){g(this,"blockResizer");g(this,"handleResizing",(t,e)=>{var i,o;const r=t.getBlock();if(r){if(((o=(i=Zt(this.editor,r)).notify)==null?void 0:o.call(i,this.editor,"resize",{block:r,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(r).embedData,height:s};this.editor.updateEmbedData(r,d)}});g(this,"handleHoveringBlockChange",(t,e)=>{e&&Ie(e)&&Rt(e,"resizable")&&this.disableResizer(),t&&Ie(t)&&Rt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new Pu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}tryEnableResizer(t){this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}static get(t){return t.addCustom("EmbedBlockResizer",()=>new nf(t))}static register(t,e){return z(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new nf(t))}}var Vy=(n=>(n.Card="card",n.Preview="preview",n))(Vy||{});const sz=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="#5587F0">
694
694
  <g clip-path="url(#clip0)">
695
695
  <path d="M6.01 10.4886C5.85 10.4886 5.7 10.4286 5.58 10.3086L3.98 8.71859C3.35 8.07859 3 7.23859 3 6.34859C3 5.45859 3.35 4.60859 3.98 3.97859C5.29 2.66859 7.41 2.66859 8.72 3.97859L10.31 5.56859C10.55 5.80859 10.55 6.18859 10.31 6.42859C10.07 6.66859 9.69 6.66859 9.45 6.42859L7.86 4.83859C7.03 4.00859 5.68 4.00859 4.85 4.83859C4.45 5.23859 4.23 5.77859 4.23 6.34859C4.23 6.91859 4.45 7.44859 4.85 7.85859L6.44 9.44859C6.68 9.68859 6.68 10.0686 6.44 10.3086C6.32 10.4286 6.16 10.4886 6.01 10.4886ZM11.65 14.9986C10.79 14.9986 9.93 14.6686 9.28 14.0186L7.4 12.1386C7.16 11.8986 7.16 11.5186 7.4 11.2786C7.64 11.0386 8.02 11.0386 8.26 11.2786L10.14 13.1586C10.97 13.9886 12.32 13.9886 13.15 13.1586C13.55 12.7586 13.77 12.2186 13.77 11.6486C13.77 11.0786 13.55 10.5486 13.15 10.1386L11.28 8.25859C11.04 8.01859 11.04 7.63859 11.28 7.39859C11.52 7.15859 11.9 7.15859 12.14 7.39859L14.02 9.27859C14.65 9.90859 15 10.7486 15 11.6486C15 12.5386 14.65 13.3886 14.02 14.0186C13.37 14.6686 12.51 14.9986 11.65 14.9986Z" fill="currentColor"/>
696
696
  <path d="M10.88 10.8604C10.67 11.0704 10.32 11.0704 10.1 10.8604L7.64004 8.40039C7.43004 8.19039 7.43004 7.84039 7.64004 7.62039C7.85004 7.41039 8.20004 7.41039 8.42004 7.62039L10.88 10.0804C11.1 10.3004 11.1 10.6404 10.88 10.8604Z" fill="currentColor"/>