@kendew-agency/react-feedback-layer 0.3.2 → 0.4.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +772 -451
- package/dist/index.cjs +981 -224
- package/dist/index.d.cts +69 -13
- package/dist/index.d.ts +69 -13
- package/dist/index.js +981 -220
- package/dist/types.d.cts +481 -7
- package/dist/types.d.ts +481 -7
- package/package.json +9 -3
- package/dist/comment.types-C0m3sQ_Q.d.cts +0 -322
- package/dist/comment.types-C0m3sQ_Q.d.ts +0 -322
package/dist/index.cjs
CHANGED
|
@@ -35,31 +35,24 @@ __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
|
+
commentReducer: () => commentReducer,
|
|
41
45
|
useCommentScope: () => useCommentScope,
|
|
42
|
-
useComments: () => useComments
|
|
46
|
+
useComments: () => useComments,
|
|
47
|
+
useFeedbackSession: () => useFeedbackSession
|
|
43
48
|
});
|
|
44
49
|
module.exports = __toCommonJS(src_exports);
|
|
45
50
|
|
|
46
51
|
// src/components/comment-overlay.tsx
|
|
47
|
-
var
|
|
52
|
+
var import_react5 = require("react");
|
|
48
53
|
|
|
49
54
|
// 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
|
-
}
|
|
55
|
+
var import_react4 = require("react");
|
|
63
56
|
|
|
64
57
|
// src/errors.ts
|
|
65
58
|
var BaseError = class extends Error {
|
|
@@ -76,23 +69,88 @@ var InsertError = class extends BaseError {
|
|
|
76
69
|
}
|
|
77
70
|
};
|
|
78
71
|
var ResolveError = class extends BaseError {
|
|
79
|
-
constructor(message = "An error occured while resolving your
|
|
72
|
+
constructor(message = "An error occured while resolving your comment") {
|
|
80
73
|
super(message, "RESOLVE_ERROR", 500);
|
|
81
74
|
}
|
|
82
75
|
};
|
|
83
76
|
var ConfirmError = class extends BaseError {
|
|
84
|
-
constructor(message = "An error occured while confirming your
|
|
77
|
+
constructor(message = "An error occured while confirming your session") {
|
|
85
78
|
super(message, "CONFIRM_ERROR", 500);
|
|
86
79
|
}
|
|
87
80
|
};
|
|
81
|
+
var SessionCreateError = class extends BaseError {
|
|
82
|
+
constructor(message = "An error occured while creating your session") {
|
|
83
|
+
super(message, "SESSION_CREATE_ERROR", 500);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var AddError = class extends BaseError {
|
|
87
|
+
constructor(message = "An error occured while adding your comment") {
|
|
88
|
+
super(message, "ADD_ERROR", 500);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var EditError = class extends BaseError {
|
|
92
|
+
constructor(message = "An error occured while editing your comment") {
|
|
93
|
+
super(message, "EDIT_ERROR", 500);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var DeleteError = class extends BaseError {
|
|
97
|
+
constructor(message = "An error occured while deleting your comment") {
|
|
98
|
+
super(message, "DELETE_ERROR", 500);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var SessionStateError = class extends BaseError {
|
|
102
|
+
constructor(message = "This action is not allowed in the current session state") {
|
|
103
|
+
super(message, "SESSION_STATE_ERROR", 500);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var ReopenError = class extends BaseError {
|
|
107
|
+
constructor(message = "An error occured while reopening your comment") {
|
|
108
|
+
super(message, "REOPEN_ERROR", 500);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var StartResolvingError = class extends BaseError {
|
|
112
|
+
constructor(message = "An error occured while starting the resolution of your session") {
|
|
113
|
+
super(message, "START_RESOLVING_ERROR", 500);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var SessionResolveError = class extends BaseError {
|
|
117
|
+
constructor(message = "An error occured while resolving your session") {
|
|
118
|
+
super(message, "SESSION_RESOLVE_ERROR", 500);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var PermissionError = class extends BaseError {
|
|
122
|
+
constructor(message = "You do not have permission to perform this action") {
|
|
123
|
+
super(message, "PERMISSION_ERROR", 500);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/lib/to-known-error.ts
|
|
128
|
+
var toKnownError = (reason, ErrorClass) => {
|
|
129
|
+
const message = reason instanceof Error && reason.message.length > 0 ? reason.message : void 0;
|
|
130
|
+
return new ErrorClass(message);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/lib/tx.ts
|
|
134
|
+
var import_tryx_handler = require("@j31/tryx-handler");
|
|
135
|
+
var tx = new import_tryx_handler.TryX({
|
|
136
|
+
timeout: 1e4
|
|
137
|
+
// 10 seconds
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// src/utils/hasStatus.ts
|
|
141
|
+
function hasStatus(status) {
|
|
142
|
+
return (comment) => comment.status === status;
|
|
143
|
+
}
|
|
88
144
|
|
|
89
145
|
// src/lib/use-comment-events.ts
|
|
90
146
|
var import_react = require("react");
|
|
91
147
|
var useCommentEvents = () => {
|
|
92
148
|
const listenersRef = (0, import_react.useRef)({
|
|
93
149
|
onFocusChange: /* @__PURE__ */ new Set(),
|
|
94
|
-
|
|
95
|
-
|
|
150
|
+
onCommentAdded: /* @__PURE__ */ new Set(),
|
|
151
|
+
onCommentEdited: /* @__PURE__ */ new Set(),
|
|
152
|
+
onCommentResolved: /* @__PURE__ */ new Set(),
|
|
153
|
+
onCommentReopened: /* @__PURE__ */ new Set(),
|
|
96
154
|
onCommentDeleted: /* @__PURE__ */ new Set(),
|
|
97
155
|
onCommentRegistered: /* @__PURE__ */ new Set()
|
|
98
156
|
});
|
|
@@ -115,17 +173,545 @@ var useCommentEvents = () => {
|
|
|
115
173
|
);
|
|
116
174
|
const events = {
|
|
117
175
|
onFocusChange: (callback) => subscribe("onFocusChange", callback),
|
|
118
|
-
|
|
119
|
-
|
|
176
|
+
onCommentAdded: (callback) => subscribe("onCommentAdded", callback),
|
|
177
|
+
onCommentEdited: (callback) => subscribe("onCommentEdited", callback),
|
|
178
|
+
onCommentResolved: (callback) => subscribe("onCommentResolved", callback),
|
|
179
|
+
onCommentReopened: (callback) => subscribe("onCommentReopened", callback),
|
|
120
180
|
onCommentDeleted: (callback) => subscribe("onCommentDeleted", callback),
|
|
121
181
|
onCommentRegistered: (callback) => subscribe("onCommentRegistered", callback)
|
|
122
182
|
};
|
|
123
183
|
return { events, emit };
|
|
124
184
|
};
|
|
125
185
|
|
|
126
|
-
// src/
|
|
186
|
+
// src/utils/select-visible-comments.ts
|
|
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
|
+
};
|
|
214
|
+
var selectVisibleComments = ({
|
|
215
|
+
comments,
|
|
216
|
+
session,
|
|
217
|
+
locationId,
|
|
218
|
+
draftVisibility = "visible",
|
|
219
|
+
currentUserId
|
|
220
|
+
}) => {
|
|
221
|
+
if (session === null) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
const inSession = selectCommentsByLocation({ comments, locationId }).filter(
|
|
225
|
+
(comment) => comment.sessionId === session.id
|
|
226
|
+
);
|
|
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
|
+
}
|
|
244
|
+
}
|
|
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
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return grouped;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/contexts/feedback-session-context.tsx
|
|
265
|
+
var import_react3 = require("react");
|
|
266
|
+
|
|
267
|
+
// src/lib/use-session-events.ts
|
|
268
|
+
var import_react2 = require("react");
|
|
269
|
+
var useSessionEvents = () => {
|
|
270
|
+
const listenersRef = (0, import_react2.useRef)({
|
|
271
|
+
onSessionCreated: /* @__PURE__ */ new Set(),
|
|
272
|
+
onSessionConfirmed: /* @__PURE__ */ new Set(),
|
|
273
|
+
onSessionResolving: /* @__PURE__ */ new Set(),
|
|
274
|
+
onSessionResolved: /* @__PURE__ */ new Set()
|
|
275
|
+
});
|
|
276
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
277
|
+
(event, callback) => {
|
|
278
|
+
listenersRef.current[event].add(callback);
|
|
279
|
+
return () => {
|
|
280
|
+
listenersRef.current[event].delete(callback);
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
[]
|
|
284
|
+
);
|
|
285
|
+
const emit = (0, import_react2.useCallback)(
|
|
286
|
+
(event, ...args) => {
|
|
287
|
+
for (const listener of listenersRef.current[event]) {
|
|
288
|
+
listener(...args);
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
[]
|
|
292
|
+
);
|
|
293
|
+
const events = {
|
|
294
|
+
onSessionCreated: (callback) => subscribe("onSessionCreated", callback),
|
|
295
|
+
onSessionConfirmed: (callback) => subscribe("onSessionConfirmed", callback),
|
|
296
|
+
onSessionResolving: (callback) => subscribe("onSessionResolving", callback),
|
|
297
|
+
onSessionResolved: (callback) => subscribe("onSessionResolved", callback)
|
|
298
|
+
};
|
|
299
|
+
return { events, emit };
|
|
300
|
+
};
|
|
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
|
+
|
|
341
|
+
// src/utils/session-reducer.ts
|
|
342
|
+
var initialSessionReducerState = {
|
|
343
|
+
session: null,
|
|
344
|
+
sessionState: "idle"
|
|
345
|
+
};
|
|
346
|
+
var withSession = (state, session) => ({ ...state, session });
|
|
347
|
+
var onSessionCreated = (state, action) => {
|
|
348
|
+
const { confirmedAt: _c, resolvedAt: _r, ...rest } = action.session;
|
|
349
|
+
return withSession(state, {
|
|
350
|
+
...rest,
|
|
351
|
+
participantIds: [...action.session.participantIds],
|
|
352
|
+
status: "draft",
|
|
353
|
+
comments: []
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
var onSessionConfirmed = (state, action) => {
|
|
357
|
+
const { session } = state;
|
|
358
|
+
if (!session || session.status !== "draft") return state;
|
|
359
|
+
return withSession(state, {
|
|
360
|
+
...session,
|
|
361
|
+
status: "confirmed",
|
|
362
|
+
confirmedAt: action.confirmedAt
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
var onResolvingStarted = (state) => {
|
|
366
|
+
const { session } = state;
|
|
367
|
+
if (!session || session.status !== "confirmed") return state;
|
|
368
|
+
return withSession(state, { ...session, status: "resolving" });
|
|
369
|
+
};
|
|
370
|
+
var onSessionResolved = (state, action) => {
|
|
371
|
+
const { session } = state;
|
|
372
|
+
if (!session || session.status !== "resolving") return state;
|
|
373
|
+
return withSession(state, {
|
|
374
|
+
...session,
|
|
375
|
+
status: "resolved",
|
|
376
|
+
resolvedAt: action.resolvedAt
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
var onCommentCommitted = (state, action) => {
|
|
380
|
+
const { session } = state;
|
|
381
|
+
if (!session || session.status !== "draft") return state;
|
|
382
|
+
const { comment } = action;
|
|
383
|
+
const exists = session.comments.some((c) => c.id === comment.id);
|
|
384
|
+
const comments = exists ? session.comments.map((c) => c.id === comment.id ? comment : c) : [...session.comments, comment];
|
|
385
|
+
const userId = comment.user?.id;
|
|
386
|
+
const participantIds = userId !== void 0 && !session.participantIds.includes(userId) ? [...session.participantIds, userId] : session.participantIds;
|
|
387
|
+
return withSession(state, { ...session, comments, participantIds });
|
|
388
|
+
};
|
|
389
|
+
var onCommentStatusChanged = (state, action) => {
|
|
390
|
+
const { session } = state;
|
|
391
|
+
if (!session || session.status !== "resolving") return state;
|
|
392
|
+
const { comment } = action;
|
|
393
|
+
return withSession(state, {
|
|
394
|
+
...session,
|
|
395
|
+
comments: session.comments.map((c) => c.id === comment.id ? comment : c)
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
var onCommentRemoved = (state, action) => {
|
|
399
|
+
const { session } = state;
|
|
400
|
+
if (!session || session.status !== "draft") return state;
|
|
401
|
+
return withSession(state, {
|
|
402
|
+
...session,
|
|
403
|
+
comments: session.comments.filter((c) => c.id !== action.commentId)
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
var onSetOperationState = (state, action) => {
|
|
407
|
+
if (state.sessionState === action.to) return state;
|
|
408
|
+
return { ...state, sessionState: action.to };
|
|
409
|
+
};
|
|
410
|
+
var sessionReducer = (state, action) => {
|
|
411
|
+
switch (action.type) {
|
|
412
|
+
case "SESSION_CREATED":
|
|
413
|
+
return onSessionCreated(state, action);
|
|
414
|
+
case "SESSION_CONFIRMED":
|
|
415
|
+
return onSessionConfirmed(state, action);
|
|
416
|
+
case "SESSION_RESOLVING_STARTED":
|
|
417
|
+
return onResolvingStarted(state, action);
|
|
418
|
+
case "SESSION_RESOLVED":
|
|
419
|
+
return onSessionResolved(state, action);
|
|
420
|
+
case "COMMENT_COMMITTED":
|
|
421
|
+
return onCommentCommitted(state, action);
|
|
422
|
+
case "COMMENT_STATUS_CHANGED":
|
|
423
|
+
return onCommentStatusChanged(state, action);
|
|
424
|
+
case "COMMENT_REMOVED":
|
|
425
|
+
return onCommentRemoved(state, action);
|
|
426
|
+
case "SET_OPERATION_STATE":
|
|
427
|
+
return onSetOperationState(state, action);
|
|
428
|
+
default:
|
|
429
|
+
return state;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// src/contexts/feedback-session-context.tsx
|
|
127
434
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
128
|
-
var
|
|
435
|
+
var FeedbackSessionContext = (0, import_react3.createContext)(
|
|
436
|
+
null
|
|
437
|
+
);
|
|
438
|
+
var SessionBridgeContext = (0, import_react3.createContext)(null);
|
|
439
|
+
var MAX_PROJECT_ID_LENGTH = 128;
|
|
440
|
+
var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
|
|
441
|
+
var pick = (value, fallback) => value !== void 0 ? value : fallback;
|
|
442
|
+
var createRefusal = (type, projectId, inFlight, session, hasCallback, user) => {
|
|
443
|
+
if (!user) return "user is required";
|
|
444
|
+
if (!isSessionType(type)) return "unknown session type";
|
|
445
|
+
if (!isValidProjectId(projectId)) {
|
|
446
|
+
return "projectId must be 1 to 128 characters";
|
|
447
|
+
}
|
|
448
|
+
if (inFlight === "creating") return "creation already in progress";
|
|
449
|
+
if (session?.status === "draft") return "draft session already exists";
|
|
450
|
+
if (!hasCallback) return "onCreateSession is not provided";
|
|
451
|
+
return null;
|
|
452
|
+
};
|
|
453
|
+
var FeedbackSessionProvider = ({
|
|
454
|
+
children,
|
|
455
|
+
initialSession,
|
|
456
|
+
projectId,
|
|
457
|
+
canResolveSession = false,
|
|
458
|
+
onCreateSession,
|
|
459
|
+
onConfirmSession,
|
|
460
|
+
onStartResolving,
|
|
461
|
+
onResolveSession,
|
|
462
|
+
onError
|
|
463
|
+
}) => {
|
|
464
|
+
const initialParsedRef = (0, import_react3.useRef)(
|
|
465
|
+
void 0
|
|
466
|
+
);
|
|
467
|
+
if (initialParsedRef.current === void 0) {
|
|
468
|
+
initialParsedRef.current = initialSession === void 0 ? null : parseInitialSession(initialSession);
|
|
469
|
+
}
|
|
470
|
+
const [state, dispatch] = (0, import_react3.useReducer)(
|
|
471
|
+
sessionReducer,
|
|
472
|
+
initialParsedRef.current,
|
|
473
|
+
(session) => ({
|
|
474
|
+
...initialSessionReducerState,
|
|
475
|
+
session
|
|
476
|
+
})
|
|
477
|
+
);
|
|
478
|
+
const stateRef = (0, import_react3.useRef)({
|
|
479
|
+
...initialSessionReducerState,
|
|
480
|
+
session: initialParsedRef.current
|
|
481
|
+
});
|
|
482
|
+
const apply = (0, import_react3.useCallback)((action) => {
|
|
483
|
+
stateRef.current = sessionReducer(stateRef.current, action);
|
|
484
|
+
dispatch(action);
|
|
485
|
+
}, []);
|
|
486
|
+
const canResolveRef = (0, import_react3.useRef)(canResolveSession);
|
|
487
|
+
canResolveRef.current = canResolveSession;
|
|
488
|
+
const onErrorRef = (0, import_react3.useRef)(onError);
|
|
489
|
+
onErrorRef.current = onError;
|
|
490
|
+
const inFlightRef = (0, import_react3.useRef)("idle");
|
|
491
|
+
const localDraftCountsRef = (0, import_react3.useRef)(/* @__PURE__ */ new Map());
|
|
492
|
+
const { events, emit } = useSessionEvents();
|
|
493
|
+
const report = (0, import_react3.useCallback)((error) => {
|
|
494
|
+
onErrorRef.current?.(error);
|
|
495
|
+
}, []);
|
|
496
|
+
(0, import_react3.useEffect)(() => {
|
|
497
|
+
if (initialSession !== void 0 && initialParsedRef.current === null) {
|
|
498
|
+
report(new SessionStateError("initialSession has an invalid status"));
|
|
499
|
+
}
|
|
500
|
+
}, []);
|
|
501
|
+
const createSession = (0, import_react3.useCallback)(
|
|
502
|
+
async (options) => {
|
|
503
|
+
const type = options?.type ?? "feedback";
|
|
504
|
+
const user = options?.user;
|
|
505
|
+
const sessionProjectId = pick(options?.projectId, projectId);
|
|
506
|
+
const refusal = createRefusal(
|
|
507
|
+
type,
|
|
508
|
+
sessionProjectId,
|
|
509
|
+
inFlightRef.current,
|
|
510
|
+
stateRef.current.session,
|
|
511
|
+
onCreateSession !== void 0,
|
|
512
|
+
user
|
|
513
|
+
);
|
|
514
|
+
if (refusal !== null || !onCreateSession) {
|
|
515
|
+
const error = new SessionCreateError(refusal ?? void 0);
|
|
516
|
+
report(error);
|
|
517
|
+
return { error };
|
|
518
|
+
}
|
|
519
|
+
inFlightRef.current = "creating";
|
|
520
|
+
apply({ type: "SET_OPERATION_STATE", to: "creating" });
|
|
521
|
+
try {
|
|
522
|
+
const input = {
|
|
523
|
+
type,
|
|
524
|
+
user,
|
|
525
|
+
projectId: sessionProjectId
|
|
526
|
+
};
|
|
527
|
+
const { data, error } = await tx.executeAsync(
|
|
528
|
+
async () => onCreateSession(input)
|
|
529
|
+
);
|
|
530
|
+
if (error || !data) {
|
|
531
|
+
const known = toKnownError(error, SessionCreateError);
|
|
532
|
+
report(known);
|
|
533
|
+
return { error: known };
|
|
534
|
+
}
|
|
535
|
+
apply({
|
|
536
|
+
type: "SESSION_CREATED",
|
|
537
|
+
session: { ...data, status: "draft", type }
|
|
538
|
+
});
|
|
539
|
+
const created = stateRef.current.session;
|
|
540
|
+
if (created) emit("onSessionCreated", created);
|
|
541
|
+
return { error: null };
|
|
542
|
+
} finally {
|
|
543
|
+
inFlightRef.current = "idle";
|
|
544
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
[apply, emit, onCreateSession, projectId, report]
|
|
548
|
+
);
|
|
549
|
+
const confirmSession = (0, import_react3.useCallback)(async () => {
|
|
550
|
+
if (inFlightRef.current === "confirming") return { error: null };
|
|
551
|
+
const session = stateRef.current.session;
|
|
552
|
+
const refusal = confirmRefusal(
|
|
553
|
+
session,
|
|
554
|
+
sumCounts(localDraftCountsRef.current)
|
|
555
|
+
);
|
|
556
|
+
if (refusal !== null || !session) {
|
|
557
|
+
const error = new SessionStateError(refusal ?? void 0);
|
|
558
|
+
report(error);
|
|
559
|
+
return { error };
|
|
560
|
+
}
|
|
561
|
+
inFlightRef.current = "confirming";
|
|
562
|
+
apply({ type: "SET_OPERATION_STATE", to: "confirming" });
|
|
563
|
+
try {
|
|
564
|
+
if (onConfirmSession) {
|
|
565
|
+
const { error } = await tx.executeAsync(
|
|
566
|
+
async () => onConfirmSession(session.id, session.type)
|
|
567
|
+
);
|
|
568
|
+
if (error) {
|
|
569
|
+
const known = toKnownError(error, ConfirmError);
|
|
570
|
+
report(known);
|
|
571
|
+
return { error: known };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
apply({ type: "SESSION_CONFIRMED", confirmedAt: /* @__PURE__ */ new Date() });
|
|
575
|
+
const confirmed = stateRef.current.session;
|
|
576
|
+
if (confirmed) emit("onSessionConfirmed", confirmed);
|
|
577
|
+
return { error: null };
|
|
578
|
+
} finally {
|
|
579
|
+
inFlightRef.current = "idle";
|
|
580
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
581
|
+
}
|
|
582
|
+
}, [apply, emit, onConfirmSession, report]);
|
|
583
|
+
const refuse = (0, import_react3.useCallback)(
|
|
584
|
+
(error) => {
|
|
585
|
+
report(error);
|
|
586
|
+
return { error };
|
|
587
|
+
},
|
|
588
|
+
[report]
|
|
589
|
+
);
|
|
590
|
+
const runTransition = (0, import_react3.useCallback)(
|
|
591
|
+
async (step) => {
|
|
592
|
+
if (!canResolveRef.current) return refuse(new PermissionError());
|
|
593
|
+
if (inFlightRef.current === step.pending) return { error: null };
|
|
594
|
+
const session = stateRef.current.session;
|
|
595
|
+
const refusal = step.guard(session);
|
|
596
|
+
if (refusal !== null || !session) {
|
|
597
|
+
return refuse(new SessionStateError(refusal ?? void 0));
|
|
598
|
+
}
|
|
599
|
+
inFlightRef.current = step.pending;
|
|
600
|
+
apply({ type: "SET_OPERATION_STATE", to: step.pending });
|
|
601
|
+
try {
|
|
602
|
+
const call = step.call;
|
|
603
|
+
if (call) {
|
|
604
|
+
const { error } = await tx.executeAsync(async () => call(session.id));
|
|
605
|
+
if (error) return refuse(toKnownError(error, step.failure));
|
|
606
|
+
}
|
|
607
|
+
step.commit();
|
|
608
|
+
return { error: null };
|
|
609
|
+
} finally {
|
|
610
|
+
inFlightRef.current = "idle";
|
|
611
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
[apply, refuse]
|
|
615
|
+
);
|
|
616
|
+
const startResolving = (0, import_react3.useCallback)(
|
|
617
|
+
() => runTransition({
|
|
618
|
+
pending: "startingResolution",
|
|
619
|
+
guard: (session) => session?.status === "confirmed" ? null : "session is not confirmed",
|
|
620
|
+
call: onStartResolving,
|
|
621
|
+
failure: StartResolvingError,
|
|
622
|
+
commit: () => {
|
|
623
|
+
apply({ type: "SESSION_RESOLVING_STARTED" });
|
|
624
|
+
const resolving = stateRef.current.session;
|
|
625
|
+
if (resolving) emit("onSessionResolving", resolving);
|
|
626
|
+
}
|
|
627
|
+
}),
|
|
628
|
+
[apply, emit, onStartResolving, runTransition]
|
|
629
|
+
);
|
|
630
|
+
const resolveSession = (0, import_react3.useCallback)(
|
|
631
|
+
() => runTransition({
|
|
632
|
+
pending: "completingResolution",
|
|
633
|
+
guard: resolveRefusal,
|
|
634
|
+
call: onResolveSession,
|
|
635
|
+
failure: SessionResolveError,
|
|
636
|
+
commit: () => {
|
|
637
|
+
apply({ type: "SESSION_RESOLVED", resolvedAt: /* @__PURE__ */ new Date() });
|
|
638
|
+
const resolved = stateRef.current.session;
|
|
639
|
+
if (resolved) emit("onSessionResolved", resolved);
|
|
640
|
+
}
|
|
641
|
+
}),
|
|
642
|
+
[apply, emit, onResolveSession, runTransition]
|
|
643
|
+
);
|
|
644
|
+
const commitComment = (0, import_react3.useCallback)(
|
|
645
|
+
(comment) => apply({ type: "COMMENT_COMMITTED", comment }),
|
|
646
|
+
[apply]
|
|
647
|
+
);
|
|
648
|
+
const commitCommentStatus = (0, import_react3.useCallback)(
|
|
649
|
+
(comment) => apply({ type: "COMMENT_STATUS_CHANGED", comment }),
|
|
650
|
+
[apply]
|
|
651
|
+
);
|
|
652
|
+
const removeComment = (0, import_react3.useCallback)(
|
|
653
|
+
(commentId) => apply({ type: "COMMENT_REMOVED", commentId }),
|
|
654
|
+
[apply]
|
|
655
|
+
);
|
|
656
|
+
const setLocalDraftCount = (0, import_react3.useCallback)(
|
|
657
|
+
(providerId, count) => {
|
|
658
|
+
if (count > 0) localDraftCountsRef.current.set(providerId, count);
|
|
659
|
+
else localDraftCountsRef.current.delete(providerId);
|
|
660
|
+
},
|
|
661
|
+
[]
|
|
662
|
+
);
|
|
663
|
+
const bridge = (0, import_react3.useMemo)(
|
|
664
|
+
() => ({
|
|
665
|
+
session: state.session,
|
|
666
|
+
canResolve: canResolveSession,
|
|
667
|
+
commitComment,
|
|
668
|
+
commitCommentStatus,
|
|
669
|
+
removeComment,
|
|
670
|
+
setLocalDraftCount
|
|
671
|
+
}),
|
|
672
|
+
[
|
|
673
|
+
state.session,
|
|
674
|
+
canResolveSession,
|
|
675
|
+
commitComment,
|
|
676
|
+
commitCommentStatus,
|
|
677
|
+
removeComment,
|
|
678
|
+
setLocalDraftCount
|
|
679
|
+
]
|
|
680
|
+
);
|
|
681
|
+
const value = {
|
|
682
|
+
session: state.session,
|
|
683
|
+
sessionState: state.sessionState,
|
|
684
|
+
canResolve: canResolveSession,
|
|
685
|
+
createSession,
|
|
686
|
+
confirmSession,
|
|
687
|
+
startResolving,
|
|
688
|
+
resolveSession,
|
|
689
|
+
events
|
|
690
|
+
};
|
|
691
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FeedbackSessionContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SessionBridgeContext.Provider, { value: bridge, children }) });
|
|
692
|
+
};
|
|
693
|
+
var useFeedbackSession = () => {
|
|
694
|
+
const context = (0, import_react3.useContext)(FeedbackSessionContext);
|
|
695
|
+
if (!context) {
|
|
696
|
+
throw new Error(
|
|
697
|
+
"useFeedbackSession must be used within a FeedbackSessionProvider"
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
return context;
|
|
701
|
+
};
|
|
702
|
+
var useSessionBridge = () => {
|
|
703
|
+
const bridge = (0, import_react3.useContext)(SessionBridgeContext);
|
|
704
|
+
if (!bridge) {
|
|
705
|
+
throw new Error(
|
|
706
|
+
"CommentContextProvider must be used within a FeedbackSessionProvider"
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
return bridge;
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/contexts/comment-context.tsx
|
|
713
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
714
|
+
var CommentContext = (0, import_react4.createContext)(null);
|
|
129
715
|
var commentReducer = (state, action) => {
|
|
130
716
|
switch (action.type) {
|
|
131
717
|
case "REGISTER": {
|
|
@@ -138,6 +724,8 @@ var commentReducer = (state, action) => {
|
|
|
138
724
|
...state.comments,
|
|
139
725
|
{
|
|
140
726
|
id: newId,
|
|
727
|
+
sessionId: action.sessionId,
|
|
728
|
+
locationId: action.locationId,
|
|
141
729
|
projectId: state.projectId,
|
|
142
730
|
user: state.currentUser,
|
|
143
731
|
position: {
|
|
@@ -212,22 +800,14 @@ var commentReducer = (state, action) => {
|
|
|
212
800
|
}
|
|
213
801
|
}
|
|
214
802
|
};
|
|
215
|
-
case "
|
|
216
|
-
return {
|
|
217
|
-
...state,
|
|
218
|
-
comments: state.comments.filter(
|
|
219
|
-
(comment) => comment.status !== "draft"
|
|
220
|
-
),
|
|
221
|
-
focussedComment: null
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
case "RESET_RESOLVING_COMMENTS":
|
|
803
|
+
case "REPLACE_COMMENT":
|
|
225
804
|
return {
|
|
226
805
|
...state,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
806
|
+
overlayState: "idle",
|
|
807
|
+
focussedComment: null,
|
|
808
|
+
comments: state.comments.map(
|
|
809
|
+
(comment) => comment.id === action.id ? action.comment : comment
|
|
810
|
+
)
|
|
231
811
|
};
|
|
232
812
|
default: {
|
|
233
813
|
console.warn(`Unhandled action type, returning state`, action);
|
|
@@ -247,30 +827,53 @@ var CommentContextProvider = ({
|
|
|
247
827
|
* @default "inactive"
|
|
248
828
|
*/
|
|
249
829
|
initialOverlayState,
|
|
250
|
-
|
|
251
|
-
onResolve,
|
|
252
|
-
currentUser,
|
|
830
|
+
currentUser: currentUserProp,
|
|
253
831
|
subscription,
|
|
254
832
|
config = {
|
|
255
833
|
commentVisibility: {
|
|
256
|
-
hideResolved: false
|
|
257
|
-
hideResolving: false
|
|
834
|
+
hideResolved: false
|
|
258
835
|
}
|
|
259
836
|
},
|
|
260
837
|
projectId,
|
|
261
|
-
|
|
838
|
+
locationId: locationIdProp,
|
|
839
|
+
onError,
|
|
840
|
+
onAdd,
|
|
841
|
+
onEdit,
|
|
842
|
+
onDelete,
|
|
843
|
+
onResolve,
|
|
844
|
+
onReopen
|
|
262
845
|
}) => {
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
846
|
+
const locationId = normalizeLocationId(locationIdProp);
|
|
847
|
+
const locationIdRef = (0, import_react4.useRef)(locationId);
|
|
848
|
+
locationIdRef.current = locationId;
|
|
849
|
+
const hostRef = (0, import_react4.useRef)({ onAdd, onEdit, onDelete, onResolve, onReopen });
|
|
850
|
+
hostRef.current = { onAdd, onEdit, onDelete, onResolve, onReopen };
|
|
851
|
+
const bridge = useSessionBridge();
|
|
852
|
+
const bridgeRef = (0, import_react4.useRef)(bridge);
|
|
853
|
+
bridgeRef.current = bridge;
|
|
854
|
+
const canResolveRef = (0, import_react4.useRef)(bridge.canResolve);
|
|
855
|
+
canResolveRef.current = bridge.canResolve;
|
|
856
|
+
const currentUser = currentUserProp ?? null;
|
|
857
|
+
const currentUserRef = (0, import_react4.useRef)(currentUser);
|
|
858
|
+
currentUserRef.current = currentUser;
|
|
859
|
+
const [state, dispatch] = (0, import_react4.useReducer)(
|
|
860
|
+
(current, action) => commentReducer(
|
|
861
|
+
{ ...current, currentUser: currentUserRef.current },
|
|
862
|
+
action
|
|
863
|
+
),
|
|
864
|
+
void 0,
|
|
865
|
+
() => ({
|
|
866
|
+
comments: initialComments ?? bridge.session?.comments ?? [],
|
|
867
|
+
overlayState: initialOverlayState || "inactive",
|
|
868
|
+
currentUser,
|
|
869
|
+
focussedComment: null,
|
|
870
|
+
config,
|
|
871
|
+
projectId
|
|
872
|
+
})
|
|
873
|
+
);
|
|
271
874
|
const { events, emit } = useCommentEvents();
|
|
272
|
-
const prevFocusRef = (0,
|
|
273
|
-
(0,
|
|
875
|
+
const prevFocusRef = (0, import_react4.useRef)(null);
|
|
876
|
+
(0, import_react4.useEffect)(() => {
|
|
274
877
|
if (state.focussedComment !== prevFocusRef.current) {
|
|
275
878
|
const comment = state.comments.find(
|
|
276
879
|
(c) => c.id === state.focussedComment
|
|
@@ -279,7 +882,7 @@ var CommentContextProvider = ({
|
|
|
279
882
|
prevFocusRef.current = state.focussedComment;
|
|
280
883
|
}
|
|
281
884
|
}, [state.focussedComment, state.comments, emit]);
|
|
282
|
-
(0,
|
|
885
|
+
(0, import_react4.useEffect)(() => {
|
|
283
886
|
if (!subscription) return;
|
|
284
887
|
subscription.subscribe((data) => {
|
|
285
888
|
dispatch({ type: "APPEND_COMMENT", comment: data });
|
|
@@ -289,14 +892,26 @@ var CommentContextProvider = ({
|
|
|
289
892
|
};
|
|
290
893
|
}, [subscription]);
|
|
291
894
|
const registerComment = (position, indicatorPosition) => {
|
|
895
|
+
const session = bridgeRef.current.session;
|
|
896
|
+
if (session?.status !== "draft") {
|
|
897
|
+
onError?.(new SessionStateError());
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const currentLocationId = locationIdRef.current;
|
|
901
|
+
if (currentLocationId === void 0) {
|
|
902
|
+
onError?.(new AddError("locationId is missing"));
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
292
905
|
dispatch({
|
|
293
906
|
type: "REGISTER",
|
|
907
|
+
sessionId: session.id,
|
|
908
|
+
locationId: currentLocationId,
|
|
294
909
|
position,
|
|
295
910
|
indicatorPosition: indicatorPosition || null
|
|
296
911
|
});
|
|
297
912
|
};
|
|
298
|
-
const prevCommentsLengthRef = (0,
|
|
299
|
-
(0,
|
|
913
|
+
const prevCommentsLengthRef = (0, import_react4.useRef)(state.comments.length);
|
|
914
|
+
(0, import_react4.useEffect)(() => {
|
|
300
915
|
if (state.comments.length > prevCommentsLengthRef.current) {
|
|
301
916
|
const lastComment = state.comments[state.comments.length - 1];
|
|
302
917
|
if (lastComment && lastComment.status === "draft") {
|
|
@@ -305,13 +920,154 @@ var CommentContextProvider = ({
|
|
|
305
920
|
}
|
|
306
921
|
prevCommentsLengthRef.current = state.comments.length;
|
|
307
922
|
}, [state.comments, emit]);
|
|
308
|
-
const
|
|
923
|
+
const providerId = (0, import_react4.useId)();
|
|
924
|
+
const localDraftCount = state.comments.filter(hasStatus("draft")).length;
|
|
925
|
+
(0, import_react4.useEffect)(() => {
|
|
926
|
+
bridgeRef.current.setLocalDraftCount(providerId, localDraftCount);
|
|
927
|
+
}, [providerId, localDraftCount]);
|
|
928
|
+
(0, import_react4.useEffect)(
|
|
929
|
+
() => () => bridgeRef.current.setLocalDraftCount(providerId, 0),
|
|
930
|
+
[providerId]
|
|
931
|
+
);
|
|
932
|
+
const fail = (error) => {
|
|
933
|
+
onError?.(error);
|
|
934
|
+
return { error };
|
|
935
|
+
};
|
|
936
|
+
const findComment = (id) => state.comments.find((comment) => comment.id === id);
|
|
937
|
+
const addComment = async (draft, content) => {
|
|
938
|
+
if (content.trim().length === 0) {
|
|
939
|
+
return fail(new AddError("content is empty"));
|
|
940
|
+
}
|
|
941
|
+
const persisted = {
|
|
942
|
+
...draft,
|
|
943
|
+
content,
|
|
944
|
+
status: "published"
|
|
945
|
+
};
|
|
946
|
+
const { onAdd: onAdd2 } = hostRef.current;
|
|
947
|
+
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "saving" });
|
|
948
|
+
if (onAdd2) {
|
|
949
|
+
const { error } = await tx.executeAsync(async () => onAdd2(persisted));
|
|
950
|
+
if (error) {
|
|
951
|
+
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "editing" });
|
|
952
|
+
return fail(toKnownError(error, AddError));
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
dispatch({ type: "REPLACE_COMMENT", id: draft.id, comment: persisted });
|
|
956
|
+
bridgeRef.current.commitComment(persisted);
|
|
957
|
+
emit("onCommentAdded", persisted);
|
|
958
|
+
return { error: null };
|
|
959
|
+
};
|
|
960
|
+
const editComment = async (comment, content) => {
|
|
961
|
+
if (content === comment.content) return { error: null };
|
|
962
|
+
const updated = {
|
|
963
|
+
...comment,
|
|
964
|
+
content,
|
|
965
|
+
status: "published"
|
|
966
|
+
};
|
|
967
|
+
const { onEdit: onEdit2 } = hostRef.current;
|
|
968
|
+
if (onEdit2) {
|
|
969
|
+
const { error } = await tx.executeAsync(async () => onEdit2(updated));
|
|
970
|
+
if (error) return fail(toKnownError(error, EditError));
|
|
971
|
+
}
|
|
972
|
+
dispatch({ type: "REPLACE_COMMENT", id: comment.id, comment: updated });
|
|
973
|
+
bridgeRef.current.commitComment(updated);
|
|
974
|
+
emit("onCommentEdited", updated);
|
|
975
|
+
return { error: null };
|
|
976
|
+
};
|
|
977
|
+
const updateComment = async (id, newComment) => {
|
|
978
|
+
const session = bridgeRef.current.session;
|
|
979
|
+
if (session?.status !== "draft") {
|
|
980
|
+
return fail(new SessionStateError());
|
|
981
|
+
}
|
|
982
|
+
const comment = findComment(id);
|
|
983
|
+
if (!comment) return fail(new EditError("comment not found"));
|
|
984
|
+
if (comment.status === "draft") {
|
|
985
|
+
if (comment.sessionId !== session.id) {
|
|
986
|
+
return fail(new SessionStateError());
|
|
987
|
+
}
|
|
988
|
+
return addComment(comment, newComment.content);
|
|
989
|
+
}
|
|
990
|
+
if (comment.status === "published") {
|
|
991
|
+
return editComment(comment, newComment.content);
|
|
992
|
+
}
|
|
993
|
+
return fail(new EditError("a resolved comment cannot be edited"));
|
|
994
|
+
};
|
|
995
|
+
const removePersisted = async (id) => {
|
|
996
|
+
const { onDelete: onDelete2 } = hostRef.current;
|
|
997
|
+
if (onDelete2) {
|
|
998
|
+
const { error } = await tx.executeAsync(async () => onDelete2(id));
|
|
999
|
+
if (error) return fail(toKnownError(error, DeleteError));
|
|
1000
|
+
}
|
|
1001
|
+
bridgeRef.current.removeComment(id);
|
|
309
1002
|
dispatch({ type: "DELETE", id });
|
|
310
1003
|
emit("onCommentDeleted", id);
|
|
1004
|
+
return { error: null };
|
|
1005
|
+
};
|
|
1006
|
+
const deleteComment = async (id) => {
|
|
1007
|
+
if (bridgeRef.current.session?.status !== "draft") {
|
|
1008
|
+
return fail(new SessionStateError());
|
|
1009
|
+
}
|
|
1010
|
+
const comment = findComment(id);
|
|
1011
|
+
if (!comment) return fail(new DeleteError("comment not found"));
|
|
1012
|
+
if (comment.status === "draft") {
|
|
1013
|
+
dispatch({ type: "DELETE", id });
|
|
1014
|
+
emit("onCommentDeleted", id);
|
|
1015
|
+
return { error: null };
|
|
1016
|
+
}
|
|
1017
|
+
return removePersisted(id);
|
|
1018
|
+
};
|
|
1019
|
+
const statusInFlightRef = (0, import_react4.useRef)(/* @__PURE__ */ new Set());
|
|
1020
|
+
const guardStatusChange = (id, from, failure) => {
|
|
1021
|
+
if (!canResolveRef.current) return fail(new PermissionError());
|
|
1022
|
+
if (bridgeRef.current.session?.status !== "resolving") {
|
|
1023
|
+
return fail(new SessionStateError());
|
|
1024
|
+
}
|
|
1025
|
+
const comment = findComment(id);
|
|
1026
|
+
if (!comment) return fail(new failure("comment not found"));
|
|
1027
|
+
if (comment.status !== from) return { error: null };
|
|
1028
|
+
if (statusInFlightRef.current.has(id)) return { error: null };
|
|
1029
|
+
return { comment };
|
|
311
1030
|
};
|
|
312
|
-
const
|
|
313
|
-
|
|
1031
|
+
const changeStatus = async (id, step) => {
|
|
1032
|
+
const guard = guardStatusChange(id, step.from, step.failure);
|
|
1033
|
+
if (!("comment" in guard)) return guard;
|
|
1034
|
+
statusInFlightRef.current.add(id);
|
|
1035
|
+
try {
|
|
1036
|
+
const next = step.build(guard.comment);
|
|
1037
|
+
if (step.call) {
|
|
1038
|
+
const { call } = step;
|
|
1039
|
+
const { error } = await tx.executeAsync(async () => call(next));
|
|
1040
|
+
if (error) return fail(toKnownError(error, step.failure));
|
|
1041
|
+
}
|
|
1042
|
+
dispatch({ type: "REPLACE_COMMENT", id, comment: next });
|
|
1043
|
+
bridgeRef.current.commitCommentStatus(next);
|
|
1044
|
+
emit(step.event, next);
|
|
1045
|
+
return { error: null };
|
|
1046
|
+
} finally {
|
|
1047
|
+
statusInFlightRef.current.delete(id);
|
|
1048
|
+
}
|
|
314
1049
|
};
|
|
1050
|
+
const resolveComment = (id) => changeStatus(id, {
|
|
1051
|
+
from: "published",
|
|
1052
|
+
build: (comment) => ({
|
|
1053
|
+
...comment,
|
|
1054
|
+
status: "resolved",
|
|
1055
|
+
resolvedAt: /* @__PURE__ */ new Date()
|
|
1056
|
+
}),
|
|
1057
|
+
call: hostRef.current.onResolve,
|
|
1058
|
+
failure: ResolveError,
|
|
1059
|
+
event: "onCommentResolved"
|
|
1060
|
+
});
|
|
1061
|
+
const reopenComment = (id) => changeStatus(id, {
|
|
1062
|
+
from: "resolved",
|
|
1063
|
+
build: (comment) => {
|
|
1064
|
+
const { resolvedAt: _resolvedAt, ...rest } = comment;
|
|
1065
|
+
return { ...rest, status: "published" };
|
|
1066
|
+
},
|
|
1067
|
+
call: hostRef.current.onReopen,
|
|
1068
|
+
failure: ReopenError,
|
|
1069
|
+
event: "onCommentReopened"
|
|
1070
|
+
});
|
|
315
1071
|
const getActiveComment = () => {
|
|
316
1072
|
return state.comments.find(
|
|
317
1073
|
(comment) => comment.id === state.focussedComment
|
|
@@ -323,81 +1079,21 @@ var CommentContextProvider = ({
|
|
|
323
1079
|
const toggleOverlay = () => {
|
|
324
1080
|
dispatch({ type: "TOGGLE_OVERLAY" });
|
|
325
1081
|
};
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
};
|
|
1082
|
+
const activeSession = bridge.session ? { id: bridge.session.id, status: bridge.session.status } : null;
|
|
1083
|
+
const visibleComments = selectVisibleComments({
|
|
1084
|
+
comments: state.comments,
|
|
1085
|
+
session: activeSession,
|
|
1086
|
+
locationId,
|
|
1087
|
+
draftVisibility: state.config?.draftVisibility,
|
|
1088
|
+
currentUserId: currentUser?.id
|
|
1089
|
+
});
|
|
1090
|
+
const commentsBySession = selectCommentsBySession({
|
|
1091
|
+
comments: state.comments,
|
|
1092
|
+
locationId,
|
|
1093
|
+
session: activeSession,
|
|
1094
|
+
draftVisibility: state.config?.draftVisibility,
|
|
1095
|
+
currentUserId: currentUser?.id
|
|
1096
|
+
});
|
|
401
1097
|
const updateCommentVisibility = (visibility) => {
|
|
402
1098
|
dispatch({ type: "UPDATE_VISIBILITY", visibility });
|
|
403
1099
|
};
|
|
@@ -409,18 +1105,17 @@ var CommentContextProvider = ({
|
|
|
409
1105
|
onError(error);
|
|
410
1106
|
}
|
|
411
1107
|
};
|
|
412
|
-
return /* @__PURE__ */ (0,
|
|
1108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
413
1109
|
CommentContext.Provider,
|
|
414
1110
|
{
|
|
415
1111
|
value: {
|
|
416
|
-
draftComments:
|
|
417
|
-
comments:
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
1112
|
+
draftComments: visibleComments.filter(hasStatus("draft")),
|
|
1113
|
+
comments: visibleComments.filter(hasStatus("published")),
|
|
1114
|
+
resolvedComments: visibleComments.filter(hasStatus("resolved")),
|
|
1115
|
+
allComments: visibleComments,
|
|
1116
|
+
commentsBySession,
|
|
421
1117
|
config: state.config,
|
|
422
1118
|
changeOverlayState,
|
|
423
|
-
toggleResolvingComment,
|
|
424
1119
|
overlayState: state.overlayState,
|
|
425
1120
|
deleteComment,
|
|
426
1121
|
updateComment,
|
|
@@ -428,9 +1123,10 @@ var CommentContextProvider = ({
|
|
|
428
1123
|
registerComment,
|
|
429
1124
|
getActiveComment,
|
|
430
1125
|
toggleOverlay,
|
|
431
|
-
confirmComments,
|
|
432
1126
|
currentUser,
|
|
433
|
-
|
|
1127
|
+
resolveComment,
|
|
1128
|
+
reopenComment,
|
|
1129
|
+
canResolve: bridge.canResolve,
|
|
434
1130
|
updateCommentVisibility,
|
|
435
1131
|
triggerError,
|
|
436
1132
|
events
|
|
@@ -440,7 +1136,8 @@ var CommentContextProvider = ({
|
|
|
440
1136
|
);
|
|
441
1137
|
};
|
|
442
1138
|
var useComments = () => {
|
|
443
|
-
|
|
1139
|
+
useSessionBridge();
|
|
1140
|
+
const context = (0, import_react4.useContext)(CommentContext);
|
|
444
1141
|
if (!context) {
|
|
445
1142
|
throw new Error("useComments must be used within a CommentContextProvider");
|
|
446
1143
|
}
|
|
@@ -461,7 +1158,7 @@ var normalizeRect = (a, b) => {
|
|
|
461
1158
|
};
|
|
462
1159
|
|
|
463
1160
|
// src/components/comment-overlay.tsx
|
|
464
|
-
var
|
|
1161
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
465
1162
|
var DRAG_THRESHOLD = 4;
|
|
466
1163
|
var CommentOverlay = ({ children, ...rest }) => {
|
|
467
1164
|
const {
|
|
@@ -472,10 +1169,10 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
472
1169
|
changeOverlayState,
|
|
473
1170
|
triggerError
|
|
474
1171
|
} = useComments();
|
|
475
|
-
const [preview, setPreview] = (0,
|
|
476
|
-
const startRef = (0,
|
|
477
|
-
const draggingRef = (0,
|
|
478
|
-
const overlayRef = (0,
|
|
1172
|
+
const [preview, setPreview] = (0, import_react5.useState)(null);
|
|
1173
|
+
const startRef = (0, import_react5.useRef)(null);
|
|
1174
|
+
const draggingRef = (0, import_react5.useRef)(false);
|
|
1175
|
+
const overlayRef = (0, import_react5.useRef)(null);
|
|
479
1176
|
const onPointerDown = (e) => {
|
|
480
1177
|
if (overlayState === "editing") {
|
|
481
1178
|
triggerError(
|
|
@@ -536,8 +1233,8 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
536
1233
|
setPreview(null);
|
|
537
1234
|
};
|
|
538
1235
|
if (overlayState === "inactive") return children;
|
|
539
|
-
return /* @__PURE__ */ (0,
|
|
540
|
-
/* @__PURE__ */ (0,
|
|
1236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-overlay": true, style: { position: "relative", ...rest.style }, ...rest, children: [
|
|
1237
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
541
1238
|
"div",
|
|
542
1239
|
{
|
|
543
1240
|
ref: overlayRef,
|
|
@@ -551,7 +1248,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
551
1248
|
}
|
|
552
1249
|
),
|
|
553
1250
|
getActiveComment() && // biome-ignore lint: This element should only handle clicks as a guard
|
|
554
|
-
/* @__PURE__ */ (0,
|
|
1251
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
555
1252
|
"div",
|
|
556
1253
|
{
|
|
557
1254
|
"data-comment-guard": true,
|
|
@@ -577,7 +1274,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
577
1274
|
}
|
|
578
1275
|
}
|
|
579
1276
|
),
|
|
580
|
-
preview && /* @__PURE__ */ (0,
|
|
1277
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
581
1278
|
"div",
|
|
582
1279
|
{
|
|
583
1280
|
style: {
|
|
@@ -609,47 +1306,35 @@ var EDITING_STYLES = {
|
|
|
609
1306
|
};
|
|
610
1307
|
|
|
611
1308
|
// src/components/comment-renderer.tsx
|
|
612
|
-
var
|
|
1309
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
613
1310
|
var CommentRenderer = ({
|
|
614
1311
|
Comment: Comment2,
|
|
615
1312
|
DraftComment,
|
|
616
|
-
ResolvingComment,
|
|
617
1313
|
ResolvedComment
|
|
618
1314
|
}) => {
|
|
619
|
-
const {
|
|
620
|
-
comments,
|
|
621
|
-
draftComments,
|
|
622
|
-
overlayState,
|
|
623
|
-
resolvedComments,
|
|
624
|
-
resolvingComments,
|
|
625
|
-
config
|
|
626
|
-
} = useComments();
|
|
1315
|
+
const { comments, draftComments, overlayState, resolvedComments, config } = useComments();
|
|
627
1316
|
if (overlayState === "inactive") return null;
|
|
628
|
-
return /* @__PURE__ */ (0,
|
|
1317
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
629
1318
|
draftComments.map((comment) => {
|
|
630
|
-
return /* @__PURE__ */ (0,
|
|
1319
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DraftComment, { comment }, comment.id);
|
|
631
1320
|
}),
|
|
632
1321
|
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);
|
|
1322
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Comment2, { comment }, comment.id);
|
|
638
1323
|
}),
|
|
639
1324
|
resolvedComments.map((comment) => {
|
|
640
1325
|
if (config?.commentVisibility?.hideResolved) return null;
|
|
641
|
-
return /* @__PURE__ */ (0,
|
|
1326
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ResolvedComment, { comment }, comment.id);
|
|
642
1327
|
})
|
|
643
1328
|
] });
|
|
644
1329
|
};
|
|
645
1330
|
|
|
646
1331
|
// src/components/comment-actions.tsx
|
|
647
1332
|
var import_react_slot = require("@radix-ui/react-slot");
|
|
648
|
-
var
|
|
1333
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
649
1334
|
var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
650
1335
|
const { toggleOverlay, overlayState } = useComments();
|
|
651
1336
|
const Comp = asChild ? import_react_slot.Slot : "button";
|
|
652
|
-
return /* @__PURE__ */ (0,
|
|
1337
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
653
1338
|
Comp,
|
|
654
1339
|
{
|
|
655
1340
|
"data-active": overlayState !== "inactive",
|
|
@@ -661,37 +1346,9 @@ var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
|
661
1346
|
}
|
|
662
1347
|
);
|
|
663
1348
|
};
|
|
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
1349
|
|
|
693
1350
|
// src/components/comment.tsx
|
|
694
|
-
var
|
|
1351
|
+
var import_react6 = require("react");
|
|
695
1352
|
var import_react_slot2 = require("@radix-ui/react-slot");
|
|
696
1353
|
|
|
697
1354
|
// src/contexts/scoped-comment.tsx
|
|
@@ -708,7 +1365,7 @@ function useCommentScope() {
|
|
|
708
1365
|
}
|
|
709
1366
|
|
|
710
1367
|
// src/components/comment.tsx
|
|
711
|
-
var
|
|
1368
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
712
1369
|
var CommentRoot = ({
|
|
713
1370
|
comment,
|
|
714
1371
|
defaultDraft,
|
|
@@ -718,17 +1375,17 @@ var CommentRoot = ({
|
|
|
718
1375
|
}) => {
|
|
719
1376
|
const { getActiveComment } = useComments();
|
|
720
1377
|
const isActive = getActiveComment()?.id === comment.id;
|
|
721
|
-
const [draft, setDraft] = (0,
|
|
1378
|
+
const [draft, setDraft] = (0, import_react6.useState)(defaultDraft ?? comment.content ?? "");
|
|
722
1379
|
const positionStyles = {
|
|
723
1380
|
position: "absolute",
|
|
724
1381
|
top: comment.position.y,
|
|
725
1382
|
left: comment.position.x
|
|
726
1383
|
};
|
|
727
|
-
return /* @__PURE__ */ (0,
|
|
1384
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
728
1385
|
CommentScopeContext.Provider,
|
|
729
1386
|
{
|
|
730
1387
|
value: { comment, isActive, draft, setDraft },
|
|
731
|
-
children: /* @__PURE__ */ (0,
|
|
1388
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
732
1389
|
"div",
|
|
733
1390
|
{
|
|
734
1391
|
...rest,
|
|
@@ -750,7 +1407,7 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
750
1407
|
const { config } = useComments();
|
|
751
1408
|
if (!comment.indicator) return null;
|
|
752
1409
|
if (config?.indicatorVisibility === "active" && !isActive) return null;
|
|
753
|
-
return /* @__PURE__ */ (0,
|
|
1410
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
754
1411
|
"div",
|
|
755
1412
|
{
|
|
756
1413
|
...rest,
|
|
@@ -772,12 +1429,12 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
772
1429
|
var CommentContent = ({ asChild, ...rest }) => {
|
|
773
1430
|
const { draft } = useCommentScope();
|
|
774
1431
|
const Comp = asChild ? import_react_slot2.Slot : "p";
|
|
775
|
-
return /* @__PURE__ */ (0,
|
|
1432
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Comp, { ...rest, children: draft });
|
|
776
1433
|
};
|
|
777
1434
|
var CommentEdit = ({ asChild, ...rest }) => {
|
|
778
1435
|
const { draft, setDraft } = useCommentScope();
|
|
779
1436
|
const Comp = asChild ? import_react_slot2.Slot : "textarea";
|
|
780
|
-
return /* @__PURE__ */ (0,
|
|
1437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
781
1438
|
Comp,
|
|
782
1439
|
{
|
|
783
1440
|
...rest,
|
|
@@ -795,7 +1452,7 @@ var CommentConfirm = ({ asChild, ...rest }) => {
|
|
|
795
1452
|
const { updateComment } = useComments();
|
|
796
1453
|
const { comment, draft } = useCommentScope();
|
|
797
1454
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
798
|
-
return /* @__PURE__ */ (0,
|
|
1455
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
799
1456
|
Comp,
|
|
800
1457
|
{
|
|
801
1458
|
...rest,
|
|
@@ -811,7 +1468,7 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
811
1468
|
const { deleteComment } = useComments();
|
|
812
1469
|
const { comment } = useCommentScope();
|
|
813
1470
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
814
|
-
return /* @__PURE__ */ (0,
|
|
1471
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
815
1472
|
Comp,
|
|
816
1473
|
{
|
|
817
1474
|
...rest,
|
|
@@ -823,27 +1480,54 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
823
1480
|
);
|
|
824
1481
|
};
|
|
825
1482
|
var CommentResolve = ({ asChild, ...rest }) => {
|
|
826
|
-
const {
|
|
1483
|
+
const { resolveComment } = useComments();
|
|
827
1484
|
const { comment } = useCommentScope();
|
|
828
1485
|
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
829
1486
|
if (comment.status === "draft") {
|
|
830
1487
|
console.error(
|
|
831
|
-
`A draft comment can not be
|
|
1488
|
+
`A draft comment can not be resolved, remove this button from this comment: ${comment.id}`
|
|
832
1489
|
);
|
|
833
1490
|
return null;
|
|
834
1491
|
}
|
|
835
1492
|
if (comment.status === "resolved") {
|
|
836
1493
|
console.error(
|
|
837
|
-
`A resolved comment can not be
|
|
1494
|
+
`A resolved comment can not be resolved again, remove this button from this comment: ${comment.id}`
|
|
838
1495
|
);
|
|
839
1496
|
return null;
|
|
840
1497
|
}
|
|
841
|
-
return /* @__PURE__ */ (0,
|
|
1498
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
842
1499
|
Comp,
|
|
843
1500
|
{
|
|
844
1501
|
...rest,
|
|
845
1502
|
onClick: (e) => {
|
|
846
|
-
|
|
1503
|
+
resolveComment(comment.id);
|
|
1504
|
+
rest.onClick?.(e);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
);
|
|
1508
|
+
};
|
|
1509
|
+
var CommentReopen = ({ asChild, ...rest }) => {
|
|
1510
|
+
const { reopenComment } = useComments();
|
|
1511
|
+
const { comment } = useCommentScope();
|
|
1512
|
+
const Comp = asChild ? import_react_slot2.Slot : "button";
|
|
1513
|
+
if (comment.status === "draft") {
|
|
1514
|
+
console.error(
|
|
1515
|
+
`A draft comment can not be reopened, remove this button from this comment: ${comment.id}`
|
|
1516
|
+
);
|
|
1517
|
+
return null;
|
|
1518
|
+
}
|
|
1519
|
+
if (comment.status === "published") {
|
|
1520
|
+
console.error(
|
|
1521
|
+
`A published comment can not be reopened, remove this button from this comment: ${comment.id}`
|
|
1522
|
+
);
|
|
1523
|
+
return null;
|
|
1524
|
+
}
|
|
1525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1526
|
+
Comp,
|
|
1527
|
+
{
|
|
1528
|
+
...rest,
|
|
1529
|
+
onClick: (e) => {
|
|
1530
|
+
reopenComment(comment.id);
|
|
847
1531
|
rest.onClick?.(e);
|
|
848
1532
|
}
|
|
849
1533
|
}
|
|
@@ -899,13 +1583,81 @@ var Comment = {
|
|
|
899
1583
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
900
1584
|
Delete: CommentDelete,
|
|
901
1585
|
/**
|
|
902
|
-
*
|
|
1586
|
+
* Resolves a comment
|
|
1587
|
+
*
|
|
1588
|
+
* @description Calls `resolveComment` for this comment. Renders nothing (and logs an error) for draft and resolved comments
|
|
1589
|
+
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
1590
|
+
*/
|
|
1591
|
+
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
1592
|
+
Resolve: CommentResolve,
|
|
1593
|
+
/**
|
|
1594
|
+
* Reopens a resolved comment
|
|
903
1595
|
*
|
|
904
|
-
* @description
|
|
1596
|
+
* @description Calls `reopenComment` for this comment. Renders nothing (and logs an error) for draft and published comments
|
|
905
1597
|
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
906
1598
|
*/
|
|
907
1599
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
908
|
-
|
|
1600
|
+
Reopen: CommentReopen
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/components/session-actions.tsx
|
|
1604
|
+
var import_react_slot3 = require("@radix-ui/react-slot");
|
|
1605
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1606
|
+
var CreateSession = ({ asChild, user, ...rest }) => {
|
|
1607
|
+
const { createSession } = useFeedbackSession();
|
|
1608
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1609
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1610
|
+
Comp,
|
|
1611
|
+
{
|
|
1612
|
+
...rest,
|
|
1613
|
+
onClick: (e) => {
|
|
1614
|
+
void createSession({ user });
|
|
1615
|
+
rest.onClick?.(e);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
);
|
|
1619
|
+
};
|
|
1620
|
+
var ConfirmSession = ({ asChild, ...rest }) => {
|
|
1621
|
+
const { confirmSession } = useFeedbackSession();
|
|
1622
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1623
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1624
|
+
Comp,
|
|
1625
|
+
{
|
|
1626
|
+
...rest,
|
|
1627
|
+
onClick: (e) => {
|
|
1628
|
+
void confirmSession();
|
|
1629
|
+
rest.onClick?.(e);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
);
|
|
1633
|
+
};
|
|
1634
|
+
var StartResolving = ({ asChild, ...rest }) => {
|
|
1635
|
+
const { startResolving } = useFeedbackSession();
|
|
1636
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1637
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1638
|
+
Comp,
|
|
1639
|
+
{
|
|
1640
|
+
...rest,
|
|
1641
|
+
onClick: (e) => {
|
|
1642
|
+
void startResolving();
|
|
1643
|
+
rest.onClick?.(e);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
);
|
|
1647
|
+
};
|
|
1648
|
+
var ResolveSession = ({ asChild, ...rest }) => {
|
|
1649
|
+
const { resolveSession } = useFeedbackSession();
|
|
1650
|
+
const Comp = asChild ? import_react_slot3.Slot : "button";
|
|
1651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1652
|
+
Comp,
|
|
1653
|
+
{
|
|
1654
|
+
...rest,
|
|
1655
|
+
onClick: (e) => {
|
|
1656
|
+
void resolveSession();
|
|
1657
|
+
rest.onClick?.(e);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
);
|
|
909
1661
|
};
|
|
910
1662
|
// Annotate the CommonJS export names for ESM import in node:
|
|
911
1663
|
0 && (module.exports = {
|
|
@@ -914,9 +1666,14 @@ var Comment = {
|
|
|
914
1666
|
CommentOverlay,
|
|
915
1667
|
CommentRenderer,
|
|
916
1668
|
CommentScopeContext,
|
|
917
|
-
|
|
918
|
-
|
|
1669
|
+
ConfirmSession,
|
|
1670
|
+
CreateSession,
|
|
1671
|
+
FeedbackSessionProvider,
|
|
1672
|
+
ResolveSession,
|
|
1673
|
+
StartResolving,
|
|
919
1674
|
ToggleOverlayButton,
|
|
1675
|
+
commentReducer,
|
|
920
1676
|
useCommentScope,
|
|
921
|
-
useComments
|
|
1677
|
+
useComments,
|
|
1678
|
+
useFeedbackSession
|
|
922
1679
|
});
|