@univerjs/thread-comment 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,541 +1 @@
1
- var L = Object.defineProperty;
2
- var j = (s, t, e) => t in s ? L(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var h = (s, t, e) => j(s, typeof t != "symbol" ? t + "" : t, e);
4
- import { createIdentifier as H, Disposable as U, Inject as g, LifecycleService as W, LifecycleStages as O, CommandType as l, ICommandService as M, dayjs as k, IResourceManagerService as J, UniverInstanceType as T, Plugin as G, merge as V, mergeOverrideWithDependencies as Y, Injector as B, IConfigService as b } from "@univerjs/core";
5
- import { Subject as K } from "rxjs";
6
- class F extends U {
7
- constructor() {
8
- super();
9
- h(this, "_dataSource", null);
10
- h(this, "syncUpdateMutationToColla", !0);
11
- }
12
- set dataSource(e) {
13
- this._dataSource = e;
14
- }
15
- get dataSource() {
16
- return this._dataSource;
17
- }
18
- async getThreadComment(e, n, o) {
19
- return this._dataSource ? (await this._dataSource.listComments(e, n, [o]))[0] : null;
20
- }
21
- async addComment(e) {
22
- var n;
23
- return this._dataSource ? this._dataSource.addComment(e) : { ...e, threadId: (n = e.threadId) != null ? n : e.id };
24
- }
25
- async updateComment(e) {
26
- return this._dataSource ? this._dataSource.updateComment(e) : !0;
27
- }
28
- async resolveComment(e) {
29
- return this._dataSource ? this._dataSource.resolveComment(e) : !0;
30
- }
31
- async deleteComment(e, n, o, r) {
32
- return this._dataSource ? this._dataSource.deleteComment(e, n, o, r) : !0;
33
- }
34
- async listThreadComments(e, n, o) {
35
- return this.dataSource ? this.dataSource.listComments(e, n, o) : !1;
36
- }
37
- saveToSnapshot(e, n) {
38
- if (this._dataSource) {
39
- const o = {};
40
- return Object.keys(e).forEach((r) => {
41
- const a = e[r];
42
- o[r] = a.map(this.dataSource.saveCommentToSnapshot);
43
- }), o;
44
- }
45
- return e;
46
- }
47
- }
48
- const p = H("univer.thread-comment.data-source-service");
49
- var q = Object.getOwnPropertyDescriptor, z = (s, t, e, n) => {
50
- for (var o = n > 1 ? void 0 : n ? q(t, e) : t, r = s.length - 1, a; r >= 0; r--)
51
- (a = s[r]) && (o = a(o) || o);
52
- return o;
53
- }, w = (s, t) => (e, n) => t(e, n, s);
54
- let i = class extends U {
55
- constructor(t, e) {
56
- super();
57
- h(this, "_commentsMap", /* @__PURE__ */ new Map());
58
- h(this, "_threadMap", /* @__PURE__ */ new Map());
59
- h(this, "_commentUpdate$", new K());
60
- h(this, "commentUpdate$", this._commentUpdate$.asObservable());
61
- h(this, "_tasks", []);
62
- this._dataSourceService = t, this._lifecycleService = e, this.disposeWithMe(() => {
63
- this._commentUpdate$.complete();
64
- }), this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe((n) => {
65
- const o = /* @__PURE__ */ new Map();
66
- n === O.Rendered && (this._tasks.forEach(({ unitId: r, subUnitId: a, threadIds: d }) => {
67
- let m = o.get(r);
68
- m || (m = /* @__PURE__ */ new Map(), o.set(r, m));
69
- let c = m.get(a);
70
- c || (c = /* @__PURE__ */ new Set(), m.set(a, c));
71
- for (const u of d)
72
- c.add(u);
73
- }), this._tasks = [], o.forEach((r, a) => {
74
- r.forEach((d, m) => {
75
- this.syncThreadComments(a, m, Array.from(d));
76
- });
77
- }));
78
- }));
79
- }
80
- _ensureCommentMap(t, e) {
81
- let n = this._commentsMap.get(t);
82
- n || (n = /* @__PURE__ */ new Map(), this._commentsMap.set(t, n));
83
- let o = n.get(e);
84
- return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
85
- }
86
- ensureMap(t, e) {
87
- return this._ensureCommentMap(t, e);
88
- }
89
- _ensureThreadMap(t, e) {
90
- let n = this._threadMap.get(t);
91
- n || (n = /* @__PURE__ */ new Map(), this._threadMap.set(t, n));
92
- let o = n.get(e);
93
- return o || (o = /* @__PURE__ */ new Map(), n.set(e, o)), o;
94
- }
95
- _replaceComment(t, e, n) {
96
- const o = this._ensureCommentMap(t, e), r = o.get(n.id);
97
- if (r) {
98
- const { children: a, ...d } = n, m = {
99
- ...d,
100
- ref: r.ref
101
- };
102
- o.set(n.id, m), a == null || a.forEach((c) => {
103
- o.set(c.id, {
104
- ...c,
105
- ref: ""
106
- });
107
- }), this._commentUpdate$.next({
108
- unitId: t,
109
- subUnitId: e,
110
- type: "syncUpdate",
111
- payload: m
112
- }), !!n.resolved != !!r.resolved && this._commentUpdate$.next({
113
- unitId: t,
114
- subUnitId: e,
115
- type: "resolve",
116
- payload: {
117
- commentId: n.id,
118
- resolved: !!n.resolved
119
- }
120
- });
121
- }
122
- }
123
- async syncThreadComments(t, e, n) {
124
- if (this._lifecycleService.stage < O.Rendered) {
125
- this._tasks.push({ unitId: t, subUnitId: e, threadIds: n });
126
- return;
127
- }
128
- const o = this._ensureThreadMap(t, e), r = this._ensureCommentMap(t, e), a = await this._dataSourceService.listThreadComments(t, e, n);
129
- if (!a)
130
- return;
131
- const d = new Set(n);
132
- a.forEach((m) => {
133
- this._replaceComment(t, e, m), d.delete(m.threadId);
134
- }), d.forEach((m) => {
135
- o.delete(m), r.forEach((c, u) => {
136
- c.threadId === m && r.delete(u);
137
- });
138
- });
139
- }
140
- addComment(t, e, n, o) {
141
- const r = this._ensureCommentMap(t, e), { parentId: a, children: d = [], ...m } = n, c = {
142
- ...m,
143
- parentId: a === n.id ? void 0 : a
144
- };
145
- c.threadId || (c.threadId = c.parentId || c.id);
146
- const u = (C) => {
147
- r.set(C.id, C), this._commentUpdate$.next({
148
- unitId: t,
149
- subUnitId: e,
150
- type: "add",
151
- payload: C,
152
- isRoot: !C.parentId
153
- });
154
- };
155
- u(c);
156
- const _ = this._ensureThreadMap(t, e);
157
- if (!c.parentId) {
158
- _.set(c.threadId, c);
159
- for (const C of d)
160
- u(C);
161
- }
162
- return o && this.syncThreadComments(t, e, [c.threadId]), !0;
163
- }
164
- updateComment(t, e, n, o) {
165
- const a = this._ensureCommentMap(t, e).get(n.commentId);
166
- return a && (a.updated = !0, a.text = n.text, a.attachments = n.attachments, a.updateT = n.updateT, this._commentUpdate$.next({
167
- unitId: t,
168
- subUnitId: e,
169
- type: "update",
170
- payload: n,
171
- silent: o
172
- })), !0;
173
- }
174
- updateCommentRef(t, e, n, o) {
175
- const a = this._ensureCommentMap(t, e).get(n.commentId);
176
- return a ? (a.ref = n.ref, this._commentUpdate$.next({
177
- unitId: t,
178
- subUnitId: e,
179
- type: "updateRef",
180
- payload: n,
181
- silent: o,
182
- threadId: a.threadId
183
- }), !0) : !1;
184
- }
185
- resolveComment(t, e, n, o) {
186
- const a = this._ensureCommentMap(t, e).get(n);
187
- return a ? (a.resolved = o, this._commentUpdate$.next({
188
- unitId: t,
189
- subUnitId: e,
190
- type: "resolve",
191
- payload: {
192
- commentId: n,
193
- resolved: o
194
- }
195
- }), !0) : !1;
196
- }
197
- getComment(t, e, n) {
198
- return this._ensureCommentMap(t, e).get(n);
199
- }
200
- getRootComment(t, e, n) {
201
- return this._ensureThreadMap(t, e).get(n);
202
- }
203
- getThread(t, e, n) {
204
- const o = this._ensureCommentMap(t, e), r = Array.from(o.values()).filter((c) => c.threadId === n);
205
- let a;
206
- const d = [], m = /* @__PURE__ */ new Set();
207
- for (const c of r)
208
- c.parentId ? d.push(c) : a = c, m.add(c.personId);
209
- if (a)
210
- return {
211
- root: a,
212
- children: d,
213
- relativeUsers: m,
214
- unitId: t,
215
- subUnitId: e,
216
- threadId: n
217
- };
218
- }
219
- getCommentWithChildren(t, e, n) {
220
- const o = this.getComment(t, e, n);
221
- if (o)
222
- return this.getThread(t, e, o.threadId);
223
- }
224
- _deleteComment(t, e, n) {
225
- const o = this._ensureCommentMap(t, e), r = o.get(n);
226
- r && (o.delete(n), this._commentUpdate$.next({
227
- unitId: t,
228
- subUnitId: e,
229
- type: "delete",
230
- payload: {
231
- commentId: n,
232
- isRoot: !r.parentId,
233
- comment: r
234
- }
235
- }));
236
- }
237
- deleteThread(t, e, n) {
238
- this._ensureThreadMap(t, e).delete(n), this._ensureCommentMap(t, e).forEach((a) => {
239
- a.threadId === n && this._deleteComment(t, e, a.id);
240
- });
241
- }
242
- deleteComment(t, e, n) {
243
- const r = this._ensureCommentMap(t, e).get(n);
244
- return r && (r.parentId ? this._deleteComment(t, e, n) : this.deleteThread(t, e, r.threadId)), !0;
245
- }
246
- deleteUnit(t) {
247
- const e = this._commentsMap.get(t);
248
- e && e.forEach((n, o) => {
249
- n.forEach((r) => {
250
- this.deleteComment(t, o, r.id);
251
- });
252
- });
253
- }
254
- getUnit(t) {
255
- const e = this._threadMap.get(t);
256
- if (!e)
257
- return [];
258
- const n = [];
259
- return e.forEach((o, r) => {
260
- o.forEach((a, d) => {
261
- const m = this.getThread(t, r, d);
262
- m && n.push(m);
263
- });
264
- }), n;
265
- }
266
- getAll() {
267
- const t = [];
268
- return this._commentsMap.forEach((e, n) => {
269
- t.push({
270
- unitId: n,
271
- threads: this.getUnit(n)
272
- });
273
- }), t;
274
- }
275
- };
276
- i = z([
277
- w(0, g(p)),
278
- w(1, g(W))
279
- ], i);
280
- const x = {
281
- id: "thread-comment.mutation.add-comment",
282
- type: l.MUTATION,
283
- handler(s, t, e) {
284
- if (!t)
285
- return !1;
286
- const n = s.get(i), { unitId: o, subUnitId: r, comment: a, sync: d } = t, m = d || (e == null ? void 0 : e.fromChangeset) && !a.parentId;
287
- return n.addComment(o, r, a, m);
288
- }
289
- }, A = {
290
- id: "thread-comment.mutation.update-comment",
291
- type: l.MUTATION,
292
- handler(s, t) {
293
- if (!t)
294
- return !1;
295
- const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
296
- return e.updateComment(n, o, r, a);
297
- }
298
- }, Q = {
299
- id: "thread-comment.mutation.update-comment-ref",
300
- type: l.MUTATION,
301
- handler(s, t) {
302
- if (!t)
303
- return !1;
304
- const e = s.get(i), { unitId: n, subUnitId: o, payload: r, silent: a } = t;
305
- return e.updateCommentRef(n, o, r, a);
306
- }
307
- }, $ = {
308
- id: "thread-comment.mutation.resolve-comment",
309
- type: l.MUTATION,
310
- handler(s, t) {
311
- if (!t)
312
- return !1;
313
- const e = s.get(i), { unitId: n, subUnitId: o, resolved: r, commentId: a } = t;
314
- return e.resolveComment(n, o, a, r);
315
- }
316
- }, E = {
317
- id: "thread-comment.mutation.delete-comment",
318
- type: l.MUTATION,
319
- handler(s, t) {
320
- if (!t)
321
- return !1;
322
- const e = s.get(i), { unitId: n, subUnitId: o, commentId: r } = t;
323
- return e.deleteComment(n, o, r);
324
- }
325
- }, X = {
326
- id: "thread-comment.command.add-comment",
327
- type: l.COMMAND,
328
- async handler(s, t) {
329
- if (!t)
330
- return !1;
331
- const e = s.get(M), n = s.get(p), { comment: o } = t, r = await n.addComment(o), a = n.syncUpdateMutationToColla, d = !o.parentId, m = {
332
- id: x.id,
333
- params: {
334
- ...t,
335
- comment: r
336
- }
337
- };
338
- return d ? await e.executeCommand(m.id, m.params) : e.executeCommand(m.id, m.params, {
339
- onlyLocal: !a
340
- });
341
- }
342
- }, Z = {
343
- id: "thread-comment.command.update-comment",
344
- type: l.COMMAND,
345
- async handler(s, t) {
346
- if (!t)
347
- return !1;
348
- const { unitId: e, subUnitId: n, payload: o } = t, r = s.get(M), a = s.get(i), d = s.get(p), m = d.syncUpdateMutationToColla, c = a.getComment(
349
- e,
350
- n,
351
- o.commentId
352
- );
353
- if (!c)
354
- return !1;
355
- const { children: u, ..._ } = c;
356
- if (!await d.updateComment({
357
- ..._,
358
- ...o
359
- }))
360
- return !1;
361
- const N = {
362
- id: A.id,
363
- params: t
364
- };
365
- return r.executeCommand(N.id, N.params, { onlyLocal: !m }), !0;
366
- }
367
- }, ee = {
368
- id: "thread-comment.command.resolve-comment",
369
- type: l.COMMAND,
370
- async handler(s, t) {
371
- if (!t)
372
- return !1;
373
- const { unitId: e, subUnitId: n, resolved: o, commentId: r } = t, a = s.get(p), m = s.get(i).getComment(e, n, r), c = a.syncUpdateMutationToColla;
374
- return !m || !await a.resolveComment({
375
- ...m,
376
- resolved: o
377
- }) ? !1 : s.get(M).executeCommand(
378
- $.id,
379
- t,
380
- { onlyLocal: !c }
381
- );
382
- }
383
- }, te = {
384
- id: "thread-comment.command.delete-comment",
385
- type: l.COMMAND,
386
- async handler(s, t) {
387
- if (!t)
388
- return !1;
389
- const e = s.get(i), n = s.get(p), o = s.get(M), { unitId: r, subUnitId: a, commentId: d } = t, m = n.syncUpdateMutationToColla, c = e.getComment(r, a, d);
390
- if (!c || !await n.deleteComment(r, a, c.threadId, d))
391
- return !1;
392
- const u = {
393
- id: E.id,
394
- params: t
395
- };
396
- return o.executeCommand(u.id, u.params, { onlyLocal: !m });
397
- }
398
- }, ne = {
399
- id: "thread-comment.command.delete-comment-tree",
400
- type: l.COMMAND,
401
- async handler(s, t) {
402
- if (!t)
403
- return !1;
404
- const e = s.get(i), n = s.get(M), o = s.get(p), { unitId: r, subUnitId: a, commentId: d } = t, m = e.getCommentWithChildren(r, a, d);
405
- return !m || !await o.deleteComment(r, a, m.root.threadId, d) ? !1 : await n.executeCommand(E.id, {
406
- unitId: r,
407
- subUnitId: a,
408
- commentId: m.root.id
409
- });
410
- }
411
- };
412
- function pe(s) {
413
- return k(s).format("YYYY/MM/DD HH:mm");
414
- }
415
- const P = "UNIVER_THREAD_COMMENT_PLUGIN";
416
- var oe = Object.getOwnPropertyDescriptor, re = (s, t, e, n) => {
417
- for (var o = n > 1 ? void 0 : n ? oe(t, e) : t, r = s.length - 1, a; r >= 0; r--)
418
- (a = s[r]) && (o = a(o) || o);
419
- return o;
420
- }, S = (s, t) => (e, n) => t(e, n, s);
421
- const ae = `SHEET_${P}`;
422
- let v = class extends U {
423
- constructor(s, t, e) {
424
- super(), this._resourceManagerService = s, this._threadCommentModel = t, this._threadCommentDataSourceService = e, this._initSnapshot();
425
- }
426
- _initSnapshot() {
427
- const s = (e) => {
428
- const n = this._threadCommentModel.getUnit(e), o = {};
429
- return n ? (n.forEach((r) => {
430
- var d;
431
- const a = (d = o[r.subUnitId]) != null ? d : [];
432
- a.push({
433
- ...r.root,
434
- children: r.children
435
- }), o[r.subUnitId] = a;
436
- }), JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(o, e))) : "";
437
- }, t = (e) => {
438
- if (!e)
439
- return {};
440
- try {
441
- return JSON.parse(e);
442
- } catch {
443
- return {};
444
- }
445
- };
446
- this.disposeWithMe(
447
- this._resourceManagerService.registerPluginResource({
448
- pluginName: ae,
449
- businesses: [T.UNIVER_SHEET, T.UNIVER_DOC],
450
- toJson: (e) => s(e),
451
- parseJson: (e) => t(e),
452
- onUnLoad: (e) => {
453
- this._threadCommentModel.deleteUnit(e);
454
- },
455
- onLoad: async (e, n) => {
456
- Object.keys(n).forEach((o) => {
457
- const r = n[o];
458
- r.forEach((a) => {
459
- this._threadCommentModel.addComment(e, o, a);
460
- }), this._threadCommentModel.syncThreadComments(e, o, r.map((a) => a.threadId));
461
- });
462
- }
463
- })
464
- );
465
- }
466
- };
467
- v = re([
468
- S(0, J),
469
- S(1, g(i)),
470
- S(2, p)
471
- ], v);
472
- const se = "@univerjs/thread-comment", me = "0.17.0", D = {
473
- name: se,
474
- version: me
475
- }, ce = "thread-comment.config", I = {};
476
- var de = Object.getOwnPropertyDescriptor, ie = (s, t, e, n) => {
477
- for (var o = n > 1 ? void 0 : n ? de(t, e) : t, r = s.length - 1, a; r >= 0; r--)
478
- (a = s[r]) && (o = a(o) || o);
479
- return o;
480
- }, y = (s, t) => (e, n) => t(e, n, s), f;
481
- let R = (f = class extends G {
482
- constructor(s = I, t, e, n) {
483
- super(), this._config = s, this._injector = t, this._commandService = e, this._configService = n;
484
- const { ...o } = V(
485
- {},
486
- I,
487
- this._config
488
- );
489
- this._configService.setConfig(ce, o);
490
- }
491
- onStarting() {
492
- var s;
493
- Y([
494
- [p, { useClass: F }],
495
- [i],
496
- [v]
497
- ], (s = this._config) == null ? void 0 : s.overrides).forEach(
498
- (t) => {
499
- this._injector.add(t);
500
- }
501
- ), [
502
- X,
503
- Z,
504
- te,
505
- ee,
506
- ne,
507
- x,
508
- A,
509
- Q,
510
- E,
511
- $
512
- ].forEach((t) => {
513
- this._commandService.registerCommand(t);
514
- }), this._injector.get(v);
515
- }
516
- }, h(f, "pluginName", P), h(f, "packageName", D.name), h(f, "version", D.version), h(f, "type", T.UNIVER_UNKNOWN), f);
517
- R = ie([
518
- y(1, g(B)),
519
- y(2, M),
520
- y(3, b)
521
- ], R);
522
- export {
523
- X as AddCommentCommand,
524
- x as AddCommentMutation,
525
- te as DeleteCommentCommand,
526
- E as DeleteCommentMutation,
527
- ne as DeleteCommentTreeCommand,
528
- p as IThreadCommentDataSourceService,
529
- ee as ResolveCommentCommand,
530
- $ as ResolveCommentMutation,
531
- ae as SHEET_UNIVER_THREAD_COMMENT_PLUGIN,
532
- P as TC_PLUGIN_NAME,
533
- F as ThreadCommentDataSourceService,
534
- i as ThreadCommentModel,
535
- v as ThreadCommentResourceController,
536
- R as UniverThreadCommentPlugin,
537
- Z as UpdateCommentCommand,
538
- A as UpdateCommentMutation,
539
- Q as UpdateCommentRefMutation,
540
- pe as getDT
541
- };
1
+ import{CommandType as e,Disposable as t,ICommandService as n,IConfigService as r,IResourceManagerService as i,Inject as a,Injector as o,LifecycleService as s,LifecycleStages as c,Plugin as l,UniverInstanceType as u,createIdentifier as d,dayjs as f,merge as p,mergeOverrideWithDependencies as m}from"@univerjs/core";import{Subject as h}from"rxjs";function g(e){"@babel/helpers - typeof";return g=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},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var b=class extends t{set dataSource(e){this._dataSource=e}get dataSource(){return this._dataSource}constructor(){super(),y(this,`_dataSource`,null),y(this,`syncUpdateMutationToColla`,!0)}async getThreadComment(e,t,n){return this._dataSource?(await this._dataSource.listComments(e,t,[n]))[0]:null}async addComment(e){var t;return this._dataSource?this._dataSource.addComment(e):{...e,threadId:(t=e.threadId)==null?e.id:t}}async updateComment(e){return this._dataSource?this._dataSource.updateComment(e):!0}async resolveComment(e){return this._dataSource?this._dataSource.resolveComment(e):!0}async deleteComment(e,t,n,r){return this._dataSource?this._dataSource.deleteComment(e,t,n,r):!0}async listThreadComments(e,t,n){return this.dataSource?this.dataSource.listComments(e,t,n):!1}saveToSnapshot(e,t){if(this._dataSource){let t={};return Object.keys(e).forEach(n=>{t[n]=e[n].map(this.dataSource.saveCommentToSnapshot)}),t}return e}};const x=d(`univer.thread-comment.data-source-service`);function S(e,t){return function(n,r){t(n,r,e)}}function C(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let w=class extends t{constructor(e,t){super(),this._dataSourceService=e,this._lifecycleService=t,y(this,`_commentsMap`,new Map),y(this,`_threadMap`,new Map),y(this,`_commentUpdate$`,new h),y(this,`commentUpdate$`,this._commentUpdate$.asObservable()),y(this,`_tasks`,[]),this.disposeWithMe(()=>{this._commentUpdate$.complete()}),this.disposeWithMe(this._lifecycleService.lifecycle$.subscribe(e=>{let t=new Map;e===c.Rendered&&(this._tasks.forEach(({unitId:e,subUnitId:n,threadIds:r})=>{let i=t.get(e);i||(i=new Map,t.set(e,i));let a=i.get(n);a||(a=new Set,i.set(n,a));for(let e of r)a.add(e)}),this._tasks=[],t.forEach((e,t)=>{e.forEach((e,n)=>{this.syncThreadComments(t,n,Array.from(e))})}))}))}_ensureCommentMap(e,t){let n=this._commentsMap.get(e);n||(n=new Map,this._commentsMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}ensureMap(e,t){return this._ensureCommentMap(e,t)}_ensureThreadMap(e,t){let n=this._threadMap.get(e);n||(n=new Map,this._threadMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_replaceComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n.id);if(i){let{children:a,...o}=n,s={...o,ref:i.ref};r.set(n.id,s),a==null||a.forEach(e=>{r.set(e.id,{...e,ref:``})}),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`syncUpdate`,payload:s}),!!n.resolved!=!!i.resolved&&this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n.id,resolved:!!n.resolved}})}}async syncThreadComments(e,t,n){if(this._lifecycleService.stage<c.Rendered){this._tasks.push({unitId:e,subUnitId:t,threadIds:n});return}let r=this._ensureThreadMap(e,t),i=this._ensureCommentMap(e,t),a=await this._dataSourceService.listThreadComments(e,t,n);if(!a)return;let o=new Set(n);a.forEach(n=>{this._replaceComment(e,t,n),o.delete(n.threadId)}),o.forEach(e=>{r.delete(e),i.forEach((t,n)=>{t.threadId===e&&i.delete(n)})})}addComment(e,t,n,r){let i=this._ensureCommentMap(e,t),{parentId:a,children:o=[],...s}=n,c={...s,parentId:a===n.id?void 0:a};c.threadId||(c.threadId=c.parentId||c.id);let l=n=>{i.set(n.id,n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`add`,payload:n,isRoot:!n.parentId})};l(c);let u=this._ensureThreadMap(e,t);if(!c.parentId){u.set(c.threadId,c);for(let e of o)l(e)}return r&&this.syncThreadComments(e,t,[c.threadId]),!0}updateComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.updated=!0,i.text=n.text,i.attachments=n.attachments,i.updateT=n.updateT,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`update`,payload:n,silent:r}),!0):!0}updateCommentRef(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n.commentId);return i?(i.ref=n.ref,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`updateRef`,payload:n,silent:r,threadId:i.threadId}),!0):!1}resolveComment(e,t,n,r){let i=this._ensureCommentMap(e,t).get(n);return i?(i.resolved=r,this._commentUpdate$.next({unitId:e,subUnitId:t,type:`resolve`,payload:{commentId:n,resolved:r}}),!0):!1}getComment(e,t,n){return this._ensureCommentMap(e,t).get(n)}getRootComment(e,t,n){return this._ensureThreadMap(e,t).get(n)}getThread(e,t,n){let r=this._ensureCommentMap(e,t),i=Array.from(r.values()).filter(e=>e.threadId===n),a,o=[],s=new Set;for(let e of i)e.parentId?o.push(e):a=e,s.add(e.personId);if(a)return{root:a,children:o,relativeUsers:s,unitId:e,subUnitId:t,threadId:n}}getCommentWithChildren(e,t,n){let r=this.getComment(e,t,n);if(r)return this.getThread(e,t,r.threadId)}_deleteComment(e,t,n){let r=this._ensureCommentMap(e,t),i=r.get(n);i&&(r.delete(n),this._commentUpdate$.next({unitId:e,subUnitId:t,type:`delete`,payload:{commentId:n,isRoot:!i.parentId,comment:i}}))}deleteThread(e,t,n){this._ensureThreadMap(e,t).delete(n),this._ensureCommentMap(e,t).forEach(r=>{r.threadId===n&&this._deleteComment(e,t,r.id)})}deleteComment(e,t,n){let r=this._ensureCommentMap(e,t).get(n);return r&&(r.parentId?this._deleteComment(e,t,n):this.deleteThread(e,t,r.threadId)),!0}deleteUnit(e){let t=this._commentsMap.get(e);t&&t.forEach((t,n)=>{t.forEach(t=>{this.deleteComment(e,n,t.id)})})}getUnit(e){let t=this._threadMap.get(e);if(!t)return[];let n=[];return t.forEach((t,r)=>{t.forEach((t,i)=>{let a=this.getThread(e,r,i);a&&n.push(a)})}),n}getAll(){let e=[];return this._commentsMap.forEach((t,n)=>{e.push({unitId:n,threads:this.getUnit(n)})}),e}};w=C([S(0,a(x)),S(1,a(s))],w);const T={id:`thread-comment.mutation.add-comment`,type:e.MUTATION,handler(e,t,n){if(!t)return!1;let r=e.get(w),{unitId:i,subUnitId:a,comment:o,sync:s}=t,c=s||(n==null?void 0:n.fromChangeset)&&!o.parentId;return r.addComment(i,a,o,c)}},E={id:`thread-comment.mutation.update-comment`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateComment(r,i,a,o)}},D={id:`thread-comment.mutation.update-comment-ref`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,payload:a,silent:o}=t;return n.updateCommentRef(r,i,a,o)}},O={id:`thread-comment.mutation.resolve-comment`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,resolved:a,commentId:o}=t;return n.resolveComment(r,i,o,a)}},k={id:`thread-comment.mutation.delete-comment`,type:e.MUTATION,handler(e,t){if(!t)return!1;let n=e.get(w),{unitId:r,subUnitId:i,commentId:a}=t;return n.deleteComment(r,i,a)}},A={id:`thread-comment.command.add-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let r=e.get(n),i=e.get(x),{comment:a}=t,o=await i.addComment(a),s=i.syncUpdateMutationToColla,c=!a.parentId,l={id:T.id,params:{...t,comment:o}};return c?await r.executeCommand(l.id,l.params):r.executeCommand(l.id,l.params,{onlyLocal:!s})}},j={id:`thread-comment.command.update-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let{unitId:r,subUnitId:i,payload:a}=t,o=e.get(n),s=e.get(w),c=e.get(x),l=c.syncUpdateMutationToColla,u=s.getComment(r,i,a.commentId);if(!u)return!1;let{children:d,...f}=u;if(!await c.updateComment({...f,...a}))return!1;let p={id:E.id,params:t};return o.executeCommand(p.id,p.params,{onlyLocal:!l}),!0}},M={id:`thread-comment.command.resolve-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let{unitId:r,subUnitId:i,resolved:a,commentId:o}=t,s=e.get(x),c=e.get(w).getComment(r,i,o),l=s.syncUpdateMutationToColla;return!c||!await s.resolveComment({...c,resolved:a})?!1:e.get(n).executeCommand(O.id,t,{onlyLocal:!l})}},N={id:`thread-comment.command.delete-comment`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let r=e.get(w),i=e.get(x),a=e.get(n),{unitId:o,subUnitId:s,commentId:c}=t,l=i.syncUpdateMutationToColla,u=r.getComment(o,s,c);if(!u||!await i.deleteComment(o,s,u.threadId,c))return!1;let d={id:k.id,params:t};return a.executeCommand(d.id,d.params,{onlyLocal:!l})}},P={id:`thread-comment.command.delete-comment-tree`,type:e.COMMAND,async handler(e,t){if(!t)return!1;let r=e.get(w),i=e.get(n),a=e.get(x),{unitId:o,subUnitId:s,commentId:c}=t,l=r.getCommentWithChildren(o,s,c);return!l||!await a.deleteComment(o,s,l.root.threadId,c)?!1:await i.executeCommand(k.id,{unitId:o,subUnitId:s,commentId:l.root.id})}};function F(e){return f(e).format(`YYYY/MM/DD HH:mm`)}const I=`UNIVER_THREAD_COMMENT_PLUGIN`,L=`SHEET_${I}`;let R=class extends t{constructor(e,t,n){super(),this._resourceManagerService=e,this._threadCommentModel=t,this._threadCommentDataSourceService=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._threadCommentModel.getUnit(e),n={};return t?(t.forEach(e=>{var t;let r=(t=n[e.subUnitId])==null?[]:t;r.push({...e.root,children:e.children}),n[e.subUnitId]=r}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(n,e))):``},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:L,businesses:[u.UNIVER_SHEET,u.UNIVER_DOC],toJson:t=>e(t),parseJson:e=>t(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,t)=>{Object.keys(t).forEach(n=>{let r=t[n];r.forEach(t=>{this._threadCommentModel.addComment(e,n,t)}),this._threadCommentModel.syncThreadComments(e,n,r.map(e=>e.threadId))})}}))}};R=C([S(0,i),S(1,a(w)),S(2,x)],R);var z=`@univerjs/thread-comment`,B=`0.18.0`;const V=`thread-comment.config`;Symbol(V);const H={};let U=class extends l{constructor(e=H,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{...i}=p({},H,this._config);this._configService.setConfig(V,i)}onStarting(){var e;m([[x,{useClass:b}],[w],[R]],(e=this._config)==null?void 0:e.overrides).forEach(e=>{this._injector.add(e)}),[A,j,N,M,P,T,E,D,k,O].forEach(e=>{this._commandService.registerCommand(e)}),this._injector.get(R)}};y(U,`pluginName`,I),y(U,`packageName`,z),y(U,`version`,B),y(U,`type`,u.UNIVER_UNKNOWN),U=C([S(1,a(o)),S(2,n),S(3,r)],U);export{A as AddCommentCommand,T as AddCommentMutation,N as DeleteCommentCommand,k as DeleteCommentMutation,P as DeleteCommentTreeCommand,x as IThreadCommentDataSourceService,M as ResolveCommentCommand,O as ResolveCommentMutation,L as SHEET_UNIVER_THREAD_COMMENT_PLUGIN,I as TC_PLUGIN_NAME,b as ThreadCommentDataSourceService,w as ThreadCommentModel,R as ThreadCommentResourceController,U as UniverThreadCommentPlugin,j as UpdateCommentCommand,E as UpdateCommentMutation,D as UpdateCommentRefMutation,F as getDT};
@@ -1,6 +1,21 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { IThreadComment } from '../../types/interfaces/i-thread-comment';
3
- import { IUpdateCommentPayload } from '../mutations/comment.mutation';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand } from '@univerjs/core';
17
+ import type { IThreadComment } from '../../types/interfaces/i-thread-comment';
18
+ import type { IUpdateCommentPayload } from '../mutations/comment.mutation';
4
19
  export interface IAddCommentCommandParams {
5
20
  unitId: string;
6
21
  subUnitId: string;
@@ -1,5 +1,20 @@
1
- import { ICommand, IDocumentBody } from '@univerjs/core';
2
- import { IThreadComment } from '../../types/interfaces/i-thread-comment';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICommand, IDocumentBody } from '@univerjs/core';
17
+ import type { IThreadComment } from '../../types/interfaces/i-thread-comment';
3
18
  export interface IAddCommentMutationParams {
4
19
  unitId: string;
5
20
  subUnitId: string;
@@ -1,4 +1,19 @@
1
- import { DependencyOverride } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DependencyOverride } from '@univerjs/core';
2
17
  export declare const THREAD_COMMENT_PLUGIN_CONFIG_KEY = "thread-comment.config";
3
18
  export declare const configSymbol: unique symbol;
4
19
  export interface IUniverThreadCommentConfig {
@@ -1,4 +1,19 @@
1
- import { IThreadComment } from '../types/interfaces/i-thread-comment';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IThreadComment } from '../types/interfaces/i-thread-comment';
2
17
  import { Disposable, IResourceManagerService } from '@univerjs/core';
3
18
  import { ThreadCommentModel } from '../models/thread-comment.model';
4
19
  import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
@@ -1,6 +1,22 @@
1
- import { Nullable, Disposable, LifecycleService } from '@univerjs/core';
2
- import { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../commands/mutations/comment.mutation';
3
- import { IThreadComment } from '../types/interfaces/i-thread-comment';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Nullable } from '@univerjs/core';
17
+ import type { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../commands/mutations/comment.mutation';
18
+ import type { IThreadComment } from '../types/interfaces/i-thread-comment';
19
+ import { Disposable, LifecycleService } from '@univerjs/core';
4
20
  import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
5
21
  export type CommentUpdate = {
6
22
  unitId: string;
@@ -48,7 +64,7 @@ export declare class ThreadCommentModel extends Disposable {
48
64
  private _commentsMap;
49
65
  private _threadMap;
50
66
  private _commentUpdate$;
51
- commentUpdate$: import('rxjs').Observable<CommentUpdate>;
67
+ commentUpdate$: import("rxjs").Observable<CommentUpdate>;
52
68
  private _tasks;
53
69
  constructor(_dataSourceService: IThreadCommentDataSourceService, _lifecycleService: LifecycleService);
54
70
  private _ensureCommentMap;