@ones-editor/editor 0.0.6-beta.13 → 0.0.6-beta.14

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
@@ -499,7 +499,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
499
499
  <path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
500
500
  </svg>`,gH=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
501
501
  <path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
502
- </svg>`,Ort="",f1="reply-editor-editing",{t:KC}=_;class pH{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();Um(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{yt(this.root,f1)||(z(this.root,f1),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!yt(this.root,f1)||st(this.root,f1)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,s=r.getDoc(),o=u1({editor:t,commentGroupId:e.groupId});i.localCreateComment(o,s),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{yt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{st(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=v("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=el(this.root,Jt.QuickReply,KC("comment.placeholder"));ls(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=v("div",["quick-reply-editor"],this.root),i=Qi(),s=new FC(this.mainEditor,t,i);s.editor.addListener("docChanged",this.handleDocChange),s.editor.addListener("focus",this.handleFocus),s.editor.input.addHandler(new aH(this.groupItem)),r.append(s.root);const o=v("div",["reply-editor-actions"],r),l=pr(Jt.QuickReplyCancel,KC("common.cancel"));ls(l,Jt.QuickReplyCancel);const c=pr(Jt.QuickReplyOk,KC("comment.send"),void 0,["primary","disabled"]);return ls(c,Jt.QuickReplyOk),o.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:s,replyEditorContainer:r,okButton:c}}}const as=D("comment-group-item");class CH extends Te.TypedEmitter{constructor(e,r,i,s){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>v("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=v("div",["comment-children-list-container"],this.root);return new hH({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(as,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{st(i,r9)});const r=e[e.length-1];z(r,r9)});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(as,e,"switchUpButton not exist"),p(as,r,"switchDownButton not exist"),st(r,"disabled"),st(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"):st(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=s,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 ResizeObserver(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return s9(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,s=new pH(e,r,i,this);return this.root.append(s.root),s}createHeader(){const{comment:e}=this,r=v("div",["comment-item-head"],this.root),i=v("span",["item-head-quote"],r);i.innerText=e.abstract;const s=v("span",["item-head-switch"],r),o=el(s,Jt.SwitchUp,"up",mH),l=el(s,Jt.SwitchDown,"down",gH);return ls(o,Jt.SwitchUp),ls(l,Jt.SwitchDown),r}createItem(){const e=v("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:s,groupList:o}=this,l=new p9({mainEditor:r,commentsProvider:i,comment:s,groupList:o,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(as,il(e),"invalid comment, not a child comment"),p(as,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){p(as,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){as.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(as,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(as,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 EH=D("arrange=items"),E9=20;function A9(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 x9(n,t){return Number.parseInt(t.root.style.top,10)}function b9(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let s=i;s<t.length;s++){const o=t[s],l=o.comment,c=A9(n,l.groupId);if(o.root.setAttribute("data-target-top",c.toString()),s===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else o.root.style.top=`${c}px`;continue}const d=t[s-1],h=x9(n,d)+d.root.getBoundingClientRect().height;h>c?o.root.style.top=`${h+E9}px`:o.root.style.top=`${c}px`}for(let s=i-1;s>=0;s--){const o=t[s],l=o.comment,c=A9(n,l.groupId);o.root.setAttribute("data-target-top",c.toString());const d=o.root.getBoundingClientRect(),h=c+d.height,C=t[s+1];p(EH,C,"no next item");const E=x9(n,C);E<h?o.root.style.top=`${E-d.height-E9}px`:o.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const d1=D("comment-group-item-handler");class AH{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(d1,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:s}=r,o=i.getReplyEditor(),l=o.editor.getFocusedBlock(),c={type:"mention",id:et(),box:!0,created:Date.now(),text:s.displayName,iconUrl:s.avatarUrl,mentionId:s.userId};o.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(d1,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:s,getCommentEditor:o}=r,l=o(),c=l.getDoc();this.commentsProvider.localUpdateComment(s,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(d1,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let s=!1;if((c=i.blocks)!=null&&c.length||(s=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];s=!!h.text&&an(h.text)===0}if(s){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:o}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),o.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 s=tH(t);if(!s||nH(s))return;const o=eH(s);switch(o){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=o;d1.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const h1=D("comment-group-list");class xH extends Yu{constructor(e,r,i){super(e,r,i,no(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=J$(e.target),s=this.items.findIndex(o=>o.root===r);if(s!==-1){this.setActiveItem(s);const{groupItemHandlers:o}=this;o.execute(e.target,this.items[s],i,s)}});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=f9(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],s=this.items.findIndex(o=>o.comment.groupId===i);this.setActiveItem(s),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 s=Number.parseFloat(i.style.top),o=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(s)&&!Number.isNaN(o)&&s<o&&b9(this.editor,this.items,null,Math.min(s+(0-e.deltaY)*3,o))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(h1,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Fe.default(()=>{const e=no(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const s=e[i];if(!this.findGroupItem(s.groupId)){this.handleCreateComment(s,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const s=this.items[i];e.findIndex(o=>o.groupId===s.comment.groupId)===-1&&(this.deleteItem(s.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(s=>s.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new AH(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(){b9(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 CH(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{st(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=no(this.editor,this.commentsProvider).findIndex(s=>s.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 s=[i,...i.childrenList.items];for(let o=0;o<s.length;o++){const l=s[o];if(!l.getCommentEditor().editor.readonly&&(!l.getCommentEditor().isEmpty()||e))return r}}return-1}isEditing(){return this.findFirstEditingComment()!==-1}setActiveItem(e,r){if(p(h1,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 s=this.items[this.activeIndex];this.closeEditing(s.comment.id),st(i,"active")}if(e!==-1){const s=this.items[e];z(s.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(il(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(h1,!i,"comment group item has already exists");const s={children:[],...e};p(h1,s.children,"not a comment group");const o=this.insertItem(s,{active:r});if(!!o&&r){const l=this.items.indexOf(o);this.setActiveItem(l),o.quickReply.hide(),setTimeout(()=>{o.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(il(e)){const i=this.commentsProvider.getComment(e.groupId),s=this.findItem(i.id);s&&s.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}}const bH="comment-mini";D("comment-list");class BH 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=sH(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var s,o;const i=this.list.activeItem;h9(this.editor,(o=(s=i==null?void 0:i.comment)==null?void 0:s.groupId)!=null?o:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=yt(this.root,bH);(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=v("div",["editor-web-comment-root"],null),this.groupsContainer=v("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 xH(this.editor,this.commentsProvider,this.groupsContainer)}isEditing(){return this.list.isEditing()}setFirstEditingCommentActive(){this.list.setFirstEditingCommentActive()}show(e){var r;if(st(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 vH extends Yu{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 C9(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const m1=D("mobile-comment-group-item"),TH=20;class RH extends Te.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>v("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:s}=this,o=new C9(r,i,s);return e.append(o.root),o});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:s}=this,o=v("div",["mobile-comment-children-list-container"],e);return new vH({editor:r,commentsProvider:i,comments:s.children,parent:o})});g(this,"handleTouchEnd",()=>{var s;const{scroller:e}=this,{pullThreshold:r=TH}=(s=this.editor.getComponentOptions("comment"))!=null?s:{};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 o=i.id;this.emit("onSwitchGroup",o,i9)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=v("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const s=v("div",["mobile-group-item"],this.root),o=v("div",["mobile-group-item-space"],null),l=v("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=v("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),s.append(o,l,c),this.scroller=new u3.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return s9(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(m1,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){m1.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(m1,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(m1,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 VC=D("mobile-group-list");class yH extends Yu{constructor(e,r,i,s){super(e,r,i,no(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,i9),!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(VC,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),h9(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=no(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(s=>s.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new u3.default(s),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new RH(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=no(this.editor,this.commentsProvider).findIndex(s=>s.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(il(e)){const o=this.findGroupItem(e.groupId);o&&o.childrenList.insertItem(e)}const i=this.findItem(e.id);p(VC,!i,"comment group item has already exists");const s={children:[],...e};p(VC,s.children,"not a comment group"),this.insertItem(s),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(il(e)){const i=this.commentsProvider.getComment(e.groupId),s=this.findItem(i.id);s&&s.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 kH=D("mobile-comment-list"),{t:B9}=_;class wH 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(kH,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(()=>{st(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;st(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"),st(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=v("div",["editor-mobile-comments-root"],null),this.mask=v("div",["mobile-comment-mask"],this.root);const i=v("div",["mobile-comment-groups-container"],this.root),s=v("div",["mobile-comment-groups-scroll-container"],i);this.list=new yH(this.editor,this.commentsProvider,s,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=v("div",["mobile-comment-pull-info-container"],this.root);return v("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=B9(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 v9(n,t){const e=no(n,t),r=new Map;for(const i of e){const s=o9(n,i.groupId);if(!!s)if(r.has(s)){const o=r.get(s);u9(i).forEach(c=>{o==null||o.commentIds.add(c.id)})}else{const o=u9(i),l=new Set(o.map(c=>c.id));r.set(s,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,s])=>({blockId:i,...s}))}const LH=D("mini-group-item");class SH{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=v("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new dH(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return o9(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(LH,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,o=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${o}px)`})}destroy(){this.root.remove()}}class IH extends Yu{constructor(e,r,i){super(e,r,i,v9(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=v9(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 SH(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 DH=D("mini-comments-list");class _H extends Te.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=v("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new IH(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(DH,i instanceof HTMLElement,"The target is not a valid html element");const s=i.closest(".mini-comment-item");s&&this.emit("onItemClick",s.id)});this.editor=e,this.commentsProvider=r,this.root=v("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(){st(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function T9(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),s=`comment-${e.id.toLocaleLowerCase()}`,o=e.id;a5(n,r,i,s,o)}function MH(n,t,e){const r=ci(n).map(o=>o.block),i=MC(n,r),s=u1({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{ci(n,{simpleBlockOnly:!0}).forEach(c=>{!nt(n,c.block)||T9(n,c,s)});const l=Qi();e.localCreateComment(s,l)}),s}class UH{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 s=ot(e),o=St(e),l=Dr(t,e);return[{id:"add-comment",name:_.t("comment.command"),blockId:s,blockType:o,blockKind:l,groupIndex:1e3,icon:da}]}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,s){if(r.id==="add-comment"){this.editorComments.showCommentList();const o=MH(t,e,this.provider);return s["add-comment"]=o,this.hideToolbar(t),!0}return!1}}class R9{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 UH(e,this)),t.blockHooks.push(new Z$(this.provider,this)),this.isMobile?(this.mobileCommentList=new wH(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new BH(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new _H(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new Q$)}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 Prt="",NH={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"}},OH={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"}},PH={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":NH,"en-US":OH,"ja-JP":PH});class y9{renderText(t,e,r){const i=[],s={};return Object.entries(r).forEach(([o,l])=>{o.startsWith("comment-")&&(i.push("comment"),s[o]=l)}),{classes:i,attributes:s}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const s=["comment"],o={};return i.forEach(l=>{o[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:s,attributes:o}}updateBlock(t,e,r,i){const s=i.comments;st(r,"comment"),Array.from(r.attributes).forEach(o=>{o.name.startsWith("comment-")&&r.removeAttribute(o.name)}),!(!s||s.length===0)&&(z(r,"comment"),s.forEach(o=>{r.setAttribute(`comment-${o.toLocaleLowerCase()}`,o)}))}}class FH{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,s)=>{const o=t.getFocusedBlock(),l=t.getFirstBlock();o===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Qh(t,e,_.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function KH(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const o=new Set(i);o.delete(e),n.updateBlockData(t,{comments:Array.from(o)})}const s=r.text;if(!!s&&nt(n,t)){const o=Im(s,`comment-${e.toLocaleLowerCase()}`,e);Bc.default(s,o)||n.setBlockText(t,o)}}const VH=D("editor-comment");function $H(n){const t=n.getCustom("editor-comments");if(p(VH,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const o=n.selection.startBlock,l=Ps(o);if(l.length>=2){const{containerId:c}=l[l.length-1],d=rt(li(n,c));if(d&&St(d)==="code"){UC(n,d,t.commentProvider);return}}UC(n,o,t.commentProvider);return}const e=ci(n,{simpleBlockOnly:!0}),r=e.map(o=>o.block),i=MC(n,r),s=u1({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?T9(n,l,s):n9(n,l.block,s)});const o=Qi();t.commentProvider.localCreateComment(s,o)})}const $C=D("text-styles");function HH(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([s])=>!!s.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(([s,o])=>i.get(s)===o))}return e}function jH(n,t,e,r,i){p($C,e.isSimple(),"invalid range");const{start:s,end:o}=e;p($C,s.blockId===o.blockId&&s.blockId===ot(t),"invalid range"),p($C,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=ea(s.offset,o.offset-s.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=ea(s.offset,o.offset-s.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=ea(s.offset,o.offset-s.offset,c,r,void 0,{ignoreValue:!0}):c=$c(s.offset,o.offset-s.offset,c,r,i),n.setBlockText(t,c),c}const zH=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
502
+ </svg>`,Ort="",f1="reply-editor-editing",{t:KC}=_;class pH{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();Um(r)?e.disabled=!0:e.disabled=!1});g(this,"getReplyEditor",()=>this.components.replyEditor);g(this,"showReplyEditor",()=>{yt(this.root,f1)||(z(this.root,f1),this.components.replyEditor.edit())});g(this,"hideReplyEditor",()=>{!yt(this.root,f1)||st(this.root,f1)});g(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:r},commentsProvider:i}=this,s=r.getDoc(),o=u1({editor:t,commentGroupId:e.groupId});i.localCreateComment(o,s),this.hideReplyEditor(),r.clear()});g(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});g(this,"hide",()=>{yt(this.root,"hidden")||z(this.root,"hidden")});g(this,"show",()=>{st(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=r,this.groupItem=i,this.root=v("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=el(this.root,Jt.QuickReply,KC("comment.placeholder"));ls(e,Jt.QuickReply),e.classList.add("quick-reply-button");const r=v("div",["quick-reply-editor"],this.root),i=Qi(),s=new FC(this.mainEditor,t,i);s.editor.addListener("docChanged",this.handleDocChange),s.editor.addListener("focus",this.handleFocus),s.editor.input.addHandler(new aH(this.groupItem)),r.append(s.root);const o=v("div",["reply-editor-actions"],r),l=pr(Jt.QuickReplyCancel,KC("common.cancel"));ls(l,Jt.QuickReplyCancel);const c=pr(Jt.QuickReplyOk,KC("comment.send"),void 0,["primary","disabled"]);return ls(c,Jt.QuickReplyOk),o.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:s,replyEditorContainer:r,okButton:c}}}const as=D("comment-group-item");class CH extends Te.TypedEmitter{constructor(e,r,i,s){super();g(this,"root");g(this,"header");g(this,"mainItem");g(this,"childrenList");g(this,"resizeObserver");g(this,"quickReply");g(this,"createRoot",()=>v("div",["comment-group-item-root"],null));g(this,"createChildrenList",()=>{const e=v("div",["comment-children-list-container"],this.root);return new hH({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(as,e.length!==0,"current group item not exist comment-item"),e.forEach(i=>{st(i,r9)});const r=e[e.length-1];z(r,r9)});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(as,e,"switchUpButton not exist"),p(as,r,"switchDownButton not exist"),st(r,"disabled"),st(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"):st(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=s,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 ResizeObserver(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return s9(this.root)}createQuickReply(){const{editor:e,commentsProvider:r,comment:i}=this,s=new pH(e,r,i,this);return this.root.append(s.root),s}createHeader(){const{comment:e}=this,r=v("div",["comment-item-head"],this.root),i=v("span",["item-head-quote"],r);i.innerText=e.abstract;const s=v("span",["item-head-switch"],r),o=el(s,Jt.SwitchUp,"up",mH),l=el(s,Jt.SwitchDown,"down",gH);return ls(o,Jt.SwitchUp),ls(l,Jt.SwitchDown),r}createItem(){const e=v("div",["comment-item-container"],this.root),{editor:r,commentsProvider:i,comment:s,groupList:o}=this,l=new p9({mainEditor:r,commentsProvider:i,comment:s,groupList:o,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(as,il(e),"invalid comment, not a child comment"),p(as,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){p(as,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){as.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(as,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(as,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 EH=D("arrange=items"),E9=20;function A9(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 x9(n,t){return Number.parseInt(t.root.style.top,10)}function b9(n,t,e,r){let i=0;e&&(i=t.indexOf(e),i===-1&&(i=0));for(let s=i;s<t.length;s++){const o=t[s],l=o.comment,c=A9(n,l.groupId);if(o.root.setAttribute("data-target-top",c.toString()),s===i){if(r!==void 0){const C=t[0];C.root.style.top=`${r}px`}else o.root.style.top=`${c}px`;continue}const d=t[s-1],h=x9(n,d)+d.root.getBoundingClientRect().height;h>c?o.root.style.top=`${h+E9}px`:o.root.style.top=`${c}px`}for(let s=i-1;s>=0;s--){const o=t[s],l=o.comment,c=A9(n,l.groupId);o.root.setAttribute("data-target-top",c.toString());const d=o.root.getBoundingClientRect(),h=c+d.height,C=t[s+1];p(EH,C,"no next item");const E=x9(n,C);E<h?o.root.style.top=`${E-d.height-E9}px`:o.root.style.top=`${c}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const d1=D("comment-group-item-handler");class AH{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(d1,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t;i.show(),i.showReplyEditor();const{comment:s}=r,o=i.getReplyEditor(),l=o.editor.getFocusedBlock(),c={type:"mention",id:et(),box:!0,created:Date.now(),text:s.displayName,iconUrl:s.avatarUrl,mentionId:s.userId};o.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(d1,r,`the commentItem: ${e} not exist `);const{quickReply:i}=t,{comment:s,getCommentEditor:o}=r,l=o(),c=l.getDoc();this.commentsProvider.localUpdateComment(s,c),l.readonly(),i.show()});g(this,"handleCommentItemCancel",(t,e)=>{var c,d;const r=t.findCommentItem(e);p(d1,r,`the commentItem: ${e} not exist `);const i=this.commentsProvider.getComment(r.comment.id);let s=!1;if((c=i.blocks)!=null&&c.length||(s=!0),((d=i.blocks)==null?void 0:d.length)===1){const h=i.blocks[0];s=!!h.text&&an(h.text)===0}if(s){this.commentsProvider.localDeleteComment(r.comment.id);return}const{quickReply:o}=t,l=r.getCommentEditor();l.setDoc(r.doc),l.readonly(),o.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 s=tH(t);if(!s||nH(s))return;const o=eH(s);switch(o){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=o;d1.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const h1=D("comment-group-list");class xH extends Yu{constructor(e,r,i){super(e,r,i,no(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=J$(e.target),s=this.items.findIndex(o=>o.root===r);if(s!==-1){this.activeIndex!==s&&this.setActiveItem(s);const{groupItemHandlers:o}=this;o.execute(e.target,this.items[s],i,s)}});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];i!=null&&i.comment&&this.closeEditing(i.comment.id)});g(this,"handleSelectionChanged",()=>{setTimeout(()=>{var r;const e=f9(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],s=this.items.findIndex(o=>o.comment.groupId===i);this.setActiveItem(s),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 s=Number.parseFloat(i.style.top),o=Number.parseFloat(i.getAttribute("data-target-top")||"0");!Number.isNaN(s)&&!Number.isNaN(o)&&s<o&&b9(this.editor,this.items,null,Math.min(s+(0-e.deltaY)*3,o))});g(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;p(h1,e,"invalid activeItem"),e.updateSwitchButton()});g(this,"updateComments",Fe.default(()=>{const e=no(this.editor,this.commentsProvider);let r=!1;for(let i=0;i<e.length;i++){const s=e[i];if(!this.findGroupItem(s.groupId)){this.handleCreateComment(s,!1),r=!0;continue}}for(let i=this.items.length-1;i>=0;i--){const s=this.items[i];e.findIndex(o=>o.groupId===s.comment.groupId)===-1&&(this.deleteItem(s.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(s=>s.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new AH(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(){b9(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 CH(this.editor,this.commentsProvider,e,this);return r==="insert"&&(z(i.root,"no-animation"),i.root.style.opacity="0",setTimeout(()=>{st(i.root,"no-animation"),i.root.style.opacity="1"},150)),i}findInsertPos(e){const i=no(this.editor,this.commentsProvider).findIndex(s=>s.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 s=[i,...i.childrenList.items];for(let o=0;o<s.length;o++){const l=s[o];if(!l.getCommentEditor().editor.readonly&&(!l.getCommentEditor().isEmpty()||e))return r}}return-1}isEditing(){return this.findFirstEditingComment()!==-1}setActiveItem(e,r){if(p(h1,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 s=this.items[this.activeIndex];this.closeEditing(s.comment.id),st(i,"active")}if(e!==-1){const s=this.items[e];z(s.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(il(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const i=this.findItem(e.id);p(h1,!i,"comment group item has already exists");const s={children:[],...e};p(h1,s.children,"not a comment group");const o=this.insertItem(s,{active:r});if(!!o&&r){const l=this.items.indexOf(o);this.setActiveItem(l),o.quickReply.hide(),setTimeout(()=>{o.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(il(e)){const i=this.commentsProvider.getComment(e.groupId),s=this.findItem(i.id);s&&s.handleUpdateChildComment(e);return}const r=this.findItem(e.id);r&&r.handleUpdateMainComment(e)}}const bH="comment-mini";D("comment-list");class BH 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=sH(this.editor,this.commentsProvider);(i=(r=this.commentOptions)==null?void 0:r.onCommentCountChange)==null||i.call(r,e)});g(this,"handleActiveItemChanged",(e,r)=>{var s,o;const i=this.list.activeItem;h9(this.editor,(o=(s=i==null?void 0:i.comment)==null?void 0:s.groupId)!=null?o:"",r)});g(this,"handleItemLayoutUpdated",()=>{var r,i;const e=yt(this.root,bH);(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=v("div",["editor-web-comment-root"],null),this.groupsContainer=v("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 xH(this.editor,this.commentsProvider,this.groupsContainer)}isEditing(){return this.list.isEditing()}setFirstEditingCommentActive(){this.list.setFirstEditingCommentActive()}show(e){var r;if(st(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 vH extends Yu{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 C9(e,r,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const m1=D("mobile-comment-group-item"),TH=20;class RH extends Te.TypedEmitter{constructor(e,r,i){super();g(this,"root");g(this,"childrenList");g(this,"mainItem");g(this,"scroller");g(this,"createRoot",()=>v("div",["mobile-group-item-root"],null));g(this,"createMainItem",e=>{const{editor:r,commentsProvider:i,comment:s}=this,o=new C9(r,i,s);return e.append(o.root),o});g(this,"createChildrenList",e=>{const{editor:r,commentsProvider:i,comment:s}=this,o=v("div",["mobile-comment-children-list-container"],e);return new vH({editor:r,commentsProvider:i,comments:s.children,parent:o})});g(this,"handleTouchEnd",()=>{var s;const{scroller:e}=this,{pullThreshold:r=TH}=(s=this.editor.getComponentOptions("comment"))!=null?s:{};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 o=i.id;this.emit("onSwitchGroup",o,i9)}});g(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=r,this.comment=i,this.root=v("div",["mobile-group-item-root"],null),this.root.id=i.groupId;const s=v("div",["mobile-group-item"],this.root),o=v("div",["mobile-group-item-space"],null),l=v("div",["mobile-group-item-abstract"],null);l.textContent=i.abstract;const c=v("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),s.append(o,l,c),this.scroller=new u3.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return s9(this.root,".mobile-group-item")}handleUpdateChildComment(e){p(m1,e.groupId===this.mainItem.comment.id,"invalid child comment");const r=this.childrenList.findItem(e.id);if(!r){m1.error(`can't find child comment item: ${e.id}`);return}r.reloadDoc()}handleUpdateMainComment(e){p(m1,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){p(m1,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 VC=D("mobile-group-list");class yH extends Yu{constructor(e,r,i,s){super(e,r,i,no(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,i9),!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(VC,i,"invalid scroll target"),this.scroller.scrollToElement(i.root,r,!1,!1),h9(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=no(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(s=>s.groupId===i.comment.groupId)===-1&&this.deleteItem(i.comment.id)}},100));this.scroller=new u3.default(s),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new RH(this.editor,this.commentsProvider,e)}insertItem(e){const r=super.insertItem(e);return r?(this.setupGroupItem(r),r):null}findInsertPos(e){const i=no(this.editor,this.commentsProvider).findIndex(s=>s.id===e.id);return i===-1||i>this.items.length?-1:i}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,r){if(il(e)){const o=this.findGroupItem(e.groupId);o&&o.childrenList.insertItem(e)}const i=this.findItem(e.id);p(VC,!i,"comment group item has already exists");const s={children:[],...e};p(VC,s.children,"not a comment group"),this.insertItem(s),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(il(e)){const i=this.commentsProvider.getComment(e.groupId),s=this.findItem(i.id);s&&s.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 kH=D("mobile-comment-list"),{t:B9}=_;class wH 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(kH,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(()=>{st(this.pullInfoContainer,"active")},1e3*3));g(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});g(this,"handleReachTop",()=>{this.showPullInfo("top")});g(this,"show",e=>{var r;st(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"),st(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=r,this.root=v("div",["editor-mobile-comments-root"],null),this.mask=v("div",["mobile-comment-mask"],this.root);const i=v("div",["mobile-comment-groups-container"],this.root),s=v("div",["mobile-comment-groups-scroll-container"],i);this.list=new yH(this.editor,this.commentsProvider,s,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=v("div",["mobile-comment-pull-info-container"],this.root);return v("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const r=B9(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 v9(n,t){const e=no(n,t),r=new Map;for(const i of e){const s=o9(n,i.groupId);if(!!s)if(r.has(s)){const o=r.get(s);u9(i).forEach(c=>{o==null||o.commentIds.add(c.id)})}else{const o=u9(i),l=new Set(o.map(c=>c.id));r.set(s,{commentIds:l,firstComment:i})}}return Array.from(r.entries()).map(([i,s])=>({blockId:i,...s}))}const LH=D("mini-group-item");class SH{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=v("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new dH(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return o9(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(LH,e,`The blockId: ${t} not exist in doc`);const r=this.editor.scrollContainer.getBoundingClientRect(),i=this.editor.scrollContainer.scrollTop,o=e.getBoundingClientRect().top-r.top+i;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${o}px)`})}destroy(){this.root.remove()}}class IH extends Yu{constructor(e,r,i){super(e,r,i,v9(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=v9(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 SH(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 DH=D("mini-comments-list");class _H extends Te.TypedEmitter{constructor(e,r){super();g(this,"list");g(this,"root");g(this,"createList",()=>{const e=v("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new IH(this.editor,this.commentsProvider,e)});g(this,"handleListContainerClick",(e,r)=>{const i=r.target;p(DH,i instanceof HTMLElement,"The target is not a valid html element");const s=i.closest(".mini-comment-item");s&&this.emit("onItemClick",s.id)});this.editor=e,this.commentsProvider=r,this.root=v("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(){st(this.root,"hidden")}hide(){z(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function T9(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),s=`comment-${e.id.toLocaleLowerCase()}`,o=e.id;a5(n,r,i,s,o)}function MH(n,t,e){const r=ci(n).map(o=>o.block),i=MC(n,r),s=u1({editor:n,abstract:i});return n.undoManager.runInGroup(()=>{ci(n,{simpleBlockOnly:!0}).forEach(c=>{!nt(n,c.block)||T9(n,c,s)});const l=Qi();e.localCreateComment(s,l)}),s}class UH{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 s=ot(e),o=St(e),l=Dr(t,e);return[{id:"add-comment",name:_.t("comment.command"),blockId:s,blockType:o,blockKind:l,groupIndex:1e3,icon:da}]}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,s){if(r.id==="add-comment"){this.editorComments.showCommentList();const o=MH(t,e,this.provider);return s["add-comment"]=o,this.hideToolbar(t),!0}return!1}}class R9{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 UH(e,this)),t.blockHooks.push(new Z$(this.provider,this)),this.isMobile?(this.mobileCommentList=new wH(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new BH(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new _H(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new Q$)}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 Prt="",NH={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"}},OH={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"}},PH={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":NH,"en-US":OH,"ja-JP":PH});class y9{renderText(t,e,r){const i=[],s={};return Object.entries(r).forEach(([o,l])=>{o.startsWith("comment-")&&(i.push("comment"),s[o]=l)}),{classes:i,attributes:s}}renderBlock(t,e,r){const i=r.comments;if(!i||i.length===0)return{};const s=["comment"],o={};return i.forEach(l=>{o[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:s,attributes:o}}updateBlock(t,e,r,i){const s=i.comments;st(r,"comment"),Array.from(r.attributes).forEach(o=>{o.name.startsWith("comment-")&&r.removeAttribute(o.name)}),!(!s||s.length===0)&&(z(r,"comment"),s.forEach(o=>{r.setAttribute(`comment-${o.toLocaleLowerCase()}`,o)}))}}class FH{constructor(t){g(this,"handleUpdateCompositionText",(t,e,r,i,s)=>{const o=t.getFocusedBlock(),l=t.getFirstBlock();o===l&&this.applyPlaceholder(t)});g(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});g(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Qh(t,e,_.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function KH(n,t,e){const r=n.getBlockData(t),i=r.comments;if((i==null?void 0:i.indexOf(e))!==-1){const o=new Set(i);o.delete(e),n.updateBlockData(t,{comments:Array.from(o)})}const s=r.text;if(!!s&&nt(n,t)){const o=Im(s,`comment-${e.toLocaleLowerCase()}`,e);Bc.default(s,o)||n.setBlockText(t,o)}}const VH=D("editor-comment");function $H(n){const t=n.getCustom("editor-comments");if(p(VH,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const o=n.selection.startBlock,l=Ps(o);if(l.length>=2){const{containerId:c}=l[l.length-1],d=rt(li(n,c));if(d&&St(d)==="code"){UC(n,d,t.commentProvider);return}}UC(n,o,t.commentProvider);return}const e=ci(n,{simpleBlockOnly:!0}),r=e.map(o=>o.block),i=MC(n,r),s=u1({editor:n,abstract:i});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?T9(n,l,s):n9(n,l.block,s)});const o=Qi();t.commentProvider.localCreateComment(s,o)})}const $C=D("text-styles");function HH(n){const t=r=>{if(!r.attributes)return new Map;const i=Object.entries(r.attributes).filter(([s])=>!!s.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(([s,o])=>i.get(s)===o))}return e}function jH(n,t,e,r,i){p($C,e.isSimple(),"invalid range");const{start:s,end:o}=e;p($C,s.blockId===o.blockId&&s.blockId===ot(t),"invalid range"),p($C,r.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return r==="style-sub"?c=ea(s.offset,o.offset-s.offset,c,"style-super",i,{ignoreValue:!0}):r==="style-super"&&(c=ea(s.offset,o.offset-s.offset,c,"style-sub",i,{ignoreValue:!0})),i===!1||i===void 0||i===null?c=ea(s.offset,o.offset-s.offset,c,r,void 0,{ignoreValue:!0}):c=$c(s.offset,o.offset-s.offset,c,r,i),n.setBlockText(t,c),c}const zH=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
503
503
  <line x1="3.5" y1="0.5" x2="3.5" y2="15.5" stroke="currentColor"/>
504
504
  <path d="M4 8L7.5 8C9.433 8 11 6.433 11 4.5V4.5C11 2.567 9.433 1 7.5 1L4 1" stroke="currentColor"/>
505
505
  <path d="M4 15L9.5 15C11.433 15 13 13.433 13 11.5V11.5C13 9.567 11.433 8 9.5 8L4 8" stroke="currentColor"/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "0.0.6-beta.13",
3
+ "version": "0.0.6-beta.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",