@univerjs/sheets-thread-comment 0.17.0 → 0.18.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.
@@ -1,5 +1,21 @@
1
- import { CommentUpdate, IThreadComment, ThreadCommentModel } from '@univerjs/thread-comment';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { CommentUpdate, IThreadComment } from '@univerjs/thread-comment';
2
17
  import { Disposable, IUniverInstanceService } from '@univerjs/core';
18
+ import { ThreadCommentModel } from '@univerjs/thread-comment';
3
19
  export type SheetCommentUpdate = CommentUpdate & {
4
20
  row: number;
5
21
  column: number;
@@ -10,7 +26,7 @@ export declare class SheetsThreadCommentModel extends Disposable {
10
26
  private _matrixMap;
11
27
  private _locationMap;
12
28
  private _commentUpdate$;
13
- commentUpdate$: import('rxjs').Observable<SheetCommentUpdate>;
29
+ commentUpdate$: import("rxjs").Observable<SheetCommentUpdate>;
14
30
  constructor(_threadCommentModel: ThreadCommentModel, _univerInstanceService: IUniverInstanceService);
15
31
  private _init;
16
32
  private _ensureCommentMatrix;
@@ -24,7 +40,7 @@ export declare class SheetsThreadCommentModel extends Disposable {
24
40
  getByLocation(unitId: string, subUnitId: string, row: number, column: number): string | undefined;
25
41
  getAllByLocation(unitId: string, subUnitId: string, row: number, column: number): IThreadComment[];
26
42
  getComment(unitId: string, subUnitId: string, commentId: string): IThreadComment | undefined;
27
- getCommentWithChildren(unitId: string, subUnitId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/thread-comment').IThreadInfo>;
43
+ getCommentWithChildren(unitId: string, subUnitId: string, row: number, column: number): import("@univerjs/core").Nullable<import("@univerjs/thread-comment").IThreadInfo>;
28
44
  showCommentMarker(unitId: string, subUnitId: string, row: number, column: number): boolean;
29
45
  getSubUnitAll(unitId: string, subUnitId: string): IThreadComment[];
30
46
  }
@@ -1,4 +1,19 @@
1
- import { IUniverSheetsThreadCommentConfig } from './config/config';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IUniverSheetsThreadCommentConfig } from './config/config';
2
17
  import { ICommandService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
18
  export declare class UniverSheetsThreadCommentPlugin extends Plugin {
4
19
  private readonly _config;
@@ -1,4 +1,19 @@
1
- import { IThreadComment } from '@univerjs/thread-comment';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IThreadComment } from '@univerjs/thread-comment';
2
17
  export interface ISheetThreadComment extends IThreadComment {
3
18
  row: number;
4
19
  column: number;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(a,o){typeof exports=="object"&&typeof module<"u"?o(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"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a.UniverSheetsThreadCommentFacade={},a.UniverCore,a.UniverSheetsThreadComment,a.UniverSheetsFacade,a.UniverThreadComment,a.UniverEngineFormula,a.rxjs,a.UniverCoreFacade))})(this,(function(a,o,l,f,h,U,R,T){"use strict";var A=Object.defineProperty;var M=(a,o,l)=>o in a?A(a,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[o]=l;var b=(a,o,l)=>M(a,typeof o!="symbol"?o+"":o,l);var S=Object.getOwnPropertyDescriptor,E=(v,t,n,e)=>{for(var r=e>1?void 0:e?S(t,n):t,i=v.length-1,s;i>=0;i--)(s=v[i])&&(r=s(r)||r);return r},p=(v,t)=>(n,e)=>t(n,e,v);class k{constructor(t){b(this,"_comment",{id:o.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:o.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});t&&(this._comment=t)}static create(t){return new k(t)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return o.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return w.create(o.Tools.deepClone(this._comment))}}class w extends k{static create(t){return new w(t)}setContent(t){return t instanceof o.RichTextValue?this._comment.text=t.getData().body:this._comment.text=t,this}setPersonId(t){return this._comment.personId=t,this}setDateTime(t){return this._comment.dT=h.getDT(t),this}setId(t){return this._comment.id=t,this}setThreadId(t){return this._comment.threadId=t,this}build(){return this._comment}}a.FThreadComment=class{constructor(t,n,e,r,i,s,c){this._thread=t,this._parent=n,this._injector=e,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=s,this._userManagerService=c}_getRef(){var e;const t=((e=this._parent)==null?void 0:e.ref)||this._thread.ref;return U.deserializeRangeWithSheet(t).range}getIsRoot(){return!this._parent}getCommentData(){const{children:t,...n}=this._thread;return n}getReplies(){var e;const t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return(e=n==null?void 0:n.children)==null?void 0:e.map(r=>this._injector.createInstance(a.FThreadComment,r))}getRange(){const t=this._univerInstanceService.getUnit(this._thread.unitId,o.UniverInstanceType.UNIVER_SHEET);if(!t)return null;const n=t.getSheetBySheetId(this._thread.subUnitId);if(!n)return null;const e=this._getRef();return this._injector.createInstance(f.FRange,t,n,e)}getContent(){return this._thread.text}getRichText(){const t=this._thread.text;return o.RichTextValue.create({body:t,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?h.DeleteCommentTreeCommand.id:h.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(t){return this.updateAsync(t)}async updateAsync(t){const n=t instanceof o.RichTextValue?t.getData().body:t,e=h.getDT();return await this._commandService.executeCommand(h.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:n,updated:!0,updateT:e}})}resolve(t){return this.resolveAsync(t)}resolveAsync(t){return this._commandService.executeCommand(h.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:t!=null?t:!this._thread.resolved})}replyAsync(t){var e;const n=t.build();return this._commandService.executeCommand(h.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:o.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((e=this._parent)==null?void 0:e.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:n.text,attachments:n.attachments,dT:n.dT||h.getDT(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}},a.FThreadComment=E([p(2,o.Inject(o.Injector)),p(3,o.ICommandService),p(4,o.IUniverInstanceService),p(5,o.Inject(l.SheetsThreadCommentModel)),p(6,o.Inject(o.UserManagerService))],a.FThreadComment);class y extends f.FRange{getComment(){const n=this._injector.get(l.SheetsThreadCommentModel),e=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=n.getByLocation(e,r,this._range.startRow,this._range.startColumn);if(!i)return null;const s=n.getComment(e,r,i);return s?this._injector.createInstance(a.FThreadComment,s):null}getComments(){const n=this._injector.get(l.SheetsThreadCommentModel),e=this._workbook.getUnitId(),r=this._worksheet.getSheetId(),i=[];return o.Range.foreach(this._range,(s,c)=>{const m=n.getByLocation(e,r,s,c);if(m){const d=n.getComment(e,r,m);d&&i.push(this._injector.createInstance(a.FThreadComment,d))}}),i}addComment(t){var C;const n=this._injector,e=(C=this.getComment())==null?void 0:C.getCommentData(),r=n.get(o.ICommandService),i=n.get(o.UserManagerService),s=this._workbook.getUnitId(),c=this._worksheet.getSheetId(),m=`${o.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,d=i.getCurrentUser(),u=t instanceof w?t.build():{text:t};return r.executeCommand(h.AddCommentCommand.id,{unitId:s,subUnitId:c,comment:{text:u.text,dT:u.dT||h.getDT(),attachments:[],id:u.id||o.generateRandomId(),ref:m,personId:u.personId||d.userID,parentId:e==null?void 0:e.id,unitId:s,subUnitId:c,threadId:(e==null?void 0:e.threadId)||o.generateRandomId()}})}clearComment(){var s;const t=this._injector,n=(s=this.getComment())==null?void 0:s.getCommentData(),e=t.get(o.ICommandService),r=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return n?e.executeCommand(h.DeleteCommentTreeCommand.id,{unitId:r,subUnitId:i,threadId:n.threadId,commentId:n.id}):Promise.resolve(!0)}clearComments(){const n=this.getComments().map(e=>e.deleteAsync());return Promise.all(n).then(()=>!0)}addCommentAsync(t){return this.addComment(t)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}}f.FRange.extend(y);class x extends f.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(h.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(t=>this._injector.createInstance(a.FThreadComment,t.root))}clearComments(){const n=this.getComments().map(e=>e.deleteAsync());return Promise.all(n).then(()=>!0)}onThreadCommentChange(t){return o.toDisposable(this._threadCommentModel.commentUpdate$.pipe(R.filter(n=>n.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddThreadComment(t){return o.toDisposable(this._commandService.beforeCommandExecuted((n,e)=>{const r=n.params;if(n.id===h.AddCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,e)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(t){return o.toDisposable(this._commandService.beforeCommandExecuted((n,e)=>{const r=n.params;if(n.id===h.UpdateCommentCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,e)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(t){return o.toDisposable(this._commandService.beforeCommandExecuted((n,e)=>{const r=n.params;if(n.id===h.DeleteCommentCommand.id||n.id===h.DeleteCommentTreeCommand.id){if(r.unitId!==this._workbook.getUnitId())return;if(t(r,e)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}f.FWorkbook.extend(x);class B extends f.FWorksheet{getComments(){return this._injector.get(l.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(a.FThreadComment,e))}clearComments(){const n=this.getComments().map(e=>e.deleteAsync());return Promise.all(n).then(()=>!0)}onCommented(t){return this._injector.get(o.ICommandService).onCommandExecuted(e=>{if(e.id===h.AddCommentCommand.id){const r=e.params;t(r)}})}getCommentById(t){const e=this._injector.get(l.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);if(e)return this._injector.createInstance(a.FThreadComment,e)}}f.FWorksheet.extend(B);const _={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDelete:"BeforeCommentDelete",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class j extends T.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}}T.FEventName.extend(j);class D extends T.FUniver{_getTargetSheet(t={}){var r;const n=t.unitId?this.getUniverSheet(t.unitId):(r=this.getActiveWorkbook)==null?void 0:r.call(this);if(!n)return null;const e=t.subUnitId?n.getSheetBySheetId(t.subUnitId):n.getActiveSheet();return e?{workbook:n,worksheet:e}:null}_initialize(t){const n=t.get(o.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>n.onCommandExecuted(e=>{var d,u,C,g;if(e.id!==h.AddCommentCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{comment:c}=e.params,m=s.getCommentById(c.id);m&&this.fireEvent(this.Event.CommentAdded,{workbook:i,worksheet:s,row:(u=(d=m.getRange())==null?void 0:d.getRow())!=null?u:0,col:(g=(C=m.getRange())==null?void 0:C.getColumn())!=null?g:0,comment:m})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>n.onCommandExecuted(e=>{var d,u,C,g;if(e.id!==h.UpdateCommentCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{payload:c}=e.params,m=s.getCommentById(c.commentId);m&&this.fireEvent(this.Event.CommentUpdated,{workbook:i,worksheet:s,row:(u=(d=m.getRange())==null?void 0:d.getRow())!=null?u:0,col:(g=(C=m.getRange())==null?void 0:C.getColumn())!=null?g:0,comment:m})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>n.onCommandExecuted(e=>{if(e.id!==h.DeleteCommentCommand.id&&e.id!==h.DeleteCommentTreeCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{commentId:c}=e.params;this.fireEvent(this.Event.CommentDeleted,{workbook:i,worksheet:s,commentId:c})}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>n.onCommandExecuted(e=>{var u,C,g,I;if(e.id!==h.ResolveCommentCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{commentId:c,resolved:m}=e.params,d=s.getCommentById(c);d&&this.fireEvent(this.Event.CommentResolved,{workbook:i,worksheet:s,row:(C=(u=d.getRange())==null?void 0:u.getRow())!=null?C:0,col:(I=(g=d.getRange())==null?void 0:g.getColumn())!=null?I:0,comment:d,resolved:m})}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>n.beforeCommandExecuted(e=>{if(e.id!==h.AddCommentCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{comment:c}=e.params,{range:m}=U.deserializeRangeWithSheet(c.ref),d={workbook:i,worksheet:s,row:m.startRow,col:m.startColumn,comment:k.create(c)};if(this.fireEvent(this.Event.BeforeCommentAdd,d),d.cancel)throw new o.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>n.beforeCommandExecuted(e=>{var d,u,C,g;if(e.id!==h.UpdateCommentCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{payload:c}=e.params,m=s.getCommentById(c.commentId);if(m){const I={workbook:i,worksheet:s,row:(u=(d=m.getRange())==null?void 0:d.getRow())!=null?u:0,col:(g=(C=m.getRange())==null?void 0:C.getColumn())!=null?g:0,comment:m,newContent:o.RichTextValue.createByBody(c.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,I),I.cancel)throw new o.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>n.beforeCommandExecuted(e=>{var d,u,C,g;if(e.id!==h.DeleteCommentCommand.id&&e.id!==h.DeleteCommentTreeCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{commentId:c}=e.params,m=s.getCommentById(c);if(m){const I={workbook:i,worksheet:s,row:(u=(d=m.getRange())==null?void 0:d.getRow())!=null?u:0,col:(g=(C=m.getRange())==null?void 0:C.getColumn())!=null?g:0,comment:m};if(this.fireEvent(this.Event.BeforeCommentDelete,I),I.cancel)throw new o.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>n.beforeCommandExecuted(e=>{var u,C;if(e.id!==h.ResolveCommentCommand.id)return;const r=this._getTargetSheet(e.params);if(!r)return;const{workbook:i,worksheet:s}=r,{commentId:c,resolved:m}=e.params,d=s.getCommentById(c);if(d){const g={workbook:i,worksheet:s,row:(u=d.getRange().getRow())!=null?u:0,col:(C=d.getRange().getColumn())!=null?C:0,comment:d,resolved:m};if(this.fireEvent(this.Event.BeforeCommentResolve,g),g.cancel)throw new o.CanceledError}})))}newTheadComment(t){return new w(t)}}T.FUniver.extend(D),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
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 _}})});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(m,i){typeof exports=="object"&&typeof module<"u"?i(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"],i):(m=typeof globalThis<"u"?globalThis:m||self,i(m.UniverSheetsThreadComment={},m.UniverCore,m.UniverEngineFormula,m.UniverSheets,m.UniverThreadComment,m.rxjs))})(this,(function(m,i,p,C,_,y){"use strict";var L=Object.defineProperty;var V=(m,i,p)=>i in m?L(m,i,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[i]=p;var f=(m,i,p)=>V(m,typeof i!="symbol"?i+"":i,p);var w=Object.getOwnPropertyDescriptor,b=(c,o,e,n)=>{for(var t=n>1?void 0:n?w(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},I=(c,o)=>(e,n)=>o(e,n,c);m.SheetsThreadCommentModel=class extends i.Disposable{constructor(e,n){super();f(this,"_matrixMap",new Map);f(this,"_locationMap",new Map);f(this,"_commentUpdate$",new y.Subject);f(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let t=this._matrixMap.get(e);t||(t=new Map,this._matrixMap.set(e,t));let r=t.get(n);return r||(r=new i.ObjectMatrix,t.set(n,r)),r}_ensureCommentLocationMap(e,n){let t=this._locationMap.get(e);t||(t=new Map,this._locationMap.set(e,t));let r=t.get(n);return r||(r=new Map,t.set(n,r)),r}_addCommentToMatrix(e,n,t,r){var a;const s=(a=e.getValue(n,t))!=null?a:new Set;s.add(r),e.setValue(n,t,s)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const s=e.getValue(n,t);s&&s.has(r)&&(s.delete(r),s.size===0&&e.realDeleteValue(n,t))}}_ensure(e,n){const t=this._ensureCommentMatrix(e,n),r=this._ensureCommentLocationMap(e,n);return{matrix:t,locationMap:r}}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t;this._addComment(r,s,a)}}_addComment(e,n,t){const r=p.singleReferenceToGrid(t.ref),s=t.parentId,{row:a,column:d}=r,h=t.id,{matrix:u,locationMap:l}=this._ensure(e,n);!s&&a>=0&&d>=0&&(this._addCommentToMatrix(u,a,d,h),l.set(h,{row:a,column:d})),s||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!s,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==i.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:s}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:a,comment:d}=e.payload;if(a){const h=p.singleReferenceToGrid(d.ref),{row:u,column:l}=h;this._deleteCommentFromMatrix(r,u,l,d.id),this._commentUpdate$.next({...e,...h})}break}case"update":{const{commentId:a}=e.payload,d=this._threadCommentModel.getComment(n,t,a);if(!d)return;const h=p.singleReferenceToGrid(d.ref);this._commentUpdate$.next({...e,...h});break}case"updateRef":{const a=p.singleReferenceToGrid(e.payload.ref),{commentId:d}=e.payload,h=s.get(d);if(!h)return;const{row:u,column:l}=h;this._deleteCommentFromMatrix(r,u,l,d),s.delete(d),a.row>=0&&a.column>=0&&(this._addCommentToMatrix(r,a.row,a.column,d),s.set(d,{row:a.row,column:a.column})),this._commentUpdate$.next({...e,...a});break}case"resolve":{const{unitId:a,subUnitId:d,payload:h}=e,{locationMap:u}=this._ensure(a,d),l=u.get(h.commentId);l&&this._commentUpdate$.next({...e,...l});break}}}))}getByLocation(e,n,t,r){var d;return(d=this.getAllByLocation(e,n,t,r).filter(h=>!h.resolved)[0])==null?void 0:d.id}getAllByLocation(e,n,t,r){const a=this._ensureCommentMatrix(e,n).getValue(t,r);return a?Array.from(a).map(d=>this.getComment(e,n,d)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return;const a=this.getComment(e,n,s);if(a)return this._threadCommentModel.getThread(e,n,a.threadId)}showCommentMarker(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return!1;const a=this.getComment(e,n,s);return!!(a&&!a.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}},m.SheetsThreadCommentModel=b([I(0,i.Inject(_.ThreadCommentModel)),I(1,i.IUniverInstanceService)],m.SheetsThreadCommentModel);var j=Object.getOwnPropertyDescriptor,E=(c,o,e,n)=>{for(var t=n>1?void 0:n?j(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},g=(c,o)=>(e,n)=>o(e,n,c);m.SheetsThreadCommentRefRangeController=class extends i.Disposable{constructor(e,n,t,r,s){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(e,n,t,r,s)=>{const a=t.id,d={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:_.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:p.serializeRange(r),commentId:a},silent:s}}],undos:[{id:_.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:p.serializeRange(d),commentId:a},silent:s}}]}:{redos:[{id:_.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:a}}],undos:[{id:_.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:t,sync:!0}}]}});this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=t,this._selectionManagerService=r,this._commandService=s,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(s,a=>{const d=C.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,a,{selectionManagerService:this._selectionManagerService}),h=Array.isArray(d)?d[0]:d;return h&&h.startColumn===s.startColumn&&h.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,h,!1)},e,n))}_watch(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watcherMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.watchRange(e,n,s,(a,d)=>{const{redos:h}=this._handleRangeChange(e,n,t,d,!0);i.sequenceExecuteAsync(h,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._watcherMap.get(r))==null||s.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._disposableMap.get(r))==null||s.dispose(),this._disposableMap.delete(r)}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t,d=p.singleReferenceToGrid(a.ref),h={...a,...d};this._register(r,s,h),this._watch(r,s,h)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;switch(e.type){case"add":{if(e.payload.parentId)return;const r={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,r),this._watch(e.unitId,e.subUnitId,r);break}case"delete":{this._unregister(n,t,e.payload.commentId),this._unwatch(n,t,e.payload.commentId);break}case"updateRef":{const r=this._sheetsThreadCommentModel.getComment(n,t,e.payload.commentId);if(!r)return;this._unregister(n,t,e.payload.commentId);const s={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,s)),this._register(e.unitId,e.subUnitId,s);break}}})),this.disposeWithMe(i.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}},m.SheetsThreadCommentRefRangeController=E([g(0,i.Inject(C.RefRangeService)),g(1,i.Inject(m.SheetsThreadCommentModel)),g(2,i.Inject(_.ThreadCommentModel)),g(3,i.Inject(C.SheetsSelectionsService)),g(4,i.ICommandService)],m.SheetsThreadCommentRefRangeController);const R={name:"@univerjs/sheets-thread-comment",version:"0.17.0"},D={};var P=Object.getOwnPropertyDescriptor,$=(c,o,e,n)=>{for(var t=n>1?void 0:n?P(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},v=(c,o)=>(e,n)=>o(e,n,c);let M=class extends i.Disposable{constructor(c,o,e,n){super(),this._univerInstanceService=c,this._sheetInterceptorService=o,this._threadCommentModel=e,this._threadCommentDataSourceService=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:c=>{var o;if(c.id===C.RemoveSheetCommand.id){const e=c.params,n=e.unitId||this._univerInstanceService.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET).getUnitId(),t=e.subUnitId||((o=this._univerInstanceService.getCurrentUnitOfType(i.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:o.getSheetId());if(!n||!t)return{redos:[],undos:[]};const r=this._threadCommentModel.ensureMap(n,t),s=Array.from(r.values()).filter(u=>!u.parentId),a=this._threadCommentDataSourceService.syncUpdateMutationToColla,d=[],h=[];return s.forEach(({children:u,...l})=>{d.push({id:_.DeleteCommentMutation.id,params:{unitId:n,subUnitId:t,commentId:l.id}}),h.push({id:_.AddCommentMutation.id,params:{unitId:n,subUnitId:t,comment:{...l,children:a?u:void 0},sync:!a}})}),{redos:d,undos:h}}else if(c.id===C.CopySheetCommand.id){const e=c.params,{unitId:n,subUnitId:t,targetSubUnitId:r}=e;if(!n||!t||!r)return{redos:[],undos:[]};const s=this._threadCommentModel.ensureMap(n,t),a=Array.from(s.values()).map(l=>({...l,subUnitId:r,id:i.generateRandomId(),threadId:i.generateRandomId()})).filter(l=>!l.parentId),d=this._threadCommentDataSourceService.syncUpdateMutationToColla,h=[],u=[];return a.forEach(({children:l,...U})=>{h.push({id:_.AddCommentMutation.id,params:{unitId:n,subUnitId:r,comment:{...U,children:d?l:void 0},sync:!d}}),u.push({id:_.DeleteCommentMutation.id,params:{unitId:n,subUnitId:r,commentId:U.id}})}),{redos:h,undos:u}}return{redos:[],undos:[]}}}))}};M=$([v(0,i.IUniverInstanceService),v(1,i.Inject(C.SheetInterceptorService)),v(2,i.Inject(_.ThreadCommentModel)),v(3,_.IThreadCommentDataSourceService)],M);const O="SHEET_THREAD_COMMENT_BASE_PLUGIN";var A=Object.defineProperty,x=Object.getOwnPropertyDescriptor,W=(c,o,e)=>o in c?A(c,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[o]=e,N=(c,o,e,n)=>{for(var t=n>1?void 0:n?x(o,e):o,r=c.length-1,s;r>=0;r--)(s=c[r])&&(t=s(t)||t);return t},T=(c,o)=>(e,n)=>o(e,n,c),S=(c,o,e)=>W(c,typeof o!="symbol"?o+"":o,e);m.UniverSheetsThreadCommentPlugin=class extends i.Plugin{constructor(o=D,e,n){super(),this._config=o,this._injector=e,this._commandService=n}onStarting(){[[m.SheetsThreadCommentModel],[m.SheetsThreadCommentRefRangeController],[M]].forEach(o=>{this._injector.add(o)}),i.touchDependencies(this._injector,[[m.SheetsThreadCommentRefRangeController],[M]])}},S(m.UniverSheetsThreadCommentPlugin,"pluginName",O),S(m.UniverSheetsThreadCommentPlugin,"packageName",R.name),S(m.UniverSheetsThreadCommentPlugin,"version",R.version),S(m.UniverSheetsThreadCommentPlugin,"type",i.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsThreadCommentPlugin=N([i.DependentOn(_.UniverThreadCommentPlugin),T(1,i.Inject(i.Injector)),T(2,i.Inject(i.ICommandService))],m.UniverSheetsThreadCommentPlugin),Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
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}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-thread-comment",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "private": false,
5
5
  "description": "Univer sheets thread comment base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,24 +56,25 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/engine-formula": "0.17.0",
60
- "@univerjs/thread-comment": "0.17.0",
61
- "@univerjs/sheets": "0.17.0",
62
- "@univerjs/core": "0.17.0"
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"
63
63
  },
64
64
  "devDependencies": {
65
65
  "rxjs": "^7.8.2",
66
66
  "typescript": "^5.9.3",
67
- "vite": "^7.3.1",
68
- "vitest": "^4.0.18",
69
- "@univerjs-infra/shared": "0.17.0"
67
+ "vitest": "^4.1.0",
68
+ "@univerjs-infra/shared": "0.18.0"
70
69
  },
71
70
  "scripts": {
72
71
  "test": "vitest run",
73
72
  "test:watch": "vitest",
74
73
  "coverage": "vitest run --coverage",
75
74
  "typecheck": "tsc --noEmit",
76
- "build": "univer-cli build"
75
+ "build:bundle": "univer-cli build",
76
+ "build:types": "tsc -p tsconfig.node.json",
77
+ "build": "pnpm run build:bundle && pnpm run build:types"
77
78
  },
78
79
  "module": "./lib/es/index.js"
79
80
  }