@kendew-agency/react-feedback-layer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,756 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Comment: () => Comment,
34
+ CommentContextProvider: () => CommentContextProvider,
35
+ CommentOverlay: () => CommentOverlay,
36
+ CommentRenderer: () => CommentRenderer,
37
+ CommentScopeContext: () => CommentScopeContext,
38
+ ConfirmComments: () => ConfirmComments,
39
+ ResolveComments: () => ResolveComments,
40
+ ToggleOverlayButton: () => ToggleOverlayButton,
41
+ useCommentScope: () => useCommentScope,
42
+ useComments: () => useComments
43
+ });
44
+ module.exports = __toCommonJS(src_exports);
45
+
46
+ // src/components/comment-overlay.tsx
47
+ var import_react2 = require("react");
48
+
49
+ // src/contexts/comment-context.tsx
50
+ var import_react = require("react");
51
+
52
+ // src/lib/tx.ts
53
+ var import_tryx_handler = require("@j31/tryx-handler");
54
+ var tx = new import_tryx_handler.TryX({
55
+ timeout: 1e4
56
+ // 10 seconds
57
+ });
58
+
59
+ // src/utils/hasStatus.ts
60
+ function hasStatus(status) {
61
+ return (comment) => comment.status === status;
62
+ }
63
+
64
+ // src/contexts/comment-context.tsx
65
+ var import_jsx_runtime = require("react/jsx-runtime");
66
+ var CommentContext = (0, import_react.createContext)(null);
67
+ var commentReducer = (state, action) => {
68
+ switch (action.type) {
69
+ case "REGISTER": {
70
+ const newId = `${state.config?.idPrefix ?? ""}${crypto.randomUUID()}`;
71
+ return {
72
+ ...state,
73
+ overlayState: "editing",
74
+ focussedComment: newId,
75
+ comments: [
76
+ ...state.comments,
77
+ {
78
+ id: newId,
79
+ user: state.currentUser,
80
+ position: {
81
+ x: action.position.x,
82
+ y: action.position.y
83
+ },
84
+ content: "",
85
+ createdAt: /* @__PURE__ */ new Date(),
86
+ status: "draft",
87
+ indicator: action.indicatorPosition ? {
88
+ width: action.indicatorPosition?.width,
89
+ height: action.indicatorPosition?.height
90
+ } : null
91
+ }
92
+ ]
93
+ };
94
+ }
95
+ case "UPDATE_COMMENTS": {
96
+ return {
97
+ ...state,
98
+ comments: action.comments
99
+ };
100
+ }
101
+ case "DELETE":
102
+ return {
103
+ ...state,
104
+ overlayState: "idle",
105
+ focussedComment: null,
106
+ comments: state.comments.filter((comment) => comment.id !== action.id)
107
+ };
108
+ case "EDIT":
109
+ return {
110
+ ...state,
111
+ overlayState: "idle",
112
+ focussedComment: null,
113
+ comments: state.comments.map((comment) => {
114
+ if (comment.id === action.id) {
115
+ return { ...comment, ...action.newComment };
116
+ }
117
+ return comment;
118
+ })
119
+ };
120
+ case "FOCUS":
121
+ return {
122
+ ...state,
123
+ overlayState: "editing",
124
+ focussedComment: action.id
125
+ };
126
+ case "TOGGLE_OVERLAY":
127
+ return {
128
+ ...state,
129
+ overlayState: state.overlayState === "inactive" ? "idle" : "inactive"
130
+ };
131
+ case "CHANGE_OVERLAYSTATE":
132
+ return {
133
+ ...state,
134
+ overlayState: action.to
135
+ };
136
+ case "UPDATE_VISIBILITY":
137
+ return {
138
+ ...state,
139
+ config: {
140
+ ...state.config,
141
+ commentVisibility: {
142
+ ...state.config?.commentVisibility,
143
+ ...action.visibility
144
+ }
145
+ }
146
+ };
147
+ case "RESET_DRAFT_COMMENTS": {
148
+ return {
149
+ ...state,
150
+ comments: state.comments.filter(
151
+ (comment) => comment.status !== "draft"
152
+ ),
153
+ focussedComment: null
154
+ };
155
+ }
156
+ case "RESET_RESOLVING_COMMENTS":
157
+ return {
158
+ ...state,
159
+ comments: state.comments.filter(
160
+ (comment) => comment.status !== "resolving"
161
+ ),
162
+ focussedComment: null
163
+ };
164
+ default: {
165
+ console.warn(`Unhandled action type, returning state`, action);
166
+ return state;
167
+ }
168
+ }
169
+ };
170
+ var CommentContextProvider = ({
171
+ children,
172
+ /**
173
+ * The initial comment coming from Sanity
174
+ */
175
+ initialComments,
176
+ /**
177
+ * Initial state of the comment overlay
178
+ * This is used to determine the initial state of the comment overlay
179
+ * @default "inactive"
180
+ */
181
+ initialOverlayState,
182
+ onConfirm,
183
+ onResolve,
184
+ currentUser,
185
+ subscription,
186
+ config = {
187
+ commentVisibility: {
188
+ hideResolved: false,
189
+ hideResolving: false
190
+ }
191
+ },
192
+ onError
193
+ }) => {
194
+ const [state, dispatch] = (0, import_react.useReducer)(commentReducer, {
195
+ comments: initialComments || [],
196
+ overlayState: initialOverlayState || "inactive",
197
+ currentUser,
198
+ focussedComment: null,
199
+ config
200
+ });
201
+ (0, import_react.useEffect)(() => {
202
+ if (!subscription) return;
203
+ subscription.subscribe((update) => {
204
+ dispatch({ type: "UPDATE_COMMENTS", comments: update });
205
+ });
206
+ return () => {
207
+ subscription.unsubscribe();
208
+ };
209
+ }, [subscription]);
210
+ const registerComment = (position, indicatorPosition) => {
211
+ dispatch({
212
+ type: "REGISTER",
213
+ position,
214
+ indicatorPosition: indicatorPosition || null
215
+ });
216
+ };
217
+ const deleteComment = (id) => {
218
+ dispatch({ type: "DELETE", id });
219
+ };
220
+ const updateComment = (id, newComment) => {
221
+ dispatch({ type: "EDIT", id, newComment });
222
+ };
223
+ const getActiveComment = () => {
224
+ return state.comments.find(
225
+ (comment) => comment.id === state.focussedComment
226
+ );
227
+ };
228
+ const focusOnComment = (id) => {
229
+ dispatch({ type: "FOCUS", id });
230
+ };
231
+ const toggleOverlay = () => {
232
+ dispatch({ type: "TOGGLE_OVERLAY" });
233
+ };
234
+ const getDraftComments = () => {
235
+ return state.comments.filter(hasStatus("draft"));
236
+ };
237
+ const getConfirmedComments = () => {
238
+ return state.comments.filter(hasStatus("published"));
239
+ };
240
+ const getResolvingComments = () => {
241
+ return state.comments.filter(hasStatus("resolving"));
242
+ };
243
+ const getResolvedComments = () => {
244
+ return state.comments.filter(hasStatus("resolved"));
245
+ };
246
+ const toggleResolvingComment = (id) => {
247
+ const comment = state.comments.find((comment2) => comment2.id === id);
248
+ dispatch({
249
+ type: "EDIT",
250
+ id,
251
+ newComment: {
252
+ status: comment?.status === "resolving" ? "published" : "resolving"
253
+ }
254
+ });
255
+ };
256
+ const confirmComments = async () => {
257
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: "saving" });
258
+ const draftComments = getDraftComments();
259
+ const { error } = await tx.executeAsync(
260
+ async () => onConfirm(
261
+ draftComments.map((c) => ({
262
+ ...c,
263
+ status: "published"
264
+ }))
265
+ )
266
+ );
267
+ if (error) {
268
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
269
+ if (onError) {
270
+ onError(error);
271
+ }
272
+ return { error };
273
+ }
274
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
275
+ dispatch({ type: "RESET_DRAFT_COMMENTS" });
276
+ return { error: null };
277
+ };
278
+ const resolveComments = async () => {
279
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: "resolving" });
280
+ const resolvingComments = getResolvingComments();
281
+ const { error } = await tx.executeAsync(
282
+ async () => onResolve(
283
+ resolvingComments.map((c) => ({
284
+ ...c,
285
+ status: "resolved"
286
+ }))
287
+ )
288
+ );
289
+ if (error) {
290
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: "error" });
291
+ if (onError) {
292
+ onError(error);
293
+ }
294
+ return { error };
295
+ }
296
+ dispatch({ type: "RESET_RESOLVING_COMMENTS" });
297
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
298
+ return { error: null };
299
+ };
300
+ const updateCommentVisibility = (visibility) => {
301
+ dispatch({ type: "UPDATE_VISIBILITY", visibility });
302
+ };
303
+ const changeOverlayState = (state2) => {
304
+ dispatch({ type: "CHANGE_OVERLAYSTATE", to: state2 });
305
+ };
306
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
307
+ CommentContext.Provider,
308
+ {
309
+ value: {
310
+ draftComments: getDraftComments(),
311
+ comments: getConfirmedComments(),
312
+ resolvingComments: getResolvingComments(),
313
+ resolvedComments: getResolvedComments(),
314
+ allComments: state.comments,
315
+ config: state.config,
316
+ changeOverlayState,
317
+ toggleResolvingComment,
318
+ overlayState: state.overlayState,
319
+ deleteComment,
320
+ updateComment,
321
+ focusOnComment,
322
+ registerComment,
323
+ getActiveComment,
324
+ toggleOverlay,
325
+ confirmComments,
326
+ currentUser,
327
+ resolveComments,
328
+ updateCommentVisibility
329
+ },
330
+ children
331
+ }
332
+ );
333
+ };
334
+ var useComments = () => {
335
+ const context = (0, import_react.useContext)(CommentContext);
336
+ if (!context) {
337
+ throw new Error("useComments must be used within a CommentContextProvider");
338
+ }
339
+ return context;
340
+ };
341
+
342
+ // src/utils/position.ts
343
+ var getRelativePos = (e, el) => {
344
+ const rect = el.getBoundingClientRect();
345
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
346
+ };
347
+ var normalizeRect = (a, b) => {
348
+ const x = Math.min(a.x, b.x);
349
+ const y = Math.min(a.y, b.y);
350
+ const width = Math.abs(b.x - a.x);
351
+ const height = Math.abs(b.y - a.y);
352
+ return { x, y, width, height };
353
+ };
354
+
355
+ // src/components/comment-overlay.tsx
356
+ var import_jsx_runtime2 = require("react/jsx-runtime");
357
+ var DRAG_THRESHOLD = 4;
358
+ var CommentOverlay = ({ children }) => {
359
+ const {
360
+ overlayState,
361
+ registerComment,
362
+ focusOnComment,
363
+ getActiveComment,
364
+ changeOverlayState
365
+ } = useComments();
366
+ const [preview, setPreview] = (0, import_react2.useState)(null);
367
+ const startRef = (0, import_react2.useRef)(null);
368
+ const draggingRef = (0, import_react2.useRef)(false);
369
+ const overlayRef = (0, import_react2.useRef)(null);
370
+ const onPointerDown = (e) => {
371
+ if (overlayState === "editing") {
372
+ alert(
373
+ "Can not add a new comment. You are currently editing a comment. Please finish editing before adding a new one."
374
+ );
375
+ return;
376
+ }
377
+ const el = overlayRef.current;
378
+ if (!el) return;
379
+ el.setPointerCapture(e.pointerId);
380
+ const start = getRelativePos(e.nativeEvent, el);
381
+ startRef.current = start;
382
+ draggingRef.current = false;
383
+ setPreview(null);
384
+ };
385
+ const onPointerMove = (e) => {
386
+ const el = overlayRef.current;
387
+ const start = startRef.current;
388
+ if (!el || !start) return;
389
+ const current = getRelativePos(e.nativeEvent, el);
390
+ const dx = current.x - start.x;
391
+ const dy = current.y - start.y;
392
+ if (!draggingRef.current && Math.hypot(dx, dy) >= DRAG_THRESHOLD) {
393
+ draggingRef.current = true;
394
+ }
395
+ if (draggingRef.current) {
396
+ const rect = normalizeRect(start, current);
397
+ setPreview(rect);
398
+ }
399
+ };
400
+ const onPointerUp = (e) => {
401
+ const el = overlayRef.current;
402
+ const start = startRef.current;
403
+ if (!el || !start) return;
404
+ const end = getRelativePos(e.nativeEvent, el);
405
+ startRef.current = null;
406
+ if (!draggingRef.current) {
407
+ registerComment(start);
408
+ return;
409
+ }
410
+ draggingRef.current = false;
411
+ const rect = normalizeRect(start, end);
412
+ if (rect.width < DRAG_THRESHOLD && rect.height < DRAG_THRESHOLD) {
413
+ registerComment(start);
414
+ setPreview(null);
415
+ return;
416
+ }
417
+ const commentPosition = {
418
+ x: rect.x + rect.width,
419
+ y: rect.y + rect.height
420
+ };
421
+ registerComment(commentPosition, {
422
+ width: rect.width,
423
+ height: rect.height
424
+ });
425
+ setPreview(null);
426
+ };
427
+ if (overlayState === "inactive") return children;
428
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-overlay": true, style: { position: "relative" }, children: [
429
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
430
+ "div",
431
+ {
432
+ ref: overlayRef,
433
+ onPointerDown,
434
+ onPointerMove,
435
+ onPointerUp,
436
+ style: {
437
+ ...OVERLAY_STYLES,
438
+ ...overlayState === "editing" && EDITING_STYLES
439
+ }
440
+ }
441
+ ),
442
+ getActiveComment() && // biome-ignore lint: This element should only handle clicks as a guard
443
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
444
+ "div",
445
+ {
446
+ "data-comment-guard": true,
447
+ onClick: () => {
448
+ focusOnComment(null);
449
+ changeOverlayState("idle");
450
+ },
451
+ style: {
452
+ width: "100%",
453
+ height: "100%",
454
+ position: "absolute",
455
+ inset: 0,
456
+ zIndex: 2,
457
+ isolation: "isolate"
458
+ }
459
+ }
460
+ ),
461
+ preview && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
462
+ "div",
463
+ {
464
+ style: {
465
+ position: "absolute",
466
+ left: preview.x,
467
+ top: preview.y,
468
+ width: preview.width,
469
+ height: preview.height,
470
+ border: "1px dashed currentColor",
471
+ pointerEvents: "none"
472
+ }
473
+ }
474
+ ),
475
+ children
476
+ ] });
477
+ };
478
+ var OVERLAY_STYLES = {
479
+ width: "100%",
480
+ height: "100%",
481
+ position: "absolute",
482
+ inset: 0,
483
+ zIndex: 20,
484
+ cursor: "crosshair",
485
+ isolation: "isolate"
486
+ };
487
+ var EDITING_STYLES = {
488
+ pointerEvents: "none"
489
+ };
490
+
491
+ // src/components/comment-renderer.tsx
492
+ var import_jsx_runtime3 = require("react/jsx-runtime");
493
+ var CommentRenderer = ({
494
+ Comment: Comment2,
495
+ DraftComment,
496
+ ResolvingComment,
497
+ ResolvedComment
498
+ }) => {
499
+ const {
500
+ comments,
501
+ draftComments,
502
+ overlayState,
503
+ resolvedComments,
504
+ resolvingComments,
505
+ config
506
+ } = useComments();
507
+ if (overlayState === "inactive") return null;
508
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
509
+ draftComments.map((comment) => {
510
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DraftComment, { comment }, comment.id);
511
+ }),
512
+ comments.map((comment) => {
513
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Comment2, { comment }, comment.id);
514
+ }),
515
+ resolvingComments.map((comment) => {
516
+ if (config?.commentVisibility?.hideResolving) return null;
517
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ResolvingComment, { comment }, comment.id);
518
+ }),
519
+ resolvedComments.map((comment) => {
520
+ if (config?.commentVisibility?.hideResolved) return null;
521
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ResolvedComment, { comment }, comment.id);
522
+ })
523
+ ] });
524
+ };
525
+
526
+ // src/components/comment-actions.tsx
527
+ var import_react_slot = require("@radix-ui/react-slot");
528
+ var import_jsx_runtime4 = require("react/jsx-runtime");
529
+ var ToggleOverlayButton = ({ asChild, ...rest }) => {
530
+ const { toggleOverlay, overlayState } = useComments();
531
+ const Comp = asChild ? import_react_slot.Slot : "button";
532
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
533
+ Comp,
534
+ {
535
+ "data-active": overlayState !== "inactive",
536
+ ...rest,
537
+ onClick: (e) => {
538
+ toggleOverlay();
539
+ rest.onClick?.(e);
540
+ }
541
+ }
542
+ );
543
+ };
544
+ var ConfirmComments = ({ asChild, ...rest }) => {
545
+ const { confirmComments } = useComments();
546
+ const Comp = asChild ? import_react_slot.Slot : "button";
547
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
548
+ Comp,
549
+ {
550
+ ...rest,
551
+ onClick: (e) => {
552
+ confirmComments();
553
+ rest.onClick?.(e);
554
+ }
555
+ }
556
+ );
557
+ };
558
+ var ResolveComments = ({ asChild, ...rest }) => {
559
+ const { resolveComments } = useComments();
560
+ const Comp = asChild ? import_react_slot.Slot : "button";
561
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
562
+ Comp,
563
+ {
564
+ ...rest,
565
+ onClick: (e) => {
566
+ resolveComments();
567
+ rest.onClick?.(e);
568
+ }
569
+ }
570
+ );
571
+ };
572
+
573
+ // src/components/comment.tsx
574
+ var import_react3 = require("react");
575
+ var import_react_slot2 = require("@radix-ui/react-slot");
576
+
577
+ // src/contexts/scoped-comment.tsx
578
+ var React = __toESM(require("react"), 1);
579
+ var CommentScopeContext = React.createContext(
580
+ null
581
+ );
582
+ function useCommentScope() {
583
+ const ctx = React.useContext(CommentScopeContext);
584
+ if (!ctx) {
585
+ throw new Error("Comment.* must be used within <Comment.Root />");
586
+ }
587
+ return ctx;
588
+ }
589
+
590
+ // src/components/comment.tsx
591
+ var import_jsx_runtime5 = require("react/jsx-runtime");
592
+ var CommentRoot = ({
593
+ comment,
594
+ children,
595
+ defaultDraft,
596
+ ...rest
597
+ }) => {
598
+ const { getActiveComment } = useComments();
599
+ const isActive = getActiveComment()?.id === comment.id;
600
+ const [draft, setDraft] = (0, import_react3.useState)(defaultDraft ?? comment.content ?? "");
601
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
602
+ CommentScopeContext.Provider,
603
+ {
604
+ value: { comment, isActive, draft, setDraft },
605
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
606
+ "div",
607
+ {
608
+ ...rest,
609
+ "data-comment": comment.id,
610
+ "data-active": isActive,
611
+ style: {
612
+ top: comment.position.y,
613
+ left: comment.position.x,
614
+ position: "absolute",
615
+ zIndex: isActive ? 40 : 30,
616
+ ...rest.style ?? {}
617
+ },
618
+ children
619
+ }
620
+ )
621
+ }
622
+ );
623
+ };
624
+ var CommentIndicator = ({ ...rest }) => {
625
+ const { comment, isActive } = useCommentScope();
626
+ const { config } = useComments();
627
+ if (!comment.indicator) return null;
628
+ if (config?.indicatorVisibility === "active" && !isActive) return null;
629
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
630
+ "div",
631
+ {
632
+ ...rest,
633
+ "data-parent": comment.id,
634
+ style: {
635
+ width: comment.indicator.width,
636
+ height: comment.indicator.height,
637
+ position: "absolute",
638
+ top: 0 - comment.indicator.height,
639
+ left: 0 - comment.indicator.width,
640
+ zIndex: 1,
641
+ pointerEvents: "none",
642
+ border: "1px dashed black",
643
+ ...rest.style
644
+ }
645
+ }
646
+ );
647
+ };
648
+ var CommentContent = ({ asChild, ...rest }) => {
649
+ const { draft } = useCommentScope();
650
+ const Comp = asChild ? import_react_slot2.Slot : "p";
651
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Comp, { ...rest, children: draft });
652
+ };
653
+ var CommentEdit = ({ asChild, ...rest }) => {
654
+ const { draft, setDraft } = useCommentScope();
655
+ const Comp = asChild ? import_react_slot2.Slot : "textarea";
656
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
657
+ Comp,
658
+ {
659
+ ...rest,
660
+ value: rest.value ?? draft,
661
+ name: "commentEdit",
662
+ placeholder: "Write a comment...",
663
+ onChange: (e) => {
664
+ setDraft(e.target.value);
665
+ rest.onChange?.(e);
666
+ }
667
+ }
668
+ );
669
+ };
670
+ var CommentConfirm = ({ asChild, ...rest }) => {
671
+ const { updateComment } = useComments();
672
+ const { comment, draft } = useCommentScope();
673
+ const Comp = asChild ? import_react_slot2.Slot : "button";
674
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
675
+ Comp,
676
+ {
677
+ ...rest,
678
+ disabled: !draft,
679
+ onClick: (e) => {
680
+ updateComment(comment.id, { content: draft });
681
+ rest.onClick?.(e);
682
+ }
683
+ }
684
+ );
685
+ };
686
+ var CommentDelete = ({ asChild, ...rest }) => {
687
+ const { deleteComment } = useComments();
688
+ const { comment } = useCommentScope();
689
+ const Comp = asChild ? import_react_slot2.Slot : "button";
690
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
691
+ Comp,
692
+ {
693
+ ...rest,
694
+ onClick: (e) => {
695
+ deleteComment(comment.id);
696
+ rest.onClick?.(e);
697
+ }
698
+ }
699
+ );
700
+ };
701
+ var CommentResolve = ({ asChild, ...rest }) => {
702
+ const { toggleResolvingComment } = useComments();
703
+ const { comment } = useCommentScope();
704
+ const Comp = asChild ? import_react_slot2.Slot : "button";
705
+ if (comment.status === "draft") {
706
+ console.error(
707
+ `A draft comment can not be marked as resolving, remove this button from this comment: ${comment.id}`
708
+ );
709
+ return null;
710
+ }
711
+ if (comment.status === "resolved") {
712
+ console.error(
713
+ `A resolved comment can not be marked as resolving, remove this button from this comment: ${comment.id}`
714
+ );
715
+ return null;
716
+ }
717
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
718
+ Comp,
719
+ {
720
+ ...rest,
721
+ onClick: (e) => {
722
+ toggleResolvingComment(comment.id);
723
+ rest.onClick?.(e);
724
+ }
725
+ }
726
+ );
727
+ };
728
+ var Comment = {
729
+ // biome-ignore lint/style/useNamingConvention: Modular export
730
+ Root: CommentRoot,
731
+ // biome-ignore lint/style/useNamingConvention: Modular export
732
+ Indicator: CommentIndicator,
733
+ // biome-ignore lint/style/useNamingConvention: Modular export
734
+ Content: CommentContent,
735
+ // biome-ignore lint/style/useNamingConvention: Modular export
736
+ Edit: CommentEdit,
737
+ // biome-ignore lint/style/useNamingConvention: Modular export
738
+ Confirm: CommentConfirm,
739
+ // biome-ignore lint/style/useNamingConvention: Modular export
740
+ Delete: CommentDelete,
741
+ // biome-ignore lint/style/useNamingConvention: Modular export
742
+ Resolve: CommentResolve
743
+ };
744
+ // Annotate the CommonJS export names for ESM import in node:
745
+ 0 && (module.exports = {
746
+ Comment,
747
+ CommentContextProvider,
748
+ CommentOverlay,
749
+ CommentRenderer,
750
+ CommentScopeContext,
751
+ ConfirmComments,
752
+ ResolveComments,
753
+ ToggleOverlayButton,
754
+ useCommentScope,
755
+ useComments
756
+ });