@univerjs/sheets-thread-comment 0.6.1 → 0.6.2

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/lib/cjs/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";var T=Object.defineProperty;var E=(I,e,o)=>e in I?T(I,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):I[e]=o;var R=(I,e,o)=>E(I,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),b=require("@univerjs/sheets-thread-comment"),f=require("@univerjs/sheets/facade"),a=require("@univerjs/thread-comment"),y=require("@univerjs/engine-formula"),x=require("rxjs"),S=require("@univerjs/core/facade");var A=Object.getOwnPropertyDescriptor,B=(I,e,o,t)=>{for(var n=t>1?void 0:t?A(e,o):e,r=I.length-1,s;r>=0;r--)(s=I[r])&&(n=s(n)||n);return n},p=(I,e)=>(o,t)=>e(o,t,I);class U{constructor(e){R(this,"_comment",{id:m.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:m.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new U(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return m.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return k.create(m.Tools.deepClone(this._comment))}}class k extends U{static create(e){return new k(e)}setContent(e){return e instanceof m.RichTextValue?this._comment.text=e.getData().body:this._comment.text=e,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=a.getDT(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}}exports.FThreadComment=class{constructor(e,o,t,n,r,s,c){this._thread=e,this._parent=o,this._injector=t,this._commandService=n,this._univerInstanceService=r,this._threadCommentModel=s,this._userManagerService=c}_getRef(){var t;const e=((t=this._parent)==null?void 0:t.ref)||this._thread.ref;return y.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...o}=this._thread;return o}getReplies(){var t;const e=this._getRef(),o=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(t=o==null?void 0:o.children)==null?void 0:t.map(n=>this._injector.createInstance(exports.FThreadComment,n))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,m.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const o=e.getSheetBySheetId(this._thread.subUnitId);if(!o)return null;const t=this._getRef();return this._injector.createInstance(f.FRange,e,o,t)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return m.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?a.DeleteCommentTreeCommand.id:a.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(e){const o=e instanceof m.RichTextValue?e.getData().body:e,t=a.getDT();return await this._commandService.executeCommand(a.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:o,updated:!0,updateT:t}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(a.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}async replyAsync(e){var t;const o=e.build();return this._commandService.executeCommand(a.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:m.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(t=this._parent)==null?void 0:t.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:o.text,attachments:o.attachments,dT:o.dT||a.getDT(),personId:o.personId||this._userManagerService.getCurrentUser().userID}})}};exports.FThreadComment=B([p(2,m.Inject(m.Injector)),p(3,m.ICommandService),p(4,m.IUniverInstanceService),p(5,m.Inject(b.SheetsThreadCommentModel)),p(6,m.Inject(m.UserManagerService))],exports.FThreadComment);class D extends f.FRange{getComment(){const o=this._injector.get(b.SheetsThreadCommentModel),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=o.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;const s=o.getComment(t,n,r);return s?this._injector.createInstance(exports.FThreadComment,s):null}getComments(){const o=this._injector.get(b.SheetsThreadCommentModel),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return m.Range.foreach(this._range,(s,c)=>{const u=o.getByLocation(t,n,s,c);if(u){const i=o.getComment(t,n,u);i&&r.push(this._injector.createInstance(exports.FThreadComment,i))}}),r}addComment(e){var h;const o=this._injector,t=(h=this.getComment())==null?void 0:h.getCommentData(),n=o.get(m.ICommandService),r=o.get(m.UserManagerService),s=this._workbook.getUnitId(),c=this._worksheet.getSheetId(),u=`${m.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,i=r.getCurrentUser(),d=e instanceof k?e.build():{text:e};return n.executeCommand(a.AddCommentCommand.id,{unitId:s,subUnitId:c,comment:{text:d.text,dT:d.dT||a.getDT(),attachments:[],id:d.id||m.generateRandomId(),ref:u,personId:d.personId||i.userID,parentId:t==null?void 0:t.id,unitId:s,subUnitId:c,threadId:(t==null?void 0:t.threadId)||m.generateRandomId()}})}clearComment(){var s;const e=this._injector,o=(s=this.getComment())==null?void 0:s.getCommentData(),t=e.get(m.ICommandService),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return o?t.executeCommand(a.DeleteCommentTreeCommand.id,{unitId:n,subUnitId:r,threadId:o.threadId,commentId:o.id}):Promise.resolve(!0)}clearComments(){const o=this.getComments().map(t=>t.deleteAsync());return Promise.all(o).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}f.FRange.extend(D);class j extends f.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(a.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(exports.FThreadComment,e.root))}clearComments(){const o=this.getComments().map(t=>t.deleteAsync());return Promise.all(o).then(()=>!0)}onThreadCommentChange(e){return m.toDisposable(this._threadCommentModel.commentUpdate$.pipe(x.filter(o=>o.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((o,t)=>{const n=o.params;if(o.id===a.AddCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(e(n,t)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((o,t)=>{const n=o.params;if(o.id===a.UpdateCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(e(n,t)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((o,t)=>{const n=o.params;if(o.id===a.DeleteCommentCommand.id||o.id===a.DeleteCommentTreeCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(e(n,t)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}f.FWorkbook.extend(j);class F extends f.FWorksheet{getComments(){return this._injector.get(b.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>this._injector.createInstance(exports.FThreadComment,t))}clearComments(){const o=this.getComments().map(t=>t.deleteAsync());return Promise.all(o).then(()=>!0)}onCommented(e){return this._injector.get(m.ICommandService).onCommandExecuted(t=>{if(t.id===a.AddCommentCommand.id){const n=t.params;e(n)}})}getCommentById(e){const t=this._injector.get(b.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(exports.FThreadComment,t)}}f.FWorksheet.extend(F);const v={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class M extends S.FEventName{get CommentAdded(){return v.CommentAdded}get BeforeCommentAdd(){return v.BeforeCommentAdd}get CommentUpdated(){return v.CommentUpdated}get BeforeCommentUpdate(){return v.BeforeCommentUpdate}get CommentDeleted(){return v.CommentDeleted}get BeforeCommentDeleted(){return v.BeforeCommentDeleted}get CommentResolved(){return v.CommentResolved}get BeforeCommentResolve(){return v.BeforeCommentResolve}}S.FEventName.extend(M);class P extends S.FUniver{_initialize(e){const o=e.get(m.ICommandService);this.registerEventHandler(this.Event.CommentAdded,()=>o.onCommandExecuted(t=>{var d,h,C,g,l;if(t.id!==a.AddCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{comment:u}=c,i=s.getRange(u.ref).getComment();i&&this.fireEvent(this.Event.CommentAdded,{workbook:r,worksheet:s,row:(C=(h=i.getRange())==null?void 0:h.getRow())!=null?C:0,col:(l=(g=i.getRange())==null?void 0:g.getColumn())!=null?l:0,comment:i})})),this.registerEventHandler(this.Event.CommentUpdated,()=>o.onCommandExecuted(t=>{var d,h,C,g,l;if(t.id!==a.UpdateCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u}=c.payload,i=s.getCommentById(u);i&&this.fireEvent(this.Event.CommentUpdated,{workbook:r,worksheet:s,row:(C=(h=i.getRange())==null?void 0:h.getRow())!=null?C:0,col:(l=(g=i.getRange())==null?void 0:g.getColumn())!=null?l:0,comment:i})})),this.registerEventHandler(this.Event.CommentDeleted,()=>o.onCommandExecuted(t=>{var i;if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u}=c;this.fireEvent(this.Event.CommentDeleted,{workbook:r,worksheet:s,commentId:u})})),this.registerEventHandler(this.Event.CommentResolved,()=>o.onCommandExecuted(t=>{var h,C,g;if(t.id!==a.ResolveCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u,resolved:i}=c,d=s.getComments().find(l=>l.getCommentData().id===u);d&&this.fireEvent(this.Event.CommentResolved,{workbook:r,worksheet:s,row:(C=d.getRange().getRow())!=null?C:0,col:(g=d.getRange().getColumn())!=null?g:0,comment:d,resolved:i})})),this.registerEventHandler(this.Event.BeforeCommentAdd,()=>o.beforeCommandExecuted(t=>{var h,C,g;if(t.id!==a.AddCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{comment:u}=c,i=s.getActiveRange();if(!i)return;const d={workbook:r,worksheet:s,row:(C=i.getRow())!=null?C:0,col:(g=i.getColumn())!=null?g:0,comment:U.create(u)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new m.CanceledError})),this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>o.beforeCommandExecuted(t=>{var h,C,g,l,_;if(t.id!==a.UpdateCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u,text:i}=c.payload,d=s.getCommentById(u);if(d){const w={workbook:r,worksheet:s,row:(g=(C=d.getRange())==null?void 0:C.getRow())!=null?g:0,col:(_=(l=d.getRange())==null?void 0:l.getColumn())!=null?_:0,comment:d,newContent:m.RichTextValue.createByBody(i)};if(this.fireEvent(this.Event.BeforeCommentUpdate,w),w.cancel)throw new m.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentDeleted,()=>o.beforeCommandExecuted(t=>{var d,h,C,g,l;if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u}=c,i=s.getCommentById(u);if(i){const _={workbook:r,worksheet:s,row:(C=(h=i.getRange())==null?void 0:h.getRow())!=null?C:0,col:(l=(g=i.getRange())==null?void 0:g.getColumn())!=null?l:0,comment:i};if(this.fireEvent(this.Event.BeforeCommentDeleted,_),_.cancel)throw new m.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentResolve,()=>o.beforeCommandExecuted(t=>{var h,C,g;if(t.id!==a.ResolveCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u,resolved:i}=c,d=s.getComments().find(l=>l.getCommentData().id===u);if(d){const l={workbook:r,worksheet:s,row:(C=d.getRange().getRow())!=null?C:0,col:(g=d.getRange().getColumn())!=null?g:0,comment:d,resolved:i};if(this.fireEvent(this.Event.BeforeCommentResolve,l),l.cancel)throw new m.CanceledError}}))}newTheadComment(e){return new k(e)}}S.FUniver.extend(P);
1
+ "use strict";var T=Object.defineProperty;var E=(I,e,o)=>e in I?T(I,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):I[e]=o;var R=(I,e,o)=>E(I,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),b=require("@univerjs/sheets-thread-comment"),f=require("@univerjs/sheets/facade"),a=require("@univerjs/thread-comment"),x=require("@univerjs/engine-formula"),y=require("rxjs"),S=require("@univerjs/core/facade");var A=Object.getOwnPropertyDescriptor,B=(I,e,o,t)=>{for(var n=t>1?void 0:t?A(e,o):e,r=I.length-1,s;r>=0;r--)(s=I[r])&&(n=s(n)||n);return n},p=(I,e)=>(o,t)=>e(o,t,I);class U{constructor(e){R(this,"_comment",{id:m.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:m.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new U(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return m.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return k.create(m.Tools.deepClone(this._comment))}}class k extends U{static create(e){return new k(e)}setContent(e){return e instanceof m.RichTextValue?this._comment.text=e.getData().body:this._comment.text=e,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=a.getDT(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}}exports.FThreadComment=class{constructor(e,o,t,n,r,s,c){this._thread=e,this._parent=o,this._injector=t,this._commandService=n,this._univerInstanceService=r,this._threadCommentModel=s,this._userManagerService=c}_getRef(){var t;const e=((t=this._parent)==null?void 0:t.ref)||this._thread.ref;return x.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...o}=this._thread;return o}getReplies(){var t;const e=this._getRef(),o=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(t=o==null?void 0:o.children)==null?void 0:t.map(n=>this._injector.createInstance(exports.FThreadComment,n))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,m.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const o=e.getSheetBySheetId(this._thread.subUnitId);if(!o)return null;const t=this._getRef();return this._injector.createInstance(f.FRange,e,o,t)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return m.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?a.DeleteCommentTreeCommand.id:a.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(e){const o=e instanceof m.RichTextValue?e.getData().body:e,t=a.getDT();return await this._commandService.executeCommand(a.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:o,updated:!0,updateT:t}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(a.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}replyAsync(e){var t;const o=e.build();return this._commandService.executeCommand(a.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:m.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((t=this._parent)==null?void 0:t.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:o.text,attachments:o.attachments,dT:o.dT||a.getDT(),personId:o.personId||this._userManagerService.getCurrentUser().userID}})}};exports.FThreadComment=B([p(2,m.Inject(m.Injector)),p(3,m.ICommandService),p(4,m.IUniverInstanceService),p(5,m.Inject(b.SheetsThreadCommentModel)),p(6,m.Inject(m.UserManagerService))],exports.FThreadComment);class D extends f.FRange{getComment(){const o=this._injector.get(b.SheetsThreadCommentModel),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=o.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;const s=o.getComment(t,n,r);return s?this._injector.createInstance(exports.FThreadComment,s):null}getComments(){const o=this._injector.get(b.SheetsThreadCommentModel),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return m.Range.foreach(this._range,(s,c)=>{const u=o.getByLocation(t,n,s,c);if(u){const i=o.getComment(t,n,u);i&&r.push(this._injector.createInstance(exports.FThreadComment,i))}}),r}addComment(e){var h;const o=this._injector,t=(h=this.getComment())==null?void 0:h.getCommentData(),n=o.get(m.ICommandService),r=o.get(m.UserManagerService),s=this._workbook.getUnitId(),c=this._worksheet.getSheetId(),u=`${m.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,i=r.getCurrentUser(),d=e instanceof k?e.build():{text:e};return n.executeCommand(a.AddCommentCommand.id,{unitId:s,subUnitId:c,comment:{text:d.text,dT:d.dT||a.getDT(),attachments:[],id:d.id||m.generateRandomId(),ref:u,personId:d.personId||i.userID,parentId:t==null?void 0:t.id,unitId:s,subUnitId:c,threadId:(t==null?void 0:t.threadId)||m.generateRandomId()}})}clearComment(){var s;const e=this._injector,o=(s=this.getComment())==null?void 0:s.getCommentData(),t=e.get(m.ICommandService),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return o?t.executeCommand(a.DeleteCommentTreeCommand.id,{unitId:n,subUnitId:r,threadId:o.threadId,commentId:o.id}):Promise.resolve(!0)}clearComments(){const o=this.getComments().map(t=>t.deleteAsync());return Promise.all(o).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}f.FRange.extend(D);class j extends f.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(a.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(exports.FThreadComment,e.root))}clearComments(){const o=this.getComments().map(t=>t.deleteAsync());return Promise.all(o).then(()=>!0)}onThreadCommentChange(e){return m.toDisposable(this._threadCommentModel.commentUpdate$.pipe(y.filter(o=>o.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((o,t)=>{const n=o.params;if(o.id===a.AddCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(e(n,t)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((o,t)=>{const n=o.params;if(o.id===a.UpdateCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(e(n,t)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return m.toDisposable(this._commandService.beforeCommandExecuted((o,t)=>{const n=o.params;if(o.id===a.DeleteCommentCommand.id||o.id===a.DeleteCommentTreeCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(e(n,t)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}f.FWorkbook.extend(j);class F extends f.FWorksheet{getComments(){return this._injector.get(b.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>this._injector.createInstance(exports.FThreadComment,t))}clearComments(){const o=this.getComments().map(t=>t.deleteAsync());return Promise.all(o).then(()=>!0)}onCommented(e){return this._injector.get(m.ICommandService).onCommandExecuted(t=>{if(t.id===a.AddCommentCommand.id){const n=t.params;e(n)}})}getCommentById(e){const t=this._injector.get(b.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(exports.FThreadComment,t)}}f.FWorksheet.extend(F);const v={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDelete:"BeforeCommentDelete",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class M extends S.FEventName{get CommentAdded(){return v.CommentAdded}get BeforeCommentAdd(){return v.BeforeCommentAdd}get CommentUpdated(){return v.CommentUpdated}get BeforeCommentUpdate(){return v.BeforeCommentUpdate}get CommentDeleted(){return v.CommentDeleted}get BeforeCommentDelete(){return v.BeforeCommentDelete}get CommentResolved(){return v.CommentResolved}get BeforeCommentResolve(){return v.BeforeCommentResolve}}S.FEventName.extend(M);class P extends S.FUniver{_initialize(e){const o=e.get(m.ICommandService);this.registerEventHandler(this.Event.CommentAdded,()=>o.onCommandExecuted(t=>{var d,h,C,g,l;if(t.id!==a.AddCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{comment:u}=c,i=s.getRange(u.ref).getComment();i&&this.fireEvent(this.Event.CommentAdded,{workbook:r,worksheet:s,row:(C=(h=i.getRange())==null?void 0:h.getRow())!=null?C:0,col:(l=(g=i.getRange())==null?void 0:g.getColumn())!=null?l:0,comment:i})})),this.registerEventHandler(this.Event.CommentUpdated,()=>o.onCommandExecuted(t=>{var d,h,C,g,l;if(t.id!==a.UpdateCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u}=c.payload,i=s.getCommentById(u);i&&this.fireEvent(this.Event.CommentUpdated,{workbook:r,worksheet:s,row:(C=(h=i.getRange())==null?void 0:h.getRow())!=null?C:0,col:(l=(g=i.getRange())==null?void 0:g.getColumn())!=null?l:0,comment:i})})),this.registerEventHandler(this.Event.CommentDeleted,()=>o.onCommandExecuted(t=>{var i;if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(i=this.getActiveWorkbook)==null?void 0:i.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u}=c;this.fireEvent(this.Event.CommentDeleted,{workbook:r,worksheet:s,commentId:u})})),this.registerEventHandler(this.Event.CommentResolved,()=>o.onCommandExecuted(t=>{var h,C,g;if(t.id!==a.ResolveCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u,resolved:i}=c,d=s.getComments().find(l=>l.getCommentData().id===u);d&&this.fireEvent(this.Event.CommentResolved,{workbook:r,worksheet:s,row:(C=d.getRange().getRow())!=null?C:0,col:(g=d.getRange().getColumn())!=null?g:0,comment:d,resolved:i})})),this.registerEventHandler(this.Event.BeforeCommentAdd,()=>o.beforeCommandExecuted(t=>{var h,C,g;if(t.id!==a.AddCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{comment:u}=c,i=s.getActiveRange();if(!i)return;const d={workbook:r,worksheet:s,row:(C=i.getRow())!=null?C:0,col:(g=i.getColumn())!=null?g:0,comment:U.create(u)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new m.CanceledError})),this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>o.beforeCommandExecuted(t=>{var h,C,g,l,_;if(t.id!==a.UpdateCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u,text:i}=c.payload,d=s.getCommentById(u);if(d){const w={workbook:r,worksheet:s,row:(g=(C=d.getRange())==null?void 0:C.getRow())!=null?g:0,col:(_=(l=d.getRange())==null?void 0:l.getColumn())!=null?_:0,comment:d,newContent:m.RichTextValue.createByBody(i)};if(this.fireEvent(this.Event.BeforeCommentUpdate,w),w.cancel)throw new m.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentDelete,()=>o.beforeCommandExecuted(t=>{var d,h,C,g,l;if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u}=c,i=s.getCommentById(u);if(i){const _={workbook:r,worksheet:s,row:(C=(h=i.getRange())==null?void 0:h.getRow())!=null?C:0,col:(l=(g=i.getRange())==null?void 0:g.getColumn())!=null?l:0,comment:i};if(this.fireEvent(this.Event.BeforeCommentDelete,_),_.cancel)throw new m.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentResolve,()=>o.beforeCommandExecuted(t=>{var h,C,g;if(t.id!==a.ResolveCommentCommand.id)return;const n=t.params;if(!n)return;const r=n.unitId?this.getUniverSheet(n.unitId):(h=this.getActiveWorkbook)==null?void 0:h.call(this);if(!r)return;const s=r.getSheetBySheetId(n.subUnitId||n.sheetId)||r.getActiveSheet();if(!s)return;const c=t.params,{commentId:u,resolved:i}=c,d=s.getComments().find(l=>l.getCommentData().id===u);if(d){const l={workbook:r,worksheet:s,row:(C=d.getRange().getRow())!=null?C:0,col:(g=d.getRange().getColumn())!=null?g:0,comment:d,resolved:i};if(this.fireEvent(this.Event.BeforeCommentResolve,l),l.cancel)throw new m.CanceledError}}))}newTheadComment(e){return new k(e)}}S.FUniver.extend(P);
package/lib/es/facade.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var L = Object.defineProperty;
2
2
  var N = (i, e, r) => e in i ? L(i, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : i[e] = r;
3
3
  var M = (i, e, r) => N(i, typeof e != "symbol" ? e + "" : e, r);
4
- import { Inject as T, Injector as V, ICommandService as _, IUniverInstanceService as q, UserManagerService as W, UniverInstanceType as G, RichTextValue as k, generateRandomId as R, RichTextBuilder as J, Tools as F, Range as K, toDisposable as S, CanceledError as E } from "@univerjs/core";
4
+ import { Inject as T, Injector as V, ICommandService as p, IUniverInstanceService as q, UserManagerService as W, UniverInstanceType as G, RichTextValue as k, generateRandomId as R, RichTextBuilder as J, Tools as F, Range as K, toDisposable as S, CanceledError as E } from "@univerjs/core";
5
5
  import { SheetsThreadCommentModel as b } from "@univerjs/sheets-thread-comment";
6
6
  import { FRange as j, FWorkbook as H, FWorksheet as O } from "@univerjs/sheets/facade";
7
7
  import { DeleteCommentTreeCommand as w, DeleteCommentCommand as y, getDT as B, UpdateCommentCommand as x, ResolveCommentCommand as D, AddCommentCommand as f, ThreadCommentModel as Q } from "@univerjs/thread-comment";
@@ -12,7 +12,7 @@ var Z = Object.getOwnPropertyDescriptor, ee = (i, e, r, t) => {
12
12
  for (var n = t > 1 ? void 0 : t ? Z(e, r) : e, o = i.length - 1, s; o >= 0; o--)
13
13
  (s = i[o]) && (n = s(n) || n);
14
14
  return n;
15
- }, p = (i, e) => (r, t) => e(r, t, i);
15
+ }, _ = (i, e) => (r, t) => e(r, t, i);
16
16
  class A {
17
17
  constructor(e) {
18
18
  M(this, "_comment", {
@@ -34,7 +34,8 @@ class A {
34
34
  * @returns {FTheadCommentItem} A new instance of FTheadCommentItem
35
35
  * @example
36
36
  * ```ts
37
- * const comment = univerAPI.newTheadComment();
37
+ * const commentBuilder = univerAPI.newTheadComment();
38
+ * console.log(commentBuilder);
38
39
  * ```
39
40
  */
40
41
  static create(e) {
@@ -45,10 +46,8 @@ class A {
45
46
  * @returns {string} The person id of the comment
46
47
  * @example
47
48
  * ```ts
48
- * const comment = univerAPI.getActiveWorkbook()
49
- * .getSheetById(sheetId)
50
- * .getCommentById(commentId);
51
- * const personId = comment.personId;
49
+ * const commentBuilder = univerAPI.newTheadComment();
50
+ * console.log(commentBuilder.personId);
52
51
  * ```
53
52
  */
54
53
  get personId() {
@@ -59,10 +58,8 @@ class A {
59
58
  * @returns {string} The date time of the comment
60
59
  * @example
61
60
  * ```ts
62
- * const comment = univerAPI.getActiveWorkbook()
63
- * .getSheetById(sheetId)
64
- * .getCommentById(commentId);
65
- * const dateTime = comment.dateTime;
61
+ * const commentBuilder = univerAPI.newTheadComment();
62
+ * console.log(commentBuilder.dateTime);
66
63
  * ```
67
64
  */
68
65
  get dateTime() {
@@ -73,10 +70,8 @@ class A {
73
70
  * @returns {RichTextValue} The content of the comment
74
71
  * @example
75
72
  * ```ts
76
- * const comment = univerAPI.getActiveWorkbook()
77
- * .getSheetById(sheetId)
78
- * .getCommentById(commentId);
79
- * const content = comment.content;
73
+ * const commentBuilder = univerAPI.newTheadComment();
74
+ * console.log(commentBuilder.content);
80
75
  * ```
81
76
  */
82
77
  get content() {
@@ -87,10 +82,8 @@ class A {
87
82
  * @returns {string} The id of the comment
88
83
  * @example
89
84
  * ```ts
90
- * const comment = univerAPI.getActiveWorkbook()
91
- * .getSheetById(sheetId)
92
- * .getCommentById(commentId);
93
- * const id = comment.id;
85
+ * const commentBuilder = univerAPI.newTheadComment();
86
+ * console.log(commentBuilder.id);
94
87
  * ```
95
88
  */
96
89
  get id() {
@@ -101,10 +94,8 @@ class A {
101
94
  * @returns {string} The thread id of the comment
102
95
  * @example
103
96
  * ```ts
104
- * const comment = univerAPI.getActiveWorkbook()
105
- * .getSheetById(sheetId)
106
- * .getCommentById(commentId);
107
- * const threadId = comment.threadId;
97
+ * const commentBuilder = univerAPI.newTheadComment();
98
+ * console.log(commentBuilder.threadId);
108
99
  * ```
109
100
  */
110
101
  get threadId() {
@@ -115,10 +106,9 @@ class A {
115
106
  * @returns {FTheadCommentBuilder} The comment builder
116
107
  * @example
117
108
  * ```ts
118
- * const comment = univerAPI.getActiveWorkbook()
119
- * .getSheetById(sheetId)
120
- * .getCommentById(commentId);
121
- * const newComment = comment.copy();
109
+ * const commentBuilder = univerAPI.newTheadComment();
110
+ * const newCommentBuilder = commentBuilder.copy();
111
+ * console.log(newCommentBuilder);
122
112
  * ```
123
113
  */
124
114
  copy() {
@@ -132,11 +122,21 @@ class U extends A {
132
122
  /**
133
123
  * Set the content of the comment
134
124
  * @param {IDocumentBody | RichTextValue} content The content of the comment
135
- * @returns {FTheadCommentBuilder} The comment builder
125
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
136
126
  * @example
137
127
  * ```ts
138
- * const comment = univerAPI.newTheadComment()
139
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
128
+ * // Create a new comment
129
+ * const richText = univerAPI.newRichText().insertText('hello univer');
130
+ * const commentBuilder = univerAPI.newTheadComment()
131
+ * .setContent(richText);
132
+ * console.log(commentBuilder.content);
133
+ *
134
+ * // Add the comment to the cell A1
135
+ * const fWorkbook = univerAPI.getActiveWorkbook();
136
+ * const fWorksheet = fWorkbook.getActiveSheet();
137
+ * const cell = fWorksheet.getRange('A1');
138
+ * const result = await cell.addCommentAsync(commentBuilder);
139
+ * console.log(result);
140
140
  * ```
141
141
  */
142
142
  setContent(e) {
@@ -145,11 +145,22 @@ class U extends A {
145
145
  /**
146
146
  * Set the person id of the comment
147
147
  * @param {string} userId The person id of the comment
148
- * @returns {FTheadCommentBuilder} The comment builder
148
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
149
149
  * @example
150
150
  * ```ts
151
- * const comment = univerAPI.newTheadComment()
152
- * .setPersonId('123');
151
+ * // Create a new comment
152
+ * const richText = univerAPI.newRichText().insertText('hello univer');
153
+ * const commentBuilder = univerAPI.newTheadComment()
154
+ * .setContent(richText)
155
+ * .setPersonId('mock-user-id');
156
+ * console.log(commentBuilder.personId);
157
+ *
158
+ * // Add the comment to the cell A1
159
+ * const fWorkbook = univerAPI.getActiveWorkbook();
160
+ * const fWorksheet = fWorkbook.getActiveSheet();
161
+ * const cell = fWorksheet.getRange('A1');
162
+ * const result = await cell.addCommentAsync(commentBuilder);
163
+ * console.log(result);
153
164
  * ```
154
165
  */
155
166
  setPersonId(e) {
@@ -158,11 +169,22 @@ class U extends A {
158
169
  /**
159
170
  * Set the date time of the comment
160
171
  * @param {Date} date The date time of the comment
161
- * @returns {FTheadCommentBuilder} The comment builder
172
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
162
173
  * @example
163
174
  * ```ts
164
- * const comment = univerAPI.newTheadComment()
165
- * .setDateTime(new Date());
175
+ * // Create a new comment
176
+ * const richText = univerAPI.newRichText().insertText('hello univer');
177
+ * const commentBuilder = univerAPI.newTheadComment()
178
+ * .setContent(richText)
179
+ * .setDateTime(new Date('2025-02-21 14:22:22'));
180
+ * console.log(commentBuilder.dateTime);
181
+ *
182
+ * // Add the comment to the cell A1
183
+ * const fWorkbook = univerAPI.getActiveWorkbook();
184
+ * const fWorksheet = fWorkbook.getActiveSheet();
185
+ * const cell = fWorksheet.getRange('A1');
186
+ * const result = await cell.addCommentAsync(commentBuilder);
187
+ * console.log(result);
166
188
  * ```
167
189
  */
168
190
  setDateTime(e) {
@@ -171,11 +193,22 @@ class U extends A {
171
193
  /**
172
194
  * Set the id of the comment
173
195
  * @param {string} id The id of the comment
174
- * @returns {FTheadCommentBuilder} The comment builder
196
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
175
197
  * @example
176
198
  * ```ts
177
- * const comment = univerAPI.newTheadComment()
178
- * .setId('123');
199
+ * // Create a new comment
200
+ * const richText = univerAPI.newRichText().insertText('hello univer');
201
+ * const commentBuilder = univerAPI.newTheadComment()
202
+ * .setContent(richText)
203
+ * .setId('mock-comment-id');
204
+ * console.log(commentBuilder.id);
205
+ *
206
+ * // Add the comment to the cell A1
207
+ * const fWorkbook = univerAPI.getActiveWorkbook();
208
+ * const fWorksheet = fWorkbook.getActiveSheet();
209
+ * const cell = fWorksheet.getRange('A1');
210
+ * const result = await cell.addCommentAsync(commentBuilder);
211
+ * console.log(result);
179
212
  * ```
180
213
  */
181
214
  setId(e) {
@@ -187,8 +220,19 @@ class U extends A {
187
220
  * @returns {FTheadCommentBuilder} The comment builder
188
221
  * @example
189
222
  * ```ts
190
- * const comment = univerAPI.newTheadComment()
191
- * .setThreadId('123');
223
+ * // Create a new comment
224
+ * const richText = univerAPI.newRichText().insertText('hello univer');
225
+ * const commentBuilder = univerAPI.newTheadComment()
226
+ * .setContent(richText)
227
+ * .setThreadId('mock-thread-id');
228
+ * console.log(commentBuilder.threadId);
229
+ *
230
+ * // Add the comment to the cell A1
231
+ * const fWorkbook = univerAPI.getActiveWorkbook();
232
+ * const fWorksheet = fWorkbook.getActiveSheet();
233
+ * const cell = fWorksheet.getRange('A1');
234
+ * const result = await cell.addCommentAsync(commentBuilder);
235
+ * console.log(result);
192
236
  * ```
193
237
  */
194
238
  setThreadId(e) {
@@ -199,9 +243,15 @@ class U extends A {
199
243
  * @returns {IThreadComment} The comment
200
244
  * @example
201
245
  * ```ts
246
+ * const richText = univerAPI.newRichText().insertText('hello univer');
202
247
  * const comment = univerAPI.newTheadComment()
203
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'))
248
+ * .setContent(richText)
249
+ * .setPersonId('mock-user-id')
250
+ * .setDateTime(new Date('2025-02-21 14:22:22'))
251
+ * .setId('mock-comment-id')
252
+ * .setThreadId('mock-thread-id')
204
253
  * .build();
254
+ * console.log(comment);
205
255
  * ```
206
256
  */
207
257
  build() {
@@ -225,10 +275,12 @@ let I = class {
225
275
  * @returns {boolean} Whether the comment is a root comment
226
276
  * @example
227
277
  * ```ts
228
- * const comment = univerAPI.getActiveWorkbook()
229
- * .getSheetById(sheetId)
230
- * .getCommentById(commentId);
231
- * const isRoot = comment.getIsRoot();
278
+ * const fWorkbook = univerAPI.getActiveWorkbook();
279
+ * const fWorksheet = fWorkbook.getActiveSheet();
280
+ * const comments = fWorksheet.getComments();
281
+ * comments.forEach((comment) => {
282
+ * console.log(comment.getIsRoot());
283
+ * });
232
284
  * ```
233
285
  */
234
286
  getIsRoot() {
@@ -239,10 +291,12 @@ let I = class {
239
291
  * @returns {IBaseComment} The comment data
240
292
  * @example
241
293
  * ```ts
242
- * const comment = univerAPI.getActiveWorkbook()
243
- * .getSheetById(sheetId)
244
- * .getCommentById(commentId);
245
- * const commentData = comment.getCommentData();
294
+ * const fWorkbook = univerAPI.getActiveWorkbook();
295
+ * const fWorksheet = fWorkbook.getActiveSheet();
296
+ * const comments = fWorksheet.getComments();
297
+ * comments.forEach((comment) => {
298
+ * console.log(comment.getCommentData());
299
+ * });
246
300
  * ```
247
301
  */
248
302
  getCommentData() {
@@ -254,10 +308,17 @@ let I = class {
254
308
  * @returns {FThreadComment[]} the replies of the comment
255
309
  * @example
256
310
  * ```ts
257
- * const comment = univerAPI.getActiveWorkbook()
258
- * .getSheetById(sheetId)
259
- * .getCommentById(commentId);
260
- * const replies = comment.getReplies();
311
+ * const fWorkbook = univerAPI.getActiveWorkbook();
312
+ * const fWorksheet = fWorkbook.getActiveSheet();
313
+ * const comments = fWorksheet.getComments();
314
+ * comments.forEach((comment) => {
315
+ * if (comment.getIsRoot()) {
316
+ * const replies = comment.getReplies();
317
+ * replies.forEach((reply) => {
318
+ * console.log(reply.getCommentData());
319
+ * });
320
+ * }
321
+ * });
261
322
  * ```
262
323
  */
263
324
  getReplies() {
@@ -270,10 +331,12 @@ let I = class {
270
331
  * @returns {FRange | null} The range of the comment
271
332
  * @example
272
333
  * ```ts
273
- * const comment = univerAPI.getActiveWorkbook()
274
- * .getSheetById(sheetId)
275
- * .getCommentById(commentId);
276
- * const range = comment.getRange();
334
+ * const fWorkbook = univerAPI.getActiveWorkbook();
335
+ * const fWorksheet = fWorkbook.getActiveSheet();
336
+ * const comments = fWorksheet.getComments();
337
+ * comments.forEach((comment) => {
338
+ * console.log(comment.getRange().getA1Notation());
339
+ * });
277
340
  * ```
278
341
  */
279
342
  getRange() {
@@ -298,10 +361,12 @@ let I = class {
298
361
  * @returns {RichTextValue} The rich text of the comment
299
362
  * @example
300
363
  * ```ts
301
- * const comment = univerAPI.getActiveWorkbook()
302
- * .getSheetById(sheetId)
303
- * .getCommentById(commentId);
304
- * const richText = comment.getRichText();
364
+ * const fWorkbook = univerAPI.getActiveWorkbook();
365
+ * const fWorksheet = fWorkbook.getActiveSheet();
366
+ * const comments = fWorksheet.getComments();
367
+ * comments.forEach((comment) => {
368
+ * console.log(comment.getRichText());
369
+ * });
305
370
  * ```
306
371
  */
307
372
  getRichText() {
@@ -310,13 +375,16 @@ let I = class {
310
375
  }
311
376
  /**
312
377
  * Delete the comment and it's replies
313
- * @returns {Promise<boolean>} success or not
378
+ * @returns {Promise<boolean>} Whether the comment is deleted successfully
314
379
  * @example
315
380
  * ```ts
316
- * const comment = univerAPI.getActiveWorkbook()
317
- * .getSheetById(sheetId)
318
- * .getCommentById(commentId);
319
- * const success = await comment.deleteAsync();
381
+ * const fWorkbook = univerAPI.getActiveWorkbook();
382
+ * const fWorksheet = fWorkbook.getActiveSheet();
383
+ * const comments = fWorksheet.getComments();
384
+ *
385
+ * // Delete the first comment
386
+ * const result = await comments[0]?.deleteAsync();
387
+ * console.log(result);
320
388
  * ```
321
389
  */
322
390
  deleteAsync() {
@@ -346,13 +414,27 @@ let I = class {
346
414
  /**
347
415
  * Update the comment content
348
416
  * @param {IDocumentBody | RichTextValue} content The new content of the comment
349
- * @returns {Promise<boolean>} success or not
417
+ * @returns {Promise<boolean>} Whether the comment is updated successfully
350
418
  * @example
351
419
  * ```ts
352
- * const comment = univerAPI.getActiveWorkbook()
353
- * .getSheetById(sheetId)
354
- * .getCommentById(commentId);
355
- * const success = await comment.updateAsync(univerAPI.newRichText().insertText('hello zhangsan'));
420
+ * const fWorkbook = univerAPI.getActiveWorkbook();
421
+ * const fWorksheet = fWorkbook.getActiveSheet();
422
+ *
423
+ * // Create a new comment
424
+ * const richText = univerAPI.newRichText().insertText('hello univer');
425
+ * const commentBuilder = univerAPI.newTheadComment()
426
+ * .setContent(richText)
427
+ * .setId('mock-comment-id');
428
+ * const cell = fWorksheet.getRange('A1');
429
+ * await cell.addCommentAsync(commentBuilder);
430
+ *
431
+ * // Update the comment after 3 seconds
432
+ * setTimeout(async () => {
433
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
434
+ * const newRichText = univerAPI.newRichText().insertText('Hello Univer AI');
435
+ * const result = await comment.updateAsync(newRichText);
436
+ * console.log(result);
437
+ * }, 3000);
356
438
  * ```
357
439
  */
358
440
  async updateAsync(i) {
@@ -381,13 +463,26 @@ let I = class {
381
463
  /**
382
464
  * Resolve the comment
383
465
  * @param {boolean} resolved Whether the comment is resolved
384
- * @returns {Promise<boolean>} success or not
466
+ * @returns {Promise<boolean>} Set the comment to resolved or not operation result
385
467
  * @example
386
468
  * ```ts
387
- * const comment = univerAPI.getActiveWorkbook()
388
- * .getSheetById(sheetId)
389
- * .getCommentById(commentId);
390
- * const success = await comment.resolveAsync(true);
469
+ * const fWorkbook = univerAPI.getActiveWorkbook();
470
+ * const fWorksheet = fWorkbook.getActiveSheet();
471
+ *
472
+ * // Create a new comment
473
+ * const richText = univerAPI.newRichText().insertText('hello univer');
474
+ * const commentBuilder = univerAPI.newTheadComment()
475
+ * .setContent(richText)
476
+ * .setId('mock-comment-id');
477
+ * const cell = fWorksheet.getRange('A1');
478
+ * await cell.addCommentAsync(commentBuilder);
479
+ *
480
+ * // Resolve the comment after 3 seconds
481
+ * setTimeout(async () => {
482
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
483
+ * const result = await comment.resolveAsync(true);
484
+ * console.log(result);
485
+ * }, 3000);
391
486
  * ```
392
487
  */
393
488
  resolveAsync(i) {
@@ -404,20 +499,29 @@ let I = class {
404
499
  /**
405
500
  * Reply to the comment
406
501
  * @param {FTheadCommentBuilder} comment The comment to reply to
407
- * @returns {Promise<boolean>} success or not
502
+ * @returns {Promise<boolean>} Whether the comment is replied successfully
408
503
  * @example
409
504
  * ```ts
410
- * const comment = univerAPI.getActiveWorkbook()
411
- * .getSheetById(sheetId)
412
- * .getCommentById(commentId);
505
+ * const fWorkbook = univerAPI.getActiveWorkbook();
506
+ * const fWorksheet = fWorkbook.getActiveSheet();
413
507
  *
414
- * const reply = univerAPI.newTheadComment()
415
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
508
+ * // Create a new comment
509
+ * const richText = univerAPI.newRichText().insertText('hello univer');
510
+ * const commentBuilder = univerAPI.newTheadComment()
511
+ * .setContent(richText)
512
+ * .setId('mock-comment-id');
513
+ * const cell = fWorksheet.getRange('A1');
514
+ * await cell.addCommentAsync(commentBuilder);
416
515
  *
417
- * const success = await comment.replyAsync(reply);
516
+ * // Reply to the comment
517
+ * const replyText = univerAPI.newRichText().insertText('Hello Univer AI');
518
+ * const reply = univerAPI.newTheadComment().setContent(replyText);
519
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
520
+ * const result = await comment.replyAsync(reply);
521
+ * console.log(result);
418
522
  * ```
419
523
  */
420
- async replyAsync(i) {
524
+ replyAsync(i) {
421
525
  var r;
422
526
  const e = i.build();
423
527
  return this._commandService.executeCommand(
@@ -429,7 +533,7 @@ let I = class {
429
533
  id: R(),
430
534
  parentId: this._thread.id,
431
535
  threadId: this._thread.threadId,
432
- ref: (r = this._parent) == null ? void 0 : r.ref,
536
+ ref: ((r = this._parent) == null ? void 0 : r.ref) || this._thread.ref,
433
537
  unitId: this._thread.unitId,
434
538
  subUnitId: this._thread.subUnitId,
435
539
  text: e.text,
@@ -442,11 +546,11 @@ let I = class {
442
546
  }
443
547
  };
444
548
  I = ee([
445
- p(2, T(V)),
446
- p(3, _),
447
- p(4, q),
448
- p(5, T(b)),
449
- p(6, T(W))
549
+ _(2, T(V)),
550
+ _(3, p),
551
+ _(4, q),
552
+ _(5, T(b)),
553
+ _(6, T(W))
450
554
  ], I);
451
555
  class te extends j {
452
556
  getComment() {
@@ -468,7 +572,7 @@ class te extends j {
468
572
  }
469
573
  addComment(e) {
470
574
  var a;
471
- const r = this._injector, t = (a = this.getComment()) == null ? void 0 : a.getCommentData(), n = r.get(_), o = r.get(W), s = this._workbook.getUnitId(), h = this._worksheet.getSheetId(), c = `${F.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, m = o.getCurrentUser(), d = e instanceof U ? e.build() : { text: e };
575
+ const r = this._injector, t = (a = this.getComment()) == null ? void 0 : a.getCommentData(), n = r.get(p), o = r.get(W), s = this._workbook.getUnitId(), h = this._worksheet.getSheetId(), c = `${F.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, m = o.getCurrentUser(), d = e instanceof U ? e.build() : { text: e };
472
576
  return n.executeCommand(f.id, {
473
577
  unitId: s,
474
578
  subUnitId: h,
@@ -488,7 +592,7 @@ class te extends j {
488
592
  }
489
593
  clearComment() {
490
594
  var s;
491
- const e = this._injector, r = (s = this.getComment()) == null ? void 0 : s.getCommentData(), t = e.get(_), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId();
595
+ const e = this._injector, r = (s = this.getComment()) == null ? void 0 : s.getCommentData(), t = e.get(p), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId();
492
596
  return r ? t.executeCommand(w.id, {
493
597
  unitId: n,
494
598
  subUnitId: o,
@@ -596,7 +700,7 @@ class re extends O {
596
700
  * @param callback Callback function, param contains comment info and target cell.
597
701
  */
598
702
  onCommented(e) {
599
- return this._injector.get(_).onCommandExecuted((t) => {
703
+ return this._injector.get(p).onCommandExecuted((t) => {
600
704
  if (t.id === f.id) {
601
705
  const n = t.params;
602
706
  e(n);
@@ -616,7 +720,7 @@ const l = {
616
720
  CommentUpdated: "CommentUpdated",
617
721
  BeforeCommentUpdate: "BeforeCommentUpdate",
618
722
  CommentDeleted: "CommentDeleted",
619
- BeforeCommentDeleted: "BeforeCommentDeleted",
723
+ BeforeCommentDelete: "BeforeCommentDelete",
620
724
  CommentResolved: "CommentResolved",
621
725
  BeforeCommentResolve: "BeforeCommentResolve"
622
726
  };
@@ -636,8 +740,8 @@ class oe extends z {
636
740
  get CommentDeleted() {
637
741
  return l.CommentDeleted;
638
742
  }
639
- get BeforeCommentDeleted() {
640
- return l.BeforeCommentDeleted;
743
+ get BeforeCommentDelete() {
744
+ return l.BeforeCommentDelete;
641
745
  }
642
746
  get CommentResolved() {
643
747
  return l.CommentResolved;
@@ -650,7 +754,7 @@ z.extend(oe);
650
754
  class se extends $ {
651
755
  // eslint-disable-next-line max-lines-per-function
652
756
  _initialize(e) {
653
- const r = e.get(_);
757
+ const r = e.get(p);
654
758
  this.registerEventHandler(
655
759
  this.Event.CommentAdded,
656
760
  () => r.onCommandExecuted((t) => {
@@ -779,7 +883,7 @@ class se extends $ {
779
883
  }
780
884
  })
781
885
  ), this.registerEventHandler(
782
- this.Event.BeforeCommentDeleted,
886
+ this.Event.BeforeCommentDelete,
783
887
  () => r.beforeCommandExecuted((t) => {
784
888
  var d, a, u, g, C;
785
889
  if (t.id !== y.id && t.id !== w.id) return;
@@ -798,7 +902,7 @@ class se extends $ {
798
902
  col: (C = (g = m.getRange()) == null ? void 0 : g.getColumn()) != null ? C : 0,
799
903
  comment: m
800
904
  };
801
- if (this.fireEvent(this.Event.BeforeCommentDeleted, v), v.cancel)
905
+ if (this.fireEvent(this.Event.BeforeCommentDelete, v), v.cancel)
802
906
  throw new E();
803
907
  }
804
908
  })