@ones-editor/editor 0.0.3-beta.184 → 0.0.3-beta.185

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
@@ -418,7 +418,7 @@ ${s}
418
418
  \`\`\`
419
419
  ${l}`:`<p><pre><code>${s}</code></pre></p>
420
420
  <p>${l}</p>`}const Df={blockType:"code",blockKind:"complex",createBlockContent:fN,getBlockTextLength:mN,getRangeFromPoint:gN,moveCaret:pN,getCaretRect:CN,updateSelection:AN,clearSelection:bN,getChildContainers:vN,getNextContainer:yN,getSelectedContainers:kN,convertFrom:$P,handleBlockElementUpdated:wN,getOptions:EN,getBlockProperties:xN,convertTo:IN},H0={...Tn,blockType:"code-line"};class TN{constructor(t){m(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!vc(this.editor,e))return;const o=e,r=t.range.focus.offset,i=L4(this.editor,o,r,"code-caret");i.scrollIntoView({block:"nearest"}),setTimeout(()=>{i.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function k7(n,t){const e=n.split(`
421
- `).map(s=>({id:K(),type:"text",text:Ri(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...t}],[o]:e},meta:{},comments:{}}}class DN{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!vc(t,r))return;const i=R0(r),s=t.getBlockData(i),{language:l,nowrap:a}=s;if(t.selection.range.isCollapsed()){const h=t.getBlockString(r);return k7(h,{language:l,nowrap:a})}const d=t.getSelectedText();return k7(d,{language:l,nowrap:a})}}function SN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!vc(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{Ro(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function LN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!vc(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{Ro(n).forEach(r=>{const i=ie(n.getBlockText(r.block));for(let s=0;s<e.length;s++){const l=e[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function MN(n){const t=n.getFocusedBlock(),e=nt(t);if(Xt(e))return;const o=et(e);if(!o||Dt(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!LA(e,r))return Zg(n,e),!0}const RN={Tab:SN,"Shift+Tab":LN,"CtrlOrCmd+A":MN},vu=S("code-text-decorate");class Sf{decorateText(t,e,o){var v;if(g(vu,e.length>0,"invalid path"),e.length===1)return{};const r=e[e.length-2];if(t.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=ie(s),a=t.doc.getBlockData(r.containerId,r.blockIndex),d=ua.default.tokenize(l,(v=ua.default.languages[a.language])!=null?v:ua.default.languages.plain),h=(B,D)=>{if(g(vu,B,"no token"),typeof B=="string")return[{insert:B,attributes:mt.default(D)}];g(vu,B instanceof ua.default.Token,"invalid token type");const x=B.content,_=mt.default(D);return _[`style-code-${B.type}`]=!0,typeof x=="string"?[{insert:x,attributes:_}]:Array.isArray(x)?x.map(z=>h(z,_)).flat():(g(vu,x instanceof ua.default.Token,"invalid token"),h(x,_))},A=d.map(B=>h(B,{})).flat();return g(vu,rn(A)===rn(s),"failed to highlight code, text length mismatch"),{text:A}}}const ON={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"}},_N={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},FN={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"}};R.mergeLang({"zh-CN":ON,"en-US":_N,"ja-JP":FN});const PN=S("image-data"),w7=1e3,j0=400,NN=10;function yc(n){return n.src.startsWith("empty:")||!n.src}function $N(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function B7(n){return`${_d.default(n)}_width`}function E7(n){return`${_d.default(n)}_height`}function x7(n){return`${n}_flex`}function I7(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function yu(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>{const i=r.height==="auto"?r.width/t:r.height/t;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/t:r.height/t,s=r.width/i;r.flex=s/o})}function kc(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=B7(r),l=E7(r),a=x7(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=w7,h=j0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),yu(e),e}function Vo(n){const t=n.embedData;return kc(n.embedData).length>1?100:t.widthPercent}function HN(n,t,e,o){const r=kc(t.embedData);if(r.length>1||o)return"100%";const i=Vo(t),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=I7(e);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=B7(l);o[a]=r.width;const d=E7(l);r.height!=="auto"&&(o[d]=r.height)}g(PN,r.flex,"no image flex");const s=x7(i);o[s]=r.flex}),o}function jN(n,t,e,o){const r=kc(t.embedData),i=r.length===1?n.rootContainer:e;if(r.length===1&&o)return`${j0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Vo(t);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==e&&(l=Math.min(l,I7(e))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*NN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const A=l*h.flex/a/h.width*h.height;d=Math.max(A,d)}return`${d}px`}function UN(n){return n.reduce((e,o)=>e+o.flex,0)}function zN(n,t){w("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function U0(n){return te(n).querySelector(".block-resizer")}function VN(n){const t=U0(n);t&&ot(t,"active")}function T7(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}function WN(n,t,e,o){const r=U0(n);if(r)return W(r,"active"),T7(n,t,r),r;const i=te(n),s=w("div",["block-resizer"],i);return T7(n,t,s),e.resize.forEach(l=>{zN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function z0(n,t){const e=U0(n);if(!e||!Kt(n,t))return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}const _nt="",qN=S("block-resizer");class ku extends ve.TypedEmitter{constructor(e,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,ga(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,A=h>l?h-l:0,v=new DOMRect(a,l,p,A);this.emit("resizing",this,v);const B=this.getResizableElement();B&&z0(this.block,B)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;ga(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||z0(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(VN(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&z0(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Lt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(g(qN,Kt(this.block,e),"not a block child element"),WN(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 GN=S("image-dom");function D7(n){return n.querySelector(".uploading-progress-mask")}function ZN(n){const t=D7(n);if(t)return t;const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e);return w("div",["uploading-progress-bar-value"],o),o}function QN(n){const e=ZN(n).querySelector(".uploading-progress-bar-value");return g(GN,e,"no progress value"),e}function S7(n,t){const e=QN(n);e.style.width=`${t}%`}function YN(n){var t;(t=D7(n))==null||t.remove()}function wu(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||nt(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=HN(n,t,i,s),a=jN(n,t,i,s),d=Lt(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function JN(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function KN(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=JN(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Yi(n,t){const e=typeof t=="string"?t:it(t);return n.getCustom(`image-${e}`)}function Lf(n,t){if(!t||!(t instanceof Node))return null;const e=et(t);return e?Yi(n,e):null}function Cr(n){return Array.from(n.querySelectorAll(".image-container"))}const V0=S("table-resize-drag-drop");class XN{constructor(t,e,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Yi(this.editor,i).getImages(),a=this.data.splitterIndex;g(V0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=Cr(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;Yi(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=Yi(this.editor,s),a=mt.default(l.getImages()),d=this.data.splitterIndex;g(V0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let A=r;h+A<50&&(A=50-h),p-A<50&&(A=p-50);const D=[...this.initWidths];D[d]+=A,D[d+1]-=A;const x=Cr(s);g(V0,x.length===a.length,"invalid image data");const _=D.reduce((z,q)=>z+q,0);for(let z=0;z<a.length;z++){const q=D[z]/_;a[z].flex=q,x[z].style.flexGrow=`${q}`}const M=mt.default(this.editor.getBlockData(s)),H=cn(a,Vo(M));M.embedData=H,wu(this.editor,M,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=Yi(this.editor,s),d=Cr(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function L7(n){var t;return!n||!(n instanceof HTMLElement)?null:xt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function t$(n,t){var s;const e=L7(t.target);if(!e)return;const o=et(e);if(!o)return;Yi(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};km(new XN(n,e,i,t))}function e$(n,t){t.preventDefault(),t.stopPropagation();const e=L7(t.target);if(!e)return;const o=et(e);!o||Yi(n,o).resetFlex()}function n$(n,t,e,o){const r=w("div",["image-splitter"],e);w("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",t$),n.domEvents.addEventListener(r,"dblclick",e$)}const o$=S("image-item");function M7(n){return!n||!(n instanceof Node)?null:et(n)}function R7(n){const t=M7(n);return t?Cr(t):[]}function W0(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 Bu(n){const t=W0(n);return t?R7(n).indexOf(t):-1}async function r$(n,t){const e=Lf(n,t.target);if(!e)return;const o=Bu(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(yc(i)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),i.height==="auto"&&e.fixImageSize(o,r),i.virtualSize&&e.fixImageSize(o,r),!i||!$N(i)||i.downloading))return;i.downloading=!0;const s=await KN(i.src);s?e.replaceImage(o,s):o$.warn(`failed to download image: ${i.src}`)}function i$(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=w("div",["load-error"],t),s=w("div",["error-icon"],i);s.innerHTML=cv;const l=w("div",["error-message"],i);r?(l.innerHTML=R.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=R.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&a$(a,d.target)}))}function q0(n,t){setTimeout(()=>{if(Kt(n.rootContainer,t)){const e=n.getBlockData(t);wu(n,e,null,null)}})}function s$(n,t){const e=Lf(n,t.target);if(!e)return;const o=Bu(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=W0(t.target);if(!i)return;W(i,"error","error-load");const s=et(i);s&&q0(n,s),i.innerHTML="",i$(n,i,r)}function l$(n,t,e){if(t.querySelector(".upload-error"))return;const r=w("div",["upload-error"],t),i=w("div",["error-icon"],r);i.innerHTML=cv;const s=w("div",["error-message"],r);s.innerHTML=R.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Lf(l,a.target),h=Bu(a.target);!d||h===-1||d.replaceImage(h,e)})}function O7(n,t,e,o,r){const i=Cr(t)[e];!i||(W(i,"error","error-upload"),q0(n,t),i.innerHTML="",l$(n,i,r))}function _7(n,t,e,o,r,i,s){const l=w("div",["image-container"],e);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),yc(o)){W(l,"empty");const d=w("div",["upload-image-icon"],l);return d.innerHTML=RL,l}const a=w("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",r$),n.domEvents.addEventListener(a,"error",s$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=w("div",["image-warning"],l);d.innerHTML=lv,d.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("image.load.remote.tooltip"))}return l}function c$(n,t,e,o,r){const i=w("div",["images"],e);return o.forEach((s,l)=>{l>0&&n$(n,t,i,l-1),_7(n,t,i,s,l,r,o)}),o.length>1&&W(t,"multi"),i}function F7(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const a=_7(n,t,null,e,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),q0(n,t)}function Eu(n,t){return Cr(n)[t]}function a$(n,t){const e=M7(t);if(!e)return;const o=Bu(t);if(o===-1)return;const r=Lf(n,t);if(!r)return;const i=r.getImages()[o];F7(n,e,i,o,r.getSelectedIndex(),r.getImages())}function Wo(n){return Dt(n)==="embed"&&fn(n)==="image"}async function P7(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function u$(n){const t=await jl(n);return P7(t)}function N7(n){var o;let t="image/*";const e=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return e&&(t=e.map(r=>`.${r}`).join(",")),t}function $7(n,t){var s;const{maxSize:e,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Ca(t.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function H7(n){return n.startsWith("image/")}const j7=S("image-object");class xe{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const o=Bu(e.target);if(o===-1)return;const r=this.images[o];yc(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||nt(e)===t&&wu(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,wu(this.editor,this.blockData,o,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",Se.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new ku(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=kc(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,o){const r=c$(this.editor,e,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Lo(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(t)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),wu(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 Vo(this.blockData)}isEmpty(){return this.images.length===1&&yc(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 r=Eu(e,this.selectedIndex);r&&ot(r,"active")}this.selectedIndex=t;const o=Eu(e,t);o&&W(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=Eu(e,t);if(xt(o,"error"))return;const r=N7(this.editor),i=await Ul(r);await this.replaceImage(t,i)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Eu(t,0);!this.isEmpty()&&this.images.length===1&&!xt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];yc(o)||(o.height==="auto"&&(o.height=e.height),o.width=e.naturalWidth,o.height=e.naturalHeight,o.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 o=mt.default(this.images);if(o.splice(t,1),o.length===0)return this.editor.deleteBlock(e),!0;o[0].flex=NaN,yu(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Vo(this.blockData));return this.editor.updateEmbedData(e,r),!0}async replaceImage(t,e){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await jl(e),s=this.images[t];if(s.virtualSize){const{width:a,height:d}=await P7(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};F7(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return O7(this.editor,o,t,i,e),!1}const r=Eu(o,t);if(!r)return!1;W(r,"uploading"),S7(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(e,{onProgress:a=>{S7(r,a)}});ot(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=cn(this.images,Vo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){j7.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(r,"uploading"),YN(r),O7(this.editor,s,t,i,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;g(j7,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,yu(e);const o=cn(e,Vo(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=kc(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new xe(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=it(e),t.getCustom(`image-${o}`)}}const Fnt="",Pnt="";function Mf(n){const t=te(n);let e=t.querySelector(":scope > .block-helper");return e||(e=w("div",["block-helper"],t),w("span",["helper-sizer"],e,"A")),e}function G0(n,t,e){const o=Mf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const U7=40,d$=20;class h${findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const a=et(o);if(a&&Kt(t.rootContainer,a))return a}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<U7&&(r+=U7);let l=document.elementFromPoint(r,i);if(l){const a=et(l);if(a&&Kt(t.rootContainer,a))return a}if(i-=d$,l=document.elementFromPoint(r,i),l){const a=et(l);if(a&&Kt(t.rootContainer,a))return a}return null}destroy(){}}class f$ extends Cf{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function m$(n,t,e){const o=Vm(n,t);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{e!=null&&e.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function Z0(n,t,e={withPlainText:!1}){const o=I0(n,e),r=i=>{i.forEach(s=>{s.source=t,s.children&&r(s.children)})};return r(o),o}function g$(n,t,e,o=!1){var d,h;const r=nt(t);let s=bt(t);he(n,t)||o||(s+=1);const l=at(r),a=e;return a.commandProvider?a.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:e})}function p$(n,t){const e=Do(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class z7{constructor(t,e,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=k0();this.createItem("text",eu,e,p$(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=Dt(t)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",mv,e,a),this.createItem("ordered-list",gv,e,d),this.createItem("check-list",hv,e,h)});m(this,"handleClick",(t,e)=>{var l,a;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&gf(t,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&gf(t,this.block,d)}if(i==="blockquote"&&b0(t,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");T9(t,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&y0(t,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=w("div",["text-styles"],null),r=w("div",["text-style-section"],o),i=t.getBlockData(e);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(e,r,l),this.createListItemElement(e,r,i),this.createItem("blockquote",fv,r,!!a)}const s=i.align||"left";return this.createItem("align-left",Xa,r,s==="left"),this.createItem("align-center",Dp,r,s==="center"),this.createItem("align-right",Tp,r,s==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=$l(e,i,o);s.id=t}}function V7(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const W7={copy:YL,cut:JL,delete:KL,"lock-block":XL,"unlock-block":tM,comment:tu},C$=["image","video"];function A$(n,t,e){const o=[],r=tt(n,t),i=Me(t)&&C$.includes(fn(t)),s=fn(t)!=="image"||fn(t)==="image"&&Cr(t).length===1;if(r?o.push(new z7(n,t,e)):i&&s&&o.push(new z7(n,t,{...e,fromEmbed:!0})),!he(n,t)){(r||i&&s)&&o.push(V7());const l=m$(n,t,new Set(["hovering-toolbar"]));l.sort((a,d)=>{var h,p;return((h=a.order)!=null?h:0)-((p=d.order)!=null?p:0)}),l.forEach(a=>{a.id in W7&&(a.icon=W7[a.id])}),o.push(...l)}return he(n,t)?o.push(...Z0(n,"insert-block")):o.push(V7(),{id:"insert-block-before",icon:eM,name:R.t("blockMenu.command.insertAbove"),children:Z0(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:nM,name:R.t("blockMenu.command.insertAfter"),children:Z0(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function b$(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;a4(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&g$(n,t,e,e.source==="insert-block-before")}const v$=S("exclusive-block");function Q0(n,t,e,o){var l;W(t,"block-exclusive");const r=Qt(n,t),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,t),{abstract:s}=i||{};t.setAttribute("data-user-name",o),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",R.t("exclusive.tips",{editor:o,embedType:s||R.t("exclusive.fallbackAbstract")}))}function q7(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function y$(n,t,e,o,r){v$.debug(`block ${it(t)} ${e?"exclusive":"unexclusive"}, ${o}, ${r}`),e?Q0(n,t,o,r):q7(t)}function Rf(n){return n.classList.contains("block-exclusive")}function G7(n,t){t.blockIds.forEach(e=>{const o=n.findBlockById(e);o&&y$(n,o,t.exclusive,t.userId,t.displayName)})}class Ji{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!e.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};G7(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!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;G7(this.editor,e),e.blockIds.forEach(o=>{e.exclusive?this.remoteExclusiveBlockIds.set(o,e):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:t.map(i=>it(i)),exclusive:e};this.editor.doc.broadcastMessage(r)}exclusiveBlock(t){this.exclusiveBlockIds.has(it(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(it(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(it(t))||(this.exclusiveBlockIds.delete(it(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 Ji(t))}static register(t){return this.get(t)}}function Y0(n,t){Ji.get(n).exclusiveBlock(t)}function J0(n,t){Ji.get(n).unexclusiveBlock(t)}class Z7{writable(t,e){if(Rf(e))return!1}create(t,e,o,r,i){const s=Ji.get(t).getExclusiveMessage(i.id);s&&Q0(t,r,s.userId,s.displayName)}update(t,e,o,r,i){const s=Ji.get(t).getExclusiveMessage(i.id);s?Q0(t,r,s.userId,s.displayName):q7(r)}}const Nnt="",k$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},w$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},B$={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"}};R.mergeLang({"zh-CN":k$,"en-US":w$,"ja-JP":B$});function xu(n,t){return n.getBlockData(t).lock}function Of(n,t){return!!xu(n,t)}function Iu(n,t){const e=xu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function K0(n,t){const e=xu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function E$(n,t){if(n.readonly||!n.isBlockWritable(t)||Of(n,t)&&!Iu(n,t))return;const e=n.doc.getUser(),o={userId:e.userId,displayName:e.displayName,locked:Date.now()},i={...n.getBlockData(t),lock:o};n.updateBlockData(t,i)}function x$(n,t){if(!Iu(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const I$=10,T$=80;class X0{constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?E$(t,i):r.type==="unlock"&&x$(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(t,e,o,r,i){const s=i.lock;if(s)if(s.userId!==t.doc.getUser().userId){W(r,"locked-by-others");const l=t.selection.focusedBlock;(l===r||Kt(r,l))&&(tt(t,r)||Dt(r)==="code")&&t.insertTextBlock("",at(o),bt(r)+1)}else W(r,"locked-by-self");else ot(r,"locked-by-others"),ot(r,"locked-by-self")}writable(t,e){if(K0(t,e))return!1;if(io(e))return;let o=xs(e);for(;o;){if(K0(t,o))return!1;o=xs(o)}}commands(t,e){const o=Of(t,e),r=Iu(t,e),i=Rf(e),s={blockId:it(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=R.t("locker.unlock"),s.type="unlock";else{const a=xu(t,e);let d=(a==null?void 0:a.displayName)||"";const h=MC(d,I$,T$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=R.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=R.t("locker.lock"),l.states=["disabled"]):l.name=R.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const $nt="",D$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},S$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},L$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":D$,"en-US":S$,"ja-JP":L$});class _f{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const M$=S("standard-block-actions");class R${constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&Oh(t,i),o.id==="cut"&&(Oh(t,i),t.deleteBlock(i))}catch(i){M$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=Of(t,e),r=o&&Iu(t,e),i=it(e),s=$0(),l=Rf(e),a={id:"copy",name:R.t("blockMenu.command.copy"),data:i,order:1,states:s?[]:["disabled"],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})},d={id:"cut",name:R.t("blockMenu.command.cut"),data:i,order:2,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+X"),operation:R.t("copyCutProperty.cut")})},h={id:"delete",name:R.t("blockMenu.command.delete"),data:i,order:3,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const Q7=S("block-menu");class O${constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(Q7,this.currentBlock,"no target block before show block menu");const t=A$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{g(Q7,this.commandBlock,"no command block before show block menu"),b$(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new zs([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new R$)}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 _$=1e3;async function F$(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),o=t.getBoundingClientRect();return o.width>e||o.height>=_$?"":(await G5.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const P$=S("drag-preview-image");class N${constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const o=t.target;g(P$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=t;this.startPosition={x:r,y:i};const s=w("div",["drag-image-container"],this.editor.rootContainer),l=w("img",["drag-image"],s),a=w("span",["drag-loading"],s);a.innerHTML=sM;const{x:d,width:h,height:p,y:A}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${A+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const x=await F$(this.editor,e);x?l.src=x:W(s,"drag-placeholder"),Am(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const Y7="drag-preview-element";function $$(n){if(xt(n,Y7))return n;const t=n.querySelector(`.${Y7}`);return t||(Me(n)?Lt(n):n)}const Ff=S("block-menu-drag-handler");function t2(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 H${constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(g(Ff,e,"no dragged block"),!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:o,y:r}=t;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=ro(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Gd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(Ff,o,"no dragged block"),(l=(s=Qt(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=t2(t,"dragstart");W$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=$$(o);this.dragPreview.handleDragStart(t,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:o,y:r}=t;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:o,y:r},g(Ff,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const i=t2(t,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",t=>{var r;const e=this.button.blockMenu.currentBlock;g(Ff,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=t2(t,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new N$(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Tu{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=it(t),W(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 Tu(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class J7{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=zm(t);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),G0(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Tu.get(this.editor).highlightBlock(o)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{Lt(t).setAttribute("data-content-placeholder",R.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;const e=he(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new f$(t),this.blockMenu=new O$(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new H$(this.editor,this);const e=Ce.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new h$),Tu.register(this.editor)}destroy(){Ce.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=w("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,R.t("blockMenu.button.tips")),t.innerHTML=pv,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=iM,this.buttonElement.setAttribute(e,R.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=pv,this.buttonElement.setAttribute(e,R.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),he(this.editor,t)?this.setButtonType("insert"):this.setButtonType("move")}}const j$={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
421
+ `).map(s=>({id:K(),type:"text",text:Ri(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...t}],[o]:e},meta:{},comments:{}}}class DN{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!vc(t,r))return;const i=R0(r),s=t.getBlockData(i),{language:l,nowrap:a}=s;if(t.selection.range.isCollapsed()){const h=t.getBlockString(r);return k7(h,{language:l,nowrap:a})}const d=t.getSelectedText();return k7(d,{language:l,nowrap:a})}}function SN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!vc(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{Ro(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function LN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!vc(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{Ro(n).forEach(r=>{const i=ie(n.getBlockText(r.block));for(let s=0;s<e.length;s++){const l=e[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function MN(n){const t=n.getFocusedBlock(),e=nt(t);if(Xt(e))return;const o=et(e);if(!o||Dt(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!LA(e,r))return Zg(n,e),!0}const RN={Tab:SN,"Shift+Tab":LN,"CtrlOrCmd+A":MN},vu=S("code-text-decorate");class Sf{decorateText(t,e,o){var v;if(g(vu,e.length>0,"invalid path"),e.length===1)return{};const r=e[e.length-2];if(t.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=ie(s),a=t.doc.getBlockData(r.containerId,r.blockIndex),d=ua.default.tokenize(l,(v=ua.default.languages[a.language])!=null?v:ua.default.languages.plain),h=(B,D)=>{if(g(vu,B,"no token"),typeof B=="string")return[{insert:B,attributes:mt.default(D)}];g(vu,B instanceof ua.default.Token,"invalid token type");const x=B.content,_=mt.default(D);return _[`style-code-${B.type}`]=!0,typeof x=="string"?[{insert:x,attributes:_}]:Array.isArray(x)?x.map(z=>h(z,_)).flat():(g(vu,x instanceof ua.default.Token,"invalid token"),h(x,_))},A=d.map(B=>h(B,{})).flat();return g(vu,rn(A)===rn(s),"failed to highlight code, text length mismatch"),{text:A}}}const ON={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"}},_N={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},FN={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"}};R.mergeLang({"zh-CN":ON,"en-US":_N,"ja-JP":FN});const PN=S("image-data"),w7=1e3,j0=400,NN=10;function yc(n){return n.src.startsWith("empty:")||!n.src}function $N(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function B7(n){return`${_d.default(n)}_width`}function E7(n){return`${_d.default(n)}_height`}function x7(n){return`${n}_flex`}function I7(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function yu(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>{const i=r.height==="auto"?r.width/t:r.height/t;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/t:r.height/t,s=r.width/i;r.flex=s/o})}function kc(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=B7(r),l=E7(r),a=x7(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=w7,h=j0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),yu(e),e}function Vo(n){const t=n.embedData;return kc(n.embedData).length>1?100:t.widthPercent}function HN(n,t,e,o){const r=kc(t.embedData);if(r.length>1||o)return"100%";const i=Vo(t),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=I7(e);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=B7(l);o[a]=r.width;const d=E7(l);r.height!=="auto"&&(o[d]=r.height)}g(PN,r.flex,"no image flex");const s=x7(i);o[s]=r.flex}),o}function jN(n,t,e,o){const r=kc(t.embedData),i=r.length===1?n.rootContainer:e;if(r.length===1&&o)return`${j0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Vo(t);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==e&&(l=Math.min(l,I7(e))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*NN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const A=l*h.flex/a/h.width*h.height;d=Math.max(A,d)}return`${d}px`}function UN(n){return n.reduce((e,o)=>e+o.flex,0)}function zN(n,t){w("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function U0(n){return te(n).querySelector(".block-resizer")}function VN(n){const t=U0(n);t&&ot(t,"active")}function T7(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}function WN(n,t,e,o){const r=U0(n);if(r)return W(r,"active"),T7(n,t,r),r;const i=te(n),s=w("div",["block-resizer"],i);return T7(n,t,s),e.resize.forEach(l=>{zN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function z0(n,t){const e=U0(n);if(!e||!Kt(n,t))return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}const _nt="",qN=S("block-resizer");class ku extends ve.TypedEmitter{constructor(e,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,ga(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,A=h>l?h-l:0,v=new DOMRect(a,l,p,A);this.emit("resizing",this,v);const B=this.getResizableElement();B&&z0(this.block,B)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;ga(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||z0(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(VN(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&z0(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Lt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(g(qN,Kt(this.block,e),"not a block child element"),WN(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 GN=S("image-dom");function D7(n){return n.querySelector(".uploading-progress-mask")}function ZN(n){const t=D7(n);if(t)return t;const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e);return w("div",["uploading-progress-bar-value"],o),o}function QN(n){const e=ZN(n).querySelector(".uploading-progress-bar-value");return g(GN,e,"no progress value"),e}function S7(n,t){const e=QN(n);e.style.width=`${t}%`}function YN(n){var t;(t=D7(n))==null||t.remove()}function wu(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||nt(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=HN(n,t,i,s),a=jN(n,t,i,s),d=Lt(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function JN(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function KN(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=JN(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Yi(n,t){const e=typeof t=="string"?t:it(t);return n.getCustom(`image-${e}`)}function Lf(n,t){if(!t||!(t instanceof Node))return null;const e=et(t);return e?Yi(n,e):null}function Cr(n){return Array.from(n.querySelectorAll(".image-container"))}const V0=S("table-resize-drag-drop");class XN{constructor(t,e,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Yi(this.editor,i).getImages(),a=this.data.splitterIndex;g(V0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=Cr(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;Yi(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=Yi(this.editor,s),a=mt.default(l.getImages()),d=this.data.splitterIndex;g(V0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let A=r;h+A<50&&(A=50-h),p-A<50&&(A=p-50);const D=[...this.initWidths];D[d]+=A,D[d+1]-=A;const x=Cr(s);g(V0,x.length===a.length,"invalid image data");const _=D.reduce((z,q)=>z+q,0);for(let z=0;z<a.length;z++){const q=D[z]/_;a[z].flex=q,x[z].style.flexGrow=`${q}`}const M=mt.default(this.editor.getBlockData(s)),H=cn(a,Vo(M));M.embedData=H,wu(this.editor,M,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=Yi(this.editor,s),d=Cr(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function L7(n){var t;return!n||!(n instanceof HTMLElement)?null:xt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function t$(n,t){var s;const e=L7(t.target);if(!e)return;const o=et(e);if(!o)return;Yi(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};km(new XN(n,e,i,t))}function e$(n,t){t.preventDefault(),t.stopPropagation();const e=L7(t.target);if(!e)return;const o=et(e);!o||Yi(n,o).resetFlex()}function n$(n,t,e,o){const r=w("div",["image-splitter"],e);w("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",t$),n.domEvents.addEventListener(r,"dblclick",e$)}const o$=S("image-item");function M7(n){return!n||!(n instanceof Node)?null:et(n)}function R7(n){const t=M7(n);return t?Cr(t):[]}function W0(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 Bu(n){const t=W0(n);return t?R7(n).indexOf(t):-1}async function r$(n,t){const e=Lf(n,t.target);if(!e)return;const o=Bu(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(yc(i)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),i.height==="auto"&&e.fixImageSize(o,r),i.virtualSize&&e.fixImageSize(o,r),!i||!$N(i)||i.downloading))return;i.downloading=!0;const s=await KN(i.src);s?e.replaceImage(o,s):o$.warn(`failed to download image: ${i.src}`)}function i$(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=w("div",["load-error"],t),s=w("div",["error-icon"],i);s.innerHTML=cv;const l=w("div",["error-message"],i);r?(l.innerHTML=R.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=R.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&a$(a,d.target)}))}function q0(n,t){setTimeout(()=>{if(Kt(n.rootContainer,t)){const e=n.getBlockData(t);wu(n,e,null,null)}})}function s$(n,t){const e=Lf(n,t.target);if(!e)return;const o=Bu(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=W0(t.target);if(!i)return;W(i,"error","error-load");const s=et(i);s&&q0(n,s),i.innerHTML="",i$(n,i,r)}function l$(n,t,e){if(t.querySelector(".upload-error"))return;const r=w("div",["upload-error"],t),i=w("div",["error-icon"],r);i.innerHTML=cv;const s=w("div",["error-message"],r);s.innerHTML=R.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Lf(l,a.target),h=Bu(a.target);!d||h===-1||d.replaceImage(h,e)})}function O7(n,t,e,o,r){const i=Cr(t)[e];!i||(W(i,"error","error-upload"),q0(n,t),i.innerHTML="",l$(n,i,r))}function _7(n,t,e,o,r,i,s){const l=w("div",["image-container"],e);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),yc(o)){W(l,"empty");const d=w("div",["upload-image-icon"],l);return d.innerHTML=RL,l}const a=w("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",r$),n.domEvents.addEventListener(a,"error",s$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=w("div",["image-warning"],l);d.innerHTML=lv,d.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("image.load.remote.tooltip"))}return l}function c$(n,t,e,o,r){const i=w("div",["images"],e);return o.forEach((s,l)=>{l>0&&n$(n,t,i,l-1),_7(n,t,i,s,l,r,o)}),o.length>1&&W(t,"multi"),i}function F7(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const a=_7(n,t,null,e,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),q0(n,t)}function Eu(n,t){return Cr(n)[t]}function a$(n,t){const e=M7(t);if(!e)return;const o=Bu(t);if(o===-1)return;const r=Lf(n,t);if(!r)return;const i=r.getImages()[o];F7(n,e,i,o,r.getSelectedIndex(),r.getImages())}function Wo(n){return Dt(n)==="embed"&&fn(n)==="image"}async function P7(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function u$(n){const t=await jl(n);return P7(t)}function N7(n){var o;let t="image/*";const e=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return e&&(t=e.map(r=>`.${r}`).join(",")),t}function $7(n,t){var s;const{maxSize:e,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Ca(t.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function H7(n){return n.startsWith("image/")}const j7=S("image-object");class xe{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const o=Bu(e.target);if(o===-1)return;const r=this.images[o];yc(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||nt(e)===t&&wu(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,wu(this.editor,this.blockData,o,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",Se.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new ku(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=kc(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,o){const r=c$(this.editor,e,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Lo(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(t)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),wu(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 Vo(this.blockData)}isEmpty(){return this.images.length===1&&yc(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 r=Eu(e,this.selectedIndex);r&&ot(r,"active")}this.selectedIndex=t;const o=Eu(e,t);o&&W(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=Eu(e,t);if(xt(o,"error"))return;const r=N7(this.editor),i=await Ul(r);await this.replaceImage(t,i)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Eu(t,0);!this.isEmpty()&&this.images.length===1&&!xt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];yc(o)||(o.height==="auto"&&(o.height=e.height),o.width=e.naturalWidth,o.height=e.naturalHeight,o.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 o=mt.default(this.images);if(o.splice(t,1),o.length===0)return this.editor.deleteBlock(e),!0;o[0].flex=NaN,yu(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Vo(this.blockData));return this.editor.updateEmbedData(e,r),!0}async replaceImage(t,e){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await jl(e),s=this.images[t];if(s.virtualSize){const{width:a,height:d}=await P7(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};F7(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return O7(this.editor,o,t,i,e),!1}const r=Eu(o,t);if(!r)return!1;W(r,"uploading"),S7(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(e,{onProgress:a=>{S7(r,a)}});ot(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=cn(this.images,Vo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){j7.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(r,"uploading"),YN(r),O7(this.editor,s,t,i,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;g(j7,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,yu(e);const o=cn(e,Vo(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=kc(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new xe(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=it(e),t.getCustom(`image-${o}`)}}const Fnt="",Pnt="";function Mf(n){const t=te(n);let e=t.querySelector(":scope > .block-helper");return e||(e=w("div",["block-helper"],t),w("span",["helper-sizer"],e,"A")),e}function G0(n,t,e){const o=Mf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const U7=40,d$=20;class h${findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const a=et(o);if(a&&Kt(t.rootContainer,a))return a}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<U7&&(r+=U7);let l=document.elementFromPoint(r,i);if(l){const a=et(l);if(a&&Kt(t.rootContainer,a))return a}if(i-=d$,l=document.elementFromPoint(r,i),l){const a=et(l);if(a&&Kt(t.rootContainer,a))return a}return null}destroy(){}}class f$ extends Cf{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function m$(n,t,e){const o=Vm(n,t);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{e!=null&&e.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function Z0(n,t,e={withPlainText:!1}){const o=I0(n,e),r=i=>{i.forEach(s=>{s.source=t,s.children&&r(s.children)})};return r(o),o}function g$(n,t,e,o=!1){var d,h;const r=nt(t);let s=bt(t);he(n,t)||o||(s+=1);const l=at(r),a=e;return a.commandProvider?a.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:e})}function p$(n,t){const e=Do(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class z7{constructor(t,e,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=k0();this.createItem("text",eu,e,p$(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=Dt(t)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",mv,e,a),this.createItem("ordered-list",gv,e,d),this.createItem("check-list",hv,e,h)});m(this,"handleClick",(t,e)=>{var l,a;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&gf(t,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&gf(t,this.block,d)}if(i==="blockquote"&&b0(t,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");T9(t,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&y0(t,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=w("div",["text-styles"],null),r=w("div",["text-style-section"],o),i=t.getBlockData(e);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(e,r,l),this.createListItemElement(e,r,i),this.createItem("blockquote",fv,r,!!a)}const s=i.align||"left";return this.createItem("align-left",Xa,r,s==="left"),this.createItem("align-center",Dp,r,s==="center"),this.createItem("align-right",Tp,r,s==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=$l(e,i,o);s.id=t}}function V7(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const W7={copy:YL,cut:JL,delete:KL,"lock-block":XL,"unlock-block":tM,comment:tu},C$=["image","video"];function A$(n,t,e){const o=[],r=tt(n,t),i=Me(t)&&C$.includes(fn(t)),s=i&&(fn(t)!=="image"||fn(t)==="image"&&Cr(t).length===1);if(r?o.push(new z7(n,t,e)):i&&s&&o.push(new z7(n,t,{...e,fromEmbed:!0})),!he(n,t)){(r||i&&s)&&o.push(V7());const l=m$(n,t,new Set(["hovering-toolbar"]));l.sort((a,d)=>{var h,p;return((h=a.order)!=null?h:0)-((p=d.order)!=null?p:0)}),l.forEach(a=>{a.id in W7&&(a.icon=W7[a.id])}),o.push(...l)}return he(n,t)?o.push(...Z0(n,"insert-block")):o.push(V7(),{id:"insert-block-before",icon:eM,name:R.t("blockMenu.command.insertAbove"),children:Z0(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:nM,name:R.t("blockMenu.command.insertAfter"),children:Z0(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function b$(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;a4(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&g$(n,t,e,e.source==="insert-block-before")}const v$=S("exclusive-block");function Q0(n,t,e,o){var l;W(t,"block-exclusive");const r=Qt(n,t),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,t),{abstract:s}=i||{};t.setAttribute("data-user-name",o),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",R.t("exclusive.tips",{editor:o,embedType:s||R.t("exclusive.fallbackAbstract")}))}function q7(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function y$(n,t,e,o,r){v$.debug(`block ${it(t)} ${e?"exclusive":"unexclusive"}, ${o}, ${r}`),e?Q0(n,t,o,r):q7(t)}function Rf(n){return n.classList.contains("block-exclusive")}function G7(n,t){t.blockIds.forEach(e=>{const o=n.findBlockById(e);o&&y$(n,o,t.exclusive,t.userId,t.displayName)})}class Ji{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!e.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};G7(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!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;G7(this.editor,e),e.blockIds.forEach(o=>{e.exclusive?this.remoteExclusiveBlockIds.set(o,e):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:t.map(i=>it(i)),exclusive:e};this.editor.doc.broadcastMessage(r)}exclusiveBlock(t){this.exclusiveBlockIds.has(it(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(it(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(it(t))||(this.exclusiveBlockIds.delete(it(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 Ji(t))}static register(t){return this.get(t)}}function Y0(n,t){Ji.get(n).exclusiveBlock(t)}function J0(n,t){Ji.get(n).unexclusiveBlock(t)}class Z7{writable(t,e){if(Rf(e))return!1}create(t,e,o,r,i){const s=Ji.get(t).getExclusiveMessage(i.id);s&&Q0(t,r,s.userId,s.displayName)}update(t,e,o,r,i){const s=Ji.get(t).getExclusiveMessage(i.id);s?Q0(t,r,s.userId,s.displayName):q7(r)}}const Nnt="",k$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},w$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},B$={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"}};R.mergeLang({"zh-CN":k$,"en-US":w$,"ja-JP":B$});function xu(n,t){return n.getBlockData(t).lock}function Of(n,t){return!!xu(n,t)}function Iu(n,t){const e=xu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function K0(n,t){const e=xu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function E$(n,t){if(n.readonly||!n.isBlockWritable(t)||Of(n,t)&&!Iu(n,t))return;const e=n.doc.getUser(),o={userId:e.userId,displayName:e.displayName,locked:Date.now()},i={...n.getBlockData(t),lock:o};n.updateBlockData(t,i)}function x$(n,t){if(!Iu(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const I$=10,T$=80;class X0{constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?E$(t,i):r.type==="unlock"&&x$(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(t,e,o,r,i){const s=i.lock;if(s)if(s.userId!==t.doc.getUser().userId){W(r,"locked-by-others");const l=t.selection.focusedBlock;(l===r||Kt(r,l))&&(tt(t,r)||Dt(r)==="code")&&t.insertTextBlock("",at(o),bt(r)+1)}else W(r,"locked-by-self");else ot(r,"locked-by-others"),ot(r,"locked-by-self")}writable(t,e){if(K0(t,e))return!1;if(io(e))return;let o=xs(e);for(;o;){if(K0(t,o))return!1;o=xs(o)}}commands(t,e){const o=Of(t,e),r=Iu(t,e),i=Rf(e),s={blockId:it(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=R.t("locker.unlock"),s.type="unlock";else{const a=xu(t,e);let d=(a==null?void 0:a.displayName)||"";const h=MC(d,I$,T$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=R.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=R.t("locker.lock"),l.states=["disabled"]):l.name=R.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const $nt="",D$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},S$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},L$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":D$,"en-US":S$,"ja-JP":L$});class _f{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const M$=S("standard-block-actions");class R${constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&Oh(t,i),o.id==="cut"&&(Oh(t,i),t.deleteBlock(i))}catch(i){M$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=Of(t,e),r=o&&Iu(t,e),i=it(e),s=$0(),l=Rf(e),a={id:"copy",name:R.t("blockMenu.command.copy"),data:i,order:1,states:s?[]:["disabled"],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})},d={id:"cut",name:R.t("blockMenu.command.cut"),data:i,order:2,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+X"),operation:R.t("copyCutProperty.cut")})},h={id:"delete",name:R.t("blockMenu.command.delete"),data:i,order:3,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const Q7=S("block-menu");class O${constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(Q7,this.currentBlock,"no target block before show block menu");const t=A$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{g(Q7,this.commandBlock,"no command block before show block menu"),b$(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new zs([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new R$)}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 _$=1e3;async function F$(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),o=t.getBoundingClientRect();return o.width>e||o.height>=_$?"":(await G5.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const P$=S("drag-preview-image");class N${constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const o=t.target;g(P$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=t;this.startPosition={x:r,y:i};const s=w("div",["drag-image-container"],this.editor.rootContainer),l=w("img",["drag-image"],s),a=w("span",["drag-loading"],s);a.innerHTML=sM;const{x:d,width:h,height:p,y:A}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${A+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const x=await F$(this.editor,e);x?l.src=x:W(s,"drag-placeholder"),Am(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const Y7="drag-preview-element";function $$(n){if(xt(n,Y7))return n;const t=n.querySelector(`.${Y7}`);return t||(Me(n)?Lt(n):n)}const Ff=S("block-menu-drag-handler");function t2(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 H${constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(g(Ff,e,"no dragged block"),!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:o,y:r}=t;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=ro(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Gd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(Ff,o,"no dragged block"),(l=(s=Qt(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=t2(t,"dragstart");W$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=$$(o);this.dragPreview.handleDragStart(t,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:o,y:r}=t;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:o,y:r},g(Ff,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const i=t2(t,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",t=>{var r;const e=this.button.blockMenu.currentBlock;g(Ff,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=t2(t,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new N$(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Tu{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=it(t),W(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 Tu(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class J7{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=zm(t);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),G0(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Tu.get(this.editor).highlightBlock(o)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{Lt(t).setAttribute("data-content-placeholder",R.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;const e=he(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new f$(t),this.blockMenu=new O$(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new H$(this.editor,this);const e=Ce.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new h$),Tu.register(this.editor)}destroy(){Ce.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=w("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,R.t("blockMenu.button.tips")),t.innerHTML=pv,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=iM,this.buttonElement.setAttribute(e,R.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=pv,this.buttonElement.setAttribute(e,R.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),he(this.editor,t)?this.setButtonType("insert"):this.setButtonType("move")}}const j$={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
422
422
  \u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},U$={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
423
423
  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"}}};R.mergeLang({"zh-CN":j$,"en-US":U$,"ja-JP":z$});const Hnt="";class V${constructor(){m(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Pf(n){return n.addCustom("drag-data",()=>new V$)}function e2(n,t){if(!t)return null;const e=Pf(n).getData();return!e||e.editorId!==n.id?null:e}function K7(n,t){const e=e2(n,t);return e?n.findBlockById(e.blockId):null}function W$(n,t,e){if(!t.dataTransfer)return;const r=nt(e),i=at(r),s=it(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};Pf(n).setData(l)}function q$(n,t,e,o,r){if(!t.dataTransfer)return;const s=nt(e),l=at(s),a=it(e),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Pf(n).setData(d)}function G$(n){Pf(n).clearData()}const Z$=S("drop-indicator"),Nf=2;class Q${constructor(t){m(this,"indicator");m(this,"target",null);this.editor=t,this.indicator=w("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.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 s=Ts(t);if(!s){g(Z$,Lo(nt(t)),"block does not in a child container");const d=t.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Nf)}const l=s.getBoundingClientRect(),a=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Nf)}const o=Ds(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Nf)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Nf)}}const Y$=S("find-drop-target");function J$(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(Pr(e)&&Lo(e))return e;const o=e.firstElementChild;return o&&Pr(o)&&Lo(o)?o:null}function K$(n,t){const s=t,l=n;for(let a=0;a<2;a++){const d=l+a*50;for(let h=0;h<5;h++){const p=s+h*8,A=document.elementFromPoint(d,p);if(A){const D=et(A);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=et(B);if(D)return D}}}return null}function X$(n,t,e){const o=document.elementFromPoint(t,e);if(o){const h=et(o);if(h&&!Mt(n,h))return h}const r=new Set,i=J$(t,e);if(i){const h=i.getBoundingClientRect();e<h.top+h.height/2?r.add(Le(i)):r.add(Ze(i))}const s=K$(t,e);s&&r.add(s);const l=Array.from(r),a=h=>{for(let p=0;p<l.length;p++){const A=l[p];if(h!==A&&Kt(h,A))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function n2(n,t){if(n.readonly)return!1;const e=nt(t);if(Xt(e))return!0;const o=et(e);return g(Y$,o,"no parent block"),n.isBlockWritable(o)?n2(n,o):!1}const tH=S("drop-target");function eH(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")),g(tH,e,`unSupport file type ${t.type}`),e}async function X7(n,t,e,o){var i,s;let r=o;for(const l of t){const a=eH(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:e,blockIndex:r,data:{file:l}}))&&(r+=1)}}class nH{constructor(t){m(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){const s=at(o);return X7(t,i,s,r),!0}}return!1});this.editor=t}}class Du{constructor(t){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{var d,h;const s=e2(this.editor,i.dataTransfer),l=K7(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&Kt(this.editor.rootContainer,a)){const p=this.findInsertPos(l,a,i.x,i.y,(h=s!=null?s:(d=i.dataTransfer)==null?void 0:d.items)!=null?h:null);if(p)return this.indicator.show(a,p),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});m(this,"handleDrop",t=>{var i,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=e2(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=K7(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:o,a,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus();return}if(d){const p=Qt(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,e!=null?e:o,a,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=nt(l);let A=bt(l);a==="after"&&(A+=1),t.preventDefault();for(let v=0;v<this.handlers.length;v++)if(this.handlers[v].handleDrop(this.editor,d!=null?d:o,p,A)){this.editor.focus();return}if(d){const v=this.editor.getBlockData(d),B=_i(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,A,B);this.editor.selection.selectBlock(D,0),Tu.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),G$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new Q$(this.editor),this.handlers.push(new nH(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 Du(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||Ds(e)===t&&t||!n2(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Ts(e)===t&&t||!n2(this.editor,e)||Xt(nt(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!Kt(t,e)}findTargetBlock(t,e,o){let r=X$(this.editor,e,o);if(!r||!Kt(this.editor.rootContainer,r))return null;const i=nt(r),s=et(i);return s&&Dt(s)==="code"&&(r=s),this.canDrop(t,r)?r:null}findInsertPos(t,e,o,r,i){let s=e;for(;s;){const a=Qt(this.editor,s);if(a.handleDropOver){const d=a.handleDropOver(this.editor,s,i,o,r);if(d)return d;if(d===!1)return null}s=xs(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<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 r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}function ty(n,t,e){const o=xe.getImageObject(n,t),r=mt.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=UN(r);if(r.splice(e,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(t,d);return}r[0].flex=NaN,yu(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(t,s)}function oH(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=xe.getImageObject(n,e),s=mt.default(i.getImages()),l=[],a=[];t.forEach(p=>{H7(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{$7(n,p)}catch{return}const A={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,A);const v=cn(s,i.getWidthPercent());n.updateEmbedData(e,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(e)+1,h=at(nt(e));return X7(n,a,h,d),!0}function rH(n,t,e,o,r){var s,l,a;if(Wd(e))return oH(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const d=r.targetBlock,h=nt(d);let p=bt(d);o==="after"&&(p+=1);const v=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),B=cn([i.image],v),D={id:K(),type:"embed",embedType:"image",embedData:B},x=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;x&&(D.align=x),n.insertBlock(at(h),p,D),ty(n,t,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=t;let h=o.data;const p=xe.getImageObject(n,d),A=mt.default(p.getImages());h>A.length&&(h=A.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(e.blockId);if(v===d){const x=i.index,_=h,M=i.image;if(x===_||_===x+1)return;let H=_;x<_?(A.splice(_,0,M),A.splice(x,1),H-=1):(A.splice(x,1),A.splice(_,0,M));const z=cn(A,p.getWidthPercent());n.updateEmbedData(d,z),p.setSelectedIndex(H),(B=n.findCustom("drag-handler"))==null||B.handleDragEnd()}else{A.splice(h,0,i.image),A[0].flex=NaN,yu(A);const x=cn(A,p.getWidthPercent());n.updateEmbedData(d,x),ty(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const iH=2;function $f(n,t,e){const o=Cr(t);if(e<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===o.length){const s=o[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[e-1].getBoundingClientRect(),i=o[e].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,iH,r.height)}function sH(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:$f(n,t,i),data:i}:{rect:$f(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:$f(n,t,e.length),data:e.length}:{rect:$f(n,t,e.length),data:0}}function lH(n,t,e,o,r){const i=Cr(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>H7(s.type))||i.length>=6)return}else{if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==it(t))return;const s=it(t);if(i.length===1&&s===(e==null?void 0:e.blockId))return}return sH(n,t,i,o)}async function cH(n){return await G5.default.toSvg(n)}function o2(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 aH{constructor(t){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement))return;const o=et(e);if(!o||!Wo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=xe.getImageObject(this.editor,o);if(this.imageContainer=W0(t.target),!this.imageContainer)return;const s=R7(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=t;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=o2(t,"dragstart");q$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});m(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=et(this.imageContainer);if(!e)return;const{x:o,y:r}=t,{width:i,height:s}=t.target.getBoundingClientRect(),l=te(e),a=w("div",["drag-container"],l);a.style.left=`${o-i/4}px`,a.style.top=`${r-s/4}px`,a.style.width=`${Math.max(i/2,16)}px`,a.style.height=`${s/2}px`,this.dragContainer=a;const d=w("img",["drag-target"],a),p=await cH(this.imageContainer);p&&(d.src=p),W(this.editor.contentElement,"dragging");const A=ro(e);this.autoScroll=new Gd({scrollElement:A,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active()});m(this,"handleDrag",t=>{var i;const{x:e,y:o}=t;if(((i=this.startPosition)==null?void 0:i.x)===e&&this.startPosition.y===o)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:a,y:d}=this.startPosition,h=s-a,p=l-d;this.dragContainer.style.transform=`translate(${h}px, ${p}px)`,this.dragContainer.style.opacity="0.5"}const r=o2(t,"dragover");this.editor.contentElement.dispatchEvent(r)});m(this,"handleDragEnd",t=>{var e;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(e=this.autoScroll)==null||e.inactive(),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const o=o2(t,"drop");this.editor.contentElement.dispatchEvent(o)}});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 uH{constructor(t){m(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&Wo(i)){const s=xe.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&Wo(o)&&xe.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class dH{constructor(t){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(t,e)=>{e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t))});this.editor=t,Ce.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){Ce.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){Wo(t)&&xe.getImageObject(this.editor,t).disableResizer()}enable(t){if(Wo(t)){const e=xe.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const hH={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"}},fH={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"}},mH={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"}};R.mergeLang({"zh-CN":hH,"en-US":fH,"ja-JP":mH});function gH(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o),l=ie(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return Ul("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=e+1;ie(n.getBlockText(r)).trim()?(Ql(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),Wm(n,"image",t,p,{file:h})})}),!0}class pH{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&gH(t,e,o,r))}}function CH(n){const t=n.getFocusedBlock(),e=Ds(t);if(e&&Wo(e)){n.selection.selectBlock(e,0);const o=xe.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function AH(n){const t=n.getFocusedBlock(),e=Ts(t);if(e&&Wo(e)){n.selection.selectBlock(e,0);const o=xe.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function bH(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=xe.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(r.length-1),!0;if(i>0)return o.setSelectedIndex(i-1),!0}}}function vH(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=xe.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(0),!0;if(i<r.length-1)return o.setSelectedIndex(i+1),!0}}}function r2(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=xe.getImageObject(n,e);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const yH={ArrowLeft:bH,ArrowRight:vH,ArrowUp:AH,ArrowDown:CH,Delete:r2,Backspace:r2},kH=S("copy-image");function wH(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=cn([r],i),l={id:K(),type:"embed",embedType:"image",embedData:s},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(l.align=a.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const p=h.getContext("2d");if(!p)return;const A={},v={};try{p.drawImage(t,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),q=Tm(z),rt=new File([q],`${Date.now()}.png`,{type:"image/png"});A["image/png"]=rt}catch(H){kH.error(H)}Rh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,x=Mh(D,d),_=La(n,d);A["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const M=new Blob([x],{type:"text/html"});return A["text/html"]=M,v["text/html"]=x,[A,v]}function BH(n,t,e,o,r){const i=wH(n,t,e,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Lm(a).then(d=>{if(!d&&r){const h=r.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function ey(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const r=n.getFocusedBlock();if(r&&Wo(r)){const i=xe.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=Cr(r)[l].querySelector("img");if(d)return BH(n,d,i,l,t)}}}}class EH{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,o){if(ey(t,e))return!0}handleBeforeCut(t,e){if(ey(t,e))return r2(t),!0}destroy(){}}class i2{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,o){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{if(i.type==="embed"&&i.embedType==="image"){const s=i.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=o.blockIdMap.get(i.id);l&&Yi(t,l).setAutoFix(!0)}}})}),!1}destroy(){}}const xH=S("image-embed");function IH(n,t,e,o,r,i){xe.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new uH(n)),n.addCustom("image-copy-handler",()=>new EH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new aH(n));const l=n.addCustom("image-resizer",()=>new dH(n)),a=e.embedData;yc(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function TH(n,t,e,o){const r=t.embedData,i=kc(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`![img](${n.doc.buildResourceUrl(l.src,{withToken:!0})})`).join(`
424
424
  `)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.3-beta.184",
3
+ "version": "0.0.3-beta.185",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",