| 1 |
- "use strict";var b=Object.defineProperty;var U=(d,e,t)=>e in d?b(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var T=(d,e,t)=>U(d,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),C=require("@univerjs/sheets-thread-comment"),h=require("@univerjs/sheets/facade"),m=require("@univerjs/thread-comment"),v=require("@univerjs/engine-formula"),S=require("rxjs");var x=Object.defineProperty,y=Object.getOwnPropertyDescriptor,k=(d,e,t,n)=>{for(var o=n>1?void 0:n?y(e,t):e,i=d.length-1,s;i>=0;i--)(s=d[i])&&(o=(n?s(e,t,o):s(o))||o);return n&&o&&x(e,t,o),o},u=(d,e)=>(t,n)=>e(t,n,d);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 g.create(r.Tools.deepClone(this._comment))}}class g extends p{static create(e){return new g(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}}exports.FThreadComment=class{constructor(e,t,n,o,i,s,c){this._thread=e,this._parent=t,this._injector=n,this._commandService=o,this._univerInstanceService=i,this._threadCommentModel=s,this._userManagerService=c}_getRef(){var n;const e=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return v.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(exports.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(h.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}})}};exports.FThreadComment=k([u(2,r.Inject(r.Injector)),u(3,r.ICommandService),u(4,r.IUniverInstanceService),u(5,r.Inject(C.SheetsThreadCommentModel)),u(6,r.Inject(r.UserManagerService))],exports.FThreadComment);class D extends h.FRange{getComment(){const t=this._injector.get(C.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 s=t.getComment(n,o,i);return s?this._injector.createInstance(exports.FThreadComment,s):null}getComments(){const t=this._injector.get(C.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=[];return r.Range.foreach(this._range,(s,c)=>{const l=t.getByLocation(n,o,s,c);if(l){const I=t.getComment(n,o,l);I&&i.push(this._injector.createInstance(exports.FThreadComment,I))}}),i}addComment(e){var f;const t=this._injector,n=(f=this.getComment())==null?void 0:f.getCommentData(),o=t.get(r.ICommandService),i=t.get(r.UserManagerService),s=this._workbook.getUnitId(),c=this._worksheet.getSheetId(),l=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,I=i.getCurrentUser(),_=e instanceof g?e.build():{text:e};return o.executeCommand(m.AddCommentCommand.id,{unitId:s,subUnitId:c,comment:{text:_.text,dT:_.dT||m.getDT(),attachments:[],id:_.id||r.generateRandomId(),ref:l,personId:_.personId||I.userID,parentId:n==null?void 0:n.id,unitId:s,subUnitId:c,threadId:(n==null?void 0:n.threadId)||r.generateRandomId()}})}clearComment(){var s;const e=this._injector,t=(s=this.getComment())==null?void 0:s.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()}}h.FRange.extend(D);class R extends h.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(exports.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(S.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")}}))}}h.FWorkbook.extend(R);class w extends h.FWorksheet{getComments(){return this._injector.get(C.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(exports.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(C.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(exports.FThreadComment,n)}}h.FWorksheet.extend(w);const a={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class j extends r.FEventName{get CommentAdded(){return a.CommentAdded}get BeforeCommentAdd(){return a.BeforeCommentAdd}get CommentUpdated(){return a.CommentUpdated}get BeforeCommentUpdate(){return a.BeforeCommentUpdate}get CommentDeleted(){return a.CommentDeleted}get BeforeCommentDeleted(){return a.BeforeCommentDeleted}get CommentResolved(){return a.CommentResolved}get BeforeCommentResolve(){return a.BeforeCommentResolve}}r.FEventName.extend(j);
|