@univerjs/sheets-thread-comment 0.6.7 → 0.6.9

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