@univerjs/sheets-thread-comment 0.5.4 → 0.5.5-experimental.20250123-34738ff

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,31 +1,32 @@
1
- var E = Object.defineProperty;
2
- var P = (r, e, t) => e in r ? E(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var y = (r, e, t) => P(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { Inject as v, Injector as F, UserManagerService as S, UniverInstanceType as W, RichTextValue as l, generateRandomId as g, ICommandService as p, IUniverInstanceService as O, RichTextBuilder as $, Tools as B, Range as z, toDisposable as I, FEventName as R } from "@univerjs/core";
5
- import { SheetsThreadCommentModel as h } from "@univerjs/sheets-thread-comment";
6
- import { FRange as x, FWorkbook as j, FWorksheet as D } from "@univerjs/sheets/facade";
7
- import { DeleteCommentTreeCommand as T, DeleteCommentCommand as A, getDT as f, UpdateCommentCommand as M, ResolveCommentCommand as L, AddCommentCommand as b, ThreadCommentModel as N } from "@univerjs/thread-comment";
8
- import { deserializeRangeWithSheet as V } from "@univerjs/engine-formula";
9
- import { filter as H } from "rxjs";
10
- var q = Object.defineProperty, G = Object.getOwnPropertyDescriptor, J = (r, e, t, n) => {
11
- for (var o = n > 1 ? void 0 : n ? G(e, t) : e, m = r.length - 1, s; m >= 0; m--)
12
- (s = r[m]) && (o = (n ? s(e, t, o) : s(o)) || o);
13
- return n && o && q(e, t, o), o;
14
- }, a = (r, e) => (t, n) => e(t, n, r);
15
- class k {
16
- constructor(e) {
17
- y(this, "_comment", {
18
- id: g(),
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { Inject, Injector, UserManagerService, UniverInstanceType, RichTextValue, generateRandomId, ICommandService, IUniverInstanceService, RichTextBuilder, Tools, Range, toDisposable, FEventName } from "@univerjs/core";
6
+ import { SheetsThreadCommentModel } from "@univerjs/sheets-thread-comment";
7
+ import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
8
+ import { DeleteCommentTreeCommand, DeleteCommentCommand, getDT, UpdateCommentCommand, ResolveCommentCommand, AddCommentCommand, ThreadCommentModel } from "@univerjs/thread-comment";
9
+ import { deserializeRangeWithSheet } from "@univerjs/engine-formula";
10
+ import { filter } from "rxjs";
11
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
12
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
13
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
14
+ return kind && result && __defProp2(target, key, result), result;
15
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
16
+ const _FTheadCommentItem = class _FTheadCommentItem {
17
+ constructor(comment) {
18
+ __publicField(this, "_comment", {
19
+ id: generateRandomId(),
19
20
  ref: "",
20
21
  threadId: "",
21
22
  dT: "",
22
23
  personId: "",
23
- text: $.newEmptyData().body,
24
+ text: RichTextBuilder.newEmptyData().body,
24
25
  attachments: [],
25
26
  unitId: "",
26
27
  subUnitId: ""
27
28
  });
28
- e && (this._comment = e);
29
+ comment && (this._comment = comment);
29
30
  }
30
31
  /**
31
32
  * Create a new FTheadCommentItem
@@ -36,8 +37,8 @@ class k {
36
37
  * const comment = univerAPI.newTheadComment();
37
38
  * ```
38
39
  */
39
- static create(e) {
40
- return new k(e);
40
+ static create(comment) {
41
+ return new _FTheadCommentItem(comment);
41
42
  }
42
43
  /**
43
44
  * Get the person id of the comment
@@ -45,8 +46,8 @@ class k {
45
46
  * @example
46
47
  * ```ts
47
48
  * const comment = univerAPI.getActiveWorkbook()
48
- * .getSheetById(sheetId)
49
- * .getCommentById(commentId);
49
+ * .getSheetById(sheetId)
50
+ * .getCommentById(commentId);
50
51
  * const personId = comment.personId;
51
52
  * ```
52
53
  */
@@ -59,8 +60,8 @@ class k {
59
60
  * @example
60
61
  * ```ts
61
62
  * const comment = univerAPI.getActiveWorkbook()
62
- * .getSheetById(sheetId)
63
- * .getCommentById(commentId);
63
+ * .getSheetById(sheetId)
64
+ * .getCommentById(commentId);
64
65
  * const dateTime = comment.dateTime;
65
66
  * ```
66
67
  */
@@ -73,13 +74,13 @@ class k {
73
74
  * @example
74
75
  * ```ts
75
76
  * const comment = univerAPI.getActiveWorkbook()
76
- * .getSheetById(sheetId)
77
- * .getCommentById(commentId);
77
+ * .getSheetById(sheetId)
78
+ * .getCommentById(commentId);
78
79
  * const content = comment.content;
79
80
  * ```
80
81
  */
81
82
  get content() {
82
- return l.createByBody(this._comment.text);
83
+ return RichTextValue.createByBody(this._comment.text);
83
84
  }
84
85
  /**
85
86
  * Get the id of the comment
@@ -87,8 +88,8 @@ class k {
87
88
  * @example
88
89
  * ```ts
89
90
  * const comment = univerAPI.getActiveWorkbook()
90
- * .getSheetById(sheetId)
91
- * .getCommentById(commentId);
91
+ * .getSheetById(sheetId)
92
+ * .getCommentById(commentId);
92
93
  * const id = comment.id;
93
94
  * ```
94
95
  */
@@ -101,8 +102,8 @@ class k {
101
102
  * @example
102
103
  * ```ts
103
104
  * const comment = univerAPI.getActiveWorkbook()
104
- * .getSheetById(sheetId)
105
- * .getCommentById(commentId);
105
+ * .getSheetById(sheetId)
106
+ * .getCommentById(commentId);
106
107
  * const threadId = comment.threadId;
107
108
  * ```
108
109
  */
@@ -115,18 +116,20 @@ class k {
115
116
  * @example
116
117
  * ```ts
117
118
  * const comment = univerAPI.getActiveWorkbook()
118
- * .getSheetById(sheetId)
119
- * .getCommentById(commentId);
119
+ * .getSheetById(sheetId)
120
+ * .getCommentById(commentId);
120
121
  * const newComment = comment.copy();
121
122
  * ```
122
123
  */
123
124
  copy() {
124
- return U.create(B.deepClone(this._comment));
125
+ return FTheadCommentBuilder.create(Tools.deepClone(this._comment));
125
126
  }
126
- }
127
- class U extends k {
128
- static create(e) {
129
- return new U(e);
127
+ };
128
+ __name(_FTheadCommentItem, "FTheadCommentItem");
129
+ let FTheadCommentItem = _FTheadCommentItem;
130
+ const _FTheadCommentBuilder = class _FTheadCommentBuilder extends FTheadCommentItem {
131
+ static create(comment) {
132
+ return new _FTheadCommentBuilder(comment);
130
133
  }
131
134
  /**
132
135
  * Set the content of the comment
@@ -135,11 +138,11 @@ class U extends k {
135
138
  * @example
136
139
  * ```ts
137
140
  * const comment = univerAPI.newTheadComment()
138
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
141
+ * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
139
142
  * ```
140
143
  */
141
- setContent(e) {
142
- return e instanceof l ? this._comment.text = e.getData().body : this._comment.text = e, this;
144
+ setContent(content) {
145
+ return content instanceof RichTextValue ? this._comment.text = content.getData().body : this._comment.text = content, this;
143
146
  }
144
147
  /**
145
148
  * Set the person id of the comment
@@ -148,11 +151,11 @@ class U extends k {
148
151
  * @example
149
152
  * ```ts
150
153
  * const comment = univerAPI.newTheadComment()
151
- * .setPersonId('123');
154
+ * .setPersonId('123');
152
155
  * ```
153
156
  */
154
- setPersonId(e) {
155
- return this._comment.personId = e, this;
157
+ setPersonId(userId) {
158
+ return this._comment.personId = userId, this;
156
159
  }
157
160
  /**
158
161
  * Set the date time of the comment
@@ -161,11 +164,11 @@ class U extends k {
161
164
  * @example
162
165
  * ```ts
163
166
  * const comment = univerAPI.newTheadComment()
164
- * .setDateTime(new Date());
167
+ * .setDateTime(new Date());
165
168
  * ```
166
169
  */
167
- setDateTime(e) {
168
- return this._comment.dT = f(e), this;
170
+ setDateTime(date) {
171
+ return this._comment.dT = getDT(date), this;
169
172
  }
170
173
  /**
171
174
  * Set the id of the comment
@@ -174,11 +177,11 @@ class U extends k {
174
177
  * @example
175
178
  * ```ts
176
179
  * const comment = univerAPI.newTheadComment()
177
- * .setId('123');
180
+ * .setId('123');
178
181
  * ```
179
182
  */
180
- setId(e) {
181
- return this._comment.id = e, this;
183
+ setId(id) {
184
+ return this._comment.id = id, this;
182
185
  }
183
186
  /**
184
187
  * Set the thread id of the comment
@@ -187,11 +190,11 @@ class U extends k {
187
190
  * @example
188
191
  * ```ts
189
192
  * const comment = univerAPI.newTheadComment()
190
- * .setThreadId('123');
193
+ * .setThreadId('123');
191
194
  * ```
192
195
  */
193
- setThreadId(e) {
194
- return this._comment.threadId = e, this;
196
+ setThreadId(threadId) {
197
+ return this._comment.threadId = threadId, this;
195
198
  }
196
199
  /**
197
200
  * Build the comment
@@ -199,31 +202,37 @@ class U extends k {
199
202
  * @example
200
203
  * ```ts
201
204
  * const comment = univerAPI.newTheadComment()
202
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'))
203
- * .build();
205
+ * .setContent(univerAPI.newRichText().insertText('hello zhangsan'))
206
+ * .build();
204
207
  * ```
205
208
  */
206
209
  build() {
207
210
  return this._comment;
208
211
  }
209
- }
210
- let i = class {
211
- constructor(r, e, t, n, o, m, s) {
212
- this._thread = r, this._parent = e, this._injector = t, this._commandService = n, this._univerInstanceService = o, this._threadCommentModel = m, this._userManagerService = s;
212
+ };
213
+ __name(_FTheadCommentBuilder, "FTheadCommentBuilder");
214
+ let FTheadCommentBuilder = _FTheadCommentBuilder;
215
+ var _a;
216
+ let FThreadComment = (_a = class {
217
+ /**
218
+ * @ignore
219
+ */
220
+ constructor(_thread, _parent, _injector, _commandService, _univerInstanceService, _threadCommentModel, _userManagerService) {
221
+ this._thread = _thread, this._parent = _parent, this._injector = _injector, this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._threadCommentModel = _threadCommentModel, this._userManagerService = _userManagerService;
213
222
  }
214
223
  _getRef() {
215
- var t;
216
- const r = ((t = this._parent) == null ? void 0 : t.ref) || this._thread.ref;
217
- return V(r).range;
224
+ var _a2;
225
+ const ref = ((_a2 = this._parent) == null ? void 0 : _a2.ref) || this._thread.ref;
226
+ return deserializeRangeWithSheet(ref).range;
218
227
  }
219
228
  /**
220
229
  * Whether the comment is a root comment
221
- * @returns Whether the comment is a root comment
230
+ * @returns {boolean} Whether the comment is a root comment
222
231
  * @example
223
232
  * ```ts
224
233
  * const comment = univerAPI.getActiveWorkbook()
225
- * .getSheetById(sheetId)
226
- * .getCommentById(commentId);
234
+ * .getSheetById(sheetId)
235
+ * .getCommentById(commentId);
227
236
  * const isRoot = comment.getIsRoot();
228
237
  * ```
229
238
  */
@@ -232,56 +241,57 @@ let i = class {
232
241
  }
233
242
  /**
234
243
  * Get the comment data
235
- * @returns The comment data
244
+ * @returns {IBaseComment} The comment data
236
245
  * @example
237
246
  * ```ts
238
247
  * const comment = univerAPI.getActiveWorkbook()
239
- * .getSheetById(sheetId)
240
- * .getCommentById(commentId);
248
+ * .getSheetById(sheetId)
249
+ * .getCommentById(commentId);
241
250
  * const commentData = comment.getCommentData();
242
251
  * ```
243
252
  */
244
253
  getCommentData() {
245
- const { children: r, ...e } = this._thread;
246
- return e;
254
+ const { children, ...comment } = this._thread;
255
+ return comment;
247
256
  }
248
257
  /**
249
258
  * Get the replies of the comment
250
- * @returns the replies of the comment
259
+ * @returns {FThreadComment[]} the replies of the comment
251
260
  * @example
252
261
  * ```ts
253
262
  * const comment = univerAPI.getActiveWorkbook()
254
- * .getSheetById(sheetId)
255
- * .getCommentById(commentId);
263
+ * .getSheetById(sheetId)
264
+ * .getCommentById(commentId);
256
265
  * const replies = comment.getReplies();
257
266
  * ```
258
267
  */
259
268
  getReplies() {
260
- var t;
261
- const r = this._getRef(), e = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, r.startRow, r.startColumn);
262
- return (t = e == null ? void 0 : e.children) == null ? void 0 : t.map((n) => this._injector.createInstance(i, n));
269
+ var _a2;
270
+ const range = this._getRef(), comments = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, range.startRow, range.startColumn);
271
+ return (_a2 = comments == null ? void 0 : comments.children) == null ? void 0 : _a2.map((child) => this._injector.createInstance(FThreadComment, child));
263
272
  }
264
273
  /**
265
274
  * Get the range of the comment
266
- * @returns The range of the comment
275
+ * @returns {FRange | null} The range of the comment
267
276
  * @example
268
277
  * ```ts
269
278
  * const comment = univerAPI.getActiveWorkbook()
270
- * .getSheetById(sheetId)
271
- * .getCommentById(commentId);
279
+ * .getSheetById(sheetId)
280
+ * .getCommentById(commentId);
272
281
  * const range = comment.getRange();
273
282
  * ```
274
283
  */
275
284
  getRange() {
276
- const r = this._univerInstanceService.getUnit(this._thread.unitId, W.UNIVER_SHEET);
277
- if (!r)
285
+ const workbook = this._univerInstanceService.getUnit(this._thread.unitId, UniverInstanceType.UNIVER_SHEET);
286
+ if (!workbook)
278
287
  return null;
279
- const e = r.getSheetBySheetId(this._thread.subUnitId);
280
- if (!e)
288
+ const worksheet = workbook.getSheetBySheetId(this._thread.subUnitId);
289
+ if (!worksheet)
281
290
  return null;
282
- const t = this._getRef();
283
- return this._injector.createInstance(x, r, e, t);
291
+ const range = this._getRef();
292
+ return this._injector.createInstance(FRange, workbook, worksheet, range);
284
293
  }
294
+ // eslint-disable-next-line
285
295
  /**
286
296
  * @deprecated use `getRichText` as instead
287
297
  */
@@ -294,14 +304,14 @@ let i = class {
294
304
  * @example
295
305
  * ```ts
296
306
  * const comment = univerAPI.getActiveWorkbook()
297
- * .getSheetById(sheetId)
298
- * .getCommentById(commentId);
307
+ * .getSheetById(sheetId)
308
+ * .getCommentById(commentId);
299
309
  * const richText = comment.getRichText();
300
310
  * ```
301
311
  */
302
312
  getRichText() {
303
- const r = this._thread.text;
304
- return l.create({ body: r, documentStyle: {}, id: "d" });
313
+ const body = this._thread.text;
314
+ return RichTextValue.create({ body, documentStyle: {}, id: "d" });
305
315
  }
306
316
  /**
307
317
  * Delete the comment and it's replies
@@ -309,14 +319,14 @@ let i = class {
309
319
  * @example
310
320
  * ```ts
311
321
  * const comment = univerAPI.getActiveWorkbook()
312
- * .getSheetById(sheetId)
313
- * .getCommentById(commentId);
322
+ * .getSheetById(sheetId)
323
+ * .getCommentById(commentId);
314
324
  * const success = await comment.deleteAsync();
315
325
  * ```
316
326
  */
317
327
  deleteAsync() {
318
328
  return this._commandService.executeCommand(
319
- this.getIsRoot() ? T.id : A.id,
329
+ this.getIsRoot() ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id,
320
330
  {
321
331
  commentId: this._thread.id,
322
332
  unitId: this._thread.unitId,
@@ -324,271 +334,294 @@ let i = class {
324
334
  }
325
335
  );
326
336
  }
337
+ // eslint-disable-next-line
327
338
  /**
328
339
  * @deprecated use `deleteAsync` as instead.
329
340
  */
330
341
  delete() {
331
342
  return this.deleteAsync();
332
343
  }
344
+ // eslint-disable-next-line
333
345
  /**
334
- * @param content
335
346
  * @deprecated use `updateAsync` as instead
336
347
  */
337
- async update(r) {
338
- return this.updateAsync(r);
348
+ async update(content) {
349
+ return this.updateAsync(content);
339
350
  }
340
351
  /**
341
352
  * Update the comment content
342
- * @param content The new content of the comment
343
- * @returns success or not
353
+ * @param {IDocumentBody | RichTextValue} content The new content of the comment
354
+ * @returns {Promise<boolean>} success or not
344
355
  * @example
345
356
  * ```ts
346
357
  * const comment = univerAPI.getActiveWorkbook()
347
- * .getSheetById(sheetId)
348
- * .getCommentById(commentId);
358
+ * .getSheetById(sheetId)
359
+ * .getCommentById(commentId);
349
360
  * const success = await comment.updateAsync(univerAPI.newRichText().insertText('hello zhangsan'));
350
361
  * ```
351
362
  */
352
- async updateAsync(r) {
353
- const e = r instanceof l ? r.getData().body : r, t = f();
363
+ async updateAsync(content) {
364
+ const body = content instanceof RichTextValue ? content.getData().body : content, dt = getDT();
354
365
  return await this._commandService.executeCommand(
355
- M.id,
366
+ UpdateCommentCommand.id,
356
367
  {
357
368
  unitId: this._thread.unitId,
358
369
  subUnitId: this._thread.subUnitId,
359
370
  payload: {
360
371
  commentId: this._thread.id,
361
- text: e,
372
+ text: body,
362
373
  updated: !0,
363
- updateT: t
374
+ updateT: dt
364
375
  }
365
376
  }
366
377
  );
367
378
  }
379
+ // eslint-disable-next-line
368
380
  /**
369
- * @param resolved
370
381
  * @deprecated use `resolveAsync` as instead
371
382
  */
372
- resolve(r) {
373
- return this.resolveAsync(r);
383
+ resolve(resolved) {
384
+ return this.resolveAsync(resolved);
374
385
  }
375
386
  /**
376
387
  * Resolve the comment
377
- * @param resolved Whether the comment is resolved
378
- * @returns success or not
388
+ * @param {boolean} resolved Whether the comment is resolved
389
+ * @returns {Promise<boolean>} success or not
379
390
  * @example
380
391
  * ```ts
381
392
  * const comment = univerAPI.getActiveWorkbook()
382
- * .getSheetById(sheetId)
383
- * .getCommentById(commentId);
393
+ * .getSheetById(sheetId)
394
+ * .getCommentById(commentId);
384
395
  * const success = await comment.resolveAsync(true);
385
396
  * ```
386
397
  */
387
- resolveAsync(r) {
398
+ resolveAsync(resolved) {
388
399
  return this._commandService.executeCommand(
389
- L.id,
400
+ ResolveCommentCommand.id,
390
401
  {
391
402
  unitId: this._thread.unitId,
392
403
  subUnitId: this._thread.subUnitId,
393
404
  commentId: this._thread.id,
394
- resolved: r != null ? r : !this._thread.resolved
405
+ resolved: resolved != null ? resolved : !this._thread.resolved
395
406
  }
396
407
  );
397
408
  }
398
409
  /**
399
410
  * Reply to the comment
400
- * @param comment The comment to reply to
401
- * @returns success or not
411
+ * @param {FTheadCommentBuilder} comment The comment to reply to
412
+ * @returns {Promise<boolean>} success or not
402
413
  * @example
403
414
  * ```ts
404
415
  * const comment = univerAPI.getActiveWorkbook()
405
- * .getSheetById(sheetId)
406
- * .getCommentById(commentId);
416
+ * .getSheetById(sheetId)
417
+ * .getCommentById(commentId);
407
418
  *
408
419
  * const reply = univerAPI.newTheadComment()
409
- * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
420
+ * .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
410
421
  *
411
422
  * const success = await comment.replyAsync(reply);
412
423
  * ```
413
424
  */
414
- async replyAsync(r) {
415
- var t;
416
- const e = r.build();
425
+ async replyAsync(comment) {
426
+ var _a2;
427
+ const commentData = comment.build();
417
428
  return this._commandService.executeCommand(
418
- b.id,
429
+ AddCommentCommand.id,
419
430
  {
420
431
  unitId: this._thread.unitId,
421
432
  subUnitId: this._thread.subUnitId,
422
433
  comment: {
423
- id: g(),
434
+ id: generateRandomId(),
424
435
  parentId: this._thread.id,
425
436
  threadId: this._thread.threadId,
426
- ref: (t = this._parent) == null ? void 0 : t.ref,
437
+ ref: (_a2 = this._parent) == null ? void 0 : _a2.ref,
427
438
  unitId: this._thread.unitId,
428
439
  subUnitId: this._thread.subUnitId,
429
- text: e.text,
430
- attachments: e.attachments,
431
- dT: e.dT || f(),
432
- personId: e.personId || this._userManagerService.getCurrentUser().userID
440
+ text: commentData.text,
441
+ attachments: commentData.attachments,
442
+ dT: commentData.dT || getDT(),
443
+ personId: commentData.personId || this._userManagerService.getCurrentUser().userID
433
444
  }
434
445
  }
435
446
  );
436
447
  }
437
- };
438
- i = J([
439
- a(2, v(F)),
440
- a(3, p),
441
- a(4, O),
442
- a(5, v(h)),
443
- a(6, v(S))
444
- ], i);
445
- class K extends x {
448
+ }, __name(_a, "FThreadComment"), _a);
449
+ FThreadComment = __decorateClass([
450
+ __decorateParam(2, Inject(Injector)),
451
+ __decorateParam(3, ICommandService),
452
+ __decorateParam(4, IUniverInstanceService),
453
+ __decorateParam(5, Inject(SheetsThreadCommentModel)),
454
+ __decorateParam(6, Inject(UserManagerService))
455
+ ], FThreadComment);
456
+ const _FRangeCommentMixin = class _FRangeCommentMixin extends FRange {
446
457
  getComment() {
447
- const t = this._injector.get(h), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m = t.getByLocation(n, o, this._range.startRow, this._range.startColumn);
448
- if (!m)
458
+ const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
459
+ if (!commentId)
449
460
  return null;
450
- const s = t.getComment(n, o, m);
451
- return s ? this._injector.createInstance(i, s) : null;
461
+ const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
462
+ return comment ? this._injector.createInstance(FThreadComment, comment) : null;
452
463
  }
453
464
  getComments() {
454
- const t = this._injector.get(h), n = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), m = [];
455
- return z.foreach(this._range, (s, c) => {
456
- const u = t.getByLocation(n, o, s, c);
457
- if (u) {
458
- const C = t.getComment(n, o, u);
459
- C && m.push(this._injector.createInstance(i, C));
465
+ const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), comments = [];
466
+ return Range.foreach(this._range, (row, col) => {
467
+ const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, row, col);
468
+ if (commentId) {
469
+ const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
470
+ comment && comments.push(this._injector.createInstance(FThreadComment, comment));
460
471
  }
461
- }), m;
462
- }
463
- addComment(e) {
464
- var w;
465
- const t = this._injector, n = (w = this.getComment()) == null ? void 0 : w.getCommentData(), o = t.get(p), m = t.get(S), s = this._workbook.getUnitId(), c = this._worksheet.getSheetId(), u = `${B.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, C = m.getCurrentUser(), _ = e instanceof U ? e.build() : { text: e };
466
- return o.executeCommand(b.id, {
467
- unitId: s,
468
- subUnitId: c,
472
+ }), comments;
473
+ }
474
+ addComment(content) {
475
+ var _a2;
476
+ const injector = this._injector, currentComment = (_a2 = this.getComment()) == null ? void 0 : _a2.getCommentData(), commentService = injector.get(ICommandService), userService = injector.get(UserManagerService), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, currentUser = userService.getCurrentUser(), commentData = content instanceof FTheadCommentBuilder ? content.build() : { text: content };
477
+ return commentService.executeCommand(AddCommentCommand.id, {
478
+ unitId,
479
+ subUnitId: sheetId,
469
480
  comment: {
470
- text: _.text,
471
- dT: _.dT || f(),
481
+ text: commentData.text,
482
+ dT: commentData.dT || getDT(),
472
483
  attachments: [],
473
- id: _.id || g(),
474
- ref: u,
475
- personId: _.personId || C.userID,
476
- parentId: n == null ? void 0 : n.id,
477
- unitId: s,
478
- subUnitId: c,
479
- threadId: (n == null ? void 0 : n.threadId) || g()
484
+ id: commentData.id || generateRandomId(),
485
+ ref: refStr,
486
+ personId: commentData.personId || currentUser.userID,
487
+ parentId: currentComment == null ? void 0 : currentComment.id,
488
+ unitId,
489
+ subUnitId: sheetId,
490
+ threadId: (currentComment == null ? void 0 : currentComment.threadId) || generateRandomId()
480
491
  }
481
492
  });
482
493
  }
483
494
  clearComment() {
484
- var s;
485
- const e = this._injector, t = (s = this.getComment()) == null ? void 0 : s.getCommentData(), n = e.get(p), o = this._workbook.getUnitId(), m = this._worksheet.getSheetId();
486
- return t ? n.executeCommand(T.id, {
487
- unitId: o,
488
- subUnitId: m,
489
- threadId: t.threadId,
490
- commentId: t.id
495
+ var _a2;
496
+ const injector = this._injector, currentComment = (_a2 = this.getComment()) == null ? void 0 : _a2.getCommentData(), commentService = injector.get(ICommandService), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId();
497
+ return currentComment ? commentService.executeCommand(DeleteCommentTreeCommand.id, {
498
+ unitId,
499
+ subUnitId: sheetId,
500
+ threadId: currentComment.threadId,
501
+ commentId: currentComment.id
491
502
  }) : Promise.resolve(!0);
492
503
  }
493
504
  clearComments() {
494
- const t = this.getComments().map((n) => n.deleteAsync());
495
- return Promise.all(t).then(() => !0);
505
+ const promises = this.getComments().map((comment) => comment.deleteAsync());
506
+ return Promise.all(promises).then(() => !0);
507
+ }
508
+ addCommentAsync(content) {
509
+ return this.addComment(content);
496
510
  }
497
- }
498
- x.extend(K);
499
- class Q extends j {
511
+ clearCommentAsync() {
512
+ return this.clearComment();
513
+ }
514
+ clearCommentsAsync() {
515
+ return this.clearComments();
516
+ }
517
+ };
518
+ __name(_FRangeCommentMixin, "FRangeCommentMixin");
519
+ let FRangeCommentMixin = _FRangeCommentMixin;
520
+ FRange.extend(FRangeCommentMixin);
521
+ const _FWorkbookThreadCommentMixin = class _FWorkbookThreadCommentMixin extends FWorkbook {
522
+ /**
523
+ * @ignore
524
+ */
500
525
  _initialize() {
501
526
  Object.defineProperty(this, "_threadCommentModel", {
502
527
  get() {
503
- return this._injector.get(N);
528
+ return this._injector.get(ThreadCommentModel);
504
529
  }
505
530
  });
506
531
  }
507
532
  getComments() {
508
- return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((e) => this._injector.createInstance(i, e.root));
533
+ return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map((i) => this._injector.createInstance(FThreadComment, i.root));
509
534
  }
510
535
  clearComments() {
511
- const t = this.getComments().map((n) => n.deleteAsync());
512
- return Promise.all(t).then(() => !0);
536
+ const promises = this.getComments().map((comment) => comment.deleteAsync());
537
+ return Promise.all(promises).then(() => !0);
513
538
  }
514
539
  /**
540
+ * @param callback
515
541
  * @deprecated
516
542
  */
517
- onThreadCommentChange(e) {
518
- return I(this._threadCommentModel.commentUpdate$.pipe(H((t) => t.unitId === this._workbook.getUnitId())).subscribe(e));
543
+ onThreadCommentChange(callback) {
544
+ return toDisposable(this._threadCommentModel.commentUpdate$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
519
545
  }
520
546
  /**
547
+ * @param callback
521
548
  * @deprecated
522
549
  */
523
- onBeforeAddThreadComment(e) {
524
- return I(this._commandService.beforeCommandExecuted((t, n) => {
525
- const o = t.params;
526
- if (t.id === b.id) {
527
- if (o.unitId !== this._workbook.getUnitId())
550
+ onBeforeAddThreadComment(callback) {
551
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
552
+ const params = commandInfo.params;
553
+ if (commandInfo.id === AddCommentCommand.id) {
554
+ if (params.unitId !== this._workbook.getUnitId())
528
555
  return;
529
- if (e(o, n) === !1)
556
+ if (callback(params, options) === !1)
530
557
  throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
531
558
  }
532
559
  }));
533
560
  }
534
561
  /**
562
+ * @param callback
535
563
  * @deprecated
536
564
  */
537
- onBeforeUpdateThreadComment(e) {
538
- return I(this._commandService.beforeCommandExecuted((t, n) => {
539
- const o = t.params;
540
- if (t.id === M.id) {
541
- if (o.unitId !== this._workbook.getUnitId())
565
+ onBeforeUpdateThreadComment(callback) {
566
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
567
+ const params = commandInfo.params;
568
+ if (commandInfo.id === UpdateCommentCommand.id) {
569
+ if (params.unitId !== this._workbook.getUnitId())
542
570
  return;
543
- if (e(o, n) === !1)
571
+ if (callback(params, options) === !1)
544
572
  throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
545
573
  }
546
574
  }));
547
575
  }
548
576
  /**
577
+ * @param callback
549
578
  * @deprecated
550
579
  */
551
- onBeforeDeleteThreadComment(e) {
552
- return I(this._commandService.beforeCommandExecuted((t, n) => {
553
- const o = t.params;
554
- if (t.id === A.id || t.id === T.id) {
555
- if (o.unitId !== this._workbook.getUnitId())
580
+ onBeforeDeleteThreadComment(callback) {
581
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
582
+ const params = commandInfo.params;
583
+ if (commandInfo.id === DeleteCommentCommand.id || commandInfo.id === DeleteCommentTreeCommand.id) {
584
+ if (params.unitId !== this._workbook.getUnitId())
556
585
  return;
557
- if (e(o, n) === !1)
586
+ if (callback(params, options) === !1)
558
587
  throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
559
588
  }
560
589
  }));
561
590
  }
562
- }
563
- j.extend(Q);
564
- class X extends D {
591
+ };
592
+ __name(_FWorkbookThreadCommentMixin, "FWorkbookThreadCommentMixin");
593
+ let FWorkbookThreadCommentMixin = _FWorkbookThreadCommentMixin;
594
+ FWorkbook.extend(FWorkbookThreadCommentMixin);
595
+ const _FWorksheetCommentMixin = class _FWorksheetCommentMixin extends FWorksheet {
565
596
  getComments() {
566
- return this._injector.get(h).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((n) => this._injector.createInstance(i, n));
597
+ return this._injector.get(SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((comment) => this._injector.createInstance(FThreadComment, comment));
567
598
  }
568
599
  clearComments() {
569
- const t = this.getComments().map((n) => n.deleteAsync());
570
- return Promise.all(t).then(() => !0);
600
+ const promises = this.getComments().map((comment) => comment.deleteAsync());
601
+ return Promise.all(promises).then(() => !0);
571
602
  }
572
603
  /**
573
604
  * Subscribe to comment events.
574
605
  * @param callback Callback function, param contains comment info and target cell.
575
606
  */
576
- onCommented(e) {
577
- return this._injector.get(p).onCommandExecuted((n) => {
578
- if (n.id === b.id) {
579
- const o = n.params;
580
- e(o);
607
+ onCommented(callback) {
608
+ return this._injector.get(ICommandService).onCommandExecuted((command) => {
609
+ if (command.id === AddCommentCommand.id) {
610
+ const params = command.params;
611
+ callback(params);
581
612
  }
582
613
  });
583
614
  }
584
- getCommentById(e) {
585
- const n = this._injector.get(h).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), e);
586
- if (n)
587
- return this._injector.createInstance(i, n);
615
+ getCommentById(commentId) {
616
+ const comment = this._injector.get(SheetsThreadCommentModel).getComment(this._workbook.getUnitId(), this._worksheet.getSheetId(), commentId);
617
+ if (comment)
618
+ return this._injector.createInstance(FThreadComment, comment);
588
619
  }
589
- }
590
- D.extend(X);
591
- const d = {
620
+ };
621
+ __name(_FWorksheetCommentMixin, "FWorksheetCommentMixin");
622
+ let FWorksheetCommentMixin = _FWorksheetCommentMixin;
623
+ FWorksheet.extend(FWorksheetCommentMixin);
624
+ const CommentEvent = {
592
625
  CommentAdded: "CommentAdded",
593
626
  BeforeCommentAdd: "BeforeCommentAdd",
594
627
  CommentUpdated: "CommentUpdated",
@@ -597,34 +630,35 @@ const d = {
597
630
  BeforeCommentDeleted: "BeforeCommentDeleted",
598
631
  CommentResolved: "CommentResolved",
599
632
  BeforeCommentResolve: "BeforeCommentResolve"
600
- };
601
- class Y extends R {
633
+ }, _FCommentEvent = class _FCommentEvent extends FEventName {
602
634
  get CommentAdded() {
603
- return d.CommentAdded;
635
+ return CommentEvent.CommentAdded;
604
636
  }
605
637
  get BeforeCommentAdd() {
606
- return d.BeforeCommentAdd;
638
+ return CommentEvent.BeforeCommentAdd;
607
639
  }
608
640
  get CommentUpdated() {
609
- return d.CommentUpdated;
641
+ return CommentEvent.CommentUpdated;
610
642
  }
611
643
  get BeforeCommentUpdate() {
612
- return d.BeforeCommentUpdate;
644
+ return CommentEvent.BeforeCommentUpdate;
613
645
  }
614
646
  get CommentDeleted() {
615
- return d.CommentDeleted;
647
+ return CommentEvent.CommentDeleted;
616
648
  }
617
649
  get BeforeCommentDeleted() {
618
- return d.BeforeCommentDeleted;
650
+ return CommentEvent.BeforeCommentDeleted;
619
651
  }
620
652
  get CommentResolved() {
621
- return d.CommentResolved;
653
+ return CommentEvent.CommentResolved;
622
654
  }
623
655
  get BeforeCommentResolve() {
624
- return d.BeforeCommentResolve;
656
+ return CommentEvent.BeforeCommentResolve;
625
657
  }
626
- }
627
- R.extend(Y);
658
+ };
659
+ __name(_FCommentEvent, "FCommentEvent");
660
+ let FCommentEvent = _FCommentEvent;
661
+ FEventName.extend(FCommentEvent);
628
662
  export {
629
- i as FThreadComment
663
+ FThreadComment
630
664
  };