@kendew-agency/react-feedback-layer 0.3.1 → 0.4.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +713 -454
- package/dist/index.cjs +982 -222
- package/dist/index.d.cts +130 -13
- package/dist/index.d.ts +130 -13
- package/dist/index.js +981 -218
- package/dist/types.d.cts +6 -5
- package/dist/types.d.ts +6 -5
- package/dist/{comment.types-C0m3sQ_Q.d.cts → use-session-events-DFksOgVA.d.cts} +177 -35
- package/dist/{comment.types-C0m3sQ_Q.d.ts → use-session-events-DFksOgVA.d.ts} +177 -35
- package/package.json +8 -3
package/dist/index.cjs
CHANGED
|
@@ -35,31 +35,25 @@ __export(src_exports, {
|
|
|
35
35
|
CommentOverlay: () => CommentOverlay,
|
|
36
36
|
CommentRenderer: () => CommentRenderer,
|
|
37
37
|
CommentScopeContext: () => CommentScopeContext,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
ConfirmSession: () => ConfirmSession,
|
|
39
|
+
CreateSession: () => CreateSession,
|
|
40
|
+
FeedbackSessionProvider: () => FeedbackSessionProvider,
|
|
41
|
+
ResolveSession: () => ResolveSession,
|
|
42
|
+
StartResolving: () => StartResolving,
|
|
40
43
|
ToggleOverlayButton: () => ToggleOverlayButton,
|
|
44
|
+
UserProvider: () => UserProvider,
|
|
41
45
|
useCommentScope: () => useCommentScope,
|
|
42
|
-
useComments: () => useComments
|
|
46
|
+
useComments: () => useComments,
|
|
47
|
+
useCurrentUser: () => useCurrentUser,
|
|
48
|
+
useFeedbackSession: () => useFeedbackSession
|
|
43
49
|
});
|
|
44
50
|
module.exports = __toCommonJS(src_exports);
|
|
45
51
|
|
|
46
52
|
// src/components/comment-overlay.tsx
|
|
47
|
-
var
|
|
53
|
+
var import_react5 = require("react");
|
|
48
54
|
|
|
49
55
|
// src/contexts/comment-context.tsx
|
|
50
|
-
var
|
|
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
|
-
}
|
|
56
|
+
var import_react4 = require("react");
|
|
63
57
|
|
|
64
58
|
// src/errors.ts
|
|
65
59
|
var BaseError = class extends Error {
|
|
@@ -76,23 +70,88 @@ var InsertError = class extends BaseError {
|
|
|
76
70
|
}
|
|
77
71
|
};
|
|
78
72
|
var ResolveError = class extends BaseError {
|
|
79
|
-
constructor(message = "An error occured while resolving your
|
|
73
|
+
constructor(message = "An error occured while resolving your comment") {
|
|
80
74
|
super(message, "RESOLVE_ERROR", 500);
|
|
81
75
|
}
|
|
82
76
|
};
|
|
83
77
|
var ConfirmError = class extends BaseError {
|
|
84
|
-
constructor(message = "An error occured while confirming your
|
|
78
|
+
constructor(message = "An error occured while confirming your session") {
|
|
85
79
|
super(message, "CONFIRM_ERROR", 500);
|
|
86
80
|
}
|
|
87
81
|
};
|
|
82
|
+
var SessionCreateError = class extends BaseError {
|
|
83
|
+
constructor(message = "An error occured while creating your session") {
|
|
84
|
+
super(message, "SESSION_CREATE_ERROR", 500);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var AddError = class extends BaseError {
|
|
88
|
+
constructor(message = "An error occured while adding your comment") {
|
|
89
|
+
super(message, "ADD_ERROR", 500);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var EditError = class extends BaseError {
|
|
93
|
+
constructor(message = "An error occured while editing your comment") {
|
|
94
|
+
super(message, "EDIT_ERROR", 500);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var DeleteError = class extends BaseError {
|
|
98
|
+
constructor(message = "An error occured while deleting your comment") {
|
|
99
|
+
super(message, "DELETE_ERROR", 500);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var SessionStateError = class extends BaseError {
|
|
103
|
+
constructor(message = "This action is not allowed in the current session state") {
|
|
104
|
+
super(message, "SESSION_STATE_ERROR", 500);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var ReopenError = class extends BaseError {
|
|
108
|
+
constructor(message = "An error occured while reopening your comment") {
|
|
109
|
+
super(message, "REOPEN_ERROR", 500);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var StartResolvingError = class extends BaseError {
|
|
113
|
+
constructor(message = "An error occured while starting the resolution of your session") {
|
|
114
|
+
super(message, "START_RESOLVING_ERROR", 500);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var SessionResolveError = class extends BaseError {
|
|
118
|
+
constructor(message = "An error occured while resolving your session") {
|
|
119
|
+
super(message, "SESSION_RESOLVE_ERROR", 500);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var PermissionError = class extends BaseError {
|
|
123
|
+
constructor(message = "You do not have permission to perform this action") {
|
|
124
|
+
super(message, "PERMISSION_ERROR", 500);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/lib/to-known-error.ts
|
|
129
|
+
var toKnownError = (reason, ErrorClass) => {
|
|
130
|
+
const message = reason instanceof Error && reason.message.length > 0 ? reason.message : void 0;
|
|
131
|
+
return new ErrorClass(message);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/lib/tx.ts
|
|
135
|
+
var import_tryx_handler = require("@j31/tryx-handler");
|
|
136
|
+
var tx = new import_tryx_handler.TryX({
|
|
137
|
+
timeout: 1e4
|
|
138
|
+
// 10 seconds
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// src/utils/hasStatus.ts
|
|
142
|
+
function hasStatus(status) {
|
|
143
|
+
return (comment) => comment.status === status;
|
|
144
|
+
}
|
|
88
145
|
|
|
89
146
|
// src/lib/use-comment-events.ts
|
|
90
147
|
var import_react = require("react");
|
|
91
148
|
var useCommentEvents = () => {
|
|
92
149
|
const listenersRef = (0, import_react.useRef)({
|
|
93
150
|
onFocusChange: /* @__PURE__ */ new Set(),
|
|
94
|
-
|
|
95
|
-
|
|
151
|
+
onCommentAdded: /* @__PURE__ */ new Set(),
|
|
152
|
+
onCommentEdited: /* @__PURE__ */ new Set(),
|
|
153
|
+
onCommentResolved: /* @__PURE__ */ new Set(),
|
|
154
|
+
onCommentReopened: /* @__PURE__ */ new Set(),
|
|
96
155
|
onCommentDeleted: /* @__PURE__ */ new Set(),
|
|
97
156
|
onCommentRegistered: /* @__PURE__ */ new Set()
|
|
98
157
|
});
|
|
@@ -115,17 +174,514 @@ var useCommentEvents = () => {
|
|
|
115
174
|
);
|
|
116
175
|
const events = {
|
|
117
176
|
onFocusChange: (callback) => subscribe("onFocusChange", callback),
|
|
118
|
-
|
|
119
|
-
|
|
177
|
+
onCommentAdded: (callback) => subscribe("onCommentAdded", callback),
|
|
178
|
+
onCommentEdited: (callback) => subscribe("onCommentEdited", callback),
|
|
179
|
+
onCommentResolved: (callback) => subscribe("onCommentResolved", callback),
|
|
180
|
+
onCommentReopened: (callback) => subscribe("onCommentReopened", callback),
|
|
120
181
|
onCommentDeleted: (callback) => subscribe("onCommentDeleted", callback),
|
|
121
182
|
onCommentRegistered: (callback) => subscribe("onCommentRegistered", callback)
|
|
122
183
|
};
|
|
123
184
|
return { events, emit };
|
|
124
185
|
};
|
|
125
186
|
|
|
126
|
-
// src/
|
|
187
|
+
// src/utils/select-visible-comments.ts
|
|
188
|
+
var normalizeDraftVisibility = (value) => value === "hidden" ? "hidden" : "visible";
|
|
189
|
+
var selectVisibleComments = ({
|
|
190
|
+
comments,
|
|
191
|
+
session,
|
|
192
|
+
draftVisibility = "visible",
|
|
193
|
+
currentUserId
|
|
194
|
+
}) => {
|
|
195
|
+
if (session === null) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const inSession = comments.filter(
|
|
199
|
+
(comment) => comment.sessionId === session.id
|
|
200
|
+
);
|
|
201
|
+
if (session.status !== "draft" || normalizeDraftVisibility(draftVisibility) !== "hidden") {
|
|
202
|
+
return inSession;
|
|
203
|
+
}
|
|
204
|
+
return inSession.filter((comment) => {
|
|
205
|
+
if (comment.status === "draft") {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const authorId = comment.user?.id;
|
|
209
|
+
return authorId === void 0 || authorId === currentUserId;
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/contexts/feedback-session-context.tsx
|
|
214
|
+
var import_react3 = require("react");
|
|
215
|
+
|
|
216
|
+
// src/lib/use-session-events.ts
|
|
217
|
+
var import_react2 = require("react");
|
|
218
|
+
var useSessionEvents = () => {
|
|
219
|
+
const listenersRef = (0, import_react2.useRef)({
|
|
220
|
+
onSessionCreated: /* @__PURE__ */ new Set(),
|
|
221
|
+
onSessionConfirmed: /* @__PURE__ */ new Set(),
|
|
222
|
+
onSessionResolving: /* @__PURE__ */ new Set(),
|
|
223
|
+
onSessionResolved: /* @__PURE__ */ new Set()
|
|
224
|
+
});
|
|
225
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
226
|
+
(event, callback) => {
|
|
227
|
+
listenersRef.current[event].add(callback);
|
|
228
|
+
return () => {
|
|
229
|
+
listenersRef.current[event].delete(callback);
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
[]
|
|
233
|
+
);
|
|
234
|
+
const emit = (0, import_react2.useCallback)(
|
|
235
|
+
(event, ...args) => {
|
|
236
|
+
for (const listener of listenersRef.current[event]) {
|
|
237
|
+
listener(...args);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
[]
|
|
241
|
+
);
|
|
242
|
+
const events = {
|
|
243
|
+
onSessionCreated: (callback) => subscribe("onSessionCreated", callback),
|
|
244
|
+
onSessionConfirmed: (callback) => subscribe("onSessionConfirmed", callback),
|
|
245
|
+
onSessionResolving: (callback) => subscribe("onSessionResolving", callback),
|
|
246
|
+
onSessionResolved: (callback) => subscribe("onSessionResolved", callback)
|
|
247
|
+
};
|
|
248
|
+
return { events, emit };
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// src/utils/session-reducer.ts
|
|
252
|
+
var initialSessionReducerState = {
|
|
253
|
+
session: null,
|
|
254
|
+
sessionState: "idle"
|
|
255
|
+
};
|
|
256
|
+
var withSession = (state, session) => ({ ...state, session });
|
|
257
|
+
var onSessionCreated = (state, action) => {
|
|
258
|
+
const { confirmedAt: _c, resolvedAt: _r, ...rest } = action.session;
|
|
259
|
+
return withSession(state, {
|
|
260
|
+
...rest,
|
|
261
|
+
participantIds: [...action.session.participantIds],
|
|
262
|
+
status: "draft",
|
|
263
|
+
comments: []
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
var onSessionConfirmed = (state, action) => {
|
|
267
|
+
const { session } = state;
|
|
268
|
+
if (!session || session.status !== "draft") return state;
|
|
269
|
+
return withSession(state, {
|
|
270
|
+
...session,
|
|
271
|
+
status: "confirmed",
|
|
272
|
+
confirmedAt: action.confirmedAt
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
var onResolvingStarted = (state) => {
|
|
276
|
+
const { session } = state;
|
|
277
|
+
if (!session || session.status !== "confirmed") return state;
|
|
278
|
+
return withSession(state, { ...session, status: "resolving" });
|
|
279
|
+
};
|
|
280
|
+
var onSessionResolved = (state, action) => {
|
|
281
|
+
const { session } = state;
|
|
282
|
+
if (!session || session.status !== "resolving") return state;
|
|
283
|
+
return withSession(state, {
|
|
284
|
+
...session,
|
|
285
|
+
status: "resolved",
|
|
286
|
+
resolvedAt: action.resolvedAt
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
var onCommentCommitted = (state, action) => {
|
|
290
|
+
const { session } = state;
|
|
291
|
+
if (!session || session.status !== "draft") return state;
|
|
292
|
+
const { comment } = action;
|
|
293
|
+
const exists = session.comments.some((c) => c.id === comment.id);
|
|
294
|
+
const comments = exists ? session.comments.map((c) => c.id === comment.id ? comment : c) : [...session.comments, comment];
|
|
295
|
+
const userId = comment.user?.id;
|
|
296
|
+
const participantIds = userId !== void 0 && !session.participantIds.includes(userId) ? [...session.participantIds, userId] : session.participantIds;
|
|
297
|
+
return withSession(state, { ...session, comments, participantIds });
|
|
298
|
+
};
|
|
299
|
+
var onCommentStatusChanged = (state, action) => {
|
|
300
|
+
const { session } = state;
|
|
301
|
+
if (!session || session.status !== "resolving") return state;
|
|
302
|
+
const { comment } = action;
|
|
303
|
+
return withSession(state, {
|
|
304
|
+
...session,
|
|
305
|
+
comments: session.comments.map((c) => c.id === comment.id ? comment : c)
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
var onCommentRemoved = (state, action) => {
|
|
309
|
+
const { session } = state;
|
|
310
|
+
if (!session || session.status !== "draft") return state;
|
|
311
|
+
return withSession(state, {
|
|
312
|
+
...session,
|
|
313
|
+
comments: session.comments.filter((c) => c.id !== action.commentId)
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
var onSetOperationState = (state, action) => {
|
|
317
|
+
if (state.sessionState === action.to) return state;
|
|
318
|
+
return { ...state, sessionState: action.to };
|
|
319
|
+
};
|
|
320
|
+
var sessionReducer = (state, action) => {
|
|
321
|
+
switch (action.type) {
|
|
322
|
+
case "SESSION_CREATED":
|
|
323
|
+
return onSessionCreated(state, action);
|
|
324
|
+
case "SESSION_CONFIRMED":
|
|
325
|
+
return onSessionConfirmed(state, action);
|
|
326
|
+
case "SESSION_RESOLVING_STARTED":
|
|
327
|
+
return onResolvingStarted(state, action);
|
|
328
|
+
case "SESSION_RESOLVED":
|
|
329
|
+
return onSessionResolved(state, action);
|
|
330
|
+
case "COMMENT_COMMITTED":
|
|
331
|
+
return onCommentCommitted(state, action);
|
|
332
|
+
case "COMMENT_STATUS_CHANGED":
|
|
333
|
+
return onCommentStatusChanged(state, action);
|
|
334
|
+
case "COMMENT_REMOVED":
|
|
335
|
+
return onCommentRemoved(state, action);
|
|
336
|
+
case "SET_OPERATION_STATE":
|
|
337
|
+
return onSetOperationState(state, action);
|
|
338
|
+
default:
|
|
339
|
+
return state;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
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);
|
|
127
365
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
128
|
-
var
|
|
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
|
+
// src/contexts/feedback-session-context.tsx
|
|
389
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
390
|
+
var FeedbackSessionContext = (0, import_react3.createContext)(
|
|
391
|
+
null
|
|
392
|
+
);
|
|
393
|
+
var SessionBridgeContext = (0, import_react3.createContext)(null);
|
|
394
|
+
var MAX_PROJECT_ID_LENGTH = 128;
|
|
395
|
+
var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
|
|
396
|
+
var pick = (value, fallback) => value !== void 0 ? value : fallback;
|
|
397
|
+
var createRefusal = (type, projectId, inFlight, session, hasCallback) => {
|
|
398
|
+
if (!isSessionType(type)) return "unknown session type";
|
|
399
|
+
if (!isValidProjectId(projectId)) {
|
|
400
|
+
return "projectId must be 1 to 128 characters";
|
|
401
|
+
}
|
|
402
|
+
if (inFlight === "creating") return "creation already in progress";
|
|
403
|
+
if (session?.status === "draft") return "draft session already exists";
|
|
404
|
+
if (!hasCallback) return "onCreateSession is not provided";
|
|
405
|
+
return null;
|
|
406
|
+
};
|
|
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
|
+
var FeedbackSessionProvider = ({
|
|
420
|
+
children,
|
|
421
|
+
initialSession,
|
|
422
|
+
projectId,
|
|
423
|
+
canResolveSession = false,
|
|
424
|
+
onCreateSession,
|
|
425
|
+
onConfirmSession,
|
|
426
|
+
onStartResolving,
|
|
427
|
+
onResolveSession,
|
|
428
|
+
onError
|
|
429
|
+
}) => {
|
|
430
|
+
const contextUser = useOptionalCurrentUser();
|
|
431
|
+
const initialParsedRef = (0, import_react3.useRef)(
|
|
432
|
+
void 0
|
|
433
|
+
);
|
|
434
|
+
if (initialParsedRef.current === void 0) {
|
|
435
|
+
initialParsedRef.current = initialSession === void 0 ? null : parseInitialSession(initialSession);
|
|
436
|
+
}
|
|
437
|
+
const [state, dispatch] = (0, import_react3.useReducer)(
|
|
438
|
+
sessionReducer,
|
|
439
|
+
initialParsedRef.current,
|
|
440
|
+
(session) => ({
|
|
441
|
+
...initialSessionReducerState,
|
|
442
|
+
session
|
|
443
|
+
})
|
|
444
|
+
);
|
|
445
|
+
const stateRef = (0, import_react3.useRef)({
|
|
446
|
+
...initialSessionReducerState,
|
|
447
|
+
session: initialParsedRef.current
|
|
448
|
+
});
|
|
449
|
+
const apply = (0, import_react3.useCallback)((action) => {
|
|
450
|
+
stateRef.current = sessionReducer(stateRef.current, action);
|
|
451
|
+
dispatch(action);
|
|
452
|
+
}, []);
|
|
453
|
+
const canResolveRef = (0, import_react3.useRef)(canResolveSession);
|
|
454
|
+
canResolveRef.current = canResolveSession;
|
|
455
|
+
const onErrorRef = (0, import_react3.useRef)(onError);
|
|
456
|
+
onErrorRef.current = onError;
|
|
457
|
+
const inFlightRef = (0, import_react3.useRef)("idle");
|
|
458
|
+
const localDraftCountsRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
459
|
+
const { events, emit } = useSessionEvents();
|
|
460
|
+
const report = (0, import_react3.useCallback)((error) => {
|
|
461
|
+
onErrorRef.current?.(error);
|
|
462
|
+
}, []);
|
|
463
|
+
(0, import_react3.useEffect)(() => {
|
|
464
|
+
if (initialSession !== void 0 && initialParsedRef.current === null) {
|
|
465
|
+
report(new SessionStateError("initialSession has an invalid status"));
|
|
466
|
+
}
|
|
467
|
+
}, []);
|
|
468
|
+
const createSession = (0, import_react3.useCallback)(
|
|
469
|
+
async (options) => {
|
|
470
|
+
const type = options?.type ?? "feedback";
|
|
471
|
+
const user = pick(options?.user, contextUser);
|
|
472
|
+
const sessionProjectId = pick(options?.projectId, projectId);
|
|
473
|
+
const refusal = createRefusal(
|
|
474
|
+
type,
|
|
475
|
+
sessionProjectId,
|
|
476
|
+
inFlightRef.current,
|
|
477
|
+
stateRef.current.session,
|
|
478
|
+
onCreateSession !== void 0
|
|
479
|
+
);
|
|
480
|
+
if (refusal !== null || !onCreateSession) {
|
|
481
|
+
const error = new SessionCreateError(refusal ?? void 0);
|
|
482
|
+
report(error);
|
|
483
|
+
return { error };
|
|
484
|
+
}
|
|
485
|
+
inFlightRef.current = "creating";
|
|
486
|
+
apply({ type: "SET_OPERATION_STATE", to: "creating" });
|
|
487
|
+
try {
|
|
488
|
+
const input = {
|
|
489
|
+
type,
|
|
490
|
+
user: user ?? null,
|
|
491
|
+
projectId: sessionProjectId
|
|
492
|
+
};
|
|
493
|
+
const { data, error } = await tx.executeAsync(
|
|
494
|
+
async () => onCreateSession(input)
|
|
495
|
+
);
|
|
496
|
+
if (error || !data) {
|
|
497
|
+
const known = toKnownError(error, SessionCreateError);
|
|
498
|
+
report(known);
|
|
499
|
+
return { error: known };
|
|
500
|
+
}
|
|
501
|
+
apply({
|
|
502
|
+
type: "SESSION_CREATED",
|
|
503
|
+
session: { ...data, status: "draft", type }
|
|
504
|
+
});
|
|
505
|
+
const created = stateRef.current.session;
|
|
506
|
+
if (created) emit("onSessionCreated", created);
|
|
507
|
+
return { error: null };
|
|
508
|
+
} finally {
|
|
509
|
+
inFlightRef.current = "idle";
|
|
510
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
[apply, contextUser, emit, onCreateSession, projectId, report]
|
|
514
|
+
);
|
|
515
|
+
const confirmSession = (0, import_react3.useCallback)(async () => {
|
|
516
|
+
if (inFlightRef.current === "confirming") return { error: null };
|
|
517
|
+
const session = stateRef.current.session;
|
|
518
|
+
const refusal = confirmRefusal(
|
|
519
|
+
session,
|
|
520
|
+
sumCounts(localDraftCountsRef.current)
|
|
521
|
+
);
|
|
522
|
+
if (refusal !== null || !session) {
|
|
523
|
+
const error = new SessionStateError(refusal ?? void 0);
|
|
524
|
+
report(error);
|
|
525
|
+
return { error };
|
|
526
|
+
}
|
|
527
|
+
inFlightRef.current = "confirming";
|
|
528
|
+
apply({ type: "SET_OPERATION_STATE", to: "confirming" });
|
|
529
|
+
try {
|
|
530
|
+
if (onConfirmSession) {
|
|
531
|
+
const { error } = await tx.executeAsync(
|
|
532
|
+
async () => onConfirmSession(session.id, session.type)
|
|
533
|
+
);
|
|
534
|
+
if (error) {
|
|
535
|
+
const known = toKnownError(error, ConfirmError);
|
|
536
|
+
report(known);
|
|
537
|
+
return { error: known };
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
apply({ type: "SESSION_CONFIRMED", confirmedAt: /* @__PURE__ */ new Date() });
|
|
541
|
+
const confirmed = stateRef.current.session;
|
|
542
|
+
if (confirmed) emit("onSessionConfirmed", confirmed);
|
|
543
|
+
return { error: null };
|
|
544
|
+
} finally {
|
|
545
|
+
inFlightRef.current = "idle";
|
|
546
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
547
|
+
}
|
|
548
|
+
}, [apply, emit, onConfirmSession, report]);
|
|
549
|
+
const refuse = (0, import_react3.useCallback)(
|
|
550
|
+
(error) => {
|
|
551
|
+
report(error);
|
|
552
|
+
return { error };
|
|
553
|
+
},
|
|
554
|
+
[report]
|
|
555
|
+
);
|
|
556
|
+
const runTransition = (0, import_react3.useCallback)(
|
|
557
|
+
async (step) => {
|
|
558
|
+
if (!canResolveRef.current) return refuse(new PermissionError());
|
|
559
|
+
if (inFlightRef.current === step.pending) return { error: null };
|
|
560
|
+
const session = stateRef.current.session;
|
|
561
|
+
const refusal = step.guard(session);
|
|
562
|
+
if (refusal !== null || !session) {
|
|
563
|
+
return refuse(new SessionStateError(refusal ?? void 0));
|
|
564
|
+
}
|
|
565
|
+
inFlightRef.current = step.pending;
|
|
566
|
+
apply({ type: "SET_OPERATION_STATE", to: step.pending });
|
|
567
|
+
try {
|
|
568
|
+
const call = step.call;
|
|
569
|
+
if (call) {
|
|
570
|
+
const { error } = await tx.executeAsync(async () => call(session.id));
|
|
571
|
+
if (error) return refuse(toKnownError(error, step.failure));
|
|
572
|
+
}
|
|
573
|
+
step.commit();
|
|
574
|
+
return { error: null };
|
|
575
|
+
} finally {
|
|
576
|
+
inFlightRef.current = "idle";
|
|
577
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
[apply, refuse]
|
|
581
|
+
);
|
|
582
|
+
const startResolving = (0, import_react3.useCallback)(
|
|
583
|
+
() => runTransition({
|
|
584
|
+
pending: "startingResolution",
|
|
585
|
+
guard: (session) => session?.status === "confirmed" ? null : "session is not confirmed",
|
|
586
|
+
call: onStartResolving,
|
|
587
|
+
failure: StartResolvingError,
|
|
588
|
+
commit: () => {
|
|
589
|
+
apply({ type: "SESSION_RESOLVING_STARTED" });
|
|
590
|
+
const resolving = stateRef.current.session;
|
|
591
|
+
if (resolving) emit("onSessionResolving", resolving);
|
|
592
|
+
}
|
|
593
|
+
}),
|
|
594
|
+
[apply, emit, onStartResolving, runTransition]
|
|
595
|
+
);
|
|
596
|
+
const resolveSession = (0, import_react3.useCallback)(
|
|
597
|
+
() => runTransition({
|
|
598
|
+
pending: "completingResolution",
|
|
599
|
+
guard: (session) => {
|
|
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
|
+
},
|
|
604
|
+
call: onResolveSession,
|
|
605
|
+
failure: SessionResolveError,
|
|
606
|
+
commit: () => {
|
|
607
|
+
apply({ type: "SESSION_RESOLVED", resolvedAt: /* @__PURE__ */ new Date() });
|
|
608
|
+
const resolved = stateRef.current.session;
|
|
609
|
+
if (resolved) emit("onSessionResolved", resolved);
|
|
610
|
+
}
|
|
611
|
+
}),
|
|
612
|
+
[apply, emit, onResolveSession, runTransition]
|
|
613
|
+
);
|
|
614
|
+
const commitComment = (0, import_react3.useCallback)(
|
|
615
|
+
(comment) => apply({ type: "COMMENT_COMMITTED", comment }),
|
|
616
|
+
[apply]
|
|
617
|
+
);
|
|
618
|
+
const commitCommentStatus = (0, import_react3.useCallback)(
|
|
619
|
+
(comment) => apply({ type: "COMMENT_STATUS_CHANGED", comment }),
|
|
620
|
+
[apply]
|
|
621
|
+
);
|
|
622
|
+
const removeComment = (0, import_react3.useCallback)(
|
|
623
|
+
(commentId) => apply({ type: "COMMENT_REMOVED", commentId }),
|
|
624
|
+
[apply]
|
|
625
|
+
);
|
|
626
|
+
const setLocalDraftCount = (0, import_react3.useCallback)(
|
|
627
|
+
(providerId, count) => {
|
|
628
|
+
if (count > 0) localDraftCountsRef.current.set(providerId, count);
|
|
629
|
+
else localDraftCountsRef.current.delete(providerId);
|
|
630
|
+
},
|
|
631
|
+
[]
|
|
632
|
+
);
|
|
633
|
+
const bridge = (0, import_react3.useMemo)(
|
|
634
|
+
() => ({
|
|
635
|
+
session: state.session,
|
|
636
|
+
canResolve: canResolveSession,
|
|
637
|
+
commitComment,
|
|
638
|
+
commitCommentStatus,
|
|
639
|
+
removeComment,
|
|
640
|
+
setLocalDraftCount
|
|
641
|
+
}),
|
|
642
|
+
[
|
|
643
|
+
state.session,
|
|
644
|
+
canResolveSession,
|
|
645
|
+
commitComment,
|
|
646
|
+
commitCommentStatus,
|
|
647
|
+
removeComment,
|
|
648
|
+
setLocalDraftCount
|
|
649
|
+
]
|
|
650
|
+
);
|
|
651
|
+
const value = {
|
|
652
|
+
session: state.session,
|
|
653
|
+
sessionState: state.sessionState,
|
|
654
|
+
canResolve: canResolveSession,
|
|
655
|
+
createSession,
|
|
656
|
+
confirmSession,
|
|
657
|
+
startResolving,
|
|
658
|
+
resolveSession,
|
|
659
|
+
events
|
|
660
|
+
};
|
|
661
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FeedbackSessionContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SessionBridgeContext.Provider, { value: bridge, children }) });
|
|
662
|
+
};
|
|
663
|
+
var useFeedbackSession = () => {
|
|
664
|
+
const context = (0, import_react3.useContext)(FeedbackSessionContext);
|
|
665
|
+
if (!context) {
|
|
666
|
+
throw new Error(
|
|
667
|
+
"useFeedbackSession must be used within a FeedbackSessionProvider"
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
return context;
|
|
671
|
+
};
|
|
672
|
+
var useSessionBridge = () => {
|
|
673
|
+
const bridge = (0, import_react3.useContext)(SessionBridgeContext);
|
|
674
|
+
if (!bridge) {
|
|
675
|
+
throw new Error(
|
|
676
|
+
"CommentContextProvider must be used within a FeedbackSessionProvider"
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
return bridge;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
// src/contexts/comment-context.tsx
|
|
683
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
684
|
+
var CommentContext = (0, import_react4.createContext)(null);
|
|
129
685
|
var commentReducer = (state, action) => {
|
|
130
686
|
switch (action.type) {
|
|
131
687
|
case "REGISTER": {
|
|
@@ -138,6 +694,7 @@ var commentReducer = (state, action) => {
|
|
|
138
694
|
...state.comments,
|
|
139
695
|
{
|
|
140
696
|
id: newId,
|
|
697
|
+
sessionId: action.sessionId,
|
|
141
698
|
projectId: state.projectId,
|
|
142
699
|
user: state.currentUser,
|
|
143
700
|
position: {
|
|
@@ -212,22 +769,14 @@ var commentReducer = (state, action) => {
|
|
|
212
769
|
}
|
|
213
770
|
}
|
|
214
771
|
};
|
|
215
|
-
case "
|
|
772
|
+
case "REPLACE_COMMENT":
|
|
216
773
|
return {
|
|
217
774
|
...state,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
case "RESET_RESOLVING_COMMENTS":
|
|
225
|
-
return {
|
|
226
|
-
...state,
|
|
227
|
-
comments: state.comments.filter(
|
|
228
|
-
(comment) => comment.status !== "resolving"
|
|
229
|
-
),
|
|
230
|
-
focussedComment: null
|
|
775
|
+
overlayState: "idle",
|
|
776
|
+
focussedComment: null,
|
|
777
|
+
comments: state.comments.map(
|
|
778
|
+
(comment) => comment.id === action.id ? action.comment : comment
|
|
779
|
+
)
|
|
231
780
|
};
|
|
232
781
|
default: {
|
|
233
782
|
console.warn(`Unhandled action type, returning state`, action);
|
|
@@ -247,30 +796,50 @@ var CommentContextProvider = ({
|
|
|
247
796
|
* @default "inactive"
|
|
248
797
|
*/
|
|
249
798
|
initialOverlayState,
|
|
250
|
-
|
|
251
|
-
onResolve,
|
|
252
|
-
currentUser,
|
|
799
|
+
currentUser: currentUserProp,
|
|
253
800
|
subscription,
|
|
254
801
|
config = {
|
|
255
802
|
commentVisibility: {
|
|
256
|
-
hideResolved: false
|
|
257
|
-
hideResolving: false
|
|
803
|
+
hideResolved: false
|
|
258
804
|
}
|
|
259
805
|
},
|
|
260
806
|
projectId,
|
|
261
|
-
onError
|
|
807
|
+
onError,
|
|
808
|
+
onAdd,
|
|
809
|
+
onEdit,
|
|
810
|
+
onDelete,
|
|
811
|
+
onResolve,
|
|
812
|
+
onReopen
|
|
262
813
|
}) => {
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
814
|
+
const hostRef = (0, import_react4.useRef)({ onAdd, onEdit, onDelete, onResolve, onReopen });
|
|
815
|
+
hostRef.current = { onAdd, onEdit, onDelete, onResolve, onReopen };
|
|
816
|
+
const bridge = useSessionBridge();
|
|
817
|
+
const bridgeRef = (0, import_react4.useRef)(bridge);
|
|
818
|
+
bridgeRef.current = bridge;
|
|
819
|
+
const canResolveRef = (0, import_react4.useRef)(bridge.canResolve);
|
|
820
|
+
canResolveRef.current = bridge.canResolve;
|
|
821
|
+
const contextUser = useOptionalCurrentUser();
|
|
822
|
+
const currentUser = contextUser !== void 0 ? contextUser : currentUserProp ?? null;
|
|
823
|
+
const currentUserRef = (0, import_react4.useRef)(currentUser);
|
|
824
|
+
currentUserRef.current = currentUser;
|
|
825
|
+
const [state, dispatch] = (0, import_react4.useReducer)(
|
|
826
|
+
(current, action) => commentReducer(
|
|
827
|
+
{ ...current, currentUser: currentUserRef.current },
|
|
828
|
+
action
|
|
829
|
+
),
|
|
830
|
+
void 0,
|
|
831
|
+
() => ({
|
|
832
|
+
comments: initialComments ?? bridge.session?.comments ?? [],
|
|
833
|
+
overlayState: initialOverlayState || "inactive",
|
|
834
|
+
currentUser,
|
|
835
|
+
focussedComment: null,
|
|
836
|
+
config,
|
|
837
|
+
projectId
|
|
838
|
+
})
|
|
839
|
+
);
|
|
271
840
|
const { events, emit } = useCommentEvents();
|
|
272
|
-
const prevFocusRef = (0,
|
|
273
|
-
(0,
|
|
841
|
+
const prevFocusRef = (0, import_react4.useRef)(null);
|
|
842
|
+
(0, import_react4.useEffect)(() => {
|
|
274
843
|
if (state.focussedComment !== prevFocusRef.current) {
|
|
275
844
|
const comment = state.comments.find(
|
|
276
845
|
(c) => c.id === state.focussedComment
|
|
@@ -279,7 +848,7 @@ var CommentContextProvider = ({
|
|
|
279
848
|
prevFocusRef.current = state.focussedComment;
|
|
280
849
|
}
|
|
281
850
|
}, [state.focussedComment, state.comments, emit]);
|
|
282
|
-
(0,
|
|
851
|
+
(0, import_react4.useEffect)(() => {
|
|
283
852
|
if (!subscription) return;
|
|
284
853
|
subscription.subscribe((data) => {
|
|
285
854
|
dispatch({ type: "APPEND_COMMENT", comment: data });
|
|
@@ -289,14 +858,20 @@ var CommentContextProvider = ({
|
|
|
289
858
|
};
|
|
290
859
|
}, [subscription]);
|
|
291
860
|
const registerComment = (position, indicatorPosition) => {
|
|
861
|
+
const session = bridgeRef.current.session;
|
|
862
|
+
if (session?.status !== "draft") {
|
|
863
|
+
onError?.(new SessionStateError());
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
292
866
|
dispatch({
|
|
293
867
|
type: "REGISTER",
|
|
868
|
+
sessionId: session.id,
|
|
294
869
|
position,
|
|
295
870
|
indicatorPosition: indicatorPosition || null
|
|
296
871
|
});
|
|
297
872
|
};
|
|
298
|
-
const prevCommentsLengthRef = (0,
|
|
299
|
-
(0,
|
|
873
|
+
const prevCommentsLengthRef = (0, import_react4.useRef)(state.comments.length);
|
|
874
|
+
(0, import_react4.useEffect)(() => {
|
|
300
875
|
if (state.comments.length > prevCommentsLengthRef.current) {
|
|
301
876
|
const lastComment = state.comments[state.comments.length - 1];
|
|
302
877
|
if (lastComment && lastComment.status === "draft") {
|
|
@@ -305,13 +880,154 @@ var CommentContextProvider = ({
|
|
|
305
880
|
}
|
|
306
881
|
prevCommentsLengthRef.current = state.comments.length;
|
|
307
882
|
}, [state.comments, emit]);
|
|
308
|
-
const
|
|
883
|
+
const providerId = (0, import_react4.useId)();
|
|
884
|
+
const localDraftCount = state.comments.filter(hasStatus("draft")).length;
|
|
885
|
+
(0, import_react4.useEffect)(() => {
|
|
886
|
+
bridgeRef.current.setLocalDraftCount(providerId, localDraftCount);
|
|
887
|
+
}, [providerId, localDraftCount]);
|
|
888
|
+
(0, import_react4.useEffect)(
|
|
889
|
+
() => () => bridgeRef.current.setLocalDraftCount(providerId, 0),
|
|
890
|
+
[providerId]
|
|
891
|
+
);
|
|
892
|
+
const fail = (error) => {
|
|
893
|
+
onError?.(error);
|
|
894
|
+
return { error };
|
|
895
|
+
};
|
|
896
|
+
const findComment = (id) => state.comments.find((comment) => comment.id === id);
|
|
897
|
+
const addComment = async (draft, content) => {
|
|
898
|
+
if (content.trim().length === 0) {
|
|
899
|
+
return fail(new AddError("content is empty"));
|
|
900
|
+
}
|
|
901
|
+
const persisted = {
|
|
902
|
+
...draft,
|
|
903
|
+
content,
|
|
904
|
+
status: "published"
|
|
905
|
+
};
|
|
906
|
+
const { onAdd: onAdd2 } = hostRef.current;
|
|
907
|
+
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "saving" });
|
|
908
|
+
if (onAdd2) {
|
|
909
|
+
const { error } = await tx.executeAsync(async () => onAdd2(persisted));
|
|
910
|
+
if (error) {
|
|
911
|
+
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "editing" });
|
|
912
|
+
return fail(toKnownError(error, AddError));
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
dispatch({ type: "REPLACE_COMMENT", id: draft.id, comment: persisted });
|
|
916
|
+
bridgeRef.current.commitComment(persisted);
|
|
917
|
+
emit("onCommentAdded", persisted);
|
|
918
|
+
return { error: null };
|
|
919
|
+
};
|
|
920
|
+
const editComment = async (comment, content) => {
|
|
921
|
+
if (content === comment.content) return { error: null };
|
|
922
|
+
const updated = {
|
|
923
|
+
...comment,
|
|
924
|
+
content,
|
|
925
|
+
status: "published"
|
|
926
|
+
};
|
|
927
|
+
const { onEdit: onEdit2 } = hostRef.current;
|
|
928
|
+
if (onEdit2) {
|
|
929
|
+
const { error } = await tx.executeAsync(async () => onEdit2(updated));
|
|
930
|
+
if (error) return fail(toKnownError(error, EditError));
|
|
931
|
+
}
|
|
932
|
+
dispatch({ type: "REPLACE_COMMENT", id: comment.id, comment: updated });
|
|
933
|
+
bridgeRef.current.commitComment(updated);
|
|
934
|
+
emit("onCommentEdited", updated);
|
|
935
|
+
return { error: null };
|
|
936
|
+
};
|
|
937
|
+
const updateComment = async (id, newComment) => {
|
|
938
|
+
const session = bridgeRef.current.session;
|
|
939
|
+
if (session?.status !== "draft") {
|
|
940
|
+
return fail(new SessionStateError());
|
|
941
|
+
}
|
|
942
|
+
const comment = findComment(id);
|
|
943
|
+
if (!comment) return fail(new EditError("comment not found"));
|
|
944
|
+
if (comment.status === "draft") {
|
|
945
|
+
if (comment.sessionId !== session.id) {
|
|
946
|
+
return fail(new SessionStateError());
|
|
947
|
+
}
|
|
948
|
+
return addComment(comment, newComment.content);
|
|
949
|
+
}
|
|
950
|
+
if (comment.status === "published") {
|
|
951
|
+
return editComment(comment, newComment.content);
|
|
952
|
+
}
|
|
953
|
+
return fail(new EditError("a resolved comment cannot be edited"));
|
|
954
|
+
};
|
|
955
|
+
const removePersisted = async (id) => {
|
|
956
|
+
const { onDelete: onDelete2 } = hostRef.current;
|
|
957
|
+
if (onDelete2) {
|
|
958
|
+
const { error } = await tx.executeAsync(async () => onDelete2(id));
|
|
959
|
+
if (error) return fail(toKnownError(error, DeleteError));
|
|
960
|
+
}
|
|
961
|
+
bridgeRef.current.removeComment(id);
|
|
309
962
|
dispatch({ type: "DELETE", id });
|
|
310
963
|
emit("onCommentDeleted", id);
|
|
964
|
+
return { error: null };
|
|
965
|
+
};
|
|
966
|
+
const deleteComment = async (id) => {
|
|
967
|
+
if (bridgeRef.current.session?.status !== "draft") {
|
|
968
|
+
return fail(new SessionStateError());
|
|
969
|
+
}
|
|
970
|
+
const comment = findComment(id);
|
|
971
|
+
if (!comment) return fail(new DeleteError("comment not found"));
|
|
972
|
+
if (comment.status === "draft") {
|
|
973
|
+
dispatch({ type: "DELETE", id });
|
|
974
|
+
emit("onCommentDeleted", id);
|
|
975
|
+
return { error: null };
|
|
976
|
+
}
|
|
977
|
+
return removePersisted(id);
|
|
311
978
|
};
|
|
312
|
-
const
|
|
313
|
-
|
|
979
|
+
const statusInFlightRef = (0, import_react4.useRef)(/* @__PURE__ */ new Set());
|
|
980
|
+
const guardStatusChange = (id, from, failure) => {
|
|
981
|
+
if (!canResolveRef.current) return fail(new PermissionError());
|
|
982
|
+
if (bridgeRef.current.session?.status !== "resolving") {
|
|
983
|
+
return fail(new SessionStateError());
|
|
984
|
+
}
|
|
985
|
+
const comment = findComment(id);
|
|
986
|
+
if (!comment) return fail(new failure("comment not found"));
|
|
987
|
+
if (comment.status !== from) return { error: null };
|
|
988
|
+
if (statusInFlightRef.current.has(id)) return { error: null };
|
|
989
|
+
return { comment };
|
|
314
990
|
};
|
|
991
|
+
const changeStatus = async (id, step) => {
|
|
992
|
+
const guard = guardStatusChange(id, step.from, step.failure);
|
|
993
|
+
if (!("comment" in guard)) return guard;
|
|
994
|
+
statusInFlightRef.current.add(id);
|
|
995
|
+
try {
|
|
996
|
+
const next = step.build(guard.comment);
|
|
997
|
+
if (step.call) {
|
|
998
|
+
const { call } = step;
|
|
999
|
+
const { error } = await tx.executeAsync(async () => call(next));
|
|
1000
|
+
if (error) return fail(toKnownError(error, step.failure));
|
|
1001
|
+
}
|
|
1002
|
+
dispatch({ type: "REPLACE_COMMENT", id, comment: next });
|
|
1003
|
+
bridgeRef.current.commitCommentStatus(next);
|
|
1004
|
+
emit(step.event, next);
|
|
1005
|
+
return { error: null };
|
|
1006
|
+
} finally {
|
|
1007
|
+
statusInFlightRef.current.delete(id);
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
const resolveComment = (id) => changeStatus(id, {
|
|
1011
|
+
from: "published",
|
|
1012
|
+
build: (comment) => ({
|
|
1013
|
+
...comment,
|
|
1014
|
+
status: "resolved",
|
|
1015
|
+
resolvedAt: /* @__PURE__ */ new Date()
|
|
1016
|
+
}),
|
|
1017
|
+
call: hostRef.current.onResolve,
|
|
1018
|
+
failure: ResolveError,
|
|
1019
|
+
event: "onCommentResolved"
|
|
1020
|
+
});
|
|
1021
|
+
const reopenComment = (id) => changeStatus(id, {
|
|
1022
|
+
from: "resolved",
|
|
1023
|
+
build: (comment) => {
|
|
1024
|
+
const { resolvedAt: _resolvedAt, ...rest } = comment;
|
|
1025
|
+
return { ...rest, status: "published" };
|
|
1026
|
+
},
|
|
1027
|
+
call: hostRef.current.onReopen,
|
|
1028
|
+
failure: ReopenError,
|
|
1029
|
+
event: "onCommentReopened"
|
|
1030
|
+
});
|
|
315
1031
|
const getActiveComment = () => {
|
|
316
1032
|
return state.comments.find(
|
|
317
1033
|
(comment) => comment.id === state.focussedComment
|
|
@@ -323,81 +1039,12 @@ var CommentContextProvider = ({
|
|
|
323
1039
|
const toggleOverlay = () => {
|
|
324
1040
|
dispatch({ type: "TOGGLE_OVERLAY" });
|
|
325
1041
|
};
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
};
|
|
332
|
-
const getResolvingComments = () => {
|
|
333
|
-
return state.comments.filter(hasStatus("resolving"));
|
|
334
|
-
};
|
|
335
|
-
const getResolvedComments = () => {
|
|
336
|
-
return state.comments.filter(hasStatus("resolved"));
|
|
337
|
-
};
|
|
338
|
-
const toggleResolvingComment = (id) => {
|
|
339
|
-
const comment = state.comments.find((comment2) => comment2.id === id);
|
|
340
|
-
dispatch({
|
|
341
|
-
type: "EDIT",
|
|
342
|
-
id,
|
|
343
|
-
newComment: {
|
|
344
|
-
status: comment?.status === "resolving" ? "published" : "resolving"
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
const confirmComments = async () => {
|
|
349
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "saving" });
|
|
350
|
-
const draftComments = getDraftComments();
|
|
351
|
-
const { error } = await tx.executeAsync(
|
|
352
|
-
async () => onConfirm(
|
|
353
|
-
draftComments.map((c) => ({
|
|
354
|
-
...c,
|
|
355
|
-
status: "published"
|
|
356
|
-
})),
|
|
357
|
-
projectId
|
|
358
|
-
)
|
|
359
|
-
);
|
|
360
|
-
if (error) {
|
|
361
|
-
if (onError) {
|
|
362
|
-
onError(new ConfirmError(error.message));
|
|
363
|
-
}
|
|
364
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
365
|
-
return { error: new ConfirmError(error.message) };
|
|
366
|
-
}
|
|
367
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
368
|
-
dispatch({ type: "RESET_DRAFT_COMMENTS" });
|
|
369
|
-
emit(
|
|
370
|
-
"onCommentsConfirmed",
|
|
371
|
-
draftComments.map((c) => ({ ...c, status: "published" }))
|
|
372
|
-
);
|
|
373
|
-
return { error: null };
|
|
374
|
-
};
|
|
375
|
-
const resolveComments = async () => {
|
|
376
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "resolving" });
|
|
377
|
-
const resolvingComments = getResolvingComments();
|
|
378
|
-
const { error } = await tx.executeAsync(
|
|
379
|
-
async () => onResolve(
|
|
380
|
-
resolvingComments.map((c) => ({
|
|
381
|
-
...c,
|
|
382
|
-
status: "resolved"
|
|
383
|
-
}))
|
|
384
|
-
)
|
|
385
|
-
);
|
|
386
|
-
if (error) {
|
|
387
|
-
if (onError) {
|
|
388
|
-
onError(new ResolveError(error.message));
|
|
389
|
-
}
|
|
390
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
391
|
-
return { error: new ResolveError(error.message) };
|
|
392
|
-
}
|
|
393
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
394
|
-
dispatch({ type: "RESET_RESOLVING_COMMENTS" });
|
|
395
|
-
emit(
|
|
396
|
-
"onCommentsResolved",
|
|
397
|
-
resolvingComments.map((c) => ({ ...c, status: "resolved" }))
|
|
398
|
-
);
|
|
399
|
-
return { error: null };
|
|
400
|
-
};
|
|
1042
|
+
const visibleComments = selectVisibleComments({
|
|
1043
|
+
comments: state.comments,
|
|
1044
|
+
session: bridge.session ? { id: bridge.session.id, status: bridge.session.status } : null,
|
|
1045
|
+
draftVisibility: state.config?.draftVisibility,
|
|
1046
|
+
currentUserId: currentUser?.id
|
|
1047
|
+
});
|
|
401
1048
|
const updateCommentVisibility = (visibility) => {
|
|
402
1049
|
dispatch({ type: "UPDATE_VISIBILITY", visibility });
|
|
403
1050
|
};
|
|
@@ -409,18 +1056,16 @@ var CommentContextProvider = ({
|
|
|
409
1056
|
onError(error);
|
|
410
1057
|
}
|
|
411
1058
|
};
|
|
412
|
-
return /* @__PURE__ */ (0,
|
|
1059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
413
1060
|
CommentContext.Provider,
|
|
414
1061
|
{
|
|
415
1062
|
value: {
|
|
416
|
-
draftComments:
|
|
417
|
-
comments:
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
allComments: state.comments,
|
|
1063
|
+
draftComments: visibleComments.filter(hasStatus("draft")),
|
|
1064
|
+
comments: visibleComments.filter(hasStatus("published")),
|
|
1065
|
+
resolvedComments: visibleComments.filter(hasStatus("resolved")),
|
|
1066
|
+
allComments: visibleComments,
|
|
421
1067
|
config: state.config,
|
|
422
1068
|
changeOverlayState,
|
|
423
|
-
toggleResolvingComment,
|
|
424
1069
|
overlayState: state.overlayState,
|
|
425
1070
|
deleteComment,
|
|
426
1071
|
updateComment,
|
|
@@ -428,9 +1073,10 @@ var CommentContextProvider = ({
|
|
|
428
1073
|
registerComment,
|
|
429
1074
|
getActiveComment,
|
|
430
1075
|
toggleOverlay,
|
|
431
|
-
confirmComments,
|
|
432
1076
|
currentUser,
|
|
433
|
-
|
|
1077
|
+
resolveComment,
|
|
1078
|
+
reopenComment,
|
|
1079
|
+
canResolve: bridge.canResolve,
|
|
434
1080
|
updateCommentVisibility,
|
|
435
1081
|
triggerError,
|
|
436
1082
|
events
|
|
@@ -440,7 +1086,8 @@ var CommentContextProvider = ({
|
|
|
440
1086
|
);
|
|
441
1087
|
};
|
|
442
1088
|
var useComments = () => {
|
|
443
|
-
|
|
1089
|
+
useSessionBridge();
|
|
1090
|
+
const context = (0, import_react4.useContext)(CommentContext);
|
|
444
1091
|
if (!context) {
|
|
445
1092
|
throw new Error("useComments must be used within a CommentContextProvider");
|
|
446
1093
|
}
|
|
@@ -461,7 +1108,7 @@ var normalizeRect = (a, b) => {
|
|
|
461
1108
|
};
|
|
462
1109
|
|
|
463
1110
|
// src/components/comment-overlay.tsx
|
|
464
|
-
var
|
|
1111
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
465
1112
|
var DRAG_THRESHOLD = 4;
|
|
466
1113
|
var CommentOverlay = ({ children, ...rest }) => {
|
|
467
1114
|
const {
|
|
@@ -472,10 +1119,10 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
472
1119
|
changeOverlayState,
|
|
473
1120
|
triggerError
|
|
474
1121
|
} = useComments();
|
|
475
|
-
const [preview, setPreview] = (0,
|
|
476
|
-
const startRef = (0,
|
|
477
|
-
const draggingRef = (0,
|
|
478
|
-
const overlayRef = (0,
|
|
1122
|
+
const [preview, setPreview] = (0, import_react5.useState)(null);
|
|
1123
|
+
const startRef = (0, import_react5.useRef)(null);
|
|
1124
|
+
const draggingRef = (0, import_react5.useRef)(false);
|
|
1125
|
+
const overlayRef = (0, import_react5.useRef)(null);
|
|
479
1126
|
const onPointerDown = (e) => {
|
|
480
1127
|
if (overlayState === "editing") {
|
|
481
1128
|
triggerError(
|
|
@@ -536,8 +1183,8 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
536
1183
|
setPreview(null);
|
|
537
1184
|
};
|
|
538
1185
|
if (overlayState === "inactive") return children;
|
|
539
|
-
return /* @__PURE__ */ (0,
|
|
540
|
-
/* @__PURE__ */ (0,
|
|
1186
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-overlay": true, style: { position: "relative", ...rest.style }, ...rest, children: [
|
|
1187
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
541
1188
|
"div",
|
|
542
1189
|
{
|
|
543
1190
|
ref: overlayRef,
|
|
@@ -551,7 +1198,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
551
1198
|
}
|
|
552
1199
|
),
|
|
553
1200
|
getActiveComment() && // biome-ignore lint: This element should only handle clicks as a guard
|
|
554
|
-
/* @__PURE__ */ (0,
|
|
1201
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
555
1202
|
"div",
|
|
556
1203
|
{
|
|
557
1204
|
"data-comment-guard": true,
|
|
@@ -577,7 +1224,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
577
1224
|
}
|
|
578
1225
|
}
|
|
579
1226
|
),
|
|
580
|
-
preview && /* @__PURE__ */ (0,
|
|
1227
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
581
1228
|
"div",
|
|
582
1229
|
{
|
|
583
1230
|
style: {
|
|
@@ -609,11 +1256,10 @@ var EDITING_STYLES = {
|
|
|
609
1256
|
};
|
|
610
1257
|
|
|
611
1258
|
// src/components/comment-renderer.tsx
|
|
612
|
-
var
|
|
1259
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
613
1260
|
var CommentRenderer = ({
|
|
614
1261
|
Comment: Comment2,
|
|
615
1262
|
DraftComment,
|
|
616
|
-
ResolvingComment,
|
|
617
1263
|
ResolvedComment
|
|
618
1264
|
}) => {
|
|
619
1265
|
const {
|
|
@@ -621,35 +1267,30 @@ var CommentRenderer = ({
|
|
|
621
1267
|
draftComments,
|
|
622
1268
|
overlayState,
|
|
623
1269
|
resolvedComments,
|
|
624
|
-
resolvingComments,
|
|
625
1270
|
config
|
|
626
1271
|
} = useComments();
|
|
627
1272
|
if (overlayState === "inactive") return null;
|
|
628
|
-
return /* @__PURE__ */ (0,
|
|
1273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
629
1274
|
draftComments.map((comment) => {
|
|
630
|
-
return /* @__PURE__ */ (0,
|
|
1275
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DraftComment, { comment }, comment.id);
|
|
631
1276
|
}),
|
|
632
1277
|
comments.map((comment) => {
|
|
633
|
-
return /* @__PURE__ */ (0,
|
|
634
|
-
}),
|
|
635
|
-
resolvingComments.map((comment) => {
|
|
636
|
-
if (config?.commentVisibility?.hideResolving) return null;
|
|
637
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ResolvingComment, { comment }, comment.id);
|
|
1278
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Comment2, { comment }, comment.id);
|
|
638
1279
|
}),
|
|
639
1280
|
resolvedComments.map((comment) => {
|
|
640
1281
|
if (config?.commentVisibility?.hideResolved) return null;
|
|
641
|
-
return /* @__PURE__ */ (0,
|
|
1282
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ResolvedComment, { comment }, comment.id);
|
|
642
1283
|
})
|
|
643
1284
|
] });
|
|
644
1285
|
};
|
|
645
1286
|
|
|
646
1287
|
// src/components/comment-actions.tsx
|
|
647
1288
|
var import_react_slot = require("@radix-ui/react-slot");
|
|
648
|
-
var
|
|
1289
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
649
1290
|
var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
650
1291
|
const { toggleOverlay, overlayState } = useComments();
|
|
651
1292
|
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
652
|
-
return /* @__PURE__ */ (0,
|
|
1293
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
653
1294
|
Comp,
|
|
654
1295
|
{
|
|
655
1296
|
"data-active": overlayState !== "inactive",
|
|
@@ -661,46 +1302,18 @@ var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
|
661
1302
|
}
|
|
662
1303
|
);
|
|
663
1304
|
};
|
|
664
|
-
var ConfirmComments = ({ asChild, ...rest }) => {
|
|
665
|
-
const { confirmComments } = useComments();
|
|
666
|
-
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
667
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
668
|
-
Comp,
|
|
669
|
-
{
|
|
670
|
-
...rest,
|
|
671
|
-
onClick: (e) => {
|
|
672
|
-
confirmComments();
|
|
673
|
-
rest.onClick?.(e);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
);
|
|
677
|
-
};
|
|
678
|
-
var ResolveComments = ({ asChild, ...rest }) => {
|
|
679
|
-
const { resolveComments } = useComments();
|
|
680
|
-
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
681
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
682
|
-
Comp,
|
|
683
|
-
{
|
|
684
|
-
...rest,
|
|
685
|
-
onClick: (e) => {
|
|
686
|
-
resolveComments();
|
|
687
|
-
rest.onClick?.(e);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
);
|
|
691
|
-
};
|
|
692
1305
|
|
|
693
1306
|
// src/components/comment.tsx
|
|
694
|
-
var
|
|
1307
|
+
var import_react6 = require("react");
|
|
695
1308
|
var import_react_slot2 = require("@radix-ui/react-slot");
|
|
696
1309
|
|
|
697
1310
|
// src/contexts/scoped-comment.tsx
|
|
698
|
-
var
|
|
699
|
-
var CommentScopeContext =
|
|
1311
|
+
var React2 = __toESM(require("react"), 1);
|
|
1312
|
+
var CommentScopeContext = React2.createContext(
|
|
700
1313
|
null
|
|
701
1314
|
);
|
|
702
1315
|
function useCommentScope() {
|
|
703
|
-
const ctx =
|
|
1316
|
+
const ctx = React2.useContext(CommentScopeContext);
|
|
704
1317
|
if (!ctx) {
|
|
705
1318
|
throw new Error("Comment.* must be used within <Comment.Root />");
|
|
706
1319
|
}
|
|
@@ -708,31 +1321,35 @@ function useCommentScope() {
|
|
|
708
1321
|
}
|
|
709
1322
|
|
|
710
1323
|
// src/components/comment.tsx
|
|
711
|
-
var
|
|
1324
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
712
1325
|
var CommentRoot = ({
|
|
713
1326
|
comment,
|
|
714
|
-
children,
|
|
715
1327
|
defaultDraft,
|
|
1328
|
+
withPosition = true,
|
|
1329
|
+
children,
|
|
716
1330
|
...rest
|
|
717
1331
|
}) => {
|
|
718
1332
|
const { getActiveComment } = useComments();
|
|
719
1333
|
const isActive = getActiveComment()?.id === comment.id;
|
|
720
|
-
const [draft, setDraft] = (0,
|
|
721
|
-
|
|
1334
|
+
const [draft, setDraft] = (0, import_react6.useState)(defaultDraft ?? comment.content ?? "");
|
|
1335
|
+
const positionStyles = {
|
|
1336
|
+
position: "absolute",
|
|
1337
|
+
top: comment.position.y,
|
|
1338
|
+
left: comment.position.x
|
|
1339
|
+
};
|
|
1340
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
722
1341
|
CommentScopeContext.Provider,
|
|
723
1342
|
{
|
|
724
1343
|
value: { comment, isActive, draft, setDraft },
|
|
725
|
-
children: /* @__PURE__ */ (0,
|
|
1344
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
726
1345
|
"div",
|
|
727
1346
|
{
|
|
728
1347
|
...rest,
|
|
729
1348
|
"data-comment": comment.id,
|
|
730
1349
|
"data-active": isActive,
|
|
731
1350
|
style: {
|
|
732
|
-
top: comment.position.y,
|
|
733
|
-
left: comment.position.x,
|
|
734
|
-
position: "absolute",
|
|
735
1351
|
zIndex: isActive ? 40 : 30,
|
|
1352
|
+
...withPosition ? positionStyles : {},
|
|
736
1353
|
...rest.style ?? {}
|
|
737
1354
|
},
|
|
738
1355
|
children
|
|
@@ -746,7 +1363,7 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
746
1363
|
const { config } = useComments();
|
|
747
1364
|
if (!comment.indicator) return null;
|
|
748
1365
|
if (config?.indicatorVisibility === "active" && !isActive) return null;
|
|
749
|
-
return /* @__PURE__ */ (0,
|
|
1366
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
750
1367
|
"div",
|
|
751
1368
|
{
|
|
752
1369
|
...rest,
|
|
@@ -768,12 +1385,12 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
768
1385
|
var CommentContent = ({ asChild, ...rest }) => {
|
|
769
1386
|
const { draft } = useCommentScope();
|
|
770
1387
|
const Comp = asChild ? import_react_slot2.Slot : "p";
|
|
771
|
-
return /* @__PURE__ */ (0,
|
|
1388
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Comp, { ...rest, children: draft });
|
|
772
1389
|
};
|
|
773
1390
|
var CommentEdit = ({ asChild, ...rest }) => {
|
|
774
1391
|
const { draft, setDraft } = useCommentScope();
|
|
775
1392
|
const Comp = asChild ? import_react_slot2.Slot : "textarea";
|
|
776
|
-
return /* @__PURE__ */ (0,
|
|
1393
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
777
1394
|
Comp,
|
|
778
1395
|
{
|
|
779
1396
|
...rest,
|
|
@@ -791,7 +1408,7 @@ var CommentConfirm = ({ asChild, ...rest }) => {
|
|
|
791
1408
|
const { updateComment } = useComments();
|
|
792
1409
|
const { comment, draft } = useCommentScope();
|
|
793
1410
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
794
|
-
return /* @__PURE__ */ (0,
|
|
1411
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
795
1412
|
Comp,
|
|
796
1413
|
{
|
|
797
1414
|
...rest,
|
|
@@ -807,7 +1424,7 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
807
1424
|
const { deleteComment } = useComments();
|
|
808
1425
|
const { comment } = useCommentScope();
|
|
809
1426
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
810
|
-
return /* @__PURE__ */ (0,
|
|
1427
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
811
1428
|
Comp,
|
|
812
1429
|
{
|
|
813
1430
|
...rest,
|
|
@@ -819,47 +1436,184 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
819
1436
|
);
|
|
820
1437
|
};
|
|
821
1438
|
var CommentResolve = ({ asChild, ...rest }) => {
|
|
822
|
-
const {
|
|
1439
|
+
const { resolveComment } = useComments();
|
|
823
1440
|
const { comment } = useCommentScope();
|
|
824
1441
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
825
1442
|
if (comment.status === "draft") {
|
|
826
1443
|
console.error(
|
|
827
|
-
`A draft comment can not be
|
|
1444
|
+
`A draft comment can not be resolved, remove this button from this comment: ${comment.id}`
|
|
828
1445
|
);
|
|
829
1446
|
return null;
|
|
830
1447
|
}
|
|
831
1448
|
if (comment.status === "resolved") {
|
|
832
1449
|
console.error(
|
|
833
|
-
`A resolved comment can not be
|
|
1450
|
+
`A resolved comment can not be resolved again, remove this button from this comment: ${comment.id}`
|
|
1451
|
+
);
|
|
1452
|
+
return null;
|
|
1453
|
+
}
|
|
1454
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1455
|
+
Comp,
|
|
1456
|
+
{
|
|
1457
|
+
...rest,
|
|
1458
|
+
onClick: (e) => {
|
|
1459
|
+
resolveComment(comment.id);
|
|
1460
|
+
rest.onClick?.(e);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
);
|
|
1464
|
+
};
|
|
1465
|
+
var CommentReopen = ({ asChild, ...rest }) => {
|
|
1466
|
+
const { reopenComment } = useComments();
|
|
1467
|
+
const { comment } = useCommentScope();
|
|
1468
|
+
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
1469
|
+
if (comment.status === "draft") {
|
|
1470
|
+
console.error(
|
|
1471
|
+
`A draft comment can not be reopened, remove this button from this comment: ${comment.id}`
|
|
1472
|
+
);
|
|
1473
|
+
return null;
|
|
1474
|
+
}
|
|
1475
|
+
if (comment.status === "published") {
|
|
1476
|
+
console.error(
|
|
1477
|
+
`A published comment can not be reopened, remove this button from this comment: ${comment.id}`
|
|
834
1478
|
);
|
|
835
1479
|
return null;
|
|
836
1480
|
}
|
|
837
|
-
return /* @__PURE__ */ (0,
|
|
1481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
838
1482
|
Comp,
|
|
839
1483
|
{
|
|
840
1484
|
...rest,
|
|
841
1485
|
onClick: (e) => {
|
|
842
|
-
|
|
1486
|
+
reopenComment(comment.id);
|
|
843
1487
|
rest.onClick?.(e);
|
|
844
1488
|
}
|
|
845
1489
|
}
|
|
846
1490
|
);
|
|
847
1491
|
};
|
|
848
1492
|
var Comment = {
|
|
1493
|
+
/**
|
|
1494
|
+
* The root component for a comment, must be used to wrap all other comment components.
|
|
1495
|
+
*
|
|
1496
|
+
* @param comment as the current comment from the comments array
|
|
1497
|
+
* @param defaultDraft as the optional initial value for the comment edit state
|
|
1498
|
+
* @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
|
+
*/
|
|
849
1500
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
850
1501
|
Root: CommentRoot,
|
|
1502
|
+
/**
|
|
1503
|
+
* The comment indicator
|
|
1504
|
+
*
|
|
1505
|
+
* @description Shows a dashed line that indicates a section this comment relates to
|
|
1506
|
+
*/
|
|
851
1507
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
852
1508
|
Indicator: CommentIndicator,
|
|
1509
|
+
/**
|
|
1510
|
+
* The comment's static safed content
|
|
1511
|
+
*
|
|
1512
|
+
* @description Displays the comment's content as a `<p>` tag
|
|
1513
|
+
* @param asChild as whether to use the child as the base element instead of the default `<p>` tag. This allows for more flexibility
|
|
1514
|
+
*/
|
|
853
1515
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
854
1516
|
Content: CommentContent,
|
|
1517
|
+
/**
|
|
1518
|
+
* The comment's editable content
|
|
1519
|
+
*
|
|
1520
|
+
* @description A textarea to edit the comment's content
|
|
1521
|
+
* @param asChild as whether to use the child as the base element instead of the default `<textarea>` tag. This allows for more flexibility
|
|
1522
|
+
*/
|
|
855
1523
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
856
1524
|
Edit: CommentEdit,
|
|
1525
|
+
/**
|
|
1526
|
+
* Confirms the changes made to a comment
|
|
1527
|
+
*
|
|
1528
|
+
* @description Updates the comment's content with the current draft
|
|
1529
|
+
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
1530
|
+
*/
|
|
857
1531
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
858
1532
|
Confirm: CommentConfirm,
|
|
1533
|
+
/**
|
|
1534
|
+
* Deletes a comment
|
|
1535
|
+
*
|
|
1536
|
+
* @description Removes the comment from the comment list
|
|
1537
|
+
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
1538
|
+
*/
|
|
859
1539
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
860
1540
|
Delete: CommentDelete,
|
|
1541
|
+
/**
|
|
1542
|
+
* Resolves a comment
|
|
1543
|
+
*
|
|
1544
|
+
* @description Calls `resolveComment` for this comment. Renders nothing (and logs an error) for draft and resolved comments
|
|
1545
|
+
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
1546
|
+
*/
|
|
1547
|
+
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
1548
|
+
Resolve: CommentResolve,
|
|
1549
|
+
/**
|
|
1550
|
+
* Reopens a resolved comment
|
|
1551
|
+
*
|
|
1552
|
+
* @description Calls `reopenComment` for this comment. Renders nothing (and logs an error) for draft and published comments
|
|
1553
|
+
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
1554
|
+
*/
|
|
861
1555
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
862
|
-
|
|
1556
|
+
Reopen: CommentReopen
|
|
1557
|
+
};
|
|
1558
|
+
|
|
1559
|
+
// src/components/session-actions.tsx
|
|
1560
|
+
var import_react_slot3 = require("@radix-ui/react-slot");
|
|
1561
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1562
|
+
var CreateSession = ({ asChild, ...rest }) => {
|
|
1563
|
+
const { createSession } = useFeedbackSession();
|
|
1564
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1565
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1566
|
+
Comp,
|
|
1567
|
+
{
|
|
1568
|
+
...rest,
|
|
1569
|
+
onClick: (e) => {
|
|
1570
|
+
void createSession();
|
|
1571
|
+
rest.onClick?.(e);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
);
|
|
1575
|
+
};
|
|
1576
|
+
var ConfirmSession = ({ asChild, ...rest }) => {
|
|
1577
|
+
const { confirmSession } = useFeedbackSession();
|
|
1578
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1579
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1580
|
+
Comp,
|
|
1581
|
+
{
|
|
1582
|
+
...rest,
|
|
1583
|
+
onClick: (e) => {
|
|
1584
|
+
void confirmSession();
|
|
1585
|
+
rest.onClick?.(e);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
);
|
|
1589
|
+
};
|
|
1590
|
+
var StartResolving = ({ asChild, ...rest }) => {
|
|
1591
|
+
const { startResolving } = useFeedbackSession();
|
|
1592
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1593
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1594
|
+
Comp,
|
|
1595
|
+
{
|
|
1596
|
+
...rest,
|
|
1597
|
+
onClick: (e) => {
|
|
1598
|
+
void startResolving();
|
|
1599
|
+
rest.onClick?.(e);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
);
|
|
1603
|
+
};
|
|
1604
|
+
var ResolveSession = ({ asChild, ...rest }) => {
|
|
1605
|
+
const { resolveSession } = useFeedbackSession();
|
|
1606
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1607
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1608
|
+
Comp,
|
|
1609
|
+
{
|
|
1610
|
+
...rest,
|
|
1611
|
+
onClick: (e) => {
|
|
1612
|
+
void resolveSession();
|
|
1613
|
+
rest.onClick?.(e);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
);
|
|
863
1617
|
};
|
|
864
1618
|
// Annotate the CommonJS export names for ESM import in node:
|
|
865
1619
|
0 && (module.exports = {
|
|
@@ -868,9 +1622,15 @@ var Comment = {
|
|
|
868
1622
|
CommentOverlay,
|
|
869
1623
|
CommentRenderer,
|
|
870
1624
|
CommentScopeContext,
|
|
871
|
-
|
|
872
|
-
|
|
1625
|
+
ConfirmSession,
|
|
1626
|
+
CreateSession,
|
|
1627
|
+
FeedbackSessionProvider,
|
|
1628
|
+
ResolveSession,
|
|
1629
|
+
StartResolving,
|
|
873
1630
|
ToggleOverlayButton,
|
|
1631
|
+
UserProvider,
|
|
874
1632
|
useCommentScope,
|
|
875
|
-
useComments
|
|
1633
|
+
useComments,
|
|
1634
|
+
useCurrentUser,
|
|
1635
|
+
useFeedbackSession
|
|
876
1636
|
});
|