@ones-editor/editor 0.0.7-beta.20 → 0.0.7-beta.21

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
@@ -690,7 +690,7 @@ ${s}
690
690
  <path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
691
691
  </svg>`,Ej=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
692
692
  <path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
693
- </svg>`,_it="",L0="reply-editor-editing",{t:aE}=_;class Aj{constructor(t,e,r,i){g(this,"root");g(this,"components");g(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});g(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,r=t.getDoc();t1(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{Rt(this.root,L0)||(z(this.root,L0),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!Rt(this.root,L0)||ot(this.root,L0)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,o=r.getDoc(),s=w0({editor:t,commentGroupId:e.groupId});i.localCreateComment(s,o),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{Rt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{ot(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=B("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=il(this.root,Jt.QuickReply,aE("comment.placeholder"));lo(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=B("div",["quick-reply-editor"],this.root),i=Yi(),o=new lE(this.mainEditor,t,i);o.editor.addListener("docChanged",this.handleDocChange),o.editor.addListener("focus",this.handleFocus),o.editor.input.addHandler(new fj(this.groupItem)),r.append(o.root);const s=B("div",["reply-editor-actions"],r),l=pr(Jt.QuickReplyCancel,aE("common.cancel"));lo(l,Jt.QuickReplyCancel);const c=pr(Jt.QuickReplyOk,aE("comment.send"),void 0,["primary","disabled"]);return lo(c,Jt.QuickReplyOk),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:o,replyEditorContainer:r,okButton:c}}}const ao=D("comment-group-item");class xj extends Te.TypedEmitter{constructor(e,r,i,o){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>B("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=B("div",["comment-children-list-container"],this.root);return new pj({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});g(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));p(ao,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{ot(i,Cy)});const r=e[e.length-1];z(r,Cy)});g(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),r=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');p(ao,e,"switchUpButton not exist"),p(ao,r,"switchDownButton not exist"),ot(r,"disabled"),ot(e,"disabled"),this.root.previousElementSibling===null&&z(e,"disabled"),this.root.nextElementSibling===null&&z(r,"disabled")});g(this,"handleReadonlyChanged",e=>{e.readonly?z(this.root,"readonly"):ot(this.root,"readonly")});g(this,"getCommentEditor",()=>this.mainItem.getCommentEditor());g(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=r,this.comment=i,this.groupList=o,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new vs(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return Ay(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,o=new Aj(e,r,i,this);return this.root.append(o.root),o}createHeader(){const{comment:e}=this,r=B("div",["comment-item-head"],this.root),i=B("span",["item-head-quote"],r);i.innerText=e.abstract;const o=B("span",["item-head-switch"],r),s=il(o,Jt.SwitchUp,"up",Cj),l=il(o,Jt.SwitchDown,"down",Ej);return lo(s,Jt.SwitchUp),lo(l,Jt.SwitchDown),r}createItem(){const e=B("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:o,groupList:s}=this,l=new Sy({mainEditor:r,commentsProvider:i,comment:o,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(r=>r.comment.id===e):null}handleCreateComment(e){return p(ao,ll(e),"invalid comment, not a child comment"),p(ao,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){p(ao,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){ao.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(ao,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(ao,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const bj=D("arrange=items"),Dy=20;function _y(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const r=n.scrollContainer.getBoundingClientRect(),i=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-r.top+i}function My(n,t){return Number.parseInt(t.root.style.top,10)}function Uy(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let o=i;o<t.length;o++){const s=t[o],l=s.comment,c=_y(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),o===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else s.root.style.top=`${c}px`;continue}const d=t[o-1],h=My(n,d)+d.root.getBoundingClientRect().height;h>c?s.root.style.top=`${h+Dy}px`:s.root.style.top=`${c}px`}for(let o=i-1;o>=0;o--){const s=t[o],l=s.comment,c=_y(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const d=s.root.getBoundingClientRect(),h=c+d.height,C=t[o+1];p(bj,C,"no next item");const E=My(n,C);E<h?s.root.style.top=`${E-d.height-Dy}px`:s.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const S0=D("comment-group-item-handler");class Bj{constructor(t,e){g(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});g(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});g(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});g(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});g(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});g(this,"handleCommentItemReply",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:o}=r,s=i.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:et(),box:!0,created:Date.now(),text:o.displayName,iconUrl:o.avatarUrl,mentionId:o.userId};s.editor.insertBoxToBlock(l,0,c)});g(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});g(this,"handleCommentItemOk",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:o,getCommentEditor:s}=r,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(o,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let o=!1;if((c=i.blocks)!=null&&c.length||(o=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];o=!!h.text&&an(h.text)===0}if(o){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:s}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),s.show()});g(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e;t.getCommentEditor().edit(),r.hide()});g(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e,{comment:i}=t;this.commentsProvider.localDeleteComment(i.id),r.show()});g(this,"execute",(t,e,r,i)=>{const o=rj(t);if(!o||oj(o))return;const s=ij(o);switch(s){case Jt.SwitchUp:this.handleSwitchUp(i);break;case Jt.SwitchDown:this.handleSwitchDown(i);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,r);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,r);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,r);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;S0.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const I0=D("comment-group-list");class vj extends tf{constructor(e,r,i){super(e,r,i,rs(e,r),{});g(this,"groupItemHandlers");g(this,"closeEditing",e=>{const r=this.items.find(i=>i.comment.id===e);r&&([r,...r.childrenList.items].forEach(i=>{!i.getCommentEditor().editor.readonly&&i.getCommentEditor().isEmpty()&&this.groupItemHandlers.handleCommentItemCancel(r,i.comment.id)}),r.quickReply.getReplyEditor().isEmpty()&&r.quickReply.cancel())});g(this,"setFirstEditingCommentActive",()=>{const e=this.findFirstEditingComment();e!==-1&&this.setActiveItem(e)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const r=e.target.closest(".comment-group-item-root");if(!r)return;const i=nj(e.target),o=this.items.findIndex(s=>s.root===r);if(o!==-1){this.setActiveItem(o);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[o],i,o)}});g(this,"handleDocumentClick",e=>{if(!e.target||!(e.target instanceof Element)||e.target.closest(".comment-group-item-root.active"))return;const i=this.items[this.activeIndex];this.closeEditing(i.comment.id)});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=ky(this.editor);if(e.length>0){if(((r=this.activeItem)==null?void 0:r.comment.id)&&e.includes(this.activeItem.comment.id))return;const i=e[0],o=this.items.findIndex(s=>s.comment.groupId===i);this.setActiveItem(o),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});g(this,"handleEditorResize",()=>{this.updateItemsLayout()});g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"handleItemResize",()=>{this.updateItemsLayout()});g(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const r=document.elementFromPoint(e.clientX,e.clientY);if(!r||!(r instanceof HTMLElement)||!this.editor.scrollContainer.contains(r))return;const i=this.container.querySelector(".comment-group-item-root");if(!i)return;const o=Number.parseFloat(i.style.top),s=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(o)&&!Number.isNaN(s)&&o<s&&Uy(this.editor,this.items,null,Math.min(o+(0-e.deltaY)*3,s))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(I0,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Fe.default(()=>{const e=rs(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const o=e[i];if(!this.findGroupItem(o.groupId)){this.handleCreateComment(o,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const o=this.items[i];e.findIndex(s=>s.groupId===o.comment.groupId)===-1&&(this.deleteItem(o.comment.id),r=!0)}r&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(o=>o.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new Bj(this,r),document.addEventListener("click",this.handleDocumentClick)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners(),document.removeEventListener("click",this.handleDocumentClick)}updateItemsLayout(){Uy(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,r){const i=new xj(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{ot(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=rs(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}insertItem(e,r){const i=super.insertItem(e);return i?(r!=null&&r.active&&this.setActiveItem(this.items.indexOf(i)),this.updateItemsLayout(),i.addListener("resize",this.handleItemResize),i):null}findFirstEditingComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if((!i.quickReply.getReplyEditor().isEmpty()||e)&&!i.quickReply.getReplyEditor().editor.readonly)return r;const o=[i,...i.childrenList.items];for(let s=0;s<o.length;s++){const l=o[s];if(!l.getCommentEditor().editor.readonly&&(!l.getCommentEditor().isEmpty()||e))return r}}return-1}isEditing(){return this.findFirstEditingComment()!==-1}setActiveItem(e,r){if(p(I0,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const i=this.container.querySelector(".comment-group-item-root.active");if(i){const o=this.items[this.activeIndex];this.closeEditing(o.comment.id),ot(i,"active")}if(e!==-1){const o=this.items[e];z(o.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,r)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(r=>r.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,r){if(ll(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(I0,!i,"comment group item has already exists");const o={children:[],...e};p(I0,o.children,"not a comment group");const s=this.insertItem(o,{active:r});if(!!s&&r){const l=this.items.indexOf(s);this.setActiveItem(l),s.quickReply.hide(),setTimeout(()=>{s.edit()},300)}}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?(this.deleteItem(i.comment.id),this.updateItemsLayout()):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&(this.deleteItem(i.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}}const Tj="comment-mini";D("comment-list");class kj extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"groupsContainer");g(this,"list");g(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});g(this,"updateCommentCount",()=>{var r,i;const e=aj(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var o,s;const i=this.list.activeItem;yy(this.editor,(s=(o=i==null?void 0:i.comment)==null?void 0:o.groupId)!=null?s:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=Rt(this.root,Tj);(i=(r=this.commentOptions)==null?void 0:r.onUpdateLayout)==null||i.call(r,this.editor,{expand:e})});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-web-comment-root"],null),this.groupsContainer=B("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r),this.updateCommentCount()}onDeleteComment(e,r){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}createList(){return new vj(this.editor,this.commentsProvider,this.groupsContainer)}isEditing(){return this.list.isEditing()}setFirstEditingCommentActive(){this.list.setFirstEditingCommentActive()}show(e){var r;if(ot(this.root,"hidden"),e){const i=this.list.findItemIndex(e);this.list.setActiveItem(i)}(r=this.commentOptions)==null||r.controller.showCommentList()}hide(){z(this.root,"hidden")}}class Rj extends tf{constructor({editor:t,parent:e,commentsProvider:r,comments:i}){super(t,r,e,i,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:r}=this;return new Iy(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const D0=D("mobile-comment-group-item"),yj=20;class wj extends Te.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>B("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=new Iy(r,i,o);return e.append(s.root),s});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=B("div",["mobile-comment-children-list-container"],e);return new Rj({editor:r,commentsProvider:i,comments:o.children,parent:s})});g(this,"handleTouchEnd",()=>{var o;const{scroller:e}=this,{pullThreshold:r=yj}=(o=this.editor.getComponentOptions("comment"))!=null?o:{};let i=null;if(e.y>e.minScrollY+r?(i=this.root.previousElementSibling,i||this.emit("onReachTop")):e.y<e.maxScrollY-r&&(i=this.root.nextElementSibling,i||this.emit("onReachBottom")),i){const s=i.id;this.emit("onSwitchGroup",s,Ey)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=B("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const o=B("div",["mobile-group-item"],this.root),s=B("div",["mobile-group-item-space"],null),l=B("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=B("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),o.append(s,l,c),this.scroller=new Dx.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return Ay(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(D0,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){D0.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(D0,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(D0,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const cE=D("mobile-group-list");class Lj extends tf{constructor(e,r,i,o){super(e,r,i,rs(e,r),{});g(this,"scroller");g(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});g(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const r=this.findItemIndex(e);let i=null;return r===0?i=this.items[r+1].root.id:i=this.items[r-1].root.id,super.deleteItem(e)?(this.scrollToGroup(i,Ey),!0):!1});g(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});g(this,"handleReachBottom",()=>{this.emit("onReachBottom")});g(this,"handleReachTop",()=>{this.emit("onReachTop")});g(this,"scrollToGroup",(e,r=0)=>{const i=this.findGroupItem(e);p(cE,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),yy(this.editor,i.comment.groupId)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"updateComments",Fe.default(()=>{const e=rs(this.editor,this.commentsProvider);for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1);continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(o=>o.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new Dx.default(o),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new wj(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=rs(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(ll(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const i=this.findItem(e.id);p(cE,!i,"comment group item has already exists");const o={children:[],...e};p(cE,o.children,"not a comment group"),this.insertItem(o),this.scroller.refresh()}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?this.deleteItem(i.comment.id):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&this.deleteItem(i.comment.id);return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const Sj=D("mobile-comment-list"),{t:Oy}=_;class Ij extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"list");g(this,"mask");g(this,"pullInfoContainer");g(this,"handleRootClick",e=>{const r=e.target;p(Sj,r instanceof Element,"invalid target"),!(r.closest(".mobile-group-item-abstract")||r.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});g(this,"hidePullInfo",Fe.default(()=>{ot(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;ot(this.root,"hidden"),z(document.documentElement,"disabled-scroll"),(r=this.commentOptions)==null||r.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});g(this,"hide",()=>{z(this.root,"hidden"),ot(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mobile-comments-root"],null),this.mask=B("div",["mobile-comment-mask"],this.root);const i=B("div",["mobile-comment-groups-container"],this.root),o=B("div",["mobile-comment-groups-scroll-container"],i);this.list=new Lj(this.editor,this.commentsProvider,o,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=B("div",["mobile-comment-pull-info-container"],this.root);return B("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=Oy(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=r,z(this.pullInfoContainer,"active"),this.hidePullInfo()}isEditing(){return!1}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function Ny(n,t){const e=rs(n,t),r=new Map;for(const i of e){const o=xy(n,i.groupId);if(!!o)if(r.has(o)){const s=r.get(o);Ty(i).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=Ty(i),l=new Set(s.map(c=>c.id));r.set(o,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,o])=>({blockId:i,...o}))}const Dj=D("mini-group-item");class _j{constructor(t,e){g(this,"root");g(this,"blockId");g(this,"comment");g(this,"miniCommentItem");g(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=B("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new gj(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return xy(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);p(Dj,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class Mj extends tf{constructor(e,r,i){super(e,r,i,Ny(e,r),{});g(this,"fixListOps",Fe.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));g(this,"handleDocChanged",Fe.default(()=>{this.updateMiniCommentsGroup()},100));g(this,"updateMiniCommentsGroup",()=>{const e=Ny(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=r,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new _j(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,r){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const Uj=D("mini-comments-list");class Oj extends Te.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=B("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new Mj(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(Uj,i instanceof HTMLElement,"The target is not a valid html element");const o=i.closest(".mini-comment-item");o&&this.emit("onItemClick",o.id)});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){}show(){ot(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function Py(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const r=t.block,i=Ee(n,r,t.start.offset,t.end.offset),o=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;K3(n,r,i,o,s)}function Nj(n,t,e){const r=ci(n).map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{ci(n,{simpleBlockOnly:!0}).forEach(c=>{!nt(n,c.block)||Py(n,c,o)});const l=Yi();e.localCreateComment(o,l)}),o}class Pj{constructor(t,e){g(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,r){const i=t.selection.range;if(nt(t,e)&&!r.isCollapsed()&&i.isSimple()){const o=st(e),s=St(e),l=Ir(t,e);return[{id:"add-comment",name:_.t("comment.command"),blockId:o,blockType:s,blockKind:l,groupIndex:1e3,icon:Qs}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,r,i,o){if(r.id==="add-comment"){this.editorComments.showCommentList();const s=Nj(t,e,this.provider);return o["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class Fy{constructor(t,e){g(this,"commentList",null);g(this,"mobileCommentList",null);g(this,"miniCommentList");g(this,"showComment",(t,e)=>{var r,i;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((r=this.mobileCommentList)==null||r.show(e)),t==="web"&&((i=this.commentList)==null||i.show(e))});g(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});g(this,"handleCommentListClose",()=>{this.showComment("mini")});g(this,"handleOnSelectComment",()=>{this.showComment("web")});g(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new Pj(e,this)),t.blockHooks.push(new JH(this.provider,this)),this.isMobile?(this.mobileCommentList=new Ij(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new kj(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new Oj(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new tj)}get commentProvider(){return this.provider}get isMobile(){return ge.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}setFirstEditingCommentActive(){var t;(t=this.commentList)==null||t.setFirstEditingCommentActive()}isEditing(){var t,e;return((t=this.commentList)==null?void 0:t.isEditing())||((e=this.mobileCommentList)==null?void 0:e.isEditing())||!1}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const Mit="",Fj={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u5B9A",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u6DFB\u52A0\u6279\u6CE8\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},Kj={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotation or mention someone",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},Vj={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u5B9A",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0\u3059\u308B\u304B\u30E1\u30F3\u30D0\u30FC\u3092\u30E1\u30F3\u30B7\u30E7\u30F3",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":Fj,"en-US":Kj,"ja-JP":Vj});class Ky{renderText(t,e,r){const i=[],o={};return Object.entries(r).forEach(([s,l])=>{s.startsWith("comment-")&&(i.push("comment"),o[s]=l)}),{classes:i,attributes:o}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const o=["comment"],s={};return i.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:o,attributes:s}}updateBlock(t,e,r,i){const o=i.comments;ot(r,"comment"),Array.from(r.attributes).forEach(s=>{s.name.startsWith("comment-")&&r.removeAttribute(s.name)}),!(!o||o.length===0)&&(z(r,"comment"),o.forEach(s=>{r.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class $j{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,o)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();g0(t,e,_.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function Hj(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const s=new Set(i);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const o=r.text;if(!!o&&nt(n,t)){const s=Pg(o,`comment-${e.toLocaleLowerCase()}`,e);yc.default(o,s)||n.setBlockText(t,s)}}const jj=D("editor-comment");function zj(n){const t=n.getCustom("editor-comments");if(p(jj,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Fo(s);if(l.length>=2){const{containerId:c}=l[l.length-1],d=rt(li(n,c));if(d&&St(d)==="code"){rE(n,d,t.commentProvider);return}}rE(n,s,t.commentProvider);return}const e=ci(n,{simpleBlockOnly:!0}),r=e.map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?Py(n,l,o):py(n,l.block,o)});const s=Yi();t.commentProvider.localCreateComment(o,s)})}const uE=D("text-styles");function Gj(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([o])=>!!o.startsWith("style-"));return new Map(i)};if(n.length===0)return new Map;let e=t(n[0]);for(let r=1;r<n.length;r++){const i=t(n[r]);e=new Map(Array.from(e.entries()).filter(([o,s])=>i.get(o)===s))}return e}function Wj(n,t,e,r,i){p(uE,e.isSimple(),"invalid range");const{start:o,end:s}=e;p(uE,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(uE,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=ra(o.offset,s.offset-o.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=ra(o.offset,s.offset-o.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=ra(o.offset,s.offset-o.offset,c,r,void 0,{ignoreValue:!0}):c=Gc(o.offset,s.offset-o.offset,c,r,i),n.setBlockText(t,c),c}const al=D("text-commands");function Vy(n){const t={id:"more",name:_.t("commands.more"),icon:rp,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[_.t("commands.bold"),ur("CtrlOrCmd+B"),I2],"style-italic":[_.t("commands.italic"),ur("CtrlOrCmd+I"),D2],"style-underline":[_.t("commands.underline"),ur("CtrlOrCmd+U"),_2],"style-strikethrough":[_.t("commands.strikethrough"),ur("CtrlOrCmd+D"),M2],"style-code":[_.t("commands.code"),void 0,U2]},r={"style-super":[_.t("commands.superscript"),void 0,N2],"style-sub":[_.t("commands.subscript"),void 0,O2]};if(an(n)===0){const l=Object.entries(e).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h}));return t.children=Object.entries(r).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h})),l.concat(t)}const i=Gj(n);function o([l,[c,d,h]]){const C=i.get(l);return C!==void 0?{id:l,name:c,value:C,states:C===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:c,icon:h,desc:d}}const s=Object.entries(e).map(o);return t.children=Object.entries(r).map(o),s.concat(t)}function qj(n,t){const e=st(t),r=St(t),i=Ir(n,t);return Vy([]).map(o=>({blockId:e,blockType:r,blockKind:i,...o,groupIndex:500}))}function Xj(n,t,e){p(al,e.isSimple(),"nor a simple range");const{start:r,end:i}=e;p(al,r.isSimple(),"is not a simple block position"),p(al,i.isSimple(),"is not a simple block position"),p(al,nt(n,t),"invalid block type, not a text kind block");const o=st(t);p(al,r.blockId===o&&i.blockId===o,"invalid range");const s=n.getBlockText(t);let l=[];r.offset===i.offset?r.offset!==0&&(l=Xe(s,r.offset-1,1).middle):l=Xe(s,r.offset,i.offset-r.offset).middle;const c=St(t),d=Ir(n,t);return Vy(l).map((h,C)=>({blockId:o,blockType:c,blockKind:d,...h,groupIndex:500,order:C*100}))}function Qj(n,t,e,r,i,o){if(!nt(n,t))return!1;if(!r.startsWith("style-"))return al.warn(`unknown command: ${r}`),!1;const s=i==null?void 0:i.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return al.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const c=Wj(n,t,e,r,s);return o.result=c,!0}const Yj=D("text-command-provider");class ki{constructor(t){g(this,"id","TextCommandProvider");g(this,"emptyTextBlockAttributes",new Map);g(this,"colorItem");g(this,"updateButtonColor",t=>{const e=H3(this.editor,t,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(e)});g(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")V3(this.editor,t,e,this.setEmptyTextBlockColor);else{const r=["clearAll","clearColor","clearBackground"];$3(this.editor,r[e],this.setEmptyTextBlockColor)}});g(this,"getEmptyTextBlockColor",(t,e)=>{const r=this.getEmptyBlockTextAttributes(t,e);return Fg(r)});g(this,"setEmptyTextBlockColor",(t,e,r,i)=>{var s;const o=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};M5(o,r,i),this.emptyTextBlockAttributes.set(e,o)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new eM(t)),this.colorItem.addListener("onClick",this.handleChangeColor)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,r){if(!nt(t,e))return[];let i;ft(t,e)===0?i=this.getCommandsOnEmptyText(t,e).map(ki.toTextCommand):i=Xj(t,e,r).map(ki.toTextCommand),this.updateButtonColor(r);const s={...this.colorItem,blockId:st(e),blockKind:Ir(t,e),blockType:St(e),groupIndex:500,order:350};return i.push(s),i}executeCommand(t,e,r,i,o,s){if(!nt(t,e))return!1;let l=o.value;l===void 0&&(l=!i.value);const c=ki.fromTextCommandId(i.id);if(c.startsWith("style-")){if(c==="style-font")return this.handleChangeColor(o.type,l),!0;if(ft(t,e)===0)return this.executeCommandOnEmptyText(e,i,{value:l})}return Qj(t,e,r,c,{value:l},s)}executeCommandOnEmptyText(t,e,r){let i=this.emptyTextBlockAttributes.get(st(t));i||(i={},this.emptyTextBlockAttributes.set(st(t),i));const o=ki.fromTextCommandId(e.id),s=r.value;return s==null||s===!1?(delete i[o],!0):(i[o]=r.value,!0)}getCommandsOnEmptyText(t,e){const r=qj(t,e);return this.setCommandsStates(r,e)}setCommandsStates(t,e){var o;const r=st(e),i=(o=this.emptyTextBlockAttributes.get(r))!=null?o:{};return t.map(s=>{const l=i[s.id],c=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:c}})}getEmptyBlockTextAttributes(t,e){var i;const r=gt.default((i=this.emptyTextBlockAttributes.get(e))!=null?i:{});if(Array.from(Object.entries(r)).forEach(([o,s])=>{s||delete r[o]}),Object.keys(r).length!==0)return r}static toTextCommand(t){return t.children&&(t.children=t.children.map(ki.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return p(Yj,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(ki.toTextCommand)}static fromTextCommands(t){return t.map(ki.fromTextCommand)}}function $y(n){const t=n.findCustom("toolbar-handler");t==null||t.disableTextToolbar(),t==null||t.hide(),setTimeout(()=>{t==null||t.enableTextToolbar()},300)}function Zj(n){n.undoManager.canUndo()&&$y(n)}function Jj(n){n.undoManager.canRedo()&&$y(n)}const tz={"CtrlOrCmd+Z":Zj,"CtrlOrCmd+Shift+Z":Jj},ez={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},nz={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},rz={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};_.mergeLang({"zh-CN":ez,"en-US":nz,"ja-JP":rz});const iz={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},oz={embedProperties:{edit:"Edit",addComment:"Add annotation"}},sz={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":iz,"en-US":oz,"ja-JP":sz});const Hy=D("embed-block-properties");function ef(n,t){var e;for(const r of n.blockHooks){const i=(e=r.commands)==null?void 0:e.call(r,n,t);if(!!i&&i.group==="block-comment-actions")return i.executeCommand(n,t,i.commands[0]),!0}return!1}class fE{constructor(t,e,r){g(this,"group","hovering-toolbar");g(this,"_commands",[{id:"edit",name:_.t("embedProperties.edit"),icon:Dh},{id:"add-comment",name:_.t("embedProperties.addComment"),icon:Qs}]);this.editor=t,this.block=e,this.properties=r}get commands(){var i,o,s;if(this.editor.readonly)return[];let t=this._commands;const{enableComments:e=!0}=this.editor.options;e||(t=t.filter(l=>l.id!=="add-comment")),t.forEach(l=>{(l.id==="add-comment"||l.id==="edit")&&(l.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});let r=(i=this.properties)!=null&&i.presetIds?t.filter(l=>{var c,d;return(d=(c=this.properties)==null?void 0:c.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(o=this.properties)==null?void 0:o.extCommands)!=null&&s.length&&(r.length&&r.push({id:et(),type:"separator",name:""}),r.push(...this.properties.extCommands)),r.length<=3&&(r=r.filter(l=>l.id!=="separator")),r}executeCommand(t,e,r){var i,o;if(!((o=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&o.call(i,t,e,r))){if(r.id==="add-comment"){ef(t,e)||Hy.error("failed to add comment to block");return}Hy.error(`unknown command: ${JSON.stringify(r)}`)}}}function dE(n,t,e){return{blockCommands:{"hovering-toolbar":new fE(n,t,e)}}}class nf{constructor(t){g(this,"blockResizer");g(this,"handleResizing",(t,e)=>{var i,o;const r=t.getBlock();if(r){if(((o=(i=Zt(this.editor,r)).notify)==null?void 0:o.call(i,this.editor,"resize",{block:r,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(r).embedData,height:s};this.editor.updateEmbedData(r,d)}});g(this,"handleHoveringBlockChange",(t,e)=>{e&&Ie(e)&&Rt(e,"resizable")&&this.disableResizer(),t&&Ie(t)&&Rt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new Pu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}tryEnableResizer(t){this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}static get(t){return t.addCustom("EmbedBlockResizer",()=>new nf(t))}static register(t,e){return z(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new nf(t))}}var jy=(n=>(n.Card="card",n.Preview="preview",n))(jy||{});const lz=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="#5587F0">
693
+ </svg>`,_it="",L0="reply-editor-editing",{t:aE}=_;class Aj{constructor(t,e,r,i){g(this,"root");g(this,"components");g(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});g(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,r=t.getDoc();t1(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{Rt(this.root,L0)||(z(this.root,L0),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!Rt(this.root,L0)||ot(this.root,L0)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,o=r.getDoc(),s=w0({editor:t,commentGroupId:e.groupId});i.localCreateComment(s,o),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{Rt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{ot(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=B("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=il(this.root,Jt.QuickReply,aE("comment.placeholder"));lo(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=B("div",["quick-reply-editor"],this.root),i=Yi(),o=new lE(this.mainEditor,t,i);o.editor.addListener("docChanged",this.handleDocChange),o.editor.addListener("focus",this.handleFocus),o.editor.input.addHandler(new fj(this.groupItem)),r.append(o.root);const s=B("div",["reply-editor-actions"],r),l=pr(Jt.QuickReplyCancel,aE("common.cancel"));lo(l,Jt.QuickReplyCancel);const c=pr(Jt.QuickReplyOk,aE("comment.send"),void 0,["primary","disabled"]);return lo(c,Jt.QuickReplyOk),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:o,replyEditorContainer:r,okButton:c}}}const ao=D("comment-group-item");class xj extends Te.TypedEmitter{constructor(e,r,i,o){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>B("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=B("div",["comment-children-list-container"],this.root);return new pj({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});g(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));p(ao,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{ot(i,Cy)});const r=e[e.length-1];z(r,Cy)});g(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),r=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');p(ao,e,"switchUpButton not exist"),p(ao,r,"switchDownButton not exist"),ot(r,"disabled"),ot(e,"disabled"),this.root.previousElementSibling===null&&z(e,"disabled"),this.root.nextElementSibling===null&&z(r,"disabled")});g(this,"handleReadonlyChanged",e=>{e.readonly?z(this.root,"readonly"):ot(this.root,"readonly")});g(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=r,this.comment=i,this.groupList=o,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new vs(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return Ay(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,o=new Aj(e,r,i,this);return this.root.append(o.root),o}createHeader(){const{comment:e}=this,r=B("div",["comment-item-head"],this.root),i=B("span",["item-head-quote"],r);i.innerText=e.abstract;const o=B("span",["item-head-switch"],r),s=il(o,Jt.SwitchUp,"up",Cj),l=il(o,Jt.SwitchDown,"down",Ej);return lo(s,Jt.SwitchUp),lo(l,Jt.SwitchDown),r}createItem(){const e=B("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:o,groupList:s}=this,l=new Sy({mainEditor:r,commentsProvider:i,comment:o,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(r=>r.comment.id===e):null}handleCreateComment(e){return p(ao,ll(e),"invalid comment, not a child comment"),p(ao,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){p(ao,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){ao.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(ao,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(ao,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const bj=D("arrange=items"),Dy=20;function _y(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const r=n.scrollContainer.getBoundingClientRect(),i=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-r.top+i}function My(n,t){return Number.parseInt(t.root.style.top,10)}function Uy(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let o=i;o<t.length;o++){const s=t[o],l=s.comment,c=_y(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),o===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else s.root.style.top=`${c}px`;continue}const d=t[o-1],h=My(n,d)+d.root.getBoundingClientRect().height;h>c?s.root.style.top=`${h+Dy}px`:s.root.style.top=`${c}px`}for(let o=i-1;o>=0;o--){const s=t[o],l=s.comment,c=_y(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const d=s.root.getBoundingClientRect(),h=c+d.height,C=t[o+1];p(bj,C,"no next item");const E=My(n,C);E<h?s.root.style.top=`${E-d.height-Dy}px`:s.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const S0=D("comment-group-item-handler");class Bj{constructor(t,e){g(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});g(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});g(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});g(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});g(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});g(this,"handleCommentItemReply",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:o}=r,s=i.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:et(),box:!0,created:Date.now(),text:o.displayName,iconUrl:o.avatarUrl,mentionId:o.userId};s.editor.insertBoxToBlock(l,0,c)});g(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});g(this,"handleCommentItemOk",(t,e)=>{const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:o,getCommentEditor:s}=r,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(o,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(S0,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let o=!1;if((c=i.blocks)!=null&&c.length||(o=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];o=!!h.text&&an(h.text)===0}if(o){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:s}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),s.show()});g(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e;t.getCommentEditor().edit(),r.hide()});g(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:r}=e,{comment:i}=t;this.commentsProvider.localDeleteComment(i.id),r.show()});g(this,"execute",(t,e,r,i)=>{const o=rj(t);if(!o||oj(o))return;const s=ij(o);switch(s){case Jt.SwitchUp:this.handleSwitchUp(i);break;case Jt.SwitchDown:this.handleSwitchDown(i);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,r);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,r);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,r);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;S0.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const I0=D("comment-group-list");class vj extends tf{constructor(e,r,i){super(e,r,i,rs(e,r),{});g(this,"groupItemHandlers");g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const r=e.target.closest(".comment-group-item-root");if(!r)return;const i=nj(e.target),o=this.items.findIndex(s=>s.root===r);if(o!==-1){this.setActiveItem(o);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[o],i,o)}});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=ky(this.editor);if(e.length>0){if(((r=this.activeItem)==null?void 0:r.comment.id)&&e.includes(this.activeItem.comment.id))return;const i=e[0],o=this.items.findIndex(s=>s.comment.groupId===i);this.setActiveItem(o),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});g(this,"handleEditorResize",()=>{this.updateItemsLayout()});g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"handleItemResize",()=>{this.updateItemsLayout()});g(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const r=document.elementFromPoint(e.clientX,e.clientY);if(!r||!(r instanceof HTMLElement)||!this.editor.scrollContainer.contains(r))return;const i=this.container.querySelector(".comment-group-item-root");if(!i)return;const o=Number.parseFloat(i.style.top),s=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(o)&&!Number.isNaN(s)&&o<s&&Uy(this.editor,this.items,null,Math.min(o+(0-e.deltaY)*3,s))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(I0,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Fe.default(()=>{const e=rs(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const o=e[i];if(!this.findGroupItem(o.groupId)){this.handleCreateComment(o,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const o=this.items[i];e.findIndex(s=>s.groupId===o.comment.groupId)===-1&&(this.deleteItem(o.comment.id),r=!0)}r&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(o=>o.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new Bj(this,r)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){Uy(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,r){const i=new xj(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{ot(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=rs(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}insertItem(e,r){const i=super.insertItem(e);return i?(r!=null&&r.active&&this.setActiveItem(this.items.indexOf(i)),this.updateItemsLayout(),i.addListener("resize",this.handleItemResize),i):null}setActiveItem(e,r){if(p(I0,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const i=this.container.querySelector(".comment-group-item-root.active");if(i&&ot(i,"active"),e!==-1){const o=this.items[e];z(o.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,r)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(r=>r.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,r){if(ll(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(I0,!i,"comment group item has already exists");const o={children:[],...e};p(I0,o.children,"not a comment group");const s=this.insertItem(o,{active:r});if(!!s&&r){const l=this.items.indexOf(s);this.setActiveItem(l),s.quickReply.hide(),setTimeout(()=>{s.edit()},300)}}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?(this.deleteItem(i.comment.id),this.updateItemsLayout()):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&(this.deleteItem(i.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}}const Tj="comment-mini";D("comment-list");class kj extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"groupsContainer");g(this,"list");g(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});g(this,"updateCommentCount",()=>{var r,i;const e=aj(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var o,s;const i=this.list.activeItem;yy(this.editor,(s=(o=i==null?void 0:i.comment)==null?void 0:o.groupId)!=null?s:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=Rt(this.root,Tj);(i=(r=this.commentOptions)==null?void 0:r.onUpdateLayout)==null||i.call(r,this.editor,{expand:e})});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-web-comment-root"],null),this.groupsContainer=B("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r),this.updateCommentCount()}onDeleteComment(e,r){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}createList(){return new vj(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var r;if(ot(this.root,"hidden"),e){const i=this.list.findItemIndex(e);this.list.setActiveItem(i)}(r=this.commentOptions)==null||r.controller.showCommentList()}hide(){z(this.root,"hidden")}}class Rj extends tf{constructor({editor:t,parent:e,commentsProvider:r,comments:i}){super(t,r,e,i,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:r}=this;return new Iy(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const D0=D("mobile-comment-group-item"),yj=20;class wj extends Te.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>B("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=new Iy(r,i,o);return e.append(s.root),s});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:o}=this,s=B("div",["mobile-comment-children-list-container"],e);return new Rj({editor:r,commentsProvider:i,comments:o.children,parent:s})});g(this,"handleTouchEnd",()=>{var o;const{scroller:e}=this,{pullThreshold:r=yj}=(o=this.editor.getComponentOptions("comment"))!=null?o:{};let i=null;if(e.y>e.minScrollY+r?(i=this.root.previousElementSibling,i||this.emit("onReachTop")):e.y<e.maxScrollY-r&&(i=this.root.nextElementSibling,i||this.emit("onReachBottom")),i){const s=i.id;this.emit("onSwitchGroup",s,Ey)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=B("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const o=B("div",["mobile-group-item"],this.root),s=B("div",["mobile-group-item-space"],null),l=B("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=B("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),o.append(s,l,c),this.scroller=new Dx.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return Ay(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(D0,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){D0.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(D0,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(D0,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const cE=D("mobile-group-list");class Lj extends tf{constructor(e,r,i,o){super(e,r,i,rs(e,r),{});g(this,"scroller");g(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});g(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const r=this.findItemIndex(e);let i=null;return r===0?i=this.items[r+1].root.id:i=this.items[r-1].root.id,super.deleteItem(e)?(this.scrollToGroup(i,Ey),!0):!1});g(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});g(this,"handleReachBottom",()=>{this.emit("onReachBottom")});g(this,"handleReachTop",()=>{this.emit("onReachTop")});g(this,"scrollToGroup",(e,r=0)=>{const i=this.findGroupItem(e);p(cE,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),yy(this.editor,i.comment.groupId)});g(this,"findGroupItem",e=>this.items.find(r=>r.comment.groupId===e));g(this,"handleDocChanged",()=>{this.updateComments()});g(this,"updateComments",Fe.default(()=>{const e=rs(this.editor,this.commentsProvider);for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1);continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(o=>o.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new Dx.default(o),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new wj(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=rs(this.editor,this.commentsProvider).findIndex(o=>o.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(ll(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const i=this.findItem(e.id);p(cE,!i,"comment group item has already exists");const o={children:[],...e};p(cE,o.children,"not a comment group"),this.insertItem(o),this.scroller.refresh()}handleDeleteComment(e){for(let r=0;r<this.items.length;r++){const i=this.items[r];if(i.comment.id===e){i.childrenList.items.length===0?this.deleteItem(i.comment.id):i.deleteMainComment(e);return}if(i.childrenList.deleteItem(e)){i.commentCount===0&&this.deleteItem(i.comment.id);return}}}handleUpdateComment(e){if(ll(e)){const i=this.commentsProvider.getComment(e.groupId),o=this.findItem(i.id);o&&o.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const Sj=D("mobile-comment-list"),{t:Oy}=_;class Ij extends Te.TypedEmitter{constructor(e,r){super();g(this,"root");g(this,"list");g(this,"mask");g(this,"pullInfoContainer");g(this,"handleRootClick",e=>{const r=e.target;p(Sj,r instanceof Element,"invalid target"),!(r.closest(".mobile-group-item-abstract")||r.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});g(this,"hidePullInfo",Fe.default(()=>{ot(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;ot(this.root,"hidden"),z(document.documentElement,"disabled-scroll"),(r=this.commentOptions)==null||r.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});g(this,"hide",()=>{z(this.root,"hidden"),ot(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mobile-comments-root"],null),this.mask=B("div",["mobile-comment-mask"],this.root);const i=B("div",["mobile-comment-groups-container"],this.root),o=B("div",["mobile-comment-groups-scroll-container"],i);this.list=new Lj(this.editor,this.commentsProvider,o,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleUpdateComment(i)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=B("div",["mobile-comment-pull-info-container"],this.root);return B("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=Oy(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=r,z(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function Ny(n,t){const e=rs(n,t),r=new Map;for(const i of e){const o=xy(n,i.groupId);if(!!o)if(r.has(o)){const s=r.get(o);Ty(i).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=Ty(i),l=new Set(s.map(c=>c.id));r.set(o,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,o])=>({blockId:i,...o}))}const Dj=D("mini-group-item");class _j{constructor(t,e){g(this,"root");g(this,"blockId");g(this,"comment");g(this,"miniCommentItem");g(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=B("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new gj(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return xy(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);p(Dj,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class Mj extends tf{constructor(e,r,i){super(e,r,i,Ny(e,r),{});g(this,"fixListOps",Fe.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));g(this,"handleDocChanged",Fe.default(()=>{this.updateMiniCommentsGroup()},100));g(this,"updateMiniCommentsGroup",()=>{const e=Ny(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=r,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new _j(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,r){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const Uj=D("mini-comments-list");class Oj extends Te.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=B("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new Mj(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(Uj,i instanceof HTMLElement,"The target is not a valid html element");const o=i.closest(".mini-comment-item");o&&this.emit("onItemClick",o.id)});this.editor=e,this.commentsProvider=r,this.root=B("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,r){const i=this.commentsProvider.getComment(e);this.list.handleCreateComment(i,r)}onDeleteComment(e,r){this.list.handleDeleteComment(e)}onUpdateComment(e,r){}show(){ot(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function Py(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const r=t.block,i=Ee(n,r,t.start.offset,t.end.offset),o=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;K3(n,r,i,o,s)}function Nj(n,t,e){const r=ci(n).map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{ci(n,{simpleBlockOnly:!0}).forEach(c=>{!nt(n,c.block)||Py(n,c,o)});const l=Yi();e.localCreateComment(o,l)}),o}class Pj{constructor(t,e){g(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,r){const i=t.selection.range;if(nt(t,e)&&!r.isCollapsed()&&i.isSimple()){const o=st(e),s=St(e),l=Ir(t,e);return[{id:"add-comment",name:_.t("comment.command"),blockId:o,blockType:s,blockKind:l,groupIndex:1e3,icon:Qs}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,r,i,o){if(r.id==="add-comment"){this.editorComments.showCommentList();const s=Nj(t,e,this.provider);return o["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class Fy{constructor(t,e){g(this,"commentList",null);g(this,"mobileCommentList",null);g(this,"miniCommentList");g(this,"showComment",(t,e)=>{var r,i;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((r=this.mobileCommentList)==null||r.show(e)),t==="web"&&((i=this.commentList)==null||i.show(e))});g(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});g(this,"handleCommentListClose",()=>{this.showComment("mini")});g(this,"handleOnSelectComment",()=>{this.showComment("web")});g(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new Pj(e,this)),t.blockHooks.push(new JH(this.provider,this)),this.isMobile?(this.mobileCommentList=new Ij(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new kj(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new Oj(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new tj)}get commentProvider(){return this.provider}get isMobile(){return ge.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const Mit="",Fj={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u5B9A",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u6DFB\u52A0\u6279\u6CE8\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},Kj={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotation or mention someone",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},Vj={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u5B9A",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0\u3059\u308B\u304B\u30E1\u30F3\u30D0\u30FC\u3092\u30E1\u30F3\u30B7\u30E7\u30F3",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":Fj,"en-US":Kj,"ja-JP":Vj});class Ky{renderText(t,e,r){const i=[],o={};return Object.entries(r).forEach(([s,l])=>{s.startsWith("comment-")&&(i.push("comment"),o[s]=l)}),{classes:i,attributes:o}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const o=["comment"],s={};return i.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:o,attributes:s}}updateBlock(t,e,r,i){const o=i.comments;ot(r,"comment"),Array.from(r.attributes).forEach(s=>{s.name.startsWith("comment-")&&r.removeAttribute(s.name)}),!(!o||o.length===0)&&(z(r,"comment"),o.forEach(s=>{r.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class $j{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,o)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();g0(t,e,_.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function Hj(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const s=new Set(i);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const o=r.text;if(!!o&&nt(n,t)){const s=Pg(o,`comment-${e.toLocaleLowerCase()}`,e);yc.default(o,s)||n.setBlockText(t,s)}}const jj=D("editor-comment");function zj(n){const t=n.getCustom("editor-comments");if(p(jj,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Fo(s);if(l.length>=2){const{containerId:c}=l[l.length-1],d=rt(li(n,c));if(d&&St(d)==="code"){rE(n,d,t.commentProvider);return}}rE(n,s,t.commentProvider);return}const e=ci(n,{simpleBlockOnly:!0}),r=e.map(s=>s.block),i=nE(n,r),o=w0({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?Py(n,l,o):py(n,l.block,o)});const s=Yi();t.commentProvider.localCreateComment(o,s)})}const uE=D("text-styles");function Gj(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([o])=>!!o.startsWith("style-"));return new Map(i)};if(n.length===0)return new Map;let e=t(n[0]);for(let r=1;r<n.length;r++){const i=t(n[r]);e=new Map(Array.from(e.entries()).filter(([o,s])=>i.get(o)===s))}return e}function Wj(n,t,e,r,i){p(uE,e.isSimple(),"invalid range");const{start:o,end:s}=e;p(uE,o.blockId===s.blockId&&o.blockId===st(t),"invalid range"),p(uE,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=ra(o.offset,s.offset-o.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=ra(o.offset,s.offset-o.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=ra(o.offset,s.offset-o.offset,c,r,void 0,{ignoreValue:!0}):c=Gc(o.offset,s.offset-o.offset,c,r,i),n.setBlockText(t,c),c}const al=D("text-commands");function Vy(n){const t={id:"more",name:_.t("commands.more"),icon:rp,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[_.t("commands.bold"),ur("CtrlOrCmd+B"),I2],"style-italic":[_.t("commands.italic"),ur("CtrlOrCmd+I"),D2],"style-underline":[_.t("commands.underline"),ur("CtrlOrCmd+U"),_2],"style-strikethrough":[_.t("commands.strikethrough"),ur("CtrlOrCmd+D"),M2],"style-code":[_.t("commands.code"),void 0,U2]},r={"style-super":[_.t("commands.superscript"),void 0,N2],"style-sub":[_.t("commands.subscript"),void 0,O2]};if(an(n)===0){const l=Object.entries(e).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h}));return t.children=Object.entries(r).map(([c,[d,h,C]])=>({id:c,name:d,icon:C,desc:h})),l.concat(t)}const i=Gj(n);function o([l,[c,d,h]]){const C=i.get(l);return C!==void 0?{id:l,name:c,value:C,states:C===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:c,icon:h,desc:d}}const s=Object.entries(e).map(o);return t.children=Object.entries(r).map(o),s.concat(t)}function qj(n,t){const e=st(t),r=St(t),i=Ir(n,t);return Vy([]).map(o=>({blockId:e,blockType:r,blockKind:i,...o,groupIndex:500}))}function Xj(n,t,e){p(al,e.isSimple(),"nor a simple range");const{start:r,end:i}=e;p(al,r.isSimple(),"is not a simple block position"),p(al,i.isSimple(),"is not a simple block position"),p(al,nt(n,t),"invalid block type, not a text kind block");const o=st(t);p(al,r.blockId===o&&i.blockId===o,"invalid range");const s=n.getBlockText(t);let l=[];r.offset===i.offset?r.offset!==0&&(l=Xe(s,r.offset-1,1).middle):l=Xe(s,r.offset,i.offset-r.offset).middle;const c=St(t),d=Ir(n,t);return Vy(l).map((h,C)=>({blockId:o,blockType:c,blockKind:d,...h,groupIndex:500,order:C*100}))}function Qj(n,t,e,r,i,o){if(!nt(n,t))return!1;if(!r.startsWith("style-"))return al.warn(`unknown command: ${r}`),!1;const s=i==null?void 0:i.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return al.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const c=Wj(n,t,e,r,s);return o.result=c,!0}const Yj=D("text-command-provider");class ki{constructor(t){g(this,"id","TextCommandProvider");g(this,"emptyTextBlockAttributes",new Map);g(this,"colorItem");g(this,"updateButtonColor",t=>{const e=H3(this.editor,t,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(e)});g(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")V3(this.editor,t,e,this.setEmptyTextBlockColor);else{const r=["clearAll","clearColor","clearBackground"];$3(this.editor,r[e],this.setEmptyTextBlockColor)}});g(this,"getEmptyTextBlockColor",(t,e)=>{const r=this.getEmptyBlockTextAttributes(t,e);return Fg(r)});g(this,"setEmptyTextBlockColor",(t,e,r,i)=>{var s;const o=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};M5(o,r,i),this.emptyTextBlockAttributes.set(e,o)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new eM(t)),this.colorItem.addListener("onClick",this.handleChangeColor)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,r){if(!nt(t,e))return[];let i;ft(t,e)===0?i=this.getCommandsOnEmptyText(t,e).map(ki.toTextCommand):i=Xj(t,e,r).map(ki.toTextCommand),this.updateButtonColor(r);const s={...this.colorItem,blockId:st(e),blockKind:Ir(t,e),blockType:St(e),groupIndex:500,order:350};return i.push(s),i}executeCommand(t,e,r,i,o,s){if(!nt(t,e))return!1;let l=o.value;l===void 0&&(l=!i.value);const c=ki.fromTextCommandId(i.id);if(c.startsWith("style-")){if(c==="style-font")return this.handleChangeColor(o.type,l),!0;if(ft(t,e)===0)return this.executeCommandOnEmptyText(e,i,{value:l})}return Qj(t,e,r,c,{value:l},s)}executeCommandOnEmptyText(t,e,r){let i=this.emptyTextBlockAttributes.get(st(t));i||(i={},this.emptyTextBlockAttributes.set(st(t),i));const o=ki.fromTextCommandId(e.id),s=r.value;return s==null||s===!1?(delete i[o],!0):(i[o]=r.value,!0)}getCommandsOnEmptyText(t,e){const r=qj(t,e);return this.setCommandsStates(r,e)}setCommandsStates(t,e){var o;const r=st(e),i=(o=this.emptyTextBlockAttributes.get(r))!=null?o:{};return t.map(s=>{const l=i[s.id],c=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:c}})}getEmptyBlockTextAttributes(t,e){var i;const r=gt.default((i=this.emptyTextBlockAttributes.get(e))!=null?i:{});if(Array.from(Object.entries(r)).forEach(([o,s])=>{s||delete r[o]}),Object.keys(r).length!==0)return r}static toTextCommand(t){return t.children&&(t.children=t.children.map(ki.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return p(Yj,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(ki.toTextCommand)}static fromTextCommands(t){return t.map(ki.fromTextCommand)}}function $y(n){const t=n.findCustom("toolbar-handler");t==null||t.disableTextToolbar(),t==null||t.hide(),setTimeout(()=>{t==null||t.enableTextToolbar()},300)}function Zj(n){n.undoManager.canUndo()&&$y(n)}function Jj(n){n.undoManager.canRedo()&&$y(n)}const tz={"CtrlOrCmd+Z":Zj,"CtrlOrCmd+Shift+Z":Jj},ez={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},nz={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},rz={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};_.mergeLang({"zh-CN":ez,"en-US":nz,"ja-JP":rz});const iz={embedProperties:{edit:"\u7F16\u8F91",addComment:"\u6DFB\u52A0\u6279\u6CE8"}},oz={embedProperties:{edit:"Edit",addComment:"Add annotation"}},sz={embedProperties:{edit:"\u7DE8\u96C6",addComment:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0"}};_.mergeLang({"zh-CN":iz,"en-US":oz,"ja-JP":sz});const Hy=D("embed-block-properties");function ef(n,t){var e;for(const r of n.blockHooks){const i=(e=r.commands)==null?void 0:e.call(r,n,t);if(!!i&&i.group==="block-comment-actions")return i.executeCommand(n,t,i.commands[0]),!0}return!1}class fE{constructor(t,e,r){g(this,"group","hovering-toolbar");g(this,"_commands",[{id:"edit",name:_.t("embedProperties.edit"),icon:Dh},{id:"add-comment",name:_.t("embedProperties.addComment"),icon:Qs}]);this.editor=t,this.block=e,this.properties=r}get commands(){var i,o,s;if(this.editor.readonly)return[];let t=this._commands;const{enableComments:e=!0}=this.editor.options;e||(t=t.filter(l=>l.id!=="add-comment")),t.forEach(l=>{(l.id==="add-comment"||l.id==="edit")&&(l.states=this.editor.isBlockWritable(this.block)?[]:["disabled"])});let r=(i=this.properties)!=null&&i.presetIds?t.filter(l=>{var c,d;return(d=(c=this.properties)==null?void 0:c.presetIds)==null?void 0:d.includes(l.id)}):[...t];return(s=(o=this.properties)==null?void 0:o.extCommands)!=null&&s.length&&(r.length&&r.push({id:et(),type:"separator",name:""}),r.push(...this.properties.extCommands)),r.length<=3&&(r=r.filter(l=>l.id!=="separator")),r}executeCommand(t,e,r){var i,o;if(!((o=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&o.call(i,t,e,r))){if(r.id==="add-comment"){ef(t,e)||Hy.error("failed to add comment to block");return}Hy.error(`unknown command: ${JSON.stringify(r)}`)}}}function dE(n,t,e){return{blockCommands:{"hovering-toolbar":new fE(n,t,e)}}}class nf{constructor(t){g(this,"blockResizer");g(this,"handleResizing",(t,e)=>{var i,o;const r=t.getBlock();if(r){if(((o=(i=Zt(this.editor,r)).notify)==null?void 0:o.call(i,this.editor,"resize",{block:r,rect:e}))===!0)return;const s=Math.max(e.height,100),d={...this.editor.getBlockData(r).embedData,height:s};this.editor.updateEmbedData(r,d)}});g(this,"handleHoveringBlockChange",(t,e)=>{e&&Ie(e)&&Rt(e,"resizable")&&this.disableResizer(),t&&Ie(t)&&Rt(t,"resizable")&&this.editor.isBlockWritable(t)&&this.tryEnableResizer(t)});this.editor=t,be.get(t).addListener("change",this.handleHoveringBlockChange),this.blockResizer=new Pu(this.editor,{resize:["bottom"]}),this.blockResizer.addListener("resizing",this.handleResizing)}destroy(){be.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}tryEnableResizer(t){this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}static get(t){return t.addCustom("EmbedBlockResizer",()=>new nf(t))}static register(t,e){return z(e,"resizable"),t.addCustom("EmbedBlockResizer",()=>new nf(t))}}var jy=(n=>(n.Card="card",n.Preview="preview",n))(jy||{});const lz=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="#5587F0">
694
694
  <g clip-path="url(#clip0)">
695
695
  <path d="M6.01 10.4886C5.85 10.4886 5.7 10.4286 5.58 10.3086L3.98 8.71859C3.35 8.07859 3 7.23859 3 6.34859C3 5.45859 3.35 4.60859 3.98 3.97859C5.29 2.66859 7.41 2.66859 8.72 3.97859L10.31 5.56859C10.55 5.80859 10.55 6.18859 10.31 6.42859C10.07 6.66859 9.69 6.66859 9.45 6.42859L7.86 4.83859C7.03 4.00859 5.68 4.00859 4.85 4.83859C4.45 5.23859 4.23 5.77859 4.23 6.34859C4.23 6.91859 4.45 7.44859 4.85 7.85859L6.44 9.44859C6.68 9.68859 6.68 10.0686 6.44 10.3086C6.32 10.4286 6.16 10.4886 6.01 10.4886ZM11.65 14.9986C10.79 14.9986 9.93 14.6686 9.28 14.0186L7.4 12.1386C7.16 11.8986 7.16 11.5186 7.4 11.2786C7.64 11.0386 8.02 11.0386 8.26 11.2786L10.14 13.1586C10.97 13.9886 12.32 13.9886 13.15 13.1586C13.55 12.7586 13.77 12.2186 13.77 11.6486C13.77 11.0786 13.55 10.5486 13.15 10.1386L11.28 8.25859C11.04 8.01859 11.04 7.63859 11.28 7.39859C11.52 7.15859 11.9 7.15859 12.14 7.39859L14.02 9.27859C14.65 9.90859 15 10.7486 15 11.6486C15 12.5386 14.65 13.3886 14.02 14.0186C13.37 14.6686 12.51 14.9986 11.65 14.9986Z" fill="currentColor"/>
696
696
  <path d="M10.88 10.8604C10.67 11.0704 10.32 11.0704 10.1 10.8604L7.64004 8.40039C7.43004 8.19039 7.43004 7.84039 7.64004 7.62039C7.85004 7.41039 8.20004 7.41039 8.42004 7.62039L10.88 10.0804C11.1 10.3004 11.1 10.6404 10.88 10.8604Z" fill="currentColor"/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.7-beta.20",
3
+ "version": "0.0.7-beta.21",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",