@univerjs/sheets-thread-comment 0.15.3 → 0.15.4
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 +1 -1
- package/lib/es/facade.js +308 -318
- package/lib/facade.js +308 -318
- package/lib/types/facade/f-univer.d.ts +1 -0
- package/lib/umd/facade.js +1 -1
- package/package.json +7 -7
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"),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);
|
|
1
|
+
"use strict";var R=Object.defineProperty;var U=(g,e,n)=>e in g?R(g,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):g[e]=n;var b=(g,e,n)=>U(g,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),v=require("@univerjs/sheets-thread-comment"),I=require("@univerjs/sheets/facade"),a=require("@univerjs/thread-comment"),k=require("@univerjs/engine-formula"),S=require("rxjs"),w=require("@univerjs/core/facade");var E=Object.getOwnPropertyDescriptor,x=(g,e,n,t)=>{for(var o=t>1?void 0:t?E(e,n):e,m=g.length-1,r;m>=0;m--)(r=g[m])&&(o=r(o)||o);return o},p=(g,e)=>(n,t)=>e(n,t,g);class T{constructor(e){b(this,"_comment",{id:s.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:s.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new T(e)}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 f.create(s.Tools.deepClone(this._comment))}}class f extends T{static create(e){return new f(e)}setContent(e){return e instanceof s.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,n,t,o,m,r,h){this._thread=e,this._parent=n,this._injector=t,this._commandService=o,this._univerInstanceService=m,this._threadCommentModel=r,this._userManagerService=h}_getRef(){var t;const e=((t=this._parent)==null?void 0:t.ref)||this._thread.ref;return k.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...n}=this._thread;return n}getReplies(){var t;const e=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(t=n==null?void 0:n.children)==null?void 0:t.map(o=>this._injector.createInstance(exports.FThreadComment,o))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,s.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const n=e.getSheetBySheetId(this._thread.subUnitId);if(!n)return null;const t=this._getRef();return this._injector.createInstance(I.FRange,e,n,t)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return s.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 n=e instanceof s.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:n,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 n=e.build();return this._commandService.executeCommand(a.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:s.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:n.text,attachments:n.attachments,dT:n.dT||a.getDT(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};exports.FThreadComment=x([p(2,s.Inject(s.Injector)),p(3,s.ICommandService),p(4,s.IUniverInstanceService),p(5,s.Inject(v.SheetsThreadCommentModel)),p(6,s.Inject(s.UserManagerService))],exports.FThreadComment);class y extends I.FRange{getComment(){const n=this._injector.get(v.SheetsThreadCommentModel),t=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),m=n.getByLocation(t,o,this._range.startRow,this._range.startColumn);if(!m)return null;const r=n.getComment(t,o,m);return r?this._injector.createInstance(exports.FThreadComment,r):null}getComments(){const n=this._injector.get(v.SheetsThreadCommentModel),t=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),m=[];return s.Range.foreach(this._range,(r,h)=>{const i=n.getByLocation(t,o,r,h);if(i){const d=n.getComment(t,o,i);d&&m.push(this._injector.createInstance(exports.FThreadComment,d))}}),m}addComment(e){var C;const n=this._injector,t=(C=this.getComment())==null?void 0:C.getCommentData(),o=n.get(s.ICommandService),m=n.get(s.UserManagerService),r=this._workbook.getUnitId(),h=this._worksheet.getSheetId(),i=`${s.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=m.getCurrentUser(),c=e instanceof f?e.build():{text:e};return o.executeCommand(a.AddCommentCommand.id,{unitId:r,subUnitId:h,comment:{text:c.text,dT:c.dT||a.getDT(),attachments:[],id:c.id||s.generateRandomId(),ref:i,personId:c.personId||d.userID,parentId:t==null?void 0:t.id,unitId:r,subUnitId:h,threadId:(t==null?void 0:t.threadId)||s.generateRandomId()}})}clearComment(){var r;const e=this._injector,n=(r=this.getComment())==null?void 0:r.getCommentData(),t=e.get(s.ICommandService),o=this._workbook.getUnitId(),m=this._worksheet.getSheetId();return n?t.executeCommand(a.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:m,threadId:n.threadId,commentId:n.id}):Promise.resolve(!0)}clearComments(){const n=this.getComments().map(t=>t.deleteAsync());return Promise.all(n).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}I.FRange.extend(y);class B extends I.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 n=this.getComments().map(t=>t.deleteAsync());return Promise.all(n).then(()=>!0)}onThreadCommentChange(e){return s.toDisposable(this._threadCommentModel.commentUpdate$.pipe(S.filter(n=>n.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return s.toDisposable(this._commandService.beforeCommandExecuted((n,t)=>{const o=n.params;if(n.id===a.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,t)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return s.toDisposable(this._commandService.beforeCommandExecuted((n,t)=>{const o=n.params;if(n.id===a.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,t)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return s.toDisposable(this._commandService.beforeCommandExecuted((n,t)=>{const o=n.params;if(n.id===a.DeleteCommentCommand.id||n.id===a.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,t)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}I.FWorkbook.extend(B);class D extends I.FWorksheet{getComments(){return this._injector.get(v.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>this._injector.createInstance(exports.FThreadComment,t))}clearComments(){const n=this.getComments().map(t=>t.deleteAsync());return Promise.all(n).then(()=>!0)}onCommented(e){return this._injector.get(s.ICommandService).onCommandExecuted(t=>{if(t.id===a.AddCommentCommand.id){const o=t.params;e(o)}})}getCommentById(e){const t=this._injector.get(v.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(exports.FThreadComment,t)}}I.FWorksheet.extend(D);const _={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDelete:"BeforeCommentDelete",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class A extends w.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}}w.FEventName.extend(A);class M extends w.FUniver{_getTargetSheet(e={}){var o;const n=e.unitId?this.getUniverSheet(e.unitId):(o=this.getActiveWorkbook)==null?void 0:o.call(this);if(!n)return null;const t=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return t?{workbook:n,worksheet:t}:null}_initialize(e){const n=e.get(s.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.AddCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{comment:h}=t.params,i=r.getCommentById(h.id);i&&this.fireEvent(this.Event.CommentAdded,{workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.UpdateCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{payload:h}=t.params,i=r.getCommentById(h.commentId);i&&this.fireEvent(this.Event.CommentUpdated,{workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(t=>{if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h}=t.params;this.fireEvent(this.Event.CommentDeleted,{workbook:m,worksheet:r,commentId:h})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(t=>{var c,C,u,l;if(t.id!==a.ResolveCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h,resolved:i}=t.params,d=r.getCommentById(h);d&&this.fireEvent(this.Event.CommentResolved,{workbook:m,worksheet:r,row:(C=(c=d.getRange())==null?void 0:c.getRow())!=null?C:0,col:(l=(u=d.getRange())==null?void 0:u.getColumn())!=null?l:0,comment:d,resolved:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==a.AddCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{comment:h}=t.params,{range:i}=k.deserializeRangeWithSheet(h.ref),d={workbook:m,worksheet:r,row:i.startRow,col:i.startColumn,comment:T.create(h)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new s.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.UpdateCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{payload:h}=t.params,i=r.getCommentById(h.commentId);if(i){const l={workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i,newContent:s.RichTextValue.createByBody(h.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,l),l.cancel)throw new s.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(t=>{var d,c,C,u;if(t.id!==a.DeleteCommentCommand.id&&t.id!==a.DeleteCommentTreeCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h}=t.params,i=r.getCommentById(h);if(i){const l={workbook:m,worksheet:r,row:(c=(d=i.getRange())==null?void 0:d.getRow())!=null?c:0,col:(u=(C=i.getRange())==null?void 0:C.getColumn())!=null?u:0,comment:i};if(this.fireEvent(this.Event.BeforeCommentDelete,l),l.cancel)throw new s.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(t=>{var c,C;if(t.id!==a.ResolveCommentCommand.id)return;const o=this._getTargetSheet(t.params);if(!o)return;const{workbook:m,worksheet:r}=o,{commentId:h,resolved:i}=t.params,d=r.getCommentById(h);if(d){const u={workbook:m,worksheet:r,row:(c=d.getRange().getRow())!=null?c:0,col:(C=d.getRange().getColumn())!=null?C:0,comment:d,resolved:i};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new s.CanceledError}})))}newTheadComment(e){return new f(e)}}w.FUniver.extend(M);
|