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