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