@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/README.md +124 -47
- package/dist/index.cjs +180 -134
- package/dist/index.d.cts +15 -16
- package/dist/index.d.ts +15 -16
- package/dist/index.js +189 -142
- package/dist/types.d.cts +477 -4
- package/dist/types.d.ts +477 -4
- package/package.json +2 -1
- package/dist/use-session-events-DFksOgVA.d.cts +0 -464
- package/dist/use-session-events-DFksOgVA.d.ts +0 -464
package/dist/index.cjs
CHANGED
|
@@ -41,10 +41,9 @@ __export(src_exports, {
|
|
|
41
41
|
ResolveSession: () => ResolveSession,
|
|
42
42
|
StartResolving: () => StartResolving,
|
|
43
43
|
ToggleOverlayButton: () => ToggleOverlayButton,
|
|
44
|
-
|
|
44
|
+
commentReducer: () => commentReducer,
|
|
45
45
|
useCommentScope: () => useCommentScope,
|
|
46
46
|
useComments: () => useComments,
|
|
47
|
-
useCurrentUser: () => useCurrentUser,
|
|
48
47
|
useFeedbackSession: () => useFeedbackSession
|
|
49
48
|
});
|
|
50
49
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -186,28 +185,80 @@ var useCommentEvents = () => {
|
|
|
186
185
|
|
|
187
186
|
// src/utils/select-visible-comments.ts
|
|
188
187
|
var normalizeDraftVisibility = (value) => value === "hidden" ? "hidden" : "visible";
|
|
188
|
+
var isLocated = (comment) => typeof comment.locationId === "string" && comment.locationId.length > 0;
|
|
189
|
+
var normalizeLocationId = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
190
|
+
var applyDraftFilter = (comments, session, draftVisibility, currentUserId) => {
|
|
191
|
+
if (session.status !== "draft" || normalizeDraftVisibility(draftVisibility) !== "hidden") {
|
|
192
|
+
return comments;
|
|
193
|
+
}
|
|
194
|
+
return comments.filter((comment) => {
|
|
195
|
+
if (comment.status === "draft") {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
const authorId = comment.user?.id;
|
|
199
|
+
return authorId === void 0 || authorId === currentUserId;
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
var selectCommentsByLocation = ({
|
|
203
|
+
comments,
|
|
204
|
+
locationId
|
|
205
|
+
}) => {
|
|
206
|
+
const location = normalizeLocationId(locationId);
|
|
207
|
+
if (location === void 0) {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
return comments.filter(
|
|
211
|
+
(comment) => isLocated(comment) && comment.locationId === location
|
|
212
|
+
);
|
|
213
|
+
};
|
|
189
214
|
var selectVisibleComments = ({
|
|
190
215
|
comments,
|
|
191
216
|
session,
|
|
217
|
+
locationId,
|
|
192
218
|
draftVisibility = "visible",
|
|
193
219
|
currentUserId
|
|
194
220
|
}) => {
|
|
195
221
|
if (session === null) {
|
|
196
222
|
return [];
|
|
197
223
|
}
|
|
198
|
-
const inSession = comments.filter(
|
|
224
|
+
const inSession = selectCommentsByLocation({ comments, locationId }).filter(
|
|
199
225
|
(comment) => comment.sessionId === session.id
|
|
200
226
|
);
|
|
201
|
-
|
|
202
|
-
|
|
227
|
+
return applyDraftFilter(inSession, session, draftVisibility, currentUserId);
|
|
228
|
+
};
|
|
229
|
+
var selectCommentsBySession = ({
|
|
230
|
+
comments,
|
|
231
|
+
locationId,
|
|
232
|
+
session,
|
|
233
|
+
draftVisibility = "visible",
|
|
234
|
+
currentUserId
|
|
235
|
+
}) => {
|
|
236
|
+
const grouped = {};
|
|
237
|
+
for (const comment of selectCommentsByLocation({ comments, locationId })) {
|
|
238
|
+
const list = grouped[comment.sessionId];
|
|
239
|
+
if (list) {
|
|
240
|
+
list.push(comment);
|
|
241
|
+
} else {
|
|
242
|
+
grouped[comment.sessionId] = [comment];
|
|
243
|
+
}
|
|
203
244
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
245
|
+
if (session !== null) {
|
|
246
|
+
const active = grouped[session.id];
|
|
247
|
+
if (active) {
|
|
248
|
+
const filtered = applyDraftFilter(
|
|
249
|
+
active,
|
|
250
|
+
session,
|
|
251
|
+
draftVisibility,
|
|
252
|
+
currentUserId
|
|
253
|
+
);
|
|
254
|
+
if (filtered.length === 0) {
|
|
255
|
+
delete grouped[session.id];
|
|
256
|
+
} else {
|
|
257
|
+
grouped[session.id] = filtered;
|
|
258
|
+
}
|
|
207
259
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
260
|
+
}
|
|
261
|
+
return grouped;
|
|
211
262
|
};
|
|
212
263
|
|
|
213
264
|
// src/contexts/feedback-session-context.tsx
|
|
@@ -248,6 +299,45 @@ var useSessionEvents = () => {
|
|
|
248
299
|
return { events, emit };
|
|
249
300
|
};
|
|
250
301
|
|
|
302
|
+
// src/utils/session-type.ts
|
|
303
|
+
var SESSION_TYPES = ["feedback"];
|
|
304
|
+
var isSessionType = (value) => SESSION_TYPES.includes(value);
|
|
305
|
+
var SESSION_STATUSES = [
|
|
306
|
+
"draft",
|
|
307
|
+
"confirmed",
|
|
308
|
+
"resolving",
|
|
309
|
+
"resolved"
|
|
310
|
+
];
|
|
311
|
+
var parseInitialSession = (value) => {
|
|
312
|
+
if (value === null || typeof value !== "object") return null;
|
|
313
|
+
const status = value.status;
|
|
314
|
+
if (!SESSION_STATUSES.includes(status)) return null;
|
|
315
|
+
const session = value;
|
|
316
|
+
return {
|
|
317
|
+
...value,
|
|
318
|
+
comments: session.comments ?? []
|
|
319
|
+
};
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/utils/session-guards.ts
|
|
323
|
+
var locatedComments = (session) => session.comments.filter(isLocated);
|
|
324
|
+
var confirmRefusal = (session, localDrafts) => {
|
|
325
|
+
if (!session || session.status !== "draft") return "session is not a draft";
|
|
326
|
+
if (localDrafts > 0) return "a local draft comment exists";
|
|
327
|
+
if (locatedComments(session).length === 0) return "session has no comments";
|
|
328
|
+
if (!isSessionType(session.type)) return "unknown session type";
|
|
329
|
+
return null;
|
|
330
|
+
};
|
|
331
|
+
var resolveRefusal = (session) => {
|
|
332
|
+
if (session?.status !== "resolving") return "session is not resolving";
|
|
333
|
+
return locatedComments(session).some((c) => c.status === "published") ? "a comment is still published" : null;
|
|
334
|
+
};
|
|
335
|
+
var sumCounts = (counts) => {
|
|
336
|
+
let total = 0;
|
|
337
|
+
for (const count of counts.values()) total += count;
|
|
338
|
+
return total;
|
|
339
|
+
};
|
|
340
|
+
|
|
251
341
|
// src/utils/session-reducer.ts
|
|
252
342
|
var initialSessionReducerState = {
|
|
253
343
|
session: null,
|
|
@@ -340,53 +430,8 @@ var sessionReducer = (state, action) => {
|
|
|
340
430
|
}
|
|
341
431
|
};
|
|
342
432
|
|
|
343
|
-
// src/utils/session-type.ts
|
|
344
|
-
var SESSION_TYPES = ["feedback"];
|
|
345
|
-
var isSessionType = (value) => SESSION_TYPES.includes(value);
|
|
346
|
-
var SESSION_STATUSES = [
|
|
347
|
-
"draft",
|
|
348
|
-
"confirmed",
|
|
349
|
-
"resolving",
|
|
350
|
-
"resolved"
|
|
351
|
-
];
|
|
352
|
-
var parseInitialSession = (value) => {
|
|
353
|
-
if (value === null || typeof value !== "object") return null;
|
|
354
|
-
const status = value.status;
|
|
355
|
-
if (!SESSION_STATUSES.includes(status)) return null;
|
|
356
|
-
const session = value;
|
|
357
|
-
return {
|
|
358
|
-
...value,
|
|
359
|
-
comments: session.comments ?? []
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// src/contexts/user-context.tsx
|
|
364
|
-
var React = __toESM(require("react"), 1);
|
|
365
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
366
|
-
var UserContext = React.createContext(
|
|
367
|
-
void 0
|
|
368
|
-
);
|
|
369
|
-
var UserProvider = ({ user, children }) => {
|
|
370
|
-
const value = React.useMemo(
|
|
371
|
-
() => ({ currentUser: user }),
|
|
372
|
-
[user]
|
|
373
|
-
);
|
|
374
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UserContext.Provider, { value, children });
|
|
375
|
-
};
|
|
376
|
-
var useCurrentUser = () => {
|
|
377
|
-
const ctx = React.useContext(UserContext);
|
|
378
|
-
if (!ctx) {
|
|
379
|
-
throw new Error("useCurrentUser must be used within <UserProvider />");
|
|
380
|
-
}
|
|
381
|
-
return ctx.currentUser;
|
|
382
|
-
};
|
|
383
|
-
var useOptionalCurrentUser = () => {
|
|
384
|
-
const ctx = React.useContext(UserContext);
|
|
385
|
-
return ctx ? ctx.currentUser : void 0;
|
|
386
|
-
};
|
|
387
|
-
|
|
388
433
|
// src/contexts/feedback-session-context.tsx
|
|
389
|
-
var
|
|
434
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
390
435
|
var FeedbackSessionContext = (0, import_react3.createContext)(
|
|
391
436
|
null
|
|
392
437
|
);
|
|
@@ -394,28 +439,16 @@ var SessionBridgeContext = (0, import_react3.createContext)(null);
|
|
|
394
439
|
var MAX_PROJECT_ID_LENGTH = 128;
|
|
395
440
|
var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
|
|
396
441
|
var pick = (value, fallback) => value !== void 0 ? value : fallback;
|
|
397
|
-
var createRefusal = (type, projectId, inFlight,
|
|
442
|
+
var createRefusal = (type, projectId, inFlight, hasCallback, user) => {
|
|
443
|
+
if (!user) return "user is required";
|
|
398
444
|
if (!isSessionType(type)) return "unknown session type";
|
|
399
445
|
if (!isValidProjectId(projectId)) {
|
|
400
446
|
return "projectId must be 1 to 128 characters";
|
|
401
447
|
}
|
|
402
448
|
if (inFlight === "creating") return "creation already in progress";
|
|
403
|
-
if (session?.status === "draft") return "draft session already exists";
|
|
404
449
|
if (!hasCallback) return "onCreateSession is not provided";
|
|
405
450
|
return null;
|
|
406
451
|
};
|
|
407
|
-
var confirmRefusal = (session, localDrafts) => {
|
|
408
|
-
if (!session || session.status !== "draft") return "session is not a draft";
|
|
409
|
-
if (localDrafts > 0) return "a local draft comment exists";
|
|
410
|
-
if (session.comments.length === 0) return "session has no comments";
|
|
411
|
-
if (!isSessionType(session.type)) return "unknown session type";
|
|
412
|
-
return null;
|
|
413
|
-
};
|
|
414
|
-
var sumCounts = (counts) => {
|
|
415
|
-
let total = 0;
|
|
416
|
-
for (const count of counts.values()) total += count;
|
|
417
|
-
return total;
|
|
418
|
-
};
|
|
419
452
|
var FeedbackSessionProvider = ({
|
|
420
453
|
children,
|
|
421
454
|
initialSession,
|
|
@@ -427,7 +460,6 @@ var FeedbackSessionProvider = ({
|
|
|
427
460
|
onResolveSession,
|
|
428
461
|
onError
|
|
429
462
|
}) => {
|
|
430
|
-
const contextUser = useOptionalCurrentUser();
|
|
431
463
|
const initialParsedRef = (0, import_react3.useRef)(
|
|
432
464
|
void 0
|
|
433
465
|
);
|
|
@@ -468,14 +500,14 @@ var FeedbackSessionProvider = ({
|
|
|
468
500
|
const createSession = (0, import_react3.useCallback)(
|
|
469
501
|
async (options) => {
|
|
470
502
|
const type = options?.type ?? "feedback";
|
|
471
|
-
const user =
|
|
503
|
+
const user = options?.user;
|
|
472
504
|
const sessionProjectId = pick(options?.projectId, projectId);
|
|
473
505
|
const refusal = createRefusal(
|
|
474
506
|
type,
|
|
475
507
|
sessionProjectId,
|
|
476
508
|
inFlightRef.current,
|
|
477
|
-
|
|
478
|
-
|
|
509
|
+
onCreateSession !== void 0,
|
|
510
|
+
user
|
|
479
511
|
);
|
|
480
512
|
if (refusal !== null || !onCreateSession) {
|
|
481
513
|
const error = new SessionCreateError(refusal ?? void 0);
|
|
@@ -487,7 +519,7 @@ var FeedbackSessionProvider = ({
|
|
|
487
519
|
try {
|
|
488
520
|
const input = {
|
|
489
521
|
type,
|
|
490
|
-
user
|
|
522
|
+
user,
|
|
491
523
|
projectId: sessionProjectId
|
|
492
524
|
};
|
|
493
525
|
const { data, error } = await tx.executeAsync(
|
|
@@ -510,7 +542,7 @@ var FeedbackSessionProvider = ({
|
|
|
510
542
|
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
511
543
|
}
|
|
512
544
|
},
|
|
513
|
-
[apply,
|
|
545
|
+
[apply, emit, onCreateSession, projectId, report]
|
|
514
546
|
);
|
|
515
547
|
const confirmSession = (0, import_react3.useCallback)(async () => {
|
|
516
548
|
if (inFlightRef.current === "confirming") return { error: null };
|
|
@@ -596,11 +628,7 @@ var FeedbackSessionProvider = ({
|
|
|
596
628
|
const resolveSession = (0, import_react3.useCallback)(
|
|
597
629
|
() => runTransition({
|
|
598
630
|
pending: "completingResolution",
|
|
599
|
-
guard:
|
|
600
|
-
if (session?.status !== "resolving")
|
|
601
|
-
return "session is not resolving";
|
|
602
|
-
return session.comments.some((c) => c.status === "published") ? "a comment is still published" : null;
|
|
603
|
-
},
|
|
631
|
+
guard: resolveRefusal,
|
|
604
632
|
call: onResolveSession,
|
|
605
633
|
failure: SessionResolveError,
|
|
606
634
|
commit: () => {
|
|
@@ -658,7 +686,7 @@ var FeedbackSessionProvider = ({
|
|
|
658
686
|
resolveSession,
|
|
659
687
|
events
|
|
660
688
|
};
|
|
661
|
-
return /* @__PURE__ */ (0,
|
|
689
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FeedbackSessionContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SessionBridgeContext.Provider, { value: bridge, children }) });
|
|
662
690
|
};
|
|
663
691
|
var useFeedbackSession = () => {
|
|
664
692
|
const context = (0, import_react3.useContext)(FeedbackSessionContext);
|
|
@@ -680,7 +708,7 @@ var useSessionBridge = () => {
|
|
|
680
708
|
};
|
|
681
709
|
|
|
682
710
|
// src/contexts/comment-context.tsx
|
|
683
|
-
var
|
|
711
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
684
712
|
var CommentContext = (0, import_react4.createContext)(null);
|
|
685
713
|
var commentReducer = (state, action) => {
|
|
686
714
|
switch (action.type) {
|
|
@@ -695,6 +723,7 @@ var commentReducer = (state, action) => {
|
|
|
695
723
|
{
|
|
696
724
|
id: newId,
|
|
697
725
|
sessionId: action.sessionId,
|
|
726
|
+
locationId: action.locationId,
|
|
698
727
|
projectId: state.projectId,
|
|
699
728
|
user: state.currentUser,
|
|
700
729
|
position: {
|
|
@@ -804,6 +833,7 @@ var CommentContextProvider = ({
|
|
|
804
833
|
}
|
|
805
834
|
},
|
|
806
835
|
projectId,
|
|
836
|
+
locationId: locationIdProp,
|
|
807
837
|
onError,
|
|
808
838
|
onAdd,
|
|
809
839
|
onEdit,
|
|
@@ -811,6 +841,9 @@ var CommentContextProvider = ({
|
|
|
811
841
|
onResolve,
|
|
812
842
|
onReopen
|
|
813
843
|
}) => {
|
|
844
|
+
const locationId = normalizeLocationId(locationIdProp);
|
|
845
|
+
const locationIdRef = (0, import_react4.useRef)(locationId);
|
|
846
|
+
locationIdRef.current = locationId;
|
|
814
847
|
const hostRef = (0, import_react4.useRef)({ onAdd, onEdit, onDelete, onResolve, onReopen });
|
|
815
848
|
hostRef.current = { onAdd, onEdit, onDelete, onResolve, onReopen };
|
|
816
849
|
const bridge = useSessionBridge();
|
|
@@ -818,8 +851,7 @@ var CommentContextProvider = ({
|
|
|
818
851
|
bridgeRef.current = bridge;
|
|
819
852
|
const canResolveRef = (0, import_react4.useRef)(bridge.canResolve);
|
|
820
853
|
canResolveRef.current = bridge.canResolve;
|
|
821
|
-
const
|
|
822
|
-
const currentUser = contextUser !== void 0 ? contextUser : currentUserProp ?? null;
|
|
854
|
+
const currentUser = currentUserProp ?? null;
|
|
823
855
|
const currentUserRef = (0, import_react4.useRef)(currentUser);
|
|
824
856
|
currentUserRef.current = currentUser;
|
|
825
857
|
const [state, dispatch] = (0, import_react4.useReducer)(
|
|
@@ -863,9 +895,15 @@ var CommentContextProvider = ({
|
|
|
863
895
|
onError?.(new SessionStateError());
|
|
864
896
|
return;
|
|
865
897
|
}
|
|
898
|
+
const currentLocationId = locationIdRef.current;
|
|
899
|
+
if (currentLocationId === void 0) {
|
|
900
|
+
onError?.(new AddError("locationId is missing"));
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
866
903
|
dispatch({
|
|
867
904
|
type: "REGISTER",
|
|
868
905
|
sessionId: session.id,
|
|
906
|
+
locationId: currentLocationId,
|
|
869
907
|
position,
|
|
870
908
|
indicatorPosition: indicatorPosition || null
|
|
871
909
|
});
|
|
@@ -1039,9 +1077,18 @@ var CommentContextProvider = ({
|
|
|
1039
1077
|
const toggleOverlay = () => {
|
|
1040
1078
|
dispatch({ type: "TOGGLE_OVERLAY" });
|
|
1041
1079
|
};
|
|
1080
|
+
const activeSession = bridge.session ? { id: bridge.session.id, status: bridge.session.status } : null;
|
|
1042
1081
|
const visibleComments = selectVisibleComments({
|
|
1043
1082
|
comments: state.comments,
|
|
1044
|
-
session:
|
|
1083
|
+
session: activeSession,
|
|
1084
|
+
locationId,
|
|
1085
|
+
draftVisibility: state.config?.draftVisibility,
|
|
1086
|
+
currentUserId: currentUser?.id
|
|
1087
|
+
});
|
|
1088
|
+
const commentsBySession = selectCommentsBySession({
|
|
1089
|
+
comments: state.comments,
|
|
1090
|
+
locationId,
|
|
1091
|
+
session: activeSession,
|
|
1045
1092
|
draftVisibility: state.config?.draftVisibility,
|
|
1046
1093
|
currentUserId: currentUser?.id
|
|
1047
1094
|
});
|
|
@@ -1056,7 +1103,7 @@ var CommentContextProvider = ({
|
|
|
1056
1103
|
onError(error);
|
|
1057
1104
|
}
|
|
1058
1105
|
};
|
|
1059
|
-
return /* @__PURE__ */ (0,
|
|
1106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1060
1107
|
CommentContext.Provider,
|
|
1061
1108
|
{
|
|
1062
1109
|
value: {
|
|
@@ -1064,6 +1111,7 @@ var CommentContextProvider = ({
|
|
|
1064
1111
|
comments: visibleComments.filter(hasStatus("published")),
|
|
1065
1112
|
resolvedComments: visibleComments.filter(hasStatus("resolved")),
|
|
1066
1113
|
allComments: visibleComments,
|
|
1114
|
+
commentsBySession,
|
|
1067
1115
|
config: state.config,
|
|
1068
1116
|
changeOverlayState,
|
|
1069
1117
|
overlayState: state.overlayState,
|
|
@@ -1108,7 +1156,7 @@ var normalizeRect = (a, b) => {
|
|
|
1108
1156
|
};
|
|
1109
1157
|
|
|
1110
1158
|
// src/components/comment-overlay.tsx
|
|
1111
|
-
var
|
|
1159
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1112
1160
|
var DRAG_THRESHOLD = 4;
|
|
1113
1161
|
var CommentOverlay = ({ children, ...rest }) => {
|
|
1114
1162
|
const {
|
|
@@ -1183,8 +1231,8 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
1183
1231
|
setPreview(null);
|
|
1184
1232
|
};
|
|
1185
1233
|
if (overlayState === "inactive") return children;
|
|
1186
|
-
return /* @__PURE__ */ (0,
|
|
1187
|
-
/* @__PURE__ */ (0,
|
|
1234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-overlay": true, style: { position: "relative", ...rest.style }, ...rest, children: [
|
|
1235
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1188
1236
|
"div",
|
|
1189
1237
|
{
|
|
1190
1238
|
ref: overlayRef,
|
|
@@ -1198,7 +1246,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
1198
1246
|
}
|
|
1199
1247
|
),
|
|
1200
1248
|
getActiveComment() && // biome-ignore lint: This element should only handle clicks as a guard
|
|
1201
|
-
/* @__PURE__ */ (0,
|
|
1249
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1202
1250
|
"div",
|
|
1203
1251
|
{
|
|
1204
1252
|
"data-comment-guard": true,
|
|
@@ -1206,7 +1254,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
1206
1254
|
if (getActiveComment()?.content === "") {
|
|
1207
1255
|
triggerError(
|
|
1208
1256
|
new InsertError(
|
|
1209
|
-
"
|
|
1257
|
+
"A draft comment is still open. Either delete it or confirm it before adding a new comment"
|
|
1210
1258
|
)
|
|
1211
1259
|
);
|
|
1212
1260
|
return;
|
|
@@ -1224,7 +1272,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
1224
1272
|
}
|
|
1225
1273
|
}
|
|
1226
1274
|
),
|
|
1227
|
-
preview && /* @__PURE__ */ (0,
|
|
1275
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1228
1276
|
"div",
|
|
1229
1277
|
{
|
|
1230
1278
|
style: {
|
|
@@ -1256,41 +1304,35 @@ var EDITING_STYLES = {
|
|
|
1256
1304
|
};
|
|
1257
1305
|
|
|
1258
1306
|
// src/components/comment-renderer.tsx
|
|
1259
|
-
var
|
|
1307
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1260
1308
|
var CommentRenderer = ({
|
|
1261
1309
|
Comment: Comment2,
|
|
1262
1310
|
DraftComment,
|
|
1263
1311
|
ResolvedComment
|
|
1264
1312
|
}) => {
|
|
1265
|
-
const {
|
|
1266
|
-
comments,
|
|
1267
|
-
draftComments,
|
|
1268
|
-
overlayState,
|
|
1269
|
-
resolvedComments,
|
|
1270
|
-
config
|
|
1271
|
-
} = useComments();
|
|
1313
|
+
const { comments, draftComments, overlayState, resolvedComments, config } = useComments();
|
|
1272
1314
|
if (overlayState === "inactive") return null;
|
|
1273
|
-
return /* @__PURE__ */ (0,
|
|
1315
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1274
1316
|
draftComments.map((comment) => {
|
|
1275
|
-
return /* @__PURE__ */ (0,
|
|
1317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DraftComment, { comment }, comment.id);
|
|
1276
1318
|
}),
|
|
1277
1319
|
comments.map((comment) => {
|
|
1278
|
-
return /* @__PURE__ */ (0,
|
|
1320
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Comment2, { comment }, comment.id);
|
|
1279
1321
|
}),
|
|
1280
1322
|
resolvedComments.map((comment) => {
|
|
1281
1323
|
if (config?.commentVisibility?.hideResolved) return null;
|
|
1282
|
-
return /* @__PURE__ */ (0,
|
|
1324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ResolvedComment, { comment }, comment.id);
|
|
1283
1325
|
})
|
|
1284
1326
|
] });
|
|
1285
1327
|
};
|
|
1286
1328
|
|
|
1287
1329
|
// src/components/comment-actions.tsx
|
|
1288
1330
|
var import_react_slot = require("@radix-ui/react-slot");
|
|
1289
|
-
var
|
|
1331
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1290
1332
|
var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
1291
1333
|
const { toggleOverlay, overlayState } = useComments();
|
|
1292
1334
|
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
1293
|
-
return /* @__PURE__ */ (0,
|
|
1335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1294
1336
|
Comp,
|
|
1295
1337
|
{
|
|
1296
1338
|
"data-active": overlayState !== "inactive",
|
|
@@ -1308,12 +1350,12 @@ var import_react6 = require("react");
|
|
|
1308
1350
|
var import_react_slot2 = require("@radix-ui/react-slot");
|
|
1309
1351
|
|
|
1310
1352
|
// src/contexts/scoped-comment.tsx
|
|
1311
|
-
var
|
|
1312
|
-
var CommentScopeContext =
|
|
1353
|
+
var React = __toESM(require("react"), 1);
|
|
1354
|
+
var CommentScopeContext = React.createContext(
|
|
1313
1355
|
null
|
|
1314
1356
|
);
|
|
1315
1357
|
function useCommentScope() {
|
|
1316
|
-
const ctx =
|
|
1358
|
+
const ctx = React.useContext(CommentScopeContext);
|
|
1317
1359
|
if (!ctx) {
|
|
1318
1360
|
throw new Error("Comment.* must be used within <Comment.Root />");
|
|
1319
1361
|
}
|
|
@@ -1321,7 +1363,7 @@ function useCommentScope() {
|
|
|
1321
1363
|
}
|
|
1322
1364
|
|
|
1323
1365
|
// src/components/comment.tsx
|
|
1324
|
-
var
|
|
1366
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1325
1367
|
var CommentRoot = ({
|
|
1326
1368
|
comment,
|
|
1327
1369
|
defaultDraft,
|
|
@@ -1332,16 +1374,21 @@ var CommentRoot = ({
|
|
|
1332
1374
|
const { getActiveComment } = useComments();
|
|
1333
1375
|
const isActive = getActiveComment()?.id === comment.id;
|
|
1334
1376
|
const [draft, setDraft] = (0, import_react6.useState)(defaultDraft ?? comment.content ?? "");
|
|
1377
|
+
const [prevContent, setPrevContent] = (0, import_react6.useState)(comment.content);
|
|
1378
|
+
if (prevContent !== comment.content) {
|
|
1379
|
+
setPrevContent(comment.content);
|
|
1380
|
+
setDraft(comment.content ?? "");
|
|
1381
|
+
}
|
|
1335
1382
|
const positionStyles = {
|
|
1336
1383
|
position: "absolute",
|
|
1337
1384
|
top: comment.position.y,
|
|
1338
1385
|
left: comment.position.x
|
|
1339
1386
|
};
|
|
1340
|
-
return /* @__PURE__ */ (0,
|
|
1387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1341
1388
|
CommentScopeContext.Provider,
|
|
1342
1389
|
{
|
|
1343
1390
|
value: { comment, isActive, draft, setDraft },
|
|
1344
|
-
children: /* @__PURE__ */ (0,
|
|
1391
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1345
1392
|
"div",
|
|
1346
1393
|
{
|
|
1347
1394
|
...rest,
|
|
@@ -1363,7 +1410,7 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
1363
1410
|
const { config } = useComments();
|
|
1364
1411
|
if (!comment.indicator) return null;
|
|
1365
1412
|
if (config?.indicatorVisibility === "active" && !isActive) return null;
|
|
1366
|
-
return /* @__PURE__ */ (0,
|
|
1413
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1367
1414
|
"div",
|
|
1368
1415
|
{
|
|
1369
1416
|
...rest,
|
|
@@ -1383,14 +1430,14 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
1383
1430
|
);
|
|
1384
1431
|
};
|
|
1385
1432
|
var CommentContent = ({ asChild, ...rest }) => {
|
|
1386
|
-
const {
|
|
1433
|
+
const { comment } = useCommentScope();
|
|
1387
1434
|
const Comp = asChild ? import_react_slot2.Slot : "p";
|
|
1388
|
-
return /* @__PURE__ */ (0,
|
|
1435
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Comp, { ...rest, children: comment.content });
|
|
1389
1436
|
};
|
|
1390
1437
|
var CommentEdit = ({ asChild, ...rest }) => {
|
|
1391
1438
|
const { draft, setDraft } = useCommentScope();
|
|
1392
1439
|
const Comp = asChild ? import_react_slot2.Slot : "textarea";
|
|
1393
|
-
return /* @__PURE__ */ (0,
|
|
1440
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1394
1441
|
Comp,
|
|
1395
1442
|
{
|
|
1396
1443
|
...rest,
|
|
@@ -1408,7 +1455,7 @@ var CommentConfirm = ({ asChild, ...rest }) => {
|
|
|
1408
1455
|
const { updateComment } = useComments();
|
|
1409
1456
|
const { comment, draft } = useCommentScope();
|
|
1410
1457
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
1411
|
-
return /* @__PURE__ */ (0,
|
|
1458
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1412
1459
|
Comp,
|
|
1413
1460
|
{
|
|
1414
1461
|
...rest,
|
|
@@ -1424,7 +1471,7 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
1424
1471
|
const { deleteComment } = useComments();
|
|
1425
1472
|
const { comment } = useCommentScope();
|
|
1426
1473
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
1427
|
-
return /* @__PURE__ */ (0,
|
|
1474
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1428
1475
|
Comp,
|
|
1429
1476
|
{
|
|
1430
1477
|
...rest,
|
|
@@ -1451,7 +1498,7 @@ var CommentResolve = ({ asChild, ...rest }) => {
|
|
|
1451
1498
|
);
|
|
1452
1499
|
return null;
|
|
1453
1500
|
}
|
|
1454
|
-
return /* @__PURE__ */ (0,
|
|
1501
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1455
1502
|
Comp,
|
|
1456
1503
|
{
|
|
1457
1504
|
...rest,
|
|
@@ -1478,7 +1525,7 @@ var CommentReopen = ({ asChild, ...rest }) => {
|
|
|
1478
1525
|
);
|
|
1479
1526
|
return null;
|
|
1480
1527
|
}
|
|
1481
|
-
return /* @__PURE__ */ (0,
|
|
1528
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1482
1529
|
Comp,
|
|
1483
1530
|
{
|
|
1484
1531
|
...rest,
|
|
@@ -1494,7 +1541,7 @@ var Comment = {
|
|
|
1494
1541
|
* The root component for a comment, must be used to wrap all other comment components.
|
|
1495
1542
|
*
|
|
1496
1543
|
* @param comment as the current comment from the comments array
|
|
1497
|
-
* @param defaultDraft as the optional initial value for the comment
|
|
1544
|
+
* @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
|
|
1498
1545
|
* @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
|
|
1499
1546
|
*/
|
|
1500
1547
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
@@ -1507,9 +1554,9 @@ var Comment = {
|
|
|
1507
1554
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
1508
1555
|
Indicator: CommentIndicator,
|
|
1509
1556
|
/**
|
|
1510
|
-
* The comment's static
|
|
1557
|
+
* The comment's static saved content
|
|
1511
1558
|
*
|
|
1512
|
-
* @description Displays the comment
|
|
1559
|
+
* @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
|
|
1513
1560
|
* @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
|
|
1514
1561
|
*/
|
|
1515
1562
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
@@ -1558,16 +1605,16 @@ var Comment = {
|
|
|
1558
1605
|
|
|
1559
1606
|
// src/components/session-actions.tsx
|
|
1560
1607
|
var import_react_slot3 = require("@radix-ui/react-slot");
|
|
1561
|
-
var
|
|
1562
|
-
var CreateSession = ({ asChild, ...rest }) => {
|
|
1608
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1609
|
+
var CreateSession = ({ asChild, user, ...rest }) => {
|
|
1563
1610
|
const { createSession } = useFeedbackSession();
|
|
1564
1611
|
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1565
|
-
return /* @__PURE__ */ (0,
|
|
1612
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1566
1613
|
Comp,
|
|
1567
1614
|
{
|
|
1568
1615
|
...rest,
|
|
1569
1616
|
onClick: (e) => {
|
|
1570
|
-
void createSession();
|
|
1617
|
+
void createSession({ user });
|
|
1571
1618
|
rest.onClick?.(e);
|
|
1572
1619
|
}
|
|
1573
1620
|
}
|
|
@@ -1576,7 +1623,7 @@ var CreateSession = ({ asChild, ...rest }) => {
|
|
|
1576
1623
|
var ConfirmSession = ({ asChild, ...rest }) => {
|
|
1577
1624
|
const { confirmSession } = useFeedbackSession();
|
|
1578
1625
|
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1579
|
-
return /* @__PURE__ */ (0,
|
|
1626
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1580
1627
|
Comp,
|
|
1581
1628
|
{
|
|
1582
1629
|
...rest,
|
|
@@ -1590,7 +1637,7 @@ var ConfirmSession = ({ asChild, ...rest }) => {
|
|
|
1590
1637
|
var StartResolving = ({ asChild, ...rest }) => {
|
|
1591
1638
|
const { startResolving } = useFeedbackSession();
|
|
1592
1639
|
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1593
|
-
return /* @__PURE__ */ (0,
|
|
1640
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1594
1641
|
Comp,
|
|
1595
1642
|
{
|
|
1596
1643
|
...rest,
|
|
@@ -1604,7 +1651,7 @@ var StartResolving = ({ asChild, ...rest }) => {
|
|
|
1604
1651
|
var ResolveSession = ({ asChild, ...rest }) => {
|
|
1605
1652
|
const { resolveSession } = useFeedbackSession();
|
|
1606
1653
|
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1607
|
-
return /* @__PURE__ */ (0,
|
|
1654
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1608
1655
|
Comp,
|
|
1609
1656
|
{
|
|
1610
1657
|
...rest,
|
|
@@ -1628,9 +1675,8 @@ var ResolveSession = ({ asChild, ...rest }) => {
|
|
|
1628
1675
|
ResolveSession,
|
|
1629
1676
|
StartResolving,
|
|
1630
1677
|
ToggleOverlayButton,
|
|
1631
|
-
|
|
1678
|
+
commentReducer,
|
|
1632
1679
|
useCommentScope,
|
|
1633
1680
|
useComments,
|
|
1634
|
-
useCurrentUser,
|
|
1635
1681
|
useFeedbackSession
|
|
1636
1682
|
});
|