@univerjs/sheets-thread-comment 0.18.0 → 0.19.0-insiders.20260403-3e0e122

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
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-thread-comment`),n=require(`@univerjs/sheets/facade`),r=require(`@univerjs/thread-comment`),i=require(`@univerjs/engine-formula`),a=require(`rxjs`),o=require(`@univerjs/core/facade`);function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var p,m=class t{static create(e){return new t(e)}constructor(t){u(this,`_comment`,{id:(0,e.generateRandomId)(),ref:``,threadId:``,dT:``,personId:``,text:e.RichTextBuilder.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),t&&(this._comment=t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return e.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return h.create(e.Tools.deepClone(this._comment))}},h=class t extends m{static create(e){return new t(e)}setContent(t){return t instanceof e.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=(0,r.getDT)(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let g=p=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return(0,i.deserializeRangeWithSheet)(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(p,e))}getRange(){let t=this._univerInstanceService.getUnit(this._thread.unitId,e.UniverInstanceType.UNIVER_SHEET);if(!t)return null;let r=t.getSheetBySheetId(this._thread.subUnitId);if(!r)return null;let i=this._getRef();return this._injector.createInstance(n.FRange,t,r,i)}getContent(){return this._thread.text}getRichText(){let t=this._thread.text;return e.RichTextValue.create({body:t,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?r.DeleteCommentTreeCommand.id:r.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(t){let n=t instanceof e.RichTextValue?t.getData().body:t,i=(0,r.getDT)();return await this._commandService.executeCommand(r.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:i}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(r.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(t){var n;let i=t.build();return this._commandService.executeCommand(r.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:(0,e.generateRandomId)(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((n=this._parent)==null?void 0:n.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:i.text,attachments:i.attachments,dT:i.dT||(0,r.getDT)(),personId:i.personId||this._userManagerService.getCurrentUser().userID}})}};g=p=f([d(2,(0,e.Inject)(e.Injector)),d(3,e.ICommandService),d(4,e.IUniverInstanceService),d(5,(0,e.Inject)(t.SheetsThreadCommentModel)),d(6,(0,e.Inject)(e.UserManagerService))],g);var _=class extends n.FRange{getComment(){let e=this._injector.get(t.SheetsThreadCommentModel),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=e.getByLocation(n,r,this._range.startRow,this._range.startColumn);if(!i)return null;let a=e.getComment(n,r,i);return a?this._injector.createInstance(g,a):null}getComments(){let n=this._injector.get(t.SheetsThreadCommentModel),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=[];return e.Range.foreach(this._range,(e,t)=>{let o=n.getByLocation(r,i,e,t);if(o){let e=n.getComment(r,i,o);e&&a.push(this._injector.createInstance(g,e))}}),a}addComment(t){var n;let i=this._injector,a=(n=this.getComment())==null?void 0:n.getCommentData(),o=i.get(e.ICommandService),s=i.get(e.UserManagerService),c=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),u=`${e.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=s.getCurrentUser(),f=t instanceof h?t.build():{text:t};return o.executeCommand(r.AddCommentCommand.id,{unitId:c,subUnitId:l,comment:{text:f.text,dT:f.dT||(0,r.getDT)(),attachments:[],id:f.id||(0,e.generateRandomId)(),ref:u,personId:f.personId||d.userID,parentId:a==null?void 0:a.id,unitId:c,subUnitId:l,threadId:(a==null?void 0:a.threadId)||(0,e.generateRandomId)()}})}clearComment(){var t;let n=this._injector,i=(t=this.getComment())==null?void 0:t.getCommentData(),a=n.get(e.ICommandService),o=this._workbook.getUnitId(),s=this._worksheet.getSheetId();return i?a.executeCommand(r.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:s,threadId:i.threadId,commentId:i.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};n.FRange.extend(_);var v=class extends n.FWorkbook{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(r.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(g,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(t){return(0,e.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0,a.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.AddCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.UpdateCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.DeleteCommentCommand.id||e.id===r.DeleteCommentTreeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};n.FWorkbook.extend(v);var y=class extends n.FWorksheet{getComments(){return this._injector.get(t.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(g,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(t){return this._injector.get(e.ICommandService).onCommandExecuted(e=>{if(e.id===r.AddCommentCommand.id){let n=e.params;t(n)}})}getCommentById(e){let n=this._injector.get(t.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(g,n)}};n.FWorksheet.extend(y);const b={CommentAdded:`CommentAdded`,BeforeCommentAdd:`BeforeCommentAdd`,CommentUpdated:`CommentUpdated`,BeforeCommentUpdate:`BeforeCommentUpdate`,CommentDeleted:`CommentDeleted`,BeforeCommentDelete:`BeforeCommentDelete`,CommentResolved:`CommentResolved`,BeforeCommentResolve:`BeforeCommentResolve`};var x=class extends o.FEventName{get CommentAdded(){return b.CommentAdded}get BeforeCommentAdd(){return b.BeforeCommentAdd}get CommentUpdated(){return b.CommentUpdated}get BeforeCommentUpdate(){return b.BeforeCommentUpdate}get CommentDeleted(){return b.CommentDeleted}get BeforeCommentDelete(){return b.BeforeCommentDelete}get CommentResolved(){return b.CommentResolved}get BeforeCommentResolve(){return b.BeforeCommentResolve}};o.FEventName.extend(x);var S=class extends o.FUniver{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(t){let n=t.get(e.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{if(e.id!==r.AddCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{comment:a}=e.params,o=i.getCommentById(a.id);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentAdded,{workbook:n,worksheet:i,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{if(e.id!==r.UpdateCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{payload:a}=e.params,o=i.getCommentById(a.commentId);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentUpdated,{workbook:n,worksheet:i,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==r.DeleteCommentCommand.id&&e.id!==r.DeleteCommentTreeCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{commentId:a}=e.params;this.fireEvent(this.Event.CommentDeleted,{workbook:n,worksheet:i,commentId:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{if(e.id!==r.ResolveCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{commentId:a,resolved:o}=e.params,s=i.getCommentById(a);if(s){var c,l,u,d;this.fireEvent(this.Event.CommentResolved,{workbook:n,worksheet:i,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s,resolved:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.AddCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:a,worksheet:o}=n,{comment:s}=t.params,{range:c}=(0,i.deserializeRangeWithSheet)(s.ref),l={workbook:a,worksheet:o,row:c.startRow,col:c.startColumn,comment:m.create(s)};if(this.fireEvent(this.Event.BeforeCommentAdd,l),l.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.UpdateCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:i,worksheet:a}=n,{payload:o}=t.params,s=a.getCommentById(o.commentId);if(s){var c,l,u,d;let t={workbook:i,worksheet:a,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s,newContent:e.RichTextValue.createByBody(o.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,t),t.cancel)throw new e.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.DeleteCommentCommand.id&&t.id!==r.DeleteCommentTreeCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:i,worksheet:a}=n,{commentId:o}=t.params,s=a.getCommentById(o);if(s){var c,l,u,d;let t={workbook:i,worksheet:a,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s};if(this.fireEvent(this.Event.BeforeCommentDelete,t),t.cancel)throw new e.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.ResolveCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:i,worksheet:a}=n,{commentId:o,resolved:s}=t.params,c=a.getCommentById(o);if(c){var l,u;let t={workbook:i,worksheet:a,row:(l=c.getRange().getRow())==null?0:l,col:(u=c.getRange().getColumn())==null?0:u,comment:c,resolved:s};if(this.fireEvent(this.Event.BeforeCommentResolve,t),t.cancel)throw new e.CanceledError}})))}newTheadComment(e){return new h(e)}};o.FUniver.extend(S),Object.defineProperty(exports,`FThreadComment`,{enumerable:!0,get:function(){return g}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-thread-comment`),n=require(`@univerjs/sheets/facade`),r=require(`@univerjs/thread-comment`),i=require(`@univerjs/engine-formula`),a=require(`rxjs`),o=require(`@univerjs/core/facade`);function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){return function(n,r){t(n,r,e)}}function f(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var p,m=class t{static create(e){return new t(e)}constructor(t){u(this,`_comment`,{id:(0,e.generateRandomId)(),ref:``,threadId:``,dT:``,personId:``,text:e.RichTextBuilder.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),t&&(this._comment=t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return e.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return h.create(e.Tools.deepClone(this._comment))}},h=class t extends m{static create(e){return new t(e)}setContent(t){return t instanceof e.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=(0,r.getDT)(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let g=p=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return(0,i.deserializeRangeWithSheet)(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(p,e))}getRange(){let t=this._univerInstanceService.getUnit(this._thread.unitId,e.UniverInstanceType.UNIVER_SHEET);if(!t)return null;let r=t.getSheetBySheetId(this._thread.subUnitId);if(!r)return null;let i=this._getRef();return this._injector.createInstance(n.FRange,t,r,i)}getContent(){return this._thread.text}getRichText(){let t=this._thread.text;return e.RichTextValue.create({body:t,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?r.DeleteCommentTreeCommand.id:r.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(t){let n=t instanceof e.RichTextValue?t.getData().body:t,i=(0,r.getDT)();return await this._commandService.executeCommand(r.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:i}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(r.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(t){var n;let i=t.build();return this._commandService.executeCommand(r.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:(0,e.generateRandomId)(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((n=this._parent)==null?void 0:n.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:i.text,attachments:i.attachments,dT:i.dT||(0,r.getDT)(),personId:i.personId||this._userManagerService.getCurrentUser().userID}})}};g=p=f([d(2,(0,e.Inject)(e.Injector)),d(3,e.ICommandService),d(4,e.IUniverInstanceService),d(5,(0,e.Inject)(t.SheetsThreadCommentModel)),d(6,(0,e.Inject)(e.UserManagerService))],g);var _=class extends n.FRange{getComment(){let e=this._injector.get(t.SheetsThreadCommentModel),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=e.getByLocation(n,r,this._range.startRow,this._range.startColumn);if(!i)return null;let a=e.getComment(n,r,i);return a?this._injector.createInstance(g,a):null}getComments(){let n=this._injector.get(t.SheetsThreadCommentModel),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=[];return e.Range.foreach(this._range,(e,t)=>{let o=n.getByLocation(r,i,e,t);if(o){let e=n.getComment(r,i,o);e&&a.push(this._injector.createInstance(g,e))}}),a}addComment(t){var n;let i=this._injector,a=(n=this.getComment())==null?void 0:n.getCommentData(),o=i.get(e.ICommandService),s=i.get(e.UserManagerService),c=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),u=`${e.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=s.getCurrentUser(),f=t instanceof h?t.build():{text:t};return o.executeCommand(r.AddCommentCommand.id,{unitId:c,subUnitId:l,comment:{text:f.text,dT:f.dT||(0,r.getDT)(),attachments:[],id:f.id||(0,e.generateRandomId)(),ref:u,personId:f.personId||d.userID,parentId:a==null?void 0:a.id,unitId:c,subUnitId:l,threadId:(a==null?void 0:a.threadId)||(0,e.generateRandomId)()}})}clearComment(){var t;let n=this._injector,i=(t=this.getComment())==null?void 0:t.getCommentData(),a=n.get(e.ICommandService),o=this._workbook.getUnitId(),s=this._worksheet.getSheetId();return i?a.executeCommand(r.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:s,threadId:i.threadId,commentId:i.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};n.FRange.extend(_);var v=class extends n.FWorkbook{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(r.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(g,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(t){return(0,e.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0,a.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.AddCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.UpdateCommentCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(t){return(0,e.toDisposable)(this._commandService.beforeCommandExecuted((e,n)=>{let i=e.params;if(e.id===r.DeleteCommentCommand.id||e.id===r.DeleteCommentTreeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};n.FWorkbook.extend(v);var y=class extends n.FWorksheet{getComments(){return this._injector.get(t.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(g,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(t){return this._injector.get(e.ICommandService).onCommandExecuted(e=>{if(e.id===r.AddCommentCommand.id){let n=e.params;t(n)}})}getCommentById(e){let n=this._injector.get(t.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(g,n)}};n.FWorksheet.extend(y);var b=class extends o.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`}};o.FEventName.extend(b);var x=class extends o.FUniver{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(t){let n=t.get(e.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{var t,n,i,a;if(e.id!==r.AddCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{comment:l}=e.params,u=c.getCommentById(l.id);if(!u)return;let d={workbook:s,worksheet:c,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};this.fireEvent(this.Event.CommentAdded,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{var t,n,i,a;if(e.id!==r.UpdateCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{payload:l}=e.params,u=c.getCommentById(l.commentId);if(!u)return;let d={workbook:s,worksheet:c,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};this.fireEvent(this.Event.CommentUpdated,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==r.DeleteCommentCommand.id&&e.id!==r.DeleteCommentTreeCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:i}=t,{commentId:a}=e.params,o={workbook:n,worksheet:i,commentId:a};this.fireEvent(this.Event.CommentDeleted,o)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{var t,n,i,a;if(e.id!==r.ResolveCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l,resolved:u}=e.params,d=c.getCommentById(l);if(!d)return;let f={workbook:s,worksheet:c,row:(t=(n=d.getRange())==null?void 0:n.getRow())==null?0:t,col:(i=(a=d.getRange())==null?void 0:a.getColumn())==null?0:i,comment:d,resolved:u};this.fireEvent(this.Event.CommentResolved,f)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==r.AddCommentCommand.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:a,worksheet:o}=n,{comment:s}=t.params,{range:c}=(0,i.deserializeRangeWithSheet)(s.ref),l={workbook:a,worksheet:o,row:c.startRow,col:c.startColumn,comment:m.create(s)};if(this.fireEvent(this.Event.BeforeCommentAdd,l),l.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(t=>{var n,i,a,o;if(t.id!==r.UpdateCommentCommand.id)return;let s=this._getTargetSheet(t.params);if(!s)return;let{workbook:c,worksheet:l}=s,{payload:u}=t.params,d=l.getCommentById(u.commentId);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(i=d.getRange())==null?void 0:i.getRow())==null?0:n,col:(a=(o=d.getRange())==null?void 0:o.getColumn())==null?0:a,comment:d,newContent:e.RichTextValue.createByBody(u.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,f),f.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(t=>{var n,i,a,o;if(t.id!==r.DeleteCommentCommand.id&&t.id!==r.DeleteCommentTreeCommand.id)return;let s=this._getTargetSheet(t.params);if(!s)return;let{workbook:c,worksheet:l}=s,{commentId:u}=t.params,d=l.getCommentById(u);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(i=d.getRange())==null?void 0:i.getRow())==null?0:n,col:(a=(o=d.getRange())==null?void 0:o.getColumn())==null?0:a,comment:d};if(this.fireEvent(this.Event.BeforeCommentDelete,f),f.cancel)throw new e.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(t=>{var n,i;if(t.id!==r.ResolveCommentCommand.id)return;let a=this._getTargetSheet(t.params);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=t.params,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:(n=u.getRange().getRow())==null?0:n,col:(i=u.getRange().getColumn())==null?0:i,comment:u,resolved:l};if(this.fireEvent(this.Event.BeforeCommentResolve,d),d.cancel)throw new e.CanceledError})))}newTheadComment(e){return new h(e)}};o.FUniver.extend(x),Object.defineProperty(exports,`FThreadComment`,{enumerable:!0,get:function(){return g}});
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-formula`),n=require(`@univerjs/sheets`),r=require(`@univerjs/thread-comment`),i=require(`rxjs`);function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,c(this,`_matrixMap`,new Map),c(this,`_locationMap`,new Map),c(this,`_commentUpdate$`,new i.Subject),c(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(t,n){let r=this._matrixMap.get(t);r||(r=new Map,this._matrixMap.set(t,r));let i=r.get(n);return i||(i=new e.ObjectMatrix,r.set(n,i)),i}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,n,r){let i=(0,t.singleReferenceToGrid)(r.ref),a=r.parentId,{row:o,column:s}=i,c=r.id,{matrix:l,locationMap:u}=this._ensure(e,n);!a&&o>=0&&s>=0&&(this._addCommentToMatrix(l,o,s,c),u.set(c,{row:o,column:s})),a||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:r,type:`add`,isRoot:!a,...i})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(n=>{let{unitId:r,subUnitId:i}=n;try{if(this._univerInstanceService.getUnitType(r)!==e.UniverInstanceType.UNIVER_SHEET)return}catch{}let{matrix:a,locationMap:o}=this._ensure(r,i);switch(n.type){case`add`:this._addComment(n.unitId,n.subUnitId,n.payload);break;case`delete`:{let{isRoot:e,comment:r}=n.payload;if(e){let e=(0,t.singleReferenceToGrid)(r.ref),{row:i,column:o}=e;this._deleteCommentFromMatrix(a,i,o,r.id),this._commentUpdate$.next({...n,...e})}break}case`update`:{let{commentId:e}=n.payload,a=this._threadCommentModel.getComment(r,i,e);if(!a)return;let o=(0,t.singleReferenceToGrid)(a.ref);this._commentUpdate$.next({...n,...o});break}case`updateRef`:{let e=(0,t.singleReferenceToGrid)(n.payload.ref),{commentId:r}=n.payload,i=o.get(r);if(!i)return;let{row:s,column:c}=i;this._deleteCommentFromMatrix(a,s,c,r),o.delete(r),e.row>=0&&e.column>=0&&(this._addCommentToMatrix(a,e.row,e.column,r),o.set(r,{row:e.row,column:e.column})),this._commentUpdate$.next({...n,...e});break}case`resolve`:{let{unitId:e,subUnitId:t,payload:r}=n,{locationMap:i}=this._ensure(e,t),a=i.get(r.commentId);a&&this._commentUpdate$.next({...n,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};d=u([l(0,(0,e.Inject)(r.ThreadCommentModel)),l(1,e.IUniverInstanceService)],d);let f=class extends e.Disposable{constructor(e,n,i,a,o){super(),this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=i,this._selectionManagerService=a,this._commandService=o,c(this,`_disposableMap`,new Map),c(this,`_watcherMap`,new Map),c(this,`_handleRangeChange`,(e,n,i,a,o)=>{let s=i.id,c={startColumn:i.column,endColumn:i.column,startRow:i.row,endRow:i.row};return a?{redos:[{id:r.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:(0,t.serializeRange)(a),commentId:s},silent:o}}],undos:[{id:r.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:(0,t.serializeRange)(c),commentId:s},silent:o}}]}:{redos:[{id:r.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:s}}],undos:[{id:r.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:i,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._disposableMap.set(this._getIdWithUnitId(e,t,i),this._refRangeService.registerRefRange(a,i=>{let o=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,r,s,!1)},e,t))}_watch(t,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watcherMap.set(this._getIdWithUnitId(t,n,i),this._refRangeService.watchRange(t,n,a,(i,a)=>{let{redos:o}=this._handleRangeChange(t,n,r,a,!0);(0,e.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let n of e)for(let e of n.threads){let{unitId:n,subUnitId:r,root:i}=e,a=(0,t.singleReferenceToGrid)(i.ref),o={...i,...a};this._register(n,r,o),this._watch(n,r,o)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe((0,e.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};f=u([l(0,(0,e.Inject)(n.RefRangeService)),l(1,(0,e.Inject)(d)),l(2,(0,e.Inject)(r.ThreadCommentModel)),l(3,(0,e.Inject)(n.SheetsSelectionsService)),l(4,e.ICommandService)],f);var p=`@univerjs/sheets-thread-comment`,m=`0.18.0`;const h={};let g=class extends e.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===n.RemoveSheetCommand.id){var i;let n=t.params,a=n.unitId||this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=n.subUnitId||((i=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:i.getSheetId());if(!a||!o)return{redos:[],undos:[]};let s=this._threadCommentModel.ensureMap(a,o),c=Array.from(s.values()).filter(e=>!e.parentId),l=this._threadCommentDataSourceService.syncUpdateMutationToColla,u=[],d=[];return c.forEach(({children:e,...t})=>{u.push({id:r.DeleteCommentMutation.id,params:{unitId:a,subUnitId:o,commentId:t.id}}),d.push({id:r.AddCommentMutation.id,params:{unitId:a,subUnitId:o,comment:{...t,children:l?e:void 0},sync:!l}})}),{redos:u,undos:d}}else if(t.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:i,targetSubUnitId:a}=t.params;if(!n||!i||!a)return{redos:[],undos:[]};let o=this._threadCommentModel.ensureMap(n,i),s=Array.from(o.values()).map(t=>({...t,subUnitId:a,id:(0,e.generateRandomId)(),threadId:(0,e.generateRandomId)()})).filter(e=>!e.parentId),c=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return s.forEach(({children:e,...t})=>{l.push({id:r.AddCommentMutation.id,params:{unitId:n,subUnitId:a,comment:{...t,children:c?e:void 0},sync:!c}}),u.push({id:r.DeleteCommentMutation.id,params:{unitId:n,subUnitId:a,commentId:t.id}})}),{redos:l,undos:u}}return{redos:[],undos:[]}}}))}};g=u([l(0,e.IUniverInstanceService),l(1,(0,e.Inject)(n.SheetInterceptorService)),l(2,(0,e.Inject)(r.ThreadCommentModel)),l(3,r.IThreadCommentDataSourceService)],g);let _=class extends e.Plugin{constructor(e=h,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[d],[f],[g]].forEach(e=>{this._injector.add(e)}),(0,e.touchDependencies)(this._injector,[[f],[g]])}};c(_,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),c(_,`packageName`,p),c(_,`version`,m),c(_,`type`,e.UniverInstanceType.UNIVER_SHEET),_=u([(0,e.DependentOn)(r.UniverThreadCommentPlugin),l(1,(0,e.Inject)(e.Injector)),l(2,(0,e.Inject)(e.ICommandService))],_),Object.defineProperty(exports,`SheetsThreadCommentModel`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`SheetsThreadCommentRefRangeController`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`UniverSheetsThreadCommentPlugin`,{enumerable:!0,get:function(){return _}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-formula`),n=require(`@univerjs/sheets`),r=require(`@univerjs/thread-comment`),i=require(`rxjs`);function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,c(this,`_matrixMap`,new Map),c(this,`_locationMap`,new Map),c(this,`_commentUpdate$`,new i.Subject),c(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(t,n){let r=this._matrixMap.get(t);r||(r=new Map,this._matrixMap.set(t,r));let i=r.get(n);return i||(i=new e.ObjectMatrix,r.set(n,i)),i}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,n,r){let i=(0,t.singleReferenceToGrid)(r.ref),a=r.parentId,{row:o,column:s}=i,c=r.id,{matrix:l,locationMap:u}=this._ensure(e,n);!a&&o>=0&&s>=0&&(this._addCommentToMatrix(l,o,s,c),u.set(c,{row:o,column:s})),a||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:r,type:`add`,isRoot:!a,...i})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(n=>{let{unitId:r,subUnitId:i}=n;try{if(this._univerInstanceService.getUnitType(r)!==e.UniverInstanceType.UNIVER_SHEET)return}catch{}let{matrix:a,locationMap:o}=this._ensure(r,i);switch(n.type){case`add`:this._addComment(n.unitId,n.subUnitId,n.payload);break;case`delete`:{let{isRoot:e,comment:r}=n.payload;if(e){let e=(0,t.singleReferenceToGrid)(r.ref),{row:i,column:o}=e;this._deleteCommentFromMatrix(a,i,o,r.id),this._commentUpdate$.next({...n,...e})}break}case`update`:{let{commentId:e}=n.payload,a=this._threadCommentModel.getComment(r,i,e);if(!a)return;let o=(0,t.singleReferenceToGrid)(a.ref);this._commentUpdate$.next({...n,...o});break}case`updateRef`:{let e=(0,t.singleReferenceToGrid)(n.payload.ref),{commentId:r}=n.payload,i=o.get(r);if(!i)return;let{row:s,column:c}=i;this._deleteCommentFromMatrix(a,s,c,r),o.delete(r),e.row>=0&&e.column>=0&&(this._addCommentToMatrix(a,e.row,e.column,r),o.set(r,{row:e.row,column:e.column})),this._commentUpdate$.next({...n,...e});break}case`resolve`:{let{unitId:e,subUnitId:t,payload:r}=n,{locationMap:i}=this._ensure(e,t),a=i.get(r.commentId);a&&this._commentUpdate$.next({...n,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};d=u([l(0,(0,e.Inject)(r.ThreadCommentModel)),l(1,e.IUniverInstanceService)],d);let f=class extends e.Disposable{constructor(e,n,i,a,o){super(),this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=i,this._selectionManagerService=a,this._commandService=o,c(this,`_disposableMap`,new Map),c(this,`_watcherMap`,new Map),c(this,`_handleRangeChange`,(e,n,i,a,o)=>{let s=i.id,c={startColumn:i.column,endColumn:i.column,startRow:i.row,endRow:i.row};return a?{redos:[{id:r.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:(0,t.serializeRange)(a),commentId:s},silent:o}}],undos:[{id:r.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:(0,t.serializeRange)(c),commentId:s},silent:o}}]}:{redos:[{id:r.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:s}}],undos:[{id:r.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:i,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._disposableMap.set(this._getIdWithUnitId(e,t,i),this._refRangeService.registerRefRange(a,i=>{let o=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,r,s,!1)},e,t))}_watch(t,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watcherMap.set(this._getIdWithUnitId(t,n,i),this._refRangeService.watchRange(t,n,a,(i,a)=>{let{redos:o}=this._handleRangeChange(t,n,r,a,!0);(0,e.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let n of e)for(let e of n.threads){let{unitId:n,subUnitId:r,root:i}=e,a=(0,t.singleReferenceToGrid)(i.ref),o={...i,...a};this._register(n,r,o),this._watch(n,r,o)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe((0,e.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};f=u([l(0,(0,e.Inject)(n.RefRangeService)),l(1,(0,e.Inject)(d)),l(2,(0,e.Inject)(r.ThreadCommentModel)),l(3,(0,e.Inject)(n.SheetsSelectionsService)),l(4,e.ICommandService)],f);var p=`@univerjs/sheets-thread-comment`,m=`0.19.0-insiders.20260403-3e0e122`;const h={};let g=class extends e.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===n.RemoveSheetCommand.id){var i;let n=t.params,a=n.unitId||this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=n.subUnitId||((i=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:i.getSheetId());if(!a||!o)return{redos:[],undos:[]};let s=this._threadCommentModel.ensureMap(a,o),c=Array.from(s.values()).filter(e=>!e.parentId),l=this._threadCommentDataSourceService.syncUpdateMutationToColla,u=[],d=[];return c.forEach(({children:e,...t})=>{u.push({id:r.DeleteCommentMutation.id,params:{unitId:a,subUnitId:o,commentId:t.id}}),d.push({id:r.AddCommentMutation.id,params:{unitId:a,subUnitId:o,comment:{...t,children:l?e:void 0},sync:!l}})}),{redos:u,undos:d}}else if(t.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:i,targetSubUnitId:a}=t.params;if(!n||!i||!a)return{redos:[],undos:[]};let o=this._threadCommentModel.ensureMap(n,i),s=Array.from(o.values()).map(t=>({...t,subUnitId:a,id:(0,e.generateRandomId)(),threadId:(0,e.generateRandomId)()})).filter(e=>!e.parentId),c=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return s.forEach(({children:e,...t})=>{l.push({id:r.AddCommentMutation.id,params:{unitId:n,subUnitId:a,comment:{...t,children:c?e:void 0},sync:!c}}),u.push({id:r.DeleteCommentMutation.id,params:{unitId:n,subUnitId:a,commentId:t.id}})}),{redos:l,undos:u}}return{redos:[],undos:[]}}}))}};g=u([l(0,e.IUniverInstanceService),l(1,(0,e.Inject)(n.SheetInterceptorService)),l(2,(0,e.Inject)(r.ThreadCommentModel)),l(3,r.IThreadCommentDataSourceService)],g);let _=class extends e.Plugin{constructor(e=h,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[d],[f],[g]].forEach(e=>{this._injector.add(e)}),(0,e.touchDependencies)(this._injector,[[f],[g]])}};c(_,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),c(_,`packageName`,p),c(_,`version`,m),c(_,`type`,e.UniverInstanceType.UNIVER_SHEET),_=u([(0,e.DependentOn)(r.UniverThreadCommentPlugin),l(1,(0,e.Inject)(e.Injector)),l(2,(0,e.Inject)(e.ICommandService))],_),Object.defineProperty(exports,`SheetsThreadCommentModel`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`SheetsThreadCommentRefRangeController`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`UniverSheetsThreadCommentPlugin`,{enumerable:!0,get:function(){return _}});
package/lib/es/facade.js CHANGED
@@ -1 +1 @@
1
- import{CanceledError as e,ICommandService as t,IUniverInstanceService as n,Inject as r,Injector as i,Range as a,RichTextBuilder as o,RichTextValue as s,Tools as c,UniverInstanceType as l,UserManagerService as u,generateRandomId as d,toDisposable as f}from"@univerjs/core";import{SheetsThreadCommentModel as p}from"@univerjs/sheets-thread-comment";import{FRange as m,FWorkbook as h,FWorksheet as g}from"@univerjs/sheets/facade";import{AddCommentCommand as _,DeleteCommentCommand as v,DeleteCommentTreeCommand as y,ResolveCommentCommand as b,ThreadCommentModel as x,UpdateCommentCommand as S,getDT as C}from"@univerjs/thread-comment";import{deserializeRangeWithSheet as w}from"@univerjs/engine-formula";import{filter as T}from"rxjs";import{FEventName as E,FUniver as D}from"@univerjs/core/facade";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var P,F=class e{static create(t){return new e(t)}constructor(e){j(this,`_comment`,{id:d(),ref:``,threadId:``,dT:``,personId:``,text:o.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return I.create(c.deepClone(this._comment))}},I=class e extends F{static create(t){return new e(t)}setContent(e){return e instanceof s?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=C(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let L=P=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return w(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(P,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,l.UNIVER_SHEET);if(!e)return null;let t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;let n=this._getRef();return this._injector.createInstance(m,e,t,n)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return s.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?y.id:v.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){let t=e instanceof s?e.getData().body:e,n=C();return await this._commandService.executeCommand(S.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(b.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var t;let n=e.build();return this._commandService.executeCommand(_.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:d(),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||C(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};L=P=N([M(2,r(i)),M(3,t),M(4,n),M(5,r(p)),M(6,r(u))],L);var R=class extends m{getComment(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=e.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;let i=e.getComment(t,n,r);return i?this._injector.createInstance(L,i):null}getComments(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return a.foreach(this._range,(i,a)=>{let o=e.getByLocation(t,n,i,a);if(o){let i=e.getComment(t,n,o);i&&r.push(this._injector.createInstance(L,i))}}),r}addComment(e){var n;let r=this._injector,i=(n=this.getComment())==null?void 0:n.getCommentData(),a=r.get(t),o=r.get(u),s=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),f=`${c.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,p=o.getCurrentUser(),m=e instanceof I?e.build():{text:e};return a.executeCommand(_.id,{unitId:s,subUnitId:l,comment:{text:m.text,dT:m.dT||C(),attachments:[],id:m.id||d(),ref:f,personId:m.personId||p.userID,parentId:i==null?void 0:i.id,unitId:s,subUnitId:l,threadId:(i==null?void 0:i.threadId)||d()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),i=n.get(t),a=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?i.executeCommand(y.id,{unitId:a,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};m.extend(R);var z=class extends h{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(x)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(L,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return f(this._threadCommentModel.commentUpdate$.pipe(T(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===_.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===S.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===v.id||t.id===y.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};h.extend(z);var B=class extends g{getComments(){return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(L,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t).onCommandExecuted(t=>{if(t.id===_.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(p).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(L,t)}};g.extend(B);const V={CommentAdded:`CommentAdded`,BeforeCommentAdd:`BeforeCommentAdd`,CommentUpdated:`CommentUpdated`,BeforeCommentUpdate:`BeforeCommentUpdate`,CommentDeleted:`CommentDeleted`,BeforeCommentDelete:`BeforeCommentDelete`,CommentResolved:`CommentResolved`,BeforeCommentResolve:`BeforeCommentResolve`};var H=class extends E{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}};E.extend(H);var U=class extends D{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(n){let r=n.get(t);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{if(e.id!==_.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{comment:i}=e.params,a=r.getCommentById(i.id);if(a){var o,s,c,l;this.fireEvent(this.Event.CommentAdded,{workbook:n,worksheet:r,row:(o=(s=a.getRange())==null?void 0:s.getRow())==null?0:o,col:(c=(l=a.getRange())==null?void 0:l.getColumn())==null?0:c,comment:a})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{if(e.id!==S.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{payload:i}=e.params,a=r.getCommentById(i.commentId);if(a){var o,s,c,l;this.fireEvent(this.Event.CommentUpdated,{workbook:n,worksheet:r,row:(o=(s=a.getRange())==null?void 0:s.getRow())==null?0:o,col:(c=(l=a.getRange())==null?void 0:l.getColumn())==null?0:c,comment:a})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{if(e.id!==v.id&&e.id!==y.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i}=e.params;this.fireEvent(this.Event.CommentDeleted,{workbook:n,worksheet:r,commentId:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{if(e.id!==b.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i,resolved:a}=e.params,o=r.getCommentById(i);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentResolved,{workbook:n,worksheet:r,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o,resolved:a})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(t=>{if(t.id!==_.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{comment:a}=t.params,{range:o}=w(a.ref),s={workbook:r,worksheet:i,row:o.startRow,col:o.startColumn,comment:F.create(a)};if(this.fireEvent(this.Event.BeforeCommentAdd,s),s.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(t=>{if(t.id!==S.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{payload:a}=t.params,o=i.getCommentById(a.commentId);if(o){var c,l,u,d;let t={workbook:r,worksheet:i,row:(c=(l=o.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=o.getRange())==null?void 0:d.getColumn())==null?0:u,comment:o,newContent:s.createByBody(a.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,t),t.cancel)throw new e}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>r.beforeCommandExecuted(t=>{if(t.id!==v.id&&t.id!==y.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{commentId:a}=t.params,o=i.getCommentById(a);if(o){var s,c,l,u;let t={workbook:r,worksheet:i,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o};if(this.fireEvent(this.Event.BeforeCommentDelete,t),t.cancel)throw new e}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(t=>{if(t.id!==b.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{commentId:a,resolved:o}=t.params,s=i.getCommentById(a);if(s){var c,l;let t={workbook:r,worksheet:i,row:(c=s.getRange().getRow())==null?0:c,col:(l=s.getRange().getColumn())==null?0:l,comment:s,resolved:o};if(this.fireEvent(this.Event.BeforeCommentResolve,t),t.cancel)throw new e}})))}newTheadComment(e){return new I(e)}};D.extend(U);export{L as FThreadComment};
1
+ import{CanceledError as e,ICommandService as t,IUniverInstanceService as n,Inject as r,Injector as i,Range as a,RichTextBuilder as o,RichTextValue as s,Tools as c,UniverInstanceType as l,UserManagerService as u,generateRandomId as d,toDisposable as f}from"@univerjs/core";import{SheetsThreadCommentModel as p}from"@univerjs/sheets-thread-comment";import{FRange as m,FWorkbook as h,FWorksheet as g}from"@univerjs/sheets/facade";import{AddCommentCommand as _,DeleteCommentCommand as v,DeleteCommentTreeCommand as y,ResolveCommentCommand as b,ThreadCommentModel as x,UpdateCommentCommand as S,getDT as C}from"@univerjs/thread-comment";import{deserializeRangeWithSheet as w}from"@univerjs/engine-formula";import{filter as T}from"rxjs";import{FEventName as E,FUniver as D}from"@univerjs/core/facade";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var P,F=class e{static create(t){return new e(t)}constructor(e){j(this,`_comment`,{id:d(),ref:``,threadId:``,dT:``,personId:``,text:o.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return I.create(c.deepClone(this._comment))}},I=class e extends F{static create(t){return new e(t)}setContent(e){return e instanceof s?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=C(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let L=P=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return w(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(P,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,l.UNIVER_SHEET);if(!e)return null;let t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;let n=this._getRef();return this._injector.createInstance(m,e,t,n)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return s.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?y.id:v.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){let t=e instanceof s?e.getData().body:e,n=C();return await this._commandService.executeCommand(S.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(b.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var t;let n=e.build();return this._commandService.executeCommand(_.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:d(),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||C(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};L=P=N([M(2,r(i)),M(3,t),M(4,n),M(5,r(p)),M(6,r(u))],L);var R=class extends m{getComment(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=e.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;let i=e.getComment(t,n,r);return i?this._injector.createInstance(L,i):null}getComments(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return a.foreach(this._range,(i,a)=>{let o=e.getByLocation(t,n,i,a);if(o){let i=e.getComment(t,n,o);i&&r.push(this._injector.createInstance(L,i))}}),r}addComment(e){var n;let r=this._injector,i=(n=this.getComment())==null?void 0:n.getCommentData(),a=r.get(t),o=r.get(u),s=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),f=`${c.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,p=o.getCurrentUser(),m=e instanceof I?e.build():{text:e};return a.executeCommand(_.id,{unitId:s,subUnitId:l,comment:{text:m.text,dT:m.dT||C(),attachments:[],id:m.id||d(),ref:f,personId:m.personId||p.userID,parentId:i==null?void 0:i.id,unitId:s,subUnitId:l,threadId:(i==null?void 0:i.threadId)||d()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),i=n.get(t),a=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?i.executeCommand(y.id,{unitId:a,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};m.extend(R);var z=class extends h{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(x)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(L,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return f(this._threadCommentModel.commentUpdate$.pipe(T(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===_.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===S.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===v.id||t.id===y.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};h.extend(z);var B=class extends g{getComments(){return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(L,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t).onCommandExecuted(t=>{if(t.id===_.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(p).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(L,t)}};g.extend(B);var V=class extends E{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`}};E.extend(V);var H=class extends D{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(n){let r=n.get(t);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==_.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{comment:c}=e.params,l=s.getCommentById(c.id);if(!l)return;let u={workbook:o,worksheet:s,row:(t=(n=l.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=l.getRange())==null?void 0:i.getColumn())==null?0:r,comment:l};this.fireEvent(this.Event.CommentAdded,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==S.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{payload:c}=e.params,l=s.getCommentById(c.commentId);if(!l)return;let u={workbook:o,worksheet:s,row:(t=(n=l.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=l.getRange())==null?void 0:i.getColumn())==null?0:r,comment:l};this.fireEvent(this.Event.CommentUpdated,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{if(e.id!==v.id&&e.id!==y.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i}=e.params,a={workbook:n,worksheet:r,commentId:i};this.fireEvent(this.Event.CommentDeleted,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==b.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=e.params,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=u.getRange())==null?void 0:i.getColumn())==null?0:r,comment:u,resolved:l};this.fireEvent(this.Event.CommentResolved,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(t=>{if(t.id!==_.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{comment:a}=t.params,{range:o}=w(a.ref),s={workbook:r,worksheet:i,row:o.startRow,col:o.startColumn,comment:F.create(a)};if(this.fireEvent(this.Event.BeforeCommentAdd,s),s.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(t=>{var n,r,i,a;if(t.id!==S.id)return;let o=this._getTargetSheet(t.params);if(!o)return;let{workbook:c,worksheet:l}=o,{payload:u}=t.params,d=l.getCommentById(u.commentId);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(r=d.getRange())==null?void 0:r.getRow())==null?0:n,col:(i=(a=d.getRange())==null?void 0:a.getColumn())==null?0:i,comment:d,newContent:s.createByBody(u.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,f),f.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>r.beforeCommandExecuted(t=>{var n,r,i,a;if(t.id!==v.id&&t.id!==y.id)return;let o=this._getTargetSheet(t.params);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l}=t.params,u=c.getCommentById(l);if(!u)return;let d={workbook:s,worksheet:c,row:(n=(r=u.getRange())==null?void 0:r.getRow())==null?0:n,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};if(this.fireEvent(this.Event.BeforeCommentDelete,d),d.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(t=>{var n,r;if(t.id!==b.id)return;let i=this._getTargetSheet(t.params);if(!i)return;let{workbook:a,worksheet:o}=i,{commentId:s,resolved:c}=t.params,l=o.getCommentById(s);if(!l)return;let u={workbook:a,worksheet:o,row:(n=l.getRange().getRow())==null?0:n,col:(r=l.getRange().getColumn())==null?0:r,comment:l,resolved:c};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new e})))}newTheadComment(e){return new I(e)}};D.extend(H);export{L as FThreadComment};
package/lib/es/index.js CHANGED
@@ -1 +1 @@
1
- import{DependentOn as e,Disposable as t,ICommandService as n,IUniverInstanceService as r,Inject as i,Injector as a,ObjectMatrix as o,Plugin as s,UniverInstanceType as c,generateRandomId as l,sequenceExecuteAsync as u,toDisposable as d,touchDependencies as f}from"@univerjs/core";import{serializeRange as p,singleReferenceToGrid as m}from"@univerjs/engine-formula";import{CopySheetCommand as h,RefRangeService as g,RemoveSheetCommand as _,SheetInterceptorService as v,SheetsSelectionsService as y,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as b}from"@univerjs/sheets";import{AddCommentMutation as x,DeleteCommentMutation as S,IThreadCommentDataSourceService as C,ThreadCommentModel as w,UniverThreadCommentPlugin as T,UpdateCommentRefMutation as E}from"@univerjs/thread-comment";import{Subject as D}from"rxjs";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let P=class extends t{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,j(this,`_matrixMap`,new Map),j(this,`_locationMap`,new Map),j(this,`_commentUpdate$`,new D),j(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,t){let n=this._matrixMap.get(e);n||(n=new Map,this._matrixMap.set(e,n));let r=n.get(t);return r||(r=new o,n.set(t,r)),r}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,n){let r=m(n.ref),i=n.parentId,{row:a,column:o}=r,s=n.id,{matrix:c,locationMap:l}=this._ensure(e,t);!i&&a>=0&&o>=0&&(this._addCommentToMatrix(c,a,o,s),l.set(s,{row:a,column:o})),i||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`,isRoot:!i,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==c.UNIVER_SHEET)return}catch{}let{matrix:r,locationMap:i}=this._ensure(t,n);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:n}=e.payload;if(t){let t=m(n.ref),{row:i,column:a}=t;this._deleteCommentFromMatrix(r,i,a,n.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:r}=e.payload,i=this._threadCommentModel.getComment(t,n,r);if(!i)return;let a=m(i.ref);this._commentUpdate$.next({...e,...a});break}case`updateRef`:{let t=m(e.payload.ref),{commentId:n}=e.payload,a=i.get(n);if(!a)return;let{row:o,column:s}=a;this._deleteCommentFromMatrix(r,o,s,n),i.delete(n),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(r,t.row,t.column,n),i.set(n,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};P=N([M(0,i(w)),M(1,r)],P);let F=class extends t{constructor(e,t,n,r,i){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=n,this._selectionManagerService=r,this._commandService=i,j(this,`_disposableMap`,new Map),j(this,`_watcherMap`,new Map),j(this,`_handleRangeChange`,(e,t,n,r,i)=>{let a=n.id,o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(r),commentId:a},silent:i}}],undos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(o),commentId:a},silent:i}}]}:{redos:[{id:S.id,params:{unitId:e,subUnitId:t,commentId:a}}],undos:[{id:x.id,params:{unitId:e,subUnitId:t,comment:n,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.registerRefRange(i,r=>{let a=b(i,r,{selectionManagerService:this._selectionManagerService}),o=Array.isArray(a)?a[0]:a;return o&&o.startColumn===i.startColumn&&o.startRow===i.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,o,!1)},e,t))}_watch(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watcherMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.watchRange(e,t,i,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,i,!0);u(a,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e,i=m(r.ref),a={...r,...i};this._register(t,n,a),this._watch(t,n,a)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe(d(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};F=N([M(0,i(g)),M(1,i(P)),M(2,i(w)),M(3,i(y)),M(4,n)],F);var I=`@univerjs/sheets-thread-comment`,L=`0.18.0`;const R={};let z=class extends t{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===_.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._threadCommentModel.ensureMap(r,i),o=Array.from(a.values()).filter(e=>!e.parentId),s=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return o.forEach(({children:e,...t})=>{l.push({id:S.id,params:{unitId:r,subUnitId:i,commentId:t.id}}),u.push({id:x.id,params:{unitId:r,subUnitId:i,comment:{...t,children:s?e:void 0},sync:!s}})}),{redos:l,undos:u}}else if(e.id===h.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._threadCommentModel.ensureMap(t,n),a=Array.from(i.values()).map(e=>({...e,subUnitId:r,id:l(),threadId:l()})).filter(e=>!e.parentId),o=this._threadCommentDataSourceService.syncUpdateMutationToColla,s=[],c=[];return a.forEach(({children:e,...n})=>{s.push({id:x.id,params:{unitId:t,subUnitId:r,comment:{...n,children:o?e:void 0},sync:!o}}),c.push({id:S.id,params:{unitId:t,subUnitId:r,commentId:n.id}})}),{redos:s,undos:c}}return{redos:[],undos:[]}}}))}};z=N([M(0,r),M(1,i(v)),M(2,i(w)),M(3,C)],z);let B=class extends s{constructor(e=R,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[P],[F],[z]].forEach(e=>{this._injector.add(e)}),f(this._injector,[[F],[z]])}};j(B,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),j(B,`packageName`,I),j(B,`version`,L),j(B,`type`,c.UNIVER_SHEET),B=N([e(T),M(1,i(a)),M(2,i(n))],B);export{P as SheetsThreadCommentModel,F as SheetsThreadCommentRefRangeController,B as UniverSheetsThreadCommentPlugin};
1
+ import{DependentOn as e,Disposable as t,ICommandService as n,IUniverInstanceService as r,Inject as i,Injector as a,ObjectMatrix as o,Plugin as s,UniverInstanceType as c,generateRandomId as l,sequenceExecuteAsync as u,toDisposable as d,touchDependencies as f}from"@univerjs/core";import{serializeRange as p,singleReferenceToGrid as m}from"@univerjs/engine-formula";import{CopySheetCommand as h,RefRangeService as g,RemoveSheetCommand as _,SheetInterceptorService as v,SheetsSelectionsService as y,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as b}from"@univerjs/sheets";import{AddCommentMutation as x,DeleteCommentMutation as S,IThreadCommentDataSourceService as C,ThreadCommentModel as w,UniverThreadCommentPlugin as T,UpdateCommentRefMutation as E}from"@univerjs/thread-comment";import{Subject as D}from"rxjs";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let P=class extends t{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,j(this,`_matrixMap`,new Map),j(this,`_locationMap`,new Map),j(this,`_commentUpdate$`,new D),j(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,t){let n=this._matrixMap.get(e);n||(n=new Map,this._matrixMap.set(e,n));let r=n.get(t);return r||(r=new o,n.set(t,r)),r}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,n){let r=m(n.ref),i=n.parentId,{row:a,column:o}=r,s=n.id,{matrix:c,locationMap:l}=this._ensure(e,t);!i&&a>=0&&o>=0&&(this._addCommentToMatrix(c,a,o,s),l.set(s,{row:a,column:o})),i||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`,isRoot:!i,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==c.UNIVER_SHEET)return}catch{}let{matrix:r,locationMap:i}=this._ensure(t,n);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:n}=e.payload;if(t){let t=m(n.ref),{row:i,column:a}=t;this._deleteCommentFromMatrix(r,i,a,n.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:r}=e.payload,i=this._threadCommentModel.getComment(t,n,r);if(!i)return;let a=m(i.ref);this._commentUpdate$.next({...e,...a});break}case`updateRef`:{let t=m(e.payload.ref),{commentId:n}=e.payload,a=i.get(n);if(!a)return;let{row:o,column:s}=a;this._deleteCommentFromMatrix(r,o,s,n),i.delete(n),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(r,t.row,t.column,n),i.set(n,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};P=N([M(0,i(w)),M(1,r)],P);let F=class extends t{constructor(e,t,n,r,i){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=n,this._selectionManagerService=r,this._commandService=i,j(this,`_disposableMap`,new Map),j(this,`_watcherMap`,new Map),j(this,`_handleRangeChange`,(e,t,n,r,i)=>{let a=n.id,o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(r),commentId:a},silent:i}}],undos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(o),commentId:a},silent:i}}]}:{redos:[{id:S.id,params:{unitId:e,subUnitId:t,commentId:a}}],undos:[{id:x.id,params:{unitId:e,subUnitId:t,comment:n,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.registerRefRange(i,r=>{let a=b(i,r,{selectionManagerService:this._selectionManagerService}),o=Array.isArray(a)?a[0]:a;return o&&o.startColumn===i.startColumn&&o.startRow===i.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,o,!1)},e,t))}_watch(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watcherMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.watchRange(e,t,i,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,i,!0);u(a,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e,i=m(r.ref),a={...r,...i};this._register(t,n,a),this._watch(t,n,a)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe(d(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};F=N([M(0,i(g)),M(1,i(P)),M(2,i(w)),M(3,i(y)),M(4,n)],F);var I=`@univerjs/sheets-thread-comment`,L=`0.19.0-insiders.20260403-3e0e122`;const R={};let z=class extends t{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===_.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._threadCommentModel.ensureMap(r,i),o=Array.from(a.values()).filter(e=>!e.parentId),s=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return o.forEach(({children:e,...t})=>{l.push({id:S.id,params:{unitId:r,subUnitId:i,commentId:t.id}}),u.push({id:x.id,params:{unitId:r,subUnitId:i,comment:{...t,children:s?e:void 0},sync:!s}})}),{redos:l,undos:u}}else if(e.id===h.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._threadCommentModel.ensureMap(t,n),a=Array.from(i.values()).map(e=>({...e,subUnitId:r,id:l(),threadId:l()})).filter(e=>!e.parentId),o=this._threadCommentDataSourceService.syncUpdateMutationToColla,s=[],c=[];return a.forEach(({children:e,...n})=>{s.push({id:x.id,params:{unitId:t,subUnitId:r,comment:{...n,children:o?e:void 0},sync:!o}}),c.push({id:S.id,params:{unitId:t,subUnitId:r,commentId:n.id}})}),{redos:s,undos:c}}return{redos:[],undos:[]}}}))}};z=N([M(0,r),M(1,i(v)),M(2,i(w)),M(3,C)],z);let B=class extends s{constructor(e=R,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[P],[F],[z]].forEach(e=>{this._injector.add(e)}),f(this._injector,[[F],[z]])}};j(B,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),j(B,`packageName`,I),j(B,`version`,L),j(B,`type`,c.UNIVER_SHEET),B=N([e(T),M(1,i(a)),M(2,i(n))],B);export{P as SheetsThreadCommentModel,F as SheetsThreadCommentRefRangeController,B as UniverSheetsThreadCommentPlugin};
package/lib/facade.js CHANGED
@@ -1 +1 @@
1
- import{CanceledError as e,ICommandService as t,IUniverInstanceService as n,Inject as r,Injector as i,Range as a,RichTextBuilder as o,RichTextValue as s,Tools as c,UniverInstanceType as l,UserManagerService as u,generateRandomId as d,toDisposable as f}from"@univerjs/core";import{SheetsThreadCommentModel as p}from"@univerjs/sheets-thread-comment";import{FRange as m,FWorkbook as h,FWorksheet as g}from"@univerjs/sheets/facade";import{AddCommentCommand as _,DeleteCommentCommand as v,DeleteCommentTreeCommand as y,ResolveCommentCommand as b,ThreadCommentModel as x,UpdateCommentCommand as S,getDT as C}from"@univerjs/thread-comment";import{deserializeRangeWithSheet as w}from"@univerjs/engine-formula";import{filter as T}from"rxjs";import{FEventName as E,FUniver as D}from"@univerjs/core/facade";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var P,F=class e{static create(t){return new e(t)}constructor(e){j(this,`_comment`,{id:d(),ref:``,threadId:``,dT:``,personId:``,text:o.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return I.create(c.deepClone(this._comment))}},I=class e extends F{static create(t){return new e(t)}setContent(e){return e instanceof s?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=C(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let L=P=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return w(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(P,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,l.UNIVER_SHEET);if(!e)return null;let t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;let n=this._getRef();return this._injector.createInstance(m,e,t,n)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return s.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?y.id:v.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){let t=e instanceof s?e.getData().body:e,n=C();return await this._commandService.executeCommand(S.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(b.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var t;let n=e.build();return this._commandService.executeCommand(_.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:d(),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||C(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};L=P=N([M(2,r(i)),M(3,t),M(4,n),M(5,r(p)),M(6,r(u))],L);var R=class extends m{getComment(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=e.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;let i=e.getComment(t,n,r);return i?this._injector.createInstance(L,i):null}getComments(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return a.foreach(this._range,(i,a)=>{let o=e.getByLocation(t,n,i,a);if(o){let i=e.getComment(t,n,o);i&&r.push(this._injector.createInstance(L,i))}}),r}addComment(e){var n;let r=this._injector,i=(n=this.getComment())==null?void 0:n.getCommentData(),a=r.get(t),o=r.get(u),s=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),f=`${c.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,p=o.getCurrentUser(),m=e instanceof I?e.build():{text:e};return a.executeCommand(_.id,{unitId:s,subUnitId:l,comment:{text:m.text,dT:m.dT||C(),attachments:[],id:m.id||d(),ref:f,personId:m.personId||p.userID,parentId:i==null?void 0:i.id,unitId:s,subUnitId:l,threadId:(i==null?void 0:i.threadId)||d()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),i=n.get(t),a=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?i.executeCommand(y.id,{unitId:a,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};m.extend(R);var z=class extends h{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(x)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(L,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return f(this._threadCommentModel.commentUpdate$.pipe(T(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===_.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===S.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===v.id||t.id===y.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};h.extend(z);var B=class extends g{getComments(){return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(L,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t).onCommandExecuted(t=>{if(t.id===_.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(p).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(L,t)}};g.extend(B);const V={CommentAdded:`CommentAdded`,BeforeCommentAdd:`BeforeCommentAdd`,CommentUpdated:`CommentUpdated`,BeforeCommentUpdate:`BeforeCommentUpdate`,CommentDeleted:`CommentDeleted`,BeforeCommentDelete:`BeforeCommentDelete`,CommentResolved:`CommentResolved`,BeforeCommentResolve:`BeforeCommentResolve`};var H=class extends E{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}};E.extend(H);var U=class extends D{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(n){let r=n.get(t);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{if(e.id!==_.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{comment:i}=e.params,a=r.getCommentById(i.id);if(a){var o,s,c,l;this.fireEvent(this.Event.CommentAdded,{workbook:n,worksheet:r,row:(o=(s=a.getRange())==null?void 0:s.getRow())==null?0:o,col:(c=(l=a.getRange())==null?void 0:l.getColumn())==null?0:c,comment:a})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{if(e.id!==S.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{payload:i}=e.params,a=r.getCommentById(i.commentId);if(a){var o,s,c,l;this.fireEvent(this.Event.CommentUpdated,{workbook:n,worksheet:r,row:(o=(s=a.getRange())==null?void 0:s.getRow())==null?0:o,col:(c=(l=a.getRange())==null?void 0:l.getColumn())==null?0:c,comment:a})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{if(e.id!==v.id&&e.id!==y.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i}=e.params;this.fireEvent(this.Event.CommentDeleted,{workbook:n,worksheet:r,commentId:i})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{if(e.id!==b.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i,resolved:a}=e.params,o=r.getCommentById(i);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentResolved,{workbook:n,worksheet:r,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o,resolved:a})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(t=>{if(t.id!==_.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{comment:a}=t.params,{range:o}=w(a.ref),s={workbook:r,worksheet:i,row:o.startRow,col:o.startColumn,comment:F.create(a)};if(this.fireEvent(this.Event.BeforeCommentAdd,s),s.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(t=>{if(t.id!==S.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{payload:a}=t.params,o=i.getCommentById(a.commentId);if(o){var c,l,u,d;let t={workbook:r,worksheet:i,row:(c=(l=o.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=o.getRange())==null?void 0:d.getColumn())==null?0:u,comment:o,newContent:s.createByBody(a.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,t),t.cancel)throw new e}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>r.beforeCommandExecuted(t=>{if(t.id!==v.id&&t.id!==y.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{commentId:a}=t.params,o=i.getCommentById(a);if(o){var s,c,l,u;let t={workbook:r,worksheet:i,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o};if(this.fireEvent(this.Event.BeforeCommentDelete,t),t.cancel)throw new e}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(t=>{if(t.id!==b.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{commentId:a,resolved:o}=t.params,s=i.getCommentById(a);if(s){var c,l;let t={workbook:r,worksheet:i,row:(c=s.getRange().getRow())==null?0:c,col:(l=s.getRange().getColumn())==null?0:l,comment:s,resolved:o};if(this.fireEvent(this.Event.BeforeCommentResolve,t),t.cancel)throw new e}})))}newTheadComment(e){return new I(e)}};D.extend(U);export{L as FThreadComment};
1
+ import{CanceledError as e,ICommandService as t,IUniverInstanceService as n,Inject as r,Injector as i,Range as a,RichTextBuilder as o,RichTextValue as s,Tools as c,UniverInstanceType as l,UserManagerService as u,generateRandomId as d,toDisposable as f}from"@univerjs/core";import{SheetsThreadCommentModel as p}from"@univerjs/sheets-thread-comment";import{FRange as m,FWorkbook as h,FWorksheet as g}from"@univerjs/sheets/facade";import{AddCommentCommand as _,DeleteCommentCommand as v,DeleteCommentTreeCommand as y,ResolveCommentCommand as b,ThreadCommentModel as x,UpdateCommentCommand as S,getDT as C}from"@univerjs/thread-comment";import{deserializeRangeWithSheet as w}from"@univerjs/engine-formula";import{filter as T}from"rxjs";import{FEventName as E,FUniver as D}from"@univerjs/core/facade";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var P,F=class e{static create(t){return new e(t)}constructor(e){j(this,`_comment`,{id:d(),ref:``,threadId:``,dT:``,personId:``,text:o.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return I.create(c.deepClone(this._comment))}},I=class e extends F{static create(t){return new e(t)}setContent(e){return e instanceof s?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=C(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let L=P=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return w(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(P,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,l.UNIVER_SHEET);if(!e)return null;let t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;let n=this._getRef();return this._injector.createInstance(m,e,t,n)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return s.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?y.id:v.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){let t=e instanceof s?e.getData().body:e,n=C();return await this._commandService.executeCommand(S.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(b.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var t;let n=e.build();return this._commandService.executeCommand(_.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:d(),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||C(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};L=P=N([M(2,r(i)),M(3,t),M(4,n),M(5,r(p)),M(6,r(u))],L);var R=class extends m{getComment(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=e.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;let i=e.getComment(t,n,r);return i?this._injector.createInstance(L,i):null}getComments(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return a.foreach(this._range,(i,a)=>{let o=e.getByLocation(t,n,i,a);if(o){let i=e.getComment(t,n,o);i&&r.push(this._injector.createInstance(L,i))}}),r}addComment(e){var n;let r=this._injector,i=(n=this.getComment())==null?void 0:n.getCommentData(),a=r.get(t),o=r.get(u),s=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),f=`${c.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,p=o.getCurrentUser(),m=e instanceof I?e.build():{text:e};return a.executeCommand(_.id,{unitId:s,subUnitId:l,comment:{text:m.text,dT:m.dT||C(),attachments:[],id:m.id||d(),ref:f,personId:m.personId||p.userID,parentId:i==null?void 0:i.id,unitId:s,subUnitId:l,threadId:(i==null?void 0:i.threadId)||d()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),i=n.get(t),a=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?i.executeCommand(y.id,{unitId:a,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};m.extend(R);var z=class extends h{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(x)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(L,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return f(this._threadCommentModel.commentUpdate$.pipe(T(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===_.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===S.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===v.id||t.id===y.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};h.extend(z);var B=class extends g{getComments(){return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(L,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t).onCommandExecuted(t=>{if(t.id===_.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(p).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(L,t)}};g.extend(B);var V=class extends E{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`}};E.extend(V);var H=class extends D{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(n){let r=n.get(t);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==_.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{comment:c}=e.params,l=s.getCommentById(c.id);if(!l)return;let u={workbook:o,worksheet:s,row:(t=(n=l.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=l.getRange())==null?void 0:i.getColumn())==null?0:r,comment:l};this.fireEvent(this.Event.CommentAdded,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==S.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{payload:c}=e.params,l=s.getCommentById(c.commentId);if(!l)return;let u={workbook:o,worksheet:s,row:(t=(n=l.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=l.getRange())==null?void 0:i.getColumn())==null?0:r,comment:l};this.fireEvent(this.Event.CommentUpdated,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{if(e.id!==v.id&&e.id!==y.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i}=e.params,a={workbook:n,worksheet:r,commentId:i};this.fireEvent(this.Event.CommentDeleted,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==b.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=e.params,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=u.getRange())==null?void 0:i.getColumn())==null?0:r,comment:u,resolved:l};this.fireEvent(this.Event.CommentResolved,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(t=>{if(t.id!==_.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{comment:a}=t.params,{range:o}=w(a.ref),s={workbook:r,worksheet:i,row:o.startRow,col:o.startColumn,comment:F.create(a)};if(this.fireEvent(this.Event.BeforeCommentAdd,s),s.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(t=>{var n,r,i,a;if(t.id!==S.id)return;let o=this._getTargetSheet(t.params);if(!o)return;let{workbook:c,worksheet:l}=o,{payload:u}=t.params,d=l.getCommentById(u.commentId);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(r=d.getRange())==null?void 0:r.getRow())==null?0:n,col:(i=(a=d.getRange())==null?void 0:a.getColumn())==null?0:i,comment:d,newContent:s.createByBody(u.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,f),f.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>r.beforeCommandExecuted(t=>{var n,r,i,a;if(t.id!==v.id&&t.id!==y.id)return;let o=this._getTargetSheet(t.params);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l}=t.params,u=c.getCommentById(l);if(!u)return;let d={workbook:s,worksheet:c,row:(n=(r=u.getRange())==null?void 0:r.getRow())==null?0:n,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};if(this.fireEvent(this.Event.BeforeCommentDelete,d),d.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(t=>{var n,r;if(t.id!==b.id)return;let i=this._getTargetSheet(t.params);if(!i)return;let{workbook:a,worksheet:o}=i,{commentId:s,resolved:c}=t.params,l=o.getCommentById(s);if(!l)return;let u={workbook:a,worksheet:o,row:(n=l.getRange().getRow())==null?0:n,col:(r=l.getRange().getColumn())==null?0:r,comment:l,resolved:c};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new e})))}newTheadComment(e){return new I(e)}};D.extend(H);export{L as FThreadComment};
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{DependentOn as e,Disposable as t,ICommandService as n,IUniverInstanceService as r,Inject as i,Injector as a,ObjectMatrix as o,Plugin as s,UniverInstanceType as c,generateRandomId as l,sequenceExecuteAsync as u,toDisposable as d,touchDependencies as f}from"@univerjs/core";import{serializeRange as p,singleReferenceToGrid as m}from"@univerjs/engine-formula";import{CopySheetCommand as h,RefRangeService as g,RemoveSheetCommand as _,SheetInterceptorService as v,SheetsSelectionsService as y,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as b}from"@univerjs/sheets";import{AddCommentMutation as x,DeleteCommentMutation as S,IThreadCommentDataSourceService as C,ThreadCommentModel as w,UniverThreadCommentPlugin as T,UpdateCommentRefMutation as E}from"@univerjs/thread-comment";import{Subject as D}from"rxjs";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let P=class extends t{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,j(this,`_matrixMap`,new Map),j(this,`_locationMap`,new Map),j(this,`_commentUpdate$`,new D),j(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,t){let n=this._matrixMap.get(e);n||(n=new Map,this._matrixMap.set(e,n));let r=n.get(t);return r||(r=new o,n.set(t,r)),r}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,n){let r=m(n.ref),i=n.parentId,{row:a,column:o}=r,s=n.id,{matrix:c,locationMap:l}=this._ensure(e,t);!i&&a>=0&&o>=0&&(this._addCommentToMatrix(c,a,o,s),l.set(s,{row:a,column:o})),i||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`,isRoot:!i,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==c.UNIVER_SHEET)return}catch{}let{matrix:r,locationMap:i}=this._ensure(t,n);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:n}=e.payload;if(t){let t=m(n.ref),{row:i,column:a}=t;this._deleteCommentFromMatrix(r,i,a,n.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:r}=e.payload,i=this._threadCommentModel.getComment(t,n,r);if(!i)return;let a=m(i.ref);this._commentUpdate$.next({...e,...a});break}case`updateRef`:{let t=m(e.payload.ref),{commentId:n}=e.payload,a=i.get(n);if(!a)return;let{row:o,column:s}=a;this._deleteCommentFromMatrix(r,o,s,n),i.delete(n),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(r,t.row,t.column,n),i.set(n,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};P=N([M(0,i(w)),M(1,r)],P);let F=class extends t{constructor(e,t,n,r,i){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=n,this._selectionManagerService=r,this._commandService=i,j(this,`_disposableMap`,new Map),j(this,`_watcherMap`,new Map),j(this,`_handleRangeChange`,(e,t,n,r,i)=>{let a=n.id,o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(r),commentId:a},silent:i}}],undos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(o),commentId:a},silent:i}}]}:{redos:[{id:S.id,params:{unitId:e,subUnitId:t,commentId:a}}],undos:[{id:x.id,params:{unitId:e,subUnitId:t,comment:n,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.registerRefRange(i,r=>{let a=b(i,r,{selectionManagerService:this._selectionManagerService}),o=Array.isArray(a)?a[0]:a;return o&&o.startColumn===i.startColumn&&o.startRow===i.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,o,!1)},e,t))}_watch(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watcherMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.watchRange(e,t,i,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,i,!0);u(a,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e,i=m(r.ref),a={...r,...i};this._register(t,n,a),this._watch(t,n,a)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe(d(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};F=N([M(0,i(g)),M(1,i(P)),M(2,i(w)),M(3,i(y)),M(4,n)],F);var I=`@univerjs/sheets-thread-comment`,L=`0.18.0`;const R={};let z=class extends t{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===_.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._threadCommentModel.ensureMap(r,i),o=Array.from(a.values()).filter(e=>!e.parentId),s=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return o.forEach(({children:e,...t})=>{l.push({id:S.id,params:{unitId:r,subUnitId:i,commentId:t.id}}),u.push({id:x.id,params:{unitId:r,subUnitId:i,comment:{...t,children:s?e:void 0},sync:!s}})}),{redos:l,undos:u}}else if(e.id===h.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._threadCommentModel.ensureMap(t,n),a=Array.from(i.values()).map(e=>({...e,subUnitId:r,id:l(),threadId:l()})).filter(e=>!e.parentId),o=this._threadCommentDataSourceService.syncUpdateMutationToColla,s=[],c=[];return a.forEach(({children:e,...n})=>{s.push({id:x.id,params:{unitId:t,subUnitId:r,comment:{...n,children:o?e:void 0},sync:!o}}),c.push({id:S.id,params:{unitId:t,subUnitId:r,commentId:n.id}})}),{redos:s,undos:c}}return{redos:[],undos:[]}}}))}};z=N([M(0,r),M(1,i(v)),M(2,i(w)),M(3,C)],z);let B=class extends s{constructor(e=R,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[P],[F],[z]].forEach(e=>{this._injector.add(e)}),f(this._injector,[[F],[z]])}};j(B,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),j(B,`packageName`,I),j(B,`version`,L),j(B,`type`,c.UNIVER_SHEET),B=N([e(T),M(1,i(a)),M(2,i(n))],B);export{P as SheetsThreadCommentModel,F as SheetsThreadCommentRefRangeController,B as UniverSheetsThreadCommentPlugin};
1
+ import{DependentOn as e,Disposable as t,ICommandService as n,IUniverInstanceService as r,Inject as i,Injector as a,ObjectMatrix as o,Plugin as s,UniverInstanceType as c,generateRandomId as l,sequenceExecuteAsync as u,toDisposable as d,touchDependencies as f}from"@univerjs/core";import{serializeRange as p,singleReferenceToGrid as m}from"@univerjs/engine-formula";import{CopySheetCommand as h,RefRangeService as g,RemoveSheetCommand as _,SheetInterceptorService as v,SheetsSelectionsService as y,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as b}from"@univerjs/sheets";import{AddCommentMutation as x,DeleteCommentMutation as S,IThreadCommentDataSourceService as C,ThreadCommentModel as w,UniverThreadCommentPlugin as T,UpdateCommentRefMutation as E}from"@univerjs/thread-comment";import{Subject as D}from"rxjs";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let P=class extends t{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,j(this,`_matrixMap`,new Map),j(this,`_locationMap`,new Map),j(this,`_commentUpdate$`,new D),j(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,t){let n=this._matrixMap.get(e);n||(n=new Map,this._matrixMap.set(e,n));let r=n.get(t);return r||(r=new o,n.set(t,r)),r}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,n){let r=m(n.ref),i=n.parentId,{row:a,column:o}=r,s=n.id,{matrix:c,locationMap:l}=this._ensure(e,t);!i&&a>=0&&o>=0&&(this._addCommentToMatrix(c,a,o,s),l.set(s,{row:a,column:o})),i||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`,isRoot:!i,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;try{if(this._univerInstanceService.getUnitType(t)!==c.UNIVER_SHEET)return}catch{}let{matrix:r,locationMap:i}=this._ensure(t,n);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:n}=e.payload;if(t){let t=m(n.ref),{row:i,column:a}=t;this._deleteCommentFromMatrix(r,i,a,n.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:r}=e.payload,i=this._threadCommentModel.getComment(t,n,r);if(!i)return;let a=m(i.ref);this._commentUpdate$.next({...e,...a});break}case`updateRef`:{let t=m(e.payload.ref),{commentId:n}=e.payload,a=i.get(n);if(!a)return;let{row:o,column:s}=a;this._deleteCommentFromMatrix(r,o,s,n),i.delete(n),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(r,t.row,t.column,n),i.set(n,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};P=N([M(0,i(w)),M(1,r)],P);let F=class extends t{constructor(e,t,n,r,i){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=n,this._selectionManagerService=r,this._commandService=i,j(this,`_disposableMap`,new Map),j(this,`_watcherMap`,new Map),j(this,`_handleRangeChange`,(e,t,n,r,i)=>{let a=n.id,o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(r),commentId:a},silent:i}}],undos:[{id:E.id,params:{unitId:e,subUnitId:t,payload:{ref:p(o),commentId:a},silent:i}}]}:{redos:[{id:S.id,params:{unitId:e,subUnitId:t,commentId:a}}],undos:[{id:x.id,params:{unitId:e,subUnitId:t,comment:n,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.registerRefRange(i,r=>{let a=b(i,r,{selectionManagerService:this._selectionManagerService}),o=Array.isArray(a)?a[0]:a;return o&&o.startColumn===i.startColumn&&o.startRow===i.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,o,!1)},e,t))}_watch(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watcherMap.set(this._getIdWithUnitId(e,t,r),this._refRangeService.watchRange(e,t,i,(r,i)=>{let{redos:a}=this._handleRangeChange(e,t,n,i,!0);u(a,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e,i=m(r.ref),a={...r,...i};this._register(t,n,a),this._watch(t,n,a)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe(d(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};F=N([M(0,i(g)),M(1,i(P)),M(2,i(w)),M(3,i(y)),M(4,n)],F);var I=`@univerjs/sheets-thread-comment`,L=`0.19.0-insiders.20260403-3e0e122`;const R={};let z=class extends t{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===_.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._threadCommentModel.ensureMap(r,i),o=Array.from(a.values()).filter(e=>!e.parentId),s=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return o.forEach(({children:e,...t})=>{l.push({id:S.id,params:{unitId:r,subUnitId:i,commentId:t.id}}),u.push({id:x.id,params:{unitId:r,subUnitId:i,comment:{...t,children:s?e:void 0},sync:!s}})}),{redos:l,undos:u}}else if(e.id===h.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._threadCommentModel.ensureMap(t,n),a=Array.from(i.values()).map(e=>({...e,subUnitId:r,id:l(),threadId:l()})).filter(e=>!e.parentId),o=this._threadCommentDataSourceService.syncUpdateMutationToColla,s=[],c=[];return a.forEach(({children:e,...n})=>{s.push({id:x.id,params:{unitId:t,subUnitId:r,comment:{...n,children:o?e:void 0},sync:!o}}),c.push({id:S.id,params:{unitId:t,subUnitId:r,commentId:n.id}})}),{redos:s,undos:c}}return{redos:[],undos:[]}}}))}};z=N([M(0,r),M(1,i(v)),M(2,i(w)),M(3,C)],z);let B=class extends s{constructor(e=R,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[P],[F],[z]].forEach(e=>{this._injector.add(e)}),f(this._injector,[[F],[z]])}};j(B,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),j(B,`packageName`,I),j(B,`version`,L),j(B,`type`,c.UNIVER_SHEET),B=N([e(T),M(1,i(a)),M(2,i(n))],B);export{P as SheetsThreadCommentModel,F as SheetsThreadCommentRefRangeController,B as UniverSheetsThreadCommentPlugin};
@@ -21,10 +21,10 @@ import { FEventName } from '@univerjs/core/facade';
21
21
  /**
22
22
  * @ignore
23
23
  */
24
- interface ICommentEventMixin {
24
+ interface IFSheetsThreadCommentEventNameMixin {
25
25
  /**
26
26
  * Event fired after comment added
27
- * @see {@link ISheetCommentAddEvent}
27
+ * @see {@link ISheetCommentAddEventParams}
28
28
  * @example
29
29
  * ```ts
30
30
  * const disposable = univerAPI.addEvent(univerAPI.Event.CommentAdded, (params) => {
@@ -38,7 +38,7 @@ interface ICommentEventMixin {
38
38
  readonly CommentAdded: 'CommentAdded';
39
39
  /**
40
40
  * Event fired before comment added
41
- * @see {@link IBeforeSheetCommentAddEvent}
41
+ * @see {@link IBeforeSheetCommentAddEventParams}
42
42
  * @example
43
43
  * ```ts
44
44
  * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeCommentAdd, (params) => {
@@ -55,7 +55,7 @@ interface ICommentEventMixin {
55
55
  readonly BeforeCommentAdd: 'BeforeCommentAdd';
56
56
  /**
57
57
  * Event fired after comment updated
58
- * @see {@link ISheetCommentUpdateEvent}
58
+ * @see {@link ISheetCommentUpdateEventParams}
59
59
  * @example
60
60
  * ```ts
61
61
  * const disposable = univerAPI.addEvent(univerAPI.Event.CommentUpdated, (params) => {
@@ -69,7 +69,7 @@ interface ICommentEventMixin {
69
69
  readonly CommentUpdated: 'CommentUpdated';
70
70
  /**
71
71
  * Event fired before comment update
72
- * @see {@link IBeforeSheetCommentUpdateEvent}
72
+ * @see {@link IBeforeSheetCommentUpdateEventParams}
73
73
  * @example
74
74
  * ```ts
75
75
  * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeCommentUpdate, (params) => {
@@ -86,7 +86,7 @@ interface ICommentEventMixin {
86
86
  readonly BeforeCommentUpdate: 'BeforeCommentUpdate';
87
87
  /**
88
88
  * Event fired after comment deleted
89
- * @see {@link ISheetCommentDeleteEvent}
89
+ * @see {@link ISheetCommentDeleteEventParams}
90
90
  * @example
91
91
  * ```ts
92
92
  * const disposable = univerAPI.addEvent(univerAPI.Event.CommentDeleted, (params) => {
@@ -100,7 +100,7 @@ interface ICommentEventMixin {
100
100
  readonly CommentDeleted: 'CommentDeleted';
101
101
  /**
102
102
  * Event fired before comment delete
103
- * @see {@link IBeforeSheetCommentDeleteEvent}
103
+ * @see {@link IBeforeSheetCommentDeleteEventParams}
104
104
  * @example
105
105
  * ```ts
106
106
  * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeCommentDelete, (params) => {
@@ -117,7 +117,7 @@ interface ICommentEventMixin {
117
117
  readonly BeforeCommentDelete: 'BeforeCommentDelete';
118
118
  /**
119
119
  * Event fired after comment resolve
120
- * @see {@link ISheetCommentResolveEvent}
120
+ * @see {@link ISheetCommentResolveEventParams}
121
121
  * @example
122
122
  * ```ts
123
123
  * const disposable = univerAPI.addEvent(univerAPI.Event.CommentResolved, (params) => {
@@ -131,7 +131,7 @@ interface ICommentEventMixin {
131
131
  readonly CommentResolved: 'CommentResolved';
132
132
  /**
133
133
  * Event fired before comment resolve
134
- * @see {@link ISheetCommentResolveEvent}
134
+ * @see {@link ISheetCommentResolveEventParams}
135
135
  * @example
136
136
  * ```ts
137
137
  * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeCommentResolve, (params) => {
@@ -150,7 +150,7 @@ interface ICommentEventMixin {
150
150
  /**
151
151
  * @ignore
152
152
  */
153
- export declare class FCommentEvent extends FEventName {
153
+ export declare class FSheetsThreadCommentEventNameMixin extends FEventName implements IFSheetsThreadCommentEventNameMixin {
154
154
  get CommentAdded(): 'CommentAdded';
155
155
  get BeforeCommentAdd(): 'BeforeCommentAdd';
156
156
  get CommentUpdated(): 'CommentUpdated';
@@ -162,10 +162,10 @@ export declare class FCommentEvent extends FEventName {
162
162
  }
163
163
  /**
164
164
  * Event interface triggered after a comment is added to a sheet
165
- * @interface ISheetCommentAddEvent
165
+ * @interface ISheetCommentAddEventParams
166
166
  * @augments {IEventBase}
167
167
  */
168
- export interface ISheetCommentAddEvent extends IEventBase {
168
+ export interface ISheetCommentAddEventParams extends IEventBase {
169
169
  /** The workbook instance */
170
170
  workbook: FWorkbook;
171
171
  /** The worksheet where the comment is added */
@@ -179,10 +179,10 @@ export interface ISheetCommentAddEvent extends IEventBase {
179
179
  }
180
180
  /**
181
181
  * Event interface triggered before a comment is added to a sheet
182
- * @interface IBeforeSheetCommentAddEvent
182
+ * @interface IBeforeSheetCommentAddEventParams
183
183
  * @augments {IEventBase}
184
184
  */
185
- export interface IBeforeSheetCommentAddEvent extends IEventBase {
185
+ export interface IBeforeSheetCommentAddEventParams extends IEventBase {
186
186
  /** The workbook instance */
187
187
  workbook: FWorkbook;
188
188
  /** The worksheet where the comment will be added */
@@ -196,10 +196,10 @@ export interface IBeforeSheetCommentAddEvent extends IEventBase {
196
196
  }
197
197
  /**
198
198
  * Event interface triggered after a comment is updated in a sheet
199
- * @interface ISheetCommentUpdateEvent
199
+ * @interface ISheetCommentUpdateEventParams
200
200
  * @augments {IEventBase}
201
201
  */
202
- export interface ISheetCommentUpdateEvent extends IEventBase {
202
+ export interface ISheetCommentUpdateEventParams extends IEventBase {
203
203
  /** The workbook instance */
204
204
  workbook: FWorkbook;
205
205
  /** The worksheet containing the updated comment */
@@ -213,10 +213,10 @@ export interface ISheetCommentUpdateEvent extends IEventBase {
213
213
  }
214
214
  /**
215
215
  * Event interface triggered before a comment is updated in a sheet
216
- * @interface IBeforeSheetCommentUpdateEvent
216
+ * @interface IBeforeSheetCommentUpdateEventParams
217
217
  * @augments {IEventBase}
218
218
  */
219
- export interface IBeforeSheetCommentUpdateEvent extends IEventBase {
219
+ export interface IBeforeSheetCommentUpdateEventParams extends IEventBase {
220
220
  /** The workbook instance */
221
221
  workbook: FWorkbook;
222
222
  /** The worksheet containing the comment */
@@ -232,10 +232,10 @@ export interface IBeforeSheetCommentUpdateEvent extends IEventBase {
232
232
  }
233
233
  /**
234
234
  * Event interface triggered before a comment is deleted from a sheet
235
- * @interface IBeforeSheetCommentDeleteEvent
235
+ * @interface IBeforeSheetCommentDeleteEventParams
236
236
  * @augments {IEventBase}
237
237
  */
238
- export interface IBeforeSheetCommentDeleteEvent extends IEventBase {
238
+ export interface IBeforeSheetCommentDeleteEventParams extends IEventBase {
239
239
  /** The workbook instance */
240
240
  workbook: FWorkbook;
241
241
  /** The worksheet containing the comment */
@@ -249,10 +249,10 @@ export interface IBeforeSheetCommentDeleteEvent extends IEventBase {
249
249
  }
250
250
  /**
251
251
  * Event interface triggered after a comment is deleted from a sheet
252
- * @interface ISheetCommentDeleteEvent
252
+ * @interface ISheetCommentDeleteEventParams
253
253
  * @augments {IEventBase}
254
254
  */
255
- export interface ISheetCommentDeleteEvent extends IEventBase {
255
+ export interface ISheetCommentDeleteEventParams extends IEventBase {
256
256
  /** The workbook instance */
257
257
  workbook: FWorkbook;
258
258
  /** The worksheet that contained the comment */
@@ -262,10 +262,10 @@ export interface ISheetCommentDeleteEvent extends IEventBase {
262
262
  }
263
263
  /**
264
264
  * Event interface triggered when a comment's resolve status changes
265
- * @interface ISheetCommentResolveEvent
265
+ * @interface ISheetCommentResolveEventParams
266
266
  * @augments {IEventBase}
267
267
  */
268
- export interface ISheetCommentResolveEvent extends IEventBase {
268
+ export interface ISheetCommentResolveEventParams extends IEventBase {
269
269
  /** The workbook instance */
270
270
  workbook: FWorkbook;
271
271
  /** The worksheet containing the comment */
@@ -282,20 +282,20 @@ export interface ISheetCommentResolveEvent extends IEventBase {
282
282
  /**
283
283
  * @ignore
284
284
  */
285
- export interface ISheetCommentEventConfig {
286
- BeforeCommentAdd: IBeforeSheetCommentAddEvent;
287
- CommentAdded: ISheetCommentAddEvent;
288
- BeforeCommentUpdate: IBeforeSheetCommentUpdateEvent;
289
- CommentUpdated: ISheetCommentUpdateEvent;
290
- BeforeCommentDelete: IBeforeSheetCommentDeleteEvent;
291
- CommentDeleted: ISheetCommentDeleteEvent;
292
- BeforeCommentResolve: ISheetCommentResolveEvent;
293
- CommentResolved: ISheetCommentResolveEvent;
285
+ export interface ISheetsThreadCommentEventParamConfig {
286
+ BeforeCommentAdd: IBeforeSheetCommentAddEventParams;
287
+ CommentAdded: ISheetCommentAddEventParams;
288
+ BeforeCommentUpdate: IBeforeSheetCommentUpdateEventParams;
289
+ CommentUpdated: ISheetCommentUpdateEventParams;
290
+ BeforeCommentDelete: IBeforeSheetCommentDeleteEventParams;
291
+ CommentDeleted: ISheetCommentDeleteEventParams;
292
+ BeforeCommentResolve: ISheetCommentResolveEventParams;
293
+ CommentResolved: ISheetCommentResolveEventParams;
294
294
  }
295
295
  declare module '@univerjs/core/facade' {
296
- interface FEventName extends ICommentEventMixin {
296
+ interface FEventName extends IFSheetsThreadCommentEventNameMixin {
297
297
  }
298
- interface IEventParamConfig extends ISheetCommentEventConfig {
298
+ interface IEventParamConfig extends ISheetsThreadCommentEventParamConfig {
299
299
  }
300
300
  }
301
301
  export {};
@@ -19,7 +19,7 @@ import { FTheadCommentBuilder, FThreadComment } from './f-thread-comment';
19
19
  /**
20
20
  * @ignore
21
21
  */
22
- export interface IFRangeCommentMixin {
22
+ export interface IFRangeSheetsThreadCommentMixin {
23
23
  /**
24
24
  * Get the comment of the start cell in the current range.
25
25
  * @returns {FThreadComment | null} The comment of the start cell in the current range. If the cell does not have a comment, return `null`.
@@ -101,7 +101,7 @@ export interface IFRangeCommentMixin {
101
101
  /**
102
102
  * @ignore
103
103
  */
104
- export declare class FRangeCommentMixin extends FRange implements IFRangeCommentMixin {
104
+ export declare class FRangeSheetsThreadCommentMixin extends FRange implements IFRangeSheetsThreadCommentMixin {
105
105
  getComment(): Nullable<FThreadComment>;
106
106
  getComments(): FThreadComment[];
107
107
  addComment(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>;
@@ -112,6 +112,6 @@ export declare class FRangeCommentMixin extends FRange implements IFRangeComment
112
112
  clearCommentsAsync(): Promise<boolean>;
113
113
  }
114
114
  declare module '@univerjs/sheets/facade' {
115
- interface FRange extends IFRangeCommentMixin {
115
+ interface FRange extends IFRangeSheetsThreadCommentMixin {
116
116
  }
117
117
  }
@@ -13,31 +13,14 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { IDisposable, Injector } from '@univerjs/core';
16
+ import type { Injector } from '@univerjs/core';
17
17
  import type { IThreadComment } from '@univerjs/thread-comment';
18
- import type { ISheetCommentAddEvent, ISheetCommentDeleteEvent, ISheetCommentResolveEvent, ISheetCommentUpdateEvent } from './f-event';
19
18
  import { FUniver } from '@univerjs/core/facade';
20
19
  import { FTheadCommentBuilder } from './f-thread-comment';
21
20
  /**
22
21
  * @ignore
23
22
  */
24
- export interface IFUniverCommentMixin {
25
- /**
26
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.CommentAdded, (params) => {})` as instead
27
- */
28
- onCommentAdded(callback: (event: ISheetCommentAddEvent) => void): IDisposable;
29
- /**
30
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.CommentUpdated, (params) => {})` as instead
31
- */
32
- onCommentUpdated(callback: (event: ISheetCommentUpdateEvent) => void): IDisposable;
33
- /**
34
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.CommentDeleted, (params) => {})` as instead
35
- */
36
- onCommentDeleted(callback: (event: ISheetCommentDeleteEvent) => void): IDisposable;
37
- /**
38
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.CommentResolved, (params) => {})` as instead
39
- */
40
- onCommentResolved(callback: (event: ISheetCommentResolveEvent) => void): IDisposable;
23
+ export interface IFUniverSheetsThreadCommentMixin {
41
24
  /**
42
25
  * Create a new thread comment
43
26
  * @returns {FTheadCommentBuilder} The thead comment builder
@@ -65,7 +48,7 @@ export interface IFUniverCommentMixin {
65
48
  /**
66
49
  * @ignore
67
50
  */
68
- export declare class FUniverCommentMixin extends FUniver implements IFUniverCommentMixin {
51
+ export declare class FUniverSheetsThreadCommentMixin extends FUniver implements IFUniverSheetsThreadCommentMixin {
69
52
  private _getTargetSheet;
70
53
  _initialize(injector: Injector): void;
71
54
  /**
@@ -74,6 +57,6 @@ export declare class FUniverCommentMixin extends FUniver implements IFUniverComm
74
57
  newTheadComment(comment?: IThreadComment): FTheadCommentBuilder;
75
58
  }
76
59
  declare module '@univerjs/core/facade' {
77
- interface FUniver extends IFUniverCommentMixin {
60
+ interface FUniver extends IFUniverSheetsThreadCommentMixin {
78
61
  }
79
62
  }
@@ -22,7 +22,7 @@ type IUpdateCommandParams = any;
22
22
  /**
23
23
  * @ignore
24
24
  */
25
- export interface IFWorkbookThreadCommentMixin {
25
+ export interface IFWorkbookSheetsThreadCommentMixin {
26
26
  /**
27
27
  * Get all comments in the current workbook
28
28
  * @returns {FThreadComment[]} All comments in the current workbook
@@ -76,7 +76,7 @@ export interface IFWorkbookThreadCommentMixin {
76
76
  /**
77
77
  * @ignore
78
78
  */
79
- export declare class FWorkbookThreadCommentMixin extends FWorkbook implements IFWorkbookThreadCommentMixin {
79
+ export declare class FWorkbookSheetsThreadCommentMixin extends FWorkbook implements IFWorkbookSheetsThreadCommentMixin {
80
80
  _threadCommentModel: ThreadCommentModel;
81
81
  /**
82
82
  * @ignore
@@ -106,7 +106,7 @@ export declare class FWorkbookThreadCommentMixin extends FWorkbook implements IF
106
106
  onBeforeDeleteThreadComment(callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
107
107
  }
108
108
  declare module '@univerjs/sheets/facade' {
109
- interface FWorkbook extends IFWorkbookThreadCommentMixin {
109
+ interface FWorkbook extends IFWorkbookSheetsThreadCommentMixin {
110
110
  }
111
111
  }
112
112
  export {};
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(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`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadCommentFacade={},e.UniverCore,e.UniverSheetsThreadComment,e.UniverSheetsFacade,e.UniverThreadComment,e.UniverEngineFormula,e.rxjs,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){return function(n,r){t(n,r,e)}}function p(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var m,h=class e{static create(t){return new e(t)}constructor(e){d(this,`_comment`,{id:(0,t.generateRandomId)(),ref:``,threadId:``,dT:``,personId:``,text:t.RichTextBuilder.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return t.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return g.create(t.Tools.deepClone(this._comment))}},g=class e extends h{static create(t){return new e(t)}setContent(e){return e instanceof t.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=(0,i.getDT)(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let _=m=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return(0,a.deserializeRangeWithSheet)(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(m,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,t.UniverInstanceType.UNIVER_SHEET);if(!e)return null;let n=e.getSheetBySheetId(this._thread.subUnitId);if(!n)return null;let i=this._getRef();return this._injector.createInstance(r.FRange,e,n,i)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return t.RichTextValue.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?i.DeleteCommentTreeCommand.id:i.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){let n=e instanceof t.RichTextValue?e.getData().body:e,r=(0,i.getDT)();return await this._commandService.executeCommand(i.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:r}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var n;let r=e.build();return this._commandService.executeCommand(i.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:(0,t.generateRandomId)(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((n=this._parent)==null?void 0:n.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:r.text,attachments:r.attachments,dT:r.dT||(0,i.getDT)(),personId:r.personId||this._userManagerService.getCurrentUser().userID}})}};_=m=p([f(2,(0,t.Inject)(t.Injector)),f(3,t.ICommandService),f(4,t.IUniverInstanceService),f(5,(0,t.Inject)(n.SheetsThreadCommentModel)),f(6,(0,t.Inject)(t.UserManagerService))],_);var v=class extends r.FRange{getComment(){let e=this._injector.get(n.SheetsThreadCommentModel),t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=e.getByLocation(t,r,this._range.startRow,this._range.startColumn);if(!i)return null;let a=e.getComment(t,r,i);return a?this._injector.createInstance(_,a):null}getComments(){let e=this._injector.get(n.SheetsThreadCommentModel),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=[];return t.Range.foreach(this._range,(t,n)=>{let o=e.getByLocation(r,i,t,n);if(o){let t=e.getComment(r,i,o);t&&a.push(this._injector.createInstance(_,t))}}),a}addComment(e){var n;let r=this._injector,a=(n=this.getComment())==null?void 0:n.getCommentData(),o=r.get(t.ICommandService),s=r.get(t.UserManagerService),c=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),u=`${t.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=s.getCurrentUser(),f=e instanceof g?e.build():{text:e};return o.executeCommand(i.AddCommentCommand.id,{unitId:c,subUnitId:l,comment:{text:f.text,dT:f.dT||(0,i.getDT)(),attachments:[],id:f.id||(0,t.generateRandomId)(),ref:u,personId:f.personId||d.userID,parentId:a==null?void 0:a.id,unitId:c,subUnitId:l,threadId:(a==null?void 0:a.threadId)||(0,t.generateRandomId)()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),a=n.get(t.ICommandService),o=this._workbook.getUnitId(),s=this._worksheet.getSheetId();return r?a.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:s,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};r.FRange.extend(v);var y=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(i.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(_,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return(0,t.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0,o.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===i.AddCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===i.UpdateCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===i.DeleteCommentCommand.id||t.id===i.DeleteCommentTreeCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};r.FWorkbook.extend(y);var b=class extends r.FWorksheet{getComments(){return this._injector.get(n.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(_,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t.ICommandService).onCommandExecuted(t=>{if(t.id===i.AddCommentCommand.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(n.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(_,t)}};r.FWorksheet.extend(b);let x={CommentAdded:`CommentAdded`,BeforeCommentAdd:`BeforeCommentAdd`,CommentUpdated:`CommentUpdated`,BeforeCommentUpdate:`BeforeCommentUpdate`,CommentDeleted:`CommentDeleted`,BeforeCommentDelete:`BeforeCommentDelete`,CommentResolved:`CommentResolved`,BeforeCommentResolve:`BeforeCommentResolve`};var S=class extends s.FEventName{get CommentAdded(){return x.CommentAdded}get BeforeCommentAdd(){return x.BeforeCommentAdd}get CommentUpdated(){return x.CommentUpdated}get BeforeCommentUpdate(){return x.BeforeCommentUpdate}get CommentDeleted(){return x.CommentDeleted}get BeforeCommentDelete(){return x.BeforeCommentDelete}get CommentResolved(){return x.CommentResolved}get BeforeCommentResolve(){return x.BeforeCommentResolve}};s.FEventName.extend(S);var C=class extends s.FUniver{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(e){let n=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{if(e.id!==i.AddCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{comment:a}=e.params,o=r.getCommentById(a.id);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentAdded,{workbook:n,worksheet:r,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{if(e.id!==i.UpdateCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{payload:a}=e.params,o=r.getCommentById(a.commentId);if(o){var s,c,l,u;this.fireEvent(this.Event.CommentUpdated,{workbook:n,worksheet:r,row:(s=(c=o.getRange())==null?void 0:c.getRow())==null?0:s,col:(l=(u=o.getRange())==null?void 0:u.getColumn())==null?0:l,comment:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:a}=e.params;this.fireEvent(this.Event.CommentDeleted,{workbook:n,worksheet:r,commentId:a})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{if(e.id!==i.ResolveCommentCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:a,resolved:o}=e.params,s=r.getCommentById(a);if(s){var c,l,u,d;this.fireEvent(this.Event.CommentResolved,{workbook:n,worksheet:r,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s,resolved:o})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.AddCommentCommand.id)return;let n=this._getTargetSheet(e.params);if(!n)return;let{workbook:r,worksheet:o}=n,{comment:s}=e.params,{range:c}=(0,a.deserializeRangeWithSheet)(s.ref),l={workbook:r,worksheet:o,row:c.startRow,col:c.startColumn,comment:h.create(s)};if(this.fireEvent(this.Event.BeforeCommentAdd,l),l.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.UpdateCommentCommand.id)return;let n=this._getTargetSheet(e.params);if(!n)return;let{workbook:r,worksheet:a}=n,{payload:o}=e.params,s=a.getCommentById(o.commentId);if(s){var c,l,u,d;let e={workbook:r,worksheet:a,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s,newContent:t.RichTextValue.createByBody(o.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,e),e.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let n=this._getTargetSheet(e.params);if(!n)return;let{workbook:r,worksheet:a}=n,{commentId:o}=e.params,s=a.getCommentById(o);if(s){var c,l,u,d;let e={workbook:r,worksheet:a,row:(c=(l=s.getRange())==null?void 0:l.getRow())==null?0:c,col:(u=(d=s.getRange())==null?void 0:d.getColumn())==null?0:u,comment:s};if(this.fireEvent(this.Event.BeforeCommentDelete,e),e.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.ResolveCommentCommand.id)return;let n=this._getTargetSheet(e.params);if(!n)return;let{workbook:r,worksheet:a}=n,{commentId:o,resolved:s}=e.params,c=a.getCommentById(o);if(c){var l,u;let e={workbook:r,worksheet:a,row:(l=c.getRange().getRow())==null?0:l,col:(u=c.getRange().getColumn())==null?0:u,comment:c,resolved:s};if(this.fireEvent(this.Event.BeforeCommentResolve,e),e.cancel)throw new t.CanceledError}})))}newTheadComment(e){return new g(e)}};s.FUniver.extend(C),Object.defineProperty(e,`FThreadComment`,{enumerable:!0,get:function(){return _}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(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`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadCommentFacade={},e.UniverCore,e.UniverSheetsThreadComment,e.UniverSheetsFacade,e.UniverThreadComment,e.UniverEngineFormula,e.rxjs,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){return function(n,r){t(n,r,e)}}function p(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var m,h=class e{static create(t){return new e(t)}constructor(e){d(this,`_comment`,{id:(0,t.generateRandomId)(),ref:``,threadId:``,dT:``,personId:``,text:t.RichTextBuilder.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return t.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return g.create(t.Tools.deepClone(this._comment))}},g=class e extends h{static create(t){return new e(t)}setContent(e){return e instanceof t.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=(0,i.getDT)(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let _=m=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return(0,a.deserializeRangeWithSheet)(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(m,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,t.UniverInstanceType.UNIVER_SHEET);if(!e)return null;let n=e.getSheetBySheetId(this._thread.subUnitId);if(!n)return null;let i=this._getRef();return this._injector.createInstance(r.FRange,e,n,i)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return t.RichTextValue.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?i.DeleteCommentTreeCommand.id:i.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){let n=e instanceof t.RichTextValue?e.getData().body:e,r=(0,i.getDT)();return await this._commandService.executeCommand(i.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:r}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var n;let r=e.build();return this._commandService.executeCommand(i.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:(0,t.generateRandomId)(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((n=this._parent)==null?void 0:n.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:r.text,attachments:r.attachments,dT:r.dT||(0,i.getDT)(),personId:r.personId||this._userManagerService.getCurrentUser().userID}})}};_=m=p([f(2,(0,t.Inject)(t.Injector)),f(3,t.ICommandService),f(4,t.IUniverInstanceService),f(5,(0,t.Inject)(n.SheetsThreadCommentModel)),f(6,(0,t.Inject)(t.UserManagerService))],_);var v=class extends r.FRange{getComment(){let e=this._injector.get(n.SheetsThreadCommentModel),t=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=e.getByLocation(t,r,this._range.startRow,this._range.startColumn);if(!i)return null;let a=e.getComment(t,r,i);return a?this._injector.createInstance(_,a):null}getComments(){let e=this._injector.get(n.SheetsThreadCommentModel),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId(),a=[];return t.Range.foreach(this._range,(t,n)=>{let o=e.getByLocation(r,i,t,n);if(o){let t=e.getComment(r,i,o);t&&a.push(this._injector.createInstance(_,t))}}),a}addComment(e){var n;let r=this._injector,a=(n=this.getComment())==null?void 0:n.getCommentData(),o=r.get(t.ICommandService),s=r.get(t.UserManagerService),c=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),u=`${t.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=s.getCurrentUser(),f=e instanceof g?e.build():{text:e};return o.executeCommand(i.AddCommentCommand.id,{unitId:c,subUnitId:l,comment:{text:f.text,dT:f.dT||(0,i.getDT)(),attachments:[],id:f.id||(0,t.generateRandomId)(),ref:u,personId:f.personId||d.userID,parentId:a==null?void 0:a.id,unitId:c,subUnitId:l,threadId:(a==null?void 0:a.threadId)||(0,t.generateRandomId)()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),a=n.get(t.ICommandService),o=this._workbook.getUnitId(),s=this._worksheet.getSheetId();return r?a.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:s,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};r.FRange.extend(v);var y=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(i.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(_,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return(0,t.toDisposable)(this._threadCommentModel.commentUpdate$.pipe((0,o.filter)(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===i.AddCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===i.UpdateCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return(0,t.toDisposable)(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===i.DeleteCommentCommand.id||t.id===i.DeleteCommentTreeCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};r.FWorkbook.extend(y);var b=class extends r.FWorksheet{getComments(){return this._injector.get(n.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(_,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t.ICommandService).onCommandExecuted(t=>{if(t.id===i.AddCommentCommand.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(n.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(_,t)}};r.FWorksheet.extend(b);var x=class extends s.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`}};s.FEventName.extend(x);var S=class extends s.FUniver{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(e){let n=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{var t,n,r,a;if(e.id!==i.AddCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{comment:l}=e.params,u=c.getCommentById(l.id);if(!u)return;let d={workbook:s,worksheet:c,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(a=u.getRange())==null?void 0:a.getColumn())==null?0:r,comment:u};this.fireEvent(this.Event.CommentAdded,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{var t,n,r,a;if(e.id!==i.UpdateCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{payload:l}=e.params,u=c.getCommentById(l.commentId);if(!u)return;let d={workbook:s,worksheet:c,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(a=u.getRange())==null?void 0:a.getColumn())==null?0:r,comment:u};this.fireEvent(this.Event.CommentUpdated,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:a}=e.params,o={workbook:n,worksheet:r,commentId:a};this.fireEvent(this.Event.CommentDeleted,o)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{var t,n,r,a;if(e.id!==i.ResolveCommentCommand.id)return;let o=this._getTargetSheet(e.params);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l,resolved:u}=e.params,d=c.getCommentById(l);if(!d)return;let f={workbook:s,worksheet:c,row:(t=(n=d.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(a=d.getRange())==null?void 0:a.getColumn())==null?0:r,comment:d,resolved:u};this.fireEvent(this.Event.CommentResolved,f)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.AddCommentCommand.id)return;let n=this._getTargetSheet(e.params);if(!n)return;let{workbook:r,worksheet:o}=n,{comment:s}=e.params,{range:c}=(0,a.deserializeRangeWithSheet)(s.ref),l={workbook:r,worksheet:o,row:c.startRow,col:c.startColumn,comment:h.create(s)};if(this.fireEvent(this.Event.BeforeCommentAdd,l),l.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(e=>{var n,r,a,o;if(e.id!==i.UpdateCommentCommand.id)return;let s=this._getTargetSheet(e.params);if(!s)return;let{workbook:c,worksheet:l}=s,{payload:u}=e.params,d=l.getCommentById(u.commentId);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(r=d.getRange())==null?void 0:r.getRow())==null?0:n,col:(a=(o=d.getRange())==null?void 0:o.getColumn())==null?0:a,comment:d,newContent:t.RichTextValue.createByBody(u.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,f),f.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(e=>{var n,r,a,o;if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let s=this._getTargetSheet(e.params);if(!s)return;let{workbook:c,worksheet:l}=s,{commentId:u}=e.params,d=l.getCommentById(u);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(r=d.getRange())==null?void 0:r.getRow())==null?0:n,col:(a=(o=d.getRange())==null?void 0:o.getColumn())==null?0:a,comment:d};if(this.fireEvent(this.Event.BeforeCommentDelete,f),f.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(e=>{var n,r;if(e.id!==i.ResolveCommentCommand.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=e.params,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:(n=u.getRange().getRow())==null?0:n,col:(r=u.getRange().getColumn())==null?0:r,comment:u,resolved:l};if(this.fireEvent(this.Event.BeforeCommentResolve,d),d.cancel)throw new t.CanceledError})))}newTheadComment(e){return new g(e)}};s.FUniver.extend(S),Object.defineProperty(e,`FThreadComment`,{enumerable:!0,get:function(){return _}})});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets`),require(`@univerjs/thread-comment`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-formula`,`@univerjs/sheets`,`@univerjs/thread-comment`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadComment={},e.UniverCore,e.UniverEngineFormula,e.UniverSheets,e.UniverThreadComment,e.rxjs))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e){"@babel/helpers - typeof";return o=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,l(this,`_matrixMap`,new Map),l(this,`_locationMap`,new Map),l(this,`_commentUpdate$`,new a.Subject),l(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let r=this._matrixMap.get(e);r||(r=new Map,this._matrixMap.set(e,r));let i=r.get(n);return i||(i=new t.ObjectMatrix,r.set(n,i)),i}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,r){let i=(0,n.singleReferenceToGrid)(r.ref),a=r.parentId,{row:o,column:s}=i,c=r.id,{matrix:l,locationMap:u}=this._ensure(e,t);!a&&o>=0&&s>=0&&(this._addCommentToMatrix(l,o,s,c),u.set(c,{row:o,column:s})),a||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:r,type:`add`,isRoot:!a,...i})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:r,subUnitId:i}=e;try{if(this._univerInstanceService.getUnitType(r)!==t.UniverInstanceType.UNIVER_SHEET)return}catch{}let{matrix:a,locationMap:o}=this._ensure(r,i);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:r}=e.payload;if(t){let t=(0,n.singleReferenceToGrid)(r.ref),{row:i,column:o}=t;this._deleteCommentFromMatrix(a,i,o,r.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:t}=e.payload,a=this._threadCommentModel.getComment(r,i,t);if(!a)return;let o=(0,n.singleReferenceToGrid)(a.ref);this._commentUpdate$.next({...e,...o});break}case`updateRef`:{let t=(0,n.singleReferenceToGrid)(e.payload.ref),{commentId:r}=e.payload,i=o.get(r);if(!i)return;let{row:s,column:c}=i;this._deleteCommentFromMatrix(a,s,c,r),o.delete(r),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(a,t.row,t.column,r),o.set(r,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};f=d([u(0,(0,t.Inject)(i.ThreadCommentModel)),u(1,t.IUniverInstanceService)],f);let p=class extends t.Disposable{constructor(e,t,r,a,o){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=r,this._selectionManagerService=a,this._commandService=o,l(this,`_disposableMap`,new Map),l(this,`_watcherMap`,new Map),l(this,`_handleRangeChange`,(e,t,r,a,o)=>{let s=r.id,c={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};return a?{redos:[{id:i.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:t,payload:{ref:(0,n.serializeRange)(a),commentId:s},silent:o}}],undos:[{id:i.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:t,payload:{ref:(0,n.serializeRange)(c),commentId:s},silent:o}}]}:{redos:[{id:i.DeleteCommentMutation.id,params:{unitId:e,subUnitId:t,commentId:s}}],undos:[{id:i.AddCommentMutation.id,params:{unitId:e,subUnitId:t,comment:r,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let i=n.id,a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,i),this._refRangeService.registerRefRange(a,i=>{let o=(0,r.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,s,!1)},e,t))}_watch(e,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watcherMap.set(this._getIdWithUnitId(e,n,i),this._refRangeService.watchRange(e,n,a,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,a,!0);(0,t.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:r,root:i}=e,a=(0,n.singleReferenceToGrid)(i.ref),o={...i,...a};this._register(t,r,o),this._watch(t,r,o)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};p=d([u(0,(0,t.Inject)(r.RefRangeService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(i.ThreadCommentModel)),u(3,(0,t.Inject)(r.SheetsSelectionsService)),u(4,t.ICommandService)],p);var m=`@univerjs/sheets-thread-comment`,h=`0.18.0`;let g={},_=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.RemoveSheetCommand.id){var n;let r=e.params,a=r.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=r.subUnitId||((n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:n.getSheetId());if(!a||!o)return{redos:[],undos:[]};let s=this._threadCommentModel.ensureMap(a,o),c=Array.from(s.values()).filter(e=>!e.parentId),l=this._threadCommentDataSourceService.syncUpdateMutationToColla,u=[],d=[];return c.forEach(({children:e,...t})=>{u.push({id:i.DeleteCommentMutation.id,params:{unitId:a,subUnitId:o,commentId:t.id}}),d.push({id:i.AddCommentMutation.id,params:{unitId:a,subUnitId:o,comment:{...t,children:l?e:void 0},sync:!l}})}),{redos:u,undos:d}}else if(e.id===r.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:a}=e.params;if(!n||!r||!a)return{redos:[],undos:[]};let o=this._threadCommentModel.ensureMap(n,r),s=Array.from(o.values()).map(e=>({...e,subUnitId:a,id:(0,t.generateRandomId)(),threadId:(0,t.generateRandomId)()})).filter(e=>!e.parentId),c=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return s.forEach(({children:e,...t})=>{l.push({id:i.AddCommentMutation.id,params:{unitId:n,subUnitId:a,comment:{...t,children:c?e:void 0},sync:!c}}),u.push({id:i.DeleteCommentMutation.id,params:{unitId:n,subUnitId:a,commentId:t.id}})}),{redos:l,undos:u}}return{redos:[],undos:[]}}}))}};_=d([u(0,t.IUniverInstanceService),u(1,(0,t.Inject)(r.SheetInterceptorService)),u(2,(0,t.Inject)(i.ThreadCommentModel)),u(3,i.IThreadCommentDataSourceService)],_);let v=class extends t.Plugin{constructor(e=g,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[f],[p],[_]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[p],[_]])}};l(v,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),l(v,`packageName`,m),l(v,`version`,h),l(v,`type`,t.UniverInstanceType.UNIVER_SHEET),v=d([(0,t.DependentOn)(i.UniverThreadCommentPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,(0,t.Inject)(t.ICommandService))],v),Object.defineProperty(e,`SheetsThreadCommentModel`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,`SheetsThreadCommentRefRangeController`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(e,`UniverSheetsThreadCommentPlugin`,{enumerable:!0,get:function(){return v}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets`),require(`@univerjs/thread-comment`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-formula`,`@univerjs/sheets`,`@univerjs/thread-comment`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsThreadComment={},e.UniverCore,e.UniverEngineFormula,e.UniverSheets,e.UniverThreadComment,e.rxjs))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e){"@babel/helpers - typeof";return o=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e,t){super(),this._threadCommentModel=e,this._univerInstanceService=t,l(this,`_matrixMap`,new Map),l(this,`_locationMap`,new Map),l(this,`_commentUpdate$`,new a.Subject),l(this,`commentUpdate$`,this._commentUpdate$.asObservable()),this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let r=this._matrixMap.get(e);r||(r=new Map,this._matrixMap.set(e,r));let i=r.get(n);return i||(i=new t.ObjectMatrix,r.set(n,i)),i}_ensureCommentLocationMap(e,t){let n=this._locationMap.get(e);n||(n=new Map,this._locationMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_addCommentToMatrix(e,t,n,r){var i;let a=(i=e.getValue(t,n))==null?new Set:i;a.add(r),e.setValue(t,n,a)}_deleteCommentFromMatrix(e,t,n,r){if(t>=0&&n>=0){let i=e.getValue(t,n);i&&i.has(r)&&(i.delete(r),i.size===0&&e.realDeleteValue(t,n))}}_ensure(e,t){return{matrix:this._ensureCommentMatrix(e,t),locationMap:this._ensureCommentLocationMap(e,t)}}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:n,root:r}=e;this._addComment(t,n,r)}}_addComment(e,t,r){let i=(0,n.singleReferenceToGrid)(r.ref),a=r.parentId,{row:o,column:s}=i,c=r.id,{matrix:l,locationMap:u}=this._ensure(e,t);!a&&o>=0&&s>=0&&(this._addCommentToMatrix(l,o,s,c),u.set(c,{row:o,column:s})),a||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:r,type:`add`,isRoot:!a,...i})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:r,subUnitId:i}=e;try{if(this._univerInstanceService.getUnitType(r)!==t.UniverInstanceType.UNIVER_SHEET)return}catch{}let{matrix:a,locationMap:o}=this._ensure(r,i);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:r}=e.payload;if(t){let t=(0,n.singleReferenceToGrid)(r.ref),{row:i,column:o}=t;this._deleteCommentFromMatrix(a,i,o,r.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:t}=e.payload,a=this._threadCommentModel.getComment(r,i,t);if(!a)return;let o=(0,n.singleReferenceToGrid)(a.ref);this._commentUpdate$.next({...e,...o});break}case`updateRef`:{let t=(0,n.singleReferenceToGrid)(e.payload.ref),{commentId:r}=e.payload,i=o.get(r);if(!i)return;let{row:s,column:c}=i;this._deleteCommentFromMatrix(a,s,c,r),o.delete(r),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(a,t.row,t.column,r),o.set(r,{row:t.row,column:t.column})),this._commentUpdate$.next({...e,...t});break}case`resolve`:{let{unitId:t,subUnitId:n,payload:r}=e,{locationMap:i}=this._ensure(t,n),a=i.get(r.commentId);a&&this._commentUpdate$.next({...e,...a});break}default:break}}))}getByLocation(e,t,n,r){var i;return(i=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved)[0])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);return i?Array.from(i).map(n=>this.getComment(e,t,n)).filter(Boolean):[]}getComment(e,t,n){return this._threadCommentModel.getComment(e,t,n)}getCommentWithChildren(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return;let a=this.getComment(e,t,i);if(a)return this._threadCommentModel.getThread(e,t,a.threadId)}showCommentMarker(e,t,n,r){let i=this.getByLocation(e,t,n,r);if(!i)return!1;let a=this.getComment(e,t,i);return!!(a&&!a.resolved)}getSubUnitAll(e,t){return this._threadCommentModel.getUnit(e).filter(e=>e.subUnitId===t).map(e=>e.root)}};f=d([u(0,(0,t.Inject)(i.ThreadCommentModel)),u(1,t.IUniverInstanceService)],f);let p=class extends t.Disposable{constructor(e,t,r,a,o){super(),this._refRangeService=e,this._sheetsThreadCommentModel=t,this._threadCommentModel=r,this._selectionManagerService=a,this._commandService=o,l(this,`_disposableMap`,new Map),l(this,`_watcherMap`,new Map),l(this,`_handleRangeChange`,(e,t,r,a,o)=>{let s=r.id,c={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};return a?{redos:[{id:i.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:t,payload:{ref:(0,n.serializeRange)(a),commentId:s},silent:o}}],undos:[{id:i.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:t,payload:{ref:(0,n.serializeRange)(c),commentId:s},silent:o}}]}:{redos:[{id:i.DeleteCommentMutation.id,params:{unitId:e,subUnitId:t,commentId:s}}],undos:[{id:i.AddCommentMutation.id,params:{unitId:e,subUnitId:t,comment:r,sync:!0}}]}}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n){return`${e}-${t}-${n}`}_register(e,t,n){let i=n.id,a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(this._getIdWithUnitId(e,t,i),this._refRangeService.registerRefRange(a,i=>{let o=(0,r.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,n,s,!1)},e,t))}_watch(e,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watcherMap.set(this._getIdWithUnitId(e,n,i),this._refRangeService.watchRange(e,n,a,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,a,!0);(0,t.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._watcherMap.get(i))==null||r.dispose(),this._watcherMap.delete(i)}_unregister(e,t,n){var r;let i=this._getIdWithUnitId(e,t,n);(r=this._disposableMap.get(i))==null||r.dispose(),this._disposableMap.delete(i)}_initData(){let e=this._threadCommentModel.getAll();for(let t of e)for(let e of t.threads){let{unitId:t,subUnitId:r,root:i}=e,a=(0,n.singleReferenceToGrid)(i.ref),o={...i,...a};this._register(t,r,o),this._watch(t,r,o)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:t,subUnitId:n}=e;switch(e.type){case`add`:{if(e.payload.parentId)return;let t={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,t),this._watch(e.unitId,e.subUnitId,t);break}case`delete`:this._unregister(t,n,e.payload.commentId),this._unwatch(t,n,e.payload.commentId);break;case`updateRef`:{let r=this._sheetsThreadCommentModel.getComment(t,n,e.payload.commentId);if(!r)return;this._unregister(t,n,e.payload.commentId);let i={...r,row:e.row,column:e.column};e.silent||(this._unwatch(t,n,e.payload.commentId),this._watch(t,n,i)),this._register(e.unitId,e.subUnitId,i);break}}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};p=d([u(0,(0,t.Inject)(r.RefRangeService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(i.ThreadCommentModel)),u(3,(0,t.Inject)(r.SheetsSelectionsService)),u(4,t.ICommandService)],p);var m=`@univerjs/sheets-thread-comment`,h=`0.19.0-insiders.20260403-3e0e122`;let g={},_=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=r,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.RemoveSheetCommand.id){var n;let r=e.params,a=r.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=r.subUnitId||((n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:n.getSheetId());if(!a||!o)return{redos:[],undos:[]};let s=this._threadCommentModel.ensureMap(a,o),c=Array.from(s.values()).filter(e=>!e.parentId),l=this._threadCommentDataSourceService.syncUpdateMutationToColla,u=[],d=[];return c.forEach(({children:e,...t})=>{u.push({id:i.DeleteCommentMutation.id,params:{unitId:a,subUnitId:o,commentId:t.id}}),d.push({id:i.AddCommentMutation.id,params:{unitId:a,subUnitId:o,comment:{...t,children:l?e:void 0},sync:!l}})}),{redos:u,undos:d}}else if(e.id===r.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:a}=e.params;if(!n||!r||!a)return{redos:[],undos:[]};let o=this._threadCommentModel.ensureMap(n,r),s=Array.from(o.values()).map(e=>({...e,subUnitId:a,id:(0,t.generateRandomId)(),threadId:(0,t.generateRandomId)()})).filter(e=>!e.parentId),c=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=[],u=[];return s.forEach(({children:e,...t})=>{l.push({id:i.AddCommentMutation.id,params:{unitId:n,subUnitId:a,comment:{...t,children:c?e:void 0},sync:!c}}),u.push({id:i.DeleteCommentMutation.id,params:{unitId:n,subUnitId:a,commentId:t.id}})}),{redos:l,undos:u}}return{redos:[],undos:[]}}}))}};_=d([u(0,t.IUniverInstanceService),u(1,(0,t.Inject)(r.SheetInterceptorService)),u(2,(0,t.Inject)(i.ThreadCommentModel)),u(3,i.IThreadCommentDataSourceService)],_);let v=class extends t.Plugin{constructor(e=g,t,n){super(),this._config=e,this._injector=t,this._commandService=n}onStarting(){[[f],[p],[_]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[p],[_]])}};l(v,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),l(v,`packageName`,m),l(v,`version`,h),l(v,`type`,t.UniverInstanceType.UNIVER_SHEET),v=d([(0,t.DependentOn)(i.UniverThreadCommentPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,(0,t.Inject)(t.ICommandService))],v),Object.defineProperty(e,`SheetsThreadCommentModel`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,`SheetsThreadCommentRefRangeController`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(e,`UniverSheetsThreadCommentPlugin`,{enumerable:!0,get:function(){return v}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-thread-comment",
3
- "version": "0.18.0",
3
+ "version": "0.19.0-insiders.20260403-3e0e122",
4
4
  "private": false,
5
5
  "description": "Univer sheets thread comment base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,16 +56,16 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/engine-formula": "0.18.0",
60
- "@univerjs/core": "0.18.0",
61
- "@univerjs/sheets": "0.18.0",
62
- "@univerjs/thread-comment": "0.18.0"
59
+ "@univerjs/core": "0.19.0-insiders.20260403-3e0e122",
60
+ "@univerjs/sheets": "0.19.0-insiders.20260403-3e0e122",
61
+ "@univerjs/thread-comment": "0.19.0-insiders.20260403-3e0e122",
62
+ "@univerjs/engine-formula": "0.19.0-insiders.20260403-3e0e122"
63
63
  },
64
64
  "devDependencies": {
65
65
  "rxjs": "^7.8.2",
66
- "typescript": "^5.9.3",
67
- "vitest": "^4.1.0",
68
- "@univerjs-infra/shared": "0.18.0"
66
+ "typescript": "^6.0.2",
67
+ "vitest": "^4.1.1",
68
+ "@univerjs-infra/shared": "0.19.0"
69
69
  },
70
70
  "scripts": {
71
71
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS