@ones-editor/editor 1.1.0 → 1.1.1
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
|
@@ -624,7 +624,7 @@ ${l}`:r==="markdown"?`\`\`\`${i.language}
|
|
|
624
624
|
${s}
|
|
625
625
|
\`\`\`
|
|
626
626
|
${l}`:`<p><pre><code>${Id(s)}</code></pre></p>
|
|
627
|
-
<p>${Id(l)}</p>`}const cE={blockType:"code",blockKind:"complex",createBlockContent:zH,getBlockTextLength:GH,getRangeFromPoint:WH,moveCaret:qH,getCaretRect:XH,updateSelection:QH,clearSelection:YH,getChildContainers:JH,getNextContainer:ZH,getSelectedContainers:tj,convertFrom:gH,handleBlockElementUpdated:ej,getOptions:rj,getBlockProperties:ij,convertTo:oj},uE={...Un,blockType:"code-line"};class sj{constructor(t){g(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!Yu(this.editor,e))return;const r=e,i=t.range.focus.offset,o=l3(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 lj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!Yu(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{ui(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function aj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!Yu(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{ui(n).forEach(i=>{const o=ue(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 cj(n){const t=n.getFocusedBlock(),e=rt(t);if(Yt(e))return;const r=nt(e);if(!r||St(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!V5(e,i))return Rh(n,e),!0}const uj={Tab:lj,"Shift+Tab":aj,"CtrlOrCmd+A":cj},Ju=I("code-text-decorate");class O0{decorateText(t,e,r){if(p(Ju,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=ue(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(R=>{if(!R)return ea.default.languages.plain;const L=R.replace(/\s/g,"").toLocaleLowerCase();return ea.default.languages[L]||ea.default.languages.plain})(c.language),C=ea.default.tokenize(l,h),E=(R,L)=>{if(p(Ju,R,"no token"),typeof R=="string")return[{insert:R,attributes:gt.default(L)}];p(Ju,R instanceof ea.default.Token,"invalid token type");const U=R.content,M=gt.default(L);return M[`style-code-${R.type}`]=!0,typeof U=="string"?[{insert:U,attributes:M}]:Array.isArray(U)?U.map(q=>E(q,M)).flat():(p(Ju,U instanceof ea.default.Token,"invalid token"),E(U,M))},v=C.map(R=>E(R,{})).flat();return p(Ju,fn(v)===fn(s),"failed to highlight code, text length mismatch"),{text:v}}}const fj={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"}},dj={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},hj={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":fj,"en-US":dj,"ja-JP":hj});function mj(n,t,e,r){const i=n.getBlockByIndex(t,e);if(dt(n,i)!==r)return!1;const o=ue(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,Te(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const gj={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"}}},pj={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 N0(n,t,e,r,i){const o=n.getContainerById(t);if(!Yt(o)){const s=nt(o);if(s&&bi(s))return!0}return!1}function ER(n,t,e,r,i){if(N0(n,t))return!1;if(i==="enter"&&mj(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=ue(Dn(n.getBlockText(o),r).left),l=i==="enter"?gj:pj;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var v;const h=Hd(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const x=n.insertBlock(t,e,C,Te(n,E!=null?E:C.id,0));return n.deleteBlock(o),(v=h.onConverted)==null||v.call(h,n,x),{newBlock:x,focusBlockId:E}})}return!1}function Cj(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},Te(n,i,0))}),!0)}const Ej={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function Aj(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=Ej[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},Te(n,i,0))}),!0}function xj(n,t,e,r){return!!(Aj(n,t,e,r)||Cj(n,t,e,r))}const bj=I("match-text-style");function vj(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 Bj={"*":{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 Tj(n,t,e,r){var E,x;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r),l=I1(s),c=fn(s)-l.length,d=Object.entries(Bj);for(const[v,R]of d){const L=vj(l,v);if(L===-1)continue;const U=c+L,M=r,F=v.length,G=ue(Qe(o,U+F,M-U-F*2).middle);if(R.type==="style"){const q={};R.styles.forEach(at=>{q[at]=!0});const it=Zs(G,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,U,M-U),n.insertTextToBlock(i,U,it)})}else if(R.type==="box")try{const q=(x=(E=n.editorBoxes.getBoxClass(R.boxType)).convertFrom)==null?void 0:x.call(E,n,G);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,U,M-U),n.insertBoxToBlock(i,U,q)})}catch(q){bj.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const v=C.index,R=C[1],L=C[2],U=v,M=r,G={...pa(o,U),link:L};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,U,M-U),n.insertTextToBlock(i,U,Zs(R,G))}),!0}return!1}class P0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(N0(t,e))return!1;if(xj(t,e,r,i)||Tj(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(et(t,t.getBlockByIndex(i,o))){if(oi(e,"Enter")){if(ER(t,i,o,s,"enter"))return!0}else if(oi(e,"Space")&&ER(t,i,o,s,"space"))return!0}return!1}}const yj={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};D.mergeLang(yj);function Zu(n,t){const e=jo(n,t);return!!(et(n,t)&&e.text&&fn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function AR(n,t){var r;Ot(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function tf(n,t,e){var i;if(AR(n,t),!Zu(n,t))return;const r=Ot(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=re(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function kj(n){const t=n.getAttribute("data-style-heading");return t?D.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?D.t("placeholder.quote"):null}function Rj(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?D.t("placeholder.list"):D.t("placeholder.mention"):null}function xR(n){switch(St(n)){case"text":return kj(n);case"list":return Rj(n);default:return null}}function wj(n){if(fr(n))return!1;const t=nt(rt(n));return t?St(t)==="code":!1}function Sj(n){return!fr(n)}function Lj(n,t){var h,C;const e=n.selection.focusedBlock,r=St(e),i=t.contentPlaceholder||D.t("placeholder.default");let o=i;if(r&&Jc(n,r)&&e){if(!n.isBlockWritable(e)||wj(e))return;Sj(e)&&(o=D.t("placeholder.common.contentInTable")),o=(h=xR(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:Gt(s);if(!l)return;const c=Gt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&Zu(n,l)){tf(n,l,(C=xR(l))!=null?C:i);return}const d=n.getFocusedBlock();!Zu(n,d)||d===s&&!t.hideTitle||tf(n,d,o)}function Ij(n,t){var i,o;const e=n.getFirstBlock(),r=Ot(e);Zu(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:D.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function Dj(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 _j(n,t){Dj(n),n.selection.range.isCollapsed()&&(t.hideTitle||Ij(n,t),Lj(n,t))}const ect="";function Mj(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const bR=I("enforce-title");class fE{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=ji(t.rootContainer,1),dt(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ft(t.rootContainer));p(bR,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=hi("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ft(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(bR,o.text,"invalid text block");const s=t.getBlockById(o.id);if(Mj(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=hi(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ft(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=Te(t,c.id,dt(t,C))),bh(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ft(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)||_j(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}function Gr(n){return St(n)==="embed"&&We(n)==="image"}async function vR(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function Uj(n){const t=await la(n);return vR(t)}function os(n){return typeof n=="number"}const Oj=I("image-data"),ef=1e3,BR=400,Nj=10;function tc(n){return n.src.startsWith("empty:")||!n.src}function Pj(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function TR(n){return`${vd.default(n)}_width`}function yR(n){return`${vd.default(n)}_height`}function kR(n){return`${n}_flex`}function RR(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function ec(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?ef: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"?ef:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function nc(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=TR(i),l=yR(i),c=kR(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),{src:i,width:d!=null?d:"auto",height:h!=null?h:"auto",flex:C,virtualSize:!d||!h}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),ec(e),e}function Wr(n){const t=n.embedData;return nc(n.embedData).length>1?100:t.widthPercent}function Fj(n,t,e,r){const i=nc(t.embedData);if(i.length>1||r)return"100%";const o=Wr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=RR(e);return`${Math.min(s*o/100,l)}px`}return os(i[0].width)?`${i[0].width}px`:"auto"}function hn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{const s=i.src||`empty:${o}`,l=TR(s);l&&os(i.width)&&(r[l]=i.width);const c=yR(s);c&&os(i.height)&&(r[c]=i.height),p(Oj,i.flex,"no image flex");const d=kR(o);r[d]=i.flex}),r}function Kj(n,t,e,r){const i=nc(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${BR}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=Wr(t);if(!s){if(i.length!==1||os(i[0].width))return"";const C=i[0].height;return C==="auto"?"auto":`${C}px`}let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,RR(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?ef:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*Nj;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"?ef:h.width,x=C/E*h.height;d=Math.max(x,d)}return`${d}px`}function Vj(n){return n.reduce((e,r)=>e+r.flex,0)}function $j(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function dE(n){return re(n).querySelector(".block-resizer")}function Hj(n){const t=dE(n);t&&ot(t,"active")}function wR(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function jj(n,t,e,r){const i=dE(n);if(i)return z(i,"active"),wR(n,t,i),i;const o=re(n),s=B("div",["block-resizer"],o);return wR(n,t,s),e.resize.forEach(l=>{$j(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function hE(n,t){const e=dE(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 nct="",zj=I("block-resizer");class nf extends Re.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,Gc(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,x=new DOMRect(c,l,C,E);this.emit("resizing",this,x);const v=this.getResizableElement();v&&hE(this.block,v)});g(this,"handleMouseUp",e=>{if(e.button!==0)return;Gc(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||hE(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||(Hj(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&&hE(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Ot(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(zj,ee(this.block,e),"not a block child element"),jj(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 Gj=I("image-dom");function SR(n){return n.querySelector(".uploading-progress-mask")}function Wj(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 qj(n){const e=Wj(n).querySelector(".uploading-progress-bar-value");return p(Gj,e,"no progress value"),e}function LR(n,t){const e=qj(n);e.style.width=`${t}%`}function Xj(n){var t;(t=SR(n))==null||t.remove()}function rf(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||rt(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=Fj(n,t,o,s),c=Kj(n,t,o,s),d=Ot(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function Qj(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function Yj(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=Qj(t.headers).toLocaleLowerCase();let i="";if(r){const s=bg.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function ss(n,t){const e=typeof t=="string"?t:st(t);return n.getCustom(`image-${e}`)}function F0(n,t){if(!t||!(t instanceof Node))return null;const e=nt(t);return e?ss(n,e):null}function Bi(n){return Array.from(n.querySelectorAll(".image-container"))}const mE=I("table-resize-drag-drop");class Jj{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=ss(this.editor,o).getImages(),c=this.data.splitterIndex;p(mE,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Bi(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;ss(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),c=gt.default(l.getImages()),d=this.data.splitterIndex;p(mE,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const R=[...this.initWidths];R[d]+=E,R[d+1]-=E;const L=Bi(s);p(mE,L.length===c.length,"invalid image data");const U=R.reduce((G,q)=>G+q,0);for(let G=0;G<c.length;G++){const q=R[G]/U;c[G].flex=q,L[G].style.flexGrow=`${q}`}const M=gt.default(this.editor.getBlockData(s)),F=hn(c,Wr(M));M.embedData=F,rf(this.editor,M,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),d=Bi(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function IR(n){var t;return!n||!(n instanceof HTMLElement)?null:Rt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function Zj(n,t){var s;const e=IR(t.target);if(!e)return;const r=nt(e);if(!r)return;ss(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};Sg(new Jj(n,e,o,t))}function tz(n,t){t.preventDefault(),t.stopPropagation();const e=IR(t.target);if(!e)return;const r=nt(e);!r||ss(n,r).resetFlex()}function ez(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",Zj),n.domEvents.addEventListener(i,"dblclick",tz)}const nz=I("image-item");function DR(n){return!n||!(n instanceof Node)?null:nt(n)}function _R(n){const t=DR(n);return t?Bi(t):[]}function gE(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 of(n){const t=gE(n);return t?_R(n).indexOf(t):-1}async function rz(n,t){const e=F0(n,t.target);if(!e)return;const r=of(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(tc(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||!Pj(o)||o.downloading))return;o.downloading=!0;const s=await Yj(o.src);s?e.replaceImage(r,s):nz.warn(`failed to download image: ${o.src}`)}function iz(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=Hp;const l=B("div",["error-message"],o);i?(l.innerHTML=D.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=D.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&az(c,d.target)}))}function pE(n,t){setTimeout(()=>{if(ee(n.rootContainer,t)){const e=n.getBlockData(t);rf(n,e,null,null)}})}function oz(n,t){const e=F0(n,t.target);if(!e)return;const r=of(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=gE(t.target);if(!o)return;z(o,"error","error-load");const s=nt(o);s&&pE(n,s),o.innerHTML="",iz(n,o,i)}function sz(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=Hp;const s=B("div",["error-message"],i);s.innerHTML=D.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=F0(l,c.target),h=of(c.target);!d||h===-1||d.replaceImage(h,e)})}function MR(n,t,e,r,i){const o=Bi(t)[e];!o||(z(o,"error","error-upload"),pE(n,t),o.innerHTML="",sz(n,o,i))}function UR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),tc(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=v2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",rz),n.domEvents.addEventListener(c,"error",oz),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=$p,d.setAttribute(`data-editor-tooltip-${n.clientId}`,D.t("image.load.remote.tooltip"))}return l}function lz(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&ez(n,t,o,l-1),UR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function OR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=UR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),pE(n,t)}function sf(n,t){return Bi(n)[t]}function az(n,t){const e=DR(t);if(!e)return;const r=of(t);if(r===-1)return;const i=F0(n,t);if(!i)return;const o=i.getImages()[r];OR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function NR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function PR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=Qc(t.name);if(r&&!r.includes(o)){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function FR(n){return n.startsWith("image/")}const KR=I("image-object");class Le{constructor(t,e){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=of(e.target);if(r===-1)return;const i=this.images[r];tc(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||rt(e)===t&&rf(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 i=r.querySelector(".images");i.style.height="";const s=this.editor.rootContainer.getBoundingClientRect().width,l=r.getBoundingClientRect();let c=e.width>l.width?l.width:e.width;c<50&&(c=50);const d=c*100/s;this.blockData.embedData.widthPercent=d,rf(this.editor,this.blockData,r,null)});g(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=hn(this.images,Wr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});g(this,"fixImageSizes",Ke.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=hn(this.images,Wr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new nf(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=nc(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=lz(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),_r(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Is(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),rf(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 Wr(this.blockData)}isEmpty(){return this.images.length===1&&tc(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=sf(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=sf(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=sf(e,t);if(Rt(r,"error"))return;const i=NR(this.editor),o=await ca(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=sf(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];tc(r)||(os(r.width)&&!os(r.height)?r.height=r.width/e.naturalWidth*e.naturalHeight:os(r.height)&&!os(r.width)?r.width=r.height/e.naturalHeight*e.naturalWidth:(r.width=e.naturalWidth,r.height=e.naturalHeight),r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=gt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,ec(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=hn(r,Wr(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 la(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await vR(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,ec(this.images);const h=hn(this.images,Wr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};OR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return MR(this.editor,r,t,o,e),!1}const i=sf(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=hn(this.images,Wr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){KR.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),Xj(i),MR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(KR,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=hn(this.images,Wr(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,ec(e);const r=hn(e,Wr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=nc(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new Le(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=st(e),t.getCustom(`image-${r}`)}}const rct="",ict="";function K0(n){const t=re(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function CE(n,t,e){const r=K0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const VR=40,cz=20;class uz{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=nt(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<VR&&(i+=VR);let l=document.elementFromPoint(i,o);if(l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}if(o-=cz,l=document.elementFromPoint(i,o),l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}return null}destroy(){}}class fz extends R0{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 dz(n,t,e){const r=Wg(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 EE(n,t,e={withPlainText:!1}){const r=XC(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function hz(n,t,e,r=!1){var h,C,E;const i=rt(t);let o=t;if(o&&Kt(o)&&IC(o)){if(!r){const x=nK(o);o=(h=Gt(x))!=null?h:x}x0.closeMindmap(n,t)}let l=bt(o);ce(n,o)||r||(l+=1);const c=ft(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 mz(n,t){const e=Lr(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class $R{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=zC();this.createItem("text",Ma,e,mz(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",Qp,e,c),this.createItem("ordered-list",Yp,e,d),this.createItem("check-list",qp,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"&&y0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&y0(t,this.block,d)}if(o==="blockquote"&&$C(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");Tk(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&jC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});g(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:D.t("commands.text")},blockquote:{title:D.t("commands.quote")},"align-left":{title:D.t("commands.alignLeft")},"align-center":{title:D.t("commands.alignCenter")},"align-right":{title:D.t("commands.alignRight")},"unordered-list":{title:D.t("commands.unordered")},"ordered-list":{title:D.t("commands.ordered")},"check-list":{title:D.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:D.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",Xp,i,!!c)}const s=o.align||"left";return this.createItem("align-left",_a,i,s==="left"),this.createItem("align-center",t0,i,s==="center"),this.createItem("align-right",Zh,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=Ds(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}`,Ge(d))}}function HR(){return{source:"separator",type:"separator",id:`section-${Z()}`,name:""}}const jR={copy:P2,cut:F2,delete:K2,"lock-block":V2,"unlock-block":$2,comment:il},gz=["image","video"];function pz(n,t,e){const r=[],i=et(n,t),o=ge(t)&&gz.includes(We(t)),s=o&&(We(t)!=="image"||We(t)==="image"&&Bi(t).length===1);if(i?r.push(new $R(n,t,e)):o&&s&&r.push(new $R(n,t,{...e,fromEmbed:!0})),!ce(n,t)||LC(t)){(i||o&&s)&&r.push(HR());const l=dz(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in jR&&(c.icon=jR[c.id])}),r.push(...l)}return ce(n,t)&&!LC(t)?r.push(...EE(n,"insert-block")):r.push(HR(),{id:"insert-block-before",icon:H2,name:D.t("blockMenu.command.insertAbove"),children:EE(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:j2,name:D.t("blockMenu.command.insertAfter"),children:EE(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function Cz(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;Vv(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&hz(n,t,e,e.source==="insert-block-before")}const Ez=I("exclusive-block");function AE(n,t,e,r){var l;z(t,"block-exclusive");const i=Qt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",D.t("exclusive.tips",{editor:r,embedType:s||D.t("exclusive.fallbackAbstract")}))}function zR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function Az(n,t,e,r,i){Ez.debug(`block ${st(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?AE(n,t,r,i):zR(t)}function lf(n){return n.classList.contains("block-exclusive")}function GR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&Az(n,r,t.exclusive,t.userId,t.displayName)})}class ls{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};GR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;GR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>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 ls(t))}static register(t){return this.get(t)}}function xE(n,t){ls.get(n).exclusiveBlock(t)}function bE(n,t){ls.get(n).unexclusiveBlock(t)}class WR{writable(t,e){if(Array.isArray(e)){for(const r of e)if(lf(r))return!1;return}if(lf(e))return!1}create(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s&&AE(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s?AE(t,i,s.userId,s.displayName):zR(i)}}const oct="",xz={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},bz={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},vz={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};D.mergeLang({"zh-CN":xz,"en-US":bz,"ja-JP":vz});function af(n,t){return n.getBlockData(t).lock}function V0(n,t){return!!af(n,t)}function cf(n,t){const e=af(n,t);return e?e.userId===n.doc.getUser().userId:!1}function vE(n,t){const e=af(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function Bz(n,t){if(n.readonly||!n.isBlockWritable(t)||V0(n,t)&&!cf(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 Tz(n,t){if(!cf(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const yz=10,kz=80,Rz=50;class BE{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"?Bz(t,o):i.type==="unlock"&&Tz(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))&&(et(t,i)||St(i)==="code")&&t.insertTextBlock("",ft(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(vE(t,i))return!1;if(fr(i))return;let o=Vs(i);for(;o;){if(vE(t,o))return!1;o=Vs(o)}}}commands(t,e){const r=V0(t,e),i=cf(t,e),o=lf(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=D.t("locker.unlock"),s.type="unlock";else{const c=af(t,e);let d=(c==null?void 0:c.displayName)||"";const h=D.getCurrentLang()==="ja-JP",C=sv(d,yz,h?Rz:kz);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=D.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=D.t("locker.lock"),l.states=["disabled"]):l.name=D.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const sct="",wz={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},Sz={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},Lz={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":wz,"en-US":Sz,"ja-JP":Lz});class $0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const Iz=I("standard-block-actions");class Dz{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"&&Lh(t,o),r.id==="cut"&&(Lh(t,o),t.deleteBlock(o))}catch(o){Iz.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=V0(t,e),i=r&&cf(t,e),o=st(e),s=U0(),l=lf(e),c={id:"copy",name:D.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:Ge("CtrlOrCmd+C"),operation:D.t("copyCutProperty.copy")})},d={id:"cut",name:D.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:Ge("CtrlOrCmd+X"),operation:D.t("copyCutProperty.cut")})},h={id:"delete",name:D.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const qR=I("block-menu");class _z{constructor(t){g(this,"menu");g(this,"currentBlock",null);g(this,"commandBlock",null);g(this,"handleShow",()=>{p(qR,this.currentBlock,"no target block before show block menu");const t=pz(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});g(this,"handleClose",()=>{rC(this.editor)&&this.editor.focus()});g(this,"handleItemClick",(t,e)=>{p(qR,this.commandBlock,"no command block before show block menu"),Cz(this.editor,this.commandBlock,e),e.element||this.close()});g(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new Yo([],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 Dz)}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 Mz=1e3;async function Uz(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=Mz?"":(await pb.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const Oz=I("drag-preview-image");class Nz{constructor(t){g(this,"startPosition",null);g(this,"dragContainer",null);g(this,"handleDragStart",async(t,e)=>{const r=t.target;p(Oz,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=q2;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),x=this.editor.rootContainer.getBoundingClientRect(),v=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(x.width/2,v.width)}px`,this.dragContainer=s;const L=await Uz(this.editor,e);L?l.src=L:z(s,"drag-placeholder"),kg(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 XR="drag-preview-element";function Pz(n){if(Rt(n,XR))return n;const t=n.querySelector(`.${XR}`);return t||(ge(n)?Ot(n):n)}const H0=I("block-menu-drag-handler");function TE(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 Fz{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(H0,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=un(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Nd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(H0,r,"no dragged block"),(l=(s=Qt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=TE(t,"dragstart");jz(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=Pz(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(H0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=TE(t,"dragover");this.editor.contentElement.dispatchEvent(o)});g(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(H0,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=TE(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new Nz(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class uf{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 uf(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class QR{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=$d(t);zi(o)||(this.updateButton(o),CE(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(()=>{uf.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=>{tf(this.editor,t,D.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=ce(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new fz(t),this.blockMenu=new _z(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new Fz(this.editor,this);const e=Be.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new uz),uf.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}`,D.t("blockMenu.button.tips")),t.innerHTML=Jp,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,D.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=Jp,this.buttonElement.setAttribute(e,D.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),ce(this.editor,t)&&!(Kt(t)&&LC(t))?this.setButtonType("insert"):this.setButtonType("move")}}const Kz={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
627
|
+
<p>${Id(l)}</p>`}const cE={blockType:"code",blockKind:"complex",createBlockContent:zH,getBlockTextLength:GH,getRangeFromPoint:WH,moveCaret:qH,getCaretRect:XH,updateSelection:QH,clearSelection:YH,getChildContainers:JH,getNextContainer:ZH,getSelectedContainers:tj,convertFrom:gH,handleBlockElementUpdated:ej,getOptions:rj,getBlockProperties:ij,convertTo:oj},uE={...Un,blockType:"code-line"};class sj{constructor(t){g(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!Yu(this.editor,e))return;const r=e,i=t.range.focus.offset,o=l3(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 lj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!Yu(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{ui(n).forEach(r=>{n.insertTextToBlock(r.block,0," ")})}),!0}}function aj(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!Yu(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{ui(n).forEach(i=>{const o=ue(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 cj(n){const t=n.getFocusedBlock(),e=rt(t);if(Yt(e))return;const r=nt(e);if(!r||St(r)!=="code")return;const i=n.selection.range;if(!!i.isSimple()&&!V5(e,i))return Rh(n,e),!0}const uj={Tab:lj,"Shift+Tab":aj,"CtrlOrCmd+A":cj},Ju=I("code-text-decorate");class O0{decorateText(t,e,r){if(p(Ju,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=ue(s),c=t.doc.getBlockData(i.containerId,i.blockIndex),h=(R=>{if(!R)return ea.default.languages.plain;const L=R.replace(/\s/g,"").toLocaleLowerCase();return ea.default.languages[L]||ea.default.languages.plain})(c.language),C=ea.default.tokenize(l,h),E=(R,L)=>{if(p(Ju,R,"no token"),typeof R=="string")return[{insert:R,attributes:gt.default(L)}];p(Ju,R instanceof ea.default.Token,"invalid token type");const U=R.content,M=gt.default(L);return M[`style-code-${R.type}`]=!0,typeof U=="string"?[{insert:U,attributes:M}]:Array.isArray(U)?U.filter(q=>q.length).map(q=>E(q,M)).flat():(p(Ju,U instanceof ea.default.Token,"invalid token"),E(U,M))},v=C.map(R=>E(R,{})).flat();return p(Ju,fn(v)===fn(s),"failed to highlight code, text length mismatch"),{text:v}}}const fj={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"}},dj={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},hj={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":fj,"en-US":dj,"ja-JP":hj});function mj(n,t,e,r){const i=n.getBlockByIndex(t,e);if(dt(n,i)!==r)return!1;const o=ue(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,Te(n,d!=null?d:c.id,0));n.deleteBlock(i),(C=l.onConverted)==null||C.call(l,n,h)}),!0):!1}const gj={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"}}},pj={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 N0(n,t,e,r,i){const o=n.getContainerById(t);if(!Yt(o)){const s=nt(o);if(s&&bi(s))return!0}return!1}function ER(n,t,e,r,i){if(N0(n,t))return!1;if(i==="enter"&&mj(n,t,e,r))return!0;const o=n.getBlockByIndex(t,e),s=ue(Dn(n.getBlockText(o),r).left),l=i==="enter"?gj:pj;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var v;const h=Hd(n,o,c.blockType,{offset:r,data:c.data});if(!h)return null;const{blockData:C,focusBlockId:E}=h;if(!C)return null;const x=n.insertBlock(t,e,C,Te(n,E!=null?E:C.id,0));return n.deleteBlock(o),(v=h.onConverted)==null||v.call(h,n,x),{newBlock:x,focusBlockId:E}})}return!1}function Cj(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},Te(n,i,0))}),!0)}const Ej={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function Aj(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockString(i,{boxReplacement:" "}).substring(0,r);let s=Ej[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},Te(n,i,0))}),!0}function xj(n,t,e,r){return!!(Aj(n,t,e,r)||Cj(n,t,e,r))}const bj=I("match-text-style");function vj(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 Bj={"*":{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 Tj(n,t,e,r){var E,x;const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r),l=I1(s),c=fn(s)-l.length,d=Object.entries(Bj);for(const[v,R]of d){const L=vj(l,v);if(L===-1)continue;const U=c+L,M=r,F=v.length,G=ue(Qe(o,U+F,M-U-F*2).middle);if(R.type==="style"){const q={};R.styles.forEach(at=>{q[at]=!0});const it=Zs(G,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,U,M-U),n.insertTextToBlock(i,U,it)})}else if(R.type==="box")try{const q=(x=(E=n.editorBoxes.getBoxClass(R.boxType)).convertFrom)==null?void 0:x.call(E,n,G);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,U,M-U),n.insertBoxToBlock(i,U,q)})}catch(q){bj.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,C=l.match(h);if(C){const v=C.index,R=C[1],L=C[2],U=v,M=r,G={...pa(o,U),link:L};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,U,M-U),n.insertTextToBlock(i,U,Zs(R,G))}),!0}return!1}class P0{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(N0(t,e))return!1;if(xj(t,e,r,i)||Tj(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(et(t,t.getBlockByIndex(i,o))){if(oi(e,"Enter")){if(ER(t,i,o,s,"enter"))return!0}else if(oi(e,"Space")&&ER(t,i,o,s,"space"))return!0}return!1}}const yj={"en-US":{placeholder:{default:"Type / for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};D.mergeLang(yj);function Zu(n,t){const e=jo(n,t);return!!(et(n,t)&&e.text&&fn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function AR(n,t){var r;Ot(t).removeAttribute("data-content-placeholder"),(r=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||r.remove()}function tf(n,t,e){var i;if(AR(n,t),!Zu(n,t))return;const r=Ot(t);if(typeof e=="string")r.setAttribute("data-content-placeholder",e);else{const o=re(t),s=(i=o.querySelector(".block-placeholder-container"))!=null?i:B("div",["block-placeholder-container"],o);s.innerHTML="",s.appendChild(e)}}function kj(n){const t=n.getAttribute("data-style-heading");return t?D.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?D.t("placeholder.quote"):null}function Rj(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?D.t("placeholder.list"):D.t("placeholder.mention"):null}function xR(n){switch(St(n)){case"text":return kj(n);case"list":return Rj(n);default:return null}}function wj(n){if(fr(n))return!1;const t=nt(rt(n));return t?St(t)==="code":!1}function Sj(n){return!fr(n)}function Lj(n,t){var h,C;const e=n.selection.focusedBlock,r=St(e),i=t.contentPlaceholder||D.t("placeholder.default");let o=i;if(r&&Jc(n,r)&&e){if(!n.isBlockWritable(e)||wj(e))return;Sj(e)&&(o=D.t("placeholder.common.contentInTable")),o=(h=xR(e))!=null?h:o}const s=n.getFirstBlock(),l=t.hideTitle?s:Gt(s);if(!l)return;const c=Gt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c&&Zu(n,l)){tf(n,l,(C=xR(l))!=null?C:i);return}const d=n.getFocusedBlock();!Zu(n,d)||d===s&&!t.hideTitle||tf(n,d,o)}function Ij(n,t){var i,o;const e=n.getFirstBlock(),r=Ot(e);Zu(n,e)?(r.setAttribute("data-title-placeholder",(i=t.titlePlaceholder)!=null?i:D.t("placeholder.title")),r.setAttribute("data-title-placeholder-readonly",(o=t.readonlyTitlePlaceholder)!=null?o:"")):(r.removeAttribute("data-title-placeholder"),r.removeAttribute("data-title-placeholder-readonly"))}function Dj(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 _j(n,t){Dj(n),n.selection.range.isCollapsed()&&(t.hideTitle||Ij(n,t),Lj(n,t))}const ect="";function Mj(n){for(let t=0;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const bR=I("enforce-title");class fE{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=ji(t.rootContainer,1),dt(t,c)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e,r;try{const i=t.doc.getContainerBlocks(ft(t.rootContainer));p(bR,i.length>0,"root container is empty");const o=i[0];if(o.type!=="text"&&!this.options.hideTitle){const s=hi("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(ft(t.rootContainer),0,s,t.selection.range.toDocRange()).setAttribute("data-document-title","");return}if(!this.options.hideTitle){p(bR,o.text,"invalid text block");const s=t.getBlockById(o.id);if(Mj(o.text)||o.quoted||o.heading!==this.options.headingLevel){const l=t.getBlockString(s),c=hi(l,{heading:(r=this.options.headingLevel)!=null?r:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const C=t.insertBlock(ft(t.rootContainer),0,c);C.setAttribute("data-document-title",""),d===s&&(h=Te(t,c.id,dt(t,C))),bh(t,s,h)}else s.setAttribute("data-document-title","")}if(i.length>1||this.options.hideTitle)return;t.insertTextBlock("",ft(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)||_j(t,this.options)}isDocumentTitleBlock(t,e){return t==="root"&&e===0&&!this.options.hideTitle}}function Gr(n){return St(n)==="embed"&&We(n)==="image"}async function vR(n){return new Promise((t,e)=>{const r=new Image;r.onload=()=>{t({width:r.naturalWidth,height:r.naturalHeight})},r.onerror=e,r.src=n})}async function Uj(n){const t=await la(n);return vR(t)}function os(n){return typeof n=="number"}const Oj=I("image-data"),ef=1e3,BR=400,Nj=10;function tc(n){return n.src.startsWith("empty:")||!n.src}function Pj(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function TR(n){return`${vd.default(n)}_width`}function yR(n){return`${vd.default(n)}_height`}function kR(n){return`${n}_flex`}function RR(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function ec(n){if(n.every(i=>typeof i.flex=="number"&&i.flex))return;const t=100,r=n.map(i=>{const o=i.width==="auto"?ef: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"?ef:i.width,s=i.height==="auto"?o/t:i.height/t,l=o/s;i.flex=l/r})}function nc(n){const t=(i,o)=>{i||(i=`empty:${o}`);const s=TR(i),l=yR(i),c=kR(o);let d=n[s],h=n[l],C=n[c];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof C=="string"&&(C=Number.parseInt(C,10)),{src:i,width:d!=null?d:"auto",height:h!=null?h:"auto",flex:C,virtualSize:!d||!h}};let e=[];const r=n.src;return Array.isArray(r)?e=r.map(t):typeof r=="string"&&(e=r.split("|").map(t)),ec(e),e}function Wr(n){const t=n.embedData;return nc(n.embedData).length>1?100:t.widthPercent}function Fj(n,t,e,r){const i=nc(t.embedData);if(i.length>1||r)return"100%";const o=Wr(t),s=n.rootContainer.getBoundingClientRect().width;if(o){const l=RR(e);return`${Math.min(s*o/100,l)}px`}return os(i[0].width)?`${i[0].width}px`:"auto"}function hn(n,t){const r={src:n.map(i=>i.src).join("|"),widthPercent:t};return n.forEach((i,o)=>{const s=i.src||`empty:${o}`,l=TR(s);l&&os(i.width)&&(r[l]=i.width);const c=yR(s);c&&os(i.height)&&(r[c]=i.height),p(Oj,i.flex,"no image flex");const d=kR(o);r[d]=i.flex}),r}function Kj(n,t,e,r){const i=nc(t.embedData),o=i.length===1?n.rootContainer:e;if(i.length===1&&r)return`${BR}px`;if(i.some(h=>h.height==="auto"))return"auto";const s=Wr(t);if(!s){if(i.length!==1||os(i[0].width))return"";const C=i[0].height;return C==="auto"?"auto":`${C}px`}let l=o.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(o).paddingLeft)+Number.parseFloat(window.getComputedStyle(o).paddingRight),o===n.rootContainer&&o!==e&&(l=Math.min(l,RR(e))),i.length===1){const h=i[0];if(h.virtualSize)return"";const C=h.width==="auto"?ef:h.width;return`${h.height/(C/l)}px`}l-=(i.length-1)*Nj;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"?ef:h.width,x=C/E*h.height;d=Math.max(x,d)}return`${d}px`}function Vj(n){return n.reduce((e,r)=>e+r.flex,0)}function $j(n,t){B("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function dE(n){return re(n).querySelector(".block-resizer")}function Hj(n){const t=dE(n);t&&ot(t,"active")}function wR(n,t,e){const r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),o=i.top-r.top,s=i.left-r.left,l=i.width,c=i.height;e.style.top=`${o}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function jj(n,t,e,r){const i=dE(n);if(i)return z(i,"active"),wR(n,t,i),i;const o=re(n),s=B("div",["block-resizer"],o);return wR(n,t,s),e.resize.forEach(l=>{$j(s,l)}),s.addEventListener("mousedown",r),z(s,"active"),s}function hE(n,t){const e=dE(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 nct="",zj=I("block-resizer");class nf extends Re.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,Gc(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,x=new DOMRect(c,l,C,E);this.emit("resizing",this,x);const v=this.getResizableElement();v&&hE(this.block,v)});g(this,"handleMouseUp",e=>{if(e.button!==0)return;Gc(""),this.unbindEvents(),this.emit("resized",this);const r=this.getResizableElement();!r||!this.block||hE(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||(Hj(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&&hE(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Ot(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(p(zj,ee(this.block,e),"not a block child element"),jj(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 Gj=I("image-dom");function SR(n){return n.querySelector(".uploading-progress-mask")}function Wj(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 qj(n){const e=Wj(n).querySelector(".uploading-progress-bar-value");return p(Gj,e,"no progress value"),e}function LR(n,t){const e=qj(n);e.style.width=`${t}%`}function Xj(n){var t;(t=SR(n))==null||t.remove()}function rf(n,t,e,r){const i=e!=null?e:n.findBlockById(t.id);if(!i)return;const o=r||rt(i),s=!!i.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=Fj(n,t,o,s),c=Kj(n,t,o,s),d=Ot(i);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=i.querySelector(".images");!h||(h.style.height=c||"none")}function Qj(n){let t;return n.forEach((e,r)=>{r.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function Yj(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),r=Qj(t.headers).toLocaleLowerCase();let i="";if(r){const s=bg.default[r].extensions;s&&s.length>0&&(i=s[0])}return new File([e],`${Date.now()}.${i}`,{type:r})}catch{return null}}function ss(n,t){const e=typeof t=="string"?t:st(t);return n.getCustom(`image-${e}`)}function F0(n,t){if(!t||!(t instanceof Node))return null;const e=nt(t);return e?ss(n,e):null}function Bi(n){return Array.from(n.querySelectorAll(".image-container"))}const mE=I("table-resize-drag-drop");class Jj{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=ss(this.editor,o).getImages(),c=this.data.splitterIndex;p(mE,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const h=Bi(o).map(C=>C.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,r){if(!this.editor.isWritable())return;const i=this.data.block;ss(this.editor,i).setResizing(!0)}onDragging(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),c=gt.default(l.getImages()),d=this.data.splitterIndex;p(mE,d>=0&&d<c.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],C=this.initWidths[d+1];if(h+C<100)return;let E=i;h+E<50&&(E=50-h),C-E<50&&(E=C-50);const R=[...this.initWidths];R[d]+=E,R[d+1]-=E;const L=Bi(s);p(mE,L.length===c.length,"invalid image data");const U=R.reduce((G,q)=>G+q,0);for(let G=0;G<c.length;G++){const q=R[G]/U;c[G].flex=q,L[G].style.flexGrow=`${q}`}const M=gt.default(this.editor.getBlockData(s)),F=hn(c,Wr(M));M.embedData=F,rf(this.editor,M,s,null)}onDragEnd(t,e,r,i,o){const s=this.data.block,l=ss(this.editor,s),d=Bi(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function IR(n){var t;return!n||!(n instanceof HTMLElement)?null:Rt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function Zj(n,t){var s;const e=IR(t.target);if(!e)return;const r=nt(e);if(!r)return;ss(n,r).setSelectedIndex(-1),n.selection.selectBlock(r,0);const i=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(i)||typeof i!="number")return;const o={block:r,splitterIndex:i};Sg(new Jj(n,e,o,t))}function tz(n,t){t.preventDefault(),t.stopPropagation();const e=IR(t.target);if(!e)return;const r=nt(e);!r||ss(n,r).resetFlex()}function ez(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",Zj),n.domEvents.addEventListener(i,"dblclick",tz)}const nz=I("image-item");function DR(n){return!n||!(n instanceof Node)?null:nt(n)}function _R(n){const t=DR(n);return t?Bi(t):[]}function gE(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 of(n){const t=gE(n);return t?_R(n).indexOf(t):-1}async function rz(n,t){const e=F0(n,t.target);if(!e)return;const r=of(t.target);if(r===-1)return;const i=t.target;if(!(i instanceof HTMLImageElement))return;const o=e.getImages()[r];if(tc(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||!Pj(o)||o.downloading))return;o.downloading=!0;const s=await Yj(o.src);s?e.replaceImage(r,s):nz.warn(`failed to download image: ${o.src}`)}function iz(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=Hp;const l=B("div",["error-message"],o);i?(l.innerHTML=D.t("image.load.remote.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=D.t("image.load.failed"),n.domEvents.addEventListener(o,"click",(c,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&az(c,d.target)}))}function pE(n,t){setTimeout(()=>{if(ee(n.rootContainer,t)){const e=n.getBlockData(t);rf(n,e,null,null)}})}function oz(n,t){const e=F0(n,t.target);if(!e)return;const r=of(t.target);if(r===-1)return;const i=e.getImages()[r];if(!i)return;const o=gE(t.target);if(!o)return;z(o,"error","error-load");const s=nt(o);s&&pE(n,s),o.innerHTML="",iz(n,o,i)}function sz(n,t,e){if(t.querySelector(".upload-error"))return;const i=B("div",["upload-error"],t),o=B("div",["error-icon"],i);o.innerHTML=Hp;const s=B("div",["error-message"],i);s.innerHTML=D.t("image.upload.failed"),n.domEvents.addEventListener(i,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const d=F0(l,c.target),h=of(c.target);!d||h===-1||d.replaceImage(h,e)})}function MR(n,t,e,r,i){const o=Bi(t)[e];!o||(z(o,"error","error-upload"),pE(n,t),o.innerHTML="",sz(n,o,i))}function UR(n,t,e,r,i,o,s){const l=B("div",["image-container"],e);if(l.setAttribute("data-src",r.src),s.length>1&&(l.style.flexShrink=`${r.flex}`,l.style.flexGrow=`${r.flex}`),o===i&&z(l,"active"),tc(r)){z(l,"empty");const d=B("div",["upload-image-icon"],l);return d.innerHTML=v2,l}const c=B("img",["editor-image"],l);if(c.src=n.doc.buildResourceUrl(r.src),n.domEvents.addEventListener(c,"load",rz),n.domEvents.addEventListener(c,"error",oz),r.src.startsWith("https:")||r.src.startsWith("http:")){const d=B("div",["image-warning"],l);d.innerHTML=$p,d.setAttribute(`data-editor-tooltip-${n.clientId}`,D.t("image.load.remote.tooltip"))}return l}function lz(n,t,e,r,i){const o=B("div",["images"],e);return r.forEach((s,l)=>{l>0&&ez(n,t,o,l-1),UR(n,t,o,s,l,i,r)}),r.length>1&&z(t,"multi"),o}function OR(n,t,e,r,i,o){const l=Array.from(t.querySelectorAll(".image-container"))[r];if(!l)return;const c=UR(n,t,null,e,r,i,o);l.insertAdjacentElement("beforebegin",c),l.remove(),pE(n,t)}function sf(n,t){return Bi(n)[t]}function az(n,t){const e=DR(t);if(!e)return;const r=of(t);if(r===-1)return;const i=F0(n,t);if(!i)return;const o=i.getImages()[r];OR(n,e,o,r,i.getSelectedIndex(),i.getImages())}function NR(n){var r;let t="image/*";const e=(r=n.getComponentOptions("image"))==null?void 0:r.allowedMedias;return e&&(t=e.map(i=>`.${i}`).join(",")),t}function PR(n,t){var s;const{maxSize:e,allowedMedias:r,callbacks:i}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}const o=Qc(t.name);if(r&&!r.includes(o)){const l=new Error(`media file is not allowed: ${o}`);throw l.code="NotAllowedFile",i!=null&&i.onError&&(i==null||i.onError(n,l)),l}}function FR(n){return n.startsWith("image/")}const KR=I("image-object");class Le{constructor(t,e){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=of(e.target);if(r===-1)return;const i=this.images[r];tc(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||rt(e)===t&&rf(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 i=r.querySelector(".images");i.style.height="";const s=this.editor.rootContainer.getBoundingClientRect().width,l=r.getBoundingClientRect();let c=e.width>l.width?l.width:e.width;c<50&&(c=50);const d=c*100/s;this.blockData.embedData.widthPercent=d,rf(this.editor,this.blockData,r,null)});g(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=hn(this.images,Wr(this.blockData));this.editor.updateEmbedData(e,r),this.blockResizer.enableResize(e)});g(this,"fixImageSizes",Ke.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=hn(this.images,Wr(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new nf(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=nc(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=lz(this.editor,e,r,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(r,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),_r(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new Is(s),this.parentContainerResizerObserver.observe(t)}const o=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&o()&&z(i,"empty"),rf(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 Wr(this.blockData)}isEmpty(){return this.images.length===1&&tc(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=sf(e,this.selectedIndex);i&&ot(i,"active")}this.selectedIndex=t;const r=sf(e,t);r&&z(r,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const r=sf(e,t);if(Rt(r,"error"))return;const i=NR(this.editor),o=await ca(i);await this.replaceImage(t,o)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=sf(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];tc(r)||(os(r.width)&&!os(r.height)?r.height=r.width/e.naturalWidth*e.naturalHeight:os(r.height)&&!os(r.width)?r.width=r.height/e.naturalHeight*e.naturalWidth:(r.width=e.naturalWidth,r.height=e.naturalHeight),r.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const r=gt.default(this.images);if(r.splice(t,1),r.length===0)return this.editor.deleteBlock(e),!0;r[0].flex=NaN,ec(r),this.selectedIndex>=r.length&&(this.selectedIndex=r.length-1);const i=hn(r,Wr(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 la(e),s=this.images[t];if(s.virtualSize){const{width:c,height:d}=await vR(o);s.width=c,s.height=d,s.virtualSize=!1,this.images[0].flex=NaN,ec(this.images);const h=hn(this.images,Wr(this.blockData));this.editor.updateEmbedData(r,h)}const l={...s,src:o};OR(this.editor,r,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(r)})}catch(o){return MR(this.editor,r,t,o,e),!1}const i=sf(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=hn(this.images,Wr(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(o){KR.error(o);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(i,"uploading"),Xj(i),MR(this.editor,s,t,o,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;p(KR,t.length===this.images.length,"invalid flex");for(let i=0;i<this.images.length;i++)this.images[i].flex=t[i];const r=hn(this.images,Wr(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,ec(e);const r=hn(e,Wr(this.blockData));this.editor.updateEmbedData(t,r)}setData(t){this.blockData=t,this.images=nc(t.embedData)}static create(t,e){const r=t.addCustom(`image-${e.id}`,()=>new Le(t,e));return r.setData(e),r}static getImageObject(t,e){let r;return typeof e=="string"?r=e:r=st(e),t.getCustom(`image-${r}`)}}const rct="",ict="";function K0(n){const t=re(n);let e=t.querySelector(":scope > .block-helper");return e||(e=B("div",["block-helper"],t),B("span",["helper-sizer"],e,"A")),e}function CE(n,t,e){const r=K0(n),o=Array.from(r.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});r.insertBefore(t,o!=null?o:null)}const VR=40,cz=20;class uz{findTargetBlock(t,e){const r=e.target;if(r&&r instanceof Element){const c=nt(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<VR&&(i+=VR);let l=document.elementFromPoint(i,o);if(l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}if(o-=cz,l=document.elementFromPoint(i,o),l){const c=nt(l);if(c&&ee(t.rootContainer,c))return c}return null}destroy(){}}class fz extends R0{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 dz(n,t,e){const r=Wg(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 EE(n,t,e={withPlainText:!1}){const r=XC(n,e),i=o=>{o.forEach(s=>{s.source=t,s.children&&i(s.children)})};return i(r),r}function hz(n,t,e,r=!1){var h,C,E;const i=rt(t);let o=t;if(o&&Kt(o)&&IC(o)){if(!r){const x=nK(o);o=(h=Gt(x))!=null?h:x}x0.closeMindmap(n,t)}let l=bt(o);ce(n,o)||r||(l+=1);const c=ft(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 mz(n,t){const e=Lr(n,t),r=n.getBlockData(t);return!(e!=="text"||r.heading)}class $R{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=zC();this.createItem("text",Ma,e,mz(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",Qp,e,c),this.createItem("ordered-list",Yp,e,d),this.createItem("check-list",qp,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"&&y0(t,this.block,null),o.startsWith(s)){const d=Number.parseInt(o.substring(s.length),10);d&&y0(t,this.block,d)}if(o==="blockquote"&&$C(t,this.block),o.startsWith("align")){const d=o.replace(/^align-/,"");Tk(t,this.block,d)}(o==="unordered-list"||o==="ordered-list"||o==="check-list")&&jC(t,this.block,o),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});g(this,"calcTextStyleItemTooltipsEnum",()=>{this.textStylesTooltips={text:{title:D.t("commands.text")},blockquote:{title:D.t("commands.quote")},"align-left":{title:D.t("commands.alignLeft")},"align-center":{title:D.t("commands.alignCenter")},"align-right":{title:D.t("commands.alignRight")},"unordered-list":{title:D.t("commands.unordered")},"ordered-list":{title:D.t("commands.ordered")},"check-list":{title:D.t("commands.check")}};let t=1;for(;t<=8;)this.textStylesTooltips[`heading-${t}`]={title:D.t("commands.heading",{name:`${t}`})},t++});this.editor=t,this.block=e,this.options=r,this.calcTextStyleItemTooltipsEnum(),this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const r=B("div",["text-styles"],null),i=B("div",["text-style-section"],r),o=t.getBlockData(e);if(!this.options.fromEmbed){const l=o.heading,c=o.quoted;this.createHeadingItemElement(e,i,l),this.createListItemElement(e,i,o),this.createItem("blockquote",Xp,i,!!c)}const s=o.align||"left";return this.createItem("align-left",_a,i,s==="left"),this.createItem("align-center",t0,i,s==="center"),this.createItem("align-right",Zh,i,s==="right"),r}createItem(t,e,r,i=!1){const o=["style-icon","text-style-item"];i&&o.push("active");const s=Ds(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}`,Ge(d))}}function HR(){return{source:"separator",type:"separator",id:`section-${Z()}`,name:""}}const jR={copy:P2,cut:F2,delete:K2,"lock-block":V2,"unlock-block":$2,comment:il},gz=["image","video"];function pz(n,t,e){const r=[],i=et(n,t),o=ge(t)&&gz.includes(We(t)),s=o&&(We(t)!=="image"||We(t)==="image"&&Bi(t).length===1);if(i?r.push(new $R(n,t,e)):o&&s&&r.push(new $R(n,t,{...e,fromEmbed:!0})),!ce(n,t)||LC(t)){(i||o&&s)&&r.push(HR());const l=dz(n,t,new Set(["hovering-toolbar"]));l.sort((c,d)=>{var h,C;return((h=c.order)!=null?h:0)-((C=d.order)!=null?C:0)}),l.forEach(c=>{c.id in jR&&(c.icon=jR[c.id])}),r.push(...l)}return ce(n,t)&&!LC(t)?r.push(...EE(n,"insert-block")):r.push(HR(),{id:"insert-block-before",icon:H2,name:D.t("blockMenu.command.insertAbove"),children:EE(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:j2,name:D.t("blockMenu.command.insertAfter"),children:EE(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),r}function Cz(n,t,e){if(e.source==="block-command"){const r=e.blockMenuItemCustomData;Vv(n,t,r,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&hz(n,t,e,e.source==="insert-block-before")}const Ez=I("exclusive-block");function AE(n,t,e,r){var l;z(t,"block-exclusive");const i=Qt(n,t),o=(l=i.getBlockProperties)==null?void 0:l.call(i,n,t),{abstract:s}=o||{};t.setAttribute("data-user-name",r),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",D.t("exclusive.tips",{editor:r,embedType:s||D.t("exclusive.fallbackAbstract")}))}function zR(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function Az(n,t,e,r,i){Ez.debug(`block ${st(t)} ${e?"exclusive":"unexclusive"}, ${r}, ${i}`),e?AE(n,t,r,i):zR(t)}function lf(n){return n.classList.contains("block-exclusive")}function GR(n,t){t.blockIds.forEach(e=>{const r=n.findBlockById(e);r&&Az(n,r,t.exclusive,t.userId,t.displayName)})}class ls{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};GR(this.editor,s)}});const r=Array.from(this.exclusiveBlockIds).map(i=>this.editor.findBlockById(i)).filter(i=>!!i);r.length>0&&this.broadcastExclusiveBlockMessage(r,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;GR(this.editor,e),e.blockIds.forEach(r=>{e.exclusive?this.remoteExclusiveBlockIds.set(r,e):this.remoteExclusiveBlockIds.delete(r)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const r=this.editor.doc.getUser(),i={type:"exclusiveBlock",userId:r.userId,displayName:r.displayName,blockIds:t.map(o=>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 ls(t))}static register(t){return this.get(t)}}function xE(n,t){ls.get(n).exclusiveBlock(t)}function bE(n,t){ls.get(n).unexclusiveBlock(t)}class WR{writable(t,e){if(Array.isArray(e)){for(const r of e)if(lf(r))return!1;return}if(lf(e))return!1}create(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s&&AE(t,i,s.userId,s.displayName)}update(t,e,r,i,o){const s=ls.get(t).getExclusiveMessage(o.id);s?AE(t,i,s.userId,s.displayName):zR(i)}}const oct="",xz={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},bz={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},vz={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};D.mergeLang({"zh-CN":xz,"en-US":bz,"ja-JP":vz});function af(n,t){return n.getBlockData(t).lock}function V0(n,t){return!!af(n,t)}function cf(n,t){const e=af(n,t);return e?e.userId===n.doc.getUser().userId:!1}function vE(n,t){const e=af(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function Bz(n,t){if(n.readonly||!n.isBlockWritable(t)||V0(n,t)&&!cf(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 Tz(n,t){if(!cf(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const yz=10,kz=80,Rz=50;class BE{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"?Bz(t,o):i.type==="unlock"&&Tz(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))&&(et(t,i)||St(i)==="code")&&t.insertTextBlock("",ft(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(vE(t,i))return!1;if(fr(i))return;let o=Vs(i);for(;o;){if(vE(t,o))return!1;o=Vs(o)}}}commands(t,e){const r=V0(t,e),i=cf(t,e),o=lf(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=D.t("locker.unlock"),s.type="unlock";else{const c=af(t,e);let d=(c==null?void 0:c.displayName)||"";const h=D.getCurrentLang()==="ja-JP",C=sv(d,yz,h?Rz:kz);(C==null?void 0:C.length)!==d.length&&(l.ellipsisTooltip=c==null?void 0:c.displayName,d=C||""),l.name=D.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else o?(l.name=D.t("locker.lock"),l.states=["disabled"]):l.name=D.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const sct="",wz={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},Sz={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},Lz={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};D.mergeLang({"zh-CN":wz,"en-US":Sz,"ja-JP":Lz});class $0{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{delete i.lock})}),!1}}const Iz=I("standard-block-actions");class Dz{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"&&Lh(t,o),r.id==="cut"&&(Lh(t,o),t.deleteBlock(o))}catch(o){Iz.error(`failed to execute block command: ${JSON.stringify(o)}`)}})}commands(t,e){const r=V0(t,e),i=r&&cf(t,e),o=st(e),s=U0(),l=lf(e),c={id:"copy",name:D.t("blockMenu.command.copy"),data:o,order:1,states:s?[]:["disabled"],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:Ge("CtrlOrCmd+C"),operation:D.t("copyCutProperty.copy")})},d={id:"cut",name:D.t("blockMenu.command.cut"),data:o,order:2,states:r&&!i||!s||l?["disabled"]:[],disableReason:s?void 0:D.t("copyCutProperty.unsafeEnvTips",{shortCut:Ge("CtrlOrCmd+X"),operation:D.t("copyCutProperty.cut")})},h={id:"delete",name:D.t("blockMenu.command.delete"),data:o,order:3,states:r&&!i||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[c,d,h],executeCommand:this.executeCommand}}}const qR=I("block-menu");class _z{constructor(t){g(this,"menu");g(this,"currentBlock",null);g(this,"commandBlock",null);g(this,"handleShow",()=>{p(qR,this.currentBlock,"no target block before show block menu");const t=pz(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});g(this,"handleClose",()=>{rC(this.editor)&&this.editor.focus()});g(this,"handleItemClick",(t,e)=>{p(qR,this.commandBlock,"no command block before show block menu"),Cz(this.editor,this.commandBlock,e),e.element||this.close()});g(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new Yo([],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 Dz)}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 Mz=1e3;async function Uz(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),r=t.getBoundingClientRect();return r.width>e||r.height>=Mz?"":(await pb.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const Oz=I("drag-preview-image");class Nz{constructor(t){g(this,"startPosition",null);g(this,"dragContainer",null);g(this,"handleDragStart",async(t,e)=>{const r=t.target;p(Oz,r instanceof Element,`Invalid Drag target:${r}`);const{x:i,y:o}=t;this.startPosition={x:i,y:o};const s=B("div",["drag-image-container"],this.editor.rootContainer),l=B("img",["drag-image"],s),c=B("span",["drag-loading"],s);c.innerHTML=q2;const{x:d,width:h,height:C,y:E}=r.getBoundingClientRect(),x=this.editor.rootContainer.getBoundingClientRect(),v=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${E+C}px`,s.style.width=`${Math.min(x.width/2,v.width)}px`,this.dragContainer=s;const L=await Uz(this.editor,e);L?l.src=L:z(s,"drag-placeholder"),kg(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 XR="drag-preview-element";function Pz(n){if(Rt(n,XR))return n;const t=n.querySelector(`.${XR}`);return t||(ge(n)?Ot(n):n)}const H0=I("block-menu-drag-handler");function TE(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 Fz{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(H0,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=un(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Nd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const r=this.button.blockMenu.currentBlock;p(H0,r,"no dragged block"),(l=(s=Qt(this.editor,r)).notify)==null||l.call(s,this.editor,"beginDrag");const i=TE(t,"dragstart");jz(this.editor,i,r),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const o=Pz(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(H0,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const o=TE(t,"dragover");this.editor.contentElement.dispatchEvent(o)});g(this,"handleDragEnd",t=>{var i;const e=this.button.blockMenu.currentBlock;p(H0,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=TE(t,"drop");this.editor.contentElement.dispatchEvent(r)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new Nz(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class uf{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 uf(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class QR{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=$d(t);zi(o)||(this.updateButton(o),CE(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(()=>{uf.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=>{tf(this.editor,t,D.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=ce(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new fz(t),this.blockMenu=new _z(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new Fz(this.editor,this);const e=Be.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new uz),uf.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}`,D.t("blockMenu.button.tips")),t.innerHTML=Jp,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,D.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=Jp,this.buttonElement.setAttribute(e,D.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),ce(this.editor,t)&&!(Kt(t)&&LC(t))?this.setButtonType("insert"):this.setButtonType("move")}}const Kz={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
628
628
|
\u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},Vz={blockMenu:{section:{basics:"Basic",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert below",copy:"Copy",cut:"Cut",delete:"Delete"},button:{searchPlaceholder:"Search",tips:`Hold to drag
|
|
629
629
|
Click to open the menu`,insertTips:"Click to add block"}}},$z={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};D.mergeLang({"zh-CN":Kz,"en-US":Vz,"ja-JP":$z});const lct="";class Hz{constructor(){g(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function j0(n){return n.addCustom("drag-data",()=>new Hz)}function yE(n,t){if(!t)return null;const e=j0(n).getData();return!e||e.editorId!==n.id?null:e}function YR(n,t){const e=yE(n,t);return e?n.findBlockById(e.blockId):null}function jz(n,t,e){if(!t.dataTransfer)return;const i=rt(e),o=ft(i),s=st(e),l={type:"block",editorId:n.id,containerId:o,blockId:s};j0(n).setData(l)}function zz(n,t,e,r,i){if(!t.dataTransfer)return;const s=rt(e),l=ft(s),c=st(e),d={type:"custom",customType:r,editorId:n.id,containerId:l,blockId:c,data:i};j0(n).setData(d)}function ff(n){j0(n).clearData()}const Gz=I("drop-indicator"),df=2;class Wz{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=Hs(t);if(!l){p(Gz,_r(rt(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,df)}const c=l.getBoundingClientRect(),d=t.getBoundingClientRect(),h=this.getViewRect(t);return new DOMRect(h.x,(c.bottom+d.top)/2,h.width,df)}const r=js(t);if(!r){const l=t.getBoundingClientRect(),c=this.getViewRect(t);return new DOMRect(c.x,l.bottom,c.width,df)}const i=t.getBoundingClientRect(),o=r.getBoundingClientRect(),s=this.getViewRect(t);return new DOMRect(s.x,(i.bottom+o.top)/2,s.width,df)}getViewRect(t){const e=un(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),df)}}const qz=I("find-drop-target");function Xz(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(Gi(e)&&_r(e))return e;const r=e.firstElementChild;return r&&Gi(r)&&_r(r)?r:null}function Qz(n,t){const s=t,l=n;for(let c=0;c<2;c++){const d=l+c*50;for(let h=0;h<5;h++){const C=s+h*8,E=document.elementFromPoint(d,C);if(E){const R=nt(E);if(R)return R}if(h===0)continue;const x=s-h*8,v=document.elementFromPoint(d,x);if(v){const R=nt(v);if(R)return R}}}return null}function Yz(n,t,e){const r=document.elementFromPoint(t,e);if(r){const h=nt(r);if(h&&!_t(n,h))return h}const i=new Set,o=Xz(t,e);if(o){const h=o.getBoundingClientRect();e<h.top+h.height/2?i.add(we(o)):i.add(tn(o))}const s=Qz(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 kE(n,t){if(n.readonly)return!1;const e=rt(t);if(Yt(e))return!0;const r=nt(e);return p(qz,r,"no parent block"),n.isBlockWritable(r)?kE(n,r):!1}const Jz=I("drop-target");function Zz(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(Jz,e,`unSupport file type ${t.type}`),e}async function JR(n,t,e,r){var o,s;let i=r;for(const l of t){const c=Zz(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 tG{constructor(t){g(this,"handleDrop",(t,e,r,i)=>{if(Array.isArray(e)){const o=e;if(o.length>0){const s=ft(r);return JR(t,o,s,i),!0}}return!1});this.editor=t}}class hf{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=yE(this.editor,o.dataTransfer),l=YR(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=yE(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"),ff(this.editor);return}const i=this.indicator.target;if(i){const{block:l,insertPos:c}=i,d=YR(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:r,c,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus(),ff(this.editor);return}if(d){const C=Qt(this.editor,d);if(C.handleDrop&&C.handleDrop(this.editor,d,e!=null?e:r,c,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus(),ff(this.editor);return}}if(typeof c=="string"){const C=rt(l);let E=bt(l);if(c==="after"){E+=1;let x=Gt(l);for(;x&&!Zc(x);)E+=1,x=Gt(x)}t.preventDefault();for(let x=0;x<this.handlers.length;x++)if(this.handlers[x].handleDrop(this.editor,d!=null?d:r,C,E)){this.editor.focus(),ff(this.editor);return}if(d){const x=this.editor.getBlockData(d),v=Go(this.editor.editorBlocks,this.editor.doc.toJSON(),x),[R]=this.editor.insertDocAt(C,E,v);this.editor.selection.selectBlock(R,0),uf.get(this.editor).highlightBlock(R),this.editor.deleteBlock(d),this.editor.focus()}}})}ff(this.editor)});g(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new Wz(this.editor),this.handlers.push(new tG(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 hf(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||js(e)===t&&t||!kE(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Hs(e)===t&&t||!kE(this.editor,e)||Yt(rt(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!ee(t,e)}findTargetBlock(t,e,r){let i=Yz(this.editor,e,r);if(!i||!ee(this.editor.rootContainer,i))return null;const o=rt(i),s=nt(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=Qt(this.editor,s);if(c.handleDropOver){const d=c.handleDropOver(this.editor,s,o,r,i);if(d)return d;if(d===!1)return null}s=Vs(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=i&&i<=l.bottom){if(i<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return i<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<i&&this.canInsertAfter(t,e)?"after":""}}function ZR(n,t,e){const r=Le.getImageObject(n,t),i=gt.default(r.getImages());if(i.length===1){n.deleteBlock(t);return}if(e===-1||e>=i.length)return;const o=Vj(i);if(i.splice(e,1),i.length===1){const l=i[0],c=100*(l.flex/o);l.flex=1;const d=hn([l],c);n.updateEmbedData(t,d);return}i[0].flex=NaN,ec(i);const s=hn(i,r.getWidthPercent());n.updateEmbedData(t,s)}function eG(n,t,e,r){if(t.length===0||r==="after"||r==="before")return!1;let i=r.data;const o=Le.getImageObject(n,e),s=gt.default(o.getImages()),l=[],c=[];t.forEach(C=>{FR(C.type)&&s.length+l.length<6?l.push(C):c.push(C)}),l.forEach(C=>{try{PR(n,C)}catch{return}const E={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(i,0,E);const x=hn(s,o.getWidthPercent());n.updateEmbedData(e,x),o.replaceImage(i,C),i+=1});const d=n.getBlockIndex(e)+1,h=ft(rt(e));return JR(n,c,h,d),!0}function nG(n,t,e,r,i){var s,l,c;if(Ud(e))return eG(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=rt(d);let C=bt(d);r==="after"&&(C+=1);const x=100*(o.boundingRect.width/n.rootContainer.getBoundingClientRect().width),v=hn([o.image],x),R={id:Z(),type:"embed",embedType:"image",embedData:v},L=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;L&&(R.align=L),n.insertBlock(ft(h),C,R),ZR(n,t,o.index),(c=n.findCustom("drag-handler"))==null||c.handleDragEnd()}else{if(typeof r=="string")return;const d=t;let h=r.data;const C=Le.getImageObject(n,d),E=gt.default(C.getImages());h>E.length&&(h=E.length),n.undoManager.runInGroup(()=>{var v,R;C.setAutoFix(!0);const x=n.getBlockById(e.blockId);if(x===d){const L=o.index,U=h,M=o.image;if(L===U||U===L+1)return;let F=U;L<U?(E.splice(U,0,M),E.splice(L,1),F-=1):(E.splice(L,1),E.splice(U,0,M));const G=hn(E,C.getWidthPercent());n.updateEmbedData(d,G),C.setSelectedIndex(F),(v=n.findCustom("drag-handler"))==null||v.handleDragEnd()}else{E.splice(h,0,o.image),E[0].flex=NaN,ec(E);const L=hn(E,C.getWidthPercent());n.updateEmbedData(d,L),ZR(n,x,o.index),(R=n.findCustom("drag-handler"))==null||R.handleDragEnd(),C.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const rG=2;function z0(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,rG,i.height)}function iG(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:z0(n,t,o),data:o}:{rect:z0(n,t,o+1),data:o+1}}return r>e[e.length-1].getBoundingClientRect().right?{rect:z0(n,t,e.length),data:e.length}:{rect:z0(n,t,e.length),data:0}}function oG(n,t,e,r,i){const o=Bi(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>FR(s.type))||o.length>=6)return}else{if((e==null?void 0:e.type)==="block"||o.length>=6&&(e==null?void 0:e.blockId)!==st(t))return;const s=st(t);if(o.length===1&&s===(e==null?void 0:e.blockId))return}return iG(n,t,o,r)}async function sG(n){return await pb.default.toSvg(n)}function RE(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 lG{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=nt(e);if(!r||!Gr(r)||!this.editor.isBlockWritable(r)||this.editor.readonly)return;const i=Le.getImageObject(this.editor,r);if(this.imageContainer=gE(t.target),!this.imageContainer)return;const s=_R(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=i.getImages()[s];if(!l)return;const{x:c,y:d}=t;this.startPosition={x:c,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},C=RE(t,"dragstart");zz(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=nt(this.imageContainer);if(!e)return;const{x:r,y:i}=t,{width:o,height:s}=t.target.getBoundingClientRect(),l=re(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=un(e);this.autoScroll=new Nd({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=B("img",["drag-target"],c),E=await sG(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=RE(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=RE(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 aG{constructor(t){g(this,"handleFocusBlockChanged",(t,e,r)=>{const o=this.editor.getFocusedBlock();if(o&&Gr(o)){const s=Le.getImageObject(this.editor,o);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}r&&Gr(r)&&t.findCustom(`image-${r.id}`)&&Le.getImageObject(this.editor,r).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class cG{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){Gr(t)&&Le.getImageObject(this.editor,t).disableResizer()}enable(t){if(Gr(t)){const e=Le.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const uG={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"}},fG={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"}},dG={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};D.mergeLang({"zh-CN":uG,"en-US":fG,"ja-JP":dG});function hG(n,t,e,r){const i=n.getBlockByIndex(t,e),o=n.getBlockText(i),{left:s}=Dn(o,r),l=ue(s);let c=r;if(l.endsWith("![]()"))c-=5;else if(l.endsWith("![]"))c-=3;else return!1;const d=r;return ca("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(i,c,d-c);let C=e+1;ue(n.getBlockText(i)).trim()?(va(n,i,c,{forceInsertAfter:!0}),c===0&&(n.deleteBlock(i),C--)):(n.deleteBlock(i),C--),qg(n,"image",t,C,{file:h})})}),!0}class mG{handleAfterInsertText(t,e,r,i,o){if(o===" "){if(N0(t,e))return!1;if(hG(t,e,r,i))return!0}return!1}}const gG=I("copy-image");function pG(n,t,e,r){const i=e.getImages()[r],o=e.getImages().length===1?e.getWidthPercent():i.flex*100,s=hn([i],o),l={id:Z(),type:"embed",embedType:"image",embedData:s},c=n.options.componentsOptions.image;c!=null&&c.defaultAlign&&(l.align=c.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const C=h.getContext("2d");if(!C)return;const E={},x={};try{C.drawImage(t,0,0,h.width,h.height);const F=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),G=Mg(F),q=new File([G],`${Date.now()}.png`,{type:"image/png"});E["image/png"]=q}catch(M){gG.error(M)}ka(n,d);const R=`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`,L=ya(R,d),U=new Blob([L],{type:"text/html"});return E["text/html"]=U,x["text/html"]=L,[E,x]}function CG(n,t,e,r,i){const o=pG(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 aa(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 G0(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const i=n.getFocusedBlock();if(i&&Gr(i)){const o=Le.getImageObject(n,i);if(o.getImages().length>0){const l=o.getSelectedIndex();if(l!==-1){const d=Bi(i)[l].querySelector("img");if(d)return CG(n,d,o,l,t)}}}}function EG(n){const t=n.getFocusedBlock(),e=js(t);if(e&&Gr(e)){n.selection.selectBlock(e,0);const r=Le.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function AG(n){const t=n.getFocusedBlock(),e=Hs(t);if(e&&Gr(e)){n.selection.selectBlock(e,0);const r=Le.getImageObject(n,e);return r.getImages().length>0&&r.setSelectedIndex(0),!0}}function xG(n){const e=n.getFocusedBlock();if(e&&Gr(e)){const r=Le.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(i.length-1),!0;if(o>0)return r.setSelectedIndex(o-1),!0}}}function bG(n){const e=n.getFocusedBlock();if(e&&Gr(e)){const r=Le.getImageObject(n,e),i=r.getImages();if(i.length>0){const o=r.getSelectedIndex();if(o===-1)return r.setSelectedIndex(0),!0;if(o<i.length-1)return r.setSelectedIndex(o+1),!0}}}function W0(n){const e=n.getFocusedBlock();if(e&&Gr(e)){const r=Le.getImageObject(n,e);if(r.getImages().length>0){const o=r.getSelectedIndex();if(o!==-1)return r.removeImage(o),!0}}}const vG={ArrowLeft:xG,ArrowRight:bG,ArrowUp:AG,ArrowDown:EG,Delete:W0,Backspace:W0};class BG{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,r){if(!window.isSecureContext)return;if(G0(t,e))return!0}handleBeforeCut(t,e){if(G0(t,e))return W0(t),!0}destroy(){}}class wE{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,r){return Object.values(e.blocks).forEach(i=>{i.forEach(o=>{if(o.type==="embed"&&o.embedType==="image"){const s=o.embedData;if(Array.isArray(s.src))return;let l=r.blockIdMap.get(o.id);for(;l&&r.blockIdMap.get(l);)l=r.blockIdMap.get(l);l&&ss(t,l).setAutoFix(!0)}})}),!1}destroy(){}}const TG=I("image-embed");function yG(n,t,e,r,i,o){Le.create(n,e).createContent(i,o,t),n.addCustom("image-select-handler",()=>new aG(n)),n.addCustom("image-copy-handler",()=>new BG(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new lG(n));const l=n.addCustom("image-resizer",()=>new cG(n)),c=e.embedData;tc(c)?l.disable(o):l.currentResizer===o&&l.enable(o)})}function kG(n,t,e,r){const i=t.embedData,o=nc(i);return r==="html"?o.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):r==="markdown"?`${o.map(l=>`})`).join(`
|
|
630
630
|
`)}
|