@kendew-agency/react-feedback-layer 0.3.2 → 0.4.0-rc.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.
- package/README.md +772 -451
- package/dist/index.cjs +981 -224
- package/dist/index.d.cts +69 -13
- package/dist/index.d.ts +69 -13
- package/dist/index.js +981 -220
- package/dist/types.d.cts +481 -7
- package/dist/types.d.ts +481 -7
- package/package.json +9 -3
- package/dist/comment.types-C0m3sQ_Q.d.cts +0 -322
- package/dist/comment.types-C0m3sQ_Q.d.ts +0 -322
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Event map for comment-related events
|
|
5
|
-
* Each key is an event name and the value is the callback signature
|
|
6
|
-
*/
|
|
7
|
-
type CommentEventMap = {
|
|
8
|
-
/**
|
|
9
|
-
* Triggered when focus changes to a different comment
|
|
10
|
-
* @param commentId - The id of the newly focused comment, or null if unfocused
|
|
11
|
-
* @param comment - The focused comment object, or undefined if unfocused
|
|
12
|
-
*/
|
|
13
|
-
onFocusChange: (commentId: string | null, comment: CommentType | undefined) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Triggered when comments are confirmed (saved)
|
|
16
|
-
* @param comments - The comments that were confirmed
|
|
17
|
-
*/
|
|
18
|
-
onCommentsConfirmed: (comments: CommentType[]) => void;
|
|
19
|
-
/**
|
|
20
|
-
* Triggered when comments are resolved
|
|
21
|
-
* @param comments - The comments that were resolved
|
|
22
|
-
*/
|
|
23
|
-
onCommentsResolved: (comments: CommentType[]) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Triggered when a comment is deleted
|
|
26
|
-
* @param commentId - The id of the deleted comment
|
|
27
|
-
*/
|
|
28
|
-
onCommentDeleted: (commentId: string) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Triggered when a new comment is registered (draft created)
|
|
31
|
-
* @param comment - The newly registered comment
|
|
32
|
-
*/
|
|
33
|
-
onCommentRegistered: (comment: CommentType) => void;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* A function to unsubscribe from an event
|
|
37
|
-
*/
|
|
38
|
-
type Unsubscribe = () => void;
|
|
39
|
-
/**
|
|
40
|
-
* The events object exposed via useComments()
|
|
41
|
-
* Each method accepts a callback and returns an unsubscribe function
|
|
42
|
-
*/
|
|
43
|
-
type CommentEvents = {
|
|
44
|
-
[K in keyof CommentEventMap]: (callback: CommentEventMap[K]) => Unsubscribe;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
declare class BaseError extends Error {
|
|
48
|
-
code: OverlayErrorCode;
|
|
49
|
-
status: number;
|
|
50
|
-
constructor(message: string, code?: OverlayErrorCode, status?: number);
|
|
51
|
-
}
|
|
52
|
-
declare class ResolveError extends BaseError {
|
|
53
|
-
constructor(message?: string);
|
|
54
|
-
}
|
|
55
|
-
declare class ConfirmError extends BaseError {
|
|
56
|
-
constructor(message?: string);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR";
|
|
60
|
-
type KnownError = ConfirmError | ResolveError;
|
|
61
|
-
|
|
62
|
-
type CommentState = {
|
|
63
|
-
/**
|
|
64
|
-
* All confirmed comments
|
|
65
|
-
* @description This is used to track all confirmed comments
|
|
66
|
-
*/
|
|
67
|
-
comments: CommentType[];
|
|
68
|
-
/**
|
|
69
|
-
* The state of the comment overlay
|
|
70
|
-
* @description This value is used to track the state of the comment overlay
|
|
71
|
-
* @see CommentOverlayState
|
|
72
|
-
*/
|
|
73
|
-
overlayState: CommentOverlayState;
|
|
74
|
-
/**
|
|
75
|
-
* The current loged in user.
|
|
76
|
-
* @description This data will be included when a user adds a comment
|
|
77
|
-
*/
|
|
78
|
-
currentUser: User | null;
|
|
79
|
-
/**
|
|
80
|
-
* Track the focussed comment when editing or adding a comment
|
|
81
|
-
* The comment key will be stored in this state
|
|
82
|
-
*/
|
|
83
|
-
focussedComment: string | null;
|
|
84
|
-
/**
|
|
85
|
-
* Any error that occurs during comment operations
|
|
86
|
-
* The value can be used to display an error message to the user
|
|
87
|
-
*/
|
|
88
|
-
error?: Error;
|
|
89
|
-
/**
|
|
90
|
-
* Optional configuration for the comment layer
|
|
91
|
-
*/
|
|
92
|
-
config?: Config | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Attached a project ID to the current overlay
|
|
95
|
-
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
96
|
-
*/
|
|
97
|
-
projectId?: string | undefined;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* The state of the comment overlay
|
|
101
|
-
* @description This is used to track the state of the comment overlay
|
|
102
|
-
*/
|
|
103
|
-
type CommentOverlayState = "idle" | "editing" | "saving" | "resolving" | "inactive";
|
|
104
|
-
type CommentVisibility = {
|
|
105
|
-
/**
|
|
106
|
-
* Hide comments that are marked as resolved
|
|
107
|
-
* @default false
|
|
108
|
-
*/
|
|
109
|
-
hideResolved?: boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Hide comments that are being resolved
|
|
112
|
-
* @default false
|
|
113
|
-
*/
|
|
114
|
-
hideResolving?: boolean;
|
|
115
|
-
};
|
|
116
|
-
type CommentOverlayProps = {
|
|
117
|
-
/**
|
|
118
|
-
* Initial comments present when opening the comment overlay
|
|
119
|
-
* @description These comments usually come from your database
|
|
120
|
-
*/
|
|
121
|
-
initialComments?: ConfirmedComment[];
|
|
122
|
-
/**
|
|
123
|
-
* The current user
|
|
124
|
-
*
|
|
125
|
-
* @description This is used to identify the user in your database. If you can not provide a user, comments will be added anonymously
|
|
126
|
-
* @default null
|
|
127
|
-
*/
|
|
128
|
-
currentUser: User | null;
|
|
129
|
-
/**
|
|
130
|
-
* The children of the comment overlay
|
|
131
|
-
* @description This is where the comments will be rendered
|
|
132
|
-
*/
|
|
133
|
-
children: ReactNode;
|
|
134
|
-
/**
|
|
135
|
-
* The state of the overlay on initial render
|
|
136
|
-
* @default "inactive"
|
|
137
|
-
*/
|
|
138
|
-
initialOverlayState?: CommentOverlayState;
|
|
139
|
-
/**
|
|
140
|
-
* Realtime subscription if supported by you DB
|
|
141
|
-
* @description You can use this feature with a realtime DB or a websocket
|
|
142
|
-
* @beta this featue is not yet fully tested and is subject to change
|
|
143
|
-
*/
|
|
144
|
-
subscription?: RealtimeSubscription<CommentType>;
|
|
145
|
-
/**
|
|
146
|
-
* Callback with all newly confirmed comments
|
|
147
|
-
*
|
|
148
|
-
* @param comments as the comments pushed by the user
|
|
149
|
-
* @param projectId as the project id if provided
|
|
150
|
-
*/
|
|
151
|
-
onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Callback to handle resolved comments
|
|
154
|
-
*
|
|
155
|
-
* @param comments as the comments that are marked as resolved
|
|
156
|
-
*/
|
|
157
|
-
onResolve: (comments: ConfirmedComment[]) => Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Callback to handle errors
|
|
160
|
-
*
|
|
161
|
-
* @param error as the error that occurred
|
|
162
|
-
*/
|
|
163
|
-
onError: (error: KnownError) => void;
|
|
164
|
-
/**
|
|
165
|
-
* Optional configuration for the comment layer
|
|
166
|
-
*/
|
|
167
|
-
config?: Config;
|
|
168
|
-
/**
|
|
169
|
-
* Attached a project ID to the current overlay
|
|
170
|
-
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* projectId: "proj_123456789"
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
projectId?: string;
|
|
177
|
-
};
|
|
178
|
-
interface RealtimeSubscription<T> {
|
|
179
|
-
subscribe(onUpdate: (data: T) => void): void;
|
|
180
|
-
unsubscribe(): void;
|
|
181
|
-
}
|
|
182
|
-
type Config = {
|
|
183
|
-
/**
|
|
184
|
-
* A custom prefix for the comment ids
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* idPrefix: "proj_a_" // Results in id="proj_a_a096e551-9822-4d10-876c-70651be36c70"
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
idPrefix?: string;
|
|
191
|
-
/**
|
|
192
|
-
* The visibility of the comment indicator
|
|
193
|
-
* @default 'always'
|
|
194
|
-
*/
|
|
195
|
-
indicatorVisibility?: "always" | "active";
|
|
196
|
-
/**
|
|
197
|
-
* Mode of the comment overlay
|
|
198
|
-
* @default "onConfirm"
|
|
199
|
-
*/
|
|
200
|
-
mode?: "onConfirm";
|
|
201
|
-
/**
|
|
202
|
-
* The visibility of the different type of comments
|
|
203
|
-
* @description This is used to temporarily hide comments of a certain type if a user whishes a cleaner view
|
|
204
|
-
* @see CommentVisibility
|
|
205
|
-
*/
|
|
206
|
-
commentVisibility?: CommentVisibility;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
type CommentType = {
|
|
210
|
-
/**
|
|
211
|
-
* The unique identifier of a comment
|
|
212
|
-
*/
|
|
213
|
-
id: string;
|
|
214
|
-
/**
|
|
215
|
-
* The postion of a comment
|
|
216
|
-
* @description the postion holds both the x and y coordinates of a comment
|
|
217
|
-
*/
|
|
218
|
-
position: Position;
|
|
219
|
-
/**
|
|
220
|
-
* The content of a comment
|
|
221
|
-
*/
|
|
222
|
-
content: string;
|
|
223
|
-
/**
|
|
224
|
-
* The user who created the comment
|
|
225
|
-
*/
|
|
226
|
-
user: User | null;
|
|
227
|
-
/**
|
|
228
|
-
* The date when the comment was created
|
|
229
|
-
*/
|
|
230
|
-
createdAt: Date;
|
|
231
|
-
/**
|
|
232
|
-
* The date when the comment was resolved
|
|
233
|
-
*/
|
|
234
|
-
resolvedAt?: Date;
|
|
235
|
-
/**
|
|
236
|
-
* The state of a comment tracking what the comment is currently doing
|
|
237
|
-
* @description This value will be omitted when sending the comment to your DB
|
|
238
|
-
*/
|
|
239
|
-
status: Status;
|
|
240
|
-
/**
|
|
241
|
-
* An indicator to show the user where the comment is located
|
|
242
|
-
* @description shows a box around the content a comment is tied to
|
|
243
|
-
*/
|
|
244
|
-
indicator?: Indicator | null;
|
|
245
|
-
/**
|
|
246
|
-
* The id of the project a comment is connected to
|
|
247
|
-
* @description useful for filtering comments by project
|
|
248
|
-
*/
|
|
249
|
-
projectId?: string | undefined;
|
|
250
|
-
};
|
|
251
|
-
type Status = "draft" | "published" | "resolving" | "resolved";
|
|
252
|
-
type ConfirmedStatus = Extract<Status, "published" | "resolved">;
|
|
253
|
-
type ConfirmedComment = Omit<CommentType, "status"> & {
|
|
254
|
-
status: ConfirmedStatus;
|
|
255
|
-
};
|
|
256
|
-
type Indicator = {
|
|
257
|
-
/**
|
|
258
|
-
* The width of the indicator
|
|
259
|
-
*/
|
|
260
|
-
width: number;
|
|
261
|
-
/**
|
|
262
|
-
* The height of the indicator
|
|
263
|
-
*/
|
|
264
|
-
height: number;
|
|
265
|
-
};
|
|
266
|
-
type Position = {
|
|
267
|
-
/**
|
|
268
|
-
* The comment position on the x axis
|
|
269
|
-
*/
|
|
270
|
-
x: number;
|
|
271
|
-
/**
|
|
272
|
-
* The comment position on the y axis
|
|
273
|
-
*/
|
|
274
|
-
y: number;
|
|
275
|
-
};
|
|
276
|
-
type User = {
|
|
277
|
-
/**
|
|
278
|
-
* The user ID. This is used to identify the user in your database.
|
|
279
|
-
* @description This is optional, but it is recommended to establish a connection to the user in your DB.
|
|
280
|
-
*/
|
|
281
|
-
id?: string;
|
|
282
|
-
/**
|
|
283
|
-
* The name of the user. This is used to display the user's name in the UI.
|
|
284
|
-
*/
|
|
285
|
-
name: string;
|
|
286
|
-
/**
|
|
287
|
-
* The avatar of the user if supported. This will fall back to user initials.
|
|
288
|
-
*/
|
|
289
|
-
avatar?: string;
|
|
290
|
-
};
|
|
291
|
-
type CommentContext = {
|
|
292
|
-
draftComments: CommentWithStatus<"draft">[];
|
|
293
|
-
comments: CommentWithStatus<"published">[];
|
|
294
|
-
resolvingComments: CommentWithStatus<"resolving">[];
|
|
295
|
-
resolvedComments: CommentWithStatus<"resolved">[];
|
|
296
|
-
allComments: CommentType[];
|
|
297
|
-
config: Config | undefined;
|
|
298
|
-
toggleResolvingComment: (id: string) => void;
|
|
299
|
-
changeOverlayState: (state: CommentOverlayState) => void;
|
|
300
|
-
overlayState: CommentOverlayState;
|
|
301
|
-
updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
|
|
302
|
-
deleteComment: (id: string) => void;
|
|
303
|
-
focusOnComment: (id: string | null) => void;
|
|
304
|
-
registerComment: (position: Position, indicatorPosition?: Indicator) => void;
|
|
305
|
-
getActiveComment: () => CommentType | undefined;
|
|
306
|
-
toggleOverlay: () => void;
|
|
307
|
-
confirmComments: () => Promise<{
|
|
308
|
-
error: Error | DOMException | null;
|
|
309
|
-
}>;
|
|
310
|
-
currentUser: User | null;
|
|
311
|
-
resolveComments: () => Promise<{
|
|
312
|
-
error: Error | DOMException | null;
|
|
313
|
-
}>;
|
|
314
|
-
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
315
|
-
triggerError: (error: KnownError) => void;
|
|
316
|
-
events: CommentEvents;
|
|
317
|
-
};
|
|
318
|
-
type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
|
|
319
|
-
status: T;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
export type { CommentType as C, Indicator as I, KnownError as K, OverlayErrorCode as O, Position as P, RealtimeSubscription as R, Status as S, User as U, CommentOverlayProps as a, CommentContext as b, CommentOverlayState as c, CommentVisibility as d, ConfirmedStatus as e, ConfirmedComment as f, CommentWithStatus as g, CommentState as h, Config as i, CommentEventMap as j, Unsubscribe as k, CommentEvents as l };
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Event map for comment-related events
|
|
5
|
-
* Each key is an event name and the value is the callback signature
|
|
6
|
-
*/
|
|
7
|
-
type CommentEventMap = {
|
|
8
|
-
/**
|
|
9
|
-
* Triggered when focus changes to a different comment
|
|
10
|
-
* @param commentId - The id of the newly focused comment, or null if unfocused
|
|
11
|
-
* @param comment - The focused comment object, or undefined if unfocused
|
|
12
|
-
*/
|
|
13
|
-
onFocusChange: (commentId: string | null, comment: CommentType | undefined) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Triggered when comments are confirmed (saved)
|
|
16
|
-
* @param comments - The comments that were confirmed
|
|
17
|
-
*/
|
|
18
|
-
onCommentsConfirmed: (comments: CommentType[]) => void;
|
|
19
|
-
/**
|
|
20
|
-
* Triggered when comments are resolved
|
|
21
|
-
* @param comments - The comments that were resolved
|
|
22
|
-
*/
|
|
23
|
-
onCommentsResolved: (comments: CommentType[]) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Triggered when a comment is deleted
|
|
26
|
-
* @param commentId - The id of the deleted comment
|
|
27
|
-
*/
|
|
28
|
-
onCommentDeleted: (commentId: string) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Triggered when a new comment is registered (draft created)
|
|
31
|
-
* @param comment - The newly registered comment
|
|
32
|
-
*/
|
|
33
|
-
onCommentRegistered: (comment: CommentType) => void;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* A function to unsubscribe from an event
|
|
37
|
-
*/
|
|
38
|
-
type Unsubscribe = () => void;
|
|
39
|
-
/**
|
|
40
|
-
* The events object exposed via useComments()
|
|
41
|
-
* Each method accepts a callback and returns an unsubscribe function
|
|
42
|
-
*/
|
|
43
|
-
type CommentEvents = {
|
|
44
|
-
[K in keyof CommentEventMap]: (callback: CommentEventMap[K]) => Unsubscribe;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
declare class BaseError extends Error {
|
|
48
|
-
code: OverlayErrorCode;
|
|
49
|
-
status: number;
|
|
50
|
-
constructor(message: string, code?: OverlayErrorCode, status?: number);
|
|
51
|
-
}
|
|
52
|
-
declare class ResolveError extends BaseError {
|
|
53
|
-
constructor(message?: string);
|
|
54
|
-
}
|
|
55
|
-
declare class ConfirmError extends BaseError {
|
|
56
|
-
constructor(message?: string);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR";
|
|
60
|
-
type KnownError = ConfirmError | ResolveError;
|
|
61
|
-
|
|
62
|
-
type CommentState = {
|
|
63
|
-
/**
|
|
64
|
-
* All confirmed comments
|
|
65
|
-
* @description This is used to track all confirmed comments
|
|
66
|
-
*/
|
|
67
|
-
comments: CommentType[];
|
|
68
|
-
/**
|
|
69
|
-
* The state of the comment overlay
|
|
70
|
-
* @description This value is used to track the state of the comment overlay
|
|
71
|
-
* @see CommentOverlayState
|
|
72
|
-
*/
|
|
73
|
-
overlayState: CommentOverlayState;
|
|
74
|
-
/**
|
|
75
|
-
* The current loged in user.
|
|
76
|
-
* @description This data will be included when a user adds a comment
|
|
77
|
-
*/
|
|
78
|
-
currentUser: User | null;
|
|
79
|
-
/**
|
|
80
|
-
* Track the focussed comment when editing or adding a comment
|
|
81
|
-
* The comment key will be stored in this state
|
|
82
|
-
*/
|
|
83
|
-
focussedComment: string | null;
|
|
84
|
-
/**
|
|
85
|
-
* Any error that occurs during comment operations
|
|
86
|
-
* The value can be used to display an error message to the user
|
|
87
|
-
*/
|
|
88
|
-
error?: Error;
|
|
89
|
-
/**
|
|
90
|
-
* Optional configuration for the comment layer
|
|
91
|
-
*/
|
|
92
|
-
config?: Config | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Attached a project ID to the current overlay
|
|
95
|
-
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
96
|
-
*/
|
|
97
|
-
projectId?: string | undefined;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* The state of the comment overlay
|
|
101
|
-
* @description This is used to track the state of the comment overlay
|
|
102
|
-
*/
|
|
103
|
-
type CommentOverlayState = "idle" | "editing" | "saving" | "resolving" | "inactive";
|
|
104
|
-
type CommentVisibility = {
|
|
105
|
-
/**
|
|
106
|
-
* Hide comments that are marked as resolved
|
|
107
|
-
* @default false
|
|
108
|
-
*/
|
|
109
|
-
hideResolved?: boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Hide comments that are being resolved
|
|
112
|
-
* @default false
|
|
113
|
-
*/
|
|
114
|
-
hideResolving?: boolean;
|
|
115
|
-
};
|
|
116
|
-
type CommentOverlayProps = {
|
|
117
|
-
/**
|
|
118
|
-
* Initial comments present when opening the comment overlay
|
|
119
|
-
* @description These comments usually come from your database
|
|
120
|
-
*/
|
|
121
|
-
initialComments?: ConfirmedComment[];
|
|
122
|
-
/**
|
|
123
|
-
* The current user
|
|
124
|
-
*
|
|
125
|
-
* @description This is used to identify the user in your database. If you can not provide a user, comments will be added anonymously
|
|
126
|
-
* @default null
|
|
127
|
-
*/
|
|
128
|
-
currentUser: User | null;
|
|
129
|
-
/**
|
|
130
|
-
* The children of the comment overlay
|
|
131
|
-
* @description This is where the comments will be rendered
|
|
132
|
-
*/
|
|
133
|
-
children: ReactNode;
|
|
134
|
-
/**
|
|
135
|
-
* The state of the overlay on initial render
|
|
136
|
-
* @default "inactive"
|
|
137
|
-
*/
|
|
138
|
-
initialOverlayState?: CommentOverlayState;
|
|
139
|
-
/**
|
|
140
|
-
* Realtime subscription if supported by you DB
|
|
141
|
-
* @description You can use this feature with a realtime DB or a websocket
|
|
142
|
-
* @beta this featue is not yet fully tested and is subject to change
|
|
143
|
-
*/
|
|
144
|
-
subscription?: RealtimeSubscription<CommentType>;
|
|
145
|
-
/**
|
|
146
|
-
* Callback with all newly confirmed comments
|
|
147
|
-
*
|
|
148
|
-
* @param comments as the comments pushed by the user
|
|
149
|
-
* @param projectId as the project id if provided
|
|
150
|
-
*/
|
|
151
|
-
onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Callback to handle resolved comments
|
|
154
|
-
*
|
|
155
|
-
* @param comments as the comments that are marked as resolved
|
|
156
|
-
*/
|
|
157
|
-
onResolve: (comments: ConfirmedComment[]) => Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Callback to handle errors
|
|
160
|
-
*
|
|
161
|
-
* @param error as the error that occurred
|
|
162
|
-
*/
|
|
163
|
-
onError: (error: KnownError) => void;
|
|
164
|
-
/**
|
|
165
|
-
* Optional configuration for the comment layer
|
|
166
|
-
*/
|
|
167
|
-
config?: Config;
|
|
168
|
-
/**
|
|
169
|
-
* Attached a project ID to the current overlay
|
|
170
|
-
* @description This ID will be passed to the comment actions. You can attach comments to a project by storing this ID in your database
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* projectId: "proj_123456789"
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
projectId?: string;
|
|
177
|
-
};
|
|
178
|
-
interface RealtimeSubscription<T> {
|
|
179
|
-
subscribe(onUpdate: (data: T) => void): void;
|
|
180
|
-
unsubscribe(): void;
|
|
181
|
-
}
|
|
182
|
-
type Config = {
|
|
183
|
-
/**
|
|
184
|
-
* A custom prefix for the comment ids
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* idPrefix: "proj_a_" // Results in id="proj_a_a096e551-9822-4d10-876c-70651be36c70"
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
idPrefix?: string;
|
|
191
|
-
/**
|
|
192
|
-
* The visibility of the comment indicator
|
|
193
|
-
* @default 'always'
|
|
194
|
-
*/
|
|
195
|
-
indicatorVisibility?: "always" | "active";
|
|
196
|
-
/**
|
|
197
|
-
* Mode of the comment overlay
|
|
198
|
-
* @default "onConfirm"
|
|
199
|
-
*/
|
|
200
|
-
mode?: "onConfirm";
|
|
201
|
-
/**
|
|
202
|
-
* The visibility of the different type of comments
|
|
203
|
-
* @description This is used to temporarily hide comments of a certain type if a user whishes a cleaner view
|
|
204
|
-
* @see CommentVisibility
|
|
205
|
-
*/
|
|
206
|
-
commentVisibility?: CommentVisibility;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
type CommentType = {
|
|
210
|
-
/**
|
|
211
|
-
* The unique identifier of a comment
|
|
212
|
-
*/
|
|
213
|
-
id: string;
|
|
214
|
-
/**
|
|
215
|
-
* The postion of a comment
|
|
216
|
-
* @description the postion holds both the x and y coordinates of a comment
|
|
217
|
-
*/
|
|
218
|
-
position: Position;
|
|
219
|
-
/**
|
|
220
|
-
* The content of a comment
|
|
221
|
-
*/
|
|
222
|
-
content: string;
|
|
223
|
-
/**
|
|
224
|
-
* The user who created the comment
|
|
225
|
-
*/
|
|
226
|
-
user: User | null;
|
|
227
|
-
/**
|
|
228
|
-
* The date when the comment was created
|
|
229
|
-
*/
|
|
230
|
-
createdAt: Date;
|
|
231
|
-
/**
|
|
232
|
-
* The date when the comment was resolved
|
|
233
|
-
*/
|
|
234
|
-
resolvedAt?: Date;
|
|
235
|
-
/**
|
|
236
|
-
* The state of a comment tracking what the comment is currently doing
|
|
237
|
-
* @description This value will be omitted when sending the comment to your DB
|
|
238
|
-
*/
|
|
239
|
-
status: Status;
|
|
240
|
-
/**
|
|
241
|
-
* An indicator to show the user where the comment is located
|
|
242
|
-
* @description shows a box around the content a comment is tied to
|
|
243
|
-
*/
|
|
244
|
-
indicator?: Indicator | null;
|
|
245
|
-
/**
|
|
246
|
-
* The id of the project a comment is connected to
|
|
247
|
-
* @description useful for filtering comments by project
|
|
248
|
-
*/
|
|
249
|
-
projectId?: string | undefined;
|
|
250
|
-
};
|
|
251
|
-
type Status = "draft" | "published" | "resolving" | "resolved";
|
|
252
|
-
type ConfirmedStatus = Extract<Status, "published" | "resolved">;
|
|
253
|
-
type ConfirmedComment = Omit<CommentType, "status"> & {
|
|
254
|
-
status: ConfirmedStatus;
|
|
255
|
-
};
|
|
256
|
-
type Indicator = {
|
|
257
|
-
/**
|
|
258
|
-
* The width of the indicator
|
|
259
|
-
*/
|
|
260
|
-
width: number;
|
|
261
|
-
/**
|
|
262
|
-
* The height of the indicator
|
|
263
|
-
*/
|
|
264
|
-
height: number;
|
|
265
|
-
};
|
|
266
|
-
type Position = {
|
|
267
|
-
/**
|
|
268
|
-
* The comment position on the x axis
|
|
269
|
-
*/
|
|
270
|
-
x: number;
|
|
271
|
-
/**
|
|
272
|
-
* The comment position on the y axis
|
|
273
|
-
*/
|
|
274
|
-
y: number;
|
|
275
|
-
};
|
|
276
|
-
type User = {
|
|
277
|
-
/**
|
|
278
|
-
* The user ID. This is used to identify the user in your database.
|
|
279
|
-
* @description This is optional, but it is recommended to establish a connection to the user in your DB.
|
|
280
|
-
*/
|
|
281
|
-
id?: string;
|
|
282
|
-
/**
|
|
283
|
-
* The name of the user. This is used to display the user's name in the UI.
|
|
284
|
-
*/
|
|
285
|
-
name: string;
|
|
286
|
-
/**
|
|
287
|
-
* The avatar of the user if supported. This will fall back to user initials.
|
|
288
|
-
*/
|
|
289
|
-
avatar?: string;
|
|
290
|
-
};
|
|
291
|
-
type CommentContext = {
|
|
292
|
-
draftComments: CommentWithStatus<"draft">[];
|
|
293
|
-
comments: CommentWithStatus<"published">[];
|
|
294
|
-
resolvingComments: CommentWithStatus<"resolving">[];
|
|
295
|
-
resolvedComments: CommentWithStatus<"resolved">[];
|
|
296
|
-
allComments: CommentType[];
|
|
297
|
-
config: Config | undefined;
|
|
298
|
-
toggleResolvingComment: (id: string) => void;
|
|
299
|
-
changeOverlayState: (state: CommentOverlayState) => void;
|
|
300
|
-
overlayState: CommentOverlayState;
|
|
301
|
-
updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
|
|
302
|
-
deleteComment: (id: string) => void;
|
|
303
|
-
focusOnComment: (id: string | null) => void;
|
|
304
|
-
registerComment: (position: Position, indicatorPosition?: Indicator) => void;
|
|
305
|
-
getActiveComment: () => CommentType | undefined;
|
|
306
|
-
toggleOverlay: () => void;
|
|
307
|
-
confirmComments: () => Promise<{
|
|
308
|
-
error: Error | DOMException | null;
|
|
309
|
-
}>;
|
|
310
|
-
currentUser: User | null;
|
|
311
|
-
resolveComments: () => Promise<{
|
|
312
|
-
error: Error | DOMException | null;
|
|
313
|
-
}>;
|
|
314
|
-
updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
|
|
315
|
-
triggerError: (error: KnownError) => void;
|
|
316
|
-
events: CommentEvents;
|
|
317
|
-
};
|
|
318
|
-
type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
|
|
319
|
-
status: T;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
export type { CommentType as C, Indicator as I, KnownError as K, OverlayErrorCode as O, Position as P, RealtimeSubscription as R, Status as S, User as U, CommentOverlayProps as a, CommentContext as b, CommentOverlayState as c, CommentVisibility as d, ConfirmedStatus as e, ConfirmedComment as f, CommentWithStatus as g, CommentState as h, Config as i, CommentEventMap as j, Unsubscribe as k, CommentEvents as l };
|