@kendew-agency/react-feedback-layer 0.4.0-rc.0 → 0.4.0-rc.2

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/index.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
 
7
7
  // src/contexts/comment-context.tsx
8
8
  import {
9
- createContext as createContext3,
10
- useContext as useContext3,
9
+ createContext as createContext2,
10
+ useContext as useContext2,
11
11
  useEffect as useEffect2,
12
12
  useId,
13
13
  useReducer as useReducer2,
@@ -145,37 +145,89 @@ var useCommentEvents = () => {
145
145
 
146
146
  // src/utils/select-visible-comments.ts
147
147
  var normalizeDraftVisibility = (value) => value === "hidden" ? "hidden" : "visible";
148
+ var isLocated = (comment) => typeof comment.locationId === "string" && comment.locationId.length > 0;
149
+ var normalizeLocationId = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
150
+ var applyDraftFilter = (comments, session, draftVisibility, currentUserId) => {
151
+ if (session.status !== "draft" || normalizeDraftVisibility(draftVisibility) !== "hidden") {
152
+ return comments;
153
+ }
154
+ return comments.filter((comment) => {
155
+ if (comment.status === "draft") {
156
+ return true;
157
+ }
158
+ const authorId = comment.user?.id;
159
+ return authorId === void 0 || authorId === currentUserId;
160
+ });
161
+ };
162
+ var selectCommentsByLocation = ({
163
+ comments,
164
+ locationId
165
+ }) => {
166
+ const location = normalizeLocationId(locationId);
167
+ if (location === void 0) {
168
+ return [];
169
+ }
170
+ return comments.filter(
171
+ (comment) => isLocated(comment) && comment.locationId === location
172
+ );
173
+ };
148
174
  var selectVisibleComments = ({
149
175
  comments,
150
176
  session,
177
+ locationId,
151
178
  draftVisibility = "visible",
152
179
  currentUserId
153
180
  }) => {
154
181
  if (session === null) {
155
182
  return [];
156
183
  }
157
- const inSession = comments.filter(
184
+ const inSession = selectCommentsByLocation({ comments, locationId }).filter(
158
185
  (comment) => comment.sessionId === session.id
159
186
  );
160
- if (session.status !== "draft" || normalizeDraftVisibility(draftVisibility) !== "hidden") {
161
- return inSession;
187
+ return applyDraftFilter(inSession, session, draftVisibility, currentUserId);
188
+ };
189
+ var selectCommentsBySession = ({
190
+ comments,
191
+ locationId,
192
+ session,
193
+ draftVisibility = "visible",
194
+ currentUserId
195
+ }) => {
196
+ const grouped = {};
197
+ for (const comment of selectCommentsByLocation({ comments, locationId })) {
198
+ const list = grouped[comment.sessionId];
199
+ if (list) {
200
+ list.push(comment);
201
+ } else {
202
+ grouped[comment.sessionId] = [comment];
203
+ }
162
204
  }
163
- return inSession.filter((comment) => {
164
- if (comment.status === "draft") {
165
- return true;
205
+ if (session !== null) {
206
+ const active = grouped[session.id];
207
+ if (active) {
208
+ const filtered = applyDraftFilter(
209
+ active,
210
+ session,
211
+ draftVisibility,
212
+ currentUserId
213
+ );
214
+ if (filtered.length === 0) {
215
+ delete grouped[session.id];
216
+ } else {
217
+ grouped[session.id] = filtered;
218
+ }
166
219
  }
167
- const authorId = comment.user?.id;
168
- return authorId === void 0 || authorId === currentUserId;
169
- });
220
+ }
221
+ return grouped;
170
222
  };
171
223
 
172
224
  // src/contexts/feedback-session-context.tsx
173
225
  import {
174
- createContext as createContext2,
226
+ createContext,
175
227
  useCallback as useCallback3,
176
- useContext as useContext2,
228
+ useContext,
177
229
  useEffect,
178
- useMemo as useMemo2,
230
+ useMemo,
179
231
  useReducer,
180
232
  useRef as useRef3
181
233
  } from "react";
@@ -215,6 +267,45 @@ var useSessionEvents = () => {
215
267
  return { events, emit };
216
268
  };
217
269
 
270
+ // src/utils/session-type.ts
271
+ var SESSION_TYPES = ["feedback"];
272
+ var isSessionType = (value) => SESSION_TYPES.includes(value);
273
+ var SESSION_STATUSES = [
274
+ "draft",
275
+ "confirmed",
276
+ "resolving",
277
+ "resolved"
278
+ ];
279
+ var parseInitialSession = (value) => {
280
+ if (value === null || typeof value !== "object") return null;
281
+ const status = value.status;
282
+ if (!SESSION_STATUSES.includes(status)) return null;
283
+ const session = value;
284
+ return {
285
+ ...value,
286
+ comments: session.comments ?? []
287
+ };
288
+ };
289
+
290
+ // src/utils/session-guards.ts
291
+ var locatedComments = (session) => session.comments.filter(isLocated);
292
+ var confirmRefusal = (session, localDrafts) => {
293
+ if (!session || session.status !== "draft") return "session is not a draft";
294
+ if (localDrafts > 0) return "a local draft comment exists";
295
+ if (locatedComments(session).length === 0) return "session has no comments";
296
+ if (!isSessionType(session.type)) return "unknown session type";
297
+ return null;
298
+ };
299
+ var resolveRefusal = (session) => {
300
+ if (session?.status !== "resolving") return "session is not resolving";
301
+ return locatedComments(session).some((c) => c.status === "published") ? "a comment is still published" : null;
302
+ };
303
+ var sumCounts = (counts) => {
304
+ let total = 0;
305
+ for (const count of counts.values()) total += count;
306
+ return total;
307
+ };
308
+
218
309
  // src/utils/session-reducer.ts
219
310
  var initialSessionReducerState = {
220
311
  session: null,
@@ -307,82 +398,25 @@ var sessionReducer = (state, action) => {
307
398
  }
308
399
  };
309
400
 
310
- // src/utils/session-type.ts
311
- var SESSION_TYPES = ["feedback"];
312
- var isSessionType = (value) => SESSION_TYPES.includes(value);
313
- var SESSION_STATUSES = [
314
- "draft",
315
- "confirmed",
316
- "resolving",
317
- "resolved"
318
- ];
319
- var parseInitialSession = (value) => {
320
- if (value === null || typeof value !== "object") return null;
321
- const status = value.status;
322
- if (!SESSION_STATUSES.includes(status)) return null;
323
- const session = value;
324
- return {
325
- ...value,
326
- comments: session.comments ?? []
327
- };
328
- };
329
-
330
- // src/contexts/user-context.tsx
331
- import * as React from "react";
332
- import { jsx } from "react/jsx-runtime";
333
- var UserContext = React.createContext(
334
- void 0
335
- );
336
- var UserProvider = ({ user, children }) => {
337
- const value = React.useMemo(
338
- () => ({ currentUser: user }),
339
- [user]
340
- );
341
- return /* @__PURE__ */ jsx(UserContext.Provider, { value, children });
342
- };
343
- var useCurrentUser = () => {
344
- const ctx = React.useContext(UserContext);
345
- if (!ctx) {
346
- throw new Error("useCurrentUser must be used within <UserProvider />");
347
- }
348
- return ctx.currentUser;
349
- };
350
- var useOptionalCurrentUser = () => {
351
- const ctx = React.useContext(UserContext);
352
- return ctx ? ctx.currentUser : void 0;
353
- };
354
-
355
401
  // src/contexts/feedback-session-context.tsx
356
- import { jsx as jsx2 } from "react/jsx-runtime";
357
- var FeedbackSessionContext = createContext2(
402
+ import { jsx } from "react/jsx-runtime";
403
+ var FeedbackSessionContext = createContext(
358
404
  null
359
405
  );
360
- var SessionBridgeContext = createContext2(null);
406
+ var SessionBridgeContext = createContext(null);
361
407
  var MAX_PROJECT_ID_LENGTH = 128;
362
408
  var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
363
409
  var pick = (value, fallback) => value !== void 0 ? value : fallback;
364
- var createRefusal = (type, projectId, inFlight, session, hasCallback) => {
410
+ var createRefusal = (type, projectId, inFlight, hasCallback, user) => {
411
+ if (!user) return "user is required";
365
412
  if (!isSessionType(type)) return "unknown session type";
366
413
  if (!isValidProjectId(projectId)) {
367
414
  return "projectId must be 1 to 128 characters";
368
415
  }
369
416
  if (inFlight === "creating") return "creation already in progress";
370
- if (session?.status === "draft") return "draft session already exists";
371
417
  if (!hasCallback) return "onCreateSession is not provided";
372
418
  return null;
373
419
  };
374
- var confirmRefusal = (session, localDrafts) => {
375
- if (!session || session.status !== "draft") return "session is not a draft";
376
- if (localDrafts > 0) return "a local draft comment exists";
377
- if (session.comments.length === 0) return "session has no comments";
378
- if (!isSessionType(session.type)) return "unknown session type";
379
- return null;
380
- };
381
- var sumCounts = (counts) => {
382
- let total = 0;
383
- for (const count of counts.values()) total += count;
384
- return total;
385
- };
386
420
  var FeedbackSessionProvider = ({
387
421
  children,
388
422
  initialSession,
@@ -394,7 +428,6 @@ var FeedbackSessionProvider = ({
394
428
  onResolveSession,
395
429
  onError
396
430
  }) => {
397
- const contextUser = useOptionalCurrentUser();
398
431
  const initialParsedRef = useRef3(
399
432
  void 0
400
433
  );
@@ -435,14 +468,14 @@ var FeedbackSessionProvider = ({
435
468
  const createSession = useCallback3(
436
469
  async (options) => {
437
470
  const type = options?.type ?? "feedback";
438
- const user = pick(options?.user, contextUser);
471
+ const user = options?.user;
439
472
  const sessionProjectId = pick(options?.projectId, projectId);
440
473
  const refusal = createRefusal(
441
474
  type,
442
475
  sessionProjectId,
443
476
  inFlightRef.current,
444
- stateRef.current.session,
445
- onCreateSession !== void 0
477
+ onCreateSession !== void 0,
478
+ user
446
479
  );
447
480
  if (refusal !== null || !onCreateSession) {
448
481
  const error = new SessionCreateError(refusal ?? void 0);
@@ -454,7 +487,7 @@ var FeedbackSessionProvider = ({
454
487
  try {
455
488
  const input = {
456
489
  type,
457
- user: user ?? null,
490
+ user,
458
491
  projectId: sessionProjectId
459
492
  };
460
493
  const { data, error } = await tx.executeAsync(
@@ -477,7 +510,7 @@ var FeedbackSessionProvider = ({
477
510
  apply({ type: "SET_OPERATION_STATE", to: "idle" });
478
511
  }
479
512
  },
480
- [apply, contextUser, emit, onCreateSession, projectId, report]
513
+ [apply, emit, onCreateSession, projectId, report]
481
514
  );
482
515
  const confirmSession = useCallback3(async () => {
483
516
  if (inFlightRef.current === "confirming") return { error: null };
@@ -563,11 +596,7 @@ var FeedbackSessionProvider = ({
563
596
  const resolveSession = useCallback3(
564
597
  () => runTransition({
565
598
  pending: "completingResolution",
566
- guard: (session) => {
567
- if (session?.status !== "resolving")
568
- return "session is not resolving";
569
- return session.comments.some((c) => c.status === "published") ? "a comment is still published" : null;
570
- },
599
+ guard: resolveRefusal,
571
600
  call: onResolveSession,
572
601
  failure: SessionResolveError,
573
602
  commit: () => {
@@ -597,7 +626,7 @@ var FeedbackSessionProvider = ({
597
626
  },
598
627
  []
599
628
  );
600
- const bridge = useMemo2(
629
+ const bridge = useMemo(
601
630
  () => ({
602
631
  session: state.session,
603
632
  canResolve: canResolveSession,
@@ -625,10 +654,10 @@ var FeedbackSessionProvider = ({
625
654
  resolveSession,
626
655
  events
627
656
  };
628
- return /* @__PURE__ */ jsx2(FeedbackSessionContext.Provider, { value, children: /* @__PURE__ */ jsx2(SessionBridgeContext.Provider, { value: bridge, children }) });
657
+ return /* @__PURE__ */ jsx(FeedbackSessionContext.Provider, { value, children: /* @__PURE__ */ jsx(SessionBridgeContext.Provider, { value: bridge, children }) });
629
658
  };
630
659
  var useFeedbackSession = () => {
631
- const context = useContext2(FeedbackSessionContext);
660
+ const context = useContext(FeedbackSessionContext);
632
661
  if (!context) {
633
662
  throw new Error(
634
663
  "useFeedbackSession must be used within a FeedbackSessionProvider"
@@ -637,7 +666,7 @@ var useFeedbackSession = () => {
637
666
  return context;
638
667
  };
639
668
  var useSessionBridge = () => {
640
- const bridge = useContext2(SessionBridgeContext);
669
+ const bridge = useContext(SessionBridgeContext);
641
670
  if (!bridge) {
642
671
  throw new Error(
643
672
  "CommentContextProvider must be used within a FeedbackSessionProvider"
@@ -647,8 +676,8 @@ var useSessionBridge = () => {
647
676
  };
648
677
 
649
678
  // src/contexts/comment-context.tsx
650
- import { jsx as jsx3 } from "react/jsx-runtime";
651
- var CommentContext = createContext3(null);
679
+ import { jsx as jsx2 } from "react/jsx-runtime";
680
+ var CommentContext = createContext2(null);
652
681
  var commentReducer = (state, action) => {
653
682
  switch (action.type) {
654
683
  case "REGISTER": {
@@ -662,6 +691,7 @@ var commentReducer = (state, action) => {
662
691
  {
663
692
  id: newId,
664
693
  sessionId: action.sessionId,
694
+ locationId: action.locationId,
665
695
  projectId: state.projectId,
666
696
  user: state.currentUser,
667
697
  position: {
@@ -771,6 +801,7 @@ var CommentContextProvider = ({
771
801
  }
772
802
  },
773
803
  projectId,
804
+ locationId: locationIdProp,
774
805
  onError,
775
806
  onAdd,
776
807
  onEdit,
@@ -778,6 +809,9 @@ var CommentContextProvider = ({
778
809
  onResolve,
779
810
  onReopen
780
811
  }) => {
812
+ const locationId = normalizeLocationId(locationIdProp);
813
+ const locationIdRef = useRef4(locationId);
814
+ locationIdRef.current = locationId;
781
815
  const hostRef = useRef4({ onAdd, onEdit, onDelete, onResolve, onReopen });
782
816
  hostRef.current = { onAdd, onEdit, onDelete, onResolve, onReopen };
783
817
  const bridge = useSessionBridge();
@@ -785,8 +819,7 @@ var CommentContextProvider = ({
785
819
  bridgeRef.current = bridge;
786
820
  const canResolveRef = useRef4(bridge.canResolve);
787
821
  canResolveRef.current = bridge.canResolve;
788
- const contextUser = useOptionalCurrentUser();
789
- const currentUser = contextUser !== void 0 ? contextUser : currentUserProp ?? null;
822
+ const currentUser = currentUserProp ?? null;
790
823
  const currentUserRef = useRef4(currentUser);
791
824
  currentUserRef.current = currentUser;
792
825
  const [state, dispatch] = useReducer2(
@@ -830,9 +863,15 @@ var CommentContextProvider = ({
830
863
  onError?.(new SessionStateError());
831
864
  return;
832
865
  }
866
+ const currentLocationId = locationIdRef.current;
867
+ if (currentLocationId === void 0) {
868
+ onError?.(new AddError("locationId is missing"));
869
+ return;
870
+ }
833
871
  dispatch({
834
872
  type: "REGISTER",
835
873
  sessionId: session.id,
874
+ locationId: currentLocationId,
836
875
  position,
837
876
  indicatorPosition: indicatorPosition || null
838
877
  });
@@ -1006,9 +1045,18 @@ var CommentContextProvider = ({
1006
1045
  const toggleOverlay = () => {
1007
1046
  dispatch({ type: "TOGGLE_OVERLAY" });
1008
1047
  };
1048
+ const activeSession = bridge.session ? { id: bridge.session.id, status: bridge.session.status } : null;
1009
1049
  const visibleComments = selectVisibleComments({
1010
1050
  comments: state.comments,
1011
- session: bridge.session ? { id: bridge.session.id, status: bridge.session.status } : null,
1051
+ session: activeSession,
1052
+ locationId,
1053
+ draftVisibility: state.config?.draftVisibility,
1054
+ currentUserId: currentUser?.id
1055
+ });
1056
+ const commentsBySession = selectCommentsBySession({
1057
+ comments: state.comments,
1058
+ locationId,
1059
+ session: activeSession,
1012
1060
  draftVisibility: state.config?.draftVisibility,
1013
1061
  currentUserId: currentUser?.id
1014
1062
  });
@@ -1023,7 +1071,7 @@ var CommentContextProvider = ({
1023
1071
  onError(error);
1024
1072
  }
1025
1073
  };
1026
- return /* @__PURE__ */ jsx3(
1074
+ return /* @__PURE__ */ jsx2(
1027
1075
  CommentContext.Provider,
1028
1076
  {
1029
1077
  value: {
@@ -1031,6 +1079,7 @@ var CommentContextProvider = ({
1031
1079
  comments: visibleComments.filter(hasStatus("published")),
1032
1080
  resolvedComments: visibleComments.filter(hasStatus("resolved")),
1033
1081
  allComments: visibleComments,
1082
+ commentsBySession,
1034
1083
  config: state.config,
1035
1084
  changeOverlayState,
1036
1085
  overlayState: state.overlayState,
@@ -1054,7 +1103,7 @@ var CommentContextProvider = ({
1054
1103
  };
1055
1104
  var useComments = () => {
1056
1105
  useSessionBridge();
1057
- const context = useContext3(CommentContext);
1106
+ const context = useContext2(CommentContext);
1058
1107
  if (!context) {
1059
1108
  throw new Error("useComments must be used within a CommentContextProvider");
1060
1109
  }
@@ -1075,7 +1124,7 @@ var normalizeRect = (a, b) => {
1075
1124
  };
1076
1125
 
1077
1126
  // src/components/comment-overlay.tsx
1078
- import { jsx as jsx4, jsxs } from "react/jsx-runtime";
1127
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
1079
1128
  var DRAG_THRESHOLD = 4;
1080
1129
  var CommentOverlay = ({ children, ...rest }) => {
1081
1130
  const {
@@ -1151,7 +1200,7 @@ var CommentOverlay = ({ children, ...rest }) => {
1151
1200
  };
1152
1201
  if (overlayState === "inactive") return children;
1153
1202
  return /* @__PURE__ */ jsxs("div", { "data-overlay": true, style: { position: "relative", ...rest.style }, ...rest, children: [
1154
- /* @__PURE__ */ jsx4(
1203
+ /* @__PURE__ */ jsx3(
1155
1204
  "div",
1156
1205
  {
1157
1206
  ref: overlayRef,
@@ -1165,7 +1214,7 @@ var CommentOverlay = ({ children, ...rest }) => {
1165
1214
  }
1166
1215
  ),
1167
1216
  getActiveComment() && // biome-ignore lint: This element should only handle clicks as a guard
1168
- /* @__PURE__ */ jsx4(
1217
+ /* @__PURE__ */ jsx3(
1169
1218
  "div",
1170
1219
  {
1171
1220
  "data-comment-guard": true,
@@ -1173,7 +1222,7 @@ var CommentOverlay = ({ children, ...rest }) => {
1173
1222
  if (getActiveComment()?.content === "") {
1174
1223
  triggerError(
1175
1224
  new InsertError(
1176
- "Comment is empty, either delete the comment or add some content"
1225
+ "A draft comment is still open. Either delete it or confirm it before adding a new comment"
1177
1226
  )
1178
1227
  );
1179
1228
  return;
@@ -1191,7 +1240,7 @@ var CommentOverlay = ({ children, ...rest }) => {
1191
1240
  }
1192
1241
  }
1193
1242
  ),
1194
- preview && /* @__PURE__ */ jsx4(
1243
+ preview && /* @__PURE__ */ jsx3(
1195
1244
  "div",
1196
1245
  {
1197
1246
  style: {
@@ -1223,41 +1272,35 @@ var EDITING_STYLES = {
1223
1272
  };
1224
1273
 
1225
1274
  // src/components/comment-renderer.tsx
1226
- import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1275
+ import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1227
1276
  var CommentRenderer = ({
1228
1277
  Comment: Comment2,
1229
1278
  DraftComment,
1230
1279
  ResolvedComment
1231
1280
  }) => {
1232
- const {
1233
- comments,
1234
- draftComments,
1235
- overlayState,
1236
- resolvedComments,
1237
- config
1238
- } = useComments();
1281
+ const { comments, draftComments, overlayState, resolvedComments, config } = useComments();
1239
1282
  if (overlayState === "inactive") return null;
1240
1283
  return /* @__PURE__ */ jsxs2(Fragment, { children: [
1241
1284
  draftComments.map((comment) => {
1242
- return /* @__PURE__ */ jsx5(DraftComment, { comment }, comment.id);
1285
+ return /* @__PURE__ */ jsx4(DraftComment, { comment }, comment.id);
1243
1286
  }),
1244
1287
  comments.map((comment) => {
1245
- return /* @__PURE__ */ jsx5(Comment2, { comment }, comment.id);
1288
+ return /* @__PURE__ */ jsx4(Comment2, { comment }, comment.id);
1246
1289
  }),
1247
1290
  resolvedComments.map((comment) => {
1248
1291
  if (config?.commentVisibility?.hideResolved) return null;
1249
- return /* @__PURE__ */ jsx5(ResolvedComment, { comment }, comment.id);
1292
+ return /* @__PURE__ */ jsx4(ResolvedComment, { comment }, comment.id);
1250
1293
  })
1251
1294
  ] });
1252
1295
  };
1253
1296
 
1254
1297
  // src/components/comment-actions.tsx
1255
1298
  import { Slot } from "@radix-ui/react-slot";
1256
- import { jsx as jsx6 } from "react/jsx-runtime";
1299
+ import { jsx as jsx5 } from "react/jsx-runtime";
1257
1300
  var ToggleOverlayButton = ({ asChild, ...rest }) => {
1258
1301
  const { toggleOverlay, overlayState } = useComments();
1259
1302
  const Comp = asChild ? Slot : "button";
1260
- return /* @__PURE__ */ jsx6(
1303
+ return /* @__PURE__ */ jsx5(
1261
1304
  Comp,
1262
1305
  {
1263
1306
  "data-active": overlayState !== "inactive",
@@ -1277,12 +1320,12 @@ import {
1277
1320
  import { Slot as Slot2 } from "@radix-ui/react-slot";
1278
1321
 
1279
1322
  // src/contexts/scoped-comment.tsx
1280
- import * as React2 from "react";
1281
- var CommentScopeContext = React2.createContext(
1323
+ import * as React from "react";
1324
+ var CommentScopeContext = React.createContext(
1282
1325
  null
1283
1326
  );
1284
1327
  function useCommentScope() {
1285
- const ctx = React2.useContext(CommentScopeContext);
1328
+ const ctx = React.useContext(CommentScopeContext);
1286
1329
  if (!ctx) {
1287
1330
  throw new Error("Comment.* must be used within <Comment.Root />");
1288
1331
  }
@@ -1290,7 +1333,7 @@ function useCommentScope() {
1290
1333
  }
1291
1334
 
1292
1335
  // src/components/comment.tsx
1293
- import { jsx as jsx7 } from "react/jsx-runtime";
1336
+ import { jsx as jsx6 } from "react/jsx-runtime";
1294
1337
  var CommentRoot = ({
1295
1338
  comment,
1296
1339
  defaultDraft,
@@ -1301,16 +1344,21 @@ var CommentRoot = ({
1301
1344
  const { getActiveComment } = useComments();
1302
1345
  const isActive = getActiveComment()?.id === comment.id;
1303
1346
  const [draft, setDraft] = useState2(defaultDraft ?? comment.content ?? "");
1347
+ const [prevContent, setPrevContent] = useState2(comment.content);
1348
+ if (prevContent !== comment.content) {
1349
+ setPrevContent(comment.content);
1350
+ setDraft(comment.content ?? "");
1351
+ }
1304
1352
  const positionStyles = {
1305
1353
  position: "absolute",
1306
1354
  top: comment.position.y,
1307
1355
  left: comment.position.x
1308
1356
  };
1309
- return /* @__PURE__ */ jsx7(
1357
+ return /* @__PURE__ */ jsx6(
1310
1358
  CommentScopeContext.Provider,
1311
1359
  {
1312
1360
  value: { comment, isActive, draft, setDraft },
1313
- children: /* @__PURE__ */ jsx7(
1361
+ children: /* @__PURE__ */ jsx6(
1314
1362
  "div",
1315
1363
  {
1316
1364
  ...rest,
@@ -1332,7 +1380,7 @@ var CommentIndicator = ({ ...rest }) => {
1332
1380
  const { config } = useComments();
1333
1381
  if (!comment.indicator) return null;
1334
1382
  if (config?.indicatorVisibility === "active" && !isActive) return null;
1335
- return /* @__PURE__ */ jsx7(
1383
+ return /* @__PURE__ */ jsx6(
1336
1384
  "div",
1337
1385
  {
1338
1386
  ...rest,
@@ -1352,14 +1400,14 @@ var CommentIndicator = ({ ...rest }) => {
1352
1400
  );
1353
1401
  };
1354
1402
  var CommentContent = ({ asChild, ...rest }) => {
1355
- const { draft } = useCommentScope();
1403
+ const { comment } = useCommentScope();
1356
1404
  const Comp = asChild ? Slot2 : "p";
1357
- return /* @__PURE__ */ jsx7(Comp, { ...rest, children: draft });
1405
+ return /* @__PURE__ */ jsx6(Comp, { ...rest, children: comment.content });
1358
1406
  };
1359
1407
  var CommentEdit = ({ asChild, ...rest }) => {
1360
1408
  const { draft, setDraft } = useCommentScope();
1361
1409
  const Comp = asChild ? Slot2 : "textarea";
1362
- return /* @__PURE__ */ jsx7(
1410
+ return /* @__PURE__ */ jsx6(
1363
1411
  Comp,
1364
1412
  {
1365
1413
  ...rest,
@@ -1377,7 +1425,7 @@ var CommentConfirm = ({ asChild, ...rest }) => {
1377
1425
  const { updateComment } = useComments();
1378
1426
  const { comment, draft } = useCommentScope();
1379
1427
  const Comp = asChild ? Slot2 : "button";
1380
- return /* @__PURE__ */ jsx7(
1428
+ return /* @__PURE__ */ jsx6(
1381
1429
  Comp,
1382
1430
  {
1383
1431
  ...rest,
@@ -1393,7 +1441,7 @@ var CommentDelete = ({ asChild, ...rest }) => {
1393
1441
  const { deleteComment } = useComments();
1394
1442
  const { comment } = useCommentScope();
1395
1443
  const Comp = asChild ? Slot2 : "button";
1396
- return /* @__PURE__ */ jsx7(
1444
+ return /* @__PURE__ */ jsx6(
1397
1445
  Comp,
1398
1446
  {
1399
1447
  ...rest,
@@ -1420,7 +1468,7 @@ var CommentResolve = ({ asChild, ...rest }) => {
1420
1468
  );
1421
1469
  return null;
1422
1470
  }
1423
- return /* @__PURE__ */ jsx7(
1471
+ return /* @__PURE__ */ jsx6(
1424
1472
  Comp,
1425
1473
  {
1426
1474
  ...rest,
@@ -1447,7 +1495,7 @@ var CommentReopen = ({ asChild, ...rest }) => {
1447
1495
  );
1448
1496
  return null;
1449
1497
  }
1450
- return /* @__PURE__ */ jsx7(
1498
+ return /* @__PURE__ */ jsx6(
1451
1499
  Comp,
1452
1500
  {
1453
1501
  ...rest,
@@ -1463,7 +1511,7 @@ var Comment = {
1463
1511
  * The root component for a comment, must be used to wrap all other comment components.
1464
1512
  *
1465
1513
  * @param comment as the current comment from the comments array
1466
- * @param defaultDraft as the optional initial value for the comment edit state
1514
+ * @param defaultDraft as the optional initial value for the edit state of `Comment.Edit`. It only seeds the draft on mount and does not affect `Comment.Content`. The draft resets to `comment.content` whenever that changes
1467
1515
  * @param withPosition as whether to inject positioning styles from the comment's position. Disable if you want to display the comment in a list. Defaults to true
1468
1516
  */
1469
1517
  // biome-ignore lint/style/useNamingConvention: Modular export
@@ -1476,9 +1524,9 @@ var Comment = {
1476
1524
  // biome-ignore lint/style/useNamingConvention: Modular export
1477
1525
  Indicator: CommentIndicator,
1478
1526
  /**
1479
- * The comment's static safed content
1527
+ * The comment's static saved content
1480
1528
  *
1481
- * @description Displays the comment's content as a `<p>` tag
1529
+ * @description Displays the saved `comment.content` as a `<p>` tag. Text typed in `Comment.Edit` is not shown until it is confirmed, so a draft comment renders empty until then
1482
1530
  * @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
1483
1531
  */
1484
1532
  // biome-ignore lint/style/useNamingConvention: Modular export
@@ -1527,16 +1575,16 @@ var Comment = {
1527
1575
 
1528
1576
  // src/components/session-actions.tsx
1529
1577
  import { Slot as Slot3 } from "@radix-ui/react-slot";
1530
- import { jsx as jsx8 } from "react/jsx-runtime";
1531
- var CreateSession = ({ asChild, ...rest }) => {
1578
+ import { jsx as jsx7 } from "react/jsx-runtime";
1579
+ var CreateSession = ({ asChild, user, ...rest }) => {
1532
1580
  const { createSession } = useFeedbackSession();
1533
1581
  const Comp = asChild ? Slot3 : "button";
1534
- return /* @__PURE__ */ jsx8(
1582
+ return /* @__PURE__ */ jsx7(
1535
1583
  Comp,
1536
1584
  {
1537
1585
  ...rest,
1538
1586
  onClick: (e) => {
1539
- void createSession();
1587
+ void createSession({ user });
1540
1588
  rest.onClick?.(e);
1541
1589
  }
1542
1590
  }
@@ -1545,7 +1593,7 @@ var CreateSession = ({ asChild, ...rest }) => {
1545
1593
  var ConfirmSession = ({ asChild, ...rest }) => {
1546
1594
  const { confirmSession } = useFeedbackSession();
1547
1595
  const Comp = asChild ? Slot3 : "button";
1548
- return /* @__PURE__ */ jsx8(
1596
+ return /* @__PURE__ */ jsx7(
1549
1597
  Comp,
1550
1598
  {
1551
1599
  ...rest,
@@ -1559,7 +1607,7 @@ var ConfirmSession = ({ asChild, ...rest }) => {
1559
1607
  var StartResolving = ({ asChild, ...rest }) => {
1560
1608
  const { startResolving } = useFeedbackSession();
1561
1609
  const Comp = asChild ? Slot3 : "button";
1562
- return /* @__PURE__ */ jsx8(
1610
+ return /* @__PURE__ */ jsx7(
1563
1611
  Comp,
1564
1612
  {
1565
1613
  ...rest,
@@ -1573,7 +1621,7 @@ var StartResolving = ({ asChild, ...rest }) => {
1573
1621
  var ResolveSession = ({ asChild, ...rest }) => {
1574
1622
  const { resolveSession } = useFeedbackSession();
1575
1623
  const Comp = asChild ? Slot3 : "button";
1576
- return /* @__PURE__ */ jsx8(
1624
+ return /* @__PURE__ */ jsx7(
1577
1625
  Comp,
1578
1626
  {
1579
1627
  ...rest,
@@ -1596,9 +1644,8 @@ export {
1596
1644
  ResolveSession,
1597
1645
  StartResolving,
1598
1646
  ToggleOverlayButton,
1599
- UserProvider,
1647
+ commentReducer,
1600
1648
  useCommentScope,
1601
1649
  useComments,
1602
- useCurrentUser,
1603
1650
  useFeedbackSession
1604
1651
  };