| 1 |
- (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.UniverSheetsThreadCommentFacade={},s.UniverCore,s.UniverSheetsThreadComment,s.UniverSheetsFacade,s.UniverThreadComment,s.UniverEngineFormula,s.rxjs))})(this,function(s,r,a,u,m,U,b){"use strict";var w=Object.defineProperty;var A=(s,r,a)=>r in s?w(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a;var T=(s,r,a)=>A(s,typeof r!="symbol"?r+"":r,a);var S=Object.defineProperty,j=Object.getOwnPropertyDescriptor,y=(h,e,t,n)=>{for(var o=n>1?void 0:n?j(e,t):e,i=h.length-1,d;i>=0;i--)(d=h[i])&&(o=(n?d(e,t,o):d(o))||o);return n&&o&&S(e,t,o),o},I=(h,e)=>(t,n)=>e(t,n,h);class p{constructor(e){T(this,"_comment",{id:r.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:r.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new p(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return r.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return l.create(r.Tools.deepClone(this._comment))}}class l extends p{static create(e){return new l(e)}setContent(e){return e instanceof r.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=m.getDT(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}}s.FThreadComment=class{constructor(e,t,n,o,i,d,C){this._thread=e,this._parent=t,this._injector=n,this._commandService=o,this._univerInstanceService=i,this._threadCommentModel=d,this._userManagerService=C}_getRef(){var n;const e=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return U.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...t}=this._thread;return t}getReplies(){var n;const e=this._getRef(),t=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(n=t==null?void 0:t.children)==null?void 0:n.map(o=>this._injector.createInstance(s.FThreadComment,o))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,r.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;const n=this._getRef();return this._injector.createInstance(u.FRange,e,t,n)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return r.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?m.DeleteCommentTreeCommand.id:m.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 t=e instanceof r.RichTextValue?e.getData().body:e,n=m.getDT();return await this._commandService.executeCommand(m.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:n}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(m.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 n;const t=e.build();return this._commandService.executeCommand(m.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:r.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(n=this._parent)==null?void 0:n.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:t.text,attachments:t.attachments,dT:t.dT||m.getDT(),personId:t.personId||this._userManagerService.getCurrentUser().userID}})}},s.FThreadComment=y([I(2,r.Inject(r.Injector)),I(3,r.ICommandService),I(4,r.IUniverInstanceService),I(5,r.Inject(a.SheetsThreadCommentModel)),I(6,r.Inject(r.UserManagerService))],s.FThreadComment);class k extends u.FRange{getComment(){const t=this._injector.get(a.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=t.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!i)return null;const d=t.getComment(n,o,i);return d?this._injector.createInstance(s.FThreadComment,d):null}getComments(){const t=this._injector.get(a.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=[];return r.Range.foreach(this._range,(d,C)=>{const _=t.getByLocation(n,o,d,C);if(_){const g=t.getComment(n,o,_);g&&i.push(this._injector.createInstance(s.FThreadComment,g))}}),i}addComment(e){var v;const t=this._injector,n=(v=this.getComment())==null?void 0:v.getCommentData(),o=t.get(r.ICommandService),i=t.get(r.UserManagerService),d=this._workbook.getUnitId(),C=this._worksheet.getSheetId(),_=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,g=i.getCurrentUser(),f=e instanceof l?e.build():{text:e};return o.executeCommand(m.AddCommentCommand.id,{unitId:d,subUnitId:C,comment:{text:f.text,dT:f.dT||m.getDT(),attachments:[],id:f.id||r.generateRandomId(),ref:_,personId:f.personId||g.userID,parentId:n==null?void 0:n.id,unitId:d,subUnitId:C,threadId:(n==null?void 0:n.threadId)||r.generateRandomId()}})}clearComment(){var d;const e=this._injector,t=(d=this.getComment())==null?void 0:d.getCommentData(),n=e.get(r.ICommandService),o=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return t?n.executeCommand(m.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:i,threadId:t.threadId,commentId:t.id}):Promise.resolve(!0)}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}u.FRange.extend(k);class x extends u.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(m.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(s.FThreadComment,e.root))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onThreadCommentChange(e){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(b.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.DeleteCommentCommand.id||t.id===m.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}u.FWorkbook.extend(x);class D extends u.FWorksheet{getComments(){return this._injector.get(a.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(s.FThreadComment,n))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onCommented(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===m.AddCommentCommand.id){const o=n.params;e(o)}})}getCommentById(e){const n=this._injector.get(a.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(s.FThreadComment,n)}}u.FWorksheet.extend(D);const c={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class R extends r.FEventName{get CommentAdded(){return c.CommentAdded}get BeforeCommentAdd(){return c.BeforeCommentAdd}get CommentUpdated(){return c.CommentUpdated}get BeforeCommentUpdate(){return c.BeforeCommentUpdate}get CommentDeleted(){return c.CommentDeleted}get BeforeCommentDeleted(){return c.BeforeCommentDeleted}get CommentResolved(){return c.CommentResolved}get BeforeCommentResolve(){return c.BeforeCommentResolve}}r.FEventName.extend(R),Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|