@univerjs/sheets-thread-comment 0.5.3-experimental.20250106-e3b7a39 → 0.5.3-experimental.20250107-3e6579c

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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),c=require("@univerjs/sheets-thread-comment"),a=require("@univerjs/sheets/facade"),i=require("@univerjs/thread-comment"),g=require("@univerjs/engine-formula"),l=require("rxjs");var p=Object.defineProperty,b=Object.getOwnPropertyDescriptor,f=(m,t,e,n)=>{for(var o=n>1?void 0:n?b(t,e):t,d=m.length-1,s;d>=0;d--)(s=m[d])&&(o=(n?s(t,e,o):s(o))||o);return n&&o&&p(t,e,o),o},h=(m,t)=>(e,n)=>t(e,n,m);exports.FThreadComment=class{constructor(t,e,n,o,d,s){this._thread=t,this._parent=e,this._injector=n,this._commandService=o,this._univerInstanceService=d,this._threadCommentModel=s}_getRef(){var n;const t=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return g.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...e}=this._thread;return e}getReplies(){var n;const t=this._getRef(),e=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(n=e==null?void 0:e.children)==null?void 0:n.map(o=>this._injector.createInstance(exports.FThreadComment,o))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,r.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const e=t.getSheetBySheetId(this._thread.subUnitId);if(!e)return null;const n=this._getRef();return this._injector.createInstance(a.FRange,t,e,n)}getContent(){return this._thread.text}delete(){return this._commandService.executeCommand(this.getIsRoot()?i.DeleteCommentTreeCommand.id:i.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}async update(t){const e=i.getDT();return await this._commandService.executeCommand(i.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:e}})}resolve(t){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}};exports.FThreadComment=f([h(2,r.Inject(r.Injector)),h(3,r.ICommandService),h(4,r.IUniverInstanceService),h(5,r.Inject(c.SheetsThreadCommentModel))],exports.FThreadComment);class S extends a.FRange{getComment(){const e=this._injector.get(c.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),d=e.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!d)return null;const s=e.getComment(n,o,d);return s?this._injector.createInstance(exports.FThreadComment,s):null}addComment(t){var C;const e=this._injector,n=(C=this.getComment())==null?void 0:C.getCommentData(),o=e.get(r.ICommandService),d=e.get(r.UserManagerService),s=this._workbook.getUnitId(),u=this._worksheet.getSheetId(),_=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,I=d.getCurrentUser();return o.executeCommand(i.AddCommentCommand.id,{unitId:s,subUnitId:u,comment:{text:t,attachments:[],dT:i.getDT(),id:r.Tools.generateRandomId(),ref:_,personId:I.userID,parentId:n==null?void 0:n.id,unitId:s,subUnitId:u,threadId:n==null?void 0:n.threadId}})}clearComment(){var s;const t=this._injector,e=(s=this.getComment())==null?void 0:s.getCommentData(),n=t.get(r.ICommandService),o=this._workbook.getUnitId(),d=this._worksheet.getSheetId();return e?n.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:d,threadId:e.threadId,commentId:e.id}):Promise.resolve(!0)}}a.FRange.extend(S);class T extends a.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(i.ThreadCommentModel)}})}onThreadCommentChange(t){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(l.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return r.toDisposable(this._commandService.beforeCommandExecuted((e,n)=>{const o=e.params;if(e.id===i.DeleteCommentCommand.id||e.id===i.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(t(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}a.FWorkbook.extend(T);class v extends a.FWorksheet{getComments(){return this._injector.get(c.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(exports.FThreadComment,n))}onCommented(t){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===i.AddCommentCommand.id){const o=n.params;t(o)}})}}a.FWorksheet.extend(v);
1
+ "use strict";var b=Object.defineProperty;var v=(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)=>v(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"),U=require("@univerjs/engine-formula"),S=require("rxjs");var x=Object.defineProperty,k=Object.getOwnPropertyDescriptor,y=(d,e,t,n)=>{for(var o=n>1?void 0:n?k(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 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(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=y([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)}}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);