@ckeditor/ckeditor5-comments 38.0.1 → 38.1.1

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.
Files changed (98) hide show
  1. package/build/comments.js +1 -1
  2. package/build/translations/en-au.js +1 -1
  3. package/build/translations/it.js +1 -1
  4. package/build/translations/lv.js +1 -1
  5. package/build/translations/pt-br.js +1 -1
  6. package/build/translations/sk.js +1 -1
  7. package/build/translations/sq.js +1 -0
  8. package/lang/translations/en-au.po +1 -1
  9. package/lang/translations/it.po +1 -1
  10. package/lang/translations/lv.po +1 -1
  11. package/lang/translations/pt-br.po +1 -1
  12. package/lang/translations/sk.po +1 -1
  13. package/lang/translations/sq.po +111 -0
  14. package/package.json +10 -8
  15. package/src/annotations/annotation.d.ts +86 -86
  16. package/src/annotations/annotation.js +1 -1
  17. package/src/annotations/annotationcollection.d.ts +94 -94
  18. package/src/annotations/annotationcollection.js +1 -1
  19. package/src/annotations/annotations.d.ts +150 -150
  20. package/src/annotations/annotations.js +1 -1
  21. package/src/annotations/annotationsuis.d.ts +228 -227
  22. package/src/annotations/annotationsuis.js +1 -1
  23. package/src/annotations/editorannotations.d.ts +63 -62
  24. package/src/annotations/editorannotations.js +1 -1
  25. package/src/annotations/inlineannotations.d.ts +86 -84
  26. package/src/annotations/inlineannotations.js +1 -1
  27. package/src/annotations/narrowsidebar.d.ts +81 -80
  28. package/src/annotations/narrowsidebar.js +1 -1
  29. package/src/annotations/sidebar.d.ts +96 -96
  30. package/src/annotations/sidebar.js +1 -1
  31. package/src/annotations/view/annotationcounterbuttonview.d.ts +25 -25
  32. package/src/annotations/view/annotationcounterbuttonview.js +1 -1
  33. package/src/annotations/view/annotationview.d.ts +86 -86
  34. package/src/annotations/view/annotationview.js +1 -1
  35. package/src/annotations/view/sidebaritemview.d.ts +51 -51
  36. package/src/annotations/view/sidebaritemview.js +1 -1
  37. package/src/annotations/view/sidebarview.d.ts +28 -28
  38. package/src/annotations/view/sidebarview.js +1 -1
  39. package/src/annotations/widesidebar.d.ts +73 -72
  40. package/src/annotations/widesidebar.js +1 -1
  41. package/src/augmentation.d.ts +48 -48
  42. package/src/comments/addcommentthreadcommand.d.ts +31 -31
  43. package/src/comments/addcommentthreadcommand.js +1 -1
  44. package/src/comments/commentsarchive.d.ts +27 -25
  45. package/src/comments/commentsarchive.js +1 -1
  46. package/src/comments/commentsarchiveui.d.ts +34 -32
  47. package/src/comments/commentsarchiveui.js +1 -1
  48. package/src/comments/commentsediting.d.ts +75 -71
  49. package/src/comments/commentsediting.js +1 -1
  50. package/src/comments/commentsrepository.d.ts +1088 -1084
  51. package/src/comments/commentsrepository.js +1 -1
  52. package/src/comments/commentsui.d.ts +29 -25
  53. package/src/comments/commentsui.js +1 -1
  54. package/src/comments/integrations/commentsrestrictededitingmode.d.ts +13 -13
  55. package/src/comments/integrations/commentsrestrictededitingmode.js +1 -1
  56. package/src/comments/integrations/importword.d.ts +17 -17
  57. package/src/comments/integrations/importword.js +1 -1
  58. package/src/comments/ui/commenteditor/commenteditor.d.ts +32 -32
  59. package/src/comments/ui/commenteditor/commenteditor.js +1 -1
  60. package/src/comments/ui/commenteditor/commenteditorui.d.ts +27 -27
  61. package/src/comments/ui/commenteditor/commenteditorui.js +1 -1
  62. package/src/comments/ui/commenteditor/commenteditoruiview.d.ts +32 -32
  63. package/src/comments/ui/commenteditor/commenteditoruiview.js +1 -1
  64. package/src/comments/ui/commentthreadcontroller.d.ts +64 -64
  65. package/src/comments/ui/commentthreadcontroller.js +1 -1
  66. package/src/comments/ui/view/basecommentthreadview.d.ts +108 -108
  67. package/src/comments/ui/view/basecommentthreadview.js +1 -1
  68. package/src/comments/ui/view/basecommentview.d.ts +108 -108
  69. package/src/comments/ui/view/basecommentview.js +1 -1
  70. package/src/comments/ui/view/collapsedcommentsview.d.ts +9 -9
  71. package/src/comments/ui/view/collapsedcommentsview.js +1 -1
  72. package/src/comments/ui/view/commentcontentview.d.ts +10 -10
  73. package/src/comments/ui/view/commentcontentview.js +1 -1
  74. package/src/comments/ui/view/commentinputview.d.ts +82 -82
  75. package/src/comments/ui/view/commentinputview.js +1 -1
  76. package/src/comments/ui/view/commentsarchiveview.d.ts +34 -34
  77. package/src/comments/ui/view/commentsarchiveview.js +1 -1
  78. package/src/comments/ui/view/commentslistview.d.ts +96 -96
  79. package/src/comments/ui/view/commentslistview.js +1 -1
  80. package/src/comments/ui/view/commentthreadheaderview.d.ts +46 -46
  81. package/src/comments/ui/view/commentthreadheaderview.js +1 -1
  82. package/src/comments/ui/view/commentthreadinputview.d.ts +37 -37
  83. package/src/comments/ui/view/commentthreadinputview.js +1 -1
  84. package/src/comments/ui/view/commentthreadview.d.ts +113 -113
  85. package/src/comments/ui/view/commentthreadview.js +1 -1
  86. package/src/comments/ui/view/commentview.d.ts +239 -239
  87. package/src/comments/ui/view/commentview.js +1 -1
  88. package/src/comments.d.ts +31 -22
  89. package/src/comments.js +1 -1
  90. package/src/commentsonly.d.ts +29 -28
  91. package/src/commentsonly.js +1 -1
  92. package/src/config.d.ts +172 -172
  93. package/src/index.d.ts +21 -19
  94. package/src/index.js +1 -1
  95. package/src/utils/common-translations.d.ts +5 -5
  96. package/src/utils/common-translations.js +1 -1
  97. package/src/utils/createmutationobserver.d.ts +13 -13
  98. package/src/utils/createmutationobserver.js +1 -1
@@ -1,1084 +1,1088 @@
1
- /**
2
- * @module comments/comments/commentsrepository
3
- * @publicApi
4
- */
5
- import { Context, ContextPlugin, type ContextPluginDependencies, type Editor } from 'ckeditor5/src/core';
6
- import { Collection } from 'ckeditor5/src/utils';
7
- import { type User } from 'ckeditor5-collaboration/src/collaboration-core';
8
- import CommentThreadController from './ui/commentthreadcontroller';
9
- import '../../theme/comment.css';
10
- import '../../theme/commentthread.css';
11
- import '../../theme/commentinput.css';
12
- import Annotation, { type AnnotationTarget } from '../annotations/annotation';
13
- import type BaseCommentThreadView from './ui/view/basecommentthreadview';
14
- /**
15
- * Stores the list of {@link module:comments/comments/commentsrepository~CommentThread}
16
- * and provides event-driven API for managing them. It is also responsible for using the comments adapter
17
- * to communicate with the data source.
18
- *
19
- * {@link module:comments/comments/commentsrepository~CommentsRepository} is a context plugin.
20
- * It can be added to a context or to an editor. Add it to the context configuration if you use
21
- * {@link module:core/context~Context} in your integration.
22
- *
23
- * The event-driven API makes it possible to attach a listener to each action that changes comment data.
24
- * Using different event priorities allows to attach an action before the main action ('low' priority)
25
- * or after the main action ('high' priority). It works very similar to
26
- * {@link module:utils/observablemixin~Observable#decorate}.
27
- *
28
- * Sample usage:
29
- *
30
- * ```ts
31
- * // Get the comments repository:
32
- * const commentsRepository = editor.plugins.get( 'CommentsRepository' );
33
- *
34
- * // Create a new, empty comment thread on a DOM form field element:
35
- * commentsRepository.openNewCommentThread( { channelId, target: formFieldElement } );
36
- *
37
- * // Get all comment threads:
38
- * commentsRepository.getCommentThreads();
39
- *
40
- * // Set the adapter:
41
- * commentsRepository.adapter = {
42
- * // ...
43
- * };
44
- * ```
45
- *
46
- * For more information about the comments adapter see {@link module:comments/comments/commentsrepository~CommentsAdapter}.
47
- */
48
- export default class CommentsRepository extends ContextPlugin {
49
- licenseKey: string;
50
- /**
51
- * The currently active comment thread.
52
- * An annotation with this thread will be marked as active.
53
- *
54
- * @observable
55
- */
56
- activeCommentThread: CommentThread | null;
57
- /**
58
- * @inheritDoc
59
- */
60
- static get requires(): ContextPluginDependencies;
61
- /**
62
- * @inheritDoc
63
- */
64
- static get pluginName(): 'CommentsRepository';
65
- /**
66
- * @inheritDoc
67
- */
68
- constructor(context: Context | Editor);
69
- /**
70
- * @inheritDoc
71
- */
72
- init(): void;
73
- /**
74
- * @inheritDoc
75
- */
76
- afterInit(): void;
77
- /**
78
- * An adapter object that should communicate with the data source to fetch or save the comments data.
79
- */
80
- set adapter(adapter: CommentsAdapter);
81
- get adapter(): CommentsAdapter;
82
- /**
83
- * Adds a new comment thread.
84
- *
85
- * When a target is provided, the comment annotation will be attached to this target.
86
- *
87
- * Use this method to load the comments data during the editor initialization
88
- * if you do not use the adapter integration.
89
- *
90
- * **Note:** This method fires the {@link #event:addCommentThread} event and the default behavior
91
- * is added as a `'normal'` priority listener. It makes it possible to cancel the method
92
- * or call some custom code before or after the default behavior is executed.
93
- *
94
- * **Note:** The comments adapter will send the data only if `commentThreadData.comments`
95
- * is not empty and `commentThreadData.isFromAdapter` is set to `false`.
96
- *
97
- * See also `CommentsRepository#openNewCommentThread()`.
98
- *
99
- * An example of loading a comment thread on editor initialization:
100
- *
101
- * ```ts
102
- * commentsRepository.addCommentThread( {
103
- * threadId: 'thread-id',
104
- * channelId: 'channel-id',
105
- * comments: [
106
- * {
107
- * commentId: 'comment-1', // String
108
- * authorId: 'author-id', // String
109
- * content: 'First comment', // String
110
- * createdAt: new Date( ... ) // Date instance
111
- * },
112
- * // ...
113
- * ],
114
- * target: () => ...,
115
- * // Added during initialization, so do not call the adapter:
116
- * isFromAdapter: true
117
- * } );
118
- * ```
119
- *
120
- * @fires addCommentThread
121
- * @param commentThreadData The data of the comment thread to add.
122
- * @param data.channelId The ID of a document or context to which the comment thread is added.
123
- * @param data.threadId The ID of the added comment thread.
124
- * @param data.comments Comments in the comment thread. See the example above.
125
- * @param data.resolvedAt The date when the comment thread has been resolved.
126
- * @param data.resolvedBy The ID of user who resolved the comment thread.
127
- * @param data.target The target that the comment
128
- * balloon should be attached to. If a function is passed, it should return a DOM element or `Rect`.
129
- * @param data.context The text on which the comment thread was created on or other context for the thread.
130
- * Displayed for resolved comment threads.
131
- * @param data.attributes Custom comment attributes. See also
132
- * {@link module:comments/comments/commentsrepository~CommentThread#setAttribute} and
133
- * {@link module:comments/comments/commentsrepository~CommentThread#removeAttribute}.
134
- * @param data.isResolvable Indicates whether the comment thread can become resolved.
135
- * Set this flag to `false` to disable the possibility of resolving given comment thread.
136
- * @param data.isSubmitted Indicates whether the comment thread has been submitted.
137
- * Comment thread is submitted after adding the first comment, however, in some cases,
138
- * it could be necessary to manage it in a custom way (e.g. track changes).
139
- * @param data.isFromAdapter A flag describing whether the added data
140
- * comes from an adapter (`true`) or is a new data (`false`). If set to `true`, the
141
- * comment data will be added only in the editor and will not be sent to the adapter.
142
- * @returns The added comment thread.
143
- */
144
- addCommentThread({ channelId, threadId, comments, resolvedAt, resolvedBy, target, context, attributes, isResolvable, isSubmitted, deletedAt, isFromAdapter }?: AddCommentThreadEventData): CommentThread | undefined;
145
- /**
146
- * Creates a new, empty comment thread.
147
- *
148
- * Displays a new comment annotation attached to the target and focuses the comment editor.
149
- * When the comment data is submitted, the comment thread is added to the editor
150
- * and sent to the adapter.
151
- *
152
- * Use this method to start a new comment thread after a user performed an action
153
- * (clicked a button, etc.).
154
- *
155
- * @fires addCommentThread
156
- * @param commentThreadData.channelId The ID of a document or context to which the comment is added.
157
- * @param commentThreadData.threadId The ID of the comment thread.
158
- * Random id will be generated if it is not set. All thread IDs should be unique.
159
- * @param commentThreadData.target The target that the comment
160
- * balloon should be attached to. If a function is passed, it should return a DOM element or `Rect`.
161
- * @param commentThreadData.context The text on which the comment thread was created on.
162
- * @param commentThreadData.isResolvable Indicates whether the comment thread can become resolved.
163
- * Set this flag to `false` to disable the possibility of resolving given comment thread.
164
- * @returns The created comment thread or `null` if there was a problem
165
- * creating the thread (for example, if the comments repository was in the read-only mode).
166
- */
167
- openNewCommentThread({ channelId, threadId, target, context, isResolvable }: AddCommentThreadEventData): CommentThread | null;
168
- /**
169
- * Checks if a comment thread with a given ID is added to the repository.
170
- */
171
- hasCommentThread(threadId: string): boolean;
172
- /**
173
- * Updates existing comment thread.
174
- *
175
- * @fires updateCommentThread
176
- * @param data The data of the comment thread to add.
177
- * @param data.channelId The ID of a document or context to which the comment thread is added.
178
- * @param data.threadId The ID of the updated comment thread.
179
- * @param data.resolvedAt The date when the comment thread has been resolved.
180
- * @param data.resolvedBy The ID of user who resolved the comment thread.
181
- * @param data.isFromAdapter A flag describing whether the added data
182
- * comes from an adapter (`true`) or is a new data (`false`). If set to `true`, the
183
- * comment data will be added only in the editor and will not be sent to the adapter.
184
- * @returns The updated comment thread.
185
- */
186
- updateCommentThread({ channelId, threadId, context, attributes, isFromAdapter }: UpdateCommentThreadEventData): CommentThread;
187
- /**
188
- * Returns comment thread of given id.
189
- */
190
- getCommentThread(threadId: string): CommentThread | undefined;
191
- /**
192
- * Gets the comment thread data using the adapter and adds the thread to the editor.
193
- *
194
- * When the comment thread is already present in the repository,
195
- * then the adapter will not be used but the result will be asynchronous as well.
196
- */
197
- fetchCommentThread({ channelId, threadId }?: BaseCommentThread): Promise<CommentThread | undefined>;
198
- getCommentThreads(data?: {
199
- channelId?: string | symbol;
200
- skipNotAttached?: boolean;
201
- skipEmpty?: boolean;
202
- toJSON?: false;
203
- }): Array<CommentThread>;
204
- getCommentThreads(data: {
205
- channelId?: string | symbol;
206
- skipNotAttached?: boolean;
207
- skipEmpty?: boolean;
208
- toJSON: true;
209
- }): Array<CommentThreadDataJSON>;
210
- /**
211
- * Marks a comment thread with the given ID as active.
212
- * When `threadId` is `null`, the currently active comment thread will be deactivated.
213
- */
214
- setActiveCommentThread(threadId: string | null): void;
215
- /**
216
- * Changes the read-only state for comment threads.
217
- *
218
- * When the value is `true` then all comment threads will be switched to read-only,
219
- * when the value is `false` then all comment threads will be switched to editing mode.
220
- *
221
- * Optionally new state can be applied to a comment threads limited to a given channel.
222
- * This function has precedence over any permission settings.
223
- */
224
- switchReadOnly(value: boolean, channelId?: string | symbol): void;
225
- /**
226
- * Returns `true` if a given channel is set to read-only mode, returns `false` otherwise.
227
- */
228
- isReadOnly(channelId: string | symbol): boolean;
229
- /**
230
- * Create an instance of the {@link module:comments/comments/ui/commentthreadcontroller~CommentThreadController} class.
231
- *
232
- * @param commentThreadModel Comment thread model.
233
- * @param commentThreadView Comment thread view.
234
- */
235
- createCommentThreadController(commentThreadModel: CommentThread, commentThreadView: BaseCommentThreadView): CommentThreadController;
236
- /**
237
- * Gets permissions set for repository (or default if permissions was not set).
238
- */
239
- getPermissions(channelId?: string | symbol): CommentPermissionsConfig;
240
- }
241
- interface CommentPermissionsConfig {
242
- /**
243
- * Allows for removing other users' threads.
244
- */
245
- admin: boolean;
246
- /**
247
- * Allows for editing and removing any comments created by any user.
248
- */
249
- modifyAll: boolean;
250
- /**
251
- * Allows for editing and removing comments created by this user.
252
- */
253
- write: boolean;
254
- }
255
- declare const CommentThread_base: {
256
- new (): import("ckeditor5/src/utils").Observable;
257
- prototype: import("ckeditor5/src/utils").Observable;
258
- };
259
- /**
260
- * Comment thread representation.
261
- * Stores a list of {@link module:comments/comments/commentsrepository~Comment `Comments`}.
262
- */
263
- export declare class CommentThread extends CommentThread_base {
264
- /**
265
- * Informs if the comment thread is in read-only state (`true`) or not (`false`).
266
- *
267
- * @observable
268
- */
269
- isReadOnly: boolean;
270
- /**
271
- * Informs if the comment thread can be removed by the local user.
272
- *
273
- * @observable
274
- */
275
- isRemovable: boolean;
276
- /**
277
- * User id which resolved the comment thread.
278
- *
279
- * @observable
280
- */
281
- resolvedBy: User | null;
282
- /**
283
- * Date when the comment thread has been resolved.
284
- *
285
- * @observable
286
- */
287
- resolvedAt: Date | null;
288
- /**
289
- * Informs if the comment thread is resolved.
290
- *
291
- * @observable
292
- */
293
- readonly isResolved: boolean;
294
- /**
295
- * Custom comment thread attributes. See also {@link #setAttribute} and {@link #removeAttribute}.
296
- *
297
- * @observable
298
- */
299
- attributes: Record<string, unknown>;
300
- /**
301
- * The channel where the comment thread was created.
302
- */
303
- channelId: string | symbol;
304
- /**
305
- * The comment thread ID.
306
- */
307
- id: string;
308
- /**
309
- * A collection of {@link module:comments/comments/commentsrepository~Comment}s belonging to this thread.
310
- *
311
- * @readonly
312
- */
313
- readonly comments: Collection<Comment>;
314
- constructor(commentsRepository: CommentsRepository, data: {
315
- channelId: string | symbol;
316
- id: string;
317
- author: User | null;
318
- context: CommentThreadContext;
319
- attributes: Record<string, unknown>;
320
- resolvedAt: Date | null;
321
- resolvedBy: User | null;
322
- isResolvable: boolean;
323
- isSubmitted: boolean;
324
- });
325
- /**
326
- * Sum of {@link module:comments/comments/commentsrepository~Comment#weight weights of all comments} in this thread.
327
- */
328
- get weight(): number;
329
- /**
330
- * The number of {@link module:comments/comments/commentsrepository~Comment comments} in the comment thread.
331
- */
332
- get length(): number;
333
- /**
334
- * Informs if the comment thread is attached to any target at the moment.
335
- */
336
- get isAttached(): boolean;
337
- /**
338
- * Informs if the comment thread has been submitted.
339
- */
340
- get isSubmitted(): boolean;
341
- /**
342
- * Submits the locally created comment thread draft.
343
- */
344
- submit(): void;
345
- /**
346
- * Resolves the comment thread.
347
- */
348
- resolve({ resolvedAt, resolvedBy, isFromAdapter }?: {
349
- resolvedAt?: Date | undefined;
350
- resolvedBy?: null | undefined;
351
- isFromAdapter?: boolean | undefined;
352
- }): void;
353
- /**
354
- * Reopens the resolved comment thread.
355
- */
356
- reopen({ isFromAdapter }?: {
357
- isFromAdapter?: boolean | undefined;
358
- }): void;
359
- /**
360
- * Set the context on the comment thread.
361
- * This method should be called only when the context has been not set during initialization.
362
- *
363
- * @param context Text context of comment thread.
364
- */
365
- setContext(context: CommentThreadContext): void;
366
- /**
367
- * Adds attribute to the comment thread.
368
- *
369
- * Comment thread attributes are custom data that can be set and used by features
370
- * built around comments. Use it to store your feature data with other comment thread data.
371
- * You can also group multiple values in an object, using dot notation:
372
- *
373
- * ```ts
374
- * commentThread.setAttribute( 'customData.isImportant', true );
375
- * ```
376
- *
377
- * Attributes set on the comment can be accessed through the `attribute` property:
378
- *
379
- * ```ts
380
- * const isImportant = commentThread.attributes.customData.isImportant;
381
- * ```
382
- *
383
- * You can also observe the `attributes` property or bind other properties to it:
384
- *
385
- * ```ts
386
- * myObj.bind( 'customData' ).to( commentThread, 'attributes', attributes => attributes.customData );
387
- * ```
388
- *
389
- * Whenever `setAttribute()` or `removeAttribute()` is called, the `attributes` property
390
- * is re-set and observables are refreshed.
391
- *
392
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateCommentThread
393
- * @param name Attribute name.
394
- * @param value Attribute value.
395
- */
396
- setAttribute(name: string, value: unknown): void;
397
- /**
398
- * Removes a comment attribute.
399
- *
400
- * See also {@link module:comments/comments/commentsrepository~CommentThread#setAttribute}.
401
- *
402
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateCommentThread
403
- * @param name The attribute name.
404
- */
405
- removeAttribute(name: string): void;
406
- /**
407
- * Removes comment thread.
408
- *
409
- * **Note** This method is event-driven. It means it fires an event then a normal priority listener catches
410
- * it and executes an action. It makes it possible to add some actions before and after method will be executed.
411
- *
412
- * @fires module:comments/comments/commentsrepository~RemoveCommentThreadEvent
413
- */
414
- remove({ isFromAdapter }?: {
415
- isFromAdapter?: boolean | undefined;
416
- }): void;
417
- /**
418
- * Creates comment annotations and displays it attached to the given target.
419
- *
420
- * @returns Created annotation.
421
- */
422
- attachTo(target: AnnotationTarget): Annotation;
423
- /**
424
- * Creates a new comment inside the comment thread.
425
- *
426
- * **Note** This method is event-driven. It means it fires an event then a normal priority listener catches
427
- * it and executes an action. It makes it possible to add some actions before and after method will be executed.
428
- *
429
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:addComment
430
- * @param data Data object.
431
- * @param data.commentId Comment id.
432
- * @param data.content Comment content.
433
- * @param data.authorId Author id.
434
- * @param data.createdAt Creation date. If not set, current date (`new Date()`) will be used.
435
- * @param data.attributes Custom comment attributes. See also
436
- * {@link module:comments/comments/commentsrepository~Comment#setAttribute} and
437
- * {@link module:comments/comments/commentsrepository~Comment#removeAttribute}.
438
- */
439
- addComment(data: CommentData): void;
440
- /**
441
- * Returns comment of given id.
442
- */
443
- getComment(commentId: string): Comment | null;
444
- toJSON(): CommentThreadDataJSON;
445
- }
446
- declare const Comment_base: {
447
- new (): import("ckeditor5/src/utils").Observable;
448
- prototype: import("ckeditor5/src/utils").Observable;
449
- };
450
- /**
451
- * Single comment representation. A part of a {@link module:comments/comments/commentsrepository~CommentThread commentThread}.
452
- */
453
- export declare class Comment extends Comment_base {
454
- /**
455
- * When is set to `true`, editing the comment is blocked.
456
- *
457
- * @observable
458
- */
459
- readonly isEditable: boolean;
460
- /**
461
- * When is set to `false`, removing the comment is blocked.
462
- *
463
- * @observable
464
- */
465
- readonly isRemovable: boolean;
466
- /**
467
- * The read-only state inherited from the parent {@link module:comments/comments/commentsrepository~CommentThread}.
468
- * When is set to `true`, then removing and editing the comment thread is blocked.
469
- *
470
- * In contrast to {@link #isEditable} and {@link #isRemovable}, this state can be used to
471
- * hide some UI parts instead of temporarily disabling them.
472
- *
473
- * @observable
474
- */
475
- readonly isReadOnly: boolean;
476
- /**
477
- * The comment content.
478
- */
479
- content: string;
480
- /**
481
- * Date when the comment was made.
482
- *
483
- * Usually the same as {@link #createdAt `createdAt`} but may be different in some cases
484
- * (e.g. when comment was added from an external source).
485
- *
486
- * @observable
487
- */
488
- authoredAt: Date;
489
- /**
490
- * The date when the comment thread was resolved or `null` if it is not resolved.
491
- *
492
- * @observable
493
- */
494
- resolvedAt: Date | null;
495
- /**
496
- * Custom comment attributes. See also {@link #setAttribute} and {@link #removeAttribute}.
497
- *
498
- * @observable
499
- */
500
- attributes: Record<string, any>;
501
- /**
502
- * The comment ID.
503
- */
504
- readonly id: string;
505
- /**
506
- * The ID of the comment thread that contains this comment.
507
- */
508
- readonly threadId: string;
509
- /**
510
- * The comment author.
511
- */
512
- readonly author: User;
513
- /**
514
- * The user which saved the comment data in the database.
515
- *
516
- * Usually the same as author but may be different in some cases (e.g. when comment was added from an external source).
517
- */
518
- readonly creator: User;
519
- /**
520
- * The flag indicating whether the comment comes from an external source.
521
- */
522
- readonly isExternal: boolean;
523
- /**
524
- * Date when the comment was saved in the database.
525
- */
526
- createdAt: Date;
527
- /**
528
- * @param commentsRepository
529
- * @param data Configuration object.
530
- * @param data.id Comment id.
531
- * @param data.threadId Comment thread id.
532
- * @param data.content Comment content.
533
- * @param data.author Comment author.
534
- * @param data.creator The user which saved the comment data.
535
- * Usually the same as author but may be different in some cases (e.g. when comment was added from an external source).
536
- * @param data.createdAt Date when the comment was saved in the database.
537
- * @param data.authoredAt Date when the comment was made.
538
- * @param data.attributes Custom comment attributes. See also
539
- * {@link module:comments/comments/commentsrepository~Comment#setAttribute} and
540
- * {@link module:comments/comments/commentsrepository~Comment#removeAttribute}.
541
- */
542
- constructor(commentsRepository: CommentsRepository, data: {
543
- id: string;
544
- threadId: string;
545
- content: string;
546
- author: User;
547
- creator: User;
548
- createdAt: Date;
549
- authoredAt: Date;
550
- attributes: Record<string, unknown>;
551
- });
552
- /**
553
- * The comment weight.
554
- *
555
- * It is equal to the length of the comment content, however it is never smaller than `200`.
556
- * This limit is set to avoid a long list of very short not collapsed comments.
557
- */
558
- get weight(): number;
559
- /**
560
- * Updates the comment with provided data.
561
- *
562
- * **Note:** This method fires the {@link module:comments/comments/commentsrepository~CommentsRepository#event:updateComment}
563
- * event and the default behavior is added as a normal priority listener. It makes it
564
- * possible to cancel the method or call some custom code before or after the default
565
- * behavior is executed.
566
- *
567
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateComment
568
- * @param data Data object.
569
- * @param data.content Comment content.
570
- * @param data.createdAt Creation date.
571
- * @param data.attributes Custom comment attributes. See also
572
- * {@link module:comments/comments/commentsrepository~Comment#setAttribute} and
573
- * {@link module:comments/comments/commentsrepository~Comment#removeAttribute}.
574
- * @param data.isFromAdapter
575
- */
576
- update(data: UpdateCommentData): void;
577
- /**
578
- * Adds attribute to the comment.
579
- *
580
- * Comment attributes are custom data that can be set and used by features
581
- * built around comments. Use it to store your feature data with other comment data.
582
- *
583
- * comment.setAttribute( 'isImportant', true );
584
- *
585
- * You can group multiple values in an object, using dot notation:
586
- *
587
- * comment.setAttribute( 'customData.type', 'image' );
588
- * comment.setAttribute( 'customData.src', 'foo.jpg' );
589
- *
590
- * Attributes set on the comment can be accessed through the `attribute` property:
591
- *
592
- * const isImportant = comment.attributes.isImportant;
593
- * const type = comment.attributes.customData.type;
594
- *
595
- * You can also observe the `attributes` property or bind other properties to it:
596
- *
597
- * myObj.bind( 'customData' ).to( comment, 'attributes', attributes => attributes.customData );
598
- *
599
- * Whenever `setAttribute()` or `removeAttribute()` is called, the `attributes` property
600
- * is re-set and observables are refreshed.
601
- *
602
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateComment
603
- * @param name Attribute name.
604
- * @param value Attribute value.
605
- */
606
- setAttribute(name: string, value: unknown): void;
607
- /**
608
- * Removes a comment attribute.
609
- *
610
- * See also {@link module:comments/comments/commentsrepository~Comment#setAttribute}.
611
- *
612
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateComment
613
- * @param name The attribute name.
614
- */
615
- removeAttribute(name: string): void;
616
- /**
617
- * Removes the comment.
618
- *
619
- * **Note:** This method fires the {@link module:comments/comments/commentsrepository~CommentsRepository#event:updateComment}
620
- * event and the default behavior is added as a normal priority listener. It makes it
621
- * possible to cancel the method or call some custom code before or after the default
622
- * behavior is executed.
623
- *
624
- * @fires module:comments/comments/commentsrepository~CommentsRepository#event:removeComment
625
- * @param data.isFromAdapter A flag describing whether the comment was
626
- * updated from an adapter (`true`) or from the UI (`false`). If set to `true`, the adapter will not be called.
627
- */
628
- remove(data?: {
629
- isFromAdapter?: boolean;
630
- }): void;
631
- toJSON(): CommentDataJSON;
632
- /**
633
- * Destroys the comment instance.
634
- */
635
- destroy(): void;
636
- }
637
- export type CommentThreadContext = null | {
638
- type: string;
639
- value: unknown;
640
- };
641
- /**
642
- * @param channelId The ID of a document or context that the comment thread is handled.
643
- * @param threadId The ID of the comment thread.
644
- * @param isFromAdapter A flag describing whether the operation was done on a remote client (`true`) or a local one (`false`).
645
- */
646
- export interface BaseCommentThread {
647
- channelId: string | symbol;
648
- threadId: string;
649
- isFromAdapter?: boolean;
650
- }
651
- /**
652
- * @param commentId The comment ID.
653
- */
654
- export interface BaseComment extends BaseCommentThread {
655
- commentId: string;
656
- }
657
- /**
658
- * @param content The comment content.
659
- * @param attributes Comment custom attributes.
660
- */
661
- export interface BaseCommentData {
662
- content: string;
663
- attributes: Record<string, any>;
664
- }
665
- /**
666
- * Fired whenever a comment thread is added to the comments repository.
667
- *
668
- * The event name includes `channelId` so it is possible to listen only
669
- * on changes happening in the specified channel.
670
- *
671
- * ```ts
672
- * const channelId = 'foo';
673
- *
674
- * commentsRepository.on( `addCommentThread:${ channelId }`, ( evt, data ) => {
675
- * console.log( evt, data );
676
- * } );
677
- * ```
678
- *
679
- * @eventName ~CommentsRepository#addCommentThread
680
- */
681
- export type AddCommentThreadEvent = {
682
- name: string;
683
- args: [Required<AddCommentThreadEventData>];
684
- };
685
- /**
686
- * @param context The comment ID.
687
- * @param attributes Comment thread custom attributes.
688
- * @param resolvedAt ID of the comment author.
689
- * @param resolvedBy The comment creation date.
690
- */
691
- export type CommentThreadData = BaseCommentThread & Partial<{
692
- context: CommentThreadContext;
693
- attributes: Record<string, any>;
694
- resolvedAt: Date | null;
695
- resolvedBy: string | null;
696
- }>;
697
- /**
698
- * @param comments Comments in the comment thread.
699
- * @param target The target that the comment balloon should be attached to.
700
- */
701
- export type AddCommentThreadEventData = CommentThreadData & {
702
- comments?: Array<CommentData>;
703
- target?: AnnotationTarget;
704
- isResolvable?: boolean;
705
- isSubmitted?: boolean;
706
- deletedAt?: Date | null;
707
- };
708
- /**
709
- * Fired whenever a new comment thread is submitted and occurs after creating the first comment.
710
- *
711
- * The event name includes `channelId` so it is possible to listen only
712
- * on changes happening in the specified channel.
713
- *
714
- * ```ts
715
- * const channelId = 'foo';
716
- *
717
- * commentsRepository.on( `submitCommentThread:${ channelId }`, ( evt, data ) => {
718
- * console.log( evt, data );
719
- * } );
720
- * ```
721
- *
722
- * @eventName ~CommentsRepository#submitCommentThread
723
- */
724
- export type SubmitCommentThreadEvent = {
725
- name: string;
726
- args: [BaseCommentThread];
727
- };
728
- /**
729
- * Fired whenever a comment thread is updated in comments repository.
730
- *
731
- * The event name includes `channelId` so it is possible to listen only
732
- * on changes happening in the specified channel.
733
- *
734
- * @eventName ~CommentsRepository#updateCommentThread
735
- */
736
- export type UpdateCommentThreadEvent = {
737
- name: string;
738
- args: [UpdateCommentThreadEventData];
739
- };
740
- export type UpdateCommentThreadEventData = Omit<CommentThreadData, 'resolvedAt' | 'resolvedBy'>;
741
- /**
742
- * Fired whenever a comment thread is resolved.
743
- *
744
- * The event name includes `channelId` so it is possible to listen only
745
- * on changes happening in the specified channel.
746
- *
747
- * ```ts
748
- * const channelId = 'foo';
749
- *
750
- * commentsRepository.on( `resolveCommentThread:${ channelId }`, ( evt, data ) => {
751
- * console.log( evt, data );
752
- * } );
753
- * ```
754
- *
755
- * @eventName ~CommentsRepository#resolveCommentThread
756
- */
757
- export type ResolveCommentThreadEvent = {
758
- name: string;
759
- args: [ResolveCommentThreadEventData];
760
- };
761
- export type ResolveCommentThreadEventData = Required<Omit<CommentThreadData, 'context' | 'attributes'>>;
762
- /**
763
- * Fired whenever a comment thread is reopened.
764
- *
765
- * The event name includes `channelId` so it is possible to listen only
766
- * on changes happening in the specified channel.
767
- *
768
- * ```ts
769
- * const channelId = 'foo';
770
- *
771
- * commentsRepository.on( `reopenCommentThread:${ channelId }`, ( evt, data ) => {
772
- * console.log( evt, data );
773
- * } );
774
- * ```
775
- *
776
- * @eventName ~CommentsRepository#reopenCommentThread
777
- */
778
- export type ReopenCommentThreadEvent = {
779
- name: string;
780
- args: [BaseCommentThread];
781
- };
782
- /**
783
- * Fired whenever a comment thread is removed from the comments repository.
784
- *
785
- * The event name includes `channelId` so it is possible to listen only
786
- * on changes happening in the specified channel.
787
- *
788
- * ```ts
789
- * const channelId = 'foo';
790
- *
791
- * commentsRepository.on( `removeCommentThread:${ channelId }`, ( evt, data ) => {
792
- * console.log( evt, data );
793
- * } );
794
- * ```
795
- *
796
- * @eventName ~CommentsRepository#removeCommentThread
797
- */
798
- export type RemoveCommentThreadEvent = {
799
- name: string;
800
- args: [BaseCommentThread];
801
- };
802
- /**
803
- * Fired whenever a comment is added.
804
- *
805
- * The event name includes `channelId` so it is possible to listen only
806
- * on changes happening in the specified channel.
807
- *
808
- * It is also possible to listen to events from the given thread ID by appending `:[threadId]` part to the event name
809
- *
810
- * ```ts
811
- * const channelId = 'foo';
812
- * const threadId = '1234';
813
- *
814
- * commentsRepository.on( `addComment:${ channelId }:${ threadId }`, ( evt, data ) => {
815
- * console.log( evt, data );
816
- * } );
817
- * ```
818
- *
819
- * @eventName ~CommentsRepository#addComment
820
- */
821
- export type AddCommentEvent = {
822
- name: string;
823
- args: [CommentEventData];
824
- };
825
- /**
826
- * @param commentId The comment ID.
827
- * @param authorId ID of the comment author.
828
- * @param createdAt The comment creation date.
829
- * @param isFromAdapter A flag describing whether the comment was updated on a remote client (`true`) or a local one (`false`).
830
- */
831
- export type CommentData = BaseCommentData & {
832
- commentId?: string;
833
- authorId: string;
834
- createdAt: Date;
835
- isFromAdapter?: boolean;
836
- };
837
- export type CommentEventData = BaseCommentThread & CommentData;
838
- /**
839
- * Fired whenever a comment is updated.
840
- *
841
- * The event name includes `channelId` so it is possible to listen only
842
- * to changes happening in the specified channel.
843
- *
844
- * It is also possible to listen to events from the given thread ID by appending `:[threadId]` part to the event name
845
- *
846
- * ```ts
847
- * const channelId = 'foo';
848
- * const threadId = '1234';
849
- *
850
- * commentsRepository.on( `updateComment:${ channelId }:${ threadId }`, ( evt, data ) => {
851
- * console.log( evt, data );
852
- * } );
853
- * ```
854
- *
855
- * @eventName ~CommentsRepository#updateComment
856
- */
857
- export type UpdateCommentEvent = {
858
- name: string;
859
- args: [UpdateCommentEventData];
860
- };
861
- export type UpdateCommentData = Partial<CommentEventData>;
862
- export type UpdateCommentEventData = UpdateCommentData & BaseComment;
863
- /**
864
- * Fired whenever a comment is removed.
865
- *
866
- * The event name includes `channelId` so it is possible to listen only
867
- * to changes happening in the specified channel.
868
- *
869
- * It is also possible to listen to events from the given thread ID by appending `:[threadId]` part to the event name
870
- *
871
- * ```ts
872
- * const channelId = 'foo';
873
- * const threadId = '1234';
874
- *
875
- * commentsRepository.on( `removeComment:${ channelId }:${ threadId }`, ( evt, data ) => {
876
- * console.log( evt, data );
877
- * } );
878
- * ```
879
- *
880
- * @eventName ~CommentsRepository#removeComment
881
- */
882
- export type RemoveCommentEvent = {
883
- name: string;
884
- args: [BaseComment];
885
- };
886
- export type CommentDataJSON = Omit<CommentData, 'isFromAdapter'>;
887
- export type CommentThreadDataJSON = {
888
- threadId: string;
889
- context: CommentThreadContext;
890
- resolvedAt: Date | null;
891
- resolvedBy: string | null;
892
- comments: Array<CommentDataJSON>;
893
- attributes: Record<string, unknown>;
894
- };
895
- /**
896
- * Comments adapter.
897
- *
898
- * The comments adapter is an object that communicates asynchronously with the data source to fetch or save
899
- * the comment data. It is used internally by the comments feature whenever a comment is loaded, created or deleted.
900
- * The adapter is optional. You might need to provide it if you are {@glink features/collaboration/comments/comments-integration
901
- * using the comments feature without real-time collaboration}.
902
- * To set the adapter, overwrite the `CommentsRepository#adapter` property.
903
- */
904
- export interface CommentsAdapter {
905
- /**
906
- * Called whenever a new comment thread is created.
907
- *
908
- * The object which is passed as a parameter can contain the following properties:
909
- * * channelId: string | symbol;
910
- * * threadId: string;
911
- * * context?: {@link module:comments/comments/commentsrepository~CommentThreadContext CommentThreadContext};
912
- * * comments?: Array<{@link module:comments/comments/commentsrepository~CommentDataJSON CommentDataJSON}>;
913
- * * resolvedAt?: Date | null;
914
- * * resolvedBy?: string | null;
915
- * * attributes?: Record<string, any> | null;
916
- *
917
- * It should return a promise that resolves with the new comment thread data.
918
- * The resolved data object should contain the following properties:
919
- * * threadId: string;
920
- * * comments: Array<\{ commentId: string; createdAt: Date; \}>;
921
- */
922
- addCommentThread: (data: Omit<CommentThreadData, 'isFromAdapter'> & {
923
- comments: Array<CommentDataJSON>;
924
- }) => Promise<{
925
- threadId: string;
926
- comments: Array<{
927
- commentId: string;
928
- createdAt: Date;
929
- }>;
930
- }>;
931
- /**
932
- * Called when the editor needs the data for a comment thread.
933
- *
934
- * It should return a promise that resolves with the comment thread data.
935
- * The resolved data object should contain the following properties:
936
- * * threadId: string;
937
- * * comments: Array<\{ commentId?: string; authorId: string; createdAt: Date; content: string; attributes: Record<string, any>; \}>;
938
- * * resolvedAt?: Date | null;
939
- * * resolvedBy?: string | null;
940
- * * attributes: Record<string, unknown>;
941
- *
942
- * @param data.channelId The ID of the document or context to which the comment is added.
943
- * @param data.threadId The ID of the comment thread that the comment is added to.
944
- */
945
- getCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<{
946
- threadId: string;
947
- comments: Array<CommentData>;
948
- resolvedAt?: Date | null;
949
- resolvedBy?: string | null;
950
- attributes: Record<string, unknown>;
951
- }>;
952
- /**
953
- * Called each time the user changes the existing comment thread.
954
- *
955
- * Keep in mind that for security reasons, the `authorId`, `createdAt`, `resolvedBy` and `resolvedAt` properties
956
- * are not passed in the `updateCommentThread()` call and you should not set them as a result of this call.
957
- *
958
- * It updates the comment data in the database and returns a promise
959
- * that will be resolved when the update is completed.
960
- *
961
- * The object which is passed as a parameter can contain the following properties:
962
- * * channelId: string | symbol;
963
- * * threadId: string;
964
- * * context?: {@link module:comments/comments/commentsrepository~CommentThreadContext};
965
- * * attributes?: Record<string, any> | null;
966
- */
967
- updateCommentThread: (data: Omit<UpdateCommentThreadEventData, 'isFromAdapter'>) => Promise<void>;
968
- /**
969
- * Called each time the user resolves a comment thread.
970
- *
971
- * Should set `resolvedAt` and `resolvedBy` properties in your database and should resolve with an object
972
- * containing these two properties and returns a promise that will be resolved when the operation is completed.
973
- *
974
- * The resolved data object should contain the following properties:
975
- * * threadId: string;
976
- * * resolvedAt: Date;
977
- * * resolvedBy: string;
978
- *
979
- * @param data.channelId The ID of the document or context that the comment thread is removed from.
980
- * @param data.threadId The ID of the thread to remove.
981
- */
982
- resolveCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<{
983
- threadId: string;
984
- resolvedAt: Date;
985
- resolvedBy: string;
986
- }>;
987
- /**
988
- * Called when the user reopens a resolved comment thread.
989
- *
990
- * Should set `resolvedAt` and `resolvedBy` properties to `null` in your database and returns a promise
991
- * that will be resolved when the operation is completed.
992
- *
993
- * @param data.channelId The ID of the document or context that the comment thread is removed from.
994
- * @param data.threadId The ID of the thread to remove.
995
- */
996
- reopenCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<void>;
997
- /**
998
- * Called each time the user removes a comment thread.
999
- *
1000
- * It should return a promise that resolves when the thread is removed.
1001
- *
1002
- * @param data.channelId The ID of the document or context that the comment thread is removed from.
1003
- * @param data.threadId The ID of the thread to remove.
1004
- */
1005
- removeCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<void>;
1006
- /**
1007
- * Called each time the user adds a new comment to a thread.
1008
- *
1009
- * It saves the comment data in the database and returns a promise
1010
- * that should get resolved when the save is completed.
1011
- *
1012
- * If the promise resolves with an object with the `createdAt` property, the
1013
- * comment property will be updated in the comment in the editor.
1014
- * This is to update the comment data with the server-side information.
1015
- *
1016
- * The `data` object does not expect the `authorId` property.
1017
- * For security reasons, the author of the comment should be set
1018
- * on the server side.
1019
- *
1020
- * The `data` object does not expect the `createdAt` property either.
1021
- * You should use the server-side time generator to ensure that all users
1022
- * see the same date.
1023
- *
1024
- * It is recommended to stringify the `data.attributes` value to JSON
1025
- * and to save it as a string in your database and then to parse the
1026
- * value from JSON when loading comments.
1027
- *
1028
- * The object which is passed as a parameter can contain the following properties:
1029
- * * channelId: string | symbol;
1030
- * * threadId: string;
1031
- * * commentId: string;
1032
- * * content: string;
1033
- * * attributes: Record<string, any>;
1034
- *
1035
- * The resolved data object should contain the following properties:
1036
- * * commentId: string;
1037
- * * createdAt: Date;
1038
- *
1039
- * @param data.channelId The ID of the document or context to which the comment is added.
1040
- * @param data.threadId The ID of the comment thread that the comment is added to.
1041
- * @param data.commentId The comment ID.
1042
- * @param data.content The comment content.
1043
- * @param data.attributes Comment custom attributes.
1044
- */
1045
- addComment: (data: Omit<BaseComment, 'isFromAdapter'> & BaseCommentData) => Promise<{
1046
- commentId: string;
1047
- createdAt: Date;
1048
- }>;
1049
- /**
1050
- * Called each time the user changes the existing comment.
1051
- *
1052
- * It updates the comment data in the database and returns a promise
1053
- * that will be resolved when the update is completed.
1054
- *
1055
- * Keep in mind that the `data` parameter only contains the
1056
- * properties of a comment that have changed.
1057
- *
1058
- * The object which is passed as a parameter can contain the following properties:
1059
- * * channelId: string | symbol;
1060
- * * threadId: string;
1061
- * * commentId: string;
1062
- * * content?: string;
1063
- * * attributes?: Record<string, any>;
1064
- *
1065
- * @param data.channelId The ID of the document or context where the comment is updated.
1066
- * @param data.threadId The ID of the comment thread where the comment is updated.
1067
- * @param data.commentId The ID of the comment to update.
1068
- * @param data.content The new content of the comment.
1069
- * @param data.attributes Custom comment attributes.
1070
- */
1071
- updateComment: (data: Omit<BaseComment, 'isFromAdapter'> & Partial<BaseCommentData>) => Promise<void>;
1072
- /**
1073
- * Called each time the user removes a comment from the thread.
1074
- *
1075
- * It removes the comment from the database and returns a promise
1076
- * that will be resolved when the removal is completed.
1077
- *
1078
- * @param data.channelId The ID of the document or context that the comment is removed from.
1079
- * @param data.threadId The ID of the comment thread that the comment is removed from.
1080
- * @param data.commentId The ID of the comment to remove.
1081
- */
1082
- removeComment: (data: Omit<BaseComment, 'isFromAdapter'>) => Promise<void>;
1083
- }
1084
- export {};
1
+ /**
2
+ * @module comments/comments/commentsrepository
3
+ * @publicApi
4
+ */
5
+ import { Context, PendingActions, ContextPlugin, type Editor } from 'ckeditor5/src/core';
6
+ import { Collection } from 'ckeditor5/src/utils';
7
+ import { Users, type User } from 'ckeditor5-collaboration/src/collaboration-core';
8
+ import CommentThreadController from './ui/commentthreadcontroller';
9
+ import '../../theme/comment.css';
10
+ import '../../theme/commentthread.css';
11
+ import '../../theme/commentinput.css';
12
+ import Annotation, { type AnnotationTarget } from '../annotations/annotation';
13
+ import Annotations from '../annotations/annotations';
14
+ import type BaseCommentThreadView from './ui/view/basecommentthreadview';
15
+ /**
16
+ * Stores the list of {@link module:comments/comments/commentsrepository~CommentThread}
17
+ * and provides event-driven API for managing them. It is also responsible for using the comments adapter
18
+ * to communicate with the data source.
19
+ *
20
+ * {@link module:comments/comments/commentsrepository~CommentsRepository} is a context plugin.
21
+ * It can be added to a context or to an editor. Add it to the context configuration if you use
22
+ * {@link module:core/context~Context} in your integration.
23
+ *
24
+ * The event-driven API makes it possible to attach a listener to each action that changes comment data.
25
+ * Using different event priorities allows to attach an action before the main action ('low' priority)
26
+ * or after the main action ('high' priority). It works very similar to
27
+ * {@link module:utils/observablemixin~Observable#decorate}.
28
+ *
29
+ * Sample usage:
30
+ *
31
+ * ```ts
32
+ * // Get the comments repository:
33
+ * const commentsRepository = editor.plugins.get( 'CommentsRepository' );
34
+ *
35
+ * // Create a new, empty comment thread on a DOM form field element:
36
+ * commentsRepository.openNewCommentThread( { channelId, target: formFieldElement } );
37
+ *
38
+ * // Get all comment threads:
39
+ * commentsRepository.getCommentThreads();
40
+ *
41
+ * // Set the adapter:
42
+ * commentsRepository.adapter = {
43
+ * // ...
44
+ * };
45
+ * ```
46
+ *
47
+ * For more information about the comments adapter see {@link module:comments/comments/commentsrepository~CommentsAdapter}.
48
+ */
49
+ export default class CommentsRepository extends ContextPlugin {
50
+ licenseKey: string;
51
+ /**
52
+ * The currently active comment thread.
53
+ * An annotation with this thread will be marked as active.
54
+ *
55
+ * @observable
56
+ */
57
+ activeCommentThread: CommentThread | null;
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ static get requires(): readonly [typeof Annotations, typeof PendingActions, typeof Users];
62
+ /**
63
+ * @inheritDoc
64
+ */
65
+ static get pluginName(): "CommentsRepository";
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ constructor(context: Context | Editor);
70
+ /**
71
+ * @inheritDoc
72
+ */
73
+ init(): void;
74
+ /**
75
+ * @inheritDoc
76
+ */
77
+ afterInit(): void;
78
+ /**
79
+ * An adapter object that should communicate with the data source to fetch or save the comments data.
80
+ */
81
+ set adapter(adapter: CommentsAdapter);
82
+ get adapter(): CommentsAdapter;
83
+ /**
84
+ * Adds a new comment thread.
85
+ *
86
+ * When a target is provided, the comment annotation will be attached to this target.
87
+ *
88
+ * Use this method to load the comments data during the editor initialization
89
+ * if you do not use the adapter integration.
90
+ *
91
+ * **Note:** This method fires the {@link #event:addCommentThread} event and the default behavior
92
+ * is added as a `'normal'` priority listener. It makes it possible to cancel the method
93
+ * or call some custom code before or after the default behavior is executed.
94
+ *
95
+ * **Note:** The comments adapter will send the data only if `commentThreadData.comments`
96
+ * is not empty and `commentThreadData.isFromAdapter` is set to `false`.
97
+ *
98
+ * See also `CommentsRepository#openNewCommentThread()`.
99
+ *
100
+ * An example of loading a comment thread on editor initialization:
101
+ *
102
+ * ```ts
103
+ * commentsRepository.addCommentThread( {
104
+ * threadId: 'thread-id',
105
+ * channelId: 'channel-id',
106
+ * comments: [
107
+ * {
108
+ * commentId: 'comment-1', // String
109
+ * authorId: 'author-id', // String
110
+ * content: 'First comment', // String
111
+ * createdAt: new Date( ... ) // Date instance
112
+ * },
113
+ * // ...
114
+ * ],
115
+ * target: () => ...,
116
+ * // Added during initialization, so do not call the adapter:
117
+ * isFromAdapter: true
118
+ * } );
119
+ * ```
120
+ *
121
+ * @fires addCommentThread
122
+ * @param commentThreadData The data of the comment thread to add.
123
+ * @param data.channelId The ID of a document or context to which the comment thread is added.
124
+ * @param data.threadId The ID of the added comment thread.
125
+ * @param data.comments Comments in the comment thread. See the example above.
126
+ * @param data.resolvedAt The date when the comment thread has been resolved.
127
+ * @param data.resolvedBy The ID of user who resolved the comment thread.
128
+ * @param data.target The target that the comment
129
+ * balloon should be attached to. If a function is passed, it should return a DOM element or `Rect`.
130
+ * @param data.context The text on which the comment thread was created on or other context for the thread.
131
+ * Displayed for resolved comment threads.
132
+ * @param data.attributes Custom comment attributes. See also
133
+ * {@link module:comments/comments/commentsrepository~CommentThread#setAttribute} and
134
+ * {@link module:comments/comments/commentsrepository~CommentThread#removeAttribute}.
135
+ * @param data.isResolvable Indicates whether the comment thread can become resolved.
136
+ * Set this flag to `false` to disable the possibility of resolving given comment thread.
137
+ * @param data.isSubmitted Indicates whether the comment thread has been submitted.
138
+ * Comment thread is submitted after adding the first comment, however, in some cases,
139
+ * it could be necessary to manage it in a custom way (e.g. track changes).
140
+ * @param data.isFromAdapter A flag describing whether the added data
141
+ * comes from an adapter (`true`) or is a new data (`false`). If set to `true`, the
142
+ * comment data will be added only in the editor and will not be sent to the adapter.
143
+ * @returns The added comment thread.
144
+ */
145
+ addCommentThread({ channelId, threadId, comments, resolvedAt, resolvedBy, target, context, attributes, isResolvable, isSubmitted, deletedAt, isFromAdapter }?: AddCommentThreadEventData): CommentThread | undefined;
146
+ /**
147
+ * Creates a new, empty comment thread.
148
+ *
149
+ * Displays a new comment annotation attached to the target and focuses the comment editor.
150
+ * When the comment data is submitted, the comment thread is added to the editor
151
+ * and sent to the adapter.
152
+ *
153
+ * Use this method to start a new comment thread after a user performed an action
154
+ * (clicked a button, etc.).
155
+ *
156
+ * @fires addCommentThread
157
+ * @param commentThreadData.channelId The ID of a document or context to which the comment is added.
158
+ * @param commentThreadData.threadId The ID of the comment thread.
159
+ * Random id will be generated if it is not set. All thread IDs should be unique.
160
+ * @param commentThreadData.target The target that the comment
161
+ * balloon should be attached to. If a function is passed, it should return a DOM element or `Rect`.
162
+ * @param commentThreadData.context The text on which the comment thread was created on.
163
+ * @param commentThreadData.isResolvable Indicates whether the comment thread can become resolved.
164
+ * Set this flag to `false` to disable the possibility of resolving given comment thread.
165
+ * @returns The created comment thread or `null` if there was a problem
166
+ * creating the thread (for example, if the comments repository was in the read-only mode).
167
+ */
168
+ openNewCommentThread({ channelId, threadId, target, context, isResolvable }: AddCommentThreadEventData): CommentThread | null;
169
+ /**
170
+ * Checks if a comment thread with a given ID is added to the repository.
171
+ */
172
+ hasCommentThread(threadId: string): boolean;
173
+ /**
174
+ * Updates existing comment thread.
175
+ *
176
+ * @fires updateCommentThread
177
+ * @param data The data of the comment thread to add.
178
+ * @param data.channelId The ID of a document or context to which the comment thread is added.
179
+ * @param data.threadId The ID of the updated comment thread.
180
+ * @param data.resolvedAt The date when the comment thread has been resolved.
181
+ * @param data.resolvedBy The ID of user who resolved the comment thread.
182
+ * @param data.isFromAdapter A flag describing whether the added data
183
+ * comes from an adapter (`true`) or is a new data (`false`). If set to `true`, the
184
+ * comment data will be added only in the editor and will not be sent to the adapter.
185
+ * @returns The updated comment thread.
186
+ */
187
+ updateCommentThread({ channelId, threadId, context, attributes, isFromAdapter }: UpdateCommentThreadEventData): CommentThread;
188
+ /**
189
+ * Returns comment thread of given id.
190
+ */
191
+ getCommentThread(threadId: string): CommentThread | undefined;
192
+ /**
193
+ * Gets the comment thread data using the adapter and adds the thread to the editor.
194
+ *
195
+ * When the comment thread is already present in the repository,
196
+ * then the adapter will not be used but the result will be asynchronous as well.
197
+ */
198
+ fetchCommentThread({ channelId, threadId }?: BaseCommentThread): Promise<CommentThread | undefined>;
199
+ getCommentThreads(data?: {
200
+ channelId?: string | symbol;
201
+ skipNotAttached?: boolean;
202
+ skipEmpty?: boolean;
203
+ toJSON?: false;
204
+ }): Array<CommentThread>;
205
+ getCommentThreads(data: {
206
+ channelId?: string | symbol;
207
+ skipNotAttached?: boolean;
208
+ skipEmpty?: boolean;
209
+ toJSON: true;
210
+ }): Array<CommentThreadDataJSON>;
211
+ /**
212
+ * Marks a comment thread with the given ID as active.
213
+ * When `threadId` is `null`, the currently active comment thread will be deactivated.
214
+ */
215
+ setActiveCommentThread(threadId: string | null): void;
216
+ /**
217
+ * Changes the read-only state for comment threads.
218
+ *
219
+ * When the value is `true` then all comment threads will be switched to read-only,
220
+ * when the value is `false` then all comment threads will be switched to editing mode.
221
+ *
222
+ * Optionally new state can be applied to a comment threads limited to a given channel.
223
+ * This function has precedence over any permission settings.
224
+ */
225
+ switchReadOnly(value: boolean, channelId?: string | symbol): void;
226
+ /**
227
+ * Returns `true` if a given channel is set to read-only mode, returns `false` otherwise.
228
+ */
229
+ isReadOnly(channelId: string | symbol): boolean;
230
+ /**
231
+ * Create an instance of the {@link module:comments/comments/ui/commentthreadcontroller~CommentThreadController} class.
232
+ *
233
+ * @param commentThreadModel Comment thread model.
234
+ * @param commentThreadView Comment thread view.
235
+ */
236
+ createCommentThreadController(commentThreadModel: CommentThread, commentThreadView: BaseCommentThreadView): CommentThreadController;
237
+ /**
238
+ * Gets permissions set for repository (or default if permissions was not set).
239
+ */
240
+ getPermissions(channelId?: string | symbol): CommentPermissionsConfig;
241
+ }
242
+ interface CommentPermissionsConfig {
243
+ /**
244
+ * Allows for removing other users' threads.
245
+ */
246
+ admin: boolean;
247
+ /**
248
+ * Allows for editing and removing any comments created by any user.
249
+ */
250
+ modifyAll: boolean;
251
+ /**
252
+ * Allows for editing and removing comments created by this user.
253
+ */
254
+ write: boolean;
255
+ /**
256
+ * Allows for resolving and reopening comment threads.
257
+ */
258
+ resolve: boolean;
259
+ }
260
+ declare const CommentThread_base: {
261
+ new (): import("ckeditor5/src/utils").Observable;
262
+ prototype: import("ckeditor5/src/utils").Observable;
263
+ };
264
+ /**
265
+ * Comment thread representation.
266
+ * Stores a list of {@link module:comments/comments/commentsrepository~Comment `Comments`}.
267
+ */
268
+ export declare class CommentThread extends CommentThread_base {
269
+ /**
270
+ * Informs if the comment thread is in read-only state (`true`) or not (`false`).
271
+ *
272
+ * @observable
273
+ */
274
+ isReadOnly: boolean;
275
+ /**
276
+ * Informs if the comment thread can be removed by the local user.
277
+ *
278
+ * @observable
279
+ */
280
+ isRemovable: boolean;
281
+ /**
282
+ * User id which resolved the comment thread.
283
+ *
284
+ * @observable
285
+ */
286
+ resolvedBy: User | null;
287
+ /**
288
+ * Date when the comment thread has been resolved.
289
+ *
290
+ * @observable
291
+ */
292
+ resolvedAt: Date | null;
293
+ /**
294
+ * Informs if the comment thread is resolved.
295
+ *
296
+ * @observable
297
+ */
298
+ readonly isResolved: boolean;
299
+ /**
300
+ * Custom comment thread attributes. See also {@link #setAttribute} and {@link #removeAttribute}.
301
+ *
302
+ * @observable
303
+ */
304
+ attributes: Record<string, unknown>;
305
+ /**
306
+ * The channel where the comment thread was created.
307
+ */
308
+ channelId: string | symbol;
309
+ /**
310
+ * The comment thread ID.
311
+ */
312
+ id: string;
313
+ /**
314
+ * A collection of {@link module:comments/comments/commentsrepository~Comment}s belonging to this thread.
315
+ *
316
+ * @readonly
317
+ */
318
+ readonly comments: Collection<Comment>;
319
+ constructor(commentsRepository: CommentsRepository, data: {
320
+ channelId: string | symbol;
321
+ id: string;
322
+ context: CommentThreadContext;
323
+ attributes: Record<string, unknown>;
324
+ resolvedAt: Date | null;
325
+ resolvedBy: User | null;
326
+ isResolvable: boolean;
327
+ isSubmitted: boolean;
328
+ });
329
+ /**
330
+ * Sum of {@link module:comments/comments/commentsrepository~Comment#weight weights of all comments} in this thread.
331
+ */
332
+ get weight(): number;
333
+ /**
334
+ * The number of {@link module:comments/comments/commentsrepository~Comment comments} in the comment thread.
335
+ */
336
+ get length(): number;
337
+ /**
338
+ * Informs if the comment thread is attached to any target at the moment.
339
+ */
340
+ get isAttached(): boolean;
341
+ /**
342
+ * Informs if the comment thread has been submitted.
343
+ */
344
+ get isSubmitted(): boolean;
345
+ /**
346
+ * Submits the locally created comment thread draft.
347
+ */
348
+ submit(): void;
349
+ /**
350
+ * Resolves the comment thread.
351
+ */
352
+ resolve({ resolvedAt, resolvedBy, isFromAdapter }?: {
353
+ resolvedAt?: Date | undefined;
354
+ resolvedBy?: null | undefined;
355
+ isFromAdapter?: boolean | undefined;
356
+ }): void;
357
+ /**
358
+ * Reopens the resolved comment thread.
359
+ */
360
+ reopen({ isFromAdapter }?: {
361
+ isFromAdapter?: boolean | undefined;
362
+ }): void;
363
+ /**
364
+ * Set the context on the comment thread.
365
+ * This method should be called only when the context has been not set during initialization.
366
+ *
367
+ * @param context Text context of comment thread.
368
+ */
369
+ setContext(context: CommentThreadContext): void;
370
+ /**
371
+ * Adds attribute to the comment thread.
372
+ *
373
+ * Comment thread attributes are custom data that can be set and used by features
374
+ * built around comments. Use it to store your feature data with other comment thread data.
375
+ * You can also group multiple values in an object, using dot notation:
376
+ *
377
+ * ```ts
378
+ * commentThread.setAttribute( 'customData.isImportant', true );
379
+ * ```
380
+ *
381
+ * Attributes set on the comment can be accessed through the `attribute` property:
382
+ *
383
+ * ```ts
384
+ * const isImportant = commentThread.attributes.customData.isImportant;
385
+ * ```
386
+ *
387
+ * You can also observe the `attributes` property or bind other properties to it:
388
+ *
389
+ * ```ts
390
+ * myObj.bind( 'customData' ).to( commentThread, 'attributes', attributes => attributes.customData );
391
+ * ```
392
+ *
393
+ * Whenever `setAttribute()` or `removeAttribute()` is called, the `attributes` property
394
+ * is re-set and observables are refreshed.
395
+ *
396
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateCommentThread
397
+ * @param name Attribute name.
398
+ * @param value Attribute value.
399
+ */
400
+ setAttribute(name: string, value: unknown): void;
401
+ /**
402
+ * Removes a comment attribute.
403
+ *
404
+ * See also {@link module:comments/comments/commentsrepository~CommentThread#setAttribute}.
405
+ *
406
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateCommentThread
407
+ * @param name The attribute name.
408
+ */
409
+ removeAttribute(name: string): void;
410
+ /**
411
+ * Removes comment thread.
412
+ *
413
+ * **Note** This method is event-driven. It means it fires an event then a normal priority listener catches
414
+ * it and executes an action. It makes it possible to add some actions before and after method will be executed.
415
+ *
416
+ * @fires module:comments/comments/commentsrepository~RemoveCommentThreadEvent
417
+ */
418
+ remove({ isFromAdapter }?: {
419
+ isFromAdapter?: boolean | undefined;
420
+ }): void;
421
+ /**
422
+ * Creates comment annotations and displays it attached to the given target.
423
+ *
424
+ * @returns Created annotation.
425
+ */
426
+ attachTo(target: AnnotationTarget): Annotation;
427
+ /**
428
+ * Creates a new comment inside the comment thread.
429
+ *
430
+ * **Note** This method is event-driven. It means it fires an event then a normal priority listener catches
431
+ * it and executes an action. It makes it possible to add some actions before and after method will be executed.
432
+ *
433
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:addComment
434
+ * @param data Data object.
435
+ * @param data.commentId Comment id.
436
+ * @param data.content Comment content.
437
+ * @param data.authorId Author id.
438
+ * @param data.createdAt Creation date. If not set, current date (`new Date()`) will be used.
439
+ * @param data.attributes Custom comment attributes. See also
440
+ * {@link module:comments/comments/commentsrepository~Comment#setAttribute} and
441
+ * {@link module:comments/comments/commentsrepository~Comment#removeAttribute}.
442
+ */
443
+ addComment(data: CommentData): void;
444
+ /**
445
+ * Returns comment of given id.
446
+ */
447
+ getComment(commentId: string): Comment | null;
448
+ toJSON(): CommentThreadDataJSON;
449
+ }
450
+ declare const Comment_base: {
451
+ new (): import("ckeditor5/src/utils").Observable;
452
+ prototype: import("ckeditor5/src/utils").Observable;
453
+ };
454
+ /**
455
+ * Single comment representation. A part of a {@link module:comments/comments/commentsrepository~CommentThread commentThread}.
456
+ */
457
+ export declare class Comment extends Comment_base {
458
+ /**
459
+ * When is set to `true`, editing the comment is blocked.
460
+ *
461
+ * @observable
462
+ */
463
+ readonly isEditable: boolean;
464
+ /**
465
+ * When is set to `false`, removing the comment is blocked.
466
+ *
467
+ * @observable
468
+ */
469
+ readonly isRemovable: boolean;
470
+ /**
471
+ * The read-only state inherited from the parent {@link module:comments/comments/commentsrepository~CommentThread}.
472
+ * When is set to `true`, then removing and editing the comment thread is blocked.
473
+ *
474
+ * In contrast to {@link #isEditable} and {@link #isRemovable}, this state can be used to
475
+ * hide some UI parts instead of temporarily disabling them.
476
+ *
477
+ * @observable
478
+ */
479
+ readonly isReadOnly: boolean;
480
+ /**
481
+ * The comment content.
482
+ */
483
+ content: string;
484
+ /**
485
+ * Date when the comment was made.
486
+ *
487
+ * Usually the same as {@link #createdAt `createdAt`} but may be different in some cases
488
+ * (e.g. when comment was added from an external source).
489
+ *
490
+ * @observable
491
+ */
492
+ authoredAt: Date;
493
+ /**
494
+ * The date when the comment thread was resolved or `null` if it is not resolved.
495
+ *
496
+ * @observable
497
+ */
498
+ resolvedAt: Date | null;
499
+ /**
500
+ * Custom comment attributes. See also {@link #setAttribute} and {@link #removeAttribute}.
501
+ *
502
+ * @observable
503
+ */
504
+ attributes: Record<string, any>;
505
+ /**
506
+ * The comment ID.
507
+ */
508
+ readonly id: string;
509
+ /**
510
+ * The ID of the comment thread that contains this comment.
511
+ */
512
+ readonly threadId: string;
513
+ /**
514
+ * The comment author.
515
+ */
516
+ readonly author: User;
517
+ /**
518
+ * The user which saved the comment data in the database.
519
+ *
520
+ * Usually the same as author but may be different in some cases (e.g. when comment was added from an external source).
521
+ */
522
+ readonly creator: User;
523
+ /**
524
+ * The flag indicating whether the comment comes from an external source.
525
+ */
526
+ readonly isExternal: boolean;
527
+ /**
528
+ * Date when the comment was saved in the database.
529
+ */
530
+ createdAt: Date;
531
+ /**
532
+ * @param commentsRepository
533
+ * @param data Configuration object.
534
+ * @param data.id Comment id.
535
+ * @param data.threadId Comment thread id.
536
+ * @param data.content Comment content.
537
+ * @param data.author Comment author.
538
+ * @param data.creator The user which saved the comment data.
539
+ * Usually the same as author but may be different in some cases (e.g. when comment was added from an external source).
540
+ * @param data.createdAt Date when the comment was saved in the database.
541
+ * @param data.authoredAt Date when the comment was made.
542
+ * @param data.attributes Custom comment attributes. See also
543
+ * {@link module:comments/comments/commentsrepository~Comment#setAttribute} and
544
+ * {@link module:comments/comments/commentsrepository~Comment#removeAttribute}.
545
+ */
546
+ constructor(commentsRepository: CommentsRepository, data: {
547
+ id: string;
548
+ threadId: string;
549
+ content: string;
550
+ author: User;
551
+ creator: User;
552
+ createdAt: Date;
553
+ authoredAt: Date;
554
+ attributes: Record<string, unknown>;
555
+ });
556
+ /**
557
+ * The comment weight.
558
+ *
559
+ * It is equal to the length of the comment content, however it is never smaller than `200`.
560
+ * This limit is set to avoid a long list of very short not collapsed comments.
561
+ */
562
+ get weight(): number;
563
+ /**
564
+ * Updates the comment with provided data.
565
+ *
566
+ * **Note:** This method fires the {@link module:comments/comments/commentsrepository~CommentsRepository#event:updateComment}
567
+ * event and the default behavior is added as a normal priority listener. It makes it
568
+ * possible to cancel the method or call some custom code before or after the default
569
+ * behavior is executed.
570
+ *
571
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateComment
572
+ * @param data Data object.
573
+ * @param data.content Comment content.
574
+ * @param data.createdAt Creation date.
575
+ * @param data.attributes Custom comment attributes. See also
576
+ * {@link module:comments/comments/commentsrepository~Comment#setAttribute} and
577
+ * {@link module:comments/comments/commentsrepository~Comment#removeAttribute}.
578
+ * @param data.isFromAdapter
579
+ */
580
+ update(data: UpdateCommentData): void;
581
+ /**
582
+ * Adds attribute to the comment.
583
+ *
584
+ * Comment attributes are custom data that can be set and used by features
585
+ * built around comments. Use it to store your feature data with other comment data.
586
+ *
587
+ * comment.setAttribute( 'isImportant', true );
588
+ *
589
+ * You can group multiple values in an object, using dot notation:
590
+ *
591
+ * comment.setAttribute( 'customData.type', 'image' );
592
+ * comment.setAttribute( 'customData.src', 'foo.jpg' );
593
+ *
594
+ * Attributes set on the comment can be accessed through the `attribute` property:
595
+ *
596
+ * const isImportant = comment.attributes.isImportant;
597
+ * const type = comment.attributes.customData.type;
598
+ *
599
+ * You can also observe the `attributes` property or bind other properties to it:
600
+ *
601
+ * myObj.bind( 'customData' ).to( comment, 'attributes', attributes => attributes.customData );
602
+ *
603
+ * Whenever `setAttribute()` or `removeAttribute()` is called, the `attributes` property
604
+ * is re-set and observables are refreshed.
605
+ *
606
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateComment
607
+ * @param name Attribute name.
608
+ * @param value Attribute value.
609
+ */
610
+ setAttribute(name: string, value: unknown): void;
611
+ /**
612
+ * Removes a comment attribute.
613
+ *
614
+ * See also {@link module:comments/comments/commentsrepository~Comment#setAttribute}.
615
+ *
616
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:updateComment
617
+ * @param name The attribute name.
618
+ */
619
+ removeAttribute(name: string): void;
620
+ /**
621
+ * Removes the comment.
622
+ *
623
+ * **Note:** This method fires the {@link module:comments/comments/commentsrepository~CommentsRepository#event:updateComment}
624
+ * event and the default behavior is added as a normal priority listener. It makes it
625
+ * possible to cancel the method or call some custom code before or after the default
626
+ * behavior is executed.
627
+ *
628
+ * @fires module:comments/comments/commentsrepository~CommentsRepository#event:removeComment
629
+ * @param data.isFromAdapter A flag describing whether the comment was
630
+ * updated from an adapter (`true`) or from the UI (`false`). If set to `true`, the adapter will not be called.
631
+ */
632
+ remove(data?: {
633
+ isFromAdapter?: boolean;
634
+ }): void;
635
+ toJSON(): CommentDataJSON;
636
+ /**
637
+ * Destroys the comment instance.
638
+ */
639
+ destroy(): void;
640
+ }
641
+ export type CommentThreadContext = null | {
642
+ type: string;
643
+ value: unknown;
644
+ };
645
+ /**
646
+ * @param channelId The ID of a document or context that the comment thread is handled.
647
+ * @param threadId The ID of the comment thread.
648
+ * @param isFromAdapter A flag describing whether the operation was done on a remote client (`true`) or a local one (`false`).
649
+ */
650
+ export interface BaseCommentThread {
651
+ channelId: string | symbol;
652
+ threadId: string;
653
+ isFromAdapter?: boolean;
654
+ }
655
+ /**
656
+ * @param commentId The comment ID.
657
+ */
658
+ export interface BaseComment extends BaseCommentThread {
659
+ commentId: string;
660
+ }
661
+ /**
662
+ * @param content The comment content.
663
+ * @param attributes Comment custom attributes.
664
+ */
665
+ export interface BaseCommentData {
666
+ content: string;
667
+ attributes: Record<string, any>;
668
+ }
669
+ /**
670
+ * Fired whenever a comment thread is added to the comments repository.
671
+ *
672
+ * The event name includes `channelId` so it is possible to listen only
673
+ * on changes happening in the specified channel.
674
+ *
675
+ * ```ts
676
+ * const channelId = 'foo';
677
+ *
678
+ * commentsRepository.on( `addCommentThread:${ channelId }`, ( evt, data ) => {
679
+ * console.log( evt, data );
680
+ * } );
681
+ * ```
682
+ *
683
+ * @eventName ~CommentsRepository#addCommentThread
684
+ */
685
+ export type AddCommentThreadEvent = {
686
+ name: string;
687
+ args: [Required<AddCommentThreadEventData>];
688
+ };
689
+ /**
690
+ * @param context The comment ID.
691
+ * @param attributes Comment thread custom attributes.
692
+ * @param resolvedAt ID of the comment author.
693
+ * @param resolvedBy The comment creation date.
694
+ */
695
+ export type CommentThreadData = BaseCommentThread & Partial<{
696
+ context: CommentThreadContext;
697
+ attributes: Record<string, any>;
698
+ resolvedAt: Date | null;
699
+ resolvedBy: string | null;
700
+ }>;
701
+ /**
702
+ * @param comments Comments in the comment thread.
703
+ * @param target The target that the comment balloon should be attached to.
704
+ */
705
+ export type AddCommentThreadEventData = CommentThreadData & {
706
+ comments?: Array<CommentData>;
707
+ target?: AnnotationTarget;
708
+ isResolvable?: boolean;
709
+ isSubmitted?: boolean;
710
+ deletedAt?: Date | null;
711
+ };
712
+ /**
713
+ * Fired whenever a new comment thread is submitted and occurs after creating the first comment.
714
+ *
715
+ * The event name includes `channelId` so it is possible to listen only
716
+ * on changes happening in the specified channel.
717
+ *
718
+ * ```ts
719
+ * const channelId = 'foo';
720
+ *
721
+ * commentsRepository.on( `submitCommentThread:${ channelId }`, ( evt, data ) => {
722
+ * console.log( evt, data );
723
+ * } );
724
+ * ```
725
+ *
726
+ * @eventName ~CommentsRepository#submitCommentThread
727
+ */
728
+ export type SubmitCommentThreadEvent = {
729
+ name: string;
730
+ args: [BaseCommentThread];
731
+ };
732
+ /**
733
+ * Fired whenever a comment thread is updated in comments repository.
734
+ *
735
+ * The event name includes `channelId` so it is possible to listen only
736
+ * on changes happening in the specified channel.
737
+ *
738
+ * @eventName ~CommentsRepository#updateCommentThread
739
+ */
740
+ export type UpdateCommentThreadEvent = {
741
+ name: string;
742
+ args: [UpdateCommentThreadEventData];
743
+ };
744
+ export type UpdateCommentThreadEventData = Omit<CommentThreadData, 'resolvedAt' | 'resolvedBy'>;
745
+ /**
746
+ * Fired whenever a comment thread is resolved.
747
+ *
748
+ * The event name includes `channelId` so it is possible to listen only
749
+ * on changes happening in the specified channel.
750
+ *
751
+ * ```ts
752
+ * const channelId = 'foo';
753
+ *
754
+ * commentsRepository.on( `resolveCommentThread:${ channelId }`, ( evt, data ) => {
755
+ * console.log( evt, data );
756
+ * } );
757
+ * ```
758
+ *
759
+ * @eventName ~CommentsRepository#resolveCommentThread
760
+ */
761
+ export type ResolveCommentThreadEvent = {
762
+ name: string;
763
+ args: [ResolveCommentThreadEventData];
764
+ };
765
+ export type ResolveCommentThreadEventData = Required<Omit<CommentThreadData, 'context' | 'attributes'>>;
766
+ /**
767
+ * Fired whenever a comment thread is reopened.
768
+ *
769
+ * The event name includes `channelId` so it is possible to listen only
770
+ * on changes happening in the specified channel.
771
+ *
772
+ * ```ts
773
+ * const channelId = 'foo';
774
+ *
775
+ * commentsRepository.on( `reopenCommentThread:${ channelId }`, ( evt, data ) => {
776
+ * console.log( evt, data );
777
+ * } );
778
+ * ```
779
+ *
780
+ * @eventName ~CommentsRepository#reopenCommentThread
781
+ */
782
+ export type ReopenCommentThreadEvent = {
783
+ name: string;
784
+ args: [BaseCommentThread];
785
+ };
786
+ /**
787
+ * Fired whenever a comment thread is removed from the comments repository.
788
+ *
789
+ * The event name includes `channelId` so it is possible to listen only
790
+ * on changes happening in the specified channel.
791
+ *
792
+ * ```ts
793
+ * const channelId = 'foo';
794
+ *
795
+ * commentsRepository.on( `removeCommentThread:${ channelId }`, ( evt, data ) => {
796
+ * console.log( evt, data );
797
+ * } );
798
+ * ```
799
+ *
800
+ * @eventName ~CommentsRepository#removeCommentThread
801
+ */
802
+ export type RemoveCommentThreadEvent = {
803
+ name: string;
804
+ args: [BaseCommentThread];
805
+ };
806
+ /**
807
+ * Fired whenever a comment is added.
808
+ *
809
+ * The event name includes `channelId` so it is possible to listen only
810
+ * on changes happening in the specified channel.
811
+ *
812
+ * It is also possible to listen to events from the given thread ID by appending `:[threadId]` part to the event name
813
+ *
814
+ * ```ts
815
+ * const channelId = 'foo';
816
+ * const threadId = '1234';
817
+ *
818
+ * commentsRepository.on( `addComment:${ channelId }:${ threadId }`, ( evt, data ) => {
819
+ * console.log( evt, data );
820
+ * } );
821
+ * ```
822
+ *
823
+ * @eventName ~CommentsRepository#addComment
824
+ */
825
+ export type AddCommentEvent = {
826
+ name: string;
827
+ args: [CommentEventData];
828
+ };
829
+ /**
830
+ * @param commentId The comment ID.
831
+ * @param authorId ID of the comment author.
832
+ * @param createdAt The comment creation date.
833
+ * @param isFromAdapter A flag describing whether the comment was updated on a remote client (`true`) or a local one (`false`).
834
+ */
835
+ export type CommentData = BaseCommentData & {
836
+ commentId?: string;
837
+ authorId: string;
838
+ createdAt: Date;
839
+ isFromAdapter?: boolean;
840
+ };
841
+ export type CommentEventData = BaseCommentThread & CommentData;
842
+ /**
843
+ * Fired whenever a comment is updated.
844
+ *
845
+ * The event name includes `channelId` so it is possible to listen only
846
+ * to changes happening in the specified channel.
847
+ *
848
+ * It is also possible to listen to events from the given thread ID by appending `:[threadId]` part to the event name
849
+ *
850
+ * ```ts
851
+ * const channelId = 'foo';
852
+ * const threadId = '1234';
853
+ *
854
+ * commentsRepository.on( `updateComment:${ channelId }:${ threadId }`, ( evt, data ) => {
855
+ * console.log( evt, data );
856
+ * } );
857
+ * ```
858
+ *
859
+ * @eventName ~CommentsRepository#updateComment
860
+ */
861
+ export type UpdateCommentEvent = {
862
+ name: string;
863
+ args: [UpdateCommentEventData];
864
+ };
865
+ export type UpdateCommentData = Partial<CommentEventData>;
866
+ export type UpdateCommentEventData = UpdateCommentData & BaseComment;
867
+ /**
868
+ * Fired whenever a comment is removed.
869
+ *
870
+ * The event name includes `channelId` so it is possible to listen only
871
+ * to changes happening in the specified channel.
872
+ *
873
+ * It is also possible to listen to events from the given thread ID by appending `:[threadId]` part to the event name
874
+ *
875
+ * ```ts
876
+ * const channelId = 'foo';
877
+ * const threadId = '1234';
878
+ *
879
+ * commentsRepository.on( `removeComment:${ channelId }:${ threadId }`, ( evt, data ) => {
880
+ * console.log( evt, data );
881
+ * } );
882
+ * ```
883
+ *
884
+ * @eventName ~CommentsRepository#removeComment
885
+ */
886
+ export type RemoveCommentEvent = {
887
+ name: string;
888
+ args: [BaseComment];
889
+ };
890
+ export type CommentDataJSON = Omit<CommentData, 'isFromAdapter'>;
891
+ export type CommentThreadDataJSON = {
892
+ threadId: string;
893
+ context: CommentThreadContext;
894
+ resolvedAt: Date | null;
895
+ resolvedBy: string | null;
896
+ comments: Array<CommentDataJSON>;
897
+ attributes: Record<string, unknown>;
898
+ };
899
+ /**
900
+ * Comments adapter.
901
+ *
902
+ * The comments adapter is an object that communicates asynchronously with the data source to fetch or save
903
+ * the comment data. It is used internally by the comments feature whenever a comment is loaded, created or deleted.
904
+ * The adapter is optional. You might need to provide it if you are {@glink features/collaboration/comments/comments-integration
905
+ * using the comments feature without real-time collaboration}.
906
+ * To set the adapter, overwrite the `CommentsRepository#adapter` property.
907
+ */
908
+ export interface CommentsAdapter {
909
+ /**
910
+ * Called whenever a new comment thread is created.
911
+ *
912
+ * The object which is passed as a parameter can contain the following properties:
913
+ * * channelId: string | symbol;
914
+ * * threadId: string;
915
+ * * context?: {@link module:comments/comments/commentsrepository~CommentThreadContext CommentThreadContext};
916
+ * * comments?: Array<{@link module:comments/comments/commentsrepository~CommentDataJSON CommentDataJSON}>;
917
+ * * resolvedAt?: Date | null;
918
+ * * resolvedBy?: string | null;
919
+ * * attributes?: Record<string, any> | null;
920
+ *
921
+ * It should return a promise that resolves with the new comment thread data.
922
+ * The resolved data object should contain the following properties:
923
+ * * threadId: string;
924
+ * * comments: Array<\{ commentId: string; createdAt: Date; \}>;
925
+ */
926
+ addCommentThread: (data: Omit<CommentThreadData, 'isFromAdapter'> & {
927
+ comments: Array<CommentDataJSON>;
928
+ }) => Promise<{
929
+ threadId: string;
930
+ comments: Array<{
931
+ commentId: string;
932
+ createdAt: Date;
933
+ }>;
934
+ }>;
935
+ /**
936
+ * Called when the editor needs the data for a comment thread.
937
+ *
938
+ * It should return a promise that resolves with the comment thread data.
939
+ * The resolved data object should contain the following properties:
940
+ * * threadId: string;
941
+ * * comments: Array<\{ commentId?: string; authorId: string; createdAt: Date; content: string; attributes: Record<string, any>; \}>;
942
+ * * resolvedAt?: Date | null;
943
+ * * resolvedBy?: string | null;
944
+ * * attributes: Record<string, unknown>;
945
+ *
946
+ * @param data.channelId The ID of the document or context to which the comment is added.
947
+ * @param data.threadId The ID of the comment thread that the comment is added to.
948
+ */
949
+ getCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<{
950
+ threadId: string;
951
+ comments: Array<CommentData>;
952
+ resolvedAt?: Date | null;
953
+ resolvedBy?: string | null;
954
+ attributes: Record<string, unknown>;
955
+ }>;
956
+ /**
957
+ * Called each time the user changes the existing comment thread.
958
+ *
959
+ * Keep in mind that for security reasons, the `authorId`, `createdAt`, `resolvedBy` and `resolvedAt` properties
960
+ * are not passed in the `updateCommentThread()` call and you should not set them as a result of this call.
961
+ *
962
+ * It updates the comment data in the database and returns a promise
963
+ * that will be resolved when the update is completed.
964
+ *
965
+ * The object which is passed as a parameter can contain the following properties:
966
+ * * channelId: string | symbol;
967
+ * * threadId: string;
968
+ * * context?: {@link module:comments/comments/commentsrepository~CommentThreadContext};
969
+ * * attributes?: Record<string, any> | null;
970
+ */
971
+ updateCommentThread: (data: Omit<UpdateCommentThreadEventData, 'isFromAdapter'>) => Promise<void>;
972
+ /**
973
+ * Called each time the user resolves a comment thread.
974
+ *
975
+ * Should set `resolvedAt` and `resolvedBy` properties in your database and should resolve with an object
976
+ * containing these two properties and returns a promise that will be resolved when the operation is completed.
977
+ *
978
+ * The resolved data object should contain the following properties:
979
+ * * threadId: string;
980
+ * * resolvedAt: Date;
981
+ * * resolvedBy: string;
982
+ *
983
+ * @param data.channelId The ID of the document or context that the comment thread is removed from.
984
+ * @param data.threadId The ID of the thread to remove.
985
+ */
986
+ resolveCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<{
987
+ threadId: string;
988
+ resolvedAt: Date;
989
+ resolvedBy: string;
990
+ }>;
991
+ /**
992
+ * Called when the user reopens a resolved comment thread.
993
+ *
994
+ * Should set `resolvedAt` and `resolvedBy` properties to `null` in your database and returns a promise
995
+ * that will be resolved when the operation is completed.
996
+ *
997
+ * @param data.channelId The ID of the document or context that the comment thread is removed from.
998
+ * @param data.threadId The ID of the thread to remove.
999
+ */
1000
+ reopenCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<void>;
1001
+ /**
1002
+ * Called each time the user removes a comment thread.
1003
+ *
1004
+ * It should return a promise that resolves when the thread is removed.
1005
+ *
1006
+ * @param data.channelId The ID of the document or context that the comment thread is removed from.
1007
+ * @param data.threadId The ID of the thread to remove.
1008
+ */
1009
+ removeCommentThread: (data: Omit<BaseCommentThread, 'isFromAdapter'>) => Promise<void>;
1010
+ /**
1011
+ * Called each time the user adds a new comment to a thread.
1012
+ *
1013
+ * It saves the comment data in the database and returns a promise
1014
+ * that should get resolved when the save is completed.
1015
+ *
1016
+ * If the promise resolves with an object with the `createdAt` property, the
1017
+ * comment property will be updated in the comment in the editor.
1018
+ * This is to update the comment data with the server-side information.
1019
+ *
1020
+ * The `data` object does not expect the `authorId` property.
1021
+ * For security reasons, the author of the comment should be set
1022
+ * on the server side.
1023
+ *
1024
+ * The `data` object does not expect the `createdAt` property either.
1025
+ * You should use the server-side time generator to ensure that all users
1026
+ * see the same date.
1027
+ *
1028
+ * It is recommended to stringify the `data.attributes` value to JSON
1029
+ * and to save it as a string in your database and then to parse the
1030
+ * value from JSON when loading comments.
1031
+ *
1032
+ * The object which is passed as a parameter can contain the following properties:
1033
+ * * channelId: string | symbol;
1034
+ * * threadId: string;
1035
+ * * commentId: string;
1036
+ * * content: string;
1037
+ * * attributes: Record<string, any>;
1038
+ *
1039
+ * The resolved data object should contain the following properties:
1040
+ * * commentId: string;
1041
+ * * createdAt: Date;
1042
+ *
1043
+ * @param data.channelId The ID of the document or context to which the comment is added.
1044
+ * @param data.threadId The ID of the comment thread that the comment is added to.
1045
+ * @param data.commentId The comment ID.
1046
+ * @param data.content The comment content.
1047
+ * @param data.attributes Comment custom attributes.
1048
+ */
1049
+ addComment: (data: Omit<BaseComment, 'isFromAdapter'> & BaseCommentData) => Promise<{
1050
+ commentId: string;
1051
+ createdAt: Date;
1052
+ }>;
1053
+ /**
1054
+ * Called each time the user changes the existing comment.
1055
+ *
1056
+ * It updates the comment data in the database and returns a promise
1057
+ * that will be resolved when the update is completed.
1058
+ *
1059
+ * Keep in mind that the `data` parameter only contains the
1060
+ * properties of a comment that have changed.
1061
+ *
1062
+ * The object which is passed as a parameter can contain the following properties:
1063
+ * * channelId: string | symbol;
1064
+ * * threadId: string;
1065
+ * * commentId: string;
1066
+ * * content?: string;
1067
+ * * attributes?: Record<string, any>;
1068
+ *
1069
+ * @param data.channelId The ID of the document or context where the comment is updated.
1070
+ * @param data.threadId The ID of the comment thread where the comment is updated.
1071
+ * @param data.commentId The ID of the comment to update.
1072
+ * @param data.content The new content of the comment.
1073
+ * @param data.attributes Custom comment attributes.
1074
+ */
1075
+ updateComment: (data: Omit<BaseComment, 'isFromAdapter'> & Partial<BaseCommentData>) => Promise<void>;
1076
+ /**
1077
+ * Called each time the user removes a comment from the thread.
1078
+ *
1079
+ * It removes the comment from the database and returns a promise
1080
+ * that will be resolved when the removal is completed.
1081
+ *
1082
+ * @param data.channelId The ID of the document or context that the comment is removed from.
1083
+ * @param data.threadId The ID of the comment thread that the comment is removed from.
1084
+ * @param data.commentId The ID of the comment to remove.
1085
+ */
1086
+ removeComment: (data: Omit<BaseComment, 'isFromAdapter'>) => Promise<void>;
1087
+ }
1088
+ export {};