@kendew-agency/react-feedback-layer 0.3.1 → 0.4.0-rc.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/dist/types.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-C0m3sQ_Q.cjs';
2
- export { b as CommentContext, j as CommentEventMap, l as CommentEvents, a as CommentOverlayProps, h as CommentState, g as CommentWithStatus, i as Config, f as ConfirmedComment, e as ConfirmedStatus, K as KnownError, O as OverlayErrorCode, R as RealtimeSubscription, S as Status, k as Unsubscribe, U as User } from './comment.types-C0m3sQ_Q.cjs';
1
+ import { C as CommentType, P as Position, g as Indicator, h as CommentOverlayState, i as CommentVisibility } from './use-session-events-DFksOgVA.cjs';
2
+ export { A as ActiveFeedbackSession, b as CommentContext, p as CommentEventMap, r as CommentEvents, a as CommentOverlayProps, n as CommentState, m as CommentWithStatus, o as Config, l as ConfirmedComment, k as ConfirmedStatus, c as CreateSessionInput, D as DraftVisibility, F as FeedbackSession, I as InitialFeedbackSession, K as KnownError, O as OverlayErrorCode, R as RealtimeSubscription, t as SessionEventMap, e as SessionEvents, d as SessionOperationState, s as SessionStatus, S as SessionType, j as Status, q as Unsubscribe, U as User, u as UserContextType, f as UserProviderProps } from './use-session-events-DFksOgVA.cjs';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -20,6 +20,7 @@ type CommentAction = {
20
20
  newComment: Partial<CommentType>;
21
21
  } | {
22
22
  type: "REGISTER";
23
+ sessionId: string;
23
24
  position: Position;
24
25
  indicatorPosition?: Indicator | null;
25
26
  } | {
@@ -31,9 +32,9 @@ type CommentAction = {
31
32
  type: "CHANGE_OVERLAYSTATE";
32
33
  to: CommentOverlayState;
33
34
  } | {
34
- type: "RESET_DRAFT_COMMENTS";
35
- } | {
36
- type: "RESET_RESOLVING_COMMENTS";
35
+ type: "REPLACE_COMMENT";
36
+ id: string;
37
+ comment: CommentType;
37
38
  } | {
38
39
  type: "UPDATE_VISIBILITY";
39
40
  visibility: Partial<CommentVisibility>;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CommentType, P as Position, I as Indicator, c as CommentOverlayState, d as CommentVisibility } from './comment.types-C0m3sQ_Q.js';
2
- export { b as CommentContext, j as CommentEventMap, l as CommentEvents, a as CommentOverlayProps, h as CommentState, g as CommentWithStatus, i as Config, f as ConfirmedComment, e as ConfirmedStatus, K as KnownError, O as OverlayErrorCode, R as RealtimeSubscription, S as Status, k as Unsubscribe, U as User } from './comment.types-C0m3sQ_Q.js';
1
+ import { C as CommentType, P as Position, g as Indicator, h as CommentOverlayState, i as CommentVisibility } from './use-session-events-DFksOgVA.js';
2
+ export { A as ActiveFeedbackSession, b as CommentContext, p as CommentEventMap, r as CommentEvents, a as CommentOverlayProps, n as CommentState, m as CommentWithStatus, o as Config, l as ConfirmedComment, k as ConfirmedStatus, c as CreateSessionInput, D as DraftVisibility, F as FeedbackSession, I as InitialFeedbackSession, K as KnownError, O as OverlayErrorCode, R as RealtimeSubscription, t as SessionEventMap, e as SessionEvents, d as SessionOperationState, s as SessionStatus, S as SessionType, j as Status, q as Unsubscribe, U as User, u as UserContextType, f as UserProviderProps } from './use-session-events-DFksOgVA.js';
3
3
  import 'react';
4
4
 
5
5
  /**
@@ -20,6 +20,7 @@ type CommentAction = {
20
20
  newComment: Partial<CommentType>;
21
21
  } | {
22
22
  type: "REGISTER";
23
+ sessionId: string;
23
24
  position: Position;
24
25
  indicatorPosition?: Indicator | null;
25
26
  } | {
@@ -31,9 +32,9 @@ type CommentAction = {
31
32
  type: "CHANGE_OVERLAYSTATE";
32
33
  to: CommentOverlayState;
33
34
  } | {
34
- type: "RESET_DRAFT_COMMENTS";
35
- } | {
36
- type: "RESET_RESOLVING_COMMENTS";
35
+ type: "REPLACE_COMMENT";
36
+ id: string;
37
+ comment: CommentType;
37
38
  } | {
38
39
  type: "UPDATE_VISIBILITY";
39
40
  visibility: Partial<CommentVisibility>;
@@ -12,15 +12,21 @@ type CommentEventMap = {
12
12
  */
13
13
  onFocusChange: (commentId: string | null, comment: CommentType | undefined) => void;
14
14
  /**
15
- * Triggered when comments are confirmed (saved)
16
- * @param comments - The comments that were confirmed
15
+ * Triggered when a comment was persisted through onAdd
17
16
  */
18
- onCommentsConfirmed: (comments: CommentType[]) => void;
17
+ onCommentAdded: (comment: CommentType) => void;
19
18
  /**
20
- * Triggered when comments are resolved
21
- * @param comments - The comments that were resolved
19
+ * Triggered when a comment was persisted through onEdit
22
20
  */
23
- onCommentsResolved: (comments: CommentType[]) => void;
21
+ onCommentEdited: (comment: CommentType) => void;
22
+ /**
23
+ * Triggered when a comment was resolved
24
+ */
25
+ onCommentResolved: (comment: CommentType) => void;
26
+ /**
27
+ * Triggered when a resolved comment was reopened
28
+ */
29
+ onCommentReopened: (comment: CommentType) => void;
24
30
  /**
25
31
  * Triggered when a comment is deleted
26
32
  * @param commentId - The id of the deleted comment
@@ -49,15 +55,45 @@ declare class BaseError extends Error {
49
55
  status: number;
50
56
  constructor(message: string, code?: OverlayErrorCode, status?: number);
51
57
  }
58
+ /** Error for resolving a single comment (`onResolve`). */
52
59
  declare class ResolveError extends BaseError {
53
60
  constructor(message?: string);
54
61
  }
62
+ /** Session confirmation error (`onConfirm`). */
55
63
  declare class ConfirmError extends BaseError {
56
64
  constructor(message?: string);
57
65
  }
66
+ declare class SessionCreateError extends BaseError {
67
+ constructor(message?: string);
68
+ }
69
+ declare class AddError extends BaseError {
70
+ constructor(message?: string);
71
+ }
72
+ declare class EditError extends BaseError {
73
+ constructor(message?: string);
74
+ }
75
+ declare class DeleteError extends BaseError {
76
+ constructor(message?: string);
77
+ }
78
+ declare class SessionStateError extends BaseError {
79
+ constructor(message?: string);
80
+ }
81
+ declare class ReopenError extends BaseError {
82
+ constructor(message?: string);
83
+ }
84
+ declare class StartResolvingError extends BaseError {
85
+ constructor(message?: string);
86
+ }
87
+ /** Error for resolving a session (`onResolveSession`). */
88
+ declare class SessionResolveError extends BaseError {
89
+ constructor(message?: string);
90
+ }
91
+ declare class PermissionError extends BaseError {
92
+ constructor(message?: string);
93
+ }
58
94
 
59
- type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR";
60
- type KnownError = ConfirmError | ResolveError;
95
+ type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR" | "SESSION_CREATE_ERROR" | "ADD_ERROR" | "EDIT_ERROR" | "DELETE_ERROR" | "SESSION_STATE_ERROR" | "REOPEN_ERROR" | "START_RESOLVING_ERROR" | "SESSION_RESOLVE_ERROR" | "PERMISSION_ERROR";
96
+ type KnownError = ConfirmError | ResolveError | SessionCreateError | AddError | EditError | DeleteError | SessionStateError | ReopenError | StartResolvingError | SessionResolveError | PermissionError;
61
97
 
62
98
  type CommentState = {
63
99
  /**
@@ -107,12 +143,11 @@ type CommentVisibility = {
107
143
  * @default false
108
144
  */
109
145
  hideResolved?: boolean;
110
- /**
111
- * Hide comments that are being resolved
112
- * @default false
113
- */
114
- hideResolving?: boolean;
115
146
  };
147
+ /**
148
+ * Whether persisted comments of other users are shown in a draft session
149
+ */
150
+ type DraftVisibility = "hidden" | "visible";
116
151
  type CommentOverlayProps = {
117
152
  /**
118
153
  * Initial comments present when opening the comment overlay
@@ -125,7 +160,7 @@ type CommentOverlayProps = {
125
160
  * @description This is used to identify the user in your database. If you can not provide a user, comments will be added anonymously
126
161
  * @default null
127
162
  */
128
- currentUser: User | null;
163
+ currentUser?: User | null;
129
164
  /**
130
165
  * The children of the comment overlay
131
166
  * @description This is where the comments will be rendered
@@ -143,24 +178,31 @@ type CommentOverlayProps = {
143
178
  */
144
179
  subscription?: RealtimeSubscription<CommentType>;
145
180
  /**
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
181
+ * Callback to persist a newly added comment
150
182
  */
151
- onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
183
+ onAdd?: (comment: ConfirmedComment) => Promise<void>;
152
184
  /**
153
- * Callback to handle resolved comments
154
- *
155
- * @param comments as the comments that are marked as resolved
185
+ * Callback to persist an edited comment
186
+ */
187
+ onEdit?: (comment: ConfirmedComment) => Promise<void>;
188
+ /**
189
+ * Callback to persist a resolved comment
190
+ */
191
+ onResolve?: (comment: ConfirmedComment) => Promise<void>;
192
+ /**
193
+ * Callback to persist a reopened comment
194
+ */
195
+ onReopen?: (comment: ConfirmedComment) => Promise<void>;
196
+ /**
197
+ * Callback to delete a persisted comment
156
198
  */
157
- onResolve: (comments: ConfirmedComment[]) => Promise<void>;
199
+ onDelete?: (commentId: string) => Promise<void>;
158
200
  /**
159
201
  * Callback to handle errors
160
202
  *
161
203
  * @param error as the error that occurred
162
204
  */
163
- onError: (error: KnownError) => void;
205
+ onError?: (error: KnownError) => void;
164
206
  /**
165
207
  * Optional configuration for the comment layer
166
208
  */
@@ -204,6 +246,11 @@ type Config = {
204
246
  * @see CommentVisibility
205
247
  */
206
248
  commentVisibility?: CommentVisibility;
249
+ /**
250
+ * Whether persisted comments of other users are shown while the session is a draft
251
+ * @default "visible"
252
+ */
253
+ draftVisibility?: DraftVisibility;
207
254
  };
208
255
 
209
256
  type CommentType = {
@@ -242,13 +289,17 @@ type CommentType = {
242
289
  * @description shows a box around the content a comment is tied to
243
290
  */
244
291
  indicator?: Indicator | null;
292
+ /**
293
+ * The id of the feedback session a comment belongs to
294
+ */
295
+ sessionId: string;
245
296
  /**
246
297
  * The id of the project a comment is connected to
247
298
  * @description useful for filtering comments by project
248
299
  */
249
300
  projectId?: string | undefined;
250
301
  };
251
- type Status = "draft" | "published" | "resolving" | "resolved";
302
+ type Status = "draft" | "published" | "resolved";
252
303
  type ConfirmedStatus = Extract<Status, "published" | "resolved">;
253
304
  type ConfirmedComment = Omit<CommentType, "status"> & {
254
305
  status: ConfirmedStatus;
@@ -291,26 +342,38 @@ type User = {
291
342
  type CommentContext = {
292
343
  draftComments: CommentWithStatus<"draft">[];
293
344
  comments: CommentWithStatus<"published">[];
294
- resolvingComments: CommentWithStatus<"resolving">[];
295
345
  resolvedComments: CommentWithStatus<"resolved">[];
296
346
  allComments: CommentType[];
297
347
  config: Config | undefined;
298
- toggleResolvingComment: (id: string) => void;
299
348
  changeOverlayState: (state: CommentOverlayState) => void;
300
349
  overlayState: CommentOverlayState;
301
- updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
302
- deleteComment: (id: string) => void;
350
+ updateComment: (id: string, newComment: Pick<CommentType, "content">) => Promise<{
351
+ error: KnownError | null;
352
+ }>;
353
+ deleteComment: (id: string) => Promise<{
354
+ error: KnownError | null;
355
+ }>;
303
356
  focusOnComment: (id: string | null) => void;
304
357
  registerComment: (position: Position, indicatorPosition?: Indicator) => void;
305
358
  getActiveComment: () => CommentType | undefined;
306
359
  toggleOverlay: () => void;
307
- confirmComments: () => Promise<{
308
- error: Error | DOMException | null;
309
- }>;
310
360
  currentUser: User | null;
311
- resolveComments: () => Promise<{
312
- error: Error | DOMException | null;
361
+ /**
362
+ * Resolve a published comment. Requires a resolving session and permission
363
+ */
364
+ resolveComment: (id: string) => Promise<{
365
+ error: KnownError | null;
366
+ }>;
367
+ /**
368
+ * Reopen a resolved comment. Requires a resolving session and permission
369
+ */
370
+ reopenComment: (id: string) => Promise<{
371
+ error: KnownError | null;
313
372
  }>;
373
+ /**
374
+ * Mirrors the `canResolveSession` prop of the session provider
375
+ */
376
+ canResolve: boolean;
314
377
  updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
315
378
  triggerError: (error: KnownError) => void;
316
379
  events: CommentEvents;
@@ -319,4 +382,83 @@ type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
319
382
  status: T;
320
383
  };
321
384
 
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 };
385
+ /**
386
+ * Discriminator for the kind of session.
387
+ * Adding "rework" later is a change to this union only.
388
+ */
389
+ type SessionType = "feedback";
390
+ type SessionStatus = "draft" | "confirmed" | "resolving" | "resolved";
391
+ /**
392
+ * The pending operation of the session provider
393
+ */
394
+ type SessionOperationState = "idle" | "creating" | "confirming" | "startingResolution" | "completingResolution";
395
+ type FeedbackSession = {
396
+ id: string;
397
+ type: SessionType;
398
+ status: SessionStatus;
399
+ createdAt: Date;
400
+ /** The id of the user who created the session, never a user object */
401
+ createdBy: string;
402
+ /** Ids of the users that took part in the session. May be empty */
403
+ participantIds: string[];
404
+ confirmedAt?: Date;
405
+ resolvedAt?: Date;
406
+ projectId?: string | undefined;
407
+ /** Reserved for a future rework session. No behavior depends on it. */
408
+ sourceSessionId?: string | undefined;
409
+ };
410
+ /**
411
+ * The session as held by the provider, with its persisted comments
412
+ */
413
+ type ActiveFeedbackSession = FeedbackSession & {
414
+ comments: ConfirmedComment[];
415
+ };
416
+ /**
417
+ * Accepted by `initialSession`. `comments` is optional for convenience
418
+ */
419
+ type InitialFeedbackSession = FeedbackSession & {
420
+ comments?: ConfirmedComment[];
421
+ };
422
+ /**
423
+ * Input passed to `onCreateSession`
424
+ */
425
+ type CreateSessionInput = {
426
+ type: SessionType;
427
+ user: User | null;
428
+ projectId?: string | undefined;
429
+ };
430
+ /**
431
+ * Event map for session-related events
432
+ */
433
+ type SessionEventMap = {
434
+ /** Triggered when a new draft session was created */
435
+ onSessionCreated: (session: ActiveFeedbackSession) => void;
436
+ /** Triggered when the session was confirmed */
437
+ onSessionConfirmed: (session: ActiveFeedbackSession) => void;
438
+ /** Triggered when the session moved to resolving */
439
+ onSessionResolving: (session: ActiveFeedbackSession) => void;
440
+ /** Triggered when the session was resolved */
441
+ onSessionResolved: (session: ActiveFeedbackSession) => void;
442
+ };
443
+
444
+ type UserProviderProps = {
445
+ /** The current user, or null when nobody is signed in */
446
+ user: User | null;
447
+ children: ReactNode;
448
+ };
449
+ /**
450
+ * Value held by the user context
451
+ */
452
+ type UserContextType = {
453
+ currentUser: User | null;
454
+ };
455
+
456
+ /**
457
+ * The session events object exposed via useSession()
458
+ * Each method accepts a callback and returns an unsubscribe function
459
+ */
460
+ type SessionEvents = {
461
+ [K in keyof SessionEventMap]: (callback: SessionEventMap[K]) => Unsubscribe;
462
+ };
463
+
464
+ export type { ActiveFeedbackSession as A, CommentType as C, DraftVisibility as D, FeedbackSession as F, InitialFeedbackSession as I, KnownError as K, OverlayErrorCode as O, Position as P, RealtimeSubscription as R, SessionType as S, User as U, CommentOverlayProps as a, CommentContext as b, CreateSessionInput as c, SessionOperationState as d, SessionEvents as e, UserProviderProps as f, Indicator as g, CommentOverlayState as h, CommentVisibility as i, Status as j, ConfirmedStatus as k, ConfirmedComment as l, CommentWithStatus as m, CommentState as n, Config as o, CommentEventMap as p, Unsubscribe as q, CommentEvents as r, SessionStatus as s, SessionEventMap as t, UserContextType as u };
@@ -12,15 +12,21 @@ type CommentEventMap = {
12
12
  */
13
13
  onFocusChange: (commentId: string | null, comment: CommentType | undefined) => void;
14
14
  /**
15
- * Triggered when comments are confirmed (saved)
16
- * @param comments - The comments that were confirmed
15
+ * Triggered when a comment was persisted through onAdd
17
16
  */
18
- onCommentsConfirmed: (comments: CommentType[]) => void;
17
+ onCommentAdded: (comment: CommentType) => void;
19
18
  /**
20
- * Triggered when comments are resolved
21
- * @param comments - The comments that were resolved
19
+ * Triggered when a comment was persisted through onEdit
22
20
  */
23
- onCommentsResolved: (comments: CommentType[]) => void;
21
+ onCommentEdited: (comment: CommentType) => void;
22
+ /**
23
+ * Triggered when a comment was resolved
24
+ */
25
+ onCommentResolved: (comment: CommentType) => void;
26
+ /**
27
+ * Triggered when a resolved comment was reopened
28
+ */
29
+ onCommentReopened: (comment: CommentType) => void;
24
30
  /**
25
31
  * Triggered when a comment is deleted
26
32
  * @param commentId - The id of the deleted comment
@@ -49,15 +55,45 @@ declare class BaseError extends Error {
49
55
  status: number;
50
56
  constructor(message: string, code?: OverlayErrorCode, status?: number);
51
57
  }
58
+ /** Error for resolving a single comment (`onResolve`). */
52
59
  declare class ResolveError extends BaseError {
53
60
  constructor(message?: string);
54
61
  }
62
+ /** Session confirmation error (`onConfirm`). */
55
63
  declare class ConfirmError extends BaseError {
56
64
  constructor(message?: string);
57
65
  }
66
+ declare class SessionCreateError extends BaseError {
67
+ constructor(message?: string);
68
+ }
69
+ declare class AddError extends BaseError {
70
+ constructor(message?: string);
71
+ }
72
+ declare class EditError extends BaseError {
73
+ constructor(message?: string);
74
+ }
75
+ declare class DeleteError extends BaseError {
76
+ constructor(message?: string);
77
+ }
78
+ declare class SessionStateError extends BaseError {
79
+ constructor(message?: string);
80
+ }
81
+ declare class ReopenError extends BaseError {
82
+ constructor(message?: string);
83
+ }
84
+ declare class StartResolvingError extends BaseError {
85
+ constructor(message?: string);
86
+ }
87
+ /** Error for resolving a session (`onResolveSession`). */
88
+ declare class SessionResolveError extends BaseError {
89
+ constructor(message?: string);
90
+ }
91
+ declare class PermissionError extends BaseError {
92
+ constructor(message?: string);
93
+ }
58
94
 
59
- type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR";
60
- type KnownError = ConfirmError | ResolveError;
95
+ type OverlayErrorCode = "RESOLVE_ERROR" | "CONFIRM_ERROR" | "UNKNOWN_ERROR" | "INSERT_ERROR" | "SESSION_CREATE_ERROR" | "ADD_ERROR" | "EDIT_ERROR" | "DELETE_ERROR" | "SESSION_STATE_ERROR" | "REOPEN_ERROR" | "START_RESOLVING_ERROR" | "SESSION_RESOLVE_ERROR" | "PERMISSION_ERROR";
96
+ type KnownError = ConfirmError | ResolveError | SessionCreateError | AddError | EditError | DeleteError | SessionStateError | ReopenError | StartResolvingError | SessionResolveError | PermissionError;
61
97
 
62
98
  type CommentState = {
63
99
  /**
@@ -107,12 +143,11 @@ type CommentVisibility = {
107
143
  * @default false
108
144
  */
109
145
  hideResolved?: boolean;
110
- /**
111
- * Hide comments that are being resolved
112
- * @default false
113
- */
114
- hideResolving?: boolean;
115
146
  };
147
+ /**
148
+ * Whether persisted comments of other users are shown in a draft session
149
+ */
150
+ type DraftVisibility = "hidden" | "visible";
116
151
  type CommentOverlayProps = {
117
152
  /**
118
153
  * Initial comments present when opening the comment overlay
@@ -125,7 +160,7 @@ type CommentOverlayProps = {
125
160
  * @description This is used to identify the user in your database. If you can not provide a user, comments will be added anonymously
126
161
  * @default null
127
162
  */
128
- currentUser: User | null;
163
+ currentUser?: User | null;
129
164
  /**
130
165
  * The children of the comment overlay
131
166
  * @description This is where the comments will be rendered
@@ -143,24 +178,31 @@ type CommentOverlayProps = {
143
178
  */
144
179
  subscription?: RealtimeSubscription<CommentType>;
145
180
  /**
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
181
+ * Callback to persist a newly added comment
150
182
  */
151
- onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
183
+ onAdd?: (comment: ConfirmedComment) => Promise<void>;
152
184
  /**
153
- * Callback to handle resolved comments
154
- *
155
- * @param comments as the comments that are marked as resolved
185
+ * Callback to persist an edited comment
186
+ */
187
+ onEdit?: (comment: ConfirmedComment) => Promise<void>;
188
+ /**
189
+ * Callback to persist a resolved comment
190
+ */
191
+ onResolve?: (comment: ConfirmedComment) => Promise<void>;
192
+ /**
193
+ * Callback to persist a reopened comment
194
+ */
195
+ onReopen?: (comment: ConfirmedComment) => Promise<void>;
196
+ /**
197
+ * Callback to delete a persisted comment
156
198
  */
157
- onResolve: (comments: ConfirmedComment[]) => Promise<void>;
199
+ onDelete?: (commentId: string) => Promise<void>;
158
200
  /**
159
201
  * Callback to handle errors
160
202
  *
161
203
  * @param error as the error that occurred
162
204
  */
163
- onError: (error: KnownError) => void;
205
+ onError?: (error: KnownError) => void;
164
206
  /**
165
207
  * Optional configuration for the comment layer
166
208
  */
@@ -204,6 +246,11 @@ type Config = {
204
246
  * @see CommentVisibility
205
247
  */
206
248
  commentVisibility?: CommentVisibility;
249
+ /**
250
+ * Whether persisted comments of other users are shown while the session is a draft
251
+ * @default "visible"
252
+ */
253
+ draftVisibility?: DraftVisibility;
207
254
  };
208
255
 
209
256
  type CommentType = {
@@ -242,13 +289,17 @@ type CommentType = {
242
289
  * @description shows a box around the content a comment is tied to
243
290
  */
244
291
  indicator?: Indicator | null;
292
+ /**
293
+ * The id of the feedback session a comment belongs to
294
+ */
295
+ sessionId: string;
245
296
  /**
246
297
  * The id of the project a comment is connected to
247
298
  * @description useful for filtering comments by project
248
299
  */
249
300
  projectId?: string | undefined;
250
301
  };
251
- type Status = "draft" | "published" | "resolving" | "resolved";
302
+ type Status = "draft" | "published" | "resolved";
252
303
  type ConfirmedStatus = Extract<Status, "published" | "resolved">;
253
304
  type ConfirmedComment = Omit<CommentType, "status"> & {
254
305
  status: ConfirmedStatus;
@@ -291,26 +342,38 @@ type User = {
291
342
  type CommentContext = {
292
343
  draftComments: CommentWithStatus<"draft">[];
293
344
  comments: CommentWithStatus<"published">[];
294
- resolvingComments: CommentWithStatus<"resolving">[];
295
345
  resolvedComments: CommentWithStatus<"resolved">[];
296
346
  allComments: CommentType[];
297
347
  config: Config | undefined;
298
- toggleResolvingComment: (id: string) => void;
299
348
  changeOverlayState: (state: CommentOverlayState) => void;
300
349
  overlayState: CommentOverlayState;
301
- updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
302
- deleteComment: (id: string) => void;
350
+ updateComment: (id: string, newComment: Pick<CommentType, "content">) => Promise<{
351
+ error: KnownError | null;
352
+ }>;
353
+ deleteComment: (id: string) => Promise<{
354
+ error: KnownError | null;
355
+ }>;
303
356
  focusOnComment: (id: string | null) => void;
304
357
  registerComment: (position: Position, indicatorPosition?: Indicator) => void;
305
358
  getActiveComment: () => CommentType | undefined;
306
359
  toggleOverlay: () => void;
307
- confirmComments: () => Promise<{
308
- error: Error | DOMException | null;
309
- }>;
310
360
  currentUser: User | null;
311
- resolveComments: () => Promise<{
312
- error: Error | DOMException | null;
361
+ /**
362
+ * Resolve a published comment. Requires a resolving session and permission
363
+ */
364
+ resolveComment: (id: string) => Promise<{
365
+ error: KnownError | null;
366
+ }>;
367
+ /**
368
+ * Reopen a resolved comment. Requires a resolving session and permission
369
+ */
370
+ reopenComment: (id: string) => Promise<{
371
+ error: KnownError | null;
313
372
  }>;
373
+ /**
374
+ * Mirrors the `canResolveSession` prop of the session provider
375
+ */
376
+ canResolve: boolean;
314
377
  updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
315
378
  triggerError: (error: KnownError) => void;
316
379
  events: CommentEvents;
@@ -319,4 +382,83 @@ type CommentWithStatus<T extends Status> = Omit<CommentType, "status"> & {
319
382
  status: T;
320
383
  };
321
384
 
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 };
385
+ /**
386
+ * Discriminator for the kind of session.
387
+ * Adding "rework" later is a change to this union only.
388
+ */
389
+ type SessionType = "feedback";
390
+ type SessionStatus = "draft" | "confirmed" | "resolving" | "resolved";
391
+ /**
392
+ * The pending operation of the session provider
393
+ */
394
+ type SessionOperationState = "idle" | "creating" | "confirming" | "startingResolution" | "completingResolution";
395
+ type FeedbackSession = {
396
+ id: string;
397
+ type: SessionType;
398
+ status: SessionStatus;
399
+ createdAt: Date;
400
+ /** The id of the user who created the session, never a user object */
401
+ createdBy: string;
402
+ /** Ids of the users that took part in the session. May be empty */
403
+ participantIds: string[];
404
+ confirmedAt?: Date;
405
+ resolvedAt?: Date;
406
+ projectId?: string | undefined;
407
+ /** Reserved for a future rework session. No behavior depends on it. */
408
+ sourceSessionId?: string | undefined;
409
+ };
410
+ /**
411
+ * The session as held by the provider, with its persisted comments
412
+ */
413
+ type ActiveFeedbackSession = FeedbackSession & {
414
+ comments: ConfirmedComment[];
415
+ };
416
+ /**
417
+ * Accepted by `initialSession`. `comments` is optional for convenience
418
+ */
419
+ type InitialFeedbackSession = FeedbackSession & {
420
+ comments?: ConfirmedComment[];
421
+ };
422
+ /**
423
+ * Input passed to `onCreateSession`
424
+ */
425
+ type CreateSessionInput = {
426
+ type: SessionType;
427
+ user: User | null;
428
+ projectId?: string | undefined;
429
+ };
430
+ /**
431
+ * Event map for session-related events
432
+ */
433
+ type SessionEventMap = {
434
+ /** Triggered when a new draft session was created */
435
+ onSessionCreated: (session: ActiveFeedbackSession) => void;
436
+ /** Triggered when the session was confirmed */
437
+ onSessionConfirmed: (session: ActiveFeedbackSession) => void;
438
+ /** Triggered when the session moved to resolving */
439
+ onSessionResolving: (session: ActiveFeedbackSession) => void;
440
+ /** Triggered when the session was resolved */
441
+ onSessionResolved: (session: ActiveFeedbackSession) => void;
442
+ };
443
+
444
+ type UserProviderProps = {
445
+ /** The current user, or null when nobody is signed in */
446
+ user: User | null;
447
+ children: ReactNode;
448
+ };
449
+ /**
450
+ * Value held by the user context
451
+ */
452
+ type UserContextType = {
453
+ currentUser: User | null;
454
+ };
455
+
456
+ /**
457
+ * The session events object exposed via useSession()
458
+ * Each method accepts a callback and returns an unsubscribe function
459
+ */
460
+ type SessionEvents = {
461
+ [K in keyof SessionEventMap]: (callback: SessionEventMap[K]) => Unsubscribe;
462
+ };
463
+
464
+ export type { ActiveFeedbackSession as A, CommentType as C, DraftVisibility as D, FeedbackSession as F, InitialFeedbackSession as I, KnownError as K, OverlayErrorCode as O, Position as P, RealtimeSubscription as R, SessionType as S, User as U, CommentOverlayProps as a, CommentContext as b, CreateSessionInput as c, SessionOperationState as d, SessionEvents as e, UserProviderProps as f, Indicator as g, CommentOverlayState as h, CommentVisibility as i, Status as j, ConfirmedStatus as k, ConfirmedComment as l, CommentWithStatus as m, CommentState as n, Config as o, CommentEventMap as p, Unsubscribe as q, CommentEvents as r, SessionStatus as s, SessionEventMap as t, UserContextType as u };