dot-react-comment-lib 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +416 -0
- package/dist/index.d.mts +658 -0
- package/dist/index.d.ts +658 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +89 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default, { ReactNode } from 'react';
|
|
3
|
+
import { SxProps, Theme } from '@mui/material/styles';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Author / User metadata associated with a comment
|
|
7
|
+
*/
|
|
8
|
+
interface CommentAuthor {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
avatarUrl?: string | null;
|
|
12
|
+
role?: string | null;
|
|
13
|
+
email?: string | null;
|
|
14
|
+
badge?: string | null;
|
|
15
|
+
customData?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Single emoji reaction object
|
|
19
|
+
*/
|
|
20
|
+
interface CommentReaction {
|
|
21
|
+
emoji: string;
|
|
22
|
+
count: number;
|
|
23
|
+
users?: (string | CommentAuthor)[];
|
|
24
|
+
hasReacted?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Unified internal comment representation after applying schema adapter
|
|
28
|
+
*/
|
|
29
|
+
interface NormalizedComment<TRaw = unknown> {
|
|
30
|
+
id: string;
|
|
31
|
+
parentId: string | null;
|
|
32
|
+
content: string;
|
|
33
|
+
createdAt: Date | string | number;
|
|
34
|
+
updatedAt?: Date | string | number | null;
|
|
35
|
+
deletedAt?: Date | string | number | null;
|
|
36
|
+
author: CommentAuthor;
|
|
37
|
+
reactions?: CommentReaction[];
|
|
38
|
+
isPinned?: boolean;
|
|
39
|
+
depth: number;
|
|
40
|
+
replies?: NormalizedComment<TRaw>[];
|
|
41
|
+
raw?: TRaw;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Flexible database schema mapping configuration.
|
|
45
|
+
* Allows mapping any backend data structure (TypeORM, Prisma, REST API, Supabase, MongoDB)
|
|
46
|
+
* to the nested comments component.
|
|
47
|
+
*/
|
|
48
|
+
type KeyOrGetter<T, R> = keyof T | ((item: T) => R);
|
|
49
|
+
interface CommentFieldMapping<T = Record<string, unknown>> {
|
|
50
|
+
idKey?: KeyOrGetter<T, string>;
|
|
51
|
+
parentIdKey?: KeyOrGetter<T, string | null | undefined>;
|
|
52
|
+
contentKey?: KeyOrGetter<T, string>;
|
|
53
|
+
createdAtKey?: KeyOrGetter<T, Date | string | number>;
|
|
54
|
+
updatedAtKey?: KeyOrGetter<T, Date | string | number | null | undefined>;
|
|
55
|
+
deletedAtKey?: KeyOrGetter<T, Date | string | number | null | undefined>;
|
|
56
|
+
authorKey?: KeyOrGetter<T, CommentAuthor>;
|
|
57
|
+
authorIdKey?: KeyOrGetter<T, string>;
|
|
58
|
+
authorNameKey?: KeyOrGetter<T, string>;
|
|
59
|
+
authorAvatarKey?: KeyOrGetter<T, string | null | undefined>;
|
|
60
|
+
authorRoleKey?: KeyOrGetter<T, string | null | undefined>;
|
|
61
|
+
reactionsKey?: KeyOrGetter<T, CommentReaction[] | undefined>;
|
|
62
|
+
isPinnedKey?: KeyOrGetter<T, boolean | undefined>;
|
|
63
|
+
repliesKey?: KeyOrGetter<T, T[] | undefined>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sorting criteria
|
|
67
|
+
*/
|
|
68
|
+
type CommentSortOption = 'newest' | 'oldest' | 'mostUpvoted' | 'mostReplies';
|
|
69
|
+
/**
|
|
70
|
+
* Internationalization & custom text labels
|
|
71
|
+
*/
|
|
72
|
+
interface CommentLabels {
|
|
73
|
+
title: string;
|
|
74
|
+
writeCommentPlaceholder: string;
|
|
75
|
+
writeReplyPlaceholder: string;
|
|
76
|
+
postButton: string;
|
|
77
|
+
replyButton: string;
|
|
78
|
+
cancelButton: string;
|
|
79
|
+
saveButton: string;
|
|
80
|
+
editAction: string;
|
|
81
|
+
deleteAction: string;
|
|
82
|
+
replyAction: string;
|
|
83
|
+
pinAction: string;
|
|
84
|
+
unpinAction: string;
|
|
85
|
+
reportAction: string;
|
|
86
|
+
editedTag: string;
|
|
87
|
+
pinnedTag: string;
|
|
88
|
+
deletedMessage: string;
|
|
89
|
+
loadMoreReplies: string;
|
|
90
|
+
hideReplies: string;
|
|
91
|
+
viewReplies: (count: number) => string;
|
|
92
|
+
noComments: string;
|
|
93
|
+
sortNewest: string;
|
|
94
|
+
sortOldest: string;
|
|
95
|
+
sortPopular: string;
|
|
96
|
+
confirmDeleteTitle: string;
|
|
97
|
+
confirmDeleteBody: string;
|
|
98
|
+
validationRequired: string;
|
|
99
|
+
validationMinLength: (min: number) => string;
|
|
100
|
+
validationMaxLength: (max: number) => string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Granular custom styling for every UI component and slot in the library
|
|
104
|
+
*/
|
|
105
|
+
interface CommentCustomStyles {
|
|
106
|
+
/** Root container */
|
|
107
|
+
root?: SxProps<Theme>;
|
|
108
|
+
/** Header bar with count & sort control */
|
|
109
|
+
header?: SxProps<Theme>;
|
|
110
|
+
/** Title text */
|
|
111
|
+
title?: SxProps<Theme>;
|
|
112
|
+
/** Comment count badge */
|
|
113
|
+
countBadge?: SxProps<Theme>;
|
|
114
|
+
/** Sort select dropdown */
|
|
115
|
+
sortSelect?: SxProps<Theme>;
|
|
116
|
+
/** Main comment composer container */
|
|
117
|
+
composer?: SxProps<Theme>;
|
|
118
|
+
/** Textarea input inside composer */
|
|
119
|
+
composerInput?: SxProps<Theme>;
|
|
120
|
+
/** Composer bottom toolbar */
|
|
121
|
+
composerToolbar?: SxProps<Theme>;
|
|
122
|
+
/** Composer submit button */
|
|
123
|
+
composerSubmitButton?: SxProps<Theme>;
|
|
124
|
+
/** Composer cancel button */
|
|
125
|
+
composerCancelButton?: SxProps<Theme>;
|
|
126
|
+
/** Composer emoji trigger button */
|
|
127
|
+
composerEmojiButton?: SxProps<Theme>;
|
|
128
|
+
/** Single comment item container */
|
|
129
|
+
commentItem?: SxProps<Theme>;
|
|
130
|
+
/** Comment avatar */
|
|
131
|
+
avatar?: SxProps<Theme>;
|
|
132
|
+
/** Comment header row */
|
|
133
|
+
commentHeader?: SxProps<Theme>;
|
|
134
|
+
/** Author name text */
|
|
135
|
+
authorName?: SxProps<Theme>;
|
|
136
|
+
/** Author role/badge chip */
|
|
137
|
+
authorBadge?: SxProps<Theme>;
|
|
138
|
+
/** Timestamp text */
|
|
139
|
+
timestamp?: SxProps<Theme>;
|
|
140
|
+
/** Pinned tag badge */
|
|
141
|
+
pinnedBadge?: SxProps<Theme>;
|
|
142
|
+
/** Edited indicator text */
|
|
143
|
+
editedTag?: SxProps<Theme>;
|
|
144
|
+
/** Comment body text / content */
|
|
145
|
+
commentBody?: SxProps<Theme>;
|
|
146
|
+
/** Actions container */
|
|
147
|
+
actionsContainer?: SxProps<Theme>;
|
|
148
|
+
/** Reply action button */
|
|
149
|
+
replyButton?: SxProps<Theme>;
|
|
150
|
+
/** Edit action button */
|
|
151
|
+
editButton?: SxProps<Theme>;
|
|
152
|
+
/** Delete action button */
|
|
153
|
+
deleteButton?: SxProps<Theme>;
|
|
154
|
+
/** Pin action button */
|
|
155
|
+
pinButton?: SxProps<Theme>;
|
|
156
|
+
/** More options menu button */
|
|
157
|
+
moreMenuButton?: SxProps<Theme>;
|
|
158
|
+
/** Reactions bar container */
|
|
159
|
+
reactionsContainer?: SxProps<Theme>;
|
|
160
|
+
/** Single reaction chip / pill */
|
|
161
|
+
reactionChip?: SxProps<Theme>;
|
|
162
|
+
/** Active reaction chip (when current user has reacted) */
|
|
163
|
+
activeReactionChip?: SxProps<Theme>;
|
|
164
|
+
/** Add reaction '+' button */
|
|
165
|
+
addReactionButton?: SxProps<Theme>;
|
|
166
|
+
/** Vertical thread line connector */
|
|
167
|
+
threadLine?: SxProps<Theme>;
|
|
168
|
+
/** Collapse / expand replies button */
|
|
169
|
+
collapseButton?: SxProps<Theme>;
|
|
170
|
+
/** Nested replies container */
|
|
171
|
+
repliesContainer?: SxProps<Theme>;
|
|
172
|
+
/** Empty state placeholder box */
|
|
173
|
+
emptyState?: SxProps<Theme>;
|
|
174
|
+
/** Deleted comment text */
|
|
175
|
+
deletedCommentText?: SxProps<Theme>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Custom CSS class names for every UI component
|
|
179
|
+
*/
|
|
180
|
+
interface CommentClassNames {
|
|
181
|
+
root?: string;
|
|
182
|
+
header?: string;
|
|
183
|
+
title?: string;
|
|
184
|
+
countBadge?: string;
|
|
185
|
+
composer?: string;
|
|
186
|
+
commentItem?: string;
|
|
187
|
+
commentHeader?: string;
|
|
188
|
+
avatar?: string;
|
|
189
|
+
authorName?: string;
|
|
190
|
+
authorBadge?: string;
|
|
191
|
+
commentBody?: string;
|
|
192
|
+
actions?: string;
|
|
193
|
+
reactions?: string;
|
|
194
|
+
threadLine?: string;
|
|
195
|
+
replies?: string;
|
|
196
|
+
emptyState?: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Custom render slots for full UI control
|
|
200
|
+
*/
|
|
201
|
+
interface CommentCustomRenderers<T = unknown> {
|
|
202
|
+
avatar?: (author: CommentAuthor, comment: NormalizedComment<T>) => ReactNode;
|
|
203
|
+
header?: (comment: NormalizedComment<T>, defaultHeader: ReactNode) => ReactNode;
|
|
204
|
+
body?: (comment: NormalizedComment<T>, defaultBody: ReactNode) => ReactNode;
|
|
205
|
+
actions?: (comment: NormalizedComment<T>, defaultActions: ReactNode) => ReactNode;
|
|
206
|
+
composer?: (props: ComposerRenderProps) => ReactNode;
|
|
207
|
+
emptyState?: () => ReactNode;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Props passed to custom composer renderer
|
|
211
|
+
*/
|
|
212
|
+
interface ComposerRenderProps {
|
|
213
|
+
parentId?: string | null;
|
|
214
|
+
placeholder?: string;
|
|
215
|
+
isReply?: boolean;
|
|
216
|
+
onSubmit: (content: string) => Promise<boolean | void> | boolean | void;
|
|
217
|
+
onCancel?: () => void;
|
|
218
|
+
autoFocus?: boolean;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Configuration for business rules & UI options
|
|
222
|
+
*/
|
|
223
|
+
interface NestedCommentsConfig {
|
|
224
|
+
/**
|
|
225
|
+
* Whether nesting/threading is enabled.
|
|
226
|
+
* If false, renders as a flat sequential linear list.
|
|
227
|
+
* @default true
|
|
228
|
+
*/
|
|
229
|
+
enableNesting?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Maximum allowed nesting depth (0 = top-level only, 1 = 1 level of replies, Infinity = unlimited).
|
|
232
|
+
* When max depth is reached, new replies can either be disabled or attached at the max depth level.
|
|
233
|
+
* @default Infinity
|
|
234
|
+
*/
|
|
235
|
+
maxDepth?: number;
|
|
236
|
+
/**
|
|
237
|
+
* Indentation in pixels per nesting level.
|
|
238
|
+
* @default 28
|
|
239
|
+
*/
|
|
240
|
+
indentSize?: number;
|
|
241
|
+
/**
|
|
242
|
+
* Whether to display user avatars.
|
|
243
|
+
* Useful when business rules dictate no user photos should be shown.
|
|
244
|
+
* @default true
|
|
245
|
+
*/
|
|
246
|
+
showAvatars?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Shape of the avatar.
|
|
249
|
+
* @default 'circle'
|
|
250
|
+
*/
|
|
251
|
+
avatarShape?: 'circle' | 'rounded' | 'square';
|
|
252
|
+
/**
|
|
253
|
+
* Whether to render connecting thread lines for nested replies.
|
|
254
|
+
* @default true
|
|
255
|
+
*/
|
|
256
|
+
showThreadLines?: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Whether comment threads can be collapsed/expanded.
|
|
259
|
+
* @default true
|
|
260
|
+
*/
|
|
261
|
+
collapsible?: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Default collapse/expand state for comment replies.
|
|
264
|
+
* @default true
|
|
265
|
+
*/
|
|
266
|
+
defaultExpanded?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Enable emoji reaction bar and picker.
|
|
269
|
+
* @default true
|
|
270
|
+
*/
|
|
271
|
+
enableReactions?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* List of quick emoji reactions to display on hover/click.
|
|
274
|
+
* @default ['👍', '❤️', '🔥', '🎉', '🚀', '👀']
|
|
275
|
+
*/
|
|
276
|
+
quickReactions?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Enable full emoji picker popup via emoji-picker-react.
|
|
279
|
+
* @default true
|
|
280
|
+
*/
|
|
281
|
+
enableEmojiPicker?: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* How to handle soft-deleted comments (where deletedAt is set).
|
|
284
|
+
* - 'placeholder': Renders "[This comment was deleted]" while keeping reply branch intact.
|
|
285
|
+
* - 'hide': Completely removes the comment and its subtree.
|
|
286
|
+
* @default 'placeholder'
|
|
287
|
+
*/
|
|
288
|
+
softDeleteHandling?: 'placeholder' | 'hide';
|
|
289
|
+
/**
|
|
290
|
+
* Position of the main new-comment composer.
|
|
291
|
+
* @default 'top'
|
|
292
|
+
*/
|
|
293
|
+
composerPosition?: 'top' | 'bottom' | 'both' | 'none';
|
|
294
|
+
/**
|
|
295
|
+
* Show sort dropdown control.
|
|
296
|
+
* @default true
|
|
297
|
+
*/
|
|
298
|
+
showSortControl?: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Initial or controlled sort order.
|
|
301
|
+
* @default 'newest'
|
|
302
|
+
*/
|
|
303
|
+
sortBy?: CommentSortOption;
|
|
304
|
+
/**
|
|
305
|
+
* Minimum content character length for validation.
|
|
306
|
+
* @default 1
|
|
307
|
+
*/
|
|
308
|
+
minContentLength?: number;
|
|
309
|
+
/**
|
|
310
|
+
* Maximum content character length for validation.
|
|
311
|
+
* @default 5000
|
|
312
|
+
*/
|
|
313
|
+
maxContentLength?: number;
|
|
314
|
+
/**
|
|
315
|
+
* Auto focus input when replying.
|
|
316
|
+
* @default true
|
|
317
|
+
*/
|
|
318
|
+
autoFocusOnReply?: boolean;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Permission checks (boolean or functional predicate per comment)
|
|
322
|
+
*/
|
|
323
|
+
interface CommentPermissions<T = unknown> {
|
|
324
|
+
canReply?: boolean | ((comment: NormalizedComment<T>, currentUser?: CommentAuthor) => boolean);
|
|
325
|
+
canEdit?: boolean | ((comment: NormalizedComment<T>, currentUser?: CommentAuthor) => boolean);
|
|
326
|
+
canDelete?: boolean | ((comment: NormalizedComment<T>, currentUser?: CommentAuthor) => boolean);
|
|
327
|
+
canReact?: boolean | ((comment: NormalizedComment<T>, currentUser?: CommentAuthor) => boolean);
|
|
328
|
+
canPin?: boolean | ((comment: NormalizedComment<T>, currentUser?: CommentAuthor) => boolean);
|
|
329
|
+
canReport?: boolean | ((comment: NormalizedComment<T>, currentUser?: CommentAuthor) => boolean);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Main Props for `<NestedComments />`
|
|
333
|
+
*/
|
|
334
|
+
interface NestedCommentsProps<T = Record<string, unknown>> {
|
|
335
|
+
/**
|
|
336
|
+
* Array of comments. Can be flat list (with parent IDs) or nested tree.
|
|
337
|
+
*/
|
|
338
|
+
comments: T[];
|
|
339
|
+
/**
|
|
340
|
+
* Database schema field mapping adapter or preset name ('room-chat' | 'default').
|
|
341
|
+
*/
|
|
342
|
+
schema?: CommentFieldMapping<T> | 'room-chat' | 'default';
|
|
343
|
+
/**
|
|
344
|
+
* The currently logged-in user viewing/posting comments.
|
|
345
|
+
*/
|
|
346
|
+
currentUser?: CommentAuthor;
|
|
347
|
+
/**
|
|
348
|
+
* Business rules & UI configuration options.
|
|
349
|
+
*/
|
|
350
|
+
config?: NestedCommentsConfig;
|
|
351
|
+
/**
|
|
352
|
+
* Permissions and access control.
|
|
353
|
+
*/
|
|
354
|
+
permissions?: CommentPermissions<T>;
|
|
355
|
+
/**
|
|
356
|
+
* Custom text labels & internationalization.
|
|
357
|
+
*/
|
|
358
|
+
labels?: Partial<CommentLabels>;
|
|
359
|
+
/**
|
|
360
|
+
* Granular styling overrides for all elements in the component.
|
|
361
|
+
*/
|
|
362
|
+
styles?: CommentCustomStyles;
|
|
363
|
+
/**
|
|
364
|
+
* Custom CSS classes for elements.
|
|
365
|
+
*/
|
|
366
|
+
classes?: CommentClassNames;
|
|
367
|
+
/**
|
|
368
|
+
* Custom render slots for advanced customizations.
|
|
369
|
+
*/
|
|
370
|
+
renderers?: CommentCustomRenderers<T>;
|
|
371
|
+
/**
|
|
372
|
+
* Callback fired when submitting a new top-level or reply comment.
|
|
373
|
+
*/
|
|
374
|
+
onSubmitComment?: (data: {
|
|
375
|
+
content: string;
|
|
376
|
+
parentId: string | null;
|
|
377
|
+
parentComment?: NormalizedComment<T>;
|
|
378
|
+
}) => Promise<void> | void;
|
|
379
|
+
/**
|
|
380
|
+
* Callback fired when editing a comment.
|
|
381
|
+
*/
|
|
382
|
+
onEditComment?: (data: {
|
|
383
|
+
id: string;
|
|
384
|
+
content: string;
|
|
385
|
+
comment: NormalizedComment<T>;
|
|
386
|
+
}) => Promise<void> | void;
|
|
387
|
+
/**
|
|
388
|
+
* Callback fired when deleting a comment.
|
|
389
|
+
*/
|
|
390
|
+
onDeleteComment?: (data: {
|
|
391
|
+
id: string;
|
|
392
|
+
comment: NormalizedComment<T>;
|
|
393
|
+
isPermanent?: boolean;
|
|
394
|
+
}) => Promise<void> | void;
|
|
395
|
+
/**
|
|
396
|
+
* Callback fired when reacting with an emoji.
|
|
397
|
+
*/
|
|
398
|
+
onReactComment?: (data: {
|
|
399
|
+
id: string;
|
|
400
|
+
emoji: string;
|
|
401
|
+
comment: NormalizedComment<T>;
|
|
402
|
+
action: 'add' | 'remove';
|
|
403
|
+
}) => Promise<void> | void;
|
|
404
|
+
/**
|
|
405
|
+
* Callback fired when pinning or unpinning a comment.
|
|
406
|
+
*/
|
|
407
|
+
onPinComment?: (data: {
|
|
408
|
+
id: string;
|
|
409
|
+
isPinned: boolean;
|
|
410
|
+
comment: NormalizedComment<T>;
|
|
411
|
+
}) => Promise<void> | void;
|
|
412
|
+
/**
|
|
413
|
+
* Callback fired when user reports a comment.
|
|
414
|
+
*/
|
|
415
|
+
onReportComment?: (data: {
|
|
416
|
+
id: string;
|
|
417
|
+
comment: NormalizedComment<T>;
|
|
418
|
+
}) => Promise<void> | void;
|
|
419
|
+
/**
|
|
420
|
+
* Controlled sort change handler.
|
|
421
|
+
*/
|
|
422
|
+
onSortChange?: (sort: CommentSortOption) => void;
|
|
423
|
+
/**
|
|
424
|
+
* Custom date formatter function. Defaults to relative time (e.g. "2h ago").
|
|
425
|
+
*/
|
|
426
|
+
formatDate?: (date: Date | string | number) => string;
|
|
427
|
+
/**
|
|
428
|
+
* Root CSS class name.
|
|
429
|
+
*/
|
|
430
|
+
className?: string;
|
|
431
|
+
/**
|
|
432
|
+
* MUI sx styling props for root container.
|
|
433
|
+
*/
|
|
434
|
+
sx?: SxProps<Theme>;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
declare function NestedComments<T = Record<string, unknown>>({ comments: rawComments, schema, currentUser, config, permissions, labels, styles, classes, renderers, onSubmitComment, onEditComment, onDeleteComment, onReactComment, onPinComment, onReportComment, onSortChange, formatDate, className, sx, }: NestedCommentsProps<T>): React__default.JSX.Element;
|
|
438
|
+
|
|
439
|
+
declare const CommentList: React__default.FC;
|
|
440
|
+
|
|
441
|
+
interface CommentItemProps {
|
|
442
|
+
comment: NormalizedComment;
|
|
443
|
+
}
|
|
444
|
+
declare const CommentItem: React__default.NamedExoticComponent<CommentItemProps>;
|
|
445
|
+
|
|
446
|
+
interface CommentComposerProps {
|
|
447
|
+
parentId?: string | null;
|
|
448
|
+
parentComment?: NormalizedComment;
|
|
449
|
+
placeholder?: string;
|
|
450
|
+
isReply?: boolean;
|
|
451
|
+
initialValue?: string;
|
|
452
|
+
isEdit?: boolean;
|
|
453
|
+
onCancel?: () => void;
|
|
454
|
+
onSuccess?: () => void;
|
|
455
|
+
autoFocus?: boolean;
|
|
456
|
+
}
|
|
457
|
+
declare const CommentComposer: React__default.NamedExoticComponent<CommentComposerProps>;
|
|
458
|
+
|
|
459
|
+
interface CommentAvatarProps {
|
|
460
|
+
author: CommentAuthor;
|
|
461
|
+
comment?: NormalizedComment;
|
|
462
|
+
size?: number;
|
|
463
|
+
}
|
|
464
|
+
declare const CommentAvatar: React__default.NamedExoticComponent<CommentAvatarProps>;
|
|
465
|
+
|
|
466
|
+
interface CommentActionsProps {
|
|
467
|
+
comment: NormalizedComment;
|
|
468
|
+
}
|
|
469
|
+
declare const CommentActions: React__default.NamedExoticComponent<CommentActionsProps>;
|
|
470
|
+
|
|
471
|
+
interface EmojiReactionPickerProps {
|
|
472
|
+
comment: NormalizedComment;
|
|
473
|
+
}
|
|
474
|
+
declare const EmojiReactionPicker: React__default.NamedExoticComponent<EmojiReactionPickerProps>;
|
|
475
|
+
|
|
476
|
+
interface ThreadConnectorProps {
|
|
477
|
+
onToggleCollapse?: () => void;
|
|
478
|
+
isCollapsed?: boolean;
|
|
479
|
+
}
|
|
480
|
+
declare const ThreadConnector: React__default.NamedExoticComponent<ThreadConnectorProps>;
|
|
481
|
+
|
|
482
|
+
interface CommentContextValue<T = unknown> {
|
|
483
|
+
comments: NormalizedComment<T>[];
|
|
484
|
+
currentUser?: CommentAuthor;
|
|
485
|
+
config: Required<NestedCommentsConfig>;
|
|
486
|
+
permissions: CommentPermissions<T>;
|
|
487
|
+
labels: CommentLabels;
|
|
488
|
+
renderers: CommentCustomRenderers<T>;
|
|
489
|
+
styles: CommentCustomStyles;
|
|
490
|
+
classes: CommentClassNames;
|
|
491
|
+
sortBy: CommentSortOption;
|
|
492
|
+
setSortBy: (sort: CommentSortOption) => void;
|
|
493
|
+
activeReplyId: string | null;
|
|
494
|
+
setActiveReplyId: (id: string | null) => void;
|
|
495
|
+
activeEditId: string | null;
|
|
496
|
+
setActiveEditId: (id: string | null) => void;
|
|
497
|
+
collapsedIds: Set<string>;
|
|
498
|
+
toggleCollapse: (id: string) => void;
|
|
499
|
+
isCollapsed: (id: string) => boolean;
|
|
500
|
+
handleSubmitComment: (content: string, parentId?: string | null) => Promise<boolean>;
|
|
501
|
+
handleEditComment: (id: string, content: string) => Promise<boolean>;
|
|
502
|
+
handleDeleteComment: (id: string) => Promise<boolean>;
|
|
503
|
+
handleReactComment: (id: string, emoji: string) => Promise<boolean>;
|
|
504
|
+
handlePinComment: (id: string) => Promise<boolean>;
|
|
505
|
+
handleReportComment: (id: string) => Promise<boolean>;
|
|
506
|
+
formatDate: (date: Date | string | number) => string;
|
|
507
|
+
}
|
|
508
|
+
declare const defaultConfig: Required<NestedCommentsConfig>;
|
|
509
|
+
interface CommentProviderProps<T = unknown> {
|
|
510
|
+
children: React__default.ReactNode;
|
|
511
|
+
comments: NormalizedComment<T>[];
|
|
512
|
+
currentUser?: CommentAuthor;
|
|
513
|
+
config?: NestedCommentsConfig;
|
|
514
|
+
permissions?: CommentPermissions<T>;
|
|
515
|
+
labels?: Partial<CommentLabels>;
|
|
516
|
+
styles?: CommentCustomStyles;
|
|
517
|
+
classes?: CommentClassNames;
|
|
518
|
+
renderers?: CommentCustomRenderers<T>;
|
|
519
|
+
formatDate?: (date: Date | string | number) => string;
|
|
520
|
+
sortBy?: CommentSortOption;
|
|
521
|
+
onSortChange?: (sort: CommentSortOption) => void;
|
|
522
|
+
onSubmitComment?: (data: {
|
|
523
|
+
content: string;
|
|
524
|
+
parentId: string | null;
|
|
525
|
+
parentComment?: NormalizedComment<T>;
|
|
526
|
+
}) => Promise<void> | void;
|
|
527
|
+
onEditComment?: (data: {
|
|
528
|
+
id: string;
|
|
529
|
+
content: string;
|
|
530
|
+
comment: NormalizedComment<T>;
|
|
531
|
+
}) => Promise<void> | void;
|
|
532
|
+
onDeleteComment?: (data: {
|
|
533
|
+
id: string;
|
|
534
|
+
comment: NormalizedComment<T>;
|
|
535
|
+
}) => Promise<void> | void;
|
|
536
|
+
onReactComment?: (data: {
|
|
537
|
+
id: string;
|
|
538
|
+
emoji: string;
|
|
539
|
+
comment: NormalizedComment<T>;
|
|
540
|
+
action: 'add' | 'remove';
|
|
541
|
+
}) => Promise<void> | void;
|
|
542
|
+
onPinComment?: (data: {
|
|
543
|
+
id: string;
|
|
544
|
+
isPinned: boolean;
|
|
545
|
+
comment: NormalizedComment<T>;
|
|
546
|
+
}) => Promise<void> | void;
|
|
547
|
+
onReportComment?: (data: {
|
|
548
|
+
id: string;
|
|
549
|
+
comment: NormalizedComment<T>;
|
|
550
|
+
}) => Promise<void> | void;
|
|
551
|
+
}
|
|
552
|
+
declare function CommentProvider<T = unknown>({ children, comments, currentUser, config: userConfig, permissions, labels: userLabels, styles, classes, renderers, formatDate, sortBy: controlledSortBy, onSortChange, onSubmitComment, onEditComment, onDeleteComment, onReactComment, onPinComment, onReportComment, }: CommentProviderProps<T>): React__default.JSX.Element;
|
|
553
|
+
declare function useCommentContext<T = unknown>(): CommentContextValue<T>;
|
|
554
|
+
|
|
555
|
+
interface UseCommentTreeOptions<T = Record<string, unknown>> {
|
|
556
|
+
initialData?: T[];
|
|
557
|
+
schema?: CommentFieldMapping<T> | 'room-chat' | 'default';
|
|
558
|
+
enableNesting?: boolean;
|
|
559
|
+
maxDepth?: number;
|
|
560
|
+
sortBy?: CommentSortOption;
|
|
561
|
+
currentUser?: CommentAuthor;
|
|
562
|
+
}
|
|
563
|
+
declare function useCommentTree<T = Record<string, unknown>>({ initialData, schema, enableNesting, maxDepth, sortBy, currentUser, }: UseCommentTreeOptions<T>): {
|
|
564
|
+
comments: NormalizedComment<T>[];
|
|
565
|
+
rawTree: NormalizedComment<T>[];
|
|
566
|
+
setTree: React.Dispatch<React.SetStateAction<NormalizedComment<T>[]>>;
|
|
567
|
+
sortBy: CommentSortOption;
|
|
568
|
+
setSortBy: React.Dispatch<React.SetStateAction<CommentSortOption>>;
|
|
569
|
+
addComment: (content: string, parentId?: string | null, author?: CommentAuthor) => NormalizedComment<T>;
|
|
570
|
+
editComment: (id: string, newContent: string) => void;
|
|
571
|
+
deleteComment: (id: string, softDelete?: boolean) => void;
|
|
572
|
+
reactToComment: (id: string, emoji: string, user?: CommentAuthor) => void;
|
|
573
|
+
pinComment: (id: string) => void;
|
|
574
|
+
totalComments: number;
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Helper to resolve a value either from an object key or a custom getter function.
|
|
579
|
+
*/
|
|
580
|
+
declare function resolveValue<T, R>(item: T, keyOrGetter?: KeyOrGetter<T, R>, defaultValue?: R): R | undefined;
|
|
581
|
+
/**
|
|
582
|
+
* Default fallback field mapping adapter
|
|
583
|
+
*/
|
|
584
|
+
declare const defaultFieldMapping: CommentFieldMapping<Record<string, unknown>>;
|
|
585
|
+
/**
|
|
586
|
+
* Normalizes any raw data item into a unified NormalizedComment structure.
|
|
587
|
+
*/
|
|
588
|
+
declare function normalizeComment<T = Record<string, unknown>>(rawItem: T, mapping?: CommentFieldMapping<T>, currentDepth?: number): NormalizedComment<T>;
|
|
589
|
+
/**
|
|
590
|
+
* Builds a nested comment tree from a flat list of normalized comments.
|
|
591
|
+
*/
|
|
592
|
+
declare function buildCommentTree<T = unknown>(comments: NormalizedComment<T>[], maxDepth?: number): NormalizedComment<T>[];
|
|
593
|
+
/**
|
|
594
|
+
* Flattens a comment tree back into a single 1D array.
|
|
595
|
+
*/
|
|
596
|
+
declare function flattenCommentTree<T = unknown>(tree: NormalizedComment<T>[]): NormalizedComment<T>[];
|
|
597
|
+
/**
|
|
598
|
+
* Finds a comment by its ID in a nested tree.
|
|
599
|
+
*/
|
|
600
|
+
declare function findCommentInTree<T = unknown>(tree: NormalizedComment<T>[], id: string): NormalizedComment<T> | null;
|
|
601
|
+
/**
|
|
602
|
+
* Inserts a new comment into a tree (either at root or as reply to parent).
|
|
603
|
+
*/
|
|
604
|
+
declare function insertCommentInTree<T = unknown>(tree: NormalizedComment<T>[], newComment: NormalizedComment<T>, parentId?: string | null): NormalizedComment<T>[];
|
|
605
|
+
/**
|
|
606
|
+
* Updates a comment in a tree by ID.
|
|
607
|
+
*/
|
|
608
|
+
declare function updateCommentInTree<T = unknown>(tree: NormalizedComment<T>[], id: string, updater: (comment: NormalizedComment<T>) => NormalizedComment<T>): NormalizedComment<T>[];
|
|
609
|
+
/**
|
|
610
|
+
* Deletes a comment from a tree.
|
|
611
|
+
* If softDelete is true, sets deletedAt on the comment.
|
|
612
|
+
* If false, completely removes node from the tree.
|
|
613
|
+
*/
|
|
614
|
+
declare function deleteCommentInTree<T = unknown>(tree: NormalizedComment<T>[], id: string, softDelete?: boolean): NormalizedComment<T>[];
|
|
615
|
+
/**
|
|
616
|
+
* Sorts root comments and their replies recursively.
|
|
617
|
+
*/
|
|
618
|
+
declare function sortCommentTree<T = unknown>(tree: NormalizedComment<T>[], sortOption?: CommentSortOption): NormalizedComment<T>[];
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Interface matching RoomChatEntity
|
|
622
|
+
*/
|
|
623
|
+
interface RoomChatEntityLike {
|
|
624
|
+
uuid: string;
|
|
625
|
+
message_parent_uuid?: string | null;
|
|
626
|
+
message: string;
|
|
627
|
+
created_at: Date | string;
|
|
628
|
+
updated_at?: Date | string;
|
|
629
|
+
deleted_at?: Date | string | null;
|
|
630
|
+
author_id?: string;
|
|
631
|
+
author_name?: string;
|
|
632
|
+
author_avatar?: string;
|
|
633
|
+
author_role?: string;
|
|
634
|
+
reactions?: any[];
|
|
635
|
+
is_pinned?: boolean;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Pre-configured adapter for TypeORM RoomChatEntity or similar relational DB schemas.
|
|
639
|
+
*/
|
|
640
|
+
declare const roomChatSchemaMapping: CommentFieldMapping<RoomChatEntityLike>;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Formats a date/timestamp into a friendly relative or absolute string.
|
|
644
|
+
*/
|
|
645
|
+
declare function formatRelativeTime(dateInput: Date | string | number | undefined | null): string;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Generates initials from a full name (e.g. "John Doe" -> "JD", "Antigravity" -> "A")
|
|
649
|
+
*/
|
|
650
|
+
declare function getInitials(name?: string | null): string;
|
|
651
|
+
/**
|
|
652
|
+
* Generates a pleasant HSL color based on string hash for user avatars
|
|
653
|
+
*/
|
|
654
|
+
declare function stringToColor(str?: string | null): string;
|
|
655
|
+
|
|
656
|
+
declare const defaultLabels: CommentLabels;
|
|
657
|
+
|
|
658
|
+
export { CommentActions, type CommentActionsProps, type CommentAuthor, CommentAvatar, type CommentAvatarProps, type CommentClassNames, CommentComposer, type CommentComposerProps, type CommentContextValue, type CommentCustomRenderers, type CommentCustomStyles, type CommentFieldMapping, CommentItem, type CommentItemProps, type CommentLabels, CommentList, type CommentPermissions, CommentProvider, type CommentProviderProps, type CommentReaction, type CommentSortOption, type ComposerRenderProps, EmojiReactionPicker, type EmojiReactionPickerProps, type KeyOrGetter, NestedComments, type NestedCommentsConfig, type NestedCommentsProps, type NormalizedComment, type RoomChatEntityLike, ThreadConnector, type ThreadConnectorProps, type UseCommentTreeOptions, buildCommentTree, defaultConfig, defaultFieldMapping, defaultLabels, deleteCommentInTree, findCommentInTree, flattenCommentTree, formatRelativeTime, getInitials, insertCommentInTree, normalizeComment, resolveValue, roomChatSchemaMapping, sortCommentTree, stringToColor, updateCommentInTree, useCommentContext, useCommentTree };
|