@univerjs/thread-comment 0.1.17 → 0.2.0

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