@univerjs/sheets-thread-comment 0.20.1 → 0.21.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/es/facade.js CHANGED
@@ -1 +1,1014 @@
1
- import{CanceledError as e,ICommandService as t,IUniverInstanceService as n,Inject as r,Injector as i,Range as a,RichTextBuilder as o,RichTextValue as s,Tools as c,UniverInstanceType as l,UserManagerService as u,generateRandomId as d,toDisposable as f}from"@univerjs/core";import{SheetsThreadCommentModel as p}from"@univerjs/sheets-thread-comment";import{FRange as m,FWorkbook as h,FWorksheet as g}from"@univerjs/sheets/facade";import{AddCommentCommand as _,DeleteCommentCommand as v,DeleteCommentTreeCommand as y,ResolveCommentCommand as b,ThreadCommentModel as x,UpdateCommentCommand as S,getDT as C}from"@univerjs/thread-comment";import{deserializeRangeWithSheet as w}from"@univerjs/engine-formula";import{filter as T}from"rxjs";import{FEventName as E,FUniver as D}from"@univerjs/core/facade";function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var P,F=class e{static create(t){return new e(t)}constructor(e){j(this,`_comment`,{id:d(),ref:``,threadId:``,dT:``,personId:``,text:o.newEmptyData().body,attachments:[],unitId:``,subUnitId:``}),e&&(this._comment=e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return s.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return I.create(c.deepClone(this._comment))}},I=class e extends F{static create(t){return new e(t)}setContent(e){return e instanceof s?this._comment.text=e.getData().body:this._comment.text=e,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=C(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}};let L=P=class{constructor(e,t,n,r,i,a,o){this._thread=e,this._parent=t,this._injector=n,this._commandService=r,this._univerInstanceService=i,this._threadCommentModel=a,this._userManagerService=o}_getRef(){var e;return w(((e=this._parent)==null?void 0:e.ref)||this._thread.ref).range}getIsRoot(){return!this._parent}getCommentData(){let{children:e,...t}=this._thread;return t}getReplies(){var e;let t=this._getRef(),n=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,t.startRow,t.startColumn);return n==null||(e=n.children)==null?void 0:e.map(e=>this._injector.createInstance(P,e))}getRange(){let e=this._univerInstanceService.getUnit(this._thread.unitId,l.UNIVER_SHEET);if(!e)return null;let t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;let n=this._getRef();return this._injector.createInstance(m,e,t,n)}getContent(){return this._thread.text}getRichText(){let e=this._thread.text;return s.create({body:e,documentStyle:{},id:`d`})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?y.id:v.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(e){let t=e instanceof s?e.getData().body:e,n=C();return await this._commandService.executeCommand(S.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:n}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(b.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e==null?!this._thread.resolved:e})}replyAsync(e){var t;let n=e.build();return this._commandService.executeCommand(_.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:d(),parentId:this._thread.id,threadId:this._thread.threadId,ref:((t=this._parent)==null?void 0:t.ref)||this._thread.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:n.text,attachments:n.attachments,dT:n.dT||C(),personId:n.personId||this._userManagerService.getCurrentUser().userID}})}};L=P=N([M(2,r(i)),M(3,t),M(4,n),M(5,r(p)),M(6,r(u))],L);var R=class extends m{getComment(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=e.getByLocation(t,n,this._range.startRow,this._range.startColumn);if(!r)return null;let i=e.getComment(t,n,r);return i?this._injector.createInstance(L,i):null}getComments(){let e=this._injector.get(p),t=this._workbook.getUnitId(),n=this._worksheet.getSheetId(),r=[];return a.foreach(this._range,(i,a)=>{let o=e.getByLocation(t,n,i,a);if(o){let i=e.getComment(t,n,o);i&&r.push(this._injector.createInstance(L,i))}}),r}addComment(e){var n;let r=this._injector,i=(n=this.getComment())==null?void 0:n.getCommentData(),a=r.get(t),o=r.get(u),s=this._workbook.getUnitId(),l=this._worksheet.getSheetId(),f=`${c.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,p=o.getCurrentUser(),m=e instanceof I?e.build():{text:e};return a.executeCommand(_.id,{unitId:s,subUnitId:l,comment:{text:m.text,dT:m.dT||C(),attachments:[],id:m.id||d(),ref:f,personId:m.personId||p.userID,parentId:i==null?void 0:i.id,unitId:s,subUnitId:l,threadId:(i==null?void 0:i.threadId)||d()}})}clearComment(){var e;let n=this._injector,r=(e=this.getComment())==null?void 0:e.getCommentData(),i=n.get(t),a=this._workbook.getUnitId(),o=this._worksheet.getSheetId();return r?i.executeCommand(y.id,{unitId:a,subUnitId:o,threadId:r.threadId,commentId:r.id}):Promise.resolve(!0)}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}addCommentAsync(e){return this.addComment(e)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};m.extend(R);var z=class extends h{_initialize(){Object.defineProperty(this,`_threadCommentModel`,{get(){return this._injector.get(x)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(L,e.root))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onThreadCommentChange(e){return f(this._threadCommentModel.commentUpdate$.pipe(T(e=>e.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===_.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeAddThreadComment`)}}))}onBeforeUpdateThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===S.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeUpdateThreadComment`)}}))}onBeforeDeleteThreadComment(e){return f(this._commandService.beforeCommandExecuted((t,n)=>{let r=t.params;if(t.id===v.id||t.id===y.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,n)===!1)throw Error(`Command is stopped by the hook onBeforeDeleteThreadComment`)}}))}};h.extend(z);var B=class extends g{getComments(){return this._injector.get(p).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>this._injector.createInstance(L,e))}clearComments(){let e=this.getComments().map(e=>e.deleteAsync());return Promise.all(e).then(()=>!0)}onCommented(e){return this._injector.get(t).onCommandExecuted(t=>{if(t.id===_.id){let n=t.params;e(n)}})}getCommentById(e){let t=this._injector.get(p).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(t)return this._injector.createInstance(L,t)}};g.extend(B);var V=class extends E{get CommentAdded(){return`CommentAdded`}get BeforeCommentAdd(){return`BeforeCommentAdd`}get CommentUpdated(){return`CommentUpdated`}get BeforeCommentUpdate(){return`BeforeCommentUpdate`}get CommentDeleted(){return`CommentDeleted`}get BeforeCommentDelete(){return`BeforeCommentDelete`}get CommentResolved(){return`CommentResolved`}get BeforeCommentResolve(){return`BeforeCommentResolve`}};E.extend(V);var H=class extends D{_getTargetSheet(e={}){var t;let n=e.unitId?this.getUniverSheet(e.unitId):(t=this.getActiveWorkbook)==null?void 0:t.call(this);if(!n)return null;let r=e.subUnitId?n.getSheetBySheetId(e.subUnitId):n.getActiveSheet();return r?{workbook:n,worksheet:r}:null}_initialize(n){let r=n.get(t);this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==_.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{comment:c}=e.params,l=s.getCommentById(c.id);if(!l)return;let u={workbook:o,worksheet:s,row:(t=(n=l.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=l.getRange())==null?void 0:i.getColumn())==null?0:r,comment:l};this.fireEvent(this.Event.CommentAdded,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==S.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{payload:c}=e.params,l=s.getCommentById(c.commentId);if(!l)return;let u={workbook:o,worksheet:s,row:(t=(n=l.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=l.getRange())==null?void 0:i.getColumn())==null?0:r,comment:l};this.fireEvent(this.Event.CommentUpdated,u)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted,()=>r.onCommandExecuted(e=>{if(e.id!==v.id&&e.id!==y.id)return;let t=this._getTargetSheet(e.params);if(!t)return;let{workbook:n,worksheet:r}=t,{commentId:i}=e.params,a={workbook:n,worksheet:r,commentId:i};this.fireEvent(this.Event.CommentDeleted,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved,()=>r.onCommandExecuted(e=>{var t,n,r,i;if(e.id!==b.id)return;let a=this._getTargetSheet(e.params);if(!a)return;let{workbook:o,worksheet:s}=a,{commentId:c,resolved:l}=e.params,u=s.getCommentById(c);if(!u)return;let d={workbook:o,worksheet:s,row:(t=(n=u.getRange())==null?void 0:n.getRow())==null?0:t,col:(r=(i=u.getRange())==null?void 0:i.getColumn())==null?0:r,comment:u,resolved:l};this.fireEvent(this.Event.CommentResolved,d)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd,()=>r.beforeCommandExecuted(t=>{if(t.id!==_.id)return;let n=this._getTargetSheet(t.params);if(!n)return;let{workbook:r,worksheet:i}=n,{comment:a}=t.params,{range:o}=w(a.ref),s={workbook:r,worksheet:i,row:o.startRow,col:o.startColumn,comment:F.create(a)};if(this.fireEvent(this.Event.BeforeCommentAdd,s),s.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate,()=>r.beforeCommandExecuted(t=>{var n,r,i,a;if(t.id!==S.id)return;let o=this._getTargetSheet(t.params);if(!o)return;let{workbook:c,worksheet:l}=o,{payload:u}=t.params,d=l.getCommentById(u.commentId);if(!d)return;let f={workbook:c,worksheet:l,row:(n=(r=d.getRange())==null?void 0:r.getRow())==null?0:n,col:(i=(a=d.getRange())==null?void 0:a.getColumn())==null?0:i,comment:d,newContent:s.createByBody(u.text)};if(this.fireEvent(this.Event.BeforeCommentUpdate,f),f.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete,()=>r.beforeCommandExecuted(t=>{var n,r,i,a;if(t.id!==v.id&&t.id!==y.id)return;let o=this._getTargetSheet(t.params);if(!o)return;let{workbook:s,worksheet:c}=o,{commentId:l}=t.params,u=c.getCommentById(l);if(!u)return;let d={workbook:s,worksheet:c,row:(n=(r=u.getRange())==null?void 0:r.getRow())==null?0:n,col:(i=(a=u.getRange())==null?void 0:a.getColumn())==null?0:i,comment:u};if(this.fireEvent(this.Event.BeforeCommentDelete,d),d.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve,()=>r.beforeCommandExecuted(t=>{var n,r;if(t.id!==b.id)return;let i=this._getTargetSheet(t.params);if(!i)return;let{workbook:a,worksheet:o}=i,{commentId:s,resolved:c}=t.params,l=o.getCommentById(s);if(!l)return;let u={workbook:a,worksheet:o,row:(n=l.getRange().getRow())==null?0:n,col:(r=l.getRange().getColumn())==null?0:r,comment:l,resolved:c};if(this.fireEvent(this.Event.BeforeCommentResolve,u),u.cancel)throw new e})))}newTheadComment(e){return new I(e)}};D.extend(H);export{L as FThreadComment};
1
+ import { CanceledError, ICommandService, IUniverInstanceService, Inject, Injector, Range, RichTextBuilder, RichTextValue, Tools, UniverInstanceType, UserManagerService, generateRandomId, toDisposable } from "@univerjs/core";
2
+ import { SheetsThreadCommentModel } from "@univerjs/sheets-thread-comment";
3
+ import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
4
+ import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, ThreadCommentModel, UpdateCommentCommand, getDT } from "@univerjs/thread-comment";
5
+ import { deserializeRangeWithSheet } from "@univerjs/engine-formula";
6
+ import { filter } from "rxjs";
7
+ import { FEventName, FUniver } from "@univerjs/core/facade";
8
+
9
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
10
+ function _typeof(o) {
11
+ "@babel/helpers - typeof";
12
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
13
+ return typeof o;
14
+ } : function(o) {
15
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
16
+ }, _typeof(o);
17
+ }
18
+
19
+ //#endregion
20
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
21
+ function toPrimitive(t, r) {
22
+ if ("object" != _typeof(t) || !t) return t;
23
+ var e = t[Symbol.toPrimitive];
24
+ if (void 0 !== e) {
25
+ var i = e.call(t, r || "default");
26
+ if ("object" != _typeof(i)) return i;
27
+ throw new TypeError("@@toPrimitive must return a primitive value.");
28
+ }
29
+ return ("string" === r ? String : Number)(t);
30
+ }
31
+
32
+ //#endregion
33
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
34
+ function toPropertyKey(t) {
35
+ var i = toPrimitive(t, "string");
36
+ return "symbol" == _typeof(i) ? i : i + "";
37
+ }
38
+
39
+ //#endregion
40
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
41
+ function _defineProperty(e, r, t) {
42
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
43
+ value: t,
44
+ enumerable: !0,
45
+ configurable: !0,
46
+ writable: !0
47
+ }) : e[r] = t, e;
48
+ }
49
+
50
+ //#endregion
51
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
52
+ function __decorateParam(paramIndex, decorator) {
53
+ return function(target, key) {
54
+ decorator(target, key, paramIndex);
55
+ };
56
+ }
57
+
58
+ //#endregion
59
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
60
+ function __decorate(decorators, target, key, desc) {
61
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
62
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
63
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
64
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
65
+ }
66
+
67
+ //#endregion
68
+ //#region src/facade/f-thread-comment.ts
69
+ var _FThreadComment;
70
+ /**
71
+ * An readonly class that represents a comment.
72
+ * @ignore
73
+ */
74
+ var FTheadCommentItem = class FTheadCommentItem {
75
+ /**
76
+ * Create a new FTheadCommentItem
77
+ * @param {IThreadComment|undefined} comment The comment
78
+ * @returns {FTheadCommentItem} A new instance of FTheadCommentItem
79
+ * @example
80
+ * ```ts
81
+ * const commentBuilder = univerAPI.newTheadComment();
82
+ * console.log(commentBuilder);
83
+ * ```
84
+ */
85
+ static create(comment) {
86
+ return new FTheadCommentItem(comment);
87
+ }
88
+ constructor(comment) {
89
+ _defineProperty(this, "_comment", {
90
+ id: generateRandomId(),
91
+ ref: "",
92
+ threadId: "",
93
+ dT: "",
94
+ personId: "",
95
+ text: RichTextBuilder.newEmptyData().body,
96
+ attachments: [],
97
+ unitId: "",
98
+ subUnitId: ""
99
+ });
100
+ if (comment) this._comment = comment;
101
+ }
102
+ /**
103
+ * Get the person id of the comment
104
+ * @returns {string} The person id of the comment
105
+ * @example
106
+ * ```ts
107
+ * const commentBuilder = univerAPI.newTheadComment();
108
+ * console.log(commentBuilder.personId);
109
+ * ```
110
+ */
111
+ get personId() {
112
+ return this._comment.personId;
113
+ }
114
+ /**
115
+ * Get the date time of the comment
116
+ * @returns {string} The date time of the comment
117
+ * @example
118
+ * ```ts
119
+ * const commentBuilder = univerAPI.newTheadComment();
120
+ * console.log(commentBuilder.dateTime);
121
+ * ```
122
+ */
123
+ get dateTime() {
124
+ return this._comment.dT;
125
+ }
126
+ /**
127
+ * Get the content of the comment
128
+ * @returns {RichTextValue} The content of the comment
129
+ * @example
130
+ * ```ts
131
+ * const commentBuilder = univerAPI.newTheadComment();
132
+ * console.log(commentBuilder.content);
133
+ * ```
134
+ */
135
+ get content() {
136
+ return RichTextValue.createByBody(this._comment.text);
137
+ }
138
+ /**
139
+ * Get the id of the comment
140
+ * @returns {string} The id of the comment
141
+ * @example
142
+ * ```ts
143
+ * const commentBuilder = univerAPI.newTheadComment();
144
+ * console.log(commentBuilder.id);
145
+ * ```
146
+ */
147
+ get id() {
148
+ return this._comment.id;
149
+ }
150
+ /**
151
+ * Get the thread id of the comment
152
+ * @returns {string} The thread id of the comment
153
+ * @example
154
+ * ```ts
155
+ * const commentBuilder = univerAPI.newTheadComment();
156
+ * console.log(commentBuilder.threadId);
157
+ * ```
158
+ */
159
+ get threadId() {
160
+ return this._comment.threadId;
161
+ }
162
+ /**
163
+ * Copy the comment
164
+ * @returns {FTheadCommentBuilder} The comment builder
165
+ * @example
166
+ * ```ts
167
+ * const commentBuilder = univerAPI.newTheadComment();
168
+ * const newCommentBuilder = commentBuilder.copy();
169
+ * console.log(newCommentBuilder);
170
+ * ```
171
+ */
172
+ copy() {
173
+ return FTheadCommentBuilder.create(Tools.deepClone(this._comment));
174
+ }
175
+ };
176
+ /**
177
+ * A builder for thread comment. use {@link FUniver} `univerAPI.newTheadComment()` to create a new builder.
178
+ */
179
+ var FTheadCommentBuilder = class FTheadCommentBuilder extends FTheadCommentItem {
180
+ static create(comment) {
181
+ return new FTheadCommentBuilder(comment);
182
+ }
183
+ /**
184
+ * Set the content of the comment
185
+ * @param {IDocumentBody | RichTextValue} content The content of the comment
186
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
187
+ * @example
188
+ * ```ts
189
+ * // Create a new comment
190
+ * const richText = univerAPI.newRichText().insertText('hello univer');
191
+ * const commentBuilder = univerAPI.newTheadComment()
192
+ * .setContent(richText);
193
+ * console.log(commentBuilder.content);
194
+ *
195
+ * // Add the comment to the cell A1
196
+ * const fWorkbook = univerAPI.getActiveWorkbook();
197
+ * const fWorksheet = fWorkbook.getActiveSheet();
198
+ * const cell = fWorksheet.getRange('A1');
199
+ * const result = await cell.addCommentAsync(commentBuilder);
200
+ * console.log(result);
201
+ * ```
202
+ */
203
+ setContent(content) {
204
+ if (content instanceof RichTextValue) this._comment.text = content.getData().body;
205
+ else this._comment.text = content;
206
+ return this;
207
+ }
208
+ /**
209
+ * Set the person id of the comment
210
+ * @param {string} userId The person id of the comment
211
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
212
+ * @example
213
+ * ```ts
214
+ * // Create a new comment
215
+ * const richText = univerAPI.newRichText().insertText('hello univer');
216
+ * const commentBuilder = univerAPI.newTheadComment()
217
+ * .setContent(richText)
218
+ * .setPersonId('mock-user-id');
219
+ * console.log(commentBuilder.personId);
220
+ *
221
+ * // Add the comment to the cell A1
222
+ * const fWorkbook = univerAPI.getActiveWorkbook();
223
+ * const fWorksheet = fWorkbook.getActiveSheet();
224
+ * const cell = fWorksheet.getRange('A1');
225
+ * const result = await cell.addCommentAsync(commentBuilder);
226
+ * console.log(result);
227
+ * ```
228
+ */
229
+ setPersonId(userId) {
230
+ this._comment.personId = userId;
231
+ return this;
232
+ }
233
+ /**
234
+ * Set the date time of the comment
235
+ * @param {Date} date The date time of the comment
236
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
237
+ * @example
238
+ * ```ts
239
+ * // Create a new comment
240
+ * const richText = univerAPI.newRichText().insertText('hello univer');
241
+ * const commentBuilder = univerAPI.newTheadComment()
242
+ * .setContent(richText)
243
+ * .setDateTime(new Date('2025-02-21 14:22:22'));
244
+ * console.log(commentBuilder.dateTime);
245
+ *
246
+ * // Add the comment to the cell A1
247
+ * const fWorkbook = univerAPI.getActiveWorkbook();
248
+ * const fWorksheet = fWorkbook.getActiveSheet();
249
+ * const cell = fWorksheet.getRange('A1');
250
+ * const result = await cell.addCommentAsync(commentBuilder);
251
+ * console.log(result);
252
+ * ```
253
+ */
254
+ setDateTime(date) {
255
+ this._comment.dT = getDT(date);
256
+ return this;
257
+ }
258
+ /**
259
+ * Set the id of the comment
260
+ * @param {string} id The id of the comment
261
+ * @returns {FTheadCommentBuilder} The comment builder for chaining
262
+ * @example
263
+ * ```ts
264
+ * // Create a new comment
265
+ * const richText = univerAPI.newRichText().insertText('hello univer');
266
+ * const commentBuilder = univerAPI.newTheadComment()
267
+ * .setContent(richText)
268
+ * .setId('mock-comment-id');
269
+ * console.log(commentBuilder.id);
270
+ *
271
+ * // Add the comment to the cell A1
272
+ * const fWorkbook = univerAPI.getActiveWorkbook();
273
+ * const fWorksheet = fWorkbook.getActiveSheet();
274
+ * const cell = fWorksheet.getRange('A1');
275
+ * const result = await cell.addCommentAsync(commentBuilder);
276
+ * console.log(result);
277
+ * ```
278
+ */
279
+ setId(id) {
280
+ this._comment.id = id;
281
+ return this;
282
+ }
283
+ /**
284
+ * Set the thread id of the comment
285
+ * @param {string} threadId The thread id of the comment
286
+ * @returns {FTheadCommentBuilder} The comment builder
287
+ * @example
288
+ * ```ts
289
+ * // Create a new comment
290
+ * const richText = univerAPI.newRichText().insertText('hello univer');
291
+ * const commentBuilder = univerAPI.newTheadComment()
292
+ * .setContent(richText)
293
+ * .setThreadId('mock-thread-id');
294
+ * console.log(commentBuilder.threadId);
295
+ *
296
+ * // Add the comment to the cell A1
297
+ * const fWorkbook = univerAPI.getActiveWorkbook();
298
+ * const fWorksheet = fWorkbook.getActiveSheet();
299
+ * const cell = fWorksheet.getRange('A1');
300
+ * const result = await cell.addCommentAsync(commentBuilder);
301
+ * console.log(result);
302
+ * ```
303
+ */
304
+ setThreadId(threadId) {
305
+ this._comment.threadId = threadId;
306
+ return this;
307
+ }
308
+ /**
309
+ * Build the comment
310
+ * @returns {IThreadComment} The comment
311
+ * @example
312
+ * ```ts
313
+ * const richText = univerAPI.newRichText().insertText('hello univer');
314
+ * const comment = univerAPI.newTheadComment()
315
+ * .setContent(richText)
316
+ * .setPersonId('mock-user-id')
317
+ * .setDateTime(new Date('2025-02-21 14:22:22'))
318
+ * .setId('mock-comment-id')
319
+ * .setThreadId('mock-thread-id')
320
+ * .build();
321
+ * console.log(comment);
322
+ * ```
323
+ */
324
+ build() {
325
+ return this._comment;
326
+ }
327
+ };
328
+ let FThreadComment = _FThreadComment = class FThreadComment {
329
+ /**
330
+ * @ignore
331
+ */
332
+ constructor(_thread, _parent, _injector, _commandService, _univerInstanceService, _threadCommentModel, _userManagerService) {
333
+ this._thread = _thread;
334
+ this._parent = _parent;
335
+ this._injector = _injector;
336
+ this._commandService = _commandService;
337
+ this._univerInstanceService = _univerInstanceService;
338
+ this._threadCommentModel = _threadCommentModel;
339
+ this._userManagerService = _userManagerService;
340
+ }
341
+ _getRef() {
342
+ var _this$_parent;
343
+ return deserializeRangeWithSheet(((_this$_parent = this._parent) === null || _this$_parent === void 0 ? void 0 : _this$_parent.ref) || this._thread.ref).range;
344
+ }
345
+ /**
346
+ * Whether the comment is a root comment
347
+ * @returns {boolean} Whether the comment is a root comment
348
+ * @example
349
+ * ```ts
350
+ * const fWorkbook = univerAPI.getActiveWorkbook();
351
+ * const fWorksheet = fWorkbook.getActiveSheet();
352
+ * const comments = fWorksheet.getComments();
353
+ * comments.forEach((comment) => {
354
+ * console.log(comment.getIsRoot());
355
+ * });
356
+ * ```
357
+ */
358
+ getIsRoot() {
359
+ return !this._parent;
360
+ }
361
+ /**
362
+ * Get the comment data
363
+ * @returns {IBaseComment} The comment data
364
+ * @example
365
+ * ```ts
366
+ * const fWorkbook = univerAPI.getActiveWorkbook();
367
+ * const fWorksheet = fWorkbook.getActiveSheet();
368
+ * const comments = fWorksheet.getComments();
369
+ * comments.forEach((comment) => {
370
+ * console.log(comment.getCommentData());
371
+ * });
372
+ * ```
373
+ */
374
+ getCommentData() {
375
+ const { children, ...comment } = this._thread;
376
+ return comment;
377
+ }
378
+ /**
379
+ * Get the replies of the comment
380
+ * @returns {FThreadComment[]} the replies of the comment
381
+ * @example
382
+ * ```ts
383
+ * const fWorkbook = univerAPI.getActiveWorkbook();
384
+ * const fWorksheet = fWorkbook.getActiveSheet();
385
+ * const comments = fWorksheet.getComments();
386
+ * comments.forEach((comment) => {
387
+ * if (comment.getIsRoot()) {
388
+ * const replies = comment.getReplies();
389
+ * replies.forEach((reply) => {
390
+ * console.log(reply.getCommentData());
391
+ * });
392
+ * }
393
+ * });
394
+ * ```
395
+ */
396
+ getReplies() {
397
+ var _comments$children;
398
+ const range = this._getRef();
399
+ const comments = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, range.startRow, range.startColumn);
400
+ return comments === null || comments === void 0 || (_comments$children = comments.children) === null || _comments$children === void 0 ? void 0 : _comments$children.map((child) => this._injector.createInstance(_FThreadComment, child));
401
+ }
402
+ /**
403
+ * Get the range of the comment
404
+ * @returns {FRange | null} The range of the comment
405
+ * @example
406
+ * ```ts
407
+ * const fWorkbook = univerAPI.getActiveWorkbook();
408
+ * const fWorksheet = fWorkbook.getActiveSheet();
409
+ * const comments = fWorksheet.getComments();
410
+ * comments.forEach((comment) => {
411
+ * console.log(comment.getRange().getA1Notation());
412
+ * });
413
+ * ```
414
+ */
415
+ getRange() {
416
+ const workbook = this._univerInstanceService.getUnit(this._thread.unitId, UniverInstanceType.UNIVER_SHEET);
417
+ if (!workbook) return null;
418
+ const worksheet = workbook.getSheetBySheetId(this._thread.subUnitId);
419
+ if (!worksheet) return null;
420
+ const range = this._getRef();
421
+ return this._injector.createInstance(FRange, workbook, worksheet, range);
422
+ }
423
+ /**
424
+ * @deprecated use `getRichText` as instead
425
+ */
426
+ getContent() {
427
+ return this._thread.text;
428
+ }
429
+ /**
430
+ * Get the rich text of the comment
431
+ * @returns {RichTextValue} The rich text of the comment
432
+ * @example
433
+ * ```ts
434
+ * const fWorkbook = univerAPI.getActiveWorkbook();
435
+ * const fWorksheet = fWorkbook.getActiveSheet();
436
+ * const comments = fWorksheet.getComments();
437
+ * comments.forEach((comment) => {
438
+ * console.log(comment.getRichText());
439
+ * });
440
+ * ```
441
+ */
442
+ getRichText() {
443
+ const body = this._thread.text;
444
+ return RichTextValue.create({
445
+ body,
446
+ documentStyle: {},
447
+ id: "d"
448
+ });
449
+ }
450
+ /**
451
+ * Delete the comment and it's replies
452
+ * @returns {Promise<boolean>} Whether the comment is deleted successfully
453
+ * @example
454
+ * ```ts
455
+ * const fWorkbook = univerAPI.getActiveWorkbook();
456
+ * const fWorksheet = fWorkbook.getActiveSheet();
457
+ * const comments = fWorksheet.getComments();
458
+ *
459
+ * // Delete the first comment
460
+ * const result = await comments[0]?.deleteAsync();
461
+ * console.log(result);
462
+ * ```
463
+ */
464
+ deleteAsync() {
465
+ return this._commandService.executeCommand(this.getIsRoot() ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id, {
466
+ commentId: this._thread.id,
467
+ unitId: this._thread.unitId,
468
+ subUnitId: this._thread.subUnitId
469
+ });
470
+ }
471
+ /**
472
+ * @deprecated use `deleteAsync` as instead.
473
+ */
474
+ delete() {
475
+ return this.deleteAsync();
476
+ }
477
+ /**
478
+ * @deprecated use `updateAsync` as instead
479
+ */
480
+ async update(content) {
481
+ return this.updateAsync(content);
482
+ }
483
+ /**
484
+ * Update the comment content
485
+ * @param {IDocumentBody | RichTextValue} content The new content of the comment
486
+ * @returns {Promise<boolean>} Whether the comment is updated successfully
487
+ * @example
488
+ * ```ts
489
+ * const fWorkbook = univerAPI.getActiveWorkbook();
490
+ * const fWorksheet = fWorkbook.getActiveSheet();
491
+ *
492
+ * // Create a new comment
493
+ * const richText = univerAPI.newRichText().insertText('hello univer');
494
+ * const commentBuilder = univerAPI.newTheadComment()
495
+ * .setContent(richText)
496
+ * .setId('mock-comment-id');
497
+ * const cell = fWorksheet.getRange('A1');
498
+ * await cell.addCommentAsync(commentBuilder);
499
+ *
500
+ * // Update the comment after 3 seconds
501
+ * setTimeout(async () => {
502
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
503
+ * const newRichText = univerAPI.newRichText().insertText('Hello Univer AI');
504
+ * const result = await comment.updateAsync(newRichText);
505
+ * console.log(result);
506
+ * }, 3000);
507
+ * ```
508
+ */
509
+ async updateAsync(content) {
510
+ const body = content instanceof RichTextValue ? content.getData().body : content;
511
+ const dt = getDT();
512
+ return await this._commandService.executeCommand(UpdateCommentCommand.id, {
513
+ unitId: this._thread.unitId,
514
+ subUnitId: this._thread.subUnitId,
515
+ payload: {
516
+ commentId: this._thread.id,
517
+ text: body,
518
+ updated: true,
519
+ updateT: dt
520
+ }
521
+ });
522
+ }
523
+ /**
524
+ * @deprecated use `resolveAsync` as instead
525
+ */
526
+ resolve(resolved) {
527
+ return this.resolveAsync(resolved);
528
+ }
529
+ /**
530
+ * Resolve the comment
531
+ * @param {boolean} resolved Whether the comment is resolved
532
+ * @returns {Promise<boolean>} Set the comment to resolved or not operation result
533
+ * @example
534
+ * ```ts
535
+ * const fWorkbook = univerAPI.getActiveWorkbook();
536
+ * const fWorksheet = fWorkbook.getActiveSheet();
537
+ *
538
+ * // Create a new comment
539
+ * const richText = univerAPI.newRichText().insertText('hello univer');
540
+ * const commentBuilder = univerAPI.newTheadComment()
541
+ * .setContent(richText)
542
+ * .setId('mock-comment-id');
543
+ * const cell = fWorksheet.getRange('A1');
544
+ * await cell.addCommentAsync(commentBuilder);
545
+ *
546
+ * // Resolve the comment after 3 seconds
547
+ * setTimeout(async () => {
548
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
549
+ * const result = await comment.resolveAsync(true);
550
+ * console.log(result);
551
+ * }, 3000);
552
+ * ```
553
+ */
554
+ resolveAsync(resolved) {
555
+ return this._commandService.executeCommand(ResolveCommentCommand.id, {
556
+ unitId: this._thread.unitId,
557
+ subUnitId: this._thread.subUnitId,
558
+ commentId: this._thread.id,
559
+ resolved: resolved !== null && resolved !== void 0 ? resolved : !this._thread.resolved
560
+ });
561
+ }
562
+ /**
563
+ * Reply to the comment
564
+ * @param {FTheadCommentBuilder} comment The comment to reply to
565
+ * @returns {Promise<boolean>} Whether the comment is replied successfully
566
+ * @example
567
+ * ```ts
568
+ * const fWorkbook = univerAPI.getActiveWorkbook();
569
+ * const fWorksheet = fWorkbook.getActiveSheet();
570
+ *
571
+ * // Create a new comment
572
+ * const richText = univerAPI.newRichText().insertText('hello univer');
573
+ * const commentBuilder = univerAPI.newTheadComment()
574
+ * .setContent(richText)
575
+ * .setId('mock-comment-id');
576
+ * const cell = fWorksheet.getRange('A1');
577
+ * await cell.addCommentAsync(commentBuilder);
578
+ *
579
+ * // Reply to the comment
580
+ * const replyText = univerAPI.newRichText().insertText('Hello Univer AI');
581
+ * const reply = univerAPI.newTheadComment().setContent(replyText);
582
+ * const comment = fWorksheet.getCommentById('mock-comment-id');
583
+ * const result = await comment.replyAsync(reply);
584
+ * console.log(result);
585
+ * ```
586
+ */
587
+ replyAsync(comment) {
588
+ var _this$_parent2;
589
+ const commentData = comment.build();
590
+ return this._commandService.executeCommand(AddCommentCommand.id, {
591
+ unitId: this._thread.unitId,
592
+ subUnitId: this._thread.subUnitId,
593
+ comment: {
594
+ id: generateRandomId(),
595
+ parentId: this._thread.id,
596
+ threadId: this._thread.threadId,
597
+ ref: ((_this$_parent2 = this._parent) === null || _this$_parent2 === void 0 ? void 0 : _this$_parent2.ref) || this._thread.ref,
598
+ unitId: this._thread.unitId,
599
+ subUnitId: this._thread.subUnitId,
600
+ text: commentData.text,
601
+ attachments: commentData.attachments,
602
+ dT: commentData.dT || getDT(),
603
+ personId: commentData.personId || this._userManagerService.getCurrentUser().userID
604
+ }
605
+ });
606
+ }
607
+ };
608
+ FThreadComment = _FThreadComment = __decorate([
609
+ __decorateParam(2, Inject(Injector)),
610
+ __decorateParam(3, ICommandService),
611
+ __decorateParam(4, IUniverInstanceService),
612
+ __decorateParam(5, Inject(SheetsThreadCommentModel)),
613
+ __decorateParam(6, Inject(UserManagerService))
614
+ ], FThreadComment);
615
+
616
+ //#endregion
617
+ //#region src/facade/f-range.ts
618
+ /**
619
+ * @ignore
620
+ */
621
+ var FRangeSheetsThreadCommentMixin = class extends FRange {
622
+ getComment() {
623
+ const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
624
+ const unitId = this._workbook.getUnitId();
625
+ const sheetId = this._worksheet.getSheetId();
626
+ const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
627
+ if (!commentId) return null;
628
+ const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
629
+ if (comment) return this._injector.createInstance(FThreadComment, comment);
630
+ return null;
631
+ }
632
+ getComments() {
633
+ const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
634
+ const unitId = this._workbook.getUnitId();
635
+ const sheetId = this._worksheet.getSheetId();
636
+ const comments = [];
637
+ Range.foreach(this._range, (row, col) => {
638
+ const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, row, col);
639
+ if (commentId) {
640
+ const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
641
+ if (comment) comments.push(this._injector.createInstance(FThreadComment, comment));
642
+ }
643
+ });
644
+ return comments;
645
+ }
646
+ addComment(content) {
647
+ var _this$getComment;
648
+ const injector = this._injector;
649
+ const currentComment = (_this$getComment = this.getComment()) === null || _this$getComment === void 0 ? void 0 : _this$getComment.getCommentData();
650
+ const commentService = injector.get(ICommandService);
651
+ const userService = injector.get(UserManagerService);
652
+ const unitId = this._workbook.getUnitId();
653
+ const sheetId = this._worksheet.getSheetId();
654
+ const refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
655
+ const currentUser = userService.getCurrentUser();
656
+ const commentData = content instanceof FTheadCommentBuilder ? content.build() : { text: content };
657
+ return commentService.executeCommand(AddCommentCommand.id, {
658
+ unitId,
659
+ subUnitId: sheetId,
660
+ comment: {
661
+ text: commentData.text,
662
+ dT: commentData.dT || getDT(),
663
+ attachments: [],
664
+ id: commentData.id || generateRandomId(),
665
+ ref: refStr,
666
+ personId: commentData.personId || currentUser.userID,
667
+ parentId: currentComment === null || currentComment === void 0 ? void 0 : currentComment.id,
668
+ unitId,
669
+ subUnitId: sheetId,
670
+ threadId: (currentComment === null || currentComment === void 0 ? void 0 : currentComment.threadId) || generateRandomId()
671
+ }
672
+ });
673
+ }
674
+ clearComment() {
675
+ var _this$getComment2;
676
+ const injector = this._injector;
677
+ const currentComment = (_this$getComment2 = this.getComment()) === null || _this$getComment2 === void 0 ? void 0 : _this$getComment2.getCommentData();
678
+ const commentService = injector.get(ICommandService);
679
+ const unitId = this._workbook.getUnitId();
680
+ const sheetId = this._worksheet.getSheetId();
681
+ if (currentComment) return commentService.executeCommand(DeleteCommentTreeCommand.id, {
682
+ unitId,
683
+ subUnitId: sheetId,
684
+ threadId: currentComment.threadId,
685
+ commentId: currentComment.id
686
+ });
687
+ return Promise.resolve(true);
688
+ }
689
+ clearComments() {
690
+ const promises = this.getComments().map((comment) => comment.deleteAsync());
691
+ return Promise.all(promises).then(() => true);
692
+ }
693
+ addCommentAsync(content) {
694
+ return this.addComment(content);
695
+ }
696
+ clearCommentAsync() {
697
+ return this.clearComment();
698
+ }
699
+ clearCommentsAsync() {
700
+ return this.clearComments();
701
+ }
702
+ };
703
+ FRange.extend(FRangeSheetsThreadCommentMixin);
704
+
705
+ //#endregion
706
+ //#region src/facade/f-workbook.ts
707
+ /**
708
+ * @ignore
709
+ */
710
+ var FWorkbookSheetsThreadCommentMixin = class extends FWorkbook {
711
+ /**
712
+ * @ignore
713
+ */
714
+ _initialize() {
715
+ Object.defineProperty(this, "_threadCommentModel", { get() {
716
+ return this._injector.get(ThreadCommentModel);
717
+ } });
718
+ }
719
+ getComments() {
720
+ return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((i) => this._injector.createInstance(FThreadComment, i.root));
721
+ }
722
+ clearComments() {
723
+ const promises = this.getComments().map((comment) => comment.deleteAsync());
724
+ return Promise.all(promises).then(() => true);
725
+ }
726
+ /**
727
+ * @param callback
728
+ * @deprecated
729
+ */
730
+ onThreadCommentChange(callback) {
731
+ return toDisposable(this._threadCommentModel.commentUpdate$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
732
+ }
733
+ /**
734
+ * @param callback
735
+ * @deprecated
736
+ */
737
+ onBeforeAddThreadComment(callback) {
738
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
739
+ const params = commandInfo.params;
740
+ if (commandInfo.id === AddCommentCommand.id) {
741
+ if (params.unitId !== this._workbook.getUnitId()) return;
742
+ if (callback(params, options) === false) throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
743
+ }
744
+ }));
745
+ }
746
+ /**
747
+ * @param callback
748
+ * @deprecated
749
+ */
750
+ onBeforeUpdateThreadComment(callback) {
751
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
752
+ const params = commandInfo.params;
753
+ if (commandInfo.id === UpdateCommentCommand.id) {
754
+ if (params.unitId !== this._workbook.getUnitId()) return;
755
+ if (callback(params, options) === false) throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
756
+ }
757
+ }));
758
+ }
759
+ /**
760
+ * @param callback
761
+ * @deprecated
762
+ */
763
+ onBeforeDeleteThreadComment(callback) {
764
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
765
+ const params = commandInfo.params;
766
+ if (commandInfo.id === DeleteCommentCommand.id || commandInfo.id === DeleteCommentTreeCommand.id) {
767
+ if (params.unitId !== this._workbook.getUnitId()) return;
768
+ if (callback(params, options) === false) throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
769
+ }
770
+ }));
771
+ }
772
+ };
773
+ FWorkbook.extend(FWorkbookSheetsThreadCommentMixin);
774
+
775
+ //#endregion
776
+ //#region src/facade/f-worksheet.ts
777
+ /**
778
+ * @ignore
779
+ */
780
+ var FWorksheetCommentMixin = class extends FWorksheet {
781
+ getComments() {
782
+ return this._injector.get(SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((comment) => this._injector.createInstance(FThreadComment, comment));
783
+ }
784
+ clearComments() {
785
+ const promises = this.getComments().map((comment) => comment.deleteAsync());
786
+ return Promise.all(promises).then(() => true);
787
+ }
788
+ /**
789
+ * Subscribe to comment events.
790
+ * @param callback Callback function, param contains comment info and target cell.
791
+ */
792
+ onCommented(callback) {
793
+ return this._injector.get(ICommandService).onCommandExecuted((command) => {
794
+ if (command.id === AddCommentCommand.id) {
795
+ const params = command.params;
796
+ callback(params);
797
+ }
798
+ });
799
+ }
800
+ getCommentById(commentId) {
801
+ const comment = this._injector.get(SheetsThreadCommentModel).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), commentId);
802
+ if (comment) return this._injector.createInstance(FThreadComment, comment);
803
+ }
804
+ };
805
+ FWorksheet.extend(FWorksheetCommentMixin);
806
+
807
+ //#endregion
808
+ //#region src/facade/f-event.ts
809
+ /**
810
+ * @ignore
811
+ */
812
+ var FSheetsThreadCommentEventNameMixin = class extends FEventName {
813
+ get CommentAdded() {
814
+ return "CommentAdded";
815
+ }
816
+ get BeforeCommentAdd() {
817
+ return "BeforeCommentAdd";
818
+ }
819
+ get CommentUpdated() {
820
+ return "CommentUpdated";
821
+ }
822
+ get BeforeCommentUpdate() {
823
+ return "BeforeCommentUpdate";
824
+ }
825
+ get CommentDeleted() {
826
+ return "CommentDeleted";
827
+ }
828
+ get BeforeCommentDelete() {
829
+ return "BeforeCommentDelete";
830
+ }
831
+ get CommentResolved() {
832
+ return "CommentResolved";
833
+ }
834
+ get BeforeCommentResolve() {
835
+ return "BeforeCommentResolve";
836
+ }
837
+ };
838
+ FEventName.extend(FSheetsThreadCommentEventNameMixin);
839
+
840
+ //#endregion
841
+ //#region src/facade/f-univer.ts
842
+ /**
843
+ * @ignore
844
+ */
845
+ var FUniverSheetsThreadCommentMixin = class extends FUniver {
846
+ _getTargetSheet(params = {}) {
847
+ var _this$getActiveWorkbo;
848
+ const workbook = params.unitId ? this.getUniverSheet(params.unitId) : (_this$getActiveWorkbo = this.getActiveWorkbook) === null || _this$getActiveWorkbo === void 0 ? void 0 : _this$getActiveWorkbo.call(this);
849
+ if (!workbook) return null;
850
+ const worksheet = params.subUnitId ? workbook.getSheetBySheetId(params.subUnitId) : workbook.getActiveSheet();
851
+ if (!worksheet) return null;
852
+ return {
853
+ workbook,
854
+ worksheet
855
+ };
856
+ }
857
+ _initialize(injector) {
858
+ const commandService = injector.get(ICommandService);
859
+ this.disposeWithMe(this.registerEventHandler(this.Event.CommentAdded, () => commandService.onCommandExecuted((commandInfo) => {
860
+ var _threadComment$getRan, _threadComment$getRan2, _threadComment$getRan3, _threadComment$getRan4;
861
+ if (commandInfo.id !== AddCommentCommand.id) return;
862
+ const target = this._getTargetSheet(commandInfo.params);
863
+ if (!target) return;
864
+ const { workbook, worksheet } = target;
865
+ const { comment } = commandInfo.params;
866
+ const threadComment = worksheet.getCommentById(comment.id);
867
+ if (!threadComment) return;
868
+ const eventParams = {
869
+ workbook,
870
+ worksheet,
871
+ row: (_threadComment$getRan = (_threadComment$getRan2 = threadComment.getRange()) === null || _threadComment$getRan2 === void 0 ? void 0 : _threadComment$getRan2.getRow()) !== null && _threadComment$getRan !== void 0 ? _threadComment$getRan : 0,
872
+ col: (_threadComment$getRan3 = (_threadComment$getRan4 = threadComment.getRange()) === null || _threadComment$getRan4 === void 0 ? void 0 : _threadComment$getRan4.getColumn()) !== null && _threadComment$getRan3 !== void 0 ? _threadComment$getRan3 : 0,
873
+ comment: threadComment
874
+ };
875
+ this.fireEvent(this.Event.CommentAdded, eventParams);
876
+ })));
877
+ this.disposeWithMe(this.registerEventHandler(this.Event.CommentUpdated, () => commandService.onCommandExecuted((commandInfo) => {
878
+ var _threadComment$getRan5, _threadComment$getRan6, _threadComment$getRan7, _threadComment$getRan8;
879
+ if (commandInfo.id !== UpdateCommentCommand.id) return;
880
+ const target = this._getTargetSheet(commandInfo.params);
881
+ if (!target) return;
882
+ const { workbook, worksheet } = target;
883
+ const { payload } = commandInfo.params;
884
+ const threadComment = worksheet.getCommentById(payload.commentId);
885
+ if (!threadComment) return;
886
+ const eventParams = {
887
+ workbook,
888
+ worksheet,
889
+ row: (_threadComment$getRan5 = (_threadComment$getRan6 = threadComment.getRange()) === null || _threadComment$getRan6 === void 0 ? void 0 : _threadComment$getRan6.getRow()) !== null && _threadComment$getRan5 !== void 0 ? _threadComment$getRan5 : 0,
890
+ col: (_threadComment$getRan7 = (_threadComment$getRan8 = threadComment.getRange()) === null || _threadComment$getRan8 === void 0 ? void 0 : _threadComment$getRan8.getColumn()) !== null && _threadComment$getRan7 !== void 0 ? _threadComment$getRan7 : 0,
891
+ comment: threadComment
892
+ };
893
+ this.fireEvent(this.Event.CommentUpdated, eventParams);
894
+ })));
895
+ this.disposeWithMe(this.registerEventHandler(this.Event.CommentDeleted, () => commandService.onCommandExecuted((commandInfo) => {
896
+ if (commandInfo.id !== DeleteCommentCommand.id && commandInfo.id !== DeleteCommentTreeCommand.id) return;
897
+ const target = this._getTargetSheet(commandInfo.params);
898
+ if (!target) return;
899
+ const { workbook, worksheet } = target;
900
+ const { commentId } = commandInfo.params;
901
+ const eventParams = {
902
+ workbook,
903
+ worksheet,
904
+ commentId
905
+ };
906
+ this.fireEvent(this.Event.CommentDeleted, eventParams);
907
+ })));
908
+ this.disposeWithMe(this.registerEventHandler(this.Event.CommentResolved, () => commandService.onCommandExecuted((commandInfo) => {
909
+ var _threadComment$getRan9, _threadComment$getRan10, _threadComment$getRan11, _threadComment$getRan12;
910
+ if (commandInfo.id !== ResolveCommentCommand.id) return;
911
+ const target = this._getTargetSheet(commandInfo.params);
912
+ if (!target) return;
913
+ const { workbook, worksheet } = target;
914
+ const { commentId, resolved } = commandInfo.params;
915
+ const threadComment = worksheet.getCommentById(commentId);
916
+ if (!threadComment) return;
917
+ const eventParams = {
918
+ workbook,
919
+ worksheet,
920
+ row: (_threadComment$getRan9 = (_threadComment$getRan10 = threadComment.getRange()) === null || _threadComment$getRan10 === void 0 ? void 0 : _threadComment$getRan10.getRow()) !== null && _threadComment$getRan9 !== void 0 ? _threadComment$getRan9 : 0,
921
+ col: (_threadComment$getRan11 = (_threadComment$getRan12 = threadComment.getRange()) === null || _threadComment$getRan12 === void 0 ? void 0 : _threadComment$getRan12.getColumn()) !== null && _threadComment$getRan11 !== void 0 ? _threadComment$getRan11 : 0,
922
+ comment: threadComment,
923
+ resolved
924
+ };
925
+ this.fireEvent(this.Event.CommentResolved, eventParams);
926
+ })));
927
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentAdd, () => commandService.beforeCommandExecuted((commandInfo) => {
928
+ if (commandInfo.id !== AddCommentCommand.id) return;
929
+ const target = this._getTargetSheet(commandInfo.params);
930
+ if (!target) return;
931
+ const { workbook, worksheet } = target;
932
+ const { comment } = commandInfo.params;
933
+ const { range } = deserializeRangeWithSheet(comment.ref);
934
+ const eventParams = {
935
+ workbook,
936
+ worksheet,
937
+ row: range.startRow,
938
+ col: range.startColumn,
939
+ comment: FTheadCommentItem.create(comment)
940
+ };
941
+ this.fireEvent(this.Event.BeforeCommentAdd, eventParams);
942
+ if (eventParams.cancel) throw new CanceledError();
943
+ })));
944
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
945
+ var _threadComment$getRan13, _threadComment$getRan14, _threadComment$getRan15, _threadComment$getRan16;
946
+ if (commandInfo.id !== UpdateCommentCommand.id) return;
947
+ const target = this._getTargetSheet(commandInfo.params);
948
+ if (!target) return;
949
+ const { workbook, worksheet } = target;
950
+ const { payload } = commandInfo.params;
951
+ const threadComment = worksheet.getCommentById(payload.commentId);
952
+ if (!threadComment) return;
953
+ const eventParams = {
954
+ workbook,
955
+ worksheet,
956
+ row: (_threadComment$getRan13 = (_threadComment$getRan14 = threadComment.getRange()) === null || _threadComment$getRan14 === void 0 ? void 0 : _threadComment$getRan14.getRow()) !== null && _threadComment$getRan13 !== void 0 ? _threadComment$getRan13 : 0,
957
+ col: (_threadComment$getRan15 = (_threadComment$getRan16 = threadComment.getRange()) === null || _threadComment$getRan16 === void 0 ? void 0 : _threadComment$getRan16.getColumn()) !== null && _threadComment$getRan15 !== void 0 ? _threadComment$getRan15 : 0,
958
+ comment: threadComment,
959
+ newContent: RichTextValue.createByBody(payload.text)
960
+ };
961
+ this.fireEvent(this.Event.BeforeCommentUpdate, eventParams);
962
+ if (eventParams.cancel) throw new CanceledError();
963
+ })));
964
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentDelete, () => commandService.beforeCommandExecuted((commandInfo) => {
965
+ var _threadComment$getRan17, _threadComment$getRan18, _threadComment$getRan19, _threadComment$getRan20;
966
+ if (commandInfo.id !== DeleteCommentCommand.id && commandInfo.id !== DeleteCommentTreeCommand.id) return;
967
+ const target = this._getTargetSheet(commandInfo.params);
968
+ if (!target) return;
969
+ const { workbook, worksheet } = target;
970
+ const { commentId } = commandInfo.params;
971
+ const threadComment = worksheet.getCommentById(commentId);
972
+ if (!threadComment) return;
973
+ const eventParams = {
974
+ workbook,
975
+ worksheet,
976
+ row: (_threadComment$getRan17 = (_threadComment$getRan18 = threadComment.getRange()) === null || _threadComment$getRan18 === void 0 ? void 0 : _threadComment$getRan18.getRow()) !== null && _threadComment$getRan17 !== void 0 ? _threadComment$getRan17 : 0,
977
+ col: (_threadComment$getRan19 = (_threadComment$getRan20 = threadComment.getRange()) === null || _threadComment$getRan20 === void 0 ? void 0 : _threadComment$getRan20.getColumn()) !== null && _threadComment$getRan19 !== void 0 ? _threadComment$getRan19 : 0,
978
+ comment: threadComment
979
+ };
980
+ this.fireEvent(this.Event.BeforeCommentDelete, eventParams);
981
+ if (eventParams.cancel) throw new CanceledError();
982
+ })));
983
+ this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommentResolve, () => commandService.beforeCommandExecuted((commandInfo) => {
984
+ var _getRow, _getColumn;
985
+ if (commandInfo.id !== ResolveCommentCommand.id) return;
986
+ const target = this._getTargetSheet(commandInfo.params);
987
+ if (!target) return;
988
+ const { workbook, worksheet } = target;
989
+ const { commentId, resolved } = commandInfo.params;
990
+ const threadComment = worksheet.getCommentById(commentId);
991
+ if (!threadComment) return;
992
+ const eventParams = {
993
+ workbook,
994
+ worksheet,
995
+ row: (_getRow = threadComment.getRange().getRow()) !== null && _getRow !== void 0 ? _getRow : 0,
996
+ col: (_getColumn = threadComment.getRange().getColumn()) !== null && _getColumn !== void 0 ? _getColumn : 0,
997
+ comment: threadComment,
998
+ resolved
999
+ };
1000
+ this.fireEvent(this.Event.BeforeCommentResolve, eventParams);
1001
+ if (eventParams.cancel) throw new CanceledError();
1002
+ })));
1003
+ }
1004
+ /**
1005
+ * @ignore
1006
+ */
1007
+ newTheadComment(comment) {
1008
+ return new FTheadCommentBuilder(comment);
1009
+ }
1010
+ };
1011
+ FUniver.extend(FUniverSheetsThreadCommentMixin);
1012
+
1013
+ //#endregion
1014
+ export { FThreadComment };