@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
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { IEventBase, RichTextValue, FEventName } from '@univerjs/core';
|
|
2
2
|
import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
|
|
3
3
|
import { FTheadCommentItem, FThreadComment } from './f-thread-comment';
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
4
7
|
interface ICommentEventMixin {
|
|
5
8
|
/**
|
|
6
9
|
* Event fired after comment added
|
|
@@ -99,6 +102,9 @@ interface ICommentEventMixin {
|
|
|
99
102
|
*/
|
|
100
103
|
readonly BeforeCommentResolve: 'BeforeCommentResolve';
|
|
101
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* @ignore
|
|
107
|
+
*/
|
|
102
108
|
export declare class FCommentEvent extends FEventName {
|
|
103
109
|
get CommentAdded(): 'CommentAdded';
|
|
104
110
|
get BeforeCommentAdd(): 'BeforeCommentAdd';
|
|
@@ -228,6 +234,9 @@ export interface ISheetCommentResolveEvent extends IEventBase {
|
|
|
228
234
|
/** The new resolve status */
|
|
229
235
|
resolved: boolean;
|
|
230
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* @ignore
|
|
239
|
+
*/
|
|
231
240
|
export interface ISheetCommentEventConfig {
|
|
232
241
|
BeforeCommentAdd: IBeforeSheetCommentAddEvent;
|
|
233
242
|
CommentAdded: ISheetCommentAddEvent;
|
|
@@ -1,40 +1,95 @@
|
|
|
1
1
|
import { IDocumentBody, Nullable } from '@univerjs/core';
|
|
2
2
|
import { FRange } from '@univerjs/sheets/facade';
|
|
3
3
|
import { FTheadCommentBuilder, FThreadComment } from './f-thread-comment';
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
4
7
|
export interface IFRangeCommentMixin {
|
|
5
8
|
/**
|
|
6
9
|
* Get the comment of the start cell in the current range.
|
|
7
|
-
* @returns The comment of the start cell in the current range. If the cell does not have a comment, return `null`.
|
|
10
|
+
* @returns {FThreadComment | null} The comment of the start cell in the current range. If the cell does not have a comment, return `null`.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const range = univerAPI.getActiveWorkbook()
|
|
14
|
+
* .getActiveSheet()
|
|
15
|
+
* .getActiveRange();
|
|
16
|
+
* const comment = range.getComment();
|
|
17
|
+
* ```
|
|
8
18
|
*/
|
|
9
19
|
getComment(): Nullable<FThreadComment>;
|
|
10
20
|
/**
|
|
11
21
|
* Get the comments in the current range.
|
|
12
22
|
* @returns {FThreadComment[]} The comments in the current range.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const range = univerAPI.getActiveWorkbook()
|
|
26
|
+
* .getActiveSheet()
|
|
27
|
+
* .getActiveRange();
|
|
28
|
+
* const comments = range.getComments();
|
|
29
|
+
* comments.forEach((comment) => {
|
|
30
|
+
* console.log(comment.getContent());
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
13
33
|
*/
|
|
14
34
|
getComments(): FThreadComment[];
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated use `addCommentAsync` as instead.
|
|
37
|
+
*/
|
|
38
|
+
addComment(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>;
|
|
15
39
|
/**
|
|
16
40
|
* Add a comment to the start cell in the current range.
|
|
17
41
|
* @param content The content of the comment.
|
|
18
42
|
* @returns Whether the comment is added successfully.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const range = univerAPI.getActiveWorkbook()
|
|
46
|
+
* .getActiveSheet()
|
|
47
|
+
* .getActiveRange();
|
|
48
|
+
*
|
|
49
|
+
* const comment = univerAPI.newTheadComment()
|
|
50
|
+
* .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
|
|
51
|
+
* const success = await range.addCommentAsync(comment);
|
|
52
|
+
* ```
|
|
19
53
|
*/
|
|
20
|
-
|
|
54
|
+
addCommentAsync(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated use `clearCommentAsync` as instead.
|
|
57
|
+
*/
|
|
58
|
+
clearComment(): Promise<boolean>;
|
|
21
59
|
/**
|
|
22
60
|
* Clear the comment of the start cell in the current range.
|
|
23
61
|
* @returns Whether the comment is cleared successfully.
|
|
24
62
|
*/
|
|
25
|
-
|
|
63
|
+
clearCommentAsync(): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated use `clearComments` as instead.
|
|
66
|
+
*/
|
|
67
|
+
clearComments(): Promise<boolean>;
|
|
26
68
|
/**
|
|
27
69
|
* Clear all of the comments in the current range.
|
|
28
70
|
* @returns Whether the comments are cleared successfully.
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const range = univerAPI.getActiveWorkbook()
|
|
74
|
+
* .getActiveSheet()
|
|
75
|
+
* .getActiveRange();
|
|
76
|
+
* const success = await range.clearCommentsAsync();
|
|
77
|
+
* ```
|
|
29
78
|
*/
|
|
30
|
-
|
|
79
|
+
clearCommentsAsync(): Promise<boolean>;
|
|
31
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* @ignore
|
|
83
|
+
*/
|
|
32
84
|
export declare class FRangeCommentMixin extends FRange implements IFRangeCommentMixin {
|
|
33
85
|
getComment(): Nullable<FThreadComment>;
|
|
34
86
|
getComments(): FThreadComment[];
|
|
35
87
|
addComment(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>;
|
|
36
88
|
clearComment(): Promise<boolean>;
|
|
37
89
|
clearComments(): Promise<boolean>;
|
|
90
|
+
addCommentAsync(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>;
|
|
91
|
+
clearCommentAsync(): Promise<boolean>;
|
|
92
|
+
clearCommentsAsync(): Promise<boolean>;
|
|
38
93
|
}
|
|
39
94
|
declare module '@univerjs/sheets/facade' {
|
|
40
95
|
interface FRange extends IFRangeCommentMixin {
|
|
@@ -2,6 +2,10 @@ import { IDocumentBody, ICommandService, Injector, IUniverInstanceService, RichT
|
|
|
2
2
|
import { IBaseComment, IThreadComment } from '@univerjs/thread-comment';
|
|
3
3
|
import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
|
|
4
4
|
import { FRange } from '@univerjs/sheets/facade';
|
|
5
|
+
/**
|
|
6
|
+
* An readonly class that represents a comment.
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
5
9
|
export declare class FTheadCommentItem {
|
|
6
10
|
protected _comment: IThreadComment;
|
|
7
11
|
/**
|
|
@@ -21,8 +25,8 @@ export declare class FTheadCommentItem {
|
|
|
21
25
|
* @example
|
|
22
26
|
* ```ts
|
|
23
27
|
* const comment = univerAPI.getActiveWorkbook()
|
|
24
|
-
*
|
|
25
|
-
*
|
|
28
|
+
* .getSheetById(sheetId)
|
|
29
|
+
* .getCommentById(commentId);
|
|
26
30
|
* const personId = comment.personId;
|
|
27
31
|
* ```
|
|
28
32
|
*/
|
|
@@ -33,8 +37,8 @@ export declare class FTheadCommentItem {
|
|
|
33
37
|
* @example
|
|
34
38
|
* ```ts
|
|
35
39
|
* const comment = univerAPI.getActiveWorkbook()
|
|
36
|
-
*
|
|
37
|
-
*
|
|
40
|
+
* .getSheetById(sheetId)
|
|
41
|
+
* .getCommentById(commentId);
|
|
38
42
|
* const dateTime = comment.dateTime;
|
|
39
43
|
* ```
|
|
40
44
|
*/
|
|
@@ -45,8 +49,8 @@ export declare class FTheadCommentItem {
|
|
|
45
49
|
* @example
|
|
46
50
|
* ```ts
|
|
47
51
|
* const comment = univerAPI.getActiveWorkbook()
|
|
48
|
-
*
|
|
49
|
-
*
|
|
52
|
+
* .getSheetById(sheetId)
|
|
53
|
+
* .getCommentById(commentId);
|
|
50
54
|
* const content = comment.content;
|
|
51
55
|
* ```
|
|
52
56
|
*/
|
|
@@ -57,8 +61,8 @@ export declare class FTheadCommentItem {
|
|
|
57
61
|
* @example
|
|
58
62
|
* ```ts
|
|
59
63
|
* const comment = univerAPI.getActiveWorkbook()
|
|
60
|
-
*
|
|
61
|
-
*
|
|
64
|
+
* .getSheetById(sheetId)
|
|
65
|
+
* .getCommentById(commentId);
|
|
62
66
|
* const id = comment.id;
|
|
63
67
|
* ```
|
|
64
68
|
*/
|
|
@@ -69,8 +73,8 @@ export declare class FTheadCommentItem {
|
|
|
69
73
|
* @example
|
|
70
74
|
* ```ts
|
|
71
75
|
* const comment = univerAPI.getActiveWorkbook()
|
|
72
|
-
*
|
|
73
|
-
*
|
|
76
|
+
* .getSheetById(sheetId)
|
|
77
|
+
* .getCommentById(commentId);
|
|
74
78
|
* const threadId = comment.threadId;
|
|
75
79
|
* ```
|
|
76
80
|
*/
|
|
@@ -81,13 +85,16 @@ export declare class FTheadCommentItem {
|
|
|
81
85
|
* @example
|
|
82
86
|
* ```ts
|
|
83
87
|
* const comment = univerAPI.getActiveWorkbook()
|
|
84
|
-
*
|
|
85
|
-
*
|
|
88
|
+
* .getSheetById(sheetId)
|
|
89
|
+
* .getCommentById(commentId);
|
|
86
90
|
* const newComment = comment.copy();
|
|
87
91
|
* ```
|
|
88
92
|
*/
|
|
89
93
|
copy(): FTheadCommentBuilder;
|
|
90
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* A builder for thread comment. use {@link FUniver} `univerAPI.newTheadComment()` to create a new builder.
|
|
97
|
+
*/
|
|
91
98
|
export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
92
99
|
static create(comment?: IThreadComment): FTheadCommentBuilder;
|
|
93
100
|
/**
|
|
@@ -97,7 +104,7 @@ export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
|
97
104
|
* @example
|
|
98
105
|
* ```ts
|
|
99
106
|
* const comment = univerAPI.newTheadComment()
|
|
100
|
-
*
|
|
107
|
+
* .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
|
|
101
108
|
* ```
|
|
102
109
|
*/
|
|
103
110
|
setContent(content: IDocumentBody | RichTextValue): FTheadCommentBuilder;
|
|
@@ -108,7 +115,7 @@ export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
|
108
115
|
* @example
|
|
109
116
|
* ```ts
|
|
110
117
|
* const comment = univerAPI.newTheadComment()
|
|
111
|
-
*
|
|
118
|
+
* .setPersonId('123');
|
|
112
119
|
* ```
|
|
113
120
|
*/
|
|
114
121
|
setPersonId(userId: string): FTheadCommentBuilder;
|
|
@@ -119,7 +126,7 @@ export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
|
119
126
|
* @example
|
|
120
127
|
* ```ts
|
|
121
128
|
* const comment = univerAPI.newTheadComment()
|
|
122
|
-
*
|
|
129
|
+
* .setDateTime(new Date());
|
|
123
130
|
* ```
|
|
124
131
|
*/
|
|
125
132
|
setDateTime(date: Date): FTheadCommentBuilder;
|
|
@@ -130,7 +137,7 @@ export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
|
130
137
|
* @example
|
|
131
138
|
* ```ts
|
|
132
139
|
* const comment = univerAPI.newTheadComment()
|
|
133
|
-
*
|
|
140
|
+
* .setId('123');
|
|
134
141
|
* ```
|
|
135
142
|
*/
|
|
136
143
|
setId(id: string): FTheadCommentBuilder;
|
|
@@ -141,7 +148,7 @@ export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
|
141
148
|
* @example
|
|
142
149
|
* ```ts
|
|
143
150
|
* const comment = univerAPI.newTheadComment()
|
|
144
|
-
*
|
|
151
|
+
* .setThreadId('123');
|
|
145
152
|
* ```
|
|
146
153
|
*/
|
|
147
154
|
setThreadId(threadId: string): FTheadCommentBuilder;
|
|
@@ -151,12 +158,15 @@ export declare class FTheadCommentBuilder extends FTheadCommentItem {
|
|
|
151
158
|
* @example
|
|
152
159
|
* ```ts
|
|
153
160
|
* const comment = univerAPI.newTheadComment()
|
|
154
|
-
*
|
|
155
|
-
*
|
|
161
|
+
* .setContent(univerAPI.newRichText().insertText('hello zhangsan'))
|
|
162
|
+
* .build();
|
|
156
163
|
* ```
|
|
157
164
|
*/
|
|
158
165
|
build(): IThreadComment;
|
|
159
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* A class that represents a thread comment already in the sheet.
|
|
169
|
+
*/
|
|
160
170
|
export declare class FThreadComment {
|
|
161
171
|
private readonly _thread;
|
|
162
172
|
private readonly _parent;
|
|
@@ -165,52 +175,55 @@ export declare class FThreadComment {
|
|
|
165
175
|
private readonly _univerInstanceService;
|
|
166
176
|
private readonly _threadCommentModel;
|
|
167
177
|
private readonly _userManagerService;
|
|
178
|
+
/**
|
|
179
|
+
* @ignore
|
|
180
|
+
*/
|
|
168
181
|
constructor(_thread: IThreadComment | IBaseComment, _parent: IThreadComment | undefined, _injector: Injector, _commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _threadCommentModel: SheetsThreadCommentModel, _userManagerService: UserManagerService);
|
|
169
182
|
private _getRef;
|
|
170
183
|
/**
|
|
171
184
|
* Whether the comment is a root comment
|
|
172
|
-
* @returns Whether the comment is a root comment
|
|
185
|
+
* @returns {boolean} Whether the comment is a root comment
|
|
173
186
|
* @example
|
|
174
187
|
* ```ts
|
|
175
188
|
* const comment = univerAPI.getActiveWorkbook()
|
|
176
|
-
*
|
|
177
|
-
*
|
|
189
|
+
* .getSheetById(sheetId)
|
|
190
|
+
* .getCommentById(commentId);
|
|
178
191
|
* const isRoot = comment.getIsRoot();
|
|
179
192
|
* ```
|
|
180
193
|
*/
|
|
181
194
|
getIsRoot(): boolean;
|
|
182
195
|
/**
|
|
183
196
|
* Get the comment data
|
|
184
|
-
* @returns The comment data
|
|
197
|
+
* @returns {IBaseComment} The comment data
|
|
185
198
|
* @example
|
|
186
199
|
* ```ts
|
|
187
200
|
* const comment = univerAPI.getActiveWorkbook()
|
|
188
|
-
*
|
|
189
|
-
*
|
|
201
|
+
* .getSheetById(sheetId)
|
|
202
|
+
* .getCommentById(commentId);
|
|
190
203
|
* const commentData = comment.getCommentData();
|
|
191
204
|
* ```
|
|
192
205
|
*/
|
|
193
206
|
getCommentData(): IBaseComment;
|
|
194
207
|
/**
|
|
195
208
|
* Get the replies of the comment
|
|
196
|
-
* @returns the replies of the comment
|
|
209
|
+
* @returns {FThreadComment[]} the replies of the comment
|
|
197
210
|
* @example
|
|
198
211
|
* ```ts
|
|
199
212
|
* const comment = univerAPI.getActiveWorkbook()
|
|
200
|
-
*
|
|
201
|
-
*
|
|
213
|
+
* .getSheetById(sheetId)
|
|
214
|
+
* .getCommentById(commentId);
|
|
202
215
|
* const replies = comment.getReplies();
|
|
203
216
|
* ```
|
|
204
217
|
*/
|
|
205
218
|
getReplies(): FThreadComment[] | undefined;
|
|
206
219
|
/**
|
|
207
220
|
* Get the range of the comment
|
|
208
|
-
* @returns The range of the comment
|
|
221
|
+
* @returns {FRange | null} The range of the comment
|
|
209
222
|
* @example
|
|
210
223
|
* ```ts
|
|
211
224
|
* const comment = univerAPI.getActiveWorkbook()
|
|
212
|
-
*
|
|
213
|
-
*
|
|
225
|
+
* .getSheetById(sheetId)
|
|
226
|
+
* .getCommentById(commentId);
|
|
214
227
|
* const range = comment.getRange();
|
|
215
228
|
* ```
|
|
216
229
|
*/
|
|
@@ -225,8 +238,8 @@ export declare class FThreadComment {
|
|
|
225
238
|
* @example
|
|
226
239
|
* ```ts
|
|
227
240
|
* const comment = univerAPI.getActiveWorkbook()
|
|
228
|
-
*
|
|
229
|
-
*
|
|
241
|
+
* .getSheetById(sheetId)
|
|
242
|
+
* .getCommentById(commentId);
|
|
230
243
|
* const richText = comment.getRichText();
|
|
231
244
|
* ```
|
|
232
245
|
*/
|
|
@@ -237,8 +250,8 @@ export declare class FThreadComment {
|
|
|
237
250
|
* @example
|
|
238
251
|
* ```ts
|
|
239
252
|
* const comment = univerAPI.getActiveWorkbook()
|
|
240
|
-
*
|
|
241
|
-
*
|
|
253
|
+
* .getSheetById(sheetId)
|
|
254
|
+
* .getCommentById(commentId);
|
|
242
255
|
* const success = await comment.deleteAsync();
|
|
243
256
|
* ```
|
|
244
257
|
*/
|
|
@@ -248,53 +261,51 @@ export declare class FThreadComment {
|
|
|
248
261
|
*/
|
|
249
262
|
delete(): Promise<boolean>;
|
|
250
263
|
/**
|
|
251
|
-
* @param content
|
|
252
264
|
* @deprecated use `updateAsync` as instead
|
|
253
265
|
*/
|
|
254
266
|
update(content: IDocumentBody): Promise<boolean>;
|
|
255
267
|
/**
|
|
256
268
|
* Update the comment content
|
|
257
|
-
* @param content The new content of the comment
|
|
258
|
-
* @returns success or not
|
|
269
|
+
* @param {IDocumentBody | RichTextValue} content The new content of the comment
|
|
270
|
+
* @returns {Promise<boolean>} success or not
|
|
259
271
|
* @example
|
|
260
272
|
* ```ts
|
|
261
273
|
* const comment = univerAPI.getActiveWorkbook()
|
|
262
|
-
*
|
|
263
|
-
*
|
|
274
|
+
* .getSheetById(sheetId)
|
|
275
|
+
* .getCommentById(commentId);
|
|
264
276
|
* const success = await comment.updateAsync(univerAPI.newRichText().insertText('hello zhangsan'));
|
|
265
277
|
* ```
|
|
266
278
|
*/
|
|
267
279
|
updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>;
|
|
268
280
|
/**
|
|
269
|
-
* @param resolved
|
|
270
281
|
* @deprecated use `resolveAsync` as instead
|
|
271
282
|
*/
|
|
272
283
|
resolve(resolved?: boolean): Promise<boolean>;
|
|
273
284
|
/**
|
|
274
285
|
* Resolve the comment
|
|
275
|
-
* @param resolved Whether the comment is resolved
|
|
276
|
-
* @returns success or not
|
|
286
|
+
* @param {boolean} resolved Whether the comment is resolved
|
|
287
|
+
* @returns {Promise<boolean>} success or not
|
|
277
288
|
* @example
|
|
278
289
|
* ```ts
|
|
279
290
|
* const comment = univerAPI.getActiveWorkbook()
|
|
280
|
-
*
|
|
281
|
-
*
|
|
291
|
+
* .getSheetById(sheetId)
|
|
292
|
+
* .getCommentById(commentId);
|
|
282
293
|
* const success = await comment.resolveAsync(true);
|
|
283
294
|
* ```
|
|
284
295
|
*/
|
|
285
296
|
resolveAsync(resolved?: boolean): Promise<boolean>;
|
|
286
297
|
/**
|
|
287
298
|
* Reply to the comment
|
|
288
|
-
* @param comment The comment to reply to
|
|
289
|
-
* @returns success or not
|
|
299
|
+
* @param {FTheadCommentBuilder} comment The comment to reply to
|
|
300
|
+
* @returns {Promise<boolean>} success or not
|
|
290
301
|
* @example
|
|
291
302
|
* ```ts
|
|
292
303
|
* const comment = univerAPI.getActiveWorkbook()
|
|
293
|
-
*
|
|
294
|
-
*
|
|
304
|
+
* .getSheetById(sheetId)
|
|
305
|
+
* .getCommentById(commentId);
|
|
295
306
|
*
|
|
296
307
|
* const reply = univerAPI.newTheadComment()
|
|
297
|
-
*
|
|
308
|
+
* .setContent(univerAPI.newRichText().insertText('hello zhangsan'));
|
|
298
309
|
*
|
|
299
310
|
* const success = await comment.replyAsync(reply);
|
|
300
311
|
* ```
|
|
@@ -2,6 +2,9 @@ import { IDisposable, Injector, FUniver } from '@univerjs/core';
|
|
|
2
2
|
import { IThreadComment } from '@univerjs/thread-comment';
|
|
3
3
|
import { ISheetCommentAddEvent, ISheetCommentDeleteEvent, ISheetCommentResolveEvent, ISheetCommentUpdateEvent } from './f-event';
|
|
4
4
|
import { FTheadCommentBuilder } from './f-thread-comment';
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
5
8
|
export interface IFUniverCommentMixin {
|
|
6
9
|
/**
|
|
7
10
|
* @deprecated use `univerAPI.addEvent(univerAPI.event.CommentAdded, () => {})` as instead
|
|
@@ -21,7 +24,7 @@ export interface IFUniverCommentMixin {
|
|
|
21
24
|
onCommentResolved(callback: (event: ISheetCommentResolveEvent) => void): IDisposable;
|
|
22
25
|
/**
|
|
23
26
|
* create a new thread comment
|
|
24
|
-
* @
|
|
27
|
+
* @returns {FTheadCommentBuilder} thead comment builder
|
|
25
28
|
* @example
|
|
26
29
|
* ```ts
|
|
27
30
|
* const comment = univerAPI.newTheadComment().setContent(univerAPI.newRichText().insertText('hello zhangsan'));
|
|
@@ -29,9 +32,15 @@ export interface IFUniverCommentMixin {
|
|
|
29
32
|
*/
|
|
30
33
|
newTheadComment(): FTheadCommentBuilder;
|
|
31
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* @ignore
|
|
37
|
+
*/
|
|
32
38
|
export declare class FUniverCommentMixin extends FUniver implements IFUniverCommentMixin {
|
|
33
39
|
private _handleCommentCommand;
|
|
34
40
|
private _handleBeforeCommentCommand;
|
|
41
|
+
/**
|
|
42
|
+
* @ignore
|
|
43
|
+
*/
|
|
35
44
|
_initialize(injector: Injector): void;
|
|
36
45
|
newTheadComment(comment?: IThreadComment): FTheadCommentBuilder;
|
|
37
46
|
}
|
|
@@ -3,14 +3,28 @@ import { CommentUpdate, IAddCommentCommandParams, IDeleteCommentCommandParams, T
|
|
|
3
3
|
import { FWorkbook } from '@univerjs/sheets/facade';
|
|
4
4
|
import { FThreadComment } from './f-thread-comment';
|
|
5
5
|
type IUpdateCommandParams = any;
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
6
9
|
export interface IFWorkbookThreadCommentMixin {
|
|
7
10
|
/**
|
|
8
11
|
* Get all comments in the current sheet
|
|
9
12
|
* @returns all comments in the current sheet
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
16
|
+
* const comments = workbook.getComments();
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
19
|
getComments(): FThreadComment[];
|
|
12
20
|
/**
|
|
13
21
|
* Clear all comments in the current sheet
|
|
22
|
+
* @returns Whether the comments are cleared successfully.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
26
|
+
* const success = await workbook.clearComments();
|
|
27
|
+
* ```
|
|
14
28
|
*/
|
|
15
29
|
clearComments(): Promise<boolean>;
|
|
16
30
|
/**
|
|
@@ -30,24 +44,34 @@ export interface IFWorkbookThreadCommentMixin {
|
|
|
30
44
|
*/
|
|
31
45
|
onBeforeDeleteThreadComment(this: FWorkbook, callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
32
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @ignore
|
|
49
|
+
*/
|
|
33
50
|
export declare class FWorkbookThreadCommentMixin extends FWorkbook implements IFWorkbookThreadCommentMixin {
|
|
34
51
|
_threadCommentModel: ThreadCommentModel;
|
|
52
|
+
/**
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
35
55
|
_initialize(): void;
|
|
36
56
|
getComments(): FThreadComment[];
|
|
37
57
|
clearComments(): Promise<boolean>;
|
|
38
58
|
/**
|
|
59
|
+
* @param callback
|
|
39
60
|
* @deprecated
|
|
40
61
|
*/
|
|
41
62
|
onThreadCommentChange(callback: (commentUpdate: CommentUpdate) => void | false): IDisposable;
|
|
42
63
|
/**
|
|
64
|
+
* @param callback
|
|
43
65
|
* @deprecated
|
|
44
66
|
*/
|
|
45
67
|
onBeforeAddThreadComment(callback: (params: IAddCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
46
68
|
/**
|
|
69
|
+
* @param callback
|
|
47
70
|
* @deprecated
|
|
48
71
|
*/
|
|
49
72
|
onBeforeUpdateThreadComment(callback: (params: IUpdateCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
50
73
|
/**
|
|
74
|
+
* @param callback
|
|
51
75
|
* @deprecated
|
|
52
76
|
*/
|
|
53
77
|
onBeforeDeleteThreadComment(callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
@@ -2,6 +2,9 @@ import { IDisposable } from '@univerjs/core';
|
|
|
2
2
|
import { IAddCommentCommandParams } from '@univerjs/thread-comment';
|
|
3
3
|
import { FWorksheet } from '@univerjs/sheets/facade';
|
|
4
4
|
import { FThreadComment } from './f-thread-comment';
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
5
8
|
export interface IFWorksheetCommentMixin {
|
|
6
9
|
/**
|
|
7
10
|
* Get all comments in the current sheet
|
|
@@ -33,6 +36,9 @@ export interface IFWorksheetCommentMixin {
|
|
|
33
36
|
*/
|
|
34
37
|
getCommentById(commentId: string): FThreadComment | undefined;
|
|
35
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
36
42
|
export declare class FWorksheetCommentMixin extends FWorksheet implements IFWorksheetCommentMixin {
|
|
37
43
|
getComments(): FThreadComment[];
|
|
38
44
|
clearComments(): Promise<boolean>;
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.UniverSheetsThreadCommentFacade={},s.UniverCore,s.UniverSheetsThreadComment,s.UniverSheetsFacade,s.UniverThreadComment,s.UniverEngineFormula,s.rxjs))})(this,function(s,r,a,u,m,U,b){"use strict";var w=Object.defineProperty;var B=(s,r,a)=>r in s?w(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a;var T=(s,r,a)=>B(s,typeof r!="symbol"?r+"":r,a);var S=Object.defineProperty,j=Object.getOwnPropertyDescriptor,k=(h,e,t,n)=>{for(var o=n>1?void 0:n?j(e,t):e,i=h.length-1,d;i>=0;i--)(d=h[i])&&(o=(n?d(e,t,o):d(o))||o);return n&&o&&S(e,t,o),o},I=(h,e)=>(t,n)=>e(t,n,h);class p{constructor(e){T(this,"_comment",{id:r.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:r.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new p(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return r.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return _.create(r.Tools.deepClone(this._comment))}}class _ extends p{static create(e){return new _(e)}setContent(e){return e instanceof r.RichTextValue?this._comment.text=e.getData().body:this._comment.text=e,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=m.getDT(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}}s.FThreadComment=class{constructor(e,t,n,o,i,d,C){this._thread=e,this._parent=t,this._injector=n,this._commandService=o,this._univerInstanceService=i,this._threadCommentModel=d,this._userManagerService=C}_getRef(){var n;const e=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return U.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...t}=this._thread;return t}getReplies(){var n;const e=this._getRef(),t=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(n=t==null?void 0:t.children)==null?void 0:n.map(o=>this._injector.createInstance(s.FThreadComment,o))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,r.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;const n=this._getRef();return this._injector.createInstance(u.FRange,e,t,n)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return r.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?m.DeleteCommentTreeCommand.id:m.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(e){const t=e instanceof r.RichTextValue?e.getData().body:e,n=m.getDT();return await this._commandService.executeCommand(m.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:n}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(m.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}async replyAsync(e){var n;const t=e.build();return this._commandService.executeCommand(m.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:r.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(n=this._parent)==null?void 0:n.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:t.text,attachments:t.attachments,dT:t.dT||m.getDT(),personId:t.personId||this._userManagerService.getCurrentUser().userID}})}},s.FThreadComment=k([I(2,r.Inject(r.Injector)),I(3,r.ICommandService),I(4,r.IUniverInstanceService),I(5,r.Inject(a.SheetsThreadCommentModel)),I(6,r.Inject(r.UserManagerService))],s.FThreadComment);class y extends u.FRange{getComment(){const t=this._injector.get(a.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=t.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!i)return null;const d=t.getComment(n,o,i);return d?this._injector.createInstance(s.FThreadComment,d):null}getComments(){const t=this._injector.get(a.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=[];return r.Range.foreach(this._range,(d,C)=>{const l=t.getByLocation(n,o,d,C);if(l){const g=t.getComment(n,o,l);g&&i.push(this._injector.createInstance(s.FThreadComment,g))}}),i}addComment(e){var v;const t=this._injector,n=(v=this.getComment())==null?void 0:v.getCommentData(),o=t.get(r.ICommandService),i=t.get(r.UserManagerService),d=this._workbook.getUnitId(),C=this._worksheet.getSheetId(),l=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,g=i.getCurrentUser(),f=e instanceof _?e.build():{text:e};return o.executeCommand(m.AddCommentCommand.id,{unitId:d,subUnitId:C,comment:{text:f.text,dT:f.dT||m.getDT(),attachments:[],id:f.id||r.generateRandomId(),ref:l,personId:f.personId||g.userID,parentId:n==null?void 0:n.id,unitId:d,subUnitId:C,threadId:(n==null?void 0:n.threadId)||r.generateRandomId()}})}clearComment(){var d;const e=this._injector,t=(d=this.getComment())==null?void 0:d.getCommentData(),n=e.get(r.ICommandService),o=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return t?n.executeCommand(m.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:i,threadId:t.threadId,commentId:t.id}):Promise.resolve(!0)}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}}u.FRange.extend(y);class x extends u.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(m.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(s.FThreadComment,e.root))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onThreadCommentChange(e){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(b.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.DeleteCommentCommand.id||t.id===m.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}u.FWorkbook.extend(x);class D extends u.FWorksheet{getComments(){return this._injector.get(a.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(s.FThreadComment,n))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onCommented(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===m.AddCommentCommand.id){const o=n.params;e(o)}})}getCommentById(e){const n=this._injector.get(a.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(s.FThreadComment,n)}}u.FWorksheet.extend(D);const c={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class R extends r.FEventName{get CommentAdded(){return c.CommentAdded}get BeforeCommentAdd(){return c.BeforeCommentAdd}get CommentUpdated(){return c.CommentUpdated}get BeforeCommentUpdate(){return c.BeforeCommentUpdate}get CommentDeleted(){return c.CommentDeleted}get BeforeCommentDeleted(){return c.BeforeCommentDeleted}get CommentResolved(){return c.CommentResolved}get BeforeCommentResolve(){return c.BeforeCommentResolve}}r.FEventName.extend(R),Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsThreadCommentFacade={},global.UniverCore,global.UniverSheetsThreadComment,global.UniverSheetsFacade,global.UniverThreadComment,global.UniverEngineFormula,global.rxjs))})(this,function(exports2,core,sheetsThreadComment,facade,threadComment,engineFormula,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a;var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const _FTheadCommentItem=class _FTheadCommentItem{constructor(comment){__publicField(this,"_comment",{id:core.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:core.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});comment&&(this._comment=comment)}static create(comment){return new _FTheadCommentItem(comment)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return core.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return FTheadCommentBuilder.create(core.Tools.deepClone(this._comment))}};__name(_FTheadCommentItem,"FTheadCommentItem");let FTheadCommentItem=_FTheadCommentItem;const _FTheadCommentBuilder=class _FTheadCommentBuilder extends FTheadCommentItem{static create(comment){return new _FTheadCommentBuilder(comment)}setContent(content){return content instanceof core.RichTextValue?this._comment.text=content.getData().body:this._comment.text=content,this}setPersonId(userId){return this._comment.personId=userId,this}setDateTime(date){return this._comment.dT=threadComment.getDT(date),this}setId(id){return this._comment.id=id,this}setThreadId(threadId){return this._comment.threadId=threadId,this}build(){return this._comment}};__name(_FTheadCommentBuilder,"FTheadCommentBuilder");let FTheadCommentBuilder=_FTheadCommentBuilder;exports2.FThreadComment=(_a=class{constructor(_thread,_parent,_injector,_commandService,_univerInstanceService,_threadCommentModel,_userManagerService){this._thread=_thread,this._parent=_parent,this._injector=_injector,this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._threadCommentModel=_threadCommentModel,this._userManagerService=_userManagerService}_getRef(){var _a2;const ref=((_a2=this._parent)==null?void 0:_a2.ref)||this._thread.ref;return engineFormula.deserializeRangeWithSheet(ref).range}getIsRoot(){return!this._parent}getCommentData(){const{children,...comment}=this._thread;return comment}getReplies(){var _a2;const range=this._getRef(),comments=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,range.startRow,range.startColumn);return(_a2=comments==null?void 0:comments.children)==null?void 0:_a2.map(child=>this._injector.createInstance(exports2.FThreadComment,child))}getRange(){const workbook=this._univerInstanceService.getUnit(this._thread.unitId,core.UniverInstanceType.UNIVER_SHEET);if(!workbook)return null;const worksheet=workbook.getSheetBySheetId(this._thread.subUnitId);if(!worksheet)return null;const range=this._getRef();return this._injector.createInstance(facade.FRange,workbook,worksheet,range)}getContent(){return this._thread.text}getRichText(){const body=this._thread.text;return core.RichTextValue.create({body,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?threadComment.DeleteCommentTreeCommand.id:threadComment.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(content){return this.updateAsync(content)}async updateAsync(content){const body=content instanceof core.RichTextValue?content.getData().body:content,dt=threadComment.getDT();return await this._commandService.executeCommand(threadComment.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:body,updated:!0,updateT:dt}})}resolve(resolved){return this.resolveAsync(resolved)}resolveAsync(resolved){return this._commandService.executeCommand(threadComment.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:resolved!=null?resolved:!this._thread.resolved})}async replyAsync(comment){var _a2;const commentData=comment.build();return this._commandService.executeCommand(threadComment.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:core.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(_a2=this._parent)==null?void 0:_a2.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:commentData.text,attachments:commentData.attachments,dT:commentData.dT||threadComment.getDT(),personId:commentData.personId||this._userManagerService.getCurrentUser().userID}})}},__name(_a,"FThreadComment"),_a),exports2.FThreadComment=__decorateClass([__decorateParam(2,core.Inject(core.Injector)),__decorateParam(3,core.ICommandService),__decorateParam(4,core.IUniverInstanceService),__decorateParam(5,core.Inject(sheetsThreadComment.SheetsThreadCommentModel)),__decorateParam(6,core.Inject(core.UserManagerService))],exports2.FThreadComment);const _FRangeCommentMixin=class _FRangeCommentMixin extends facade.FRange{getComment(){const sheetsTheadCommentModel=this._injector.get(sheetsThreadComment.SheetsThreadCommentModel),unitId=this._workbook.getUnitId(),sheetId=this._worksheet.getSheetId(),commentId=sheetsTheadCommentModel.getByLocation(unitId,sheetId,this._range.startRow,this._range.startColumn);if(!commentId)return null;const comment=sheetsTheadCommentModel.getComment(unitId,sheetId,commentId);return comment?this._injector.createInstance(exports2.FThreadComment,comment):null}getComments(){const sheetsTheadCommentModel=this._injector.get(sheetsThreadComment.SheetsThreadCommentModel),unitId=this._workbook.getUnitId(),sheetId=this._worksheet.getSheetId(),comments=[];return core.Range.foreach(this._range,(row,col)=>{const commentId=sheetsTheadCommentModel.getByLocation(unitId,sheetId,row,col);if(commentId){const comment=sheetsTheadCommentModel.getComment(unitId,sheetId,commentId);comment&&comments.push(this._injector.createInstance(exports2.FThreadComment,comment))}}),comments}addComment(content){var _a2;const injector=this._injector,currentComment=(_a2=this.getComment())==null?void 0:_a2.getCommentData(),commentService=injector.get(core.ICommandService),userService=injector.get(core.UserManagerService),unitId=this._workbook.getUnitId(),sheetId=this._worksheet.getSheetId(),refStr=`${core.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,currentUser=userService.getCurrentUser(),commentData=content instanceof FTheadCommentBuilder?content.build():{text:content};return commentService.executeCommand(threadComment.AddCommentCommand.id,{unitId,subUnitId:sheetId,comment:{text:commentData.text,dT:commentData.dT||threadComment.getDT(),attachments:[],id:commentData.id||core.generateRandomId(),ref:refStr,personId:commentData.personId||currentUser.userID,parentId:currentComment==null?void 0:currentComment.id,unitId,subUnitId:sheetId,threadId:(currentComment==null?void 0:currentComment.threadId)||core.generateRandomId()}})}clearComment(){var _a2;const injector=this._injector,currentComment=(_a2=this.getComment())==null?void 0:_a2.getCommentData(),commentService=injector.get(core.ICommandService),unitId=this._workbook.getUnitId(),sheetId=this._worksheet.getSheetId();return currentComment?commentService.executeCommand(threadComment.DeleteCommentTreeCommand.id,{unitId,subUnitId:sheetId,threadId:currentComment.threadId,commentId:currentComment.id}):Promise.resolve(!0)}clearComments(){const promises=this.getComments().map(comment=>comment.deleteAsync());return Promise.all(promises).then(()=>!0)}addCommentAsync(content){return this.addComment(content)}clearCommentAsync(){return this.clearComment()}clearCommentsAsync(){return this.clearComments()}};__name(_FRangeCommentMixin,"FRangeCommentMixin");let FRangeCommentMixin=_FRangeCommentMixin;facade.FRange.extend(FRangeCommentMixin);const _FWorkbookThreadCommentMixin=class _FWorkbookThreadCommentMixin extends facade.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(threadComment.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(i=>this._injector.createInstance(exports2.FThreadComment,i.root))}clearComments(){const promises=this.getComments().map(comment=>comment.deleteAsync());return Promise.all(promises).then(()=>!0)}onThreadCommentChange(callback){return core.toDisposable(this._threadCommentModel.commentUpdate$.pipe(rxjs.filter(change=>change.unitId===this._workbook.getUnitId())).subscribe(callback))}onBeforeAddThreadComment(callback){return core.toDisposable(this._commandService.beforeCommandExecuted((commandInfo,options)=>{const params=commandInfo.params;if(commandInfo.id===threadComment.AddCommentCommand.id){if(params.unitId!==this._workbook.getUnitId())return;if(callback(params,options)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(callback){return core.toDisposable(this._commandService.beforeCommandExecuted((commandInfo,options)=>{const params=commandInfo.params;if(commandInfo.id===threadComment.UpdateCommentCommand.id){if(params.unitId!==this._workbook.getUnitId())return;if(callback(params,options)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(callback){return core.toDisposable(this._commandService.beforeCommandExecuted((commandInfo,options)=>{const params=commandInfo.params;if(commandInfo.id===threadComment.DeleteCommentCommand.id||commandInfo.id===threadComment.DeleteCommentTreeCommand.id){if(params.unitId!==this._workbook.getUnitId())return;if(callback(params,options)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}};__name(_FWorkbookThreadCommentMixin,"FWorkbookThreadCommentMixin");let FWorkbookThreadCommentMixin=_FWorkbookThreadCommentMixin;facade.FWorkbook.extend(FWorkbookThreadCommentMixin);const _FWorksheetCommentMixin=class _FWorksheetCommentMixin extends facade.FWorksheet{getComments(){return this._injector.get(sheetsThreadComment.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(comment=>this._injector.createInstance(exports2.FThreadComment,comment))}clearComments(){const promises=this.getComments().map(comment=>comment.deleteAsync());return Promise.all(promises).then(()=>!0)}onCommented(callback){return this._injector.get(core.ICommandService).onCommandExecuted(command=>{if(command.id===threadComment.AddCommentCommand.id){const params=command.params;callback(params)}})}getCommentById(commentId){const comment=this._injector.get(sheetsThreadComment.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),commentId);if(comment)return this._injector.createInstance(exports2.FThreadComment,comment)}};__name(_FWorksheetCommentMixin,"FWorksheetCommentMixin");let FWorksheetCommentMixin=_FWorksheetCommentMixin;facade.FWorksheet.extend(FWorksheetCommentMixin);const CommentEvent={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"},_FCommentEvent=class _FCommentEvent extends core.FEventName{get CommentAdded(){return CommentEvent.CommentAdded}get BeforeCommentAdd(){return CommentEvent.BeforeCommentAdd}get CommentUpdated(){return CommentEvent.CommentUpdated}get BeforeCommentUpdate(){return CommentEvent.BeforeCommentUpdate}get CommentDeleted(){return CommentEvent.CommentDeleted}get BeforeCommentDeleted(){return CommentEvent.BeforeCommentDeleted}get CommentResolved(){return CommentEvent.CommentResolved}get BeforeCommentResolve(){return CommentEvent.BeforeCommentResolve}};__name(_FCommentEvent,"FCommentEvent");let FCommentEvent=_FCommentEvent;core.FEventName.extend(FCommentEvent),Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/thread-comment"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula","@univerjs/sheets","@univerjs/thread-comment","rxjs"],o):(m=typeof globalThis<"u"?globalThis:m||self,o(m.UniverSheetsThreadComment={},m.UniverCore,m.UniverEngineFormula,m.UniverSheets,m.UniverThreadComment,m.rxjs))})(this,function(m,o,l,g,p,S){"use strict";var O=Object.defineProperty;var x=(m,o,l)=>o in m?O(m,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):m[o]=l;var f=(m,o,l)=>x(m,typeof o!="symbol"?o+"":o,l);var T=Object.defineProperty,y=Object.getOwnPropertyDescriptor,U=(h,i,e,n)=>{for(var t=n>1?void 0:n?y(i,e):i,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&T(i,e,t),t},M=(h,i)=>(e,n)=>i(e,n,h);m.SheetsThreadCommentModel=class extends o.Disposable{constructor(e,n){super();f(this,"_matrixMap",new Map);f(this,"_locationMap",new Map);f(this,"_commentUpdate$",new S.Subject);f(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let t=this._matrixMap.get(e);t||(t=new Map,this._matrixMap.set(e,t));let r=t.get(n);return r||(r=new o.ObjectMatrix,t.set(n,r)),r}_ensureCommentLocationMap(e,n){let t=this._locationMap.get(e);t||(t=new Map,this._locationMap.set(e,t));let r=t.get(n);return r||(r=new Map,t.set(n,r)),r}_addCommentToMatrix(e,n,t,r){var a;const s=(a=e.getValue(n,t))!=null?a:new Set;s.add(r),e.setValue(n,t,s)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const s=e.getValue(n,t);s&&s.has(r)&&(s.delete(r),s.size===0&&e.realDeleteValue(n,t))}}_ensure(e,n){const t=this._ensureCommentMatrix(e,n),r=this._ensureCommentLocationMap(e,n);return{matrix:t,locationMap:r}}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t;this._addComment(r,s,a)}}_addComment(e,n,t){const r=l.singleReferenceToGrid(t.ref),s=t.parentId,{row:a,column:d}=r,c=t.id,{matrix:_,locationMap:u}=this._ensure(e,n);!s&&a>=0&&d>=0&&(this._addCommentToMatrix(_,a,d,c),u.set(c,{row:a,column:d})),s||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!s,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==o.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:s}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:a,comment:d}=e.payload;if(a){const c=l.singleReferenceToGrid(d.ref),{row:_,column:u}=c;this._deleteCommentFromMatrix(r,_,u,d.id),this._commentUpdate$.next({...e,...c})}break}case"update":{const{commentId:a}=e.payload,d=this._threadCommentModel.getComment(n,t,a);if(!d)return;const c=l.singleReferenceToGrid(d.ref);this._commentUpdate$.next({...e,...c});break}case"updateRef":{const a=l.singleReferenceToGrid(e.payload.ref),{commentId:d}=e.payload,c=s.get(d);if(!c)return;const{row:_,column:u}=c;this._deleteCommentFromMatrix(r,_,u,d),s.delete(d),a.row>=0&&a.column>=0&&(this._addCommentToMatrix(r,a.row,a.column,d),s.set(d,{row:a.row,column:a.column})),this._commentUpdate$.next({...e,...a});break}case"resolve":{const{unitId:a,subUnitId:d,payload:c}=e,{locationMap:_}=this._ensure(a,d),u=_.get(c.commentId);u&&this._commentUpdate$.next({...e,...u});break}}}))}getByLocation(e,n,t,r){var d;return(d=this.getAllByLocation(e,n,t,r).filter(c=>!c.resolved)[0])==null?void 0:d.id}getAllByLocation(e,n,t,r){const a=this._ensureCommentMatrix(e,n).getValue(t,r);return a?Array.from(a).map(d=>this.getComment(e,n,d)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return;const a=this.getComment(e,n,s);if(a)return this._threadCommentModel.getThread(e,n,a.threadId)}showCommentMarker(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return!1;const a=this.getComment(e,n,s);return!!(a&&!a.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}},m.SheetsThreadCommentModel=U([M(0,o.Inject(p.ThreadCommentModel)),M(1,o.IUniverInstanceService)],m.SheetsThreadCommentModel);var I=Object.defineProperty,b=Object.getOwnPropertyDescriptor,j=(h,i,e,n)=>{for(var t=n>1?void 0:n?b(i,e):i,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&I(i,e,t),t},C=(h,i)=>(e,n)=>i(e,n,h);m.SheetsThreadCommentRefRangeController=class extends o.Disposable{constructor(e,n,t,r,s){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(e,n,t,r,s)=>{const a=t.id,d={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:p.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:l.serializeRange(r),commentId:a},silent:s}}],undos:[{id:p.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:l.serializeRange(d),commentId:a},silent:s}}]}:{redos:[{id:p.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:a}}],undos:[{id:p.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:t,sync:!0}}]}});this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=t,this._selectionManagerService=r,this._commandService=s,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(s,a=>{const d=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,a,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(d)?d[0]:d;return c&&c.startColumn===s.startColumn&&c.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,c,!1)},e,n))}_watch(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watcherMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.watchRange(e,n,s,(a,d)=>{const{redos:c}=this._handleRangeChange(e,n,t,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._watcherMap.get(r))==null||s.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._disposableMap.get(r))==null||s.dispose(),this._disposableMap.delete(r)}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t,d=l.singleReferenceToGrid(a.ref),c={...a,...d};this._register(r,s,c),this._watch(r,s,c)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;switch(e.type){case"add":{if(e.payload.parentId)return;const r={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,r),this._watch(e.unitId,e.subUnitId,r);break}case"delete":{this._unregister(n,t,e.payload.commentId),this._unwatch(n,t,e.payload.commentId);break}case"updateRef":{const r=this._sheetsThreadCommentModel.getComment(n,t,e.payload.commentId);if(!r)return;this._unregister(n,t,e.payload.commentId);const s={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,s)),this._register(e.unitId,e.subUnitId,s);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}},m.SheetsThreadCommentRefRangeController=j([C(0,o.Inject(g.RefRangeService)),C(1,o.Inject(m.SheetsThreadCommentModel)),C(2,o.Inject(p.ThreadCommentModel)),C(3,o.Inject(g.SheetsSelectionsService)),C(4,o.ICommandService)],m.SheetsThreadCommentRefRangeController);const P="SHEET_THREAD_COMMENT_BASE_PLUGIN";var v=Object.defineProperty,$=Object.getOwnPropertyDescriptor,E=(h,i,e)=>i in h?v(h,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[i]=e,D=(h,i,e,n)=>{for(var t=n>1?void 0:n?$(i,e):i,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&v(i,e,t),t},R=(h,i)=>(e,n)=>i(e,n,h),w=(h,i,e)=>E(h,typeof i!="symbol"?i+"":i,e);m.UniverSheetsThreadCommentPlugin=class extends o.Plugin{constructor(i,e,n){super(),this._injector=e,this._commandService=n}onStarting(){[[m.SheetsThreadCommentModel],[m.SheetsThreadCommentRefRangeController]].forEach(i=>{this._injector.add(i)}),this._injector.get(m.SheetsThreadCommentRefRangeController)}},w(m.UniverSheetsThreadCommentPlugin,"pluginName",P),w(m.UniverSheetsThreadCommentPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsThreadCommentPlugin=D([o.DependentOn(p.UniverThreadCommentPlugin),R(1,o.Inject(o.Injector)),R(2,o.Inject(o.ICommandService))],m.UniverSheetsThreadCommentPlugin),Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/thread-comment"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula","@univerjs/sheets","@univerjs/thread-comment","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsThreadComment={},global.UniverCore,global.UniverEngineFormula,global.UniverSheets,global.UniverThreadComment,global.rxjs))})(this,function(exports2,core,engineFormula,sheets,threadComment,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");exports2.SheetsThreadCommentModel=(_a=class extends core.Disposable{constructor(_threadCommentModel,_univerInstanceService){super();__publicField(this,"_matrixMap",new Map);__publicField(this,"_locationMap",new Map);__publicField(this,"_commentUpdate$",new rxjs.Subject);__publicField(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=_threadCommentModel,this._univerInstanceService=_univerInstanceService,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(unitId,subUnitId){let unitMap=this._matrixMap.get(unitId);unitMap||(unitMap=new Map,this._matrixMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new core.ObjectMatrix,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_ensureCommentLocationMap(unitId,subUnitId){let unitMap=this._locationMap.get(unitId);unitMap||(unitMap=new Map,this._locationMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new Map,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_addCommentToMatrix(matrix,row,column,commentId){var _a2;const current=(_a2=matrix.getValue(row,column))!=null?_a2:new Set;current.add(commentId),matrix.setValue(row,column,current)}_deleteCommentFromMatrix(matrix,row,column,commentId){if(row>=0&&column>=0){const current=matrix.getValue(row,column);current&¤t.has(commentId)&&(current.delete(commentId),current.size===0&&matrix.realDeleteValue(row,column))}}_ensure(unitId,subUnitId){const matrix=this._ensureCommentMatrix(unitId,subUnitId),locationMap=this._ensureCommentLocationMap(unitId,subUnitId);return{matrix,locationMap}}_initData(){const datas=this._threadCommentModel.getAll();for(const data of datas)for(const thread of data.threads){const{unitId,subUnitId,root}=thread;this._addComment(unitId,subUnitId,root)}}_addComment(unitId,subUnitId,comment){const location=engineFormula.singleReferenceToGrid(comment.ref),parentId=comment.parentId,{row,column}=location,commentId=comment.id,{matrix,locationMap}=this._ensure(unitId,subUnitId);!parentId&&row>=0&&column>=0&&(this._addCommentToMatrix(matrix,row,column,commentId),locationMap.set(commentId,{row,column})),parentId||this._commentUpdate$.next({unitId,subUnitId,payload:comment,type:"add",isRoot:!parentId,...location})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(update=>{const{unitId,subUnitId}=update;try{if(this._univerInstanceService.getUnitType(unitId)!==core.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix,locationMap}=this._ensure(unitId,subUnitId);switch(update.type){case"add":{this._addComment(update.unitId,update.subUnitId,update.payload);break}case"delete":{const{isRoot,comment}=update.payload;if(isRoot){const location=engineFormula.singleReferenceToGrid(comment.ref),{row,column}=location;this._deleteCommentFromMatrix(matrix,row,column,comment.id),this._commentUpdate$.next({...update,...location})}break}case"update":{const{commentId}=update.payload,comment=this._threadCommentModel.getComment(unitId,subUnitId,commentId);if(!comment)return;const location=engineFormula.singleReferenceToGrid(comment.ref);this._commentUpdate$.next({...update,...location});break}case"updateRef":{const location=engineFormula.singleReferenceToGrid(update.payload.ref),{commentId}=update.payload,currentLoc=locationMap.get(commentId);if(!currentLoc)return;const{row,column}=currentLoc;this._deleteCommentFromMatrix(matrix,row,column,commentId),locationMap.delete(commentId),location.row>=0&&location.column>=0&&(this._addCommentToMatrix(matrix,location.row,location.column,commentId),locationMap.set(commentId,{row:location.row,column:location.column})),this._commentUpdate$.next({...update,...location});break}case"resolve":{const{unitId:unitId2,subUnitId:subUnitId2,payload}=update,{locationMap:locationMap2}=this._ensure(unitId2,subUnitId2),location=locationMap2.get(payload.commentId);location&&this._commentUpdate$.next({...update,...location});break}}}))}getByLocation(unitId,subUnitId,row,column){var _a2;return(_a2=this.getAllByLocation(unitId,subUnitId,row,column).filter(comment=>!comment.resolved)[0])==null?void 0:_a2.id}getAllByLocation(unitId,subUnitId,row,column){const current=this._ensureCommentMatrix(unitId,subUnitId).getValue(row,column);return current?Array.from(current).map(id=>this.getComment(unitId,subUnitId,id)).filter(Boolean):[]}getComment(unitId,subUnitId,commentId){return this._threadCommentModel.getComment(unitId,subUnitId,commentId)}getCommentWithChildren(unitId,subUnitId,row,column){const commentId=this.getByLocation(unitId,subUnitId,row,column);if(!commentId)return;const comment=this.getComment(unitId,subUnitId,commentId);if(comment)return this._threadCommentModel.getThread(unitId,subUnitId,comment.threadId)}showCommentMarker(unitId,subUnitId,row,column){const commentId=this.getByLocation(unitId,subUnitId,row,column);if(!commentId)return!1;const comment=this.getComment(unitId,subUnitId,commentId);return!!(comment&&!comment.resolved)}getSubUnitAll(unitId,subUnitId){return this._threadCommentModel.getUnit(unitId).filter(i=>i.subUnitId===subUnitId).map(i=>i.root)}},__name(_a,"SheetsThreadCommentModel"),_a),exports2.SheetsThreadCommentModel=__decorateClass$2([__decorateParam$2(0,core.Inject(threadComment.ThreadCommentModel)),__decorateParam$2(1,core.IUniverInstanceService)],exports2.SheetsThreadCommentModel);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.SheetsThreadCommentRefRangeController=(_b=class extends core.Disposable{constructor(_refRangeService,_sheetsThreadCommentModel,_threadCommentModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watcherMap",new Map);__publicField(this,"_handleRangeChange",__name((unitId,subUnitId,comment,resultRange,silent)=>{const commentId=comment.id,oldRange={startColumn:comment.column,endColumn:comment.column,startRow:comment.row,endRow:comment.row};return resultRange?{redos:[{id:threadComment.UpdateCommentRefMutation.id,params:{unitId,subUnitId,payload:{ref:engineFormula.serializeRange(resultRange),commentId},silent}}],undos:[{id:threadComment.UpdateCommentRefMutation.id,params:{unitId,subUnitId,payload:{ref:engineFormula.serializeRange(oldRange),commentId},silent}}]}:{redos:[{id:threadComment.DeleteCommentMutation.id,params:{unitId,subUnitId,commentId}}],undos:[{id:threadComment.AddCommentMutation.id,params:{unitId,subUnitId,comment,sync:!0}}]}},"_handleRangeChange"));this._refRangeService=_refRangeService,this._sheetsThreadCommentModel=_sheetsThreadCommentModel,this._threadCommentModel=_threadCommentModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_getIdWithUnitId(unitId,subUnitId,id){return`${unitId}-${subUnitId}-${id}`}_register(unitId,subUnitId,comment){const commentId=comment.id,oldRange={startColumn:comment.column,endColumn:comment.column,startRow:comment.row,endRow:comment.row};this._disposableMap.set(this._getIdWithUnitId(unitId,subUnitId,commentId),this._refRangeService.registerRefRange(oldRange,commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handleRangeChange(unitId,subUnitId,comment,resultRange,!1)},unitId,subUnitId))}_watch(unitId,subUnitId,comment){const commentId=comment.id,oldRange={startColumn:comment.column,endColumn:comment.column,startRow:comment.row,endRow:comment.row};this._watcherMap.set(this._getIdWithUnitId(unitId,subUnitId,commentId),this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handleRangeChange(unitId,subUnitId,comment,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unwatch(unitId,subUnitId,commentId){var _a2;const id=this._getIdWithUnitId(unitId,subUnitId,commentId);(_a2=this._watcherMap.get(id))==null||_a2.dispose(),this._watcherMap.delete(id)}_unregister(unitId,subUnitId,commentId){var _a2;const id=this._getIdWithUnitId(unitId,subUnitId,commentId);(_a2=this._disposableMap.get(id))==null||_a2.dispose(),this._disposableMap.delete(id)}_initData(){const datas=this._threadCommentModel.getAll();for(const data of datas)for(const thread of data.threads){const{unitId,subUnitId,root}=thread,pos=engineFormula.singleReferenceToGrid(root.ref),sheetComment={...root,...pos};this._register(unitId,subUnitId,sheetComment),this._watch(unitId,subUnitId,sheetComment)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(option=>{const{unitId,subUnitId}=option;switch(option.type){case"add":{if(option.payload.parentId)return;const comment={...option.payload,row:option.row,column:option.column};this._register(option.unitId,option.subUnitId,comment),this._watch(option.unitId,option.subUnitId,comment);break}case"delete":{this._unregister(unitId,subUnitId,option.payload.commentId),this._unwatch(unitId,subUnitId,option.payload.commentId);break}case"updateRef":{const comment=this._sheetsThreadCommentModel.getComment(unitId,subUnitId,option.payload.commentId);if(!comment)return;this._unregister(unitId,subUnitId,option.payload.commentId);const sheetComment={...comment,row:option.row,column:option.column};option.silent||(this._unwatch(unitId,subUnitId,option.payload.commentId),this._watch(unitId,subUnitId,sheetComment)),this._register(option.unitId,option.subUnitId,sheetComment);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_b,"SheetsThreadCommentRefRangeController"),_b),exports2.SheetsThreadCommentRefRangeController=__decorateClass$1([__decorateParam$1(0,core.Inject(sheets.RefRangeService)),__decorateParam$1(1,core.Inject(exports2.SheetsThreadCommentModel)),__decorateParam$1(2,core.Inject(threadComment.ThreadCommentModel)),__decorateParam$1(3,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$1(4,core.ICommandService)],exports2.SheetsThreadCommentRefRangeController);const SHEET_THREAD_COMMENT_BASE="SHEET_THREAD_COMMENT_BASE_PLUGIN";var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverSheetsThreadCommentPlugin=(_c=class extends core.Plugin{constructor(config,_injector,_commandService){super(),this._injector=_injector,this._commandService=_commandService}onStarting(){[[exports2.SheetsThreadCommentModel],[exports2.SheetsThreadCommentRefRangeController]].forEach(dep=>{this._injector.add(dep)}),this._injector.get(exports2.SheetsThreadCommentRefRangeController)}},__name(_c,"UniverSheetsThreadCommentPlugin"),_c),__publicField2(exports2.UniverSheetsThreadCommentPlugin,"pluginName",SHEET_THREAD_COMMENT_BASE),__publicField2(exports2.UniverSheetsThreadCommentPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsThreadCommentPlugin=__decorateClass([core.DependentOn(threadComment.UniverThreadCommentPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.ICommandService))],exports2.UniverSheetsThreadCommentPlugin),Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|