@ones-editor/editor 0.0.3-beta.172 → 0.0.3-beta.173

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
@@ -420,7 +420,7 @@ ${s}
420
420
  Click to open the menu`,insertTips:"Click to add block"}}},N$={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":F$,"en-US":P$,"ja-JP":N$});const One="";class $${constructor(){m(this,"dragObject",null)}setData(e){this.dragObject=e}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Pf(n){return n.addCustom("drag-data",()=>new $$)}function o2(n,e){if(!e)return null;const t=Pf(n).getData();return!t||t.editorId!==n.id?null:t}function J7(n,e){const t=o2(n,e);return t?n.findBlockById(t.blockId):null}function H$(n,e,t){if(!e.dataTransfer)return;const r=ne(t),i=ae(r),s=ie(t),l={type:"block",editorId:n.id,containerId:i,blockId:s};Pf(n).setData(l)}function j$(n,e,t,o,r){if(!e.dataTransfer)return;const s=ne(t),l=ae(s),a=ie(t),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Pf(n).setData(d)}function U$(n){Pf(n).clearData()}const z$=S("drop-indicator"),Nf=2;class V${constructor(e){m(this,"indicator");m(this,"target",null);this.editor=e,this.indicator=w("div",["editor-drop-indicator"],this.editor.contentElement)}show(e,t){const o=this.getIndicatorRect(e,t),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:e,insertPos:t}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(e,t){if(typeof t!="string")return t.rect;if(t==="before"){const s=Ss(e);if(!s){g(z$,Do(ne(e)),"block does not in a child container");const d=e.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Nf)}const l=s.getBoundingClientRect(),a=e.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Nf)}const o=Ls(e);if(!o){const s=e.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Nf)}const r=e.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Nf)}}const W$=S("find-drop-target");function q$(n,e){const t=document.elementFromPoint(n,e);if(!t)return null;if(_r(t)&&Do(t))return t;const o=t.firstElementChild;return o&&_r(o)&&Do(o)?o:null}function G$(n,e){const s=e,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=oe(A);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=oe(B);if(D)return D}}}return null}function Z$(n,e,t){const o=document.elementFromPoint(e,t);if(o){const h=oe(o);if(h&&!Le(n,h))return h}const r=new Set,i=q$(e,t);if(i){const h=i.getBoundingClientRect();t<h.top+h.height/2?r.add(St(i)):r.add(Gt(i))}const s=G$(e,t);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&&Ke(h,A))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function r2(n,e){if(n.readonly)return!1;const t=ne(e);if(Xe(t))return!0;const o=oe(t);return g(W$,o,"no parent block"),n.isBlockWritable(o)?r2(n,o):!1}const Q$=S("drop-target");function Y$(n,e){let t={};return/image/.test(e.type)?t=n.editorEmbeds.getEmbedClass("image"):/audio/.test(e.type)?t=n.editorEmbeds.getEmbedClass("audio"):/video/.test(e.type)&&(t=n.editorEmbeds.getEmbedClass("video")),g(Q$,t,`unSupport file type ${e.type}`),t}async function K7(n,e,t,o){var i,s;let r=o;for(const l of e){const a=Y$(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:t,blockIndex:r,data:{file:l}}))&&(r+=1)}}class J${constructor(e){m(this,"handleDrop",(e,t,o,r)=>{if(Array.isArray(t)){const i=t;if(i.length>0){const s=ae(o);return K7(e,i,s,r),!0}}return!1});this.editor=e}}class Su{constructor(e){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",e=>{if(!this.editor.isWritable())return;const t=i=>{var d,h;const s=o2(this.editor,i.dataTransfer),l=J7(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&Ke(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&&e.x===this.lastDropOverResult.x&&e.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(e,i);return}const r=t(e);o(e,r),this.lastDropOverResult={x:e.x,y:e.y,dropEffect:r}});m(this,"handleDrop",e=>{var i,s;e.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const t=o2(this.editor,e.dataTransfer),o=Array.from((s=(i=e.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!t&&o.length===0){e.dataTransfer&&(e.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=J7(this.editor,e.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qe(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,t!=null?t:o,a,{isSourceBlock:!1,targetBlock:l})){e.preventDefault(),this.editor.focus();return}if(d){const p=Qe(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,t!=null?t:o,a,{isSourceBlock:!0,targetBlock:l})){e.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=ne(l);let A=be(l);a==="after"&&(A+=1),e.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=Fi(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,A,B);this.editor.selection.selectBlock(D,0),Du.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),U$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=e,this.indicator=new V$(this.editor),this.handlers.push(new J$(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(e){this.handlers.push(e)}static register(e){return e.addCustom("drop-target",()=>new Su(e))}static get(e){return e.getCustom("drop-target")}static find(e){return e.findCustom("drop-target")}canInsertAfter(e,t){return!(this.editor.readonly||Ls(t)===e&&e||!r2(this.editor,t))}canInsertBefore(e,t){return!(this.editor.readonly||Ss(t)===e&&e||!r2(this.editor,t)||Xe(ne(t))&&be(t)===0)}canDrop(e,t){return e===null||e===t?!0:!Ke(e,t)}findTargetBlock(e,t,o){let r=Z$(this.editor,t,o);if(!r||!Ke(this.editor.rootContainer,r))return null;const i=ne(r),s=oe(i);return s&&De(s)==="code"&&(r=s),this.canDrop(e,r)?r:null}findInsertPos(e,t,o,r,i){let s=t;for(;s;){const a=Qe(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=Ts(s)}if(e===t)return"";const l=t.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<l.top+l.height/2){if(this.canInsertBefore(e,t))return"before";if(this.canInsertAfter(e,t))return"after"}else{if(this.canInsertAfter(e,t))return"after";if(this.canInsertBefore(e,t))return"before"}return""}return r<l.top&&this.canInsertBefore(e,t)?"before":l.bottom<r&&this.canInsertAfter(e,t)?"after":""}}function X7(n,e,t){const o=xt.getImageObject(n,e),r=me.default(o.getImages());if(r.length===1){n.deleteBlock(e);return}if(t===-1||t>=r.length)return;const i=PN(r);if(r.splice(t,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(e,d);return}r[0].flex=NaN,ku(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(e,s)}function K$(n,e,t,o){if(e.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=xt.getImageObject(n,t),s=me.default(i.getImages()),l=[],a=[];e.forEach(p=>{$7(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{N7(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(t,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(t)+1,h=ae(ne(t));return K7(n,a,h,d),!0}function X$(n,e,t,o,r){var s,l,a;if(Wd(t))return K$(n,t,e,o);if(t.type!=="custom"||t.customType!=="image"||!t.data)return;const i=t.data;if(r.isSourceBlock){const d=r.targetBlock,h=ne(d);let p=be(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},T=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;T&&(D.align=T),n.insertBlock(ae(h),p,D),X7(n,e,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=e;let h=o.data;const p=xt.getImageObject(n,d),A=me.default(p.getImages());h>A.length&&(h=A.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(t.blockId);if(v===d){const T=i.index,_=h,M=i.image;if(T===_||_===T+1)return;let H=_;T<_?(A.splice(_,0,M),A.splice(T,1),H-=1):(A.splice(T,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,ku(A);const T=cn(A,p.getWidthPercent());n.updateEmbedData(d,T),X7(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const eH=2;function $f(n,e,t){const o=Qr(e);if(t<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(t===o.length){const s=o[t-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[t-1].getBoundingClientRect(),i=o[t].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,eH,r.height)}function tH(n,e,t,o,r){for(let i=0;i<t.length;i++){const l=t[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:$f(n,e,i),data:i}:{rect:$f(n,e,i+1),data:i+1}}return o>t[t.length-1].getBoundingClientRect().right?{rect:$f(n,e,t.length),data:t.length}:{rect:$f(n,e,t.length),data:0}}function nH(n,e,t,o,r){const i=Qr(e);if(t instanceof DataTransferItemList){if(!Array.from(t).some(s=>$7(s.type))||i.length>=6)return}else{if((t==null?void 0:t.type)==="block"||i.length>=6&&(t==null?void 0:t.blockId)!==ie(e))return;const s=ie(e);if(i.length===1&&s===(t==null?void 0:t.blockId))return}return tH(n,e,i,o)}async function oH(n){return await Q5.default.toSvg(n)}function i2(n,e){return new DragEvent(e,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class rH{constructor(e){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",e=>{const t=e.target;if(!t||!(t instanceof HTMLImageElement))return;const o=oe(t);if(!o||!zo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=xt.getImageObject(this.editor,o);if(this.imageContainer=G0(e.target),!this.imageContainer)return;const s=M7(e.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=e;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=i2(e,"dragstart");j$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),e.preventDefault()});m(this,"handleDragStart",async e=>{if(!this.imageContainer)return;const t=oe(this.imageContainer);if(!t)return;const{x:o,y:r}=e,{width:i,height:s}=e.target.getBoundingClientRect(),l=lt(t),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 oH(this.imageContainer);p&&(d.src=p),W(this.editor.contentElement,"dragging");const A=oo(t);this.autoScroll=new Gd({scrollElement:A,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active()});m(this,"handleDrag",e=>{var i;const{x:t,y:o}=e;if(((i=this.startPosition)==null?void 0:i.x)===t&&this.startPosition.y===o)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(e)),this.startPosition&&this.dragContainer){const{x:s,y:l}=e;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=i2(e,"dragover");this.editor.contentElement.dispatchEvent(r)});m(this,"handleDragEnd",e=>{var t;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(t=this.autoScroll)==null||t.inactive(),te(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),e){const o=i2(e,"drop");this.editor.contentElement.dispatchEvent(o)}});this.editor=e,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 iH{constructor(e){m(this,"handleFocusBlockChanged",(e,t,o)=>{const i=this.editor.getFocusedBlock();if(i&&zo(i)){const s=xt.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&zo(o)&&xt.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=e,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class sH{constructor(e){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(e,t)=>{t&&this.disable(t),e&&(this.currentResizer=e,this.enable(e))});this.editor=e,pt.get(e).addListener("change",this.handleHoveringBlockChange)}destroy(){pt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(e){zo(e)&&xt.getImageObject(this.editor,e).disableResizer()}enable(e){if(zo(e)){const t=xt.getImageObject(this.editor,e);this.editor.isBlockWritable(e)&&t.tryEnableResizer()}}}const lH={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"}},cH={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"}},aH={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":lH,"en-US":cH,"ja-JP":aH});function uH(n,e,t,o){const r=n.getBlockByIndex(e,t),i=n.getBlockText(r),{left:s}=xn(i,o),l=rt(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return zl("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=t+1;rt(n.getBlockText(r)).trim()?(Yl(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),qm(n,"image",e,p,{file:h})})}),!0}class dH{handleAfterInsertText(e,t,o,r,i){return!!(i===" "&&uH(e,t,o,r))}}function hH(n){const e=n.getFocusedBlock(),t=Ls(e);if(t&&zo(t)){n.selection.selectBlock(t,0);const o=xt.getImageObject(n,t);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function fH(n){const e=n.getFocusedBlock(),t=Ss(e);if(t&&zo(t)){n.selection.selectBlock(t,0);const o=xt.getImageObject(n,t);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function mH(n){const t=n.getFocusedBlock();if(t&&zo(t)){const o=xt.getImageObject(n,t),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 gH(n){const t=n.getFocusedBlock();if(t&&zo(t)){const o=xt.getImageObject(n,t),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 s2(n){const t=n.getFocusedBlock();if(t&&zo(t)){const o=xt.getImageObject(n,t);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const pH={ArrowLeft:mH,ArrowRight:gH,ArrowUp:fH,ArrowDown:hH,Delete:s2,Backspace:s2},CH=S("copy-image");function AH(n,e,t,o){const r=t.getImages()[o],i=t.getImages().length===1?t.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=e.naturalWidth,h.height=e.naturalHeight;const p=h.getContext("2d");if(!p)return;const A={},v={};try{p.drawImage(e,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),q=Dm(z),re=new File([q],`${Date.now()}.png`,{type:"image/png"});A["image/png"]=re}catch(H){CH.error(H)}Mh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,T=Lh(D,d),_=Ma(n,d);A["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const M=new Blob([T],{type:"text/html"});return A["text/html"]=M,v["text/html"]=T,[A,v]}function bH(n,e,t,o,r){const i=AH(n,e,t,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Mm(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 e8(n,e){const t=n.selection.range;if(t.start.blockId!==t.end.blockId)return;const r=n.getFocusedBlock();if(r&&zo(r)){const i=xt.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=Qr(r)[l].querySelector("img");if(d)return bH(n,d,i,l,e)}}}}class vH{constructor(e){this.editor=e,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(e,t,o){if(e8(e,t))return!0}handleBeforeCut(e,t){if(e8(e,t))return s2(e),!0}destroy(){}}class l2{constructor(e){this.editor=e,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(e,t,o){return Object.values(t.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&&Ki(e,l).setAutoFix(!0)}}})}),!1}destroy(){}}const yH=S("image-embed");function kH(n,e,t,o,r,i){xt.create(n,t).createContent(r,i,e),n.addCustom("image-select-handler",()=>new iH(n)),n.addCustom("image-copy-handler",()=>new vH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new rH(n));const l=n.addCustom("image-resizer",()=>new sH(n)),a=t.embedData;kc(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function wH(n,e,t,o){const r=e.embedData,i=wc(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(`
421
421
  `)}
422
422
  `:i.map(s=>n.doc.buildResourceUrl(s.src,{withToken:!0})).join(`
423
- `)}class BH{constructor(){m(this,"group","image");m(this,"commands",[])}executeCommand(e,t,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;xt.getImageObject(e,r).replaceImage(0,i)}}}function EH(){return{blockCommands:{image:new BH},abstract:`${R.t("image.abstract")}`}}function xH(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:R.t("image.abstract"),icon:EL,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,e)=>{var v;let t;(v=e.data)!=null&&v.file&&(t=e.data.file);const o=P7(n);if(t=t!=null?t:await zl(o),!t)return null;try{N7(n,t)}catch{return null}let r={width:k7,height:z0};try{r=await i$(t)}catch(B){yH.error(B)}const i=n.rootContainer.clientWidth,s=r.width<i?Math.min(100,r.width/i*100):100,l={src:"",width:r.width,height:r.height,flex:1,virtualSize:!1},a=cn([l],s),d={id:K(),type:"embed",embedType:"image",embedData:a},h=n.options.componentsOptions.image;h!=null&&h.defaultAlign&&(d.align=h.defaultAlign);const p=n.insertBlock(e.containerId,e.blockIndex,d);return xt.getImageObject(n,p).replaceImage(0,t),p}}}function IH(n,e,t){var h;const{data:o}=t,r=n.getBlockString(e).trim();if(!o||o.embedType!=="image"||!ee(n,e))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(h=i==null?void 0:i.groups)==null?void 0:h.filename;if(!s)return null;const l={src:s},a={id:K(),type:"embed",embedType:"image",embedData:l};xt.create(n,a).setAutoFix(!0);const d=n.options.componentsOptions.image.defaultAlign;return d&&(a.align=d),{blockData:a}}function TH(n,e){const t=ie(e);n.destroyCustom(`image-${t}`)}const t8={embedType:"image",createEmbedContent:kH,convertTo:wH,convertFrom:IH,getBlockProperties:EH,getOptions:xH,handleDrop:X$,handleDropOver:nH,handleDeleteBlock:TH};class DH{constructor(e,t){m(this,"toolbar");m(this,"anchor",null);m(this,"item");m(this,"docs",null);m(this,"checkedId");m(this,"handlePasteSpecial",(e,t)=>{!t.data||(this.checkedId===t.id?this.checkedId=void 0:this.checkedId=t.id,this.onPasteSpecial(t.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});m(this,"handleClose",()=>{this.editor.focus()});m(this,"handleSelectionChange",()=>{this.hide()});this.editor=e,this.onPasteSpecial=t,this.item={id:"paste-special",name:"",icon:xL,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ou([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(e){this.docs=e;const t=this.editor,o=t.selection.range;if(!o.isCollapsed())return;const r=t.getBlockById(o.start.blockId);if(!ee(t,r))return;const i=Ti(t,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=Li(t,r,"paste-special-button-anchor",i);const s=this.getCommandItems(e);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close("selectionChange")}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(e){const t=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:R.t("pasteSpecial.originFormats"),data:e[i]}),o=[];let r=!0;return e["text/x-ones-editor-doc"]?o.push(t("text/x-ones-editor-doc")):e["text/office-html"]?o.push(t("text/office-html")):e["text/html"]?o.push(t("text/html")):e["text/plain"]&&(o.push(t("text/plain")),r=!1),e["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:R.t("pasteSpecial.plainText"),data:e["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:R.t("pasteSpecial.markdown"),data:e["text/markdown"]})),o}}const SH=S("paste-special");class c2{constructor(e){m(this,"button");m(this,"lastUndoAction",null);m(this,"event",null);m(this,"handlePasteSpecial",e=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(e)})});this.editor=e,this.button=new DH(e,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(e,t){this.event=null,this.button.hide()}async handleBeforePaste(e,t){return SH.debug("before paste"),this.lastUndoAction=e.undoManager.lastAction(),!1}async handleAfterPaste(e,t,o){if(Object.keys(o).length<=1)return!1;const r=e.selection.range;if(r.isCollapsed()){const i=e.getBlockById(r.start.blockId);if(!ee(e,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=t}return!1}}const LH={pasteSpecial:{originFormats:"\u4FDD\u6301\u539F\u6837\u5F0F",plainText:"\u7C98\u8D34\u7EAF\u6587\u672C",markdown:"\u7C98\u8D34\u4E3A Markdown"}},MH={pasteSpecial:{originFormats:"Keep origin formats",plainText:"Paste as plain text",markdown:"Paste as markdown"}},RH={pasteSpecial:{originFormats:"\u5143\u306E\u30B9\u30BF\u30A4\u30EB\u3092\u7DAD\u6301\u3059\u308B",plainText:"\u30D7\u30EC\u30FC\u30F3\u30C6\u30AD\u30B9\u30C8\u3092\u8CBC\u308A\u4ED8\u3051\u308B",markdown:"Markdown \u3068\u3057\u3066\u8CBC\u308A\u4ED8\u3051"}};R.mergeLang({"zh-CN":LH,"en-US":MH,"ja-JP":RH});const _ne="",OH=S("html-to-doc");function _H(n){const e="ones-editor-doc::",t="::ones-editor-doc";let o=n.indexOf(e);if(o!==-1){o+=e.length;const r=n.indexOf(t,o);if(r!==-1){const i=n.substr(o,r-o);try{const s=Ud(i);return JSON.parse(s)}catch(s){OH.error(`invalid doc data: ${s}, ${i}`)}}}return null}const n8="latex-b172fea480b",FH=n=>({name:"latex-block",level:"block",start(e){var t,o;return(o=(t=e.match(/\$\$[^\$]/))==null?void 0:t.index)!=null?o:-1},tokenizer(e,t){const o=/^\$\$([^\$]+)\$\$/.exec(e);return o?{type:"latex-block",raw:o[0],formula:o[1]}:void 0},renderer(e){return n.lazy?`<span class="${n8}" block>${e.formula}</span>`:n.render(e.formula,!0)}}),PH=n=>({name:"latex",level:"inline",start(e){var t,o;return(o=(t=e.match(/\$[^\$]/))==null?void 0:t.index)!=null?o:-1},tokenizer(e,t){const o=/^\$([^\$]+)\$/.exec(e);return o?{type:"latex",raw:o[0],formula:o[1]}:void 0},renderer(e){return n.lazy?`<span class="${n8}">${e.formula}</span>`:n.render(e.formula,!1)}});var NH=(n={})=>(n.lazy&&n.env!=="test"&&new IntersectionObserver((e,t)=>{for(const o of e){if(!o.isIntersecting)continue;const r=o.target;t.unobserve(r),Promise.resolve(n.render(r.innerText,r.hasAttribute("block"))).then(i=>{r.innerHTML=i}),r.classList.add("latex-rendered")}},{threshold:1}),{extensions:[FH(n),PH(n)]});function Bc(n){const e=n.type;if(e==="link")return!!n.tokens.some(Bc);switch(e){case"code":case"table":case"hr":case"blockquote":case"list":case"list_item":case"image":case"paragraph":return!0;default:return!1}}function $H(n){return!Bc(n)}function HH(n){if(n.length===0)return[];if(n.length===1)return[n];const e=[];let t=[n[0]],o=Bc(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===Bc(i)?t.push(i):(e.push(t),t=[i],o=Bc(i))}return e.push(t),e}function jH(n,e,t){const o=n.href;let r=t.tokensToText(n.tokens,e,t);return r.length===0&&(r=Oi(o,e)),r=uh(r,"link",o),r}let Lu;function a2(n){Lu||(Lu=document.createElement("textarea")),Lu.innerHTML=n;const e=Lu.childNodes.length===0?"":Lu.childNodes[0].nodeValue;return e!=null?e:""}function UH(n,e){const t=a2(n.text);return[lo(t,{...e,"style-code":!0})]}function zH(n,e,t){const r=n.tokens;return r?t.tokensToText(r,e,t):ag(a2(n.text),e)}const VH=S("token-to-text");function u2(n,e,t){return n.map(r=>r.type==="text"?zH(r,e,t):r.type==="strong"?t.tokensToText(r.tokens,{...e,"style-bold":!0},t):r.type==="em"?t.tokensToText(r.tokens,{...e,"style-italic":!0},t):r.type==="del"?t.tokensToText(r.tokens,{...e,"style-strikethrough":!0},t):r.type==="link"?jH(r,e,t):r.type==="codespan"?UH(r,e):r.type==="br"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?ag(a2(r.text),e):r.type==="latex"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(VH.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function WH(n,e){const t=u2(n.tokens,{},e);return[{id:K(),type:"text",text:t,heading:n.depth}]}function qH(n,e){const{text:t,children:o}=e.tokensToTextWithChildren(n.tokens,e),r=[];return t.length>0&&r.push({id:K(),type:"text",text:t}),r.push(...o),r}function GH(n,e){const{text:t,children:o}=e.tokensToTextWithChildren([n],e),r=[];return t.length>0&&r.push({id:K(),type:"text",text:t}),r.push(...o),r}function ZH(n,e){const t=typeof n.start=="number"?n.start:1,o=n.ordered,r=K(),i=[];return n.items.forEach((l,a)=>{const d={...e,listLevel:e.listLevel+1},{text:h,children:p}=e.tokensToTextWithChildren(l.tokens,d);let A;typeof l.checked=="boolean"&&(A=l.checked?"checked":"unchecked");const v={id:K(),type:"list",groupId:r,ordered:o,checkbox:A,start:t+a,text:h,level:e.listLevel};i.push(v),i.push(...p)}),i}function QH(n,e){const t=e.tokensToBlocks(n.tokens,e);return t.forEach(o=>{o.quoted=!0}),t}const o8=100,YH=20,JH=600;function KH(n,e){const t=e.text;if(t){const o=rt(t);return Math.min(Vd(o,n)+YH,JH)}return o8}function r8(n,e){let t=o8;return e.forEach(o=>{t=Math.max(t,KH(n,o))}),t}function XH(n,e){var l,a;const t=n.header.length,o=n.rows.length+1,r=[],i=Array(t).fill(100);for(let d=0;d<o;d++){let h;d===0?h=n.header:h=n.rows[d-1];for(let p=0;p<t;p++){const A=h[p],v=(l=A==null?void 0:A.tokens)!=null?l:[],B=K();r.push(B);let D;if(v.length===0)D=[hh()];else if(Bc(v[0]))D=e.tokensToBlocks(A.tokens,e),D.length===0&&D.push(hh());else{const{text:T,children:_}=e.tokensToTextWithChildren(A.tokens,e);D=[{id:K(),type:"text",text:T},..._]}e.doc.blocks[B]=D,i[p]=Math.max(i[p],r8((a=e.font)!=null?a:"",D))}}return[{id:K(),type:"table",cols:t,rows:o,colsWidth:i,children:r}]}function ej(n){return[{id:K(),type:"embed",embedType:"hr",embedData:{}}]}function tj(n,e){var a;const t=n.text;if(!t)return[];try{const d=n.text,h=Ud(d),p=JSON.parse(h);if(p){const{root:A,...v}=p.blocks;return e.doc.blocks={...e.doc.blocks,...v},A}}catch{}const o=(a=n.lang)!=null?a:"Plain Text";if(o==="mermaid")return[{id:K(),type:"embed",embedType:"mermaid",embedData:{mermaidText:t}}];if(o==="plantuml")return[{id:K(),type:"embed",embedType:"plantuml",embedData:{plantumlText:t}}];if(o==="flow"||o==="flowchart")return[{id:K(),type:"embed",embedType:"flowchart",embedData:{flowchartText:t}}];const i=t.split(`
423
+ `)}class BH{constructor(){m(this,"group","image");m(this,"commands",[])}executeCommand(e,t,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;xt.getImageObject(e,r).replaceImage(0,i)}}}function EH(){return{blockCommands:{image:new BH},abstract:`${R.t("image.abstract")}`}}function xH(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:R.t("image.abstract"),icon:EL,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,e)=>{var v;let t;(v=e.data)!=null&&v.file&&(t=e.data.file);const o=P7(n);if(t=t!=null?t:await zl(o),!t)return null;try{N7(n,t)}catch{return null}let r={width:k7,height:z0};try{r=await i$(t)}catch(B){yH.error(B)}const i=n.rootContainer.clientWidth,s=r.width<i?Math.min(100,r.width/i*100):100,l={src:"",width:r.width,height:r.height,flex:1,virtualSize:!1},a=cn([l],s),d={id:K(),type:"embed",embedType:"image",embedData:a},h=n.options.componentsOptions.image;h!=null&&h.defaultAlign&&(d.align=h.defaultAlign);const p=n.insertBlock(e.containerId,e.blockIndex,d);return xt.getImageObject(n,p).replaceImage(0,t),p}}}function IH(n,e,t){var h;const{data:o}=t,r=n.getBlockString(e).trim();if(!o||o.embedType!=="image"||!ee(n,e))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(h=i==null?void 0:i.groups)==null?void 0:h.filename;if(!s)return null;const l={src:s},a={id:K(),type:"embed",embedType:"image",embedData:l};xt.create(n,a).setAutoFix(!0);const d=n.options.componentsOptions.image.defaultAlign;return d&&(a.align=d),{blockData:a}}function TH(n,e){const t=ie(e);n.destroyCustom(`image-${t}`)}const t8={embedType:"image",createEmbedContent:kH,convertTo:wH,convertFrom:IH,getBlockProperties:EH,getOptions:xH,handleDrop:X$,handleDropOver:nH,handleDeleteBlock:TH};class DH{constructor(e,t){m(this,"toolbar");m(this,"anchor",null);m(this,"item");m(this,"docs",null);m(this,"checkedId");m(this,"handlePasteSpecial",(e,t)=>{!t.data||(this.checkedId===t.id?this.checkedId=void 0:this.checkedId=t.id,this.onPasteSpecial(t.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});m(this,"handleClose",()=>{this.editor.focus()});m(this,"handleSelectionChange",()=>{this.handleClose()});this.editor=e,this.onPasteSpecial=t,this.item={id:"paste-special",name:"",icon:xL,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ou([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(e){this.docs=e;const t=this.editor,o=t.selection.range;if(!o.isCollapsed())return;const r=t.getBlockById(o.start.blockId);if(!ee(t,r))return;const i=Ti(t,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=Li(t,r,"paste-special-button-anchor",i);const s=this.getCommandItems(e);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close("selectionChange")}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(e){const t=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:R.t("pasteSpecial.originFormats"),data:e[i]}),o=[];let r=!0;return e["text/x-ones-editor-doc"]?o.push(t("text/x-ones-editor-doc")):e["text/office-html"]?o.push(t("text/office-html")):e["text/html"]?o.push(t("text/html")):e["text/plain"]&&(o.push(t("text/plain")),r=!1),e["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:R.t("pasteSpecial.plainText"),data:e["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:R.t("pasteSpecial.markdown"),data:e["text/markdown"]})),o}}const SH=S("paste-special");class c2{constructor(e){m(this,"button");m(this,"lastUndoAction",null);m(this,"event",null);m(this,"handlePasteSpecial",e=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(e)})});this.editor=e,this.button=new DH(e,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(e,t){this.event=null,this.button.hide()}async handleBeforePaste(e,t){return SH.debug("before paste"),this.lastUndoAction=e.undoManager.lastAction(),!1}async handleAfterPaste(e,t,o){if(Object.keys(o).length<=1)return!1;const r=e.selection.range;if(r.isCollapsed()){const i=e.getBlockById(r.start.blockId);if(!ee(e,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=t}return!1}}const LH={pasteSpecial:{originFormats:"\u4FDD\u6301\u539F\u6837\u5F0F",plainText:"\u7C98\u8D34\u7EAF\u6587\u672C",markdown:"\u7C98\u8D34\u4E3A Markdown"}},MH={pasteSpecial:{originFormats:"Keep origin formats",plainText:"Paste as plain text",markdown:"Paste as markdown"}},RH={pasteSpecial:{originFormats:"\u5143\u306E\u30B9\u30BF\u30A4\u30EB\u3092\u7DAD\u6301\u3059\u308B",plainText:"\u30D7\u30EC\u30FC\u30F3\u30C6\u30AD\u30B9\u30C8\u3092\u8CBC\u308A\u4ED8\u3051\u308B",markdown:"Markdown \u3068\u3057\u3066\u8CBC\u308A\u4ED8\u3051"}};R.mergeLang({"zh-CN":LH,"en-US":MH,"ja-JP":RH});const _ne="",OH=S("html-to-doc");function _H(n){const e="ones-editor-doc::",t="::ones-editor-doc";let o=n.indexOf(e);if(o!==-1){o+=e.length;const r=n.indexOf(t,o);if(r!==-1){const i=n.substr(o,r-o);try{const s=Ud(i);return JSON.parse(s)}catch(s){OH.error(`invalid doc data: ${s}, ${i}`)}}}return null}const n8="latex-b172fea480b",FH=n=>({name:"latex-block",level:"block",start(e){var t,o;return(o=(t=e.match(/\$\$[^\$]/))==null?void 0:t.index)!=null?o:-1},tokenizer(e,t){const o=/^\$\$([^\$]+)\$\$/.exec(e);return o?{type:"latex-block",raw:o[0],formula:o[1]}:void 0},renderer(e){return n.lazy?`<span class="${n8}" block>${e.formula}</span>`:n.render(e.formula,!0)}}),PH=n=>({name:"latex",level:"inline",start(e){var t,o;return(o=(t=e.match(/\$[^\$]/))==null?void 0:t.index)!=null?o:-1},tokenizer(e,t){const o=/^\$([^\$]+)\$/.exec(e);return o?{type:"latex",raw:o[0],formula:o[1]}:void 0},renderer(e){return n.lazy?`<span class="${n8}">${e.formula}</span>`:n.render(e.formula,!1)}});var NH=(n={})=>(n.lazy&&n.env!=="test"&&new IntersectionObserver((e,t)=>{for(const o of e){if(!o.isIntersecting)continue;const r=o.target;t.unobserve(r),Promise.resolve(n.render(r.innerText,r.hasAttribute("block"))).then(i=>{r.innerHTML=i}),r.classList.add("latex-rendered")}},{threshold:1}),{extensions:[FH(n),PH(n)]});function Bc(n){const e=n.type;if(e==="link")return!!n.tokens.some(Bc);switch(e){case"code":case"table":case"hr":case"blockquote":case"list":case"list_item":case"image":case"paragraph":return!0;default:return!1}}function $H(n){return!Bc(n)}function HH(n){if(n.length===0)return[];if(n.length===1)return[n];const e=[];let t=[n[0]],o=Bc(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===Bc(i)?t.push(i):(e.push(t),t=[i],o=Bc(i))}return e.push(t),e}function jH(n,e,t){const o=n.href;let r=t.tokensToText(n.tokens,e,t);return r.length===0&&(r=Oi(o,e)),r=uh(r,"link",o),r}let Lu;function a2(n){Lu||(Lu=document.createElement("textarea")),Lu.innerHTML=n;const e=Lu.childNodes.length===0?"":Lu.childNodes[0].nodeValue;return e!=null?e:""}function UH(n,e){const t=a2(n.text);return[lo(t,{...e,"style-code":!0})]}function zH(n,e,t){const r=n.tokens;return r?t.tokensToText(r,e,t):ag(a2(n.text),e)}const VH=S("token-to-text");function u2(n,e,t){return n.map(r=>r.type==="text"?zH(r,e,t):r.type==="strong"?t.tokensToText(r.tokens,{...e,"style-bold":!0},t):r.type==="em"?t.tokensToText(r.tokens,{...e,"style-italic":!0},t):r.type==="del"?t.tokensToText(r.tokens,{...e,"style-strikethrough":!0},t):r.type==="link"?jH(r,e,t):r.type==="codespan"?UH(r,e):r.type==="br"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?ag(a2(r.text),e):r.type==="latex"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(VH.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function WH(n,e){const t=u2(n.tokens,{},e);return[{id:K(),type:"text",text:t,heading:n.depth}]}function qH(n,e){const{text:t,children:o}=e.tokensToTextWithChildren(n.tokens,e),r=[];return t.length>0&&r.push({id:K(),type:"text",text:t}),r.push(...o),r}function GH(n,e){const{text:t,children:o}=e.tokensToTextWithChildren([n],e),r=[];return t.length>0&&r.push({id:K(),type:"text",text:t}),r.push(...o),r}function ZH(n,e){const t=typeof n.start=="number"?n.start:1,o=n.ordered,r=K(),i=[];return n.items.forEach((l,a)=>{const d={...e,listLevel:e.listLevel+1},{text:h,children:p}=e.tokensToTextWithChildren(l.tokens,d);let A;typeof l.checked=="boolean"&&(A=l.checked?"checked":"unchecked");const v={id:K(),type:"list",groupId:r,ordered:o,checkbox:A,start:t+a,text:h,level:e.listLevel};i.push(v),i.push(...p)}),i}function QH(n,e){const t=e.tokensToBlocks(n.tokens,e);return t.forEach(o=>{o.quoted=!0}),t}const o8=100,YH=20,JH=600;function KH(n,e){const t=e.text;if(t){const o=rt(t);return Math.min(Vd(o,n)+YH,JH)}return o8}function r8(n,e){let t=o8;return e.forEach(o=>{t=Math.max(t,KH(n,o))}),t}function XH(n,e){var l,a;const t=n.header.length,o=n.rows.length+1,r=[],i=Array(t).fill(100);for(let d=0;d<o;d++){let h;d===0?h=n.header:h=n.rows[d-1];for(let p=0;p<t;p++){const A=h[p],v=(l=A==null?void 0:A.tokens)!=null?l:[],B=K();r.push(B);let D;if(v.length===0)D=[hh()];else if(Bc(v[0]))D=e.tokensToBlocks(A.tokens,e),D.length===0&&D.push(hh());else{const{text:T,children:_}=e.tokensToTextWithChildren(A.tokens,e);D=[{id:K(),type:"text",text:T},..._]}e.doc.blocks[B]=D,i[p]=Math.max(i[p],r8((a=e.font)!=null?a:"",D))}}return[{id:K(),type:"table",cols:t,rows:o,colsWidth:i,children:r}]}function ej(n){return[{id:K(),type:"embed",embedType:"hr",embedData:{}}]}function tj(n,e){var a;const t=n.text;if(!t)return[];try{const d=n.text,h=Ud(d),p=JSON.parse(h);if(p){const{root:A,...v}=p.blocks;return e.doc.blocks={...e.doc.blocks,...v},A}}catch{}const o=(a=n.lang)!=null?a:"Plain Text";if(o==="mermaid")return[{id:K(),type:"embed",embedType:"mermaid",embedData:{mermaidText:t}}];if(o==="plantuml")return[{id:K(),type:"embed",embedType:"plantuml",embedData:{plantumlText:t}}];if(o==="flow"||o==="flowchart")return[{id:K(),type:"embed",embedType:"flowchart",embedData:{flowchartText:t}}];const i=t.split(`
424
424
  `).map(d=>({id:K(),type:"text",text:Oi(d)})),s=e.doc,l=K();return s.blocks[l]=i,[{id:K(),type:"code",language:o,children:[l]}]}function nj(n){return[{id:K(),type:"embed",embedType:"image",embedData:{src:n.href,title:n.title}}]}function oj(n,e){const{text:t,children:o}=e.tokensToTextWithChildren(n.tokens,e),r=[];return t.length>0&&r.push({id:K(),type:"text",text:t}),r.push(...o),r}function rj(n){const e=n.formula;return e?[{id:K(),type:"embed",embedType:"math",embedData:{mathjaxText:e}}]:[]}const i8=S("markdown-to-doc");function ij(n,e){var t;if(n.type==="heading")return WH(n,e);if(n.type==="paragraph")return qH(n,e);if(n.type==="list")return ZH(n,e);if(n.type==="blockquote")return QH(n,e);if(n.type==="table")return XH(n,e);if(n.type==="hr")return ej();if(n.type==="code")return tj(n,e);if(n.type==="image")return nj(n);if(n.type==="link")return oj(n,e);if(n.type==="latex-block")return rj(n);if(n.type==="text")return GH(n,e);if(n.type==="space"){const o=n.raw.replaceAll(" ",""),r=Math.floor(o.split(`
425
425
  `).length/2)-1;return r>0?new Array(r).fill("").map(()=>({type:"text",id:K(),text:[]})):[]}if(n.type==="html"){const o=(t=e.htmlToDoc)==null?void 0:t.call(e,n.text);if(!o)return i8.warn(`failed to convert html to doc: ${JSON.stringify(n)}`),[];const{root:r,...i}=o.blocks;return e.doc.blocks={...e.doc.blocks,...i},r}return i8.warn(`unknown block token: ${JSON.stringify(n)}`),[]}function d2(n,e){const t=[];return n.forEach(o=>{const r=ij(o,e);t.push(...r)}),t}S("markdown-to-doc");function sj(n,e){const t={text:[],children:[]};return HH(n).forEach((r,i)=>{const s=r[0];if(i===0&&$H(s)){t.text=u2(r,{},e);return}t.children.push(...d2(r,e))}),t}const lj={render:(n,e)=>""};G5.marked.use(NH(lj));function s8(n,e){const o=new G5.marked.Lexer().lex(n),r={blocks:{root:[]},meta:{},comments:{}},i={font:e==null?void 0:e.font,doc:r,tokensToText:u2,tokensToBlocks:d2,tokensToTextWithChildren:sj,htmlToDoc:e==null?void 0:e.htmlToDoc,listLevel:1},s=d2(o,i);return s.length===0?null:(r.blocks.root.push(...s),r)}function cj(n){if(n.nodeName!=="DIV")return!1;const e=n;return Array.from(e.childNodes).every(t=>t.nodeName==="SPAN"||t instanceof Text)?!!e.querySelector(":scope > .hljs-function, :scope > .hljs-params, :scope > .hljs-string, :scope > .hljs-keyword, :scope > .hljs-attr"):!1}function l8(n){if(cj(n)){const e=n,t=e.parentNode,o=document.createElement("pre");Array.from(e.childNodes).forEach(r=>o.appendChild(r)),t==null||t.insertBefore(o,e);return}n.childNodes.forEach(e=>l8(e))}function Hf(n){var e;if(n instanceof HTMLBRElement){const t=document.createTextNode(`
426
426
  `);(e=n.parentNode)==null||e.insertBefore(t,n),n.remove();return}n.childNodes.forEach(Hf)}function aj(n){n.addRule("preOnlyBlockToCode",{filter:e=>e.nodeName!=="PRE"?!1:Array.from(e.childNodes).every(t=>t.nodeName==="SPAN"||t instanceof Text||t.nodeName==="BR"),replacement:(e,t,o)=>{var r;return Hf(t),`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.3-beta.172",
3
+ "version": "0.0.3-beta.173",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",