@ones-editor/editor 0.0.3-beta.220 → 0.0.3-beta.221
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
|
@@ -500,7 +500,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
500
500
|
<path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
501
501
|
</svg>`,VU=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
|
|
502
502
|
<path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
503
|
-
</svg>`,uot="",Kf="reply-editor-editing",{t:x2}=L;class WU{constructor(t,e,o,r){m(this,"root");m(this,"components");m(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});m(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();pg(o)?e.disabled=!0:e.disabled=!1});m(this,"getReplyEditor",()=>this.components.replyEditor);m(this,"showReplyEditor",()=>{xt(this.root,Kf)||(W(this.root,Kf),this.components.replyEditor.edit())});m(this,"hideReplyEditor",()=>{!xt(this.root,Kf)||rt(this.root,Kf)});m(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=Jf({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});m(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});m(this,"hide",()=>{xt(this.root,"hidden")||W(this.root,"hidden")});m(this,"show",()=>{rt(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=k("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=Zs(this.root,Jt.QuickReply,x2("comment.placeholder"));oi(e,Jt.QuickReply),e.classList.add("quick-reply-button");const o=k("div",["quick-reply-editor"],this.root),r=Zr(),i=new E2(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new PU(this.groupItem)),o.append(i.root);const s=k("div",["reply-editor-actions"],o),l=fo(Jt.QuickReplyCancel,x2("common.cancel"));oi(l,Jt.QuickReplyCancel);const a=fo(Jt.QuickReplyOk,x2("comment.send"),void 0,["primary","disabled"]);return oi(a,Jt.QuickReplyOk),s.append(l,a),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:a}}}const ri=S("comment-group-item");class qU extends ve.TypedEmitter{constructor(e,o,r,i){super();m(this,"root");m(this,"header");m(this,"mainItem");m(this,"childrenList");m(this,"resizeObserver");m(this,"quickReply");m(this,"createRoot",()=>k("div",["comment-group-item-root"],null));m(this,"createChildrenList",()=>{const e=k("div",["comment-children-list-container"],this.root);return new UU({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});m(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));g(ri,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{rt(r,Ny)});const o=e.at(-1);W(o,Ny)});m(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');g(ri,e,"switchUpButton not exist"),g(ri,o,"switchDownButton not exist"),rt(o,"disabled"),rt(e,"disabled"),this.root.previousElementSibling===null&&W(e,"disabled"),this.root.nextElementSibling===null&&W(o,"disabled")});m(this,"handleReadonlyChanged",e=>{e.readonly?W(this.root,"readonly"):rt(this.root,"readonly")});m(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,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 Hy(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new WU(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=k("div",["comment-item-head"],this.root),r=k("span",["item-head-quote"],o);r.innerText=e.abstract;const i=k("span",["item-head-switch"],o),s=Zs(i,Jt.SwitchUp,"up",zU),l=Zs(i,Jt.SwitchDown,"down",VU);return oi(s,Jt.SwitchUp),oi(l,Jt.SwitchDown),o}createItem(){const e=k("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new Yy({mainEditor:o,commentsProvider:r,comment:i,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(o=>o.comment.id===e):null}handleCreateComment(e){return g(ri,Js(e),"invalid comment, not a child comment"),g(ri,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){g(ri,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){ri.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(ri,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(ri,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 GU=S("arrange=items"),Ky=20;function Xy(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function t8(n,t){return Number.parseInt(t.root.style.top,10)}function e8(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,a=Xy(n,l.groupId);if(s.root.setAttribute("data-target-top",a.toString()),i===r){if(o!==void 0){const p=t[0];p.root.style.top=`${o}px`}else s.root.style.top=`${a}px`;continue}const d=t[i-1],h=t8(n,d)+d.root.getBoundingClientRect().height;h>a?s.root.style.top=`${h+Ky}px`:s.root.style.top=`${a}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,a=Xy(n,l.groupId);s.root.setAttribute("data-target-top",a.toString());const d=s.root.getBoundingClientRect(),h=a+d.height,p=t[i+1];g(GU,p,"no next item");const C=t8(n,p);C<h?s.root.style.top=`${C-d.height-Ky}px`:s.root.style.top=`${a}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const Xf=S("comment-group-item-handler");class ZU{constructor(t,e){m(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});m(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});m(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});m(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});m(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});m(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);g(Xf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),a={type:"mention",id:K(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,a)});m(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});m(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);g(Xf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),a=l.getDoc();this.commentsProvider.localUpdateComment(i,a),l.readonly(),r.show()});m(this,"handleCommentItemCancel",(t,e)=>{var a,d;const o=t.findCommentItem(e);g(Xf,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);let i=!1;if((a=r.blocks)!=null&&a.length||(i=!0),((d=r.blocks)==null?void 0:d.length)===1){const h=r.blocks[0];i=!!h.text&&rn(h.text)===0}if(i){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:s}=t,l=o.getCommentEditor();l.setDoc(o.doc),l.readonly(),s.show()});m(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});m(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});m(this,"execute",(t,e,o,r)=>{const i=DU(t);if(!i||LU(i))return;const s=SU(i);switch(s){case Jt.SwitchUp:this.handleSwitchUp(r);break;case Jt.SwitchDown:this.handleSwitchDown(r);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,o);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,o);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,o);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;Xf.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const t1=S("comment-group-list");class QU extends ju{constructor(e,o,r){super(e,o,r,Xi(e,o),{});m(this,"groupItemHandlers");m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=TU(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items.at(i),r,i)}});m(this,"handleSelectionChanged",()=>{setTimeout(()=>{var o;const e=Wy(this.editor);if(e.length>0){if(((o=this.activeItem)==null?void 0:o.comment.id)&&e.includes(this.activeItem.comment.id))return;const r=e[0],i=this.items.findIndex(s=>s.comment.groupId===r);this.setActiveItem(i),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});m(this,"handleEditorResize",()=>{this.updateItemsLayout()});m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"handleItemResize",()=>{this.updateItemsLayout()});m(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&e8(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});m(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;g(t1,e,"invalid activeItem"),e.updateSwitchButton()});m(this,"updateComments",Me.default(()=>{const e=Xi(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;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),o=!0)}o&&(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(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new ZU(this,o)}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(){e8(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new qU(this.editor,this.commentsProvider,e,this);return o==="insert"&&(W(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{rt(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=Xi(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e,o){const r=super.insertItem(e);return r?(o!=null&&o.active&&this.setActiveItem(this.items.indexOf(r)),this.updateItemsLayout(),r.addListener("resize",this.handleItemResize),r):null}setActiveItem(e,o){if(g(t1,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const r=this.container.querySelector(".comment-group-item-root.active");if(r&&rt(r,"active"),e!==-1){const i=this.items[e];W(i.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,o)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(Js(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);g(t1,!r,"comment group item has already exists");const i={children:[],...e};g(t1,i.children,"not a comment group");const s=this.insertItem(i,{active:o});!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?(this.deleteItem(r.comment.id),this.updateItemsLayout()):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&(this.deleteItem(r.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const YU="comment-mini";S("comment-list");class JU extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"groupsContainer");m(this,"list");m(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});m(this,"updateCommentCount",()=>{var o,r;const e=OU(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});m(this,"handleActiveItemChanged",(e,o)=>{var i,s;const r=this.list.activeItem;Gy(this.editor,(s=(i=r==null?void 0:r.comment)==null?void 0:i.groupId)!=null?s:"",o)});m(this,"handleItemLayoutUpdated",()=>{var o,r;const e=xt(this.root,YU);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-web-comment-root"],null),this.groupsContainer=k("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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new QU(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(rt(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){W(this.root,"hidden")}}class KU extends ju{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new Jy(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const e1=S("mobile-comment-group-item"),XU=20;class tz extends ve.TypedEmitter{constructor(e,o,r){super();m(this,"root");m(this,"childrenList");m(this,"mainItem");m(this,"scroller");m(this,"createRoot",()=>k("div",["mobile-group-item-root"],null));m(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new Jy(o,r,i);return e.append(s.root),s});m(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=k("div",["mobile-comment-children-list-container"],e);return new KU({editor:o,commentsProvider:r,comments:i.children,parent:s})});m(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=XU}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,$y)}});m(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=k("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=k("div",["mobile-group-item"],this.root),s=k("div",["mobile-group-item-space"],null),l=k("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const a=k("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(a),this.childrenList=this.createChildrenList(a),i.append(s,l,a),this.scroller=new J3.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return Hy(this.root,".mobile-group-item")}handleUpdateChildComment(e){g(e1,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){e1.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(e1,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(e1,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 I2=S("mobile-group-list");class ez extends ju{constructor(e,o,r,i){super(e,o,r,Xi(e,o),{});m(this,"scroller");m(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});m(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,$y),!0):!1});m(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});m(this,"handleReachBottom",()=>{this.emit("onReachBottom")});m(this,"handleReachTop",()=>{this.emit("onReachTop")});m(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);g(I2,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),Gy(this.editor,r.comment.groupId)});m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"updateComments",Me.default(()=>{const e=Xi(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new J3.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new tz(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=Xi(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(Js(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);g(I2,!r,"comment group item has already exists");const i={children:[],...e};g(I2,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const nz=S("mobile-comment-list"),{t:n8}=L;class oz extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"list");m(this,"mask");m(this,"pullInfoContainer");m(this,"handleRootClick",e=>{const o=e.target;g(nz,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});m(this,"hidePullInfo",Me.default(()=>{rt(this.pullInfoContainer,"active")},1e3*3));m(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});m(this,"handleReachTop",()=>{this.showPullInfo("top")});m(this,"show",e=>{var o;rt(this.root,"hidden"),W(document.documentElement,"disabled-scroll"),(o=this.commentOptions)==null||o.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});m(this,"hide",()=>{W(this.root,"hidden"),rt(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mobile-comments-root"],null),this.mask=k("div",["mobile-comment-mask"],this.root);const r=k("div",["mobile-comment-groups-container"],this.root),i=k("div",["mobile-comment-groups-scroll-container"],r);this.list=new ez(this.editor,this.commentsProvider,i,r),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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=k("div",["mobile-comment-pull-info-container"],this.root);return k("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=n8(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,W(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function o8(n,t){const e=Xi(n,t),o=new Map;for(const r of e){const i=jy(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);k2(r).forEach(a=>{s==null||s.commentIds.add(a.id)})}else{const s=k2(r),l=new Set(s.map(a=>a.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const rz=S("mini-group-item");class iz{constructor(t,e){m(this,"root");m(this,"blockId");m(this,"comment");m(this,"miniCommentItem");m(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=k("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new jU(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return jy(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);g(rz,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),r=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-o.top+r;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class sz extends ju{constructor(e,o,r){super(e,o,r,o8(e,o),{});m(this,"fixListOps",Me.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));m(this,"handleDocChanged",Me.default(()=>{this.updateMiniCommentsGroup()},100));m(this,"updateMiniCommentsGroup",()=>{const e=o8(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new iz(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const lz=S("mini-comments-list");class cz extends ve.TypedEmitter{constructor(e,o){super();m(this,"list");m(this,"root");m(this,"createList",()=>{const e=k("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new sz(this.editor,this.commentsProvider,e)});m(this,"handleListContainerClick",(e,o)=>{const r=o.target;g(lz,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){rt(this.root,"hidden")}hide(){W(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function r8(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=ke(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;Z6(n,o,r,i,s)}function az(n,t,e){const o=Oo(n).map(s=>s.block),r=b2(n,o),i=Jf({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{Oo(n,{simpleBlockOnly:!0}).forEach(a=>{!nt(n,a.block)||r8(n,a,i)});const l=Zr();e.localCreateComment(i,l)}),i}class uz{constructor(t,e){m(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(nt(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=it(e),s=Dt(e),l=So(t,e);return[{id:"add-comment",name:L.t("comment.command"),blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:ec}]}return[]}hideToolbar(t){const e=t.getCustom("toolbar-handler");e.disableTextToolbar(),e.hide(),setTimeout(()=>{e.enableTextToolbar()},300)}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=az(t,e,this.provider);return i["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class i8{constructor(t,e){m(this,"commentList",null);m(this,"mobileCommentList",null);m(this,"miniCommentList");m(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});m(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});m(this,"handleCommentListClose",()=>{this.showComment("mini")});m(this,"handleOnSelectComment",()=>{this.showComment("web")});m(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new uz(e,this)),t.blockHooks.push(new EU(this.provider,this)),this.isMobile?(this.mobileCommentList=new oz(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new JU(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new cz(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new xU)}get commentProvider(){return this.provider}get isMobile(){return Ze.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 dot="",dz={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\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"}},hz={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotations or @ others",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"}},fz={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\u8A8D",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\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"}};L.mergeLang({"zh-CN":dz,"en-US":hz,"ja-JP":fz});class s8{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;rt(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(W(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class mz{constructor(t){m(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});m(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});m(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Ff(t,e,L.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function gz(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&nt(n,t)){const s=hg(i,`comment-${e.toLocaleLowerCase()}`,e);ua.default(i,s)||n.setBlockText(t,s)}}const pz=S("editor-comment");function Cz(n){const t=n.getCustom("editor-comments");if(g(pz,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Ri(s);if(l.length>=2){const{containerId:a}=l.at(-1),d=et(Vr(n,a));if(d&&Dt(d)==="code"){v2(n,d,t.commentProvider);return}}v2(n,s,t.commentProvider);return}const e=Oo(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=b2(n,o),i=Jf({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?r8(n,l,i):Py(n,l.block,i)});const s=Zr();t.commentProvider.localCreateComment(i,s)})}const T2=S("text-styles");function Az(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function bz(n,t,e,o,r){g(T2,e.isSimple(),"invalid range");const{start:i,end:s}=e;g(T2,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(T2,o.startsWith("style-"),"invalid style");let a=n.getBlockText(t);return o==="style-sub"?a=Wl(i.offset,s.offset-i.offset,a,"style-super",r,{ignoreValue:!0}):o==="style-super"&&(a=Wl(i.offset,s.offset-i.offset,a,"style-sub",r,{ignoreValue:!0})),r===!1||r===void 0||r===null?a=Wl(i.offset,s.offset-i.offset,a,o,void 0,{ignoreValue:!0}):a=La(i.offset,s.offset-i.offset,a,o,r),n.setBlockText(t,a),a}const vz=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
503
|
+
</svg>`,uot="",Kf="reply-editor-editing",{t:x2}=L;class WU{constructor(t,e,o,r){m(this,"root");m(this,"components");m(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});m(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();pg(o)?e.disabled=!0:e.disabled=!1});m(this,"getReplyEditor",()=>this.components.replyEditor);m(this,"showReplyEditor",()=>{xt(this.root,Kf)||(W(this.root,Kf),this.components.replyEditor.edit())});m(this,"hideReplyEditor",()=>{!xt(this.root,Kf)||rt(this.root,Kf)});m(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=Jf({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});m(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});m(this,"hide",()=>{xt(this.root,"hidden")||W(this.root,"hidden")});m(this,"show",()=>{rt(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=k("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=Zs(this.root,Jt.QuickReply,x2("comment.placeholder"));oi(e,Jt.QuickReply),e.classList.add("quick-reply-button");const o=k("div",["quick-reply-editor"],this.root),r=Zr(),i=new E2(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new PU(this.groupItem)),o.append(i.root);const s=k("div",["reply-editor-actions"],o),l=fo(Jt.QuickReplyCancel,x2("common.cancel"));oi(l,Jt.QuickReplyCancel);const a=fo(Jt.QuickReplyOk,x2("comment.send"),void 0,["primary","disabled"]);return oi(a,Jt.QuickReplyOk),s.append(l,a),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:a}}}const ri=S("comment-group-item");class qU extends ve.TypedEmitter{constructor(e,o,r,i){super();m(this,"root");m(this,"header");m(this,"mainItem");m(this,"childrenList");m(this,"resizeObserver");m(this,"quickReply");m(this,"createRoot",()=>k("div",["comment-group-item-root"],null));m(this,"createChildrenList",()=>{const e=k("div",["comment-children-list-container"],this.root);return new UU({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});m(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));g(ri,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{rt(r,Ny)});const o=e[e.length-1];W(o,Ny)});m(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');g(ri,e,"switchUpButton not exist"),g(ri,o,"switchDownButton not exist"),rt(o,"disabled"),rt(e,"disabled"),this.root.previousElementSibling===null&&W(e,"disabled"),this.root.nextElementSibling===null&&W(o,"disabled")});m(this,"handleReadonlyChanged",e=>{e.readonly?W(this.root,"readonly"):rt(this.root,"readonly")});m(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,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 Hy(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new WU(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=k("div",["comment-item-head"],this.root),r=k("span",["item-head-quote"],o);r.innerText=e.abstract;const i=k("span",["item-head-switch"],o),s=Zs(i,Jt.SwitchUp,"up",zU),l=Zs(i,Jt.SwitchDown,"down",VU);return oi(s,Jt.SwitchUp),oi(l,Jt.SwitchDown),o}createItem(){const e=k("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new Yy({mainEditor:o,commentsProvider:r,comment:i,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(o=>o.comment.id===e):null}handleCreateComment(e){return g(ri,Js(e),"invalid comment, not a child comment"),g(ri,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){g(ri,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){ri.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(ri,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(ri,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 GU=S("arrange=items"),Ky=20;function Xy(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function t8(n,t){return Number.parseInt(t.root.style.top,10)}function e8(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,a=Xy(n,l.groupId);if(s.root.setAttribute("data-target-top",a.toString()),i===r){if(o!==void 0){const p=t[0];p.root.style.top=`${o}px`}else s.root.style.top=`${a}px`;continue}const d=t[i-1],h=t8(n,d)+d.root.getBoundingClientRect().height;h>a?s.root.style.top=`${h+Ky}px`:s.root.style.top=`${a}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,a=Xy(n,l.groupId);s.root.setAttribute("data-target-top",a.toString());const d=s.root.getBoundingClientRect(),h=a+d.height,p=t[i+1];g(GU,p,"no next item");const C=t8(n,p);C<h?s.root.style.top=`${C-d.height-Ky}px`:s.root.style.top=`${a}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const Xf=S("comment-group-item-handler");class ZU{constructor(t,e){m(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});m(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});m(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});m(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});m(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});m(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);g(Xf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),a={type:"mention",id:K(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,a)});m(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});m(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);g(Xf,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),a=l.getDoc();this.commentsProvider.localUpdateComment(i,a),l.readonly(),r.show()});m(this,"handleCommentItemCancel",(t,e)=>{var a,d;const o=t.findCommentItem(e);g(Xf,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);let i=!1;if((a=r.blocks)!=null&&a.length||(i=!0),((d=r.blocks)==null?void 0:d.length)===1){const h=r.blocks[0];i=!!h.text&&rn(h.text)===0}if(i){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:s}=t,l=o.getCommentEditor();l.setDoc(o.doc),l.readonly(),s.show()});m(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});m(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});m(this,"execute",(t,e,o,r)=>{const i=DU(t);if(!i||LU(i))return;const s=SU(i);switch(s){case Jt.SwitchUp:this.handleSwitchUp(r);break;case Jt.SwitchDown:this.handleSwitchDown(r);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,o);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,o);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,o);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;Xf.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const t1=S("comment-group-list");class QU extends ju{constructor(e,o,r){super(e,o,r,Xi(e,o),{});m(this,"groupItemHandlers");m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=TU(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[i],r,i)}});m(this,"handleSelectionChanged",()=>{setTimeout(()=>{var o;const e=Wy(this.editor);if(e.length>0){if(((o=this.activeItem)==null?void 0:o.comment.id)&&e.includes(this.activeItem.comment.id))return;const r=e[0],i=this.items.findIndex(s=>s.comment.groupId===r);this.setActiveItem(i),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});m(this,"handleEditorResize",()=>{this.updateItemsLayout()});m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"handleItemResize",()=>{this.updateItemsLayout()});m(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&e8(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});m(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;g(t1,e,"invalid activeItem"),e.updateSwitchButton()});m(this,"updateComments",Me.default(()=>{const e=Xi(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;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),o=!0)}o&&(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(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new ZU(this,o)}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(){e8(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new qU(this.editor,this.commentsProvider,e,this);return o==="insert"&&(W(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{rt(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=Xi(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e,o){const r=super.insertItem(e);return r?(o!=null&&o.active&&this.setActiveItem(this.items.indexOf(r)),this.updateItemsLayout(),r.addListener("resize",this.handleItemResize),r):null}setActiveItem(e,o){if(g(t1,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const r=this.container.querySelector(".comment-group-item-root.active");if(r&&rt(r,"active"),e!==-1){const i=this.items[e];W(i.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,o)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(Js(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);g(t1,!r,"comment group item has already exists");const i={children:[],...e};g(t1,i.children,"not a comment group");const s=this.insertItem(i,{active:o});!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?(this.deleteItem(r.comment.id),this.updateItemsLayout()):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&(this.deleteItem(r.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const YU="comment-mini";S("comment-list");class JU extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"groupsContainer");m(this,"list");m(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});m(this,"updateCommentCount",()=>{var o,r;const e=OU(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});m(this,"handleActiveItemChanged",(e,o)=>{var i,s;const r=this.list.activeItem;Gy(this.editor,(s=(i=r==null?void 0:r.comment)==null?void 0:i.groupId)!=null?s:"",o)});m(this,"handleItemLayoutUpdated",()=>{var o,r;const e=xt(this.root,YU);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-web-comment-root"],null),this.groupsContainer=k("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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new QU(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(rt(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){W(this.root,"hidden")}}class KU extends ju{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new Jy(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const e1=S("mobile-comment-group-item"),XU=20;class tz extends ve.TypedEmitter{constructor(e,o,r){super();m(this,"root");m(this,"childrenList");m(this,"mainItem");m(this,"scroller");m(this,"createRoot",()=>k("div",["mobile-group-item-root"],null));m(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new Jy(o,r,i);return e.append(s.root),s});m(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=k("div",["mobile-comment-children-list-container"],e);return new KU({editor:o,commentsProvider:r,comments:i.children,parent:s})});m(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=XU}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,$y)}});m(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=k("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=k("div",["mobile-group-item"],this.root),s=k("div",["mobile-group-item-space"],null),l=k("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const a=k("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(a),this.childrenList=this.createChildrenList(a),i.append(s,l,a),this.scroller=new J3.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return Hy(this.root,".mobile-group-item")}handleUpdateChildComment(e){g(e1,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){e1.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(e1,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(e1,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 I2=S("mobile-group-list");class ez extends ju{constructor(e,o,r,i){super(e,o,r,Xi(e,o),{});m(this,"scroller");m(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});m(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,$y),!0):!1});m(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});m(this,"handleReachBottom",()=>{this.emit("onReachBottom")});m(this,"handleReachTop",()=>{this.emit("onReachTop")});m(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);g(I2,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),Gy(this.editor,r.comment.groupId)});m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"updateComments",Me.default(()=>{const e=Xi(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new J3.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new tz(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=Xi(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(Js(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);g(I2,!r,"comment group item has already exists");const i={children:[],...e};g(I2,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(Js(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const nz=S("mobile-comment-list"),{t:n8}=L;class oz extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"list");m(this,"mask");m(this,"pullInfoContainer");m(this,"handleRootClick",e=>{const o=e.target;g(nz,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});m(this,"hidePullInfo",Me.default(()=>{rt(this.pullInfoContainer,"active")},1e3*3));m(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});m(this,"handleReachTop",()=>{this.showPullInfo("top")});m(this,"show",e=>{var o;rt(this.root,"hidden"),W(document.documentElement,"disabled-scroll"),(o=this.commentOptions)==null||o.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});m(this,"hide",()=>{W(this.root,"hidden"),rt(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mobile-comments-root"],null),this.mask=k("div",["mobile-comment-mask"],this.root);const r=k("div",["mobile-comment-groups-container"],this.root),i=k("div",["mobile-comment-groups-scroll-container"],r);this.list=new ez(this.editor,this.commentsProvider,i,r),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,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=k("div",["mobile-comment-pull-info-container"],this.root);return k("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=n8(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,W(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function o8(n,t){const e=Xi(n,t),o=new Map;for(const r of e){const i=jy(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);k2(r).forEach(a=>{s==null||s.commentIds.add(a.id)})}else{const s=k2(r),l=new Set(s.map(a=>a.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const rz=S("mini-group-item");class iz{constructor(t,e){m(this,"root");m(this,"blockId");m(this,"comment");m(this,"miniCommentItem");m(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=k("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new jU(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return jy(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);g(rz,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),r=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-o.top+r;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class sz extends ju{constructor(e,o,r){super(e,o,r,o8(e,o),{});m(this,"fixListOps",Me.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));m(this,"handleDocChanged",Me.default(()=>{this.updateMiniCommentsGroup()},100));m(this,"updateMiniCommentsGroup",()=>{const e=o8(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new iz(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const lz=S("mini-comments-list");class cz extends ve.TypedEmitter{constructor(e,o){super();m(this,"list");m(this,"root");m(this,"createList",()=>{const e=k("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new sz(this.editor,this.commentsProvider,e)});m(this,"handleListContainerClick",(e,o)=>{const r=o.target;g(lz,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){rt(this.root,"hidden")}hide(){W(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function r8(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=ke(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;Z6(n,o,r,i,s)}function az(n,t,e){const o=Oo(n).map(s=>s.block),r=b2(n,o),i=Jf({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{Oo(n,{simpleBlockOnly:!0}).forEach(a=>{!nt(n,a.block)||r8(n,a,i)});const l=Zr();e.localCreateComment(i,l)}),i}class uz{constructor(t,e){m(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(nt(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=it(e),s=Dt(e),l=So(t,e);return[{id:"add-comment",name:L.t("comment.command"),blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:ec}]}return[]}hideToolbar(t){const e=t.getCustom("toolbar-handler");e.disableTextToolbar(),e.hide(),setTimeout(()=>{e.enableTextToolbar()},300)}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=az(t,e,this.provider);return i["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class i8{constructor(t,e){m(this,"commentList",null);m(this,"mobileCommentList",null);m(this,"miniCommentList");m(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});m(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});m(this,"handleCommentListClose",()=>{this.showComment("mini")});m(this,"handleOnSelectComment",()=>{this.showComment("web")});m(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new uz(e,this)),t.blockHooks.push(new EU(this.provider,this)),this.isMobile?(this.mobileCommentList=new oz(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new JU(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new cz(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new xU)}get commentProvider(){return this.provider}get isMobile(){return Ze.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 dot="",dz={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\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"}},hz={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotations or @ others",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"}},fz={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\u8A8D",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\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"}};L.mergeLang({"zh-CN":dz,"en-US":hz,"ja-JP":fz});class s8{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;rt(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(W(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class mz{constructor(t){m(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});m(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});m(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Ff(t,e,L.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function gz(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&nt(n,t)){const s=hg(i,`comment-${e.toLocaleLowerCase()}`,e);ua.default(i,s)||n.setBlockText(t,s)}}const pz=S("editor-comment");function Cz(n){const t=n.getCustom("editor-comments");if(g(pz,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Ri(s);if(l.length>=2){const{containerId:a}=l[l.length-1],d=et(Vr(n,a));if(d&&Dt(d)==="code"){v2(n,d,t.commentProvider);return}}v2(n,s,t.commentProvider);return}const e=Oo(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=b2(n,o),i=Jf({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{nt(n,l.block)?r8(n,l,i):Py(n,l.block,i)});const s=Zr();t.commentProvider.localCreateComment(i,s)})}const T2=S("text-styles");function Az(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function bz(n,t,e,o,r){g(T2,e.isSimple(),"invalid range");const{start:i,end:s}=e;g(T2,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(T2,o.startsWith("style-"),"invalid style");let a=n.getBlockText(t);return o==="style-sub"?a=Wl(i.offset,s.offset-i.offset,a,"style-super",r,{ignoreValue:!0}):o==="style-super"&&(a=Wl(i.offset,s.offset-i.offset,a,"style-sub",r,{ignoreValue:!0})),r===!1||r===void 0||r===null?a=Wl(i.offset,s.offset-i.offset,a,o,void 0,{ignoreValue:!0}):a=La(i.offset,s.offset-i.offset,a,o,r),n.setBlockText(t,a),a}const vz=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
504
504
|
<line x1="3.5" y1="0.5" x2="3.5" y2="15.5" stroke="currentColor"/>
|
|
505
505
|
<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"/>
|
|
506
506
|
<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"/>
|