@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.
@@ -8,39 +8,52 @@ type IUpdateCommandParams = any;
8
8
  */
9
9
  export interface IFWorkbookThreadCommentMixin {
10
10
  /**
11
- * Get all comments in the current sheet
12
- * @returns all comments in the current sheet
11
+ * Get all comments in the current workbook
12
+ * @returns {FThreadComment[]} All comments in the current workbook
13
13
  * @example
14
14
  * ```ts
15
- * const workbook = univerAPI.getActiveWorkbook();
16
- * const comments = workbook.getComments();
15
+ * const fWorkbook = univerAPI.getActiveWorkbook();
16
+ * const comments = fWorkbook.getComments();
17
+ * comments.forEach((comment) => {
18
+ * const isRoot = comment.getIsRoot();
19
+ *
20
+ * if (isRoot) {
21
+ * console.log('root comment:', comment.getCommentData());
22
+ *
23
+ * const replies = comment.getReplies();
24
+ * replies.forEach((reply) => {
25
+ * console.log('reply comment:', reply.getCommentData());
26
+ * });
27
+ * }
28
+ * });
17
29
  * ```
18
30
  */
19
31
  getComments(): FThreadComment[];
20
32
  /**
21
- * Clear all comments in the current sheet
22
- * @returns Whether the comments are cleared successfully.
33
+ * Clear all comments in the current workbook
34
+ * @returns {Promise<boolean>} Whether the comments are cleared successfully.
23
35
  * @example
24
36
  * ```ts
25
- * const workbook = univerAPI.getActiveWorkbook();
26
- * const success = await workbook.clearComments();
37
+ * const fWorkbook = univerAPI.getActiveWorkbook();
38
+ * const result = await fWorkbook.clearComments();
39
+ * console.log(result);
27
40
  * ```
28
41
  */
29
42
  clearComments(): Promise<boolean>;
30
43
  /**
31
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.CommentUpdated, () => {})` as instead
44
+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.CommentUpdated, (params) => {})` as instead
32
45
  */
33
46
  onThreadCommentChange(callback: (commentUpdate: CommentUpdate) => void | false): IDisposable;
34
47
  /**
35
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.BeforeCommentAdd, () => {})` as instead
48
+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.BeforeCommentAdd, (params) => {})` as instead
36
49
  */
37
50
  onBeforeAddThreadComment(this: FWorkbook, callback: (params: IAddCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
38
51
  /**
39
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.BeforeCommentUpdate, () => {})` as instead
52
+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.BeforeCommentUpdate, (params) => {})` as instead
40
53
  */
41
54
  onBeforeUpdateThreadComment(this: FWorkbook, callback: (params: IUpdateCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
42
55
  /**
43
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.BeforeCommentDelete, () => {})` as instead
56
+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.BeforeCommentDelete, (params) => {})` as instead
44
57
  */
45
58
  onBeforeDeleteThreadComment(this: FWorkbook, callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
46
59
  }
@@ -8,20 +8,36 @@ import { FThreadComment } from './f-thread-comment';
8
8
  export interface IFWorksheetCommentMixin {
9
9
  /**
10
10
  * Get all comments in the current sheet
11
- * @returns all comments in the current sheet
11
+ * @returns {FThreadComment[]} All comments in the current sheet
12
+ * @example
12
13
  * ```ts
13
- * const workbook = univerAPI.getActiveWorkbook();
14
- * const worksheet = workbook.getSheetById(sheetId);
15
- * const comments = worksheet.getComments();
14
+ * const fWorkbook = univerAPI.getActiveWorkbook();
15
+ * const fWorksheet = fWorkbook.getActiveSheet();
16
+ * const comments = fWorksheet.getComments();
17
+ * comments.forEach((comment) => {
18
+ * const isRoot = comment.getIsRoot();
19
+ *
20
+ * if (isRoot) {
21
+ * console.log('root comment:', comment.getCommentData());
22
+ *
23
+ * const replies = comment.getReplies();
24
+ * replies.forEach((reply) => {
25
+ * console.log('reply comment:', reply.getCommentData());
26
+ * });
27
+ * }
28
+ * });
16
29
  * ```
17
30
  */
18
31
  getComments(): FThreadComment[];
19
32
  /**
20
33
  * Clear all comments in the current sheet
34
+ * @returns {Promise<boolean>} Whether the comments are cleared successfully.
35
+ * @example
21
36
  * ```ts
22
- * const workbook = univerAPI.getActiveWorkbook();
23
- * const worksheet = workbook.getSheetById(sheetId);
24
- * await worksheet.clearComments();
37
+ * const fWorkbook = univerAPI.getActiveWorkbook();
38
+ * const fWorksheet = fWorkbook.getActiveSheet();
39
+ * const result = await fWorksheet.clearComments();
40
+ * console.log(result);
25
41
  * ```
26
42
  */
27
43
  clearComments(): Promise<boolean>;
@@ -29,9 +45,19 @@ export interface IFWorksheetCommentMixin {
29
45
  * get comment by comment id
30
46
  * @param {string} commentId comment id
31
47
  * ```ts
32
- * const workbook = univerAPI.getActiveWorkbook();
33
- * const worksheet = workbook.getSheetById(sheetId);
34
- * const comment = worksheet.getCommentById(commentId);
48
+ * const fWorkbook = univerAPI.getActiveWorkbook();
49
+ * const fWorksheet = fWorkbook.getActiveSheet();
50
+ *
51
+ * // Create a new comment
52
+ * const richText = univerAPI.newRichText().insertText('hello univer');
53
+ * const commentBuilder = univerAPI.newTheadComment()
54
+ * .setContent(richText)
55
+ * .setId('mock-comment-id');
56
+ * const cell = fWorksheet.getRange('A1');
57
+ * await cell.addCommentAsync(commentBuilder);
58
+ *
59
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
60
+ * console.log(comment, comment?.getCommentData());
35
61
  * ```
36
62
  */
37
63
  getCommentById(commentId: string): FThreadComment | undefined;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(a,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs","@univerjs/core/facade"],s):(a=typeof globalThis<"u"?globalThis:a||self,s(a.UniverSheetsThreadCommentFacade={},a.UniverCore,a.UniverSheetsThreadComment,a.UniverSheetsFacade,a.UniverThreadComment,a.UniverEngineFormula,a.rxjs,a.UniverCoreFacade))})(this,function(a,s,I,p,h,E,y,b){"use strict";var P=Object.defineProperty;var W=(a,s,I)=>s in a?P(a,s,{enumerable:!0,configurable:!0,writable:!0,value:I}):a[s]=I;var T=(a,s,I)=>W(a,typeof s!="symbol"?s+"":s,I);var A=Object.getOwnPropertyDescriptor,B=(f,t,r,e)=>{for(var n=e>1?void 0:e?A(t,r):t,o=f.length-1,i;o>=0;o--)(i=f[o])&&(n=i(n)||n);return n},U=(f,t)=>(r,e)=>t(r,e,f);class w{constructor(t){T(this,"_comment",{id:s.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:s.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});t&&(this._comment=t)}static create(t){return new w(t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return k.create(s.Tools.deepClone(this._comment))}}class k extends w{static create(t){return new k(t)}setContent(t){return t instanceof s.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(t){return this._comment.personId=t,this}setDateTime(t){return this._comment.dT=h.getDT(t),this}setId(t){return this._comment.id=t,this}setThreadId(t){return this._comment.threadId=t,this}build(){return this._comment}}a.FThreadComment=class{constructor(t,r,e,n,o,i,u){this._thread=t,this._parent=r,this._injector=e,this._commandService=n,this._univerInstanceService=o,this._threadCommentModel=i,this._userManagerService=u}_getRef(){var e;const t=((e=this._parent)==null?void 0:e.ref)||this._thread.ref;return E.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...r}=this._thread;return r}getReplies(){var e;const t=this._getRef(),r=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(e=r==null?void 0:r.children)==null?void 0:e.map(n=>this._injector.createInstance(a.FThreadComment,n))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,s.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const r=t.getSheetBySheetId(this._thread.subUnitId);if(!r)return null;const e=this._getRef();return this._injector.createInstance(p.FRange,t,r,e)}getContent(){return this._thread.text}getRichText(){const t=this._thread.text;return s.RichTextValue.create({body:t,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?h.DeleteCommentTreeCommand.id:h.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(t){return this.updateAsync(t)}async updateAsync(t){const r=t instanceof s.RichTextValue?t.getData().body:t,e=h.getDT();return await this._commandService.executeCommand(h.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:r,updated:!0,updateT:e}})}resolve(t){return this.resolveAsync(t)}resolveAsync(t){return this._commandService.executeCommand(h.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}async replyAsync(t){var e;const r=t.build();return this._commandService.executeCommand(h.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:s.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(e=this._parent)==null?void 0:e.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:r.text,attachments:r.attachments,dT:r.dT||h.getDT(),personId:r.personId||this._userManagerService.getCurrentUser().userID}})}},a.FThreadComment=B([U(2,s.Inject(s.Injector)),U(3,s.ICommandService),U(4,s.IUniverInstanceService),U(5,s.Inject(I.SheetsThreadCommentModel)),U(6,s.Inject(s.UserManagerService))],a.FThreadComment);class x extends p.FRange{getComment(){const r=this._injector.get(I.SheetsThreadCommentModel),e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),o=r.getByLocation(e,n,this._range.startRow,this._range.startColumn);if(!o)return null;const i=r.getComment(e,n,o);return i?this._injector.createInstance(a.FThreadComment,i):null}getComments(){const r=this._injector.get(I.SheetsThreadCommentModel),e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),o=[];return s.Range.foreach(this._range,(i,u)=>{const C=r.getByLocation(e,n,i,u);if(C){const m=r.getComment(e,n,C);m&&o.push(this._injector.createInstance(a.FThreadComment,m))}}),o}addComment(t){var c;const r=this._injector,e=(c=this.getComment())==null?void 0:c.getCommentData(),n=r.get(s.ICommandService),o=r.get(s.UserManagerService),i=this._workbook.getUnitId(),u=this._worksheet.getSheetId(),C=`${s.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,m=o.getCurrentUser(),d=t instanceof k?t.build():{text:t};return n.executeCommand(h.AddCommentCommand.id,{unitId:i,subUnitId:u,comment:{text:d.text,dT:d.dT||h.getDT(),attachments:[],id:d.id||s.generateRandomId(),ref:C,personId:d.personId||m.userID,parentId:e==null?void 0:e.id,unitId:i,subUnitId:u,threadId:(e==null?void 0:e.threadId)||s.generateRandomId()}})}clearComment(){var i;const t=this._injector,r=(i=this.getComment())==null?void 0:i.getCommentData(),e=t.get(s.ICommandService),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?e.executeCommand(h.DeleteCommentTreeCommand.id,{unitId:n,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){const r=this.getComments().map(e=>e.deleteAsync());return Promise.all(r).then(()=>!0)}addCommentAsync(t){return this.addComment(t)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}p.FRange.extend(x);class D extends p.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(h.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(t=>this._injector.createInstance(a.FThreadComment,t.root))}clearComments(){const r=this.getComments().map(e=>e.deleteAsync());return Promise.all(r).then(()=>!0)}onThreadCommentChange(t){return s.toDisposable(this._threadCommentModel.commentUpdate$.pipe(y.filter(r=>r.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return s.toDisposable(this._commandService.beforeCommandExecuted((r,e)=>{const n=r.params;if(r.id===h.AddCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(t(n,e)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return s.toDisposable(this._commandService.beforeCommandExecuted((r,e)=>{const n=r.params;if(r.id===h.UpdateCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(t(n,e)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return s.toDisposable(this._commandService.beforeCommandExecuted((r,e)=>{const n=r.params;if(r.id===h.DeleteCommentCommand.id||r.id===h.DeleteCommentTreeCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(t(n,e)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}p.FWorkbook.extend(D);class j extends p.FWorksheet{getComments(){return this._injector.get(I.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(a.FThreadComment,e))}clearComments(){const r=this.getComments().map(e=>e.deleteAsync());return Promise.all(r).then(()=>!0)}onCommented(t){return this._injector.get(s.ICommandService).onCommandExecuted(e=>{if(e.id===h.AddCommentCommand.id){const n=e.params;t(n)}})}getCommentById(t){const e=this._injector.get(I.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);if(e)return this._injector.createInstance(a.FThreadComment,e)}}p.FWorksheet.extend(j);const _={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class F extends b.FEventName{get CommentAdded(){return _.CommentAdded}get BeforeCommentAdd(){return _.BeforeCommentAdd}get CommentUpdated(){return _.CommentUpdated}get BeforeCommentUpdate(){return _.BeforeCommentUpdate}get CommentDeleted(){return _.CommentDeleted}get BeforeCommentDeleted(){return _.BeforeCommentDeleted}get CommentResolved(){return _.CommentResolved}get BeforeCommentResolve(){return _.BeforeCommentResolve}}b.FEventName.extend(F);class M extends b.FUniver{_initialize(t){const r=t.get(s.ICommandService);this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{var d,c,g,l,v;if(e.id!==h.AddCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{comment:C}=u,m=i.getRange(C.ref).getComment();m&&this.fireEvent(this.Event.CommentAdded,{workbook:o,worksheet:i,row:(g=(c=m.getRange())==null?void 0:c.getRow())!=null?g:0,col:(v=(l=m.getRange())==null?void 0:l.getColumn())!=null?v:0,comment:m})})),this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{var d,c,g,l,v;if(e.id!==h.UpdateCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C}=u.payload,m=i.getCommentById(C);m&&this.fireEvent(this.Event.CommentUpdated,{workbook:o,worksheet:i,row:(g=(c=m.getRange())==null?void 0:c.getRow())!=null?g:0,col:(v=(l=m.getRange())==null?void 0:l.getColumn())!=null?v:0,comment:m})})),this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{var m;if(e.id!==h.DeleteCommentCommand.id&&e.id!==h.DeleteCommentTreeCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(m=this.getActiveWorkbook)==null?void 0:m.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C}=u;this.fireEvent(this.Event.CommentDeleted,{workbook:o,worksheet:i,commentId:C})})),this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{var c,g,l;if(e.id!==h.ResolveCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C,resolved:m}=u,d=i.getComments().find(v=>v.getCommentData().id===C);d&&this.fireEvent(this.Event.CommentResolved,{workbook:o,worksheet:i,row:(g=d.getRange().getRow())!=null?g:0,col:(l=d.getRange().getColumn())!=null?l:0,comment:d,resolved:m})})),this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(e=>{var c,g,l;if(e.id!==h.AddCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{comment:C}=u,m=i.getActiveRange();if(!m)return;const d={workbook:o,worksheet:i,row:(g=m.getRow())!=null?g:0,col:(l=m.getColumn())!=null?l:0,comment:w.create(C)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new s.CanceledError})),this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(e=>{var c,g,l,v,S;if(e.id!==h.UpdateCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C,text:m}=u.payload,d=i.getCommentById(C);if(d){const R={workbook:o,worksheet:i,row:(l=(g=d.getRange())==null?void 0:g.getRow())!=null?l:0,col:(S=(v=d.getRange())==null?void 0:v.getColumn())!=null?S:0,comment:d,newContent:s.RichTextValue.createByBody(m)};if(this.fireEvent(this.Event.BeforeCommentUpdate,R),R.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentDeleted,()=>r.beforeCommandExecuted(e=>{var d,c,g,l,v;if(e.id!==h.DeleteCommentCommand.id&&e.id!==h.DeleteCommentTreeCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C}=u,m=i.getCommentById(C);if(m){const S={workbook:o,worksheet:i,row:(g=(c=m.getRange())==null?void 0:c.getRow())!=null?g:0,col:(v=(l=m.getRange())==null?void 0:l.getColumn())!=null?v:0,comment:m};if(this.fireEvent(this.Event.BeforeCommentDeleted,S),S.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(e=>{var c,g,l;if(e.id!==h.ResolveCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C,resolved:m}=u,d=i.getComments().find(v=>v.getCommentData().id===C);if(d){const v={workbook:o,worksheet:i,row:(g=d.getRange().getRow())!=null?g:0,col:(l=d.getRange().getColumn())!=null?l:0,comment:d,resolved:m};if(this.fireEvent(this.Event.BeforeCommentResolve,v),v.cancel)throw new s.CanceledError}}))}newTheadComment(t){return new k(t)}}b.FUniver.extend(M),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs","@univerjs/core/facade"],s):(a=typeof globalThis<"u"?globalThis:a||self,s(a.UniverSheetsThreadCommentFacade={},a.UniverCore,a.UniverSheetsThreadComment,a.UniverSheetsFacade,a.UniverThreadComment,a.UniverEngineFormula,a.rxjs,a.UniverCoreFacade))})(this,function(a,s,I,p,h,E,y,b){"use strict";var P=Object.defineProperty;var W=(a,s,I)=>s in a?P(a,s,{enumerable:!0,configurable:!0,writable:!0,value:I}):a[s]=I;var T=(a,s,I)=>W(a,typeof s!="symbol"?s+"":s,I);var A=Object.getOwnPropertyDescriptor,B=(f,t,r,e)=>{for(var n=e>1?void 0:e?A(t,r):t,o=f.length-1,i;o>=0;o--)(i=f[o])&&(n=i(n)||n);return n},U=(f,t)=>(r,e)=>t(r,e,f);class w{constructor(t){T(this,"_comment",{id:s.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:s.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});t&&(this._comment=t)}static create(t){return new w(t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return k.create(s.Tools.deepClone(this._comment))}}class k extends w{static create(t){return new k(t)}setContent(t){return t instanceof s.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(t){return this._comment.personId=t,this}setDateTime(t){return this._comment.dT=h.getDT(t),this}setId(t){return this._comment.id=t,this}setThreadId(t){return this._comment.threadId=t,this}build(){return this._comment}}a.FThreadComment=class{constructor(t,r,e,n,o,i,u){this._thread=t,this._parent=r,this._injector=e,this._commandService=n,this._univerInstanceService=o,this._threadCommentModel=i,this._userManagerService=u}_getRef(){var e;const t=((e=this._parent)==null?void 0:e.ref)||this._thread.ref;return E.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...r}=this._thread;return r}getReplies(){var e;const t=this._getRef(),r=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(e=r==null?void 0:r.children)==null?void 0:e.map(n=>this._injector.createInstance(a.FThreadComment,n))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,s.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const r=t.getSheetBySheetId(this._thread.subUnitId);if(!r)return null;const e=this._getRef();return this._injector.createInstance(p.FRange,t,r,e)}getContent(){return this._thread.text}getRichText(){const t=this._thread.text;return s.RichTextValue.create({body:t,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?h.DeleteCommentTreeCommand.id:h.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(t){return this.updateAsync(t)}async updateAsync(t){const r=t instanceof s.RichTextValue?t.getData().body:t,e=h.getDT();return await this._commandService.executeCommand(h.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:r,updated:!0,updateT:e}})}resolve(t){return this.resolveAsync(t)}resolveAsync(t){return this._commandService.executeCommand(h.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}replyAsync(t){var e;const r=t.build();return this._commandService.executeCommand(h.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:s.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((e=this._parent)==null?void 0:e.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:r.text,attachments:r.attachments,dT:r.dT||h.getDT(),personId:r.personId||this._userManagerService.getCurrentUser().userID}})}},a.FThreadComment=B([U(2,s.Inject(s.Injector)),U(3,s.ICommandService),U(4,s.IUniverInstanceService),U(5,s.Inject(I.SheetsThreadCommentModel)),U(6,s.Inject(s.UserManagerService))],a.FThreadComment);class x extends p.FRange{getComment(){const r=this._injector.get(I.SheetsThreadCommentModel),e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),o=r.getByLocation(e,n,this._range.startRow,this._range.startColumn);if(!o)return null;const i=r.getComment(e,n,o);return i?this._injector.createInstance(a.FThreadComment,i):null}getComments(){const r=this._injector.get(I.SheetsThreadCommentModel),e=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),o=[];return s.Range.foreach(this._range,(i,u)=>{const C=r.getByLocation(e,n,i,u);if(C){const m=r.getComment(e,n,C);m&&o.push(this._injector.createInstance(a.FThreadComment,m))}}),o}addComment(t){var c;const r=this._injector,e=(c=this.getComment())==null?void 0:c.getCommentData(),n=r.get(s.ICommandService),o=r.get(s.UserManagerService),i=this._workbook.getUnitId(),u=this._worksheet.getSheetId(),C=`${s.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,m=o.getCurrentUser(),d=t instanceof k?t.build():{text:t};return n.executeCommand(h.AddCommentCommand.id,{unitId:i,subUnitId:u,comment:{text:d.text,dT:d.dT||h.getDT(),attachments:[],id:d.id||s.generateRandomId(),ref:C,personId:d.personId||m.userID,parentId:e==null?void 0:e.id,unitId:i,subUnitId:u,threadId:(e==null?void 0:e.threadId)||s.generateRandomId()}})}clearComment(){var i;const t=this._injector,r=(i=this.getComment())==null?void 0:i.getCommentData(),e=t.get(s.ICommandService),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?e.executeCommand(h.DeleteCommentTreeCommand.id,{unitId:n,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){const r=this.getComments().map(e=>e.deleteAsync());return Promise.all(r).then(()=>!0)}addCommentAsync(t){return this.addComment(t)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}p.FRange.extend(x);class D extends p.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(h.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(t=>this._injector.createInstance(a.FThreadComment,t.root))}clearComments(){const r=this.getComments().map(e=>e.deleteAsync());return Promise.all(r).then(()=>!0)}onThreadCommentChange(t){return s.toDisposable(this._threadCommentModel.commentUpdate$.pipe(y.filter(r=>r.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return s.toDisposable(this._commandService.beforeCommandExecuted((r,e)=>{const n=r.params;if(r.id===h.AddCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(t(n,e)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return s.toDisposable(this._commandService.beforeCommandExecuted((r,e)=>{const n=r.params;if(r.id===h.UpdateCommentCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(t(n,e)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return s.toDisposable(this._commandService.beforeCommandExecuted((r,e)=>{const n=r.params;if(r.id===h.DeleteCommentCommand.id||r.id===h.DeleteCommentTreeCommand.id){if(n.unitId!==this._workbook.getUnitId())return;if(t(n,e)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}p.FWorkbook.extend(D);class j extends p.FWorksheet{getComments(){return this._injector.get(I.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(a.FThreadComment,e))}clearComments(){const r=this.getComments().map(e=>e.deleteAsync());return Promise.all(r).then(()=>!0)}onCommented(t){return this._injector.get(s.ICommandService).onCommandExecuted(e=>{if(e.id===h.AddCommentCommand.id){const n=e.params;t(n)}})}getCommentById(t){const e=this._injector.get(I.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);if(e)return this._injector.createInstance(a.FThreadComment,e)}}p.FWorksheet.extend(j);const _={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDelete:"BeforeCommentDelete",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class F extends b.FEventName{get CommentAdded(){return _.CommentAdded}get BeforeCommentAdd(){return _.BeforeCommentAdd}get CommentUpdated(){return _.CommentUpdated}get BeforeCommentUpdate(){return _.BeforeCommentUpdate}get CommentDeleted(){return _.CommentDeleted}get BeforeCommentDelete(){return _.BeforeCommentDelete}get CommentResolved(){return _.CommentResolved}get BeforeCommentResolve(){return _.BeforeCommentResolve}}b.FEventName.extend(F);class M extends b.FUniver{_initialize(t){const r=t.get(s.ICommandService);this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{var d,c,g,l,v;if(e.id!==h.AddCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{comment:C}=u,m=i.getRange(C.ref).getComment();m&&this.fireEvent(this.Event.CommentAdded,{workbook:o,worksheet:i,row:(g=(c=m.getRange())==null?void 0:c.getRow())!=null?g:0,col:(v=(l=m.getRange())==null?void 0:l.getColumn())!=null?v:0,comment:m})})),this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{var d,c,g,l,v;if(e.id!==h.UpdateCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C}=u.payload,m=i.getCommentById(C);m&&this.fireEvent(this.Event.CommentUpdated,{workbook:o,worksheet:i,row:(g=(c=m.getRange())==null?void 0:c.getRow())!=null?g:0,col:(v=(l=m.getRange())==null?void 0:l.getColumn())!=null?v:0,comment:m})})),this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{var m;if(e.id!==h.DeleteCommentCommand.id&&e.id!==h.DeleteCommentTreeCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(m=this.getActiveWorkbook)==null?void 0:m.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C}=u;this.fireEvent(this.Event.CommentDeleted,{workbook:o,worksheet:i,commentId:C})})),this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{var c,g,l;if(e.id!==h.ResolveCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C,resolved:m}=u,d=i.getComments().find(v=>v.getCommentData().id===C);d&&this.fireEvent(this.Event.CommentResolved,{workbook:o,worksheet:i,row:(g=d.getRange().getRow())!=null?g:0,col:(l=d.getRange().getColumn())!=null?l:0,comment:d,resolved:m})})),this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(e=>{var c,g,l;if(e.id!==h.AddCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{comment:C}=u,m=i.getActiveRange();if(!m)return;const d={workbook:o,worksheet:i,row:(g=m.getRow())!=null?g:0,col:(l=m.getColumn())!=null?l:0,comment:w.create(C)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new s.CanceledError})),this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(e=>{var c,g,l,v,S;if(e.id!==h.UpdateCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C,text:m}=u.payload,d=i.getCommentById(C);if(d){const R={workbook:o,worksheet:i,row:(l=(g=d.getRange())==null?void 0:g.getRow())!=null?l:0,col:(S=(v=d.getRange())==null?void 0:v.getColumn())!=null?S:0,comment:d,newContent:s.RichTextValue.createByBody(m)};if(this.fireEvent(this.Event.BeforeCommentUpdate,R),R.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentDelete,()=>r.beforeCommandExecuted(e=>{var d,c,g,l,v;if(e.id!==h.DeleteCommentCommand.id&&e.id!==h.DeleteCommentTreeCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(d=this.getActiveWorkbook)==null?void 0:d.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C}=u,m=i.getCommentById(C);if(m){const S={workbook:o,worksheet:i,row:(g=(c=m.getRange())==null?void 0:c.getRow())!=null?g:0,col:(v=(l=m.getRange())==null?void 0:l.getColumn())!=null?v:0,comment:m};if(this.fireEvent(this.Event.BeforeCommentDelete,S),S.cancel)throw new s.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(e=>{var c,g,l;if(e.id!==h.ResolveCommentCommand.id)return;const n=e.params;if(!n)return;const o=n.unitId?this.getUniverSheet(n.unitId):(c=this.getActiveWorkbook)==null?void 0:c.call(this);if(!o)return;const i=o.getSheetBySheetId(n.subUnitId||n.sheetId)||o.getActiveSheet();if(!i)return;const u=e.params,{commentId:C,resolved:m}=u,d=i.getComments().find(v=>v.getCommentData().id===C);if(d){const v={workbook:o,worksheet:i,row:(g=d.getRange().getRow())!=null?g:0,col:(l=d.getRange().getColumn())!=null?l:0,comment:d,resolved:m};if(this.fireEvent(this.Event.BeforeCommentResolve,v),v.cancel)throw new s.CanceledError}}))}newTheadComment(t){return new k(t)}}b.FUniver.extend(M),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-thread-comment",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "description": "Univer sheets thread comment base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -51,17 +51,17 @@
51
51
  "rxjs": ">=7.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@univerjs/core": "0.6.1",
55
- "@univerjs/sheets": "0.6.1",
56
- "@univerjs/thread-comment": "0.6.1",
57
- "@univerjs/engine-formula": "0.6.1"
54
+ "@univerjs/core": "0.6.2",
55
+ "@univerjs/sheets": "0.6.2",
56
+ "@univerjs/engine-formula": "0.6.2",
57
+ "@univerjs/thread-comment": "0.6.2"
58
58
  },
59
59
  "devDependencies": {
60
60
  "rxjs": "^7.8.1",
61
61
  "typescript": "^5.7.3",
62
- "vite": "^6.1.1",
63
- "vitest": "^3.0.6",
64
- "@univerjs-infra/shared": "0.6.1"
62
+ "vite": "^6.2.0",
63
+ "vitest": "^3.0.7",
64
+ "@univerjs-infra/shared": "0.6.2"
65
65
  },
66
66
  "scripts": {
67
67
  "test": "vitest run",