@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 CHANGED
@@ -1,13 +1,15 @@
1
1
  # @kendew-agency/react-feedback-layer
2
2
 
3
- A drop-in React feedback layer for collecting contextual user feedback through interactive comments and annotations. Perfect for design review tools, bug reporting systems, and collaborative annotation platforms.
3
+ A drop-in React feedback layer for collecting contextual user feedback through interactive comments and annotations. Perfect for design review tools, bug reporting systems, and collaborative annotation platforms.
4
4
 
5
- Have a look at the [changelog](#changelog) when updating the package.
5
+ Have a look at the [changelog](#changelog) and the [migration guide](#migrating-from-03x) when updating the package.
6
6
 
7
7
  ## Features
8
8
 
9
9
  - 🎯 **Contextual Feedback** - Click or drag to create comments anywhere on your UI
10
- - 💬 **Comment Lifecycle** - Draft → Published → Resolving → Resolved states
10
+ - 🗂️ **Feedback Sessions** - Group comments in a session that moves from draft to confirmed, resolving and resolved
11
+ - 🧭 **Multi-location Sessions** - One session can span several pages. Each page shows only its own comments
12
+ - 💬 **Comment Lifecycle** - Draft → Published → Resolved, with reopen support
11
13
  - 👥 **User Attribution** - Track who created each comment with timestamps
12
14
  - 🎨 **Fully Customizable** - Headless UI with complete styling control
13
15
  - 📦 **TypeScript First** - Full type definitions included
@@ -32,60 +34,155 @@ npm install react react-dom
32
34
 
33
35
  ## Quick Start
34
36
 
37
+ `CommentContextProvider` must be rendered inside a `FeedbackSessionProvider`. The session provider owns the session and its callbacks. The comment provider owns the individual comments and their callbacks.
38
+
35
39
  ```tsx
36
40
  import {
41
+ Comment,
37
42
  CommentContextProvider,
38
43
  CommentOverlay,
39
44
  CommentRenderer,
45
+ ConfirmSession,
46
+ CreateSession,
47
+ FeedbackSessionProvider,
48
+ ResolveSession,
49
+ StartResolving,
50
+ ToggleOverlayButton,
40
51
  } from '@kendew-agency/react-feedback-layer';
41
52
 
42
- function App() {
43
- const handleConfirm = async (comments, projectId) => {
44
- // Save comments to your database
45
- await saveToDatabase(comments, projectId);
46
- };
53
+ function App({ isReviewer, pathname }: { isReviewer: boolean; pathname: string }) {
54
+ return (
55
+ <FeedbackSessionProvider
56
+ canResolveSession={isReviewer}
57
+ onCreateSession={async ({ type, user, projectId }) => {
58
+ // Persist the session and return it. The returned status is ignored,
59
+ // a new session always starts as a draft.
60
+ return api.createSession({ type, user, projectId });
61
+ }}
62
+ onConfirmSession={(sessionId, type) => api.confirmSession(sessionId)}
63
+ onStartResolving={(sessionId) => api.startResolving(sessionId)}
64
+ onResolveSession={(sessionId) => api.resolveSession(sessionId)}
65
+ onError={(error) => console.error(error.code, error.message)}
66
+ >
67
+ <CommentContextProvider
68
+ locationId={pathname} // the page this provider renders, e.g. "/page-a"
69
+ currentUser={{ name: 'John Doe', id: 'user-123' }}
70
+ onAdd={(comment) => api.addComment(comment)}
71
+ onEdit={(comment) => api.editComment(comment)}
72
+ onDelete={(commentId) => api.deleteComment(commentId)}
73
+ onResolve={(comment) => api.resolveComment(comment)}
74
+ onReopen={(comment) => api.reopenComment(comment)}
75
+ onError={(error) => console.error(error.code, error.message)}
76
+ >
77
+ <CreateSession user={{ name: 'John Doe', id: 'user-123' }}>Start feedback session</CreateSession>
78
+ <ConfirmSession>Confirm session</ConfirmSession>
79
+ <StartResolving>Start resolving</StartResolving>
80
+ <ResolveSession>Resolve session</ResolveSession>
81
+ <ToggleOverlayButton>Toggle comments</ToggleOverlayButton>
82
+
83
+ <CommentOverlay>
84
+ <YourContent />
85
+ <CommentRenderer
86
+ Comment={YourCommentComponent}
87
+ DraftComment={YourDraftComponent}
88
+ ResolvedComment={YourResolvedComponent}
89
+ />
90
+ </CommentOverlay>
91
+ </CommentContextProvider>
92
+ </FeedbackSessionProvider>
93
+ );
94
+ }
95
+ ```
47
96
 
48
- const handleResolve = async (comments) => {
49
- // Mark comments as resolved in your database
50
- await resolveInDatabase(comments);
51
- };
97
+ `locationId` identifies the page (or screen) that a `CommentContextProvider` renders. Every new comment is stored with it, and the overlay shows only the comments placed at that location. Without a `locationId` the provider shows no comments and refuses to create them. See [Sessions across multiple locations](#sessions-across-multiple-locations).
52
98
 
53
- const handleError = (error) => {
54
- console.error('Comment error:', error.code, error.message);
55
- };
99
+ ## Core Concepts
100
+
101
+ ### Feedback Sessions
102
+
103
+ Every comment belongs to a feedback session and is placed at a location. A comment is shown only when its `sessionId` equals the id of the active session and its `locationId` equals the `locationId` prop of the `CommentContextProvider`. The overlay therefore shows the active session's comments at that location. Comments without a `locationId` are hidden. Without a session no comment is shown and no comment can be added.
104
+
105
+ #### Session flow
106
+
107
+ 1. **Create the session.** Call `createSession({ user })` (or render `<CreateSession user={user} />`). The provider calls `onCreateSession`, stores the returned session as a `draft` and emits `onSessionCreated`.
108
+ 2. **Add draft comments.** While the session is a `draft`, click or drag on the overlay to register a comment, write content and confirm it with `Comment.Confirm`. Confirming a comment calls `onAdd` and turns the comment from `draft` into `published`. Published comments can be edited (`onEdit`) and deleted (`onDelete`) as long as the session is a `draft`.
109
+ 3. **Confirm the session.** Call `confirmSession()` (or render `<ConfirmSession />`). It calls `onConfirmSession(sessionId, type)`, sets `confirmedAt` and emits `onSessionConfirmed`. It is refused with a `SessionStateError` when the session is not a draft, when a local draft comment still exists (in any `CommentContextProvider`), or when the session has no comments at any location. Comments without a `locationId` are ignored by this check, so they do not count as a comment.
110
+ 4. **Start resolving.** Call `startResolving()` (or render `<StartResolving />`). It calls `onStartResolving(sessionId)` and emits `onSessionResolving`. Requires `canResolveSession` and a `confirmed` session.
111
+ 5. **Resolve comments.** While the session is `resolving`, resolve each published comment with `resolveComment(id)` or `<Comment.Resolve />`, and reopen resolved comments with `reopenComment(id)` or `<Comment.Reopen />`. Requires `canResolveSession`.
112
+ 6. **Resolve the session.** Call `resolveSession()` (or render `<ResolveSession />`). It calls `onResolveSession(sessionId)`, sets `resolvedAt` and emits `onSessionResolved`. Requires `canResolveSession`, a `resolving` session and no comment that is still `published` at any location. Comments without a `locationId` are ignored by this check, so they cannot block it.
113
+
114
+ #### Session status
115
+
116
+ `Session_Status` is `"draft" | "confirmed" | "resolving" | "resolved"`.
117
+
118
+ | From | To | Triggered by | Requires |
119
+ |------|----|--------------|----------|
120
+ | (none) | `draft` | `createSession()` | No other draft session, `onCreateSession` provided |
121
+ | `draft` | `confirmed` | `confirmSession()` | No local draft comments, at least one comment with a `locationId` |
122
+ | `confirmed` | `resolving` | `startResolving()` | `canResolveSession` |
123
+ | `resolving` | `resolved` | `resolveSession()` | `canResolveSession`, no `published` comment with a `locationId` left |
124
+
125
+ No other transitions exist. A transition is committed only after its callback resolves. When the callback throws or rejects, the status stays as it was and `onError` receives the error.
56
126
 
127
+ What each status allows:
128
+
129
+ | Status | Add, edit, delete comments | Resolve, reopen comments |
130
+ |--------|----------------------------|--------------------------|
131
+ | `draft` | Yes | No |
132
+ | `confirmed` | No | No |
133
+ | `resolving` | No | Yes, with `canResolveSession` |
134
+ | `resolved` | No | No |
135
+
136
+ Calls that are not allowed return `{ error }` with a `SessionStateError` and call `onError`. Calls without permission return a `PermissionError`.
137
+
138
+ ### Sessions across multiple locations
139
+
140
+ One feedback session can cover several pages. Render one `CommentContextProvider` per page, each with its own `locationId`, inside the same `FeedbackSessionProvider`.
141
+
142
+ - The session holds the comments of all locations. Each provider shows only the comments at its own `locationId`.
143
+ - `confirmSession()` and `resolveSession()` check the comments of all locations, not only the current page. `confirmSession()` also sums the local drafts of all providers.
144
+ - Comments without a `locationId` (for example legacy data) are hidden everywhere and ignored by these checks. They are not deleted or changed.
145
+ - Keep the `FeedbackSessionProvider` mounted while the user navigates, so the session stays the same.
146
+
147
+ ```tsx
148
+ // The same session across /page-a, /page-b and /page-c
149
+ function PageA() {
57
150
  return (
58
- <CommentContextProvider
59
- currentUser={{ name: 'John Doe', id: 'user-123' }}
60
- onConfirm={handleConfirm}
61
- onResolve={handleResolve}
62
- onError={handleError}
63
- initialComments={[]}
64
- >
151
+ <CommentContextProvider locationId="page-a" currentUser={user} onAdd={saveComment}>
65
152
  <CommentOverlay>
66
- <YourContent />
67
- <CommentRenderer
68
- Comment={YourCommentComponent}
69
- DraftComment={YourDraftComponent}
70
- ResolvingComment={YourResolvingComponent}
71
- ResolvedComment={YourResolvedComponent}
72
- />
153
+ <PageAContent />
154
+ <CommentRenderer {...renderers} />
73
155
  </CommentOverlay>
74
156
  </CommentContextProvider>
75
157
  );
76
158
  }
159
+ // PageB and PageC are the same with locationId="page-b" and "page-c"
160
+ function App() {
161
+ return (
162
+ <FeedbackSessionProvider initialSession={savedSession} onConfirmSession={confirmSession}>
163
+ <Router>
164
+ <Route path="/page-a" element={<PageA />} />
165
+ <Route path="/page-b" element={<PageB />} />
166
+ <Route path="/page-c" element={<PageC />} />
167
+ {/* Confirming on /page-c confirms the comments of all three pages */}
168
+ <ConfirmSession>Confirm session</ConfirmSession>
169
+ </Router>
170
+ </FeedbackSessionProvider>
171
+ );
172
+ }
77
173
  ```
78
174
 
79
- ## Core Concepts
175
+ To see the comments at the current location from other sessions as well, use [`commentsBySession`](#usecomments).
80
176
 
81
177
  ### Comment Lifecycle
82
178
 
83
- Comments flow through four distinct states:
179
+ Comments have three statuses:
180
+
181
+ 1. **Draft** - Newly created and only held locally. It is not persisted yet.
182
+ 2. **Published** - Persisted through `onAdd` (or `onEdit` for later edits).
183
+ 3. **Resolved** - Resolved through `onResolve`. A resolved comment can be reopened through `onReopen`, which turns it back into `published` and removes `resolvedAt`.
84
184
 
85
- 1. **Draft** - Newly created, not yet saved
86
- 2. **Published** - Confirmed and saved to your database
87
- 3. **Resolving** - Marked for resolution (in progress)
88
- 4. **Resolved** - Completed and archived
185
+ Draft comments exist only in a `draft` session. Resolving and reopening only work in a `resolving` session.
89
186
 
90
187
  ### Headless UI Architecture
91
188
 
@@ -103,6 +200,7 @@ The `Comment` component uses a compound pattern for maximum flexibility:
103
200
  <Comment.Confirm />
104
201
  <Comment.Delete />
105
202
  <Comment.Resolve />
203
+ <Comment.Reopen />
106
204
  </Comment.Root>
107
205
  ```
108
206
 
@@ -110,84 +208,157 @@ The `Comment` component uses a compound pattern for maximum flexibility:
110
208
 
111
209
  ### Components
112
210
 
211
+ #### `FeedbackSessionProvider`
212
+
213
+ Owns the active session and the session transitions. It must wrap `CommentContextProvider`.
214
+
215
+ **Props:**
216
+
217
+ ```tsx
218
+ type FeedbackSessionProviderProps = {
219
+ children: ReactNode;
220
+
221
+ // Resume a session, for example after a reload
222
+ initialSession?: InitialFeedbackSession;
223
+
224
+ // Default project id passed to onCreateSession (1 to 128 characters)
225
+ projectId?: string;
226
+
227
+ // Whether the current user may start resolving, resolve the session,
228
+ // and resolve and reopen comments. Default: false
229
+ canResolveSession?: boolean;
230
+
231
+ // Persist a new session. The returned status is ignored, it starts as a draft.
232
+ onCreateSession?: (input: CreateSessionInput) => Promise<FeedbackSession>;
233
+
234
+ // Persist the confirmation of the session
235
+ onConfirmSession?: (sessionId: string, type: SessionType) => Promise<void>;
236
+
237
+ // Persist the start of the resolution
238
+ onStartResolving?: (sessionId: string) => Promise<void>;
239
+
240
+ // Persist the resolution of the session
241
+ onResolveSession?: (sessionId: string) => Promise<void>;
242
+
243
+ // Receives every error that the provider produces
244
+ onError?: (error: KnownError) => void;
245
+ };
246
+
247
+ type CreateSessionInput = {
248
+ type: SessionType; // "feedback"
249
+ user: User;
250
+ projectId?: string | undefined;
251
+ };
252
+ ```
253
+
254
+ `createSession` is refused when `user` is missing, when `onCreateSession` is not provided, when a draft session already exists, when a creation is in progress, or when `projectId` is not 1 to 128 characters long.
255
+
256
+ `initialSession` must have a valid `status`. Otherwise the provider starts without a session and reports a `SessionStateError` once on mount. Its `comments` are optional and default to an empty array.
257
+
258
+ **Example:**
259
+
260
+ ```tsx
261
+ <FeedbackSessionProvider
262
+ initialSession={savedSession}
263
+ canResolveSession={user.role === 'reviewer'}
264
+ onCreateSession={api.createSession}
265
+ onConfirmSession={(id) => api.confirmSession(id)}
266
+ onStartResolving={(id) => api.startResolving(id)}
267
+ onResolveSession={(id) => api.resolveSession(id)}
268
+ onError={handleError}
269
+ >
270
+ {children}
271
+ </FeedbackSessionProvider>
272
+ ```
273
+
113
274
  #### `CommentContextProvider`
114
275
 
115
- The root provider that manages all comment state and actions.
276
+ The provider that manages comment state and comment actions. It throws when it is not rendered inside a `FeedbackSessionProvider`. Standalone use is no longer possible.
116
277
 
117
278
  **Props:**
118
279
 
119
280
  ```tsx
120
- interface CommentOverlayProps {
121
- // Initial comments from your database
281
+ type CommentOverlayProps = {
282
+ // Comments to start with, from all locations. Defaults to the comments of the session.
283
+ // Each comment needs a sessionId and a locationId. Comments of other sessions
284
+ // are kept, but they only appear in commentsBySession.
122
285
  initialComments?: ConfirmedComment[];
123
-
124
- // Current logged-in user
125
- currentUser: User | null;
126
-
127
- // Your app content
286
+ // The location this provider renders, for example a page name or pathname.
287
+ // New comments are stored with this id and the overlay shows only the
288
+ // comments at this location. Comments of all locations are loaded, so
289
+ // session-level checks see them.
290
+ // When missing or an empty string, no comments are shown and
291
+ // registerComment reports an AddError through onError without creating a draft.
292
+ locationId?: string;
293
+
294
+ // Current logged-in user (default: null).
295
+ currentUser?: User | null;
296
+
128
297
  children: ReactNode;
129
-
298
+
130
299
  // Initial overlay state (default: "inactive")
131
- initialOverlayState?: "idle" | "editing" | "saving" | "error" | "resolving" | "inactive";
132
-
133
- // Optional real-time subscription
300
+ initialOverlayState?: "idle" | "editing" | "saving" | "resolving" | "inactive";
301
+
302
+ // Optional real-time subscription (beta)
134
303
  subscription?: {
135
- subscribe: (update: unknown) => void;
304
+ subscribe: (onUpdate: (comment: CommentType) => void) => void;
136
305
  unsubscribe: () => void;
137
306
  };
138
-
139
- // Callback when user confirms draft comments
140
- onConfirm: (comments: ConfirmedComment[], projectId?: string) => Promise<void>;
141
-
142
- // Callback when user resolves comments
143
- onResolve: (comments: ConfirmedComment[]) => Promise<void>;
144
-
145
- // Callback to handle errors
146
- onError: (error: KnownError) => void;
147
-
307
+
308
+ // Persist a newly added comment
309
+ onAdd?: (comment: ConfirmedComment) => Promise<void>;
310
+
311
+ // Persist an edited comment
312
+ onEdit?: (comment: ConfirmedComment) => Promise<void>;
313
+
314
+ // Persist a resolved comment
315
+ onResolve?: (comment: ConfirmedComment) => Promise<void>;
316
+
317
+ // Persist a reopened comment
318
+ onReopen?: (comment: ConfirmedComment) => Promise<void>;
319
+
320
+ // Delete a persisted comment
321
+ onDelete?: (commentId: string) => Promise<void>;
322
+
323
+ // Receives every error that the provider produces
324
+ onError?: (error: KnownError) => void;
325
+
148
326
  // Optional configuration for the comment layer
149
- config?: {
150
- // Custom prefix for comment IDs
151
- idPrefix?: string;
152
- // Visibility of comment indicators: "always" | "active"
153
- indicatorVisibility?: "always" | "active";
154
- // Comment visibility settings
155
- commentVisibility?: {
156
- hideResolved?: boolean;
157
- hideResolving?: boolean;
158
- };
159
- };
160
-
161
- // Optional project ID to attach to all comments in this overlay
327
+ config?: Config;
328
+
329
+ // Optional project ID attached to every new comment
162
330
  projectId?: string;
163
- }
331
+ };
164
332
  ```
165
333
 
334
+ | Callback | Called when | Receives |
335
+ |----------|-------------|----------|
336
+ | `onAdd` | A draft comment is confirmed | The comment with status `published` |
337
+ | `onEdit` | A published comment gets new content | The updated comment with status `published` |
338
+ | `onDelete` | A published comment is deleted | The comment id |
339
+ | `onResolve` | A published comment is resolved | The comment with status `resolved` and `resolvedAt` |
340
+ | `onReopen` | A resolved comment is reopened | The comment with status `published` and no `resolvedAt` |
341
+
342
+ Every comment passed to a callback keeps its `locationId`. Every callback is optional. When a callback throws or rejects, the change is not applied and `onError` receives an `AddError`, `EditError`, `DeleteError`, `ResolveError` or `ReopenError`. Deleting a local draft does not call `onDelete`.
343
+
166
344
  **Example:**
167
345
 
168
346
  ```tsx
169
347
  <CommentContextProvider
348
+ locationId="page-a"
170
349
  currentUser={{ name: 'Jane Smith', id: '456', avatar: '/avatar.jpg' }}
171
350
  initialComments={existingComments}
172
351
  projectId="proj_123456789"
173
- onConfirm={async (comments, projectId) => {
174
- await api.createComments(comments, projectId);
175
- }}
176
- onResolve={async (comments) => {
177
- await api.resolveComments(comments);
178
- }}
179
- onError={(error) => {
180
- console.error('Comment operation failed:', error);
181
- toast.error('Failed to save comments');
182
- }}
352
+ onAdd={(comment) => api.addComment(comment)}
353
+ onResolve={(comment) => api.resolveComment(comment)}
354
+ onReopen={(comment) => api.reopenComment(comment)}
355
+ onError={(error) => toast.error(error.message)}
183
356
  initialOverlayState="idle"
184
357
  config={{
185
358
  idPrefix: 'proj_',
186
359
  indicatorVisibility: 'active',
187
- commentVisibility: {
188
- hideResolved: false,
189
- hideResolving: false,
190
- },
360
+ draftVisibility: 'visible',
361
+ commentVisibility: { hideResolved: false },
191
362
  }}
192
363
  >
193
364
  {children}
@@ -201,7 +372,7 @@ Creates an interactive overlay for adding comments via click or drag selection.
201
372
  **Props:**
202
373
 
203
374
  ```tsx
204
- interface CommentOverlayProps {
375
+ interface CommentOverlayProps extends HTMLProps<HTMLDivElement> {
205
376
  children: ReactNode;
206
377
  }
207
378
  ```
@@ -211,6 +382,7 @@ interface CommentOverlayProps {
211
382
  - **Click** - Creates a comment at the clicked position
212
383
  - **Drag** - Creates a comment with a visual indicator box
213
384
  - **Inactive State** - Renders children without overlay when `overlayState === "inactive"`
385
+ - **Session state** - Comments can only be created while the session is a `draft`. Otherwise `onError` receives a `SessionStateError`.
214
386
 
215
387
  **Example:**
216
388
 
@@ -223,7 +395,7 @@ interface CommentOverlayProps {
223
395
 
224
396
  #### `CommentRenderer`
225
397
 
226
- Renders all comments based on their current state.
398
+ Renders all visible comments based on their status. Resolved comments are skipped when `config.commentVisibility.hideResolved` is `true`.
227
399
 
228
400
  **Props:**
229
401
 
@@ -231,13 +403,10 @@ Renders all comments based on their current state.
231
403
  interface CommentRendererProps {
232
404
  // Component for published comments
233
405
  Comment: ElementType<{ comment: CommentType }>;
234
-
406
+
235
407
  // Component for draft comments
236
408
  DraftComment: ElementType<{ comment: CommentType }>;
237
-
238
- // Component for resolving comments
239
- ResolvingComment: ElementType<{ comment: CommentType }>;
240
-
409
+
241
410
  // Component for resolved comments
242
411
  ResolvedComment: ElementType<{ comment: CommentType }>;
243
412
  }
@@ -249,7 +418,6 @@ interface CommentRendererProps {
249
418
  <CommentRenderer
250
419
  Comment={PublishedComment}
251
420
  DraftComment={DraftComment}
252
- ResolvingComment={ResolvingComment}
253
421
  ResolvedComment={ResolvedComment}
254
422
  />
255
423
  ```
@@ -388,7 +556,7 @@ interface CommentDeleteProps extends ButtonHTMLAttributes<HTMLButtonElement> {
388
556
 
389
557
  ##### `Comment.Resolve`
390
558
 
391
- Button to toggle resolving state (only for published/resolving comments).
559
+ Button that resolves the comment. It calls `resolveComment(comment.id)`, which needs a `resolving` session and `canResolveSession`. It renders nothing (and logs an error) for draft and resolved comments.
392
560
 
393
561
  **Props:**
394
562
 
@@ -406,91 +574,185 @@ interface CommentResolveProps extends ButtonHTMLAttributes<HTMLButtonElement> {
406
574
  </Comment.Resolve>
407
575
  ```
408
576
 
409
- #### Action Components
577
+ ##### `Comment.Reopen`
410
578
 
411
- ##### `ToggleOverlayButton`
579
+ Button that reopens a resolved comment. It calls `reopenComment(comment.id)`, with the same requirements as `Comment.Resolve`. It renders nothing (and logs an error) for draft and published comments.
412
580
 
413
- Toggles the comment overlay on/off.
581
+ ```tsx
582
+ <Comment.Reopen className="btn-reopen">Reopen</Comment.Reopen>
583
+ ```
414
584
 
415
- **Props:**
585
+ Hide both buttons for users that may not resolve by reading `canResolve` from `useComments()`:
416
586
 
417
587
  ```tsx
418
- interface CommentButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
419
- asChild?: boolean;
588
+ function PublishedComment({ comment }) {
589
+ const { canResolve } = useComments();
590
+ return (
591
+ <Comment.Root comment={comment}>
592
+ <Comment.Content />
593
+ {canResolve && <Comment.Resolve>Resolve</Comment.Resolve>}
594
+ </Comment.Root>
595
+ );
420
596
  }
421
597
  ```
422
598
 
423
- **Example:**
599
+ #### Action Components
424
600
 
425
- ```tsx
426
- import { ToggleOverlayButton } from '@kendew-agency/react-feedback-layer';
601
+ All action components accept button props and `asChild`. They call the matching action and then your own `onClick`. The result of the action is not exposed, so use the hooks when you need it.
427
602
 
603
+ ##### `ToggleOverlayButton`
604
+
605
+ Toggles the comment overlay on/off. Sets `data-active` when the overlay is not inactive.
606
+
607
+ ```tsx
428
608
  <ToggleOverlayButton className="toggle-btn">
429
609
  Toggle Comments
430
610
  </ToggleOverlayButton>
431
611
  ```
432
612
 
433
- ##### `ConfirmComments`
613
+ ##### `CreateSession`, `ConfirmSession`, `StartResolving`, `ResolveSession`
434
614
 
435
- Confirms all draft comments and triggers the `onConfirm` callback.
615
+ Call `createSession({ user })`, `confirmSession()`, `startResolving()` and `resolveSession()` of `useFeedbackSession()`. They must be rendered inside a `FeedbackSessionProvider`.
436
616
 
437
- **Example:**
617
+ ```tsx
618
+ <CreateSession user={currentUser}>New session</CreateSession>
619
+ <ConfirmSession>Confirm</ConfirmSession>
620
+ <StartResolving>Start resolving</StartResolving>
621
+ <ResolveSession>Finish</ResolveSession>
622
+ ```
623
+
624
+ ### Hooks
625
+
626
+ #### `useFeedbackSession()`
627
+
628
+ Access the session and its actions. Throws outside a `FeedbackSessionProvider`.
629
+
630
+ **Returns:**
631
+
632
+ ```tsx
633
+ type FeedbackSessionContextType = {
634
+ // The active session with its persisted comments, or null
635
+ session: ActiveFeedbackSession | null;
636
+
637
+ // The pending operation
638
+ sessionState:
639
+ | "idle"
640
+ | "creating"
641
+ | "confirming"
642
+ | "startingResolution"
643
+ | "completingResolution";
644
+
645
+ // Mirrors the canResolveSession prop
646
+ canResolve: boolean;
647
+
648
+ createSession: (options: {
649
+ user: User; // required
650
+ type?: SessionType;
651
+ projectId?: string;
652
+ }) => Promise<{ error: KnownError | null }>;
653
+ confirmSession: () => Promise<{ error: KnownError | null }>;
654
+ startResolving: () => Promise<{ error: KnownError | null }>;
655
+ resolveSession: () => Promise<{ error: KnownError | null }>;
656
+
657
+ // Subscribe to session transitions
658
+ events: SessionEvents;
659
+ };
660
+ ```
661
+
662
+ `createSession` requires `user`. It defaults `type` to `"feedback"` and `projectId` to the provider `projectId`. Without a `user` it is refused with a `SessionCreateError` ("user is required"), returned as `{ error }` and passed to `onError`, and `onCreateSession` is not called. A failed or refused action returns `{ error }` and also calls `onError`. A second call of the same transition while it is pending resolves with `{ error: null }` and does nothing.
438
663
 
439
664
  ```tsx
440
- import { ConfirmComments } from '@kendew-agency/react-feedback-layer';
665
+ function SessionToolbar() {
666
+ const { session, sessionState, canResolve, confirmSession, startResolving } =
667
+ useFeedbackSession();
441
668
 
442
- <ConfirmComments className="btn-save">
443
- Save All Comments
444
- </ConfirmComments>
669
+ if (!session) return null;
670
+
671
+ return (
672
+ <div>
673
+ <span>Status: {session.status}</span>
674
+ {session.status === 'draft' && (
675
+ <button disabled={sessionState !== 'idle'} onClick={confirmSession}>
676
+ Confirm
677
+ </button>
678
+ )}
679
+ {session.status === 'confirmed' && canResolve && (
680
+ <button disabled={sessionState !== 'idle'} onClick={startResolving}>
681
+ Start resolving
682
+ </button>
683
+ )}
684
+ </div>
685
+ );
686
+ }
445
687
  ```
446
688
 
447
- ##### `ResolveComments`
689
+ #### Session events
448
690
 
449
- Resolves all resolving comments and triggers the `onResolve` callback.
691
+ `useFeedbackSession().events` mirrors the comment events. Each method accepts a callback and returns an `unsubscribe` function. Every event receives the `ActiveFeedbackSession` after the transition.
450
692
 
451
- **Example:**
693
+ | Event | Trigger | Callback Signature |
694
+ |-------|---------|-------------------|
695
+ | `onSessionCreated` | A draft session was created | `(session: ActiveFeedbackSession) => void` |
696
+ | `onSessionConfirmed` | The session moved to `confirmed` | `(session: ActiveFeedbackSession) => void` |
697
+ | `onSessionResolving` | The session moved to `resolving` | `(session: ActiveFeedbackSession) => void` |
698
+ | `onSessionResolved` | The session moved to `resolved` | `(session: ActiveFeedbackSession) => void` |
452
699
 
453
700
  ```tsx
454
- import { ResolveComments } from '@kendew-agency/react-feedback-layer';
701
+ function SessionTracker() {
702
+ const { events } = useFeedbackSession();
703
+
704
+ useEffect(
705
+ () =>
706
+ events.onSessionConfirmed((session) => {
707
+ analytics.track('session_confirmed', {
708
+ id: session.id,
709
+ comments: session.comments.length,
710
+ });
711
+ }),
712
+ [events],
713
+ );
455
714
 
456
- <ResolveComments className="btn-resolve-all">
457
- Resolve All
458
- </ResolveComments>
715
+ return null;
716
+ }
459
717
  ```
460
718
 
461
- ### Hooks
462
-
463
719
  #### `useComments()`
464
720
 
465
- Access the global comment context and actions.
721
+ Access the comment context and actions. Throws outside a `CommentContextProvider` (and outside a `FeedbackSessionProvider`).
466
722
 
467
723
  **Returns:**
468
724
 
469
725
  ```tsx
470
726
  interface CommentContext {
471
- // Filtered comment arrays
727
+ // Comments of the active session at the current location, after the
728
+ // draftVisibility filter. Empty without a locationId or a session.
472
729
  draftComments: CommentType[];
473
730
  comments: CommentType[]; // Published comments
474
- resolvingComments: CommentType[];
475
731
  resolvedComments: CommentType[];
476
732
  allComments: CommentType[];
477
-
733
+ // Comments at the current location, grouped by session id
734
+ commentsBySession: Record<string, CommentType[]>;
735
+
478
736
  // State
479
737
  overlayState: CommentOverlayState;
480
738
  currentUser: User | null;
481
739
  config: Config | undefined;
482
-
740
+ // Mirrors the canResolveSession prop of the session provider
741
+ canResolve: boolean;
742
+
483
743
  // Actions
484
744
  registerComment: (position: Position, indicatorPosition?: Indicator) => void;
485
- updateComment: (id: string, newComment: Pick<CommentType, "content">) => void;
486
- deleteComment: (id: string) => void;
745
+ updateComment: (
746
+ id: string,
747
+ newComment: Pick<CommentType, "content">,
748
+ ) => Promise<{ error: KnownError | null }>;
749
+ deleteComment: (id: string) => Promise<{ error: KnownError | null }>;
750
+ resolveComment: (id: string) => Promise<{ error: KnownError | null }>;
751
+ reopenComment: (id: string) => Promise<{ error: KnownError | null }>;
487
752
  focusOnComment: (id: string | null) => void;
488
753
  getActiveComment: () => CommentType | undefined;
489
754
  toggleOverlay: () => void;
490
- toggleResolvingComment: (id: string) => void;
491
755
  changeOverlayState: (state: CommentOverlayState) => void;
492
- confirmComments: () => Promise<{ error: Error | DOMException | null }>;
493
- resolveComments: () => Promise<{ error: Error | DOMException | null }>;
494
756
  updateCommentVisibility: (visibility: Partial<CommentVisibility>) => void;
495
757
  triggerError: (error: KnownError) => void;
496
758
 
@@ -499,31 +761,40 @@ interface CommentContext {
499
761
  }
500
762
  ```
501
763
 
764
+ `commentsBySession` groups the comments at the current location by session id. It includes sessions other than the active one, so you can show earlier feedback next to the active session. Keep in mind:
765
+
766
+ - Only sessions that have at least one comment at the current location have a key. Other sessions are omitted.
767
+ - `config.draftVisibility` applies only to the entry of the active session. Other sessions are not filtered.
768
+ - The order of the comments follows the loaded comments. Comments without a `locationId` are excluded, and the record is empty when the provider has no `locationId`.
769
+ - `draftComments`, `comments`, `resolvedComments` and `allComments` are not affected. They still hold only the active session.
770
+ - Comments of other sessions get into the provider through `initialComments`. The session itself only carries its own comments.
771
+
772
+ ```tsx
773
+ function EarlierFeedback({ sessionId }: { sessionId: string }) {
774
+ const { commentsBySession } = useComments();
775
+ const earlier = commentsBySession[sessionId] ?? [];
776
+ return <span>{earlier.length} comments from session {sessionId} on this page</span>;
777
+ }
778
+ ```
779
+
780
+ `registerComment` stores the current `locationId` on the new draft. Without a `locationId` it reports an `AddError` through `onError` and creates no draft.
781
+
782
+ `updateComment` adds a draft comment (`onAdd`) or edits a published one (`onEdit`). It needs a `draft` session and rejects empty content for new comments. `resolveComment` and `reopenComment` need a `resolving` session and `canResolveSession`, and they do nothing (`{ error: null }`) when the comment is already in the target status.
783
+
502
784
  **Example:**
503
785
 
504
786
  ```tsx
505
787
  import { useComments } from '@kendew-agency/react-feedback-layer';
506
788
 
507
789
  function CommentToolbar() {
508
- const {
509
- draftComments,
510
- confirmComments,
511
- overlayState,
512
- toggleOverlay,
513
- config
514
- } = useComments();
515
-
790
+ const { allComments, overlayState, toggleOverlay, config } = useComments();
791
+
516
792
  return (
517
793
  <div>
518
794
  <button onClick={toggleOverlay}>
519
795
  {overlayState === 'inactive' ? 'Enable' : 'Disable'} Comments
520
796
  </button>
521
- <button
522
- onClick={confirmComments}
523
- disabled={draftComments.length === 0}
524
- >
525
- Save {draftComments.length} Comments
526
- </button>
797
+ <span>{allComments.length} comments</span>
527
798
  {config?.commentVisibility && (
528
799
  <span>Resolved hidden: {config.commentVisibility.hideResolved ? 'Yes' : 'No'}</span>
529
800
  )}
@@ -547,14 +818,10 @@ interface CommentScope {
547
818
  }
548
819
  ```
549
820
 
550
- **Example:**
551
-
552
821
  ```tsx
553
- import { useCommentScope } from '@kendew-agency/react-feedback-layer';
554
-
555
822
  function CustomCommentContent() {
556
823
  const { comment, isActive, draft } = useCommentScope();
557
-
824
+
558
825
  return (
559
826
  <div className={isActive ? 'active' : ''}>
560
827
  <p>{draft}</p>
@@ -564,72 +831,34 @@ function CustomCommentContent() {
564
831
  }
565
832
  ```
566
833
 
567
- #### `events` (via `useComments()`)
568
-
569
- The `events` object provides a subscription-based system for reacting to comment lifecycle changes. Each event method accepts a callback and returns an `unsubscribe` function.
834
+ #### Comment events
570
835
 
571
- **Available Events:**
836
+ `useComments().events` provides a subscription-based system for reacting to comment changes. Each method accepts a callback and returns an `unsubscribe` function.
572
837
 
573
838
  | Event | Trigger | Callback Signature |
574
839
  |-------|---------|-------------------|
575
840
  | `onFocusChange` | Focus moves to a different comment | `(commentId: string \| null, comment: CommentType \| undefined) => void` |
576
- | `onCommentsConfirmed` | Draft comments are successfully saved | `(comments: CommentType[]) => void` |
577
- | `onCommentsResolved` | Comments are successfully resolved | `(comments: CommentType[]) => void` |
578
- | `onCommentDeleted` | A comment is deleted | `(commentId: string) => void` |
579
841
  | `onCommentRegistered` | A new draft comment is created | `(comment: CommentType) => void` |
580
-
581
- **Basic Usage:**
842
+ | `onCommentAdded` | A comment was persisted through `onAdd` | `(comment: CommentType) => void` |
843
+ | `onCommentEdited` | A comment was persisted through `onEdit` | `(comment: CommentType) => void` |
844
+ | `onCommentResolved` | A comment was resolved | `(comment: CommentType) => void` |
845
+ | `onCommentReopened` | A resolved comment was reopened | `(comment: CommentType) => void` |
846
+ | `onCommentDeleted` | A comment is deleted | `(commentId: string) => void` |
582
847
 
583
848
  ```tsx
584
- import { useComments } from '@kendew-agency/react-feedback-layer';
585
- import { useEffect } from 'react';
586
-
587
849
  function CommentTracker() {
588
850
  const { events } = useComments();
589
851
 
590
- useEffect(() => {
591
- const unsubscribe = events.onFocusChange((commentId, comment) => {
592
- console.log('Focus changed to:', commentId);
593
- if (comment) {
594
- highlightElement(comment.position);
595
- }
596
- });
597
-
598
- return unsubscribe;
599
- }, [events]);
600
-
601
- useEffect(() => {
602
- const unsubscribe = events.onCommentsConfirmed((comments) => {
603
- console.log(`${comments.length} comments saved`);
604
- toast.success('Comments saved successfully!');
605
- });
606
-
607
- return unsubscribe;
608
- }, [events]);
609
-
610
- return null;
611
- }
612
- ```
613
-
614
- **Multiple Subscriptions:**
615
-
616
- ```tsx
617
- function AnalyticsTracker() {
618
- const { events } = useComments();
619
-
620
852
  useEffect(() => {
621
853
  const unsubs = [
622
- events.onCommentRegistered((comment) => {
623
- analytics.track('comment_created', {
624
- position: comment.position,
625
- user: comment.user?.name,
626
- });
854
+ events.onCommentAdded((comment) => {
855
+ analytics.track('comment_added', { id: comment.id });
627
856
  }),
628
- events.onCommentsConfirmed((comments) => {
629
- analytics.track('comments_confirmed', { count: comments.length });
857
+ events.onCommentResolved((comment) => {
858
+ toast.success(`Resolved: ${comment.content}`);
630
859
  }),
631
- events.onCommentsResolved((comments) => {
632
- analytics.track('comments_resolved', { count: comments.length });
860
+ events.onCommentReopened((comment) => {
861
+ toast(`Reopened: ${comment.content}`);
633
862
  }),
634
863
  events.onCommentDeleted((id) => {
635
864
  analytics.track('comment_deleted', { commentId: id });
@@ -643,58 +872,42 @@ function AnalyticsTracker() {
643
872
  }
644
873
  ```
645
874
 
646
- **Syncing with External State:**
647
-
648
- ```tsx
649
- function CommentSidebar() {
650
- const { events, allComments } = useComments();
651
- const [activeId, setActiveId] = useState<string | null>(null);
652
-
653
- useEffect(() => {
654
- return events.onFocusChange((commentId) => {
655
- setActiveId(commentId);
656
- // Scroll sidebar to the active comment
657
- if (commentId) {
658
- document.getElementById(`sidebar-${commentId}`)?.scrollIntoView({
659
- behavior: 'smooth',
660
- });
661
- }
662
- });
663
- }, [events]);
664
-
665
- return (
666
- <aside className="comment-sidebar">
667
- {allComments.map((comment) => (
668
- <div
669
- key={comment.id}
670
- id={`sidebar-${comment.id}`}
671
- className={comment.id === activeId ? 'active' : ''}
672
- >
673
- <p>{comment.content}</p>
674
- <small>{comment.user?.name}</small>
675
- </div>
676
- ))}
677
- </aside>
678
- );
679
- }
680
- ```
681
-
682
- **Type Definitions:**
875
+ Type definitions:
683
876
 
684
877
  ```tsx
685
878
  import type {
686
879
  CommentEvents,
687
880
  CommentEventMap,
881
+ SessionEvents,
882
+ SessionEventMap,
688
883
  Unsubscribe,
689
884
  } from '@kendew-agency/react-feedback-layer/types';
690
885
  ```
691
886
 
887
+ ### Draft visibility
888
+
889
+ `config.draftVisibility` controls whether comments that other users already persisted are shown while the session is a draft. It applies to the comments at the current location.
890
+
891
+ | Value | Effect while the session is a `draft` |
892
+ |-------|----------------------------------------|
893
+ | `"visible"` (default) | All comments of the session are shown |
894
+ | `"hidden"` | Only your own comments are shown. Comments of other users are hidden. |
895
+
896
+ - The default is `"visible"`. Any other value falls back to `"visible"`.
897
+ - It only applies while the session status is `draft`. Once the session is `confirmed`, `resolving` or `resolved`, all comments of the session are shown.
898
+ - Your own local drafts are always shown. Comments without a `user.id` are also shown.
899
+ - Hidden comments are removed from `draftComments`, `comments`, `resolvedComments` and `allComments`, and from the active session's entry of `commentsBySession`.
900
+
901
+ ```tsx
902
+ <CommentContextProvider config={{ draftVisibility: 'hidden' }} /* ... */>
903
+ ```
904
+
692
905
  ### Types
693
906
 
694
907
  Import types from the `/types` subpath:
695
908
 
696
909
  ```tsx
697
- import type {
910
+ import type {
698
911
  CommentType,
699
912
  ConfirmedComment,
700
913
  User,
@@ -702,8 +915,16 @@ import type {
702
915
  Indicator,
703
916
  CommentOverlayState,
704
917
  CommentVisibility,
705
- CommentAction,
706
- Config
918
+ DraftVisibility,
919
+ Config,
920
+ FeedbackSession,
921
+ ActiveFeedbackSession,
922
+ InitialFeedbackSession,
923
+ SessionStatus,
924
+ SessionType,
925
+ SessionOperationState,
926
+ CreateSessionInput,
927
+ KnownError,
707
928
  } from '@kendew-agency/react-feedback-layer/types';
708
929
  ```
709
930
 
@@ -717,12 +938,55 @@ type CommentType = {
717
938
  user: User | null;
718
939
  createdAt: Date;
719
940
  resolvedAt?: Date;
720
- status: "draft" | "published" | "resolving" | "resolved";
941
+ status: "draft" | "published" | "resolved";
721
942
  indicator?: Indicator | null;
943
+ sessionId: string;
944
+ // The location the comment was placed at, equal to the locationId prop of
945
+ // the provider. Comments without it are hidden.
946
+ locationId: string;
947
+ projectId?: string;
948
+ };
949
+
950
+ // A persisted comment, as passed to onAdd, onEdit, onResolve and onReopen.
951
+ // It has the required locationId of CommentType.
952
+ type ConfirmedComment = Omit<CommentType, "status"> & {
953
+ status: "published" | "resolved";
954
+ locationId: string;
955
+ };
956
+ ```
957
+
958
+ #### `FeedbackSession`
959
+
960
+ ```tsx
961
+ type SessionType = "feedback";
962
+ type SessionStatus = "draft" | "confirmed" | "resolving" | "resolved";
963
+
964
+ type FeedbackSession = {
965
+ id: string;
966
+ type: SessionType;
967
+ status: SessionStatus;
968
+ createdAt: Date;
969
+ createdBy: string; // user id
970
+ participantIds: string[];
971
+ confirmedAt?: Date;
972
+ resolvedAt?: Date;
722
973
  projectId?: string;
974
+ sourceSessionId?: string; // reserved, no behavior depends on it
975
+ };
976
+
977
+ // The session held by the provider
978
+ type ActiveFeedbackSession = FeedbackSession & {
979
+ comments: ConfirmedComment[];
980
+ };
981
+
982
+ // Accepted by initialSession. comments is optional.
983
+ type InitialFeedbackSession = FeedbackSession & {
984
+ comments?: ConfirmedComment[];
723
985
  };
724
986
  ```
725
987
 
988
+ `participantIds` gets the `user.id` of every user that added a comment while the session is a draft.
989
+
726
990
  #### `User`
727
991
 
728
992
  ```tsx
@@ -756,7 +1020,6 @@ type Indicator = {
756
1020
  ```tsx
757
1021
  type CommentVisibility = {
758
1022
  hideResolved?: boolean;
759
- hideResolving?: boolean;
760
1023
  };
761
1024
  ```
762
1025
 
@@ -766,10 +1029,12 @@ type CommentVisibility = {
766
1029
  type Config = {
767
1030
  // Custom prefix for comment IDs
768
1031
  idPrefix?: string;
769
- // Visibility of comment indicators
1032
+ // Visibility of comment indicators (default: "always")
770
1033
  indicatorVisibility?: "always" | "active";
771
1034
  // Comment visibility settings
772
1035
  commentVisibility?: CommentVisibility;
1036
+ // Visibility of other users' comments in a draft session (default: "visible")
1037
+ draftVisibility?: "hidden" | "visible";
773
1038
  };
774
1039
  ```
775
1040
 
@@ -779,12 +1044,15 @@ type Config = {
779
1044
 
780
1045
  ```tsx
781
1046
  import {
1047
+ Comment,
782
1048
  CommentContextProvider,
783
1049
  CommentOverlay,
784
1050
  CommentRenderer,
785
- Comment,
1051
+ ConfirmSession,
1052
+ CreateSession,
1053
+ FeedbackSessionProvider,
786
1054
  ToggleOverlayButton,
787
- ConfirmComments,
1055
+ useComments,
788
1056
  } from '@kendew-agency/react-feedback-layer';
789
1057
 
790
1058
  function DraftComment({ comment }) {
@@ -803,6 +1071,8 @@ function DraftComment({ comment }) {
803
1071
  }
804
1072
 
805
1073
  function PublishedComment({ comment }) {
1074
+ const { canResolve } = useComments();
1075
+
806
1076
  return (
807
1077
  <Comment.Root comment={comment} className="published-comment">
808
1078
  <Comment.Indicator className="indicator" />
@@ -813,7 +1083,7 @@ function PublishedComment({ comment }) {
813
1083
  <span>{comment.createdAt.toLocaleDateString()}</span>
814
1084
  </div>
815
1085
  <div className="actions">
816
- <Comment.Resolve>Resolve</Comment.Resolve>
1086
+ {canResolve && <Comment.Resolve>Resolve</Comment.Resolve>}
817
1087
  <Comment.Delete>Delete</Comment.Delete>
818
1088
  </div>
819
1089
  </div>
@@ -821,88 +1091,106 @@ function PublishedComment({ comment }) {
821
1091
  );
822
1092
  }
823
1093
 
824
- function App() {
1094
+ function ResolvedComment({ comment }) {
825
1095
  return (
826
- <CommentContextProvider
827
- currentUser={{ name: 'John Doe', id: '123' }}
828
- onConfirm={async (comments, projectId) => {
829
- const response = await fetch('/api/comments', {
830
- method: 'POST',
831
- body: JSON.stringify({ comments, projectId }),
832
- });
833
- if (!response.ok) {
834
- throw new Error('Failed to save comments');
835
- }
836
- }}
837
- onResolve={async (comments) => {
838
- const response = await fetch('/api/comments/resolve', {
1096
+ <Comment.Root comment={comment} className="resolved-comment">
1097
+ <Comment.Content />
1098
+ <Comment.Reopen>Reopen</Comment.Reopen>
1099
+ </Comment.Root>
1100
+ );
1101
+ }
1102
+
1103
+ function App({ pathname }: { pathname: string }) {
1104
+ return (
1105
+ <FeedbackSessionProvider
1106
+ onCreateSession={async ({ type, user, projectId }) => {
1107
+ const response = await fetch('/api/sessions', {
839
1108
  method: 'POST',
840
- body: JSON.stringify(comments),
1109
+ body: JSON.stringify({ type, user, projectId }),
841
1110
  });
842
- if (!response.ok) {
843
- throw new Error('Failed to resolve comments');
844
- }
845
- }}
846
- onError={(error) => {
847
- console.error('Comment operation failed:', error);
848
- // Show user-friendly error message
1111
+ if (!response.ok) throw new Error('Failed to create session');
1112
+ return response.json();
849
1113
  }}
850
- config={{
851
- commentVisibility: {
852
- hideResolved: false,
853
- hideResolving: false,
854
- },
1114
+ onConfirmSession={async (sessionId) => {
1115
+ await fetch(`/api/sessions/${sessionId}/confirm`, { method: 'POST' });
855
1116
  }}
1117
+ onError={(error) => console.error(error.code, error.message)}
856
1118
  >
857
- <ToggleOverlayButton>Toggle Feedback Mode</ToggleOverlayButton>
858
- <ConfirmComments>Save All Comments</ConfirmComments>
859
-
860
- <CommentOverlay>
861
- <YourContent />
862
- <CommentRenderer
863
- Comment={PublishedComment}
864
- DraftComment={DraftComment}
865
- ResolvingComment={PublishedComment}
866
- ResolvedComment={PublishedComment}
867
- />
868
- </CommentOverlay>
869
- </CommentContextProvider>
1119
+ <CommentContextProvider
1120
+ locationId={pathname}
1121
+ currentUser={{ name: 'John Doe', id: '123' }}
1122
+ onAdd={async (comment) => {
1123
+ const response = await fetch('/api/comments', {
1124
+ method: 'POST',
1125
+ body: JSON.stringify(comment),
1126
+ });
1127
+ if (!response.ok) throw new Error('Failed to save comment');
1128
+ }}
1129
+ onError={(error) => console.error(error.code, error.message)}
1130
+ >
1131
+ <ToggleOverlayButton>Toggle Feedback Mode</ToggleOverlayButton>
1132
+ <CreateSession user={currentUser}>Start session</CreateSession>
1133
+ <ConfirmSession>Send feedback</ConfirmSession>
1134
+
1135
+ <CommentOverlay>
1136
+ <YourContent />
1137
+ <CommentRenderer
1138
+ Comment={PublishedComment}
1139
+ DraftComment={DraftComment}
1140
+ ResolvedComment={ResolvedComment}
1141
+ />
1142
+ </CommentOverlay>
1143
+ </CommentContextProvider>
1144
+ </FeedbackSessionProvider>
870
1145
  );
871
1146
  }
872
1147
  ```
873
1148
 
874
- ### With Real-time Subscription
1149
+ ### Resuming a session
1150
+
1151
+ Pass the saved session as `initialSession`. Each of its comments, and each entry of `initialComments`, needs a `sessionId` and a `locationId`. Comments with a `sessionId` other than the `initialSession` id are kept in `initialComments`, but they are not part of the session. They only appear in `commentsBySession`. Comments without a `locationId` are hidden.
875
1152
 
876
1153
  ```tsx
877
- import { useEffect, useState } from 'react';
1154
+ <FeedbackSessionProvider initialSession={savedSession} canResolveSession>
1155
+ <CommentContextProvider
1156
+ locationId={pathname}
1157
+ initialComments={savedSession.comments}
1158
+ initialOverlayState="idle"
1159
+ onError={handleError}
1160
+ >
1161
+ {/* ... */}
1162
+ </CommentContextProvider>
1163
+ </FeedbackSessionProvider>
1164
+ ```
878
1165
 
879
- function App() {
1166
+ `initialComments` is optional. Without it, the provider starts with `initialSession.comments`, from all locations. To show earlier sessions at the current location, add their comments to `initialComments` and read them from `commentsBySession`.
1167
+
1168
+ ### With Real-time Subscription
1169
+
1170
+ ```tsx
1171
+ function App({ pathname }: { pathname: string }) {
880
1172
  const [subscription, setSubscription] = useState(null);
881
-
1173
+
882
1174
  useEffect(() => {
883
1175
  // Example with a WebSocket or real-time database
884
- const sub = {
885
- subscribe: (callback) => {
886
- socket.on('comments:update', callback);
887
- },
888
- unsubscribe: () => {
889
- socket.off('comments:update');
890
- },
891
- };
892
-
893
- setSubscription(sub);
1176
+ setSubscription({
1177
+ subscribe: (callback) => socket.on('comments:update', callback),
1178
+ unsubscribe: () => socket.off('comments:update'),
1179
+ });
894
1180
  }, []);
895
-
1181
+
896
1182
  return (
897
- <CommentContextProvider
898
- currentUser={currentUser}
899
- subscription={subscription}
900
- onConfirm={saveComments}
901
- onResolve={resolveComments}
902
- onError={(error) => console.error(error)}
903
- >
904
- {/* ... */}
905
- </CommentContextProvider>
1183
+ <FeedbackSessionProvider onCreateSession={createSession}>
1184
+ <CommentContextProvider
1185
+ locationId={pathname}
1186
+ currentUser={currentUser}
1187
+ subscription={subscription}
1188
+ onAdd={saveComment}
1189
+ onError={(error) => console.error(error)}
1190
+ >
1191
+ {/* ... */}
1192
+ </CommentContextProvider>
1193
+ </FeedbackSessionProvider>
906
1194
  );
907
1195
  }
908
1196
  ```
@@ -910,61 +1198,45 @@ function App() {
910
1198
  ### Custom Toolbar with Visibility Controls
911
1199
 
912
1200
  ```tsx
913
- import { useComments } from '@kendew-agency/react-feedback-layer';
1201
+ import { useComments, useFeedbackSession } from '@kendew-agency/react-feedback-layer';
914
1202
 
915
1203
  function CommentToolbar() {
916
- const {
917
- draftComments,
918
- resolvingComments,
919
- config,
920
- updateCommentVisibility,
921
- confirmComments,
922
- resolveComments,
923
- overlayState,
924
- } = useComments();
925
-
1204
+ const { draftComments, resolvedComments, config, updateCommentVisibility } =
1205
+ useComments();
1206
+ const { session, sessionState, confirmSession, startResolving, resolveSession } =
1207
+ useFeedbackSession();
1208
+
926
1209
  return (
927
1210
  <div className="toolbar">
928
1211
  <div className="stats">
1212
+ <span>Session: {session?.status ?? 'none'}</span>
929
1213
  <span>{draftComments.length} drafts</span>
930
- <span>{resolvingComments.length} resolving</span>
931
- </div>
932
-
933
- <div className="visibility">
934
- <label>
935
- <input
936
- type="checkbox"
937
- checked={!config?.commentVisibility?.hideResolved}
938
- onChange={(e) =>
939
- updateCommentVisibility({ hideResolved: !e.target.checked })
940
- }
941
- />
942
- Show Resolved
943
- </label>
944
- <label>
945
- <input
946
- type="checkbox"
947
- checked={!config?.commentVisibility?.hideResolving}
948
- onChange={(e) =>
949
- updateCommentVisibility({ hideResolving: !e.target.checked })
950
- }
951
- />
952
- Show Resolving
953
- </label>
1214
+ <span>{resolvedComments.length} resolved</span>
954
1215
  </div>
955
-
1216
+
1217
+ <label>
1218
+ <input
1219
+ type="checkbox"
1220
+ checked={!config?.commentVisibility?.hideResolved}
1221
+ onChange={(e) =>
1222
+ updateCommentVisibility({ hideResolved: !e.target.checked })
1223
+ }
1224
+ />
1225
+ Show Resolved
1226
+ </label>
1227
+
956
1228
  <div className="actions">
957
- <button
958
- onClick={confirmComments}
959
- disabled={draftComments.length === 0 || overlayState === 'saving'}
1229
+ <button
1230
+ onClick={confirmSession}
1231
+ disabled={session?.status !== 'draft' || sessionState !== 'idle'}
960
1232
  >
961
- {overlayState === 'saving' ? 'Saving...' : 'Save Comments'}
1233
+ {sessionState === 'confirming' ? 'Confirming...' : 'Confirm session'}
962
1234
  </button>
963
- <button
964
- onClick={resolveComments}
965
- disabled={resolvingComments.length === 0}
966
- >
967
- Resolve All
1235
+ <button onClick={startResolving} disabled={session?.status !== 'confirmed'}>
1236
+ Start resolving
1237
+ </button>
1238
+ <button onClick={resolveSession} disabled={session?.status !== 'resolving'}>
1239
+ Resolve session
968
1240
  </button>
969
1241
  </div>
970
1242
  </div>
@@ -988,7 +1260,7 @@ function CustomComment({ comment }) {
988
1260
  Save Comment
989
1261
  </MyCustomButton>
990
1262
  </Comment.Confirm>
991
-
1263
+
992
1264
  {/* Render content as a div */}
993
1265
  <Comment.Content asChild>
994
1266
  <div className="rich-text-content" />
@@ -1000,97 +1272,84 @@ function CustomComment({ comment }) {
1000
1272
 
1001
1273
  ## Configuration Options
1002
1274
 
1003
- The `config` prop allows you to customize various aspects of the comment system:
1275
+ The `config` prop of `CommentContextProvider` customizes the comment layer.
1004
1276
 
1005
1277
  ### ID Prefix
1006
1278
 
1007
- Add a custom prefix to all comment IDs:
1008
-
1009
1279
  ```tsx
1010
- <CommentContextProvider
1011
- config={{
1012
- idPrefix: 'proj_a_', // Results in IDs like "proj_a_uuid"
1013
- }}
1014
- // ... other props
1015
- >
1280
+ <CommentContextProvider config={{ idPrefix: 'proj_a_' }} /* "proj_a_uuid" */>
1016
1281
  ```
1017
1282
 
1018
1283
  ### Indicator Visibility
1019
1284
 
1020
- Control when comment indicators (selection boxes) are shown:
1021
-
1022
1285
  ```tsx
1023
1286
  <CommentContextProvider
1024
1287
  config={{
1025
1288
  indicatorVisibility: 'active', // Only show when comment is active
1026
- // or 'always' to always show indicators
1289
+ // or 'always' (default)
1027
1290
  }}
1028
- // ... other props
1029
1291
  >
1030
1292
  ```
1031
1293
 
1032
1294
  ### Comment Visibility
1033
1295
 
1034
- Hide specific types of comments from the UI:
1296
+ Hide resolved comments from the UI:
1035
1297
 
1036
1298
  ```tsx
1037
1299
  <CommentContextProvider
1038
- config={{
1039
- commentVisibility: {
1040
- hideResolved: true, // Hide resolved comments
1041
- hideResolving: false, // Show resolving comments
1042
- },
1043
- }}
1044
- // ... other props
1300
+ config={{ commentVisibility: { hideResolved: true } }}
1045
1301
  >
1046
1302
  ```
1047
1303
 
1048
- You can also update visibility dynamically:
1304
+ Update it dynamically:
1049
1305
 
1050
1306
  ```tsx
1051
1307
  function VisibilityControls() {
1052
1308
  const { config, updateCommentVisibility } = useComments();
1053
-
1309
+
1054
1310
  return (
1055
- <div>
1056
- <label>
1057
- <input
1058
- type="checkbox"
1059
- checked={!config?.commentVisibility?.hideResolved}
1060
- onChange={(e) =>
1061
- updateCommentVisibility({ hideResolved: !e.target.checked })
1062
- }
1063
- />
1064
- Show Resolved Comments
1065
- </label>
1066
- </div>
1311
+ <label>
1312
+ <input
1313
+ type="checkbox"
1314
+ checked={!config?.commentVisibility?.hideResolved}
1315
+ onChange={(e) =>
1316
+ updateCommentVisibility({ hideResolved: !e.target.checked })
1317
+ }
1318
+ />
1319
+ Show Resolved Comments
1320
+ </label>
1067
1321
  );
1068
1322
  }
1069
1323
  ```
1070
1324
 
1325
+ ### Draft Visibility
1326
+
1327
+ See [Draft visibility](#draft-visibility). Default `"visible"`, applies only while the session is a draft.
1328
+
1071
1329
  ## Advanced Patterns
1072
1330
 
1073
1331
  ### Project ID
1074
1332
 
1075
- Attach a project ID to all comments created within an overlay. This is useful for multi-project setups where you need to associate comments with a specific project in your database.
1333
+ Set `projectId` on `FeedbackSessionProvider` to send it to `onCreateSession`, and on `CommentContextProvider` to attach it to every new comment.
1076
1334
 
1077
1335
  ```tsx
1078
- <CommentContextProvider
1079
- currentUser={currentUser}
1336
+ <FeedbackSessionProvider
1080
1337
  projectId="proj_123456789"
1081
- onConfirm={async (comments, projectId) => {
1082
- // projectId is passed through to your callback
1083
- await api.createComments(comments, projectId);
1084
- }}
1085
- onResolve={resolveComments}
1086
- onError={handleError}
1338
+ onCreateSession={({ projectId, user, type }) =>
1339
+ api.createSession({ projectId, user, type })
1340
+ }
1087
1341
  >
1088
- {children}
1089
- </CommentContextProvider>
1342
+ <CommentContextProvider
1343
+ projectId="proj_123456789"
1344
+ locationId={pathname}
1345
+ onAdd={(comment) => api.addComment(comment)} // comment.projectId is set
1346
+ onError={handleError}
1347
+ >
1348
+ {children}
1349
+ </CommentContextProvider>
1350
+ </FeedbackSessionProvider>
1090
1351
  ```
1091
1352
 
1092
- Each comment created within this provider will have the `projectId` field set, which you can use for filtering and organizing comments per project.
1093
-
1094
1353
  ### Programmatic Comment Creation
1095
1354
 
1096
1355
  ```tsx
@@ -1098,18 +1357,18 @@ import { useComments } from '@kendew-agency/react-feedback-layer';
1098
1357
 
1099
1358
  function CustomTool() {
1100
1359
  const { registerComment } = useComments();
1101
-
1360
+
1102
1361
  const addCommentAtElement = (elementId: string) => {
1103
1362
  const element = document.getElementById(elementId);
1104
1363
  if (!element) return;
1105
-
1364
+
1106
1365
  const rect = element.getBoundingClientRect();
1107
1366
  registerComment(
1108
1367
  { x: rect.right, y: rect.bottom },
1109
1368
  { width: rect.width, height: rect.height }
1110
1369
  );
1111
1370
  };
1112
-
1371
+
1113
1372
  return (
1114
1373
  <button onClick={() => addCommentAtElement('target-element')}>
1115
1374
  Comment on Element
@@ -1118,68 +1377,59 @@ function CustomTool() {
1118
1377
  }
1119
1378
  ```
1120
1379
 
1121
- ### Error Handling
1122
-
1123
- The `onError` callback is required and handles all error types, including overlay interaction errors like attempting to add a comment while editing or dismissing an empty comment.
1124
-
1125
- **1. Using the `onError` callback:**
1380
+ `registerComment` needs a `draft` session. Otherwise `onError` receives a `SessionStateError`. It also needs a `locationId` on the provider. Without one, `onError` receives an `AddError` and no draft is created.
1126
1381
 
1127
- ```tsx
1128
- <CommentContextProvider
1129
- currentUser={currentUser}
1130
- onConfirm={saveComments}
1131
- onResolve={resolveComments}
1132
- onError={(error) => {
1133
- console.error('Comment operation failed:', error.code, error.message);
1134
- toast.error(error.message);
1135
- }}
1136
- >
1137
- {children}
1138
- </CommentContextProvider>
1139
- ```
1382
+ ### Error Handling
1140
1383
 
1141
- **2. Handling errors from action results:**
1384
+ Both providers accept an optional `onError`. Every failure is reported there, including overlay interaction errors such as adding a comment while editing. Every action also returns `{ error }`.
1142
1385
 
1143
1386
  ```tsx
1144
- import { useComments } from '@kendew-agency/react-feedback-layer';
1387
+ function ConfirmButton() {
1388
+ const { confirmSession, sessionState } = useFeedbackSession();
1145
1389
 
1146
- function SaveButton() {
1147
- const { confirmComments, overlayState } = useComments();
1148
-
1149
- const handleSave = async () => {
1150
- const { error } = await confirmComments();
1151
-
1390
+ const handleConfirm = async () => {
1391
+ const { error } = await confirmSession();
1152
1392
  if (error) {
1153
- console.error('Failed to save comments:', error);
1154
- alert('Failed to save comments. Please try again.');
1155
- } else {
1156
- alert('Comments saved successfully!');
1393
+ alert(`Failed to confirm: ${error.message}`);
1157
1394
  }
1158
1395
  };
1159
-
1396
+
1160
1397
  return (
1161
- <button
1162
- onClick={handleSave}
1163
- disabled={overlayState === 'saving'}
1164
- >
1165
- {overlayState === 'saving' ? 'Saving...' : 'Save Comments'}
1398
+ <button onClick={handleConfirm} disabled={sessionState === 'confirming'}>
1399
+ {sessionState === 'confirming' ? 'Confirming...' : 'Confirm session'}
1166
1400
  </button>
1167
1401
  );
1168
1402
  }
1169
1403
  ```
1170
1404
 
1171
1405
  #### Error codes
1172
- To keep track of the origin of a comment an error code is provided. You can use this code to display a more accurate error message. For example:
1406
+
1407
+ | Code | Error class | Origin |
1408
+ |------|-------------|--------|
1409
+ | `SESSION_CREATE_ERROR` | `SessionCreateError` | `createSession` or `onCreateSession` failed |
1410
+ | `CONFIRM_ERROR` | `ConfirmError` | `onConfirmSession` failed |
1411
+ | `START_RESOLVING_ERROR` | `StartResolvingError` | `onStartResolving` failed |
1412
+ | `SESSION_RESOLVE_ERROR` | `SessionResolveError` | `onResolveSession` failed |
1413
+ | `SESSION_STATE_ERROR` | `SessionStateError` | The action is not allowed in the current session state |
1414
+ | `PERMISSION_ERROR` | `PermissionError` | `canResolveSession` is `false` |
1415
+ | `ADD_ERROR` | `AddError` | `onAdd` failed, the content is empty or the provider has no `locationId` |
1416
+ | `EDIT_ERROR` | `EditError` | `onEdit` failed |
1417
+ | `DELETE_ERROR` | `DeleteError` | `onDelete` failed |
1418
+ | `RESOLVE_ERROR` | `ResolveError` | `onResolve` failed |
1419
+ | `REOPEN_ERROR` | `ReopenError` | `onReopen` failed |
1420
+ | `INSERT_ERROR` | `InsertError` | The overlay refused to add a comment |
1421
+ | `UNKNOWN_ERROR` | `UnknownError` | Anything else |
1422
+
1173
1423
  ```ts
1174
- switch(e.code){
1175
- case "RESOLVE_ERROR":
1176
- alert('Failed to resolve your comments')
1424
+ switch (error.code) {
1425
+ case "PERMISSION_ERROR":
1426
+ alert('You are not allowed to do this')
1177
1427
  break
1178
- case "CONFIRM_ERROR":
1179
- alert('Failed to submit your comments')
1428
+ case "SESSION_STATE_ERROR":
1429
+ alert('This is not possible in the current session state')
1180
1430
  break
1181
- case "INSERT_ERROR":
1182
- alert('Failed to insert your comment')
1431
+ case "CONFIRM_ERROR":
1432
+ alert('Failed to confirm your session')
1183
1433
  break
1184
1434
  default:
1185
1435
  alert('An unknown error occured')
@@ -1221,6 +1471,64 @@ function CommentList() {
1221
1471
  }
1222
1472
  ```
1223
1473
 
1474
+ ## Migrating from 0.3.x
1475
+
1476
+ Comments now live in feedback sessions, so the batch confirm and resolve flow is gone. Each removed API maps to a replacement:
1477
+
1478
+ | Removed | Replacement |
1479
+ |---------|-------------|
1480
+ | `confirmComments()` from `useComments()` | `confirmSession()` from `useFeedbackSession()` |
1481
+ | `resolveComments()` from `useComments()` | `resolveComment(id)` per comment, then `resolveSession()` from `useFeedbackSession()` |
1482
+ | `onConfirm(comments, projectId)` on `CommentContextProvider` | `onAdd(comment)` per comment on `CommentContextProvider`, and `onConfirmSession(sessionId, type)` on `FeedbackSessionProvider` |
1483
+ | `onResolve(comments[])` on `CommentContextProvider` | `onResolve(comment)` for a single comment on `CommentContextProvider`, and `onResolveSession(sessionId)` on `FeedbackSessionProvider` |
1484
+ | `<ConfirmComments />` | `<ConfirmSession />` |
1485
+ | `<ResolveComments />` | `<ResolveSession />`, and `<Comment.Resolve />` per comment |
1486
+ | `events.onCommentsConfirmed` | `events.onCommentAdded` (per comment) and `useFeedbackSession().events.onSessionConfirmed` |
1487
+ | `events.onCommentsResolved` | `events.onCommentResolved` (per comment) and `useFeedbackSession().events.onSessionResolved` |
1488
+ | `toggleResolvingComment(id)` | `startResolving()` for the session, then `resolveComment(id)` and `reopenComment(id)` |
1489
+
1490
+ Other breaking changes:
1491
+
1492
+ - **A session provider is required.** `CommentContextProvider` and `useComments()` throw without a `FeedbackSessionProvider`. Using the comment layer standalone, without a session provider, is no longer possible.
1493
+ - **The `resolving` comment status is removed.** `CommentType["status"]` is now `"draft" | "published" | "resolved"`. The resolving phase belongs to the session (`SessionStatus` `"resolving"`).
1494
+ - **`resolvingComments` is removed** from `useComments()`.
1495
+ - **The `hideResolving` filter is removed** from `CommentVisibility` and `config.commentVisibility`. Only `hideResolved` remains.
1496
+ - **The `ResolvingComment` prop is removed** from `CommentRenderer`. Pass `Comment`, `DraftComment` and `ResolvedComment`.
1497
+ - **`initialComments` need a `sessionId` and a `locationId`.** Comments with the `initialSession` id are part of the session. Comments of another session are kept, but they only appear in `commentsBySession`. Without an active session the overlay shows no comments.
1498
+ - **`CommentType` and `ConfirmedComment` have a required `sessionId` and a required `locationId`** field. Comments without a `locationId` are hidden and ignored by `confirmSession` and `resolveSession`. Add a `locationId` to existing stored comments.
1499
+ - **`CommentContextProvider` needs a `locationId`** to show comments or create them. Without it no comments are shown and `registerComment` reports an `AddError`.
1500
+ - **`onError` is optional** on both providers.
1501
+
1502
+ Before:
1503
+
1504
+ ```tsx
1505
+ <CommentContextProvider
1506
+ currentUser={user}
1507
+ onConfirm={(comments, projectId) => api.createComments(comments, projectId)}
1508
+ onResolve={(comments) => api.resolveComments(comments)}
1509
+ onError={handleError}
1510
+ >
1511
+ ```
1512
+
1513
+ After:
1514
+
1515
+ ```tsx
1516
+ <FeedbackSessionProvider
1517
+ canResolveSession={isReviewer}
1518
+ onCreateSession={api.createSession}
1519
+ onConfirmSession={(sessionId) => api.confirmSession(sessionId)}
1520
+ onResolveSession={(sessionId) => api.resolveSession(sessionId)}
1521
+ onError={handleError}
1522
+ >
1523
+ <CommentContextProvider
1524
+ locationId={pathname}
1525
+ currentUser={user}
1526
+ onAdd={(comment) => api.addComment(comment)}
1527
+ onResolve={(comment) => api.resolveComment(comment)}
1528
+ onError={handleError}
1529
+ >
1530
+ ```
1531
+
1224
1532
  ## Styling
1225
1533
 
1226
1534
  This library is completely unstyled (headless). Here's a basic CSS example to get started:
@@ -1301,6 +1609,8 @@ const comment: CommentType = {
1301
1609
  user,
1302
1610
  createdAt: new Date(),
1303
1611
  status: 'published',
1612
+ sessionId: 'session-1',
1613
+ locationId: 'page-a',
1304
1614
  };
1305
1615
  ```
1306
1616
 
@@ -1350,6 +1660,17 @@ MIT © [Kendew Agency](https://github.com/Kendew-Agency)
1350
1660
 
1351
1661
  A list if breaking changes that could impact the way you configured the package
1352
1662
 
1663
+ ### Unreleased
1664
+
1665
+ - Added feedback sessions. See [Feedback Sessions](#feedback-sessions) and the [migration guide](#migrating-from-03x). `FeedbackSessionProvider` is now required around `CommentContextProvider`.
1666
+ - Added `FeedbackSessionProvider`, `useFeedbackSession()`, `CreateSession` (takes a required `user` prop), `ConfirmSession`, `StartResolving`, `ResolveSession` and `Comment.Reopen`.
1667
+ - `createSession` takes the user explicitly through `options.user`. There is no user provider: pass `currentUser` to `CommentContextProvider` and `user` to `createSession` or `<CreateSession user>`.
1668
+ - Added the `onAdd`, `onEdit`, `onDelete` and `onReopen` callbacks, a single-comment `onResolve`, `resolveComment`, `reopenComment`, `canResolve` and the `config.draftVisibility` option.
1669
+ - Added the session events `onSessionCreated`, `onSessionConfirmed`, `onSessionResolving` and `onSessionResolved`, and the comment events `onCommentAdded`, `onCommentEdited`, `onCommentResolved` and `onCommentReopened`.
1670
+ - Breaking: removed `confirmComments`, `resolveComments`, `onConfirm`, array `onResolve`, `ConfirmComments`, `ResolveComments`, `onCommentsConfirmed` and `onCommentsResolved`. Removed the `resolving` comment status, `resolvingComments`, the `hideResolving` filter and the `ResolvingComment` renderer prop. Standalone use without a session provider is no longer possible. `initialComments` need a `sessionId` and a `locationId`.
1671
+ - Added multi-location sessions. See [Sessions across multiple locations](#sessions-across-multiple-locations). Added the `locationId` prop on `CommentContextProvider` and `commentsBySession` on `useComments()`. `confirmSession` and `resolveSession` check the comments of all locations.
1672
+ - Breaking: `locationId` is a required string on `CommentType` and `ConfirmedComment`. A comment is shown only when its `locationId` equals the provider's `locationId` and its `sessionId` equals the active session id. Existing stored comments need a `locationId`, or they are hidden and ignored by `confirmSession` and `resolveSession`. A provider without a `locationId` shows no comments, and `registerComment` reports an `AddError`.
1673
+
1353
1674
  ### 0.3.2
1354
1675
  - Added `withPosition` prop to `Comment.Root`. It defaults to `true`, so existing behavior is unchanged. Set it to `false` to skip the absolute positioning styles (`position`, `top`, `left`), for example when rendering comments in a list.
1355
1676