@univerjs/sheets-thread-comment 1.0.0-insiders.20260813-7c9aa50 → 1.0.0

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/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("@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`,`@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.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});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 e{static create(t){return new e(t)}constructor(e){u(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 h.create(t.Tools.deepClone(this._comment))}},h=class e extends m{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 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,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(p,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)}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})}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}})}resolveAsync(e){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e??!this._thread.resolved})}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}})}};g=p=f([d(2,(0,t.Inject)(t.Injector)),d(3,t.ICommandService),d(4,t.IUniverInstanceService),d(5,(0,t.Inject)(n.SheetsThreadCommentModel)),d(6,(0,t.Inject)(t.UserManagerService))],g);var _=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(g,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(g,t))}}),a}addCommentAsync(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 h?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)()}})}clearCommentAsync(){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)}clearCommentsAsync(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}};r.FRange.extend(_);var v=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(g,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}};r.FWorkbook.extend(v);var y=class extends r.FWorksheet{getComments(){return this._injector.get(n.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(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(g,t)}};r.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{_initialize(e){let n=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{var t,n;if(e.id!==i.AddCommentCommand.id)return;let r=e.params,a=this.getSheetCommandTarget(r);if(!a)return;let{workbook:o,worksheet:s}=a,{comment:c}=r,l=s.getCommentById(c.id);if(!l)return;let u={workbook:o,worksheet:s,row:((t=l.getRange())==null?void 0:t.getRow())??0,col:((n=l.getRange())==null?void 0:n.getColumn())??0,comment:l};this.fireEvent(this.Event.CommentAdded,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{var t,n;if(e.id!==i.UpdateCommentCommand.id)return;let r=e.params,a=this.getSheetCommandTarget(r);if(!a)return;let{workbook:o,worksheet:s}=a,{payload:c}=r,l=s.getCommentById(c.commentId);if(!l)return;let u={workbook:o,worksheet:s,row:((t=l.getRange())==null?void 0:t.getRow())??0,col:((n=l.getRange())==null?void 0:n.getColumn())??0,comment:l};this.fireEvent(this.Event.CommentUpdated,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let t=e.params,n=this.getSheetCommandTarget(t);if(!n)return;let{workbook:r,worksheet:a}=n,{commentId:o}=t,s={workbook:r,worksheet:a,commentId:o};this.fireEvent(this.Event.CommentDeleted,s)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{var t,n;if(e.id!==i.ResolveCommentCommand.id)return;let r=e.params,a=this.getSheetCommandTarget(r);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=r,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:((t=u.getRange())==null?void 0:t.getRow())??0,col:((n=u.getRange())==null?void 0:n.getColumn())??0,comment:u,resolved:l};this.fireEvent(this.Event.CommentResolved,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.AddCommentCommand.id)return;let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:o,worksheet:s}=r,{comment:c}=n,{range:l}=(0,a.deserializeRangeWithSheet)(c.ref),u={workbook:o,worksheet:s,row:l.startRow,col:l.startColumn,comment:m.create(c)};if(this.fireEvent(this.Event.BeforeCommentAdd,u),u.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(e=>{var n,r;if(e.id!==i.UpdateCommentCommand.id)return;let a=e.params,o=this.getSheetCommandTarget(a);if(!o)return;let{workbook:s,worksheet:c}=o,{payload:l}=a,u=c.getCommentById(l.commentId);if(!u)return;let d={workbook:s,worksheet:c,row:((n=u.getRange())==null?void 0:n.getRow())??0,col:((r=u.getRange())==null?void 0:r.getColumn())??0,comment:u,newContent:t.RichTextValue.createByBody(l.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,d),d.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(e=>{var n,r;if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let a=e.params,o=this.getSheetCommandTarget(a);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l}=a,u=c.getCommentById(l);if(!u)return;let d={workbook:s,worksheet:c,row:((n=u.getRange())==null?void 0:n.getRow())??0,col:((r=u.getRange())==null?void 0:r.getColumn())??0,comment:u};if(this.fireEvent(this.Event.BeforeCommentDelete,d),d.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.ResolveCommentCommand.id)return;let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:a,worksheet:o}=r,{commentId:s,resolved:c}=n,l=o.getCommentById(s);if(!l)return;let u={workbook:a,worksheet:o,row:l.getRange().getRow()??0,col:l.getRange().getColumn()??0,comment:l,resolved:c};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new t.CanceledError})))}newTheadComment(e){return new h(e)}};o.FUniver.extend(x),Object.defineProperty(e,"FThreadComment",{enumerable:!0,get:function(){return g}})});
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("@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`,`@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.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e},m=(e,t,n)=>(n=e==null?{}:s(d(e)),p(t||!e||!e.__esModule||!f.call(e,`default`)?c(n,`default`,{value:e,enumerable:!0}):n,e));t=m(t),i=m(i);function h(e){"@babel/helpers - typeof";return h=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},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(n,r){t(n,r,e)}}function b(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 x,S=class e{static create(t){return new e(t)}constructor(e){v(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 C.create(t.Tools.deepClone(this._comment))}},C=class e extends S{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 w=x=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;let t=((e=this._parent)==null?void 0:e.ref)||this._thread.ref;return(0,a.deserializeRangeWithSheet)(t).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(x,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)}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})}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}})}resolveAsync(e){return this._commandService.executeCommand(i.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e??!this._thread.resolved})}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}})}};w=x=b([y(2,(0,t.Inject)(t.Injector)),y(3,t.ICommandService),y(4,t.IUniverInstanceService),y(5,(0,t.Inject)(n.SheetsThreadCommentModel)),y(6,(0,t.Inject)(t.UserManagerService))],w);function T(...e){for(let t of e)if(t)return t;return t.generateRandomId()}var E=class extends r.FRange{_initialize(e){let r;Object.defineProperty(this,"_dependencies",{get:()=>r??={commandService:e.get(t.ICommandService),model:e.get(n.SheetsThreadCommentModel),userManagerService:e.get(t.UserManagerService)}})}_getCommentDataInRange(){let e=this._dependencies.model,n=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=[];return t.Range.foreach(this._range,(t,a)=>{let o=e.getByLocation(n,r,t,a),s=o?e.getComment(n,r,o):null;s&&i.push(s)}),i}_getStartCellCommentData(){let e=this._dependencies.model,t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=e.getByLocation(t,n,this._range.startRow,this._range.startColumn);return r?e.getComment(t,n,r)??null:null}getComment(){let e=this._getStartCellCommentData();return e?this._injector.createInstance(w,e):null}getComments(){return this._getCommentDataInRange().map(e=>this._injector.createInstance(w,e))}addCommentAsync(e,n={}){let{commandService:r,userManagerService:a}=this._dependencies,o=this._getStartCellCommentData(),s=this._workbook.getUnitId(),c=this._worksheet.getSheetId(),l=`${t.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,u=a.getCurrentUser(),d=null,f;return e instanceof C?(d=e.build(),f=d.text):f=i.normalizeThreadCommentContent(e),r.executeCommand(i.AddCommentCommand.id,{unitId:s,subUnitId:c,comment:{text:f,dT:n.dateTime?i.getDT(n.dateTime):(d==null?void 0:d.dT)||i.getDT(),attachments:n.attachments??(d==null?void 0:d.attachments)??[],id:T(n.id,d==null?void 0:d.id),ref:l,personId:T(n.personId,d==null?void 0:d.personId,u.userID),authorName:n.authorName??(d==null?void 0:d.authorName),parentId:o==null?void 0:o.id,unitId:s,subUnitId:c,threadId:T(o==null?void 0:o.threadId,n.threadId,d==null?void 0:d.threadId)}})}clearCommentAsync(){let{commandService:e}=this._dependencies,t=this._getStartCellCommentData(),n=this._workbook.getUnitId(),r=this._worksheet.getSheetId();return t?e.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:n,subUnitId:r,threadId:t.threadId,commentId:t.id}):Promise.resolve(!0)}async clearCommentsAsync(){let{commandService:e}=this._dependencies,t=this._workbook.getUnitId(),n=this._worksheet.getSheetId();return(await Promise.all(this._getCommentDataInRange().map(r=>e.executeCommand(i.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:n,threadId:r.threadId,commentId:r.id})))).every(Boolean)}};r.FRange.extend(E);var D=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(w,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}};r.FWorkbook.extend(D);var O=class extends r.FWorksheet{getComments(){return this._injector.get(n.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(w,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(w,t)}};r.FWorksheet.extend(O);var k=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(k);var A=class extends o.FUniver{_initialize(e){let n=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{var t,n;if(e.id!==i.AddCommentCommand.id)return;let r=e.params,a=this.getSheetCommandTarget(r);if(!a)return;let{workbook:o,worksheet:s}=a,{comment:c}=r,l=s.getCommentById(c.id);if(!l)return;let u={workbook:o,worksheet:s,row:((t=l.getRange())==null?void 0:t.getRow())??0,col:((n=l.getRange())==null?void 0:n.getColumn())??0,comment:l};this.fireEvent(this.Event.CommentAdded,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{var t,n;if(e.id!==i.UpdateCommentCommand.id)return;let r=e.params,a=this.getSheetCommandTarget(r);if(!a)return;let{workbook:o,worksheet:s}=a,{payload:c}=r,l=s.getCommentById(c.commentId);if(!l)return;let u={workbook:o,worksheet:s,row:((t=l.getRange())==null?void 0:t.getRow())??0,col:((n=l.getRange())==null?void 0:n.getColumn())??0,comment:l};this.fireEvent(this.Event.CommentUpdated,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let t=e.params,n=this.getSheetCommandTarget(t);if(!n)return;let{workbook:r,worksheet:a}=n,{commentId:o}=t,s={workbook:r,worksheet:a,commentId:o};this.fireEvent(this.Event.CommentDeleted,s)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{var t,n;if(e.id!==i.ResolveCommentCommand.id)return;let r=e.params,a=this.getSheetCommandTarget(r);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=r,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:((t=u.getRange())==null?void 0:t.getRow())??0,col:((n=u.getRange())==null?void 0:n.getColumn())??0,comment:u,resolved:l};this.fireEvent(this.Event.CommentResolved,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.AddCommentCommand.id)return;let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:o,worksheet:s}=r,{comment:c}=n,{range:l}=(0,a.deserializeRangeWithSheet)(c.ref),u={workbook:o,worksheet:s,row:l.startRow,col:l.startColumn,comment:S.create(c)};if(this.fireEvent(this.Event.BeforeCommentAdd,u),u.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(e=>{var n,r;if(e.id!==i.UpdateCommentCommand.id)return;let a=e.params,o=this.getSheetCommandTarget(a);if(!o)return;let{workbook:s,worksheet:c}=o,{payload:l}=a,u=c.getCommentById(l.commentId);if(!u)return;let d={workbook:s,worksheet:c,row:((n=u.getRange())==null?void 0:n.getRow())??0,col:((r=u.getRange())==null?void 0:r.getColumn())??0,comment:u,newContent:t.RichTextValue.createByBody(l.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,d),d.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(e=>{var n,r;if(e.id!==i.DeleteCommentCommand.id&&e.id!==i.DeleteCommentTreeCommand.id)return;let a=e.params,o=this.getSheetCommandTarget(a);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l}=a,u=c.getCommentById(l);if(!u)return;let d={workbook:s,worksheet:c,row:((n=u.getRange())==null?void 0:n.getRow())??0,col:((r=u.getRange())==null?void 0:r.getColumn())??0,comment:u};if(this.fireEvent(this.Event.BeforeCommentDelete,d),d.cancel)throw new t.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(e=>{if(e.id!==i.ResolveCommentCommand.id)return;let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:a,worksheet:o}=r,{commentId:s,resolved:c}=n,l=o.getCommentById(s);if(!l)return;let u={workbook:a,worksheet:o,row:l.getRange().getRow()??0,col:l.getRange().getColumn()??0,comment:l,resolved:c};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new t.CanceledError})))}newTheadComment(e){return new C(e)}};o.FUniver.extend(A),Object.defineProperty(e,"FThreadComment",{enumerable:!0,get:function(){return w}})});
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){let i=e.getValue(t,n)??new Set;i.add(r),e.setValue(t,n,i)}_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);if(!i)return[];let a=[];for(let n of i){let r=this.getComment(e,t,n);r&&a.push(r)}return a}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=`1.0.0-insiders.20260813-7c9aa50`;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,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},g,this._config);this._configService.setConfig(`sheets-thread-comment.config`,a)}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,r.UniverSheetsPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,(0,t.Inject)(t.ICommandService)),u(3,t.IConfigService)],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){let i=e.getValue(t,n)??new Set;i.add(r),e.setValue(t,n,i)}_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){if((0,i.deserializeThreadCommentAnchor)(r.ref))return;let a=(0,n.singleReferenceToGrid)(r.ref),o=r.parentId,{row:s,column:c}=a,l=r.id,{matrix:u,locationMap:d}=this._ensure(e,t);!o&&s>=0&&c>=0&&(this._addCommentToMatrix(u,s,c,l),d.set(l,{row:s,column:c})),o||this._commentUpdate$.next({unitId:e,subUnitId:t,payload:r,type:`add`,isRoot:!o,...a})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{let{unitId:r,subUnitId:a}=e;try{if(this._univerInstanceService.getUnitType(r)!==t.UniverInstanceType.UNIVER_SHEET)return}catch{}let{matrix:o,locationMap:s}=this._ensure(r,a);switch(e.type){case`add`:this._addComment(e.unitId,e.subUnitId,e.payload);break;case`delete`:{let{isRoot:t,comment:r}=e.payload;if((0,i.deserializeThreadCommentAnchor)(r.ref))return;if(t){let t=(0,n.singleReferenceToGrid)(r.ref),{row:i,column:a}=t;this._deleteCommentFromMatrix(o,i,a,r.id),this._commentUpdate$.next({...e,...t})}break}case`update`:{let{commentId:t}=e.payload,o=this._threadCommentModel.getComment(r,a,t);if(!o||(0,i.deserializeThreadCommentAnchor)(o.ref))return;let s=(0,n.singleReferenceToGrid)(o.ref);this._commentUpdate$.next({...e,...s});break}case`updateRef`:{if((0,i.deserializeThreadCommentAnchor)(e.payload.ref))return;let t=(0,n.singleReferenceToGrid)(e.payload.ref),{commentId:r}=e.payload,a=s.get(r);if(!a)return;let{row:c,column:l}=a;this._deleteCommentFromMatrix(o,c,l,r),s.delete(r),t.row>=0&&t.column>=0&&(this._addCommentToMatrix(o,t.row,t.column,r),s.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}}}))}getByLocation(e,t,n,r){var i;let a=this.getAllByLocation(e,t,n,r).filter(e=>!e.resolved);return(i=a[a.length-1])==null?void 0:i.id}getAllByLocation(e,t,n,r){let i=this._ensureCommentMatrix(e,t).getValue(n,r);if(!i)return[];let a=[];for(let n of i){let r=this.getComment(e,t,n);r&&a.push(r)}return a}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:a}=e;if((0,i.deserializeThreadCommentAnchor)(a.ref))continue;let o=(0,n.singleReferenceToGrid)(a.ref),s={...a,...o};this._register(t,r,s),this._watch(t,r,s)}}_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);let m=`SHEET_${i.TC_PLUGIN_NAME}`,h=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._sheetInterceptorService=n,this._threadCommentModel=r,this._threadCommentDataSourceService=i,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){this.disposeWithMe(this._resourceManagerService.registerPluginResource((0,i.createThreadCommentResourceHook)(this._threadCommentModel,this._threadCommentDataSourceService,m,[t.UniverInstanceType.UNIVER_SHEET])))}_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}}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:[]}}}))}};h=d([u(0,t.IResourceManagerService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(r.SheetInterceptorService)),u(3,(0,t.Inject)(i.ThreadCommentModel)),u(4,i.IThreadCommentDataSourceService)],h);var g=`@univerjs/sheets-thread-comment`,_=`1.0.0`;let v={},y=class extends t.Plugin{constructor(e=v,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},v,this._config);this._configService.setConfig(`sheets-thread-comment.config`,a)}onStarting(){[[f],[p],[h]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[p],[h]])}};l(y,`pluginName`,`SHEET_THREAD_COMMENT_BASE_PLUGIN`),l(y,`packageName`,g),l(y,`version`,_),l(y,`type`,t.UniverInstanceType.UNIVER_SHEET),y=d([(0,t.DependentOn)(i.UniverThreadCommentPlugin,r.UniverSheetsPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,(0,t.Inject)(t.ICommandService)),u(3,t.IConfigService)],y),e.SHEET_UNIVER_THREAD_COMMENT_PLUGIN=m,Object.defineProperty(e,"SheetsThreadCommentModel",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"SheetsThreadCommentRefRangeController",{enumerable:!0,get:function(){return p}}),Object.defineProperty(e,"SheetsThreadCommentResourceController",{enumerable:!0,get:function(){return h}}),Object.defineProperty(e,"UniverSheetsThreadCommentPlugin",{enumerable:!0,get:function(){return y}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-thread-comment",
3
- "version": "1.0.0-insiders.20260813-7c9aa50",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "description": "Thread comment integration for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -62,16 +62,16 @@
62
62
  "rxjs": ">=7.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/core": "1.0.0-insiders.20260813-7c9aa50",
66
- "@univerjs/engine-formula": "1.0.0-insiders.20260813-7c9aa50",
67
- "@univerjs/thread-comment": "1.0.0-insiders.20260813-7c9aa50",
68
- "@univerjs/sheets": "1.0.0-insiders.20260813-7c9aa50"
65
+ "@univerjs/core": "1.0.0",
66
+ "@univerjs/engine-formula": "1.0.0",
67
+ "@univerjs/sheets": "1.0.0",
68
+ "@univerjs/thread-comment": "1.0.0"
69
69
  },
70
70
  "devDependencies": {
71
+ "@univerjs-infra/shared": "1.0.0",
71
72
  "rxjs": "^7.8.2",
72
73
  "typescript": "^6.0.3",
73
- "vitest": "^4.1.10",
74
- "@univerjs-infra/shared": "1.0.0-beta.0"
74
+ "vitest": "^5.0.0"
75
75
  },
76
76
  "scripts": {
77
77
  "test": "vitest run",