@kendew-agency/react-feedback-layer 0.3.2 → 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 +698 -453
- package/dist/index.cjs +934 -220
- package/dist/index.d.cts +70 -13
- package/dist/index.d.ts +70 -13
- package/dist/index.js +933 -216
- 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.js
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
// src/components/comment-overlay.tsx
|
|
2
2
|
import {
|
|
3
|
-
useRef as
|
|
3
|
+
useRef as useRef5,
|
|
4
4
|
useState
|
|
5
5
|
} from "react";
|
|
6
6
|
|
|
7
7
|
// src/contexts/comment-context.tsx
|
|
8
8
|
import {
|
|
9
|
-
createContext,
|
|
10
|
-
useContext,
|
|
11
|
-
useEffect,
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
createContext as createContext3,
|
|
10
|
+
useContext as useContext3,
|
|
11
|
+
useEffect as useEffect2,
|
|
12
|
+
useId,
|
|
13
|
+
useReducer as useReducer2,
|
|
14
|
+
useRef as useRef4
|
|
14
15
|
} from "react";
|
|
15
16
|
|
|
16
|
-
// src/lib/tx.ts
|
|
17
|
-
import { TryX } from "@j31/tryx-handler";
|
|
18
|
-
var tx = new TryX({
|
|
19
|
-
timeout: 1e4
|
|
20
|
-
// 10 seconds
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// src/utils/hasStatus.ts
|
|
24
|
-
function hasStatus(status) {
|
|
25
|
-
return (comment) => comment.status === status;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
17
|
// src/errors.ts
|
|
29
18
|
var BaseError = class extends Error {
|
|
30
19
|
constructor(message, code = "UNKNOWN_ERROR", status = 500) {
|
|
@@ -40,23 +29,88 @@ var InsertError = class extends BaseError {
|
|
|
40
29
|
}
|
|
41
30
|
};
|
|
42
31
|
var ResolveError = class extends BaseError {
|
|
43
|
-
constructor(message = "An error occured while resolving your
|
|
32
|
+
constructor(message = "An error occured while resolving your comment") {
|
|
44
33
|
super(message, "RESOLVE_ERROR", 500);
|
|
45
34
|
}
|
|
46
35
|
};
|
|
47
36
|
var ConfirmError = class extends BaseError {
|
|
48
|
-
constructor(message = "An error occured while confirming your
|
|
37
|
+
constructor(message = "An error occured while confirming your session") {
|
|
49
38
|
super(message, "CONFIRM_ERROR", 500);
|
|
50
39
|
}
|
|
51
40
|
};
|
|
41
|
+
var SessionCreateError = class extends BaseError {
|
|
42
|
+
constructor(message = "An error occured while creating your session") {
|
|
43
|
+
super(message, "SESSION_CREATE_ERROR", 500);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var AddError = class extends BaseError {
|
|
47
|
+
constructor(message = "An error occured while adding your comment") {
|
|
48
|
+
super(message, "ADD_ERROR", 500);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var EditError = class extends BaseError {
|
|
52
|
+
constructor(message = "An error occured while editing your comment") {
|
|
53
|
+
super(message, "EDIT_ERROR", 500);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var DeleteError = class extends BaseError {
|
|
57
|
+
constructor(message = "An error occured while deleting your comment") {
|
|
58
|
+
super(message, "DELETE_ERROR", 500);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var SessionStateError = class extends BaseError {
|
|
62
|
+
constructor(message = "This action is not allowed in the current session state") {
|
|
63
|
+
super(message, "SESSION_STATE_ERROR", 500);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var ReopenError = class extends BaseError {
|
|
67
|
+
constructor(message = "An error occured while reopening your comment") {
|
|
68
|
+
super(message, "REOPEN_ERROR", 500);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var StartResolvingError = class extends BaseError {
|
|
72
|
+
constructor(message = "An error occured while starting the resolution of your session") {
|
|
73
|
+
super(message, "START_RESOLVING_ERROR", 500);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var SessionResolveError = class extends BaseError {
|
|
77
|
+
constructor(message = "An error occured while resolving your session") {
|
|
78
|
+
super(message, "SESSION_RESOLVE_ERROR", 500);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var PermissionError = class extends BaseError {
|
|
82
|
+
constructor(message = "You do not have permission to perform this action") {
|
|
83
|
+
super(message, "PERMISSION_ERROR", 500);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/lib/to-known-error.ts
|
|
88
|
+
var toKnownError = (reason, ErrorClass) => {
|
|
89
|
+
const message = reason instanceof Error && reason.message.length > 0 ? reason.message : void 0;
|
|
90
|
+
return new ErrorClass(message);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/lib/tx.ts
|
|
94
|
+
import { TryX } from "@j31/tryx-handler";
|
|
95
|
+
var tx = new TryX({
|
|
96
|
+
timeout: 1e4
|
|
97
|
+
// 10 seconds
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// src/utils/hasStatus.ts
|
|
101
|
+
function hasStatus(status) {
|
|
102
|
+
return (comment) => comment.status === status;
|
|
103
|
+
}
|
|
52
104
|
|
|
53
105
|
// src/lib/use-comment-events.ts
|
|
54
106
|
import { useCallback, useRef } from "react";
|
|
55
107
|
var useCommentEvents = () => {
|
|
56
108
|
const listenersRef = useRef({
|
|
57
109
|
onFocusChange: /* @__PURE__ */ new Set(),
|
|
58
|
-
|
|
59
|
-
|
|
110
|
+
onCommentAdded: /* @__PURE__ */ new Set(),
|
|
111
|
+
onCommentEdited: /* @__PURE__ */ new Set(),
|
|
112
|
+
onCommentResolved: /* @__PURE__ */ new Set(),
|
|
113
|
+
onCommentReopened: /* @__PURE__ */ new Set(),
|
|
60
114
|
onCommentDeleted: /* @__PURE__ */ new Set(),
|
|
61
115
|
onCommentRegistered: /* @__PURE__ */ new Set()
|
|
62
116
|
});
|
|
@@ -79,17 +133,522 @@ var useCommentEvents = () => {
|
|
|
79
133
|
);
|
|
80
134
|
const events = {
|
|
81
135
|
onFocusChange: (callback) => subscribe("onFocusChange", callback),
|
|
82
|
-
|
|
83
|
-
|
|
136
|
+
onCommentAdded: (callback) => subscribe("onCommentAdded", callback),
|
|
137
|
+
onCommentEdited: (callback) => subscribe("onCommentEdited", callback),
|
|
138
|
+
onCommentResolved: (callback) => subscribe("onCommentResolved", callback),
|
|
139
|
+
onCommentReopened: (callback) => subscribe("onCommentReopened", callback),
|
|
84
140
|
onCommentDeleted: (callback) => subscribe("onCommentDeleted", callback),
|
|
85
141
|
onCommentRegistered: (callback) => subscribe("onCommentRegistered", callback)
|
|
86
142
|
};
|
|
87
143
|
return { events, emit };
|
|
88
144
|
};
|
|
89
145
|
|
|
90
|
-
// src/
|
|
146
|
+
// src/utils/select-visible-comments.ts
|
|
147
|
+
var normalizeDraftVisibility = (value) => value === "hidden" ? "hidden" : "visible";
|
|
148
|
+
var selectVisibleComments = ({
|
|
149
|
+
comments,
|
|
150
|
+
session,
|
|
151
|
+
draftVisibility = "visible",
|
|
152
|
+
currentUserId
|
|
153
|
+
}) => {
|
|
154
|
+
if (session === null) {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
const inSession = comments.filter(
|
|
158
|
+
(comment) => comment.sessionId === session.id
|
|
159
|
+
);
|
|
160
|
+
if (session.status !== "draft" || normalizeDraftVisibility(draftVisibility) !== "hidden") {
|
|
161
|
+
return inSession;
|
|
162
|
+
}
|
|
163
|
+
return inSession.filter((comment) => {
|
|
164
|
+
if (comment.status === "draft") {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
const authorId = comment.user?.id;
|
|
168
|
+
return authorId === void 0 || authorId === currentUserId;
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/contexts/feedback-session-context.tsx
|
|
173
|
+
import {
|
|
174
|
+
createContext as createContext2,
|
|
175
|
+
useCallback as useCallback3,
|
|
176
|
+
useContext as useContext2,
|
|
177
|
+
useEffect,
|
|
178
|
+
useMemo as useMemo2,
|
|
179
|
+
useReducer,
|
|
180
|
+
useRef as useRef3
|
|
181
|
+
} from "react";
|
|
182
|
+
|
|
183
|
+
// src/lib/use-session-events.ts
|
|
184
|
+
import { useCallback as useCallback2, useRef as useRef2 } from "react";
|
|
185
|
+
var useSessionEvents = () => {
|
|
186
|
+
const listenersRef = useRef2({
|
|
187
|
+
onSessionCreated: /* @__PURE__ */ new Set(),
|
|
188
|
+
onSessionConfirmed: /* @__PURE__ */ new Set(),
|
|
189
|
+
onSessionResolving: /* @__PURE__ */ new Set(),
|
|
190
|
+
onSessionResolved: /* @__PURE__ */ new Set()
|
|
191
|
+
});
|
|
192
|
+
const subscribe = useCallback2(
|
|
193
|
+
(event, callback) => {
|
|
194
|
+
listenersRef.current[event].add(callback);
|
|
195
|
+
return () => {
|
|
196
|
+
listenersRef.current[event].delete(callback);
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
[]
|
|
200
|
+
);
|
|
201
|
+
const emit = useCallback2(
|
|
202
|
+
(event, ...args) => {
|
|
203
|
+
for (const listener of listenersRef.current[event]) {
|
|
204
|
+
listener(...args);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
[]
|
|
208
|
+
);
|
|
209
|
+
const events = {
|
|
210
|
+
onSessionCreated: (callback) => subscribe("onSessionCreated", callback),
|
|
211
|
+
onSessionConfirmed: (callback) => subscribe("onSessionConfirmed", callback),
|
|
212
|
+
onSessionResolving: (callback) => subscribe("onSessionResolving", callback),
|
|
213
|
+
onSessionResolved: (callback) => subscribe("onSessionResolved", callback)
|
|
214
|
+
};
|
|
215
|
+
return { events, emit };
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// src/utils/session-reducer.ts
|
|
219
|
+
var initialSessionReducerState = {
|
|
220
|
+
session: null,
|
|
221
|
+
sessionState: "idle"
|
|
222
|
+
};
|
|
223
|
+
var withSession = (state, session) => ({ ...state, session });
|
|
224
|
+
var onSessionCreated = (state, action) => {
|
|
225
|
+
const { confirmedAt: _c, resolvedAt: _r, ...rest } = action.session;
|
|
226
|
+
return withSession(state, {
|
|
227
|
+
...rest,
|
|
228
|
+
participantIds: [...action.session.participantIds],
|
|
229
|
+
status: "draft",
|
|
230
|
+
comments: []
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
var onSessionConfirmed = (state, action) => {
|
|
234
|
+
const { session } = state;
|
|
235
|
+
if (!session || session.status !== "draft") return state;
|
|
236
|
+
return withSession(state, {
|
|
237
|
+
...session,
|
|
238
|
+
status: "confirmed",
|
|
239
|
+
confirmedAt: action.confirmedAt
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
var onResolvingStarted = (state) => {
|
|
243
|
+
const { session } = state;
|
|
244
|
+
if (!session || session.status !== "confirmed") return state;
|
|
245
|
+
return withSession(state, { ...session, status: "resolving" });
|
|
246
|
+
};
|
|
247
|
+
var onSessionResolved = (state, action) => {
|
|
248
|
+
const { session } = state;
|
|
249
|
+
if (!session || session.status !== "resolving") return state;
|
|
250
|
+
return withSession(state, {
|
|
251
|
+
...session,
|
|
252
|
+
status: "resolved",
|
|
253
|
+
resolvedAt: action.resolvedAt
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
var onCommentCommitted = (state, action) => {
|
|
257
|
+
const { session } = state;
|
|
258
|
+
if (!session || session.status !== "draft") return state;
|
|
259
|
+
const { comment } = action;
|
|
260
|
+
const exists = session.comments.some((c) => c.id === comment.id);
|
|
261
|
+
const comments = exists ? session.comments.map((c) => c.id === comment.id ? comment : c) : [...session.comments, comment];
|
|
262
|
+
const userId = comment.user?.id;
|
|
263
|
+
const participantIds = userId !== void 0 && !session.participantIds.includes(userId) ? [...session.participantIds, userId] : session.participantIds;
|
|
264
|
+
return withSession(state, { ...session, comments, participantIds });
|
|
265
|
+
};
|
|
266
|
+
var onCommentStatusChanged = (state, action) => {
|
|
267
|
+
const { session } = state;
|
|
268
|
+
if (!session || session.status !== "resolving") return state;
|
|
269
|
+
const { comment } = action;
|
|
270
|
+
return withSession(state, {
|
|
271
|
+
...session,
|
|
272
|
+
comments: session.comments.map((c) => c.id === comment.id ? comment : c)
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
var onCommentRemoved = (state, action) => {
|
|
276
|
+
const { session } = state;
|
|
277
|
+
if (!session || session.status !== "draft") return state;
|
|
278
|
+
return withSession(state, {
|
|
279
|
+
...session,
|
|
280
|
+
comments: session.comments.filter((c) => c.id !== action.commentId)
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
var onSetOperationState = (state, action) => {
|
|
284
|
+
if (state.sessionState === action.to) return state;
|
|
285
|
+
return { ...state, sessionState: action.to };
|
|
286
|
+
};
|
|
287
|
+
var sessionReducer = (state, action) => {
|
|
288
|
+
switch (action.type) {
|
|
289
|
+
case "SESSION_CREATED":
|
|
290
|
+
return onSessionCreated(state, action);
|
|
291
|
+
case "SESSION_CONFIRMED":
|
|
292
|
+
return onSessionConfirmed(state, action);
|
|
293
|
+
case "SESSION_RESOLVING_STARTED":
|
|
294
|
+
return onResolvingStarted(state, action);
|
|
295
|
+
case "SESSION_RESOLVED":
|
|
296
|
+
return onSessionResolved(state, action);
|
|
297
|
+
case "COMMENT_COMMITTED":
|
|
298
|
+
return onCommentCommitted(state, action);
|
|
299
|
+
case "COMMENT_STATUS_CHANGED":
|
|
300
|
+
return onCommentStatusChanged(state, action);
|
|
301
|
+
case "COMMENT_REMOVED":
|
|
302
|
+
return onCommentRemoved(state, action);
|
|
303
|
+
case "SET_OPERATION_STATE":
|
|
304
|
+
return onSetOperationState(state, action);
|
|
305
|
+
default:
|
|
306
|
+
return state;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// src/utils/session-type.ts
|
|
311
|
+
var SESSION_TYPES = ["feedback"];
|
|
312
|
+
var isSessionType = (value) => SESSION_TYPES.includes(value);
|
|
313
|
+
var SESSION_STATUSES = [
|
|
314
|
+
"draft",
|
|
315
|
+
"confirmed",
|
|
316
|
+
"resolving",
|
|
317
|
+
"resolved"
|
|
318
|
+
];
|
|
319
|
+
var parseInitialSession = (value) => {
|
|
320
|
+
if (value === null || typeof value !== "object") return null;
|
|
321
|
+
const status = value.status;
|
|
322
|
+
if (!SESSION_STATUSES.includes(status)) return null;
|
|
323
|
+
const session = value;
|
|
324
|
+
return {
|
|
325
|
+
...value,
|
|
326
|
+
comments: session.comments ?? []
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// src/contexts/user-context.tsx
|
|
331
|
+
import * as React from "react";
|
|
91
332
|
import { jsx } from "react/jsx-runtime";
|
|
92
|
-
var
|
|
333
|
+
var UserContext = React.createContext(
|
|
334
|
+
void 0
|
|
335
|
+
);
|
|
336
|
+
var UserProvider = ({ user, children }) => {
|
|
337
|
+
const value = React.useMemo(
|
|
338
|
+
() => ({ currentUser: user }),
|
|
339
|
+
[user]
|
|
340
|
+
);
|
|
341
|
+
return /* @__PURE__ */ jsx(UserContext.Provider, { value, children });
|
|
342
|
+
};
|
|
343
|
+
var useCurrentUser = () => {
|
|
344
|
+
const ctx = React.useContext(UserContext);
|
|
345
|
+
if (!ctx) {
|
|
346
|
+
throw new Error("useCurrentUser must be used within <UserProvider />");
|
|
347
|
+
}
|
|
348
|
+
return ctx.currentUser;
|
|
349
|
+
};
|
|
350
|
+
var useOptionalCurrentUser = () => {
|
|
351
|
+
const ctx = React.useContext(UserContext);
|
|
352
|
+
return ctx ? ctx.currentUser : void 0;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/contexts/feedback-session-context.tsx
|
|
356
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
357
|
+
var FeedbackSessionContext = createContext2(
|
|
358
|
+
null
|
|
359
|
+
);
|
|
360
|
+
var SessionBridgeContext = createContext2(null);
|
|
361
|
+
var MAX_PROJECT_ID_LENGTH = 128;
|
|
362
|
+
var isValidProjectId = (projectId) => projectId === void 0 || typeof projectId === "string" && projectId.length >= 1 && projectId.length <= MAX_PROJECT_ID_LENGTH;
|
|
363
|
+
var pick = (value, fallback) => value !== void 0 ? value : fallback;
|
|
364
|
+
var createRefusal = (type, projectId, inFlight, session, hasCallback) => {
|
|
365
|
+
if (!isSessionType(type)) return "unknown session type";
|
|
366
|
+
if (!isValidProjectId(projectId)) {
|
|
367
|
+
return "projectId must be 1 to 128 characters";
|
|
368
|
+
}
|
|
369
|
+
if (inFlight === "creating") return "creation already in progress";
|
|
370
|
+
if (session?.status === "draft") return "draft session already exists";
|
|
371
|
+
if (!hasCallback) return "onCreateSession is not provided";
|
|
372
|
+
return null;
|
|
373
|
+
};
|
|
374
|
+
var confirmRefusal = (session, localDrafts) => {
|
|
375
|
+
if (!session || session.status !== "draft") return "session is not a draft";
|
|
376
|
+
if (localDrafts > 0) return "a local draft comment exists";
|
|
377
|
+
if (session.comments.length === 0) return "session has no comments";
|
|
378
|
+
if (!isSessionType(session.type)) return "unknown session type";
|
|
379
|
+
return null;
|
|
380
|
+
};
|
|
381
|
+
var sumCounts = (counts) => {
|
|
382
|
+
let total = 0;
|
|
383
|
+
for (const count of counts.values()) total += count;
|
|
384
|
+
return total;
|
|
385
|
+
};
|
|
386
|
+
var FeedbackSessionProvider = ({
|
|
387
|
+
children,
|
|
388
|
+
initialSession,
|
|
389
|
+
projectId,
|
|
390
|
+
canResolveSession = false,
|
|
391
|
+
onCreateSession,
|
|
392
|
+
onConfirmSession,
|
|
393
|
+
onStartResolving,
|
|
394
|
+
onResolveSession,
|
|
395
|
+
onError
|
|
396
|
+
}) => {
|
|
397
|
+
const contextUser = useOptionalCurrentUser();
|
|
398
|
+
const initialParsedRef = useRef3(
|
|
399
|
+
void 0
|
|
400
|
+
);
|
|
401
|
+
if (initialParsedRef.current === void 0) {
|
|
402
|
+
initialParsedRef.current = initialSession === void 0 ? null : parseInitialSession(initialSession);
|
|
403
|
+
}
|
|
404
|
+
const [state, dispatch] = useReducer(
|
|
405
|
+
sessionReducer,
|
|
406
|
+
initialParsedRef.current,
|
|
407
|
+
(session) => ({
|
|
408
|
+
...initialSessionReducerState,
|
|
409
|
+
session
|
|
410
|
+
})
|
|
411
|
+
);
|
|
412
|
+
const stateRef = useRef3({
|
|
413
|
+
...initialSessionReducerState,
|
|
414
|
+
session: initialParsedRef.current
|
|
415
|
+
});
|
|
416
|
+
const apply = useCallback3((action) => {
|
|
417
|
+
stateRef.current = sessionReducer(stateRef.current, action);
|
|
418
|
+
dispatch(action);
|
|
419
|
+
}, []);
|
|
420
|
+
const canResolveRef = useRef3(canResolveSession);
|
|
421
|
+
canResolveRef.current = canResolveSession;
|
|
422
|
+
const onErrorRef = useRef3(onError);
|
|
423
|
+
onErrorRef.current = onError;
|
|
424
|
+
const inFlightRef = useRef3("idle");
|
|
425
|
+
const localDraftCountsRef = useRef3(/* @__PURE__ */ new Map());
|
|
426
|
+
const { events, emit } = useSessionEvents();
|
|
427
|
+
const report = useCallback3((error) => {
|
|
428
|
+
onErrorRef.current?.(error);
|
|
429
|
+
}, []);
|
|
430
|
+
useEffect(() => {
|
|
431
|
+
if (initialSession !== void 0 && initialParsedRef.current === null) {
|
|
432
|
+
report(new SessionStateError("initialSession has an invalid status"));
|
|
433
|
+
}
|
|
434
|
+
}, []);
|
|
435
|
+
const createSession = useCallback3(
|
|
436
|
+
async (options) => {
|
|
437
|
+
const type = options?.type ?? "feedback";
|
|
438
|
+
const user = pick(options?.user, contextUser);
|
|
439
|
+
const sessionProjectId = pick(options?.projectId, projectId);
|
|
440
|
+
const refusal = createRefusal(
|
|
441
|
+
type,
|
|
442
|
+
sessionProjectId,
|
|
443
|
+
inFlightRef.current,
|
|
444
|
+
stateRef.current.session,
|
|
445
|
+
onCreateSession !== void 0
|
|
446
|
+
);
|
|
447
|
+
if (refusal !== null || !onCreateSession) {
|
|
448
|
+
const error = new SessionCreateError(refusal ?? void 0);
|
|
449
|
+
report(error);
|
|
450
|
+
return { error };
|
|
451
|
+
}
|
|
452
|
+
inFlightRef.current = "creating";
|
|
453
|
+
apply({ type: "SET_OPERATION_STATE", to: "creating" });
|
|
454
|
+
try {
|
|
455
|
+
const input = {
|
|
456
|
+
type,
|
|
457
|
+
user: user ?? null,
|
|
458
|
+
projectId: sessionProjectId
|
|
459
|
+
};
|
|
460
|
+
const { data, error } = await tx.executeAsync(
|
|
461
|
+
async () => onCreateSession(input)
|
|
462
|
+
);
|
|
463
|
+
if (error || !data) {
|
|
464
|
+
const known = toKnownError(error, SessionCreateError);
|
|
465
|
+
report(known);
|
|
466
|
+
return { error: known };
|
|
467
|
+
}
|
|
468
|
+
apply({
|
|
469
|
+
type: "SESSION_CREATED",
|
|
470
|
+
session: { ...data, status: "draft", type }
|
|
471
|
+
});
|
|
472
|
+
const created = stateRef.current.session;
|
|
473
|
+
if (created) emit("onSessionCreated", created);
|
|
474
|
+
return { error: null };
|
|
475
|
+
} finally {
|
|
476
|
+
inFlightRef.current = "idle";
|
|
477
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
[apply, contextUser, emit, onCreateSession, projectId, report]
|
|
481
|
+
);
|
|
482
|
+
const confirmSession = useCallback3(async () => {
|
|
483
|
+
if (inFlightRef.current === "confirming") return { error: null };
|
|
484
|
+
const session = stateRef.current.session;
|
|
485
|
+
const refusal = confirmRefusal(
|
|
486
|
+
session,
|
|
487
|
+
sumCounts(localDraftCountsRef.current)
|
|
488
|
+
);
|
|
489
|
+
if (refusal !== null || !session) {
|
|
490
|
+
const error = new SessionStateError(refusal ?? void 0);
|
|
491
|
+
report(error);
|
|
492
|
+
return { error };
|
|
493
|
+
}
|
|
494
|
+
inFlightRef.current = "confirming";
|
|
495
|
+
apply({ type: "SET_OPERATION_STATE", to: "confirming" });
|
|
496
|
+
try {
|
|
497
|
+
if (onConfirmSession) {
|
|
498
|
+
const { error } = await tx.executeAsync(
|
|
499
|
+
async () => onConfirmSession(session.id, session.type)
|
|
500
|
+
);
|
|
501
|
+
if (error) {
|
|
502
|
+
const known = toKnownError(error, ConfirmError);
|
|
503
|
+
report(known);
|
|
504
|
+
return { error: known };
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
apply({ type: "SESSION_CONFIRMED", confirmedAt: /* @__PURE__ */ new Date() });
|
|
508
|
+
const confirmed = stateRef.current.session;
|
|
509
|
+
if (confirmed) emit("onSessionConfirmed", confirmed);
|
|
510
|
+
return { error: null };
|
|
511
|
+
} finally {
|
|
512
|
+
inFlightRef.current = "idle";
|
|
513
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
514
|
+
}
|
|
515
|
+
}, [apply, emit, onConfirmSession, report]);
|
|
516
|
+
const refuse = useCallback3(
|
|
517
|
+
(error) => {
|
|
518
|
+
report(error);
|
|
519
|
+
return { error };
|
|
520
|
+
},
|
|
521
|
+
[report]
|
|
522
|
+
);
|
|
523
|
+
const runTransition = useCallback3(
|
|
524
|
+
async (step) => {
|
|
525
|
+
if (!canResolveRef.current) return refuse(new PermissionError());
|
|
526
|
+
if (inFlightRef.current === step.pending) return { error: null };
|
|
527
|
+
const session = stateRef.current.session;
|
|
528
|
+
const refusal = step.guard(session);
|
|
529
|
+
if (refusal !== null || !session) {
|
|
530
|
+
return refuse(new SessionStateError(refusal ?? void 0));
|
|
531
|
+
}
|
|
532
|
+
inFlightRef.current = step.pending;
|
|
533
|
+
apply({ type: "SET_OPERATION_STATE", to: step.pending });
|
|
534
|
+
try {
|
|
535
|
+
const call = step.call;
|
|
536
|
+
if (call) {
|
|
537
|
+
const { error } = await tx.executeAsync(async () => call(session.id));
|
|
538
|
+
if (error) return refuse(toKnownError(error, step.failure));
|
|
539
|
+
}
|
|
540
|
+
step.commit();
|
|
541
|
+
return { error: null };
|
|
542
|
+
} finally {
|
|
543
|
+
inFlightRef.current = "idle";
|
|
544
|
+
apply({ type: "SET_OPERATION_STATE", to: "idle" });
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
[apply, refuse]
|
|
548
|
+
);
|
|
549
|
+
const startResolving = useCallback3(
|
|
550
|
+
() => runTransition({
|
|
551
|
+
pending: "startingResolution",
|
|
552
|
+
guard: (session) => session?.status === "confirmed" ? null : "session is not confirmed",
|
|
553
|
+
call: onStartResolving,
|
|
554
|
+
failure: StartResolvingError,
|
|
555
|
+
commit: () => {
|
|
556
|
+
apply({ type: "SESSION_RESOLVING_STARTED" });
|
|
557
|
+
const resolving = stateRef.current.session;
|
|
558
|
+
if (resolving) emit("onSessionResolving", resolving);
|
|
559
|
+
}
|
|
560
|
+
}),
|
|
561
|
+
[apply, emit, onStartResolving, runTransition]
|
|
562
|
+
);
|
|
563
|
+
const resolveSession = useCallback3(
|
|
564
|
+
() => runTransition({
|
|
565
|
+
pending: "completingResolution",
|
|
566
|
+
guard: (session) => {
|
|
567
|
+
if (session?.status !== "resolving")
|
|
568
|
+
return "session is not resolving";
|
|
569
|
+
return session.comments.some((c) => c.status === "published") ? "a comment is still published" : null;
|
|
570
|
+
},
|
|
571
|
+
call: onResolveSession,
|
|
572
|
+
failure: SessionResolveError,
|
|
573
|
+
commit: () => {
|
|
574
|
+
apply({ type: "SESSION_RESOLVED", resolvedAt: /* @__PURE__ */ new Date() });
|
|
575
|
+
const resolved = stateRef.current.session;
|
|
576
|
+
if (resolved) emit("onSessionResolved", resolved);
|
|
577
|
+
}
|
|
578
|
+
}),
|
|
579
|
+
[apply, emit, onResolveSession, runTransition]
|
|
580
|
+
);
|
|
581
|
+
const commitComment = useCallback3(
|
|
582
|
+
(comment) => apply({ type: "COMMENT_COMMITTED", comment }),
|
|
583
|
+
[apply]
|
|
584
|
+
);
|
|
585
|
+
const commitCommentStatus = useCallback3(
|
|
586
|
+
(comment) => apply({ type: "COMMENT_STATUS_CHANGED", comment }),
|
|
587
|
+
[apply]
|
|
588
|
+
);
|
|
589
|
+
const removeComment = useCallback3(
|
|
590
|
+
(commentId) => apply({ type: "COMMENT_REMOVED", commentId }),
|
|
591
|
+
[apply]
|
|
592
|
+
);
|
|
593
|
+
const setLocalDraftCount = useCallback3(
|
|
594
|
+
(providerId, count) => {
|
|
595
|
+
if (count > 0) localDraftCountsRef.current.set(providerId, count);
|
|
596
|
+
else localDraftCountsRef.current.delete(providerId);
|
|
597
|
+
},
|
|
598
|
+
[]
|
|
599
|
+
);
|
|
600
|
+
const bridge = useMemo2(
|
|
601
|
+
() => ({
|
|
602
|
+
session: state.session,
|
|
603
|
+
canResolve: canResolveSession,
|
|
604
|
+
commitComment,
|
|
605
|
+
commitCommentStatus,
|
|
606
|
+
removeComment,
|
|
607
|
+
setLocalDraftCount
|
|
608
|
+
}),
|
|
609
|
+
[
|
|
610
|
+
state.session,
|
|
611
|
+
canResolveSession,
|
|
612
|
+
commitComment,
|
|
613
|
+
commitCommentStatus,
|
|
614
|
+
removeComment,
|
|
615
|
+
setLocalDraftCount
|
|
616
|
+
]
|
|
617
|
+
);
|
|
618
|
+
const value = {
|
|
619
|
+
session: state.session,
|
|
620
|
+
sessionState: state.sessionState,
|
|
621
|
+
canResolve: canResolveSession,
|
|
622
|
+
createSession,
|
|
623
|
+
confirmSession,
|
|
624
|
+
startResolving,
|
|
625
|
+
resolveSession,
|
|
626
|
+
events
|
|
627
|
+
};
|
|
628
|
+
return /* @__PURE__ */ jsx2(FeedbackSessionContext.Provider, { value, children: /* @__PURE__ */ jsx2(SessionBridgeContext.Provider, { value: bridge, children }) });
|
|
629
|
+
};
|
|
630
|
+
var useFeedbackSession = () => {
|
|
631
|
+
const context = useContext2(FeedbackSessionContext);
|
|
632
|
+
if (!context) {
|
|
633
|
+
throw new Error(
|
|
634
|
+
"useFeedbackSession must be used within a FeedbackSessionProvider"
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
return context;
|
|
638
|
+
};
|
|
639
|
+
var useSessionBridge = () => {
|
|
640
|
+
const bridge = useContext2(SessionBridgeContext);
|
|
641
|
+
if (!bridge) {
|
|
642
|
+
throw new Error(
|
|
643
|
+
"CommentContextProvider must be used within a FeedbackSessionProvider"
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
return bridge;
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
// src/contexts/comment-context.tsx
|
|
650
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
651
|
+
var CommentContext = createContext3(null);
|
|
93
652
|
var commentReducer = (state, action) => {
|
|
94
653
|
switch (action.type) {
|
|
95
654
|
case "REGISTER": {
|
|
@@ -102,6 +661,7 @@ var commentReducer = (state, action) => {
|
|
|
102
661
|
...state.comments,
|
|
103
662
|
{
|
|
104
663
|
id: newId,
|
|
664
|
+
sessionId: action.sessionId,
|
|
105
665
|
projectId: state.projectId,
|
|
106
666
|
user: state.currentUser,
|
|
107
667
|
position: {
|
|
@@ -176,22 +736,14 @@ var commentReducer = (state, action) => {
|
|
|
176
736
|
}
|
|
177
737
|
}
|
|
178
738
|
};
|
|
179
|
-
case "
|
|
739
|
+
case "REPLACE_COMMENT":
|
|
180
740
|
return {
|
|
181
741
|
...state,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
case "RESET_RESOLVING_COMMENTS":
|
|
189
|
-
return {
|
|
190
|
-
...state,
|
|
191
|
-
comments: state.comments.filter(
|
|
192
|
-
(comment) => comment.status !== "resolving"
|
|
193
|
-
),
|
|
194
|
-
focussedComment: null
|
|
742
|
+
overlayState: "idle",
|
|
743
|
+
focussedComment: null,
|
|
744
|
+
comments: state.comments.map(
|
|
745
|
+
(comment) => comment.id === action.id ? action.comment : comment
|
|
746
|
+
)
|
|
195
747
|
};
|
|
196
748
|
default: {
|
|
197
749
|
console.warn(`Unhandled action type, returning state`, action);
|
|
@@ -211,30 +763,50 @@ var CommentContextProvider = ({
|
|
|
211
763
|
* @default "inactive"
|
|
212
764
|
*/
|
|
213
765
|
initialOverlayState,
|
|
214
|
-
|
|
215
|
-
onResolve,
|
|
216
|
-
currentUser,
|
|
766
|
+
currentUser: currentUserProp,
|
|
217
767
|
subscription,
|
|
218
768
|
config = {
|
|
219
769
|
commentVisibility: {
|
|
220
|
-
hideResolved: false
|
|
221
|
-
hideResolving: false
|
|
770
|
+
hideResolved: false
|
|
222
771
|
}
|
|
223
772
|
},
|
|
224
773
|
projectId,
|
|
225
|
-
onError
|
|
774
|
+
onError,
|
|
775
|
+
onAdd,
|
|
776
|
+
onEdit,
|
|
777
|
+
onDelete,
|
|
778
|
+
onResolve,
|
|
779
|
+
onReopen
|
|
226
780
|
}) => {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
781
|
+
const hostRef = useRef4({ onAdd, onEdit, onDelete, onResolve, onReopen });
|
|
782
|
+
hostRef.current = { onAdd, onEdit, onDelete, onResolve, onReopen };
|
|
783
|
+
const bridge = useSessionBridge();
|
|
784
|
+
const bridgeRef = useRef4(bridge);
|
|
785
|
+
bridgeRef.current = bridge;
|
|
786
|
+
const canResolveRef = useRef4(bridge.canResolve);
|
|
787
|
+
canResolveRef.current = bridge.canResolve;
|
|
788
|
+
const contextUser = useOptionalCurrentUser();
|
|
789
|
+
const currentUser = contextUser !== void 0 ? contextUser : currentUserProp ?? null;
|
|
790
|
+
const currentUserRef = useRef4(currentUser);
|
|
791
|
+
currentUserRef.current = currentUser;
|
|
792
|
+
const [state, dispatch] = useReducer2(
|
|
793
|
+
(current, action) => commentReducer(
|
|
794
|
+
{ ...current, currentUser: currentUserRef.current },
|
|
795
|
+
action
|
|
796
|
+
),
|
|
797
|
+
void 0,
|
|
798
|
+
() => ({
|
|
799
|
+
comments: initialComments ?? bridge.session?.comments ?? [],
|
|
800
|
+
overlayState: initialOverlayState || "inactive",
|
|
801
|
+
currentUser,
|
|
802
|
+
focussedComment: null,
|
|
803
|
+
config,
|
|
804
|
+
projectId
|
|
805
|
+
})
|
|
806
|
+
);
|
|
235
807
|
const { events, emit } = useCommentEvents();
|
|
236
|
-
const prevFocusRef =
|
|
237
|
-
|
|
808
|
+
const prevFocusRef = useRef4(null);
|
|
809
|
+
useEffect2(() => {
|
|
238
810
|
if (state.focussedComment !== prevFocusRef.current) {
|
|
239
811
|
const comment = state.comments.find(
|
|
240
812
|
(c) => c.id === state.focussedComment
|
|
@@ -243,7 +815,7 @@ var CommentContextProvider = ({
|
|
|
243
815
|
prevFocusRef.current = state.focussedComment;
|
|
244
816
|
}
|
|
245
817
|
}, [state.focussedComment, state.comments, emit]);
|
|
246
|
-
|
|
818
|
+
useEffect2(() => {
|
|
247
819
|
if (!subscription) return;
|
|
248
820
|
subscription.subscribe((data) => {
|
|
249
821
|
dispatch({ type: "APPEND_COMMENT", comment: data });
|
|
@@ -253,14 +825,20 @@ var CommentContextProvider = ({
|
|
|
253
825
|
};
|
|
254
826
|
}, [subscription]);
|
|
255
827
|
const registerComment = (position, indicatorPosition) => {
|
|
828
|
+
const session = bridgeRef.current.session;
|
|
829
|
+
if (session?.status !== "draft") {
|
|
830
|
+
onError?.(new SessionStateError());
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
256
833
|
dispatch({
|
|
257
834
|
type: "REGISTER",
|
|
835
|
+
sessionId: session.id,
|
|
258
836
|
position,
|
|
259
837
|
indicatorPosition: indicatorPosition || null
|
|
260
838
|
});
|
|
261
839
|
};
|
|
262
|
-
const prevCommentsLengthRef =
|
|
263
|
-
|
|
840
|
+
const prevCommentsLengthRef = useRef4(state.comments.length);
|
|
841
|
+
useEffect2(() => {
|
|
264
842
|
if (state.comments.length > prevCommentsLengthRef.current) {
|
|
265
843
|
const lastComment = state.comments[state.comments.length - 1];
|
|
266
844
|
if (lastComment && lastComment.status === "draft") {
|
|
@@ -269,13 +847,154 @@ var CommentContextProvider = ({
|
|
|
269
847
|
}
|
|
270
848
|
prevCommentsLengthRef.current = state.comments.length;
|
|
271
849
|
}, [state.comments, emit]);
|
|
272
|
-
const
|
|
850
|
+
const providerId = useId();
|
|
851
|
+
const localDraftCount = state.comments.filter(hasStatus("draft")).length;
|
|
852
|
+
useEffect2(() => {
|
|
853
|
+
bridgeRef.current.setLocalDraftCount(providerId, localDraftCount);
|
|
854
|
+
}, [providerId, localDraftCount]);
|
|
855
|
+
useEffect2(
|
|
856
|
+
() => () => bridgeRef.current.setLocalDraftCount(providerId, 0),
|
|
857
|
+
[providerId]
|
|
858
|
+
);
|
|
859
|
+
const fail = (error) => {
|
|
860
|
+
onError?.(error);
|
|
861
|
+
return { error };
|
|
862
|
+
};
|
|
863
|
+
const findComment = (id) => state.comments.find((comment) => comment.id === id);
|
|
864
|
+
const addComment = async (draft, content) => {
|
|
865
|
+
if (content.trim().length === 0) {
|
|
866
|
+
return fail(new AddError("content is empty"));
|
|
867
|
+
}
|
|
868
|
+
const persisted = {
|
|
869
|
+
...draft,
|
|
870
|
+
content,
|
|
871
|
+
status: "published"
|
|
872
|
+
};
|
|
873
|
+
const { onAdd: onAdd2 } = hostRef.current;
|
|
874
|
+
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "saving" });
|
|
875
|
+
if (onAdd2) {
|
|
876
|
+
const { error } = await tx.executeAsync(async () => onAdd2(persisted));
|
|
877
|
+
if (error) {
|
|
878
|
+
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "editing" });
|
|
879
|
+
return fail(toKnownError(error, AddError));
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
dispatch({ type: "REPLACE_COMMENT", id: draft.id, comment: persisted });
|
|
883
|
+
bridgeRef.current.commitComment(persisted);
|
|
884
|
+
emit("onCommentAdded", persisted);
|
|
885
|
+
return { error: null };
|
|
886
|
+
};
|
|
887
|
+
const editComment = async (comment, content) => {
|
|
888
|
+
if (content === comment.content) return { error: null };
|
|
889
|
+
const updated = {
|
|
890
|
+
...comment,
|
|
891
|
+
content,
|
|
892
|
+
status: "published"
|
|
893
|
+
};
|
|
894
|
+
const { onEdit: onEdit2 } = hostRef.current;
|
|
895
|
+
if (onEdit2) {
|
|
896
|
+
const { error } = await tx.executeAsync(async () => onEdit2(updated));
|
|
897
|
+
if (error) return fail(toKnownError(error, EditError));
|
|
898
|
+
}
|
|
899
|
+
dispatch({ type: "REPLACE_COMMENT", id: comment.id, comment: updated });
|
|
900
|
+
bridgeRef.current.commitComment(updated);
|
|
901
|
+
emit("onCommentEdited", updated);
|
|
902
|
+
return { error: null };
|
|
903
|
+
};
|
|
904
|
+
const updateComment = async (id, newComment) => {
|
|
905
|
+
const session = bridgeRef.current.session;
|
|
906
|
+
if (session?.status !== "draft") {
|
|
907
|
+
return fail(new SessionStateError());
|
|
908
|
+
}
|
|
909
|
+
const comment = findComment(id);
|
|
910
|
+
if (!comment) return fail(new EditError("comment not found"));
|
|
911
|
+
if (comment.status === "draft") {
|
|
912
|
+
if (comment.sessionId !== session.id) {
|
|
913
|
+
return fail(new SessionStateError());
|
|
914
|
+
}
|
|
915
|
+
return addComment(comment, newComment.content);
|
|
916
|
+
}
|
|
917
|
+
if (comment.status === "published") {
|
|
918
|
+
return editComment(comment, newComment.content);
|
|
919
|
+
}
|
|
920
|
+
return fail(new EditError("a resolved comment cannot be edited"));
|
|
921
|
+
};
|
|
922
|
+
const removePersisted = async (id) => {
|
|
923
|
+
const { onDelete: onDelete2 } = hostRef.current;
|
|
924
|
+
if (onDelete2) {
|
|
925
|
+
const { error } = await tx.executeAsync(async () => onDelete2(id));
|
|
926
|
+
if (error) return fail(toKnownError(error, DeleteError));
|
|
927
|
+
}
|
|
928
|
+
bridgeRef.current.removeComment(id);
|
|
273
929
|
dispatch({ type: "DELETE", id });
|
|
274
930
|
emit("onCommentDeleted", id);
|
|
931
|
+
return { error: null };
|
|
275
932
|
};
|
|
276
|
-
const
|
|
277
|
-
|
|
933
|
+
const deleteComment = async (id) => {
|
|
934
|
+
if (bridgeRef.current.session?.status !== "draft") {
|
|
935
|
+
return fail(new SessionStateError());
|
|
936
|
+
}
|
|
937
|
+
const comment = findComment(id);
|
|
938
|
+
if (!comment) return fail(new DeleteError("comment not found"));
|
|
939
|
+
if (comment.status === "draft") {
|
|
940
|
+
dispatch({ type: "DELETE", id });
|
|
941
|
+
emit("onCommentDeleted", id);
|
|
942
|
+
return { error: null };
|
|
943
|
+
}
|
|
944
|
+
return removePersisted(id);
|
|
278
945
|
};
|
|
946
|
+
const statusInFlightRef = useRef4(/* @__PURE__ */ new Set());
|
|
947
|
+
const guardStatusChange = (id, from, failure) => {
|
|
948
|
+
if (!canResolveRef.current) return fail(new PermissionError());
|
|
949
|
+
if (bridgeRef.current.session?.status !== "resolving") {
|
|
950
|
+
return fail(new SessionStateError());
|
|
951
|
+
}
|
|
952
|
+
const comment = findComment(id);
|
|
953
|
+
if (!comment) return fail(new failure("comment not found"));
|
|
954
|
+
if (comment.status !== from) return { error: null };
|
|
955
|
+
if (statusInFlightRef.current.has(id)) return { error: null };
|
|
956
|
+
return { comment };
|
|
957
|
+
};
|
|
958
|
+
const changeStatus = async (id, step) => {
|
|
959
|
+
const guard = guardStatusChange(id, step.from, step.failure);
|
|
960
|
+
if (!("comment" in guard)) return guard;
|
|
961
|
+
statusInFlightRef.current.add(id);
|
|
962
|
+
try {
|
|
963
|
+
const next = step.build(guard.comment);
|
|
964
|
+
if (step.call) {
|
|
965
|
+
const { call } = step;
|
|
966
|
+
const { error } = await tx.executeAsync(async () => call(next));
|
|
967
|
+
if (error) return fail(toKnownError(error, step.failure));
|
|
968
|
+
}
|
|
969
|
+
dispatch({ type: "REPLACE_COMMENT", id, comment: next });
|
|
970
|
+
bridgeRef.current.commitCommentStatus(next);
|
|
971
|
+
emit(step.event, next);
|
|
972
|
+
return { error: null };
|
|
973
|
+
} finally {
|
|
974
|
+
statusInFlightRef.current.delete(id);
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
const resolveComment = (id) => changeStatus(id, {
|
|
978
|
+
from: "published",
|
|
979
|
+
build: (comment) => ({
|
|
980
|
+
...comment,
|
|
981
|
+
status: "resolved",
|
|
982
|
+
resolvedAt: /* @__PURE__ */ new Date()
|
|
983
|
+
}),
|
|
984
|
+
call: hostRef.current.onResolve,
|
|
985
|
+
failure: ResolveError,
|
|
986
|
+
event: "onCommentResolved"
|
|
987
|
+
});
|
|
988
|
+
const reopenComment = (id) => changeStatus(id, {
|
|
989
|
+
from: "resolved",
|
|
990
|
+
build: (comment) => {
|
|
991
|
+
const { resolvedAt: _resolvedAt, ...rest } = comment;
|
|
992
|
+
return { ...rest, status: "published" };
|
|
993
|
+
},
|
|
994
|
+
call: hostRef.current.onReopen,
|
|
995
|
+
failure: ReopenError,
|
|
996
|
+
event: "onCommentReopened"
|
|
997
|
+
});
|
|
279
998
|
const getActiveComment = () => {
|
|
280
999
|
return state.comments.find(
|
|
281
1000
|
(comment) => comment.id === state.focussedComment
|
|
@@ -287,81 +1006,12 @@ var CommentContextProvider = ({
|
|
|
287
1006
|
const toggleOverlay = () => {
|
|
288
1007
|
dispatch({ type: "TOGGLE_OVERLAY" });
|
|
289
1008
|
};
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
const getResolvingComments = () => {
|
|
297
|
-
return state.comments.filter(hasStatus("resolving"));
|
|
298
|
-
};
|
|
299
|
-
const getResolvedComments = () => {
|
|
300
|
-
return state.comments.filter(hasStatus("resolved"));
|
|
301
|
-
};
|
|
302
|
-
const toggleResolvingComment = (id) => {
|
|
303
|
-
const comment = state.comments.find((comment2) => comment2.id === id);
|
|
304
|
-
dispatch({
|
|
305
|
-
type: "EDIT",
|
|
306
|
-
id,
|
|
307
|
-
newComment: {
|
|
308
|
-
status: comment?.status === "resolving" ? "published" : "resolving"
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
};
|
|
312
|
-
const confirmComments = async () => {
|
|
313
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "saving" });
|
|
314
|
-
const draftComments = getDraftComments();
|
|
315
|
-
const { error } = await tx.executeAsync(
|
|
316
|
-
async () => onConfirm(
|
|
317
|
-
draftComments.map((c) => ({
|
|
318
|
-
...c,
|
|
319
|
-
status: "published"
|
|
320
|
-
})),
|
|
321
|
-
projectId
|
|
322
|
-
)
|
|
323
|
-
);
|
|
324
|
-
if (error) {
|
|
325
|
-
if (onError) {
|
|
326
|
-
onError(new ConfirmError(error.message));
|
|
327
|
-
}
|
|
328
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
329
|
-
return { error: new ConfirmError(error.message) };
|
|
330
|
-
}
|
|
331
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
332
|
-
dispatch({ type: "RESET_DRAFT_COMMENTS" });
|
|
333
|
-
emit(
|
|
334
|
-
"onCommentsConfirmed",
|
|
335
|
-
draftComments.map((c) => ({ ...c, status: "published" }))
|
|
336
|
-
);
|
|
337
|
-
return { error: null };
|
|
338
|
-
};
|
|
339
|
-
const resolveComments = async () => {
|
|
340
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "resolving" });
|
|
341
|
-
const resolvingComments = getResolvingComments();
|
|
342
|
-
const { error } = await tx.executeAsync(
|
|
343
|
-
async () => onResolve(
|
|
344
|
-
resolvingComments.map((c) => ({
|
|
345
|
-
...c,
|
|
346
|
-
status: "resolved"
|
|
347
|
-
}))
|
|
348
|
-
)
|
|
349
|
-
);
|
|
350
|
-
if (error) {
|
|
351
|
-
if (onError) {
|
|
352
|
-
onError(new ResolveError(error.message));
|
|
353
|
-
}
|
|
354
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
355
|
-
return { error: new ResolveError(error.message) };
|
|
356
|
-
}
|
|
357
|
-
dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" });
|
|
358
|
-
dispatch({ type: "RESET_RESOLVING_COMMENTS" });
|
|
359
|
-
emit(
|
|
360
|
-
"onCommentsResolved",
|
|
361
|
-
resolvingComments.map((c) => ({ ...c, status: "resolved" }))
|
|
362
|
-
);
|
|
363
|
-
return { error: null };
|
|
364
|
-
};
|
|
1009
|
+
const visibleComments = selectVisibleComments({
|
|
1010
|
+
comments: state.comments,
|
|
1011
|
+
session: bridge.session ? { id: bridge.session.id, status: bridge.session.status } : null,
|
|
1012
|
+
draftVisibility: state.config?.draftVisibility,
|
|
1013
|
+
currentUserId: currentUser?.id
|
|
1014
|
+
});
|
|
365
1015
|
const updateCommentVisibility = (visibility) => {
|
|
366
1016
|
dispatch({ type: "UPDATE_VISIBILITY", visibility });
|
|
367
1017
|
};
|
|
@@ -373,18 +1023,16 @@ var CommentContextProvider = ({
|
|
|
373
1023
|
onError(error);
|
|
374
1024
|
}
|
|
375
1025
|
};
|
|
376
|
-
return /* @__PURE__ */
|
|
1026
|
+
return /* @__PURE__ */ jsx3(
|
|
377
1027
|
CommentContext.Provider,
|
|
378
1028
|
{
|
|
379
1029
|
value: {
|
|
380
|
-
draftComments:
|
|
381
|
-
comments:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
allComments: state.comments,
|
|
1030
|
+
draftComments: visibleComments.filter(hasStatus("draft")),
|
|
1031
|
+
comments: visibleComments.filter(hasStatus("published")),
|
|
1032
|
+
resolvedComments: visibleComments.filter(hasStatus("resolved")),
|
|
1033
|
+
allComments: visibleComments,
|
|
385
1034
|
config: state.config,
|
|
386
1035
|
changeOverlayState,
|
|
387
|
-
toggleResolvingComment,
|
|
388
1036
|
overlayState: state.overlayState,
|
|
389
1037
|
deleteComment,
|
|
390
1038
|
updateComment,
|
|
@@ -392,9 +1040,10 @@ var CommentContextProvider = ({
|
|
|
392
1040
|
registerComment,
|
|
393
1041
|
getActiveComment,
|
|
394
1042
|
toggleOverlay,
|
|
395
|
-
confirmComments,
|
|
396
1043
|
currentUser,
|
|
397
|
-
|
|
1044
|
+
resolveComment,
|
|
1045
|
+
reopenComment,
|
|
1046
|
+
canResolve: bridge.canResolve,
|
|
398
1047
|
updateCommentVisibility,
|
|
399
1048
|
triggerError,
|
|
400
1049
|
events
|
|
@@ -404,7 +1053,8 @@ var CommentContextProvider = ({
|
|
|
404
1053
|
);
|
|
405
1054
|
};
|
|
406
1055
|
var useComments = () => {
|
|
407
|
-
|
|
1056
|
+
useSessionBridge();
|
|
1057
|
+
const context = useContext3(CommentContext);
|
|
408
1058
|
if (!context) {
|
|
409
1059
|
throw new Error("useComments must be used within a CommentContextProvider");
|
|
410
1060
|
}
|
|
@@ -425,7 +1075,7 @@ var normalizeRect = (a, b) => {
|
|
|
425
1075
|
};
|
|
426
1076
|
|
|
427
1077
|
// src/components/comment-overlay.tsx
|
|
428
|
-
import { jsx as
|
|
1078
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
429
1079
|
var DRAG_THRESHOLD = 4;
|
|
430
1080
|
var CommentOverlay = ({ children, ...rest }) => {
|
|
431
1081
|
const {
|
|
@@ -437,9 +1087,9 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
437
1087
|
triggerError
|
|
438
1088
|
} = useComments();
|
|
439
1089
|
const [preview, setPreview] = useState(null);
|
|
440
|
-
const startRef =
|
|
441
|
-
const draggingRef =
|
|
442
|
-
const overlayRef =
|
|
1090
|
+
const startRef = useRef5(null);
|
|
1091
|
+
const draggingRef = useRef5(false);
|
|
1092
|
+
const overlayRef = useRef5(null);
|
|
443
1093
|
const onPointerDown = (e) => {
|
|
444
1094
|
if (overlayState === "editing") {
|
|
445
1095
|
triggerError(
|
|
@@ -501,7 +1151,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
501
1151
|
};
|
|
502
1152
|
if (overlayState === "inactive") return children;
|
|
503
1153
|
return /* @__PURE__ */ jsxs("div", { "data-overlay": true, style: { position: "relative", ...rest.style }, ...rest, children: [
|
|
504
|
-
/* @__PURE__ */
|
|
1154
|
+
/* @__PURE__ */ jsx4(
|
|
505
1155
|
"div",
|
|
506
1156
|
{
|
|
507
1157
|
ref: overlayRef,
|
|
@@ -515,7 +1165,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
515
1165
|
}
|
|
516
1166
|
),
|
|
517
1167
|
getActiveComment() && // biome-ignore lint: This element should only handle clicks as a guard
|
|
518
|
-
/* @__PURE__ */
|
|
1168
|
+
/* @__PURE__ */ jsx4(
|
|
519
1169
|
"div",
|
|
520
1170
|
{
|
|
521
1171
|
"data-comment-guard": true,
|
|
@@ -541,7 +1191,7 @@ var CommentOverlay = ({ children, ...rest }) => {
|
|
|
541
1191
|
}
|
|
542
1192
|
}
|
|
543
1193
|
),
|
|
544
|
-
preview && /* @__PURE__ */
|
|
1194
|
+
preview && /* @__PURE__ */ jsx4(
|
|
545
1195
|
"div",
|
|
546
1196
|
{
|
|
547
1197
|
style: {
|
|
@@ -573,11 +1223,10 @@ var EDITING_STYLES = {
|
|
|
573
1223
|
};
|
|
574
1224
|
|
|
575
1225
|
// src/components/comment-renderer.tsx
|
|
576
|
-
import { Fragment, jsx as
|
|
1226
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
577
1227
|
var CommentRenderer = ({
|
|
578
1228
|
Comment: Comment2,
|
|
579
1229
|
DraftComment,
|
|
580
|
-
ResolvingComment,
|
|
581
1230
|
ResolvedComment
|
|
582
1231
|
}) => {
|
|
583
1232
|
const {
|
|
@@ -585,35 +1234,30 @@ var CommentRenderer = ({
|
|
|
585
1234
|
draftComments,
|
|
586
1235
|
overlayState,
|
|
587
1236
|
resolvedComments,
|
|
588
|
-
resolvingComments,
|
|
589
1237
|
config
|
|
590
1238
|
} = useComments();
|
|
591
1239
|
if (overlayState === "inactive") return null;
|
|
592
1240
|
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
593
1241
|
draftComments.map((comment) => {
|
|
594
|
-
return /* @__PURE__ */
|
|
1242
|
+
return /* @__PURE__ */ jsx5(DraftComment, { comment }, comment.id);
|
|
595
1243
|
}),
|
|
596
1244
|
comments.map((comment) => {
|
|
597
|
-
return /* @__PURE__ */
|
|
598
|
-
}),
|
|
599
|
-
resolvingComments.map((comment) => {
|
|
600
|
-
if (config?.commentVisibility?.hideResolving) return null;
|
|
601
|
-
return /* @__PURE__ */ jsx3(ResolvingComment, { comment }, comment.id);
|
|
1245
|
+
return /* @__PURE__ */ jsx5(Comment2, { comment }, comment.id);
|
|
602
1246
|
}),
|
|
603
1247
|
resolvedComments.map((comment) => {
|
|
604
1248
|
if (config?.commentVisibility?.hideResolved) return null;
|
|
605
|
-
return /* @__PURE__ */
|
|
1249
|
+
return /* @__PURE__ */ jsx5(ResolvedComment, { comment }, comment.id);
|
|
606
1250
|
})
|
|
607
1251
|
] });
|
|
608
1252
|
};
|
|
609
1253
|
|
|
610
1254
|
// src/components/comment-actions.tsx
|
|
611
1255
|
import { Slot } from "@radix-ui/react-slot";
|
|
612
|
-
import { jsx as
|
|
1256
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
613
1257
|
var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
614
1258
|
const { toggleOverlay, overlayState } = useComments();
|
|
615
1259
|
const Comp = asChild ? Slot : "button";
|
|
616
|
-
return /* @__PURE__ */
|
|
1260
|
+
return /* @__PURE__ */ jsx6(
|
|
617
1261
|
Comp,
|
|
618
1262
|
{
|
|
619
1263
|
"data-active": overlayState !== "inactive",
|
|
@@ -625,34 +1269,6 @@ var ToggleOverlayButton = ({ asChild, ...rest }) => {
|
|
|
625
1269
|
}
|
|
626
1270
|
);
|
|
627
1271
|
};
|
|
628
|
-
var ConfirmComments = ({ asChild, ...rest }) => {
|
|
629
|
-
const { confirmComments } = useComments();
|
|
630
|
-
const Comp = asChild ? Slot : "button";
|
|
631
|
-
return /* @__PURE__ */ jsx4(
|
|
632
|
-
Comp,
|
|
633
|
-
{
|
|
634
|
-
...rest,
|
|
635
|
-
onClick: (e) => {
|
|
636
|
-
confirmComments();
|
|
637
|
-
rest.onClick?.(e);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
);
|
|
641
|
-
};
|
|
642
|
-
var ResolveComments = ({ asChild, ...rest }) => {
|
|
643
|
-
const { resolveComments } = useComments();
|
|
644
|
-
const Comp = asChild ? Slot : "button";
|
|
645
|
-
return /* @__PURE__ */ jsx4(
|
|
646
|
-
Comp,
|
|
647
|
-
{
|
|
648
|
-
...rest,
|
|
649
|
-
onClick: (e) => {
|
|
650
|
-
resolveComments();
|
|
651
|
-
rest.onClick?.(e);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
);
|
|
655
|
-
};
|
|
656
1272
|
|
|
657
1273
|
// src/components/comment.tsx
|
|
658
1274
|
import {
|
|
@@ -661,12 +1277,12 @@ import {
|
|
|
661
1277
|
import { Slot as Slot2 } from "@radix-ui/react-slot";
|
|
662
1278
|
|
|
663
1279
|
// src/contexts/scoped-comment.tsx
|
|
664
|
-
import * as
|
|
665
|
-
var CommentScopeContext =
|
|
1280
|
+
import * as React2 from "react";
|
|
1281
|
+
var CommentScopeContext = React2.createContext(
|
|
666
1282
|
null
|
|
667
1283
|
);
|
|
668
1284
|
function useCommentScope() {
|
|
669
|
-
const ctx =
|
|
1285
|
+
const ctx = React2.useContext(CommentScopeContext);
|
|
670
1286
|
if (!ctx) {
|
|
671
1287
|
throw new Error("Comment.* must be used within <Comment.Root />");
|
|
672
1288
|
}
|
|
@@ -674,7 +1290,7 @@ function useCommentScope() {
|
|
|
674
1290
|
}
|
|
675
1291
|
|
|
676
1292
|
// src/components/comment.tsx
|
|
677
|
-
import { jsx as
|
|
1293
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
678
1294
|
var CommentRoot = ({
|
|
679
1295
|
comment,
|
|
680
1296
|
defaultDraft,
|
|
@@ -690,11 +1306,11 @@ var CommentRoot = ({
|
|
|
690
1306
|
top: comment.position.y,
|
|
691
1307
|
left: comment.position.x
|
|
692
1308
|
};
|
|
693
|
-
return /* @__PURE__ */
|
|
1309
|
+
return /* @__PURE__ */ jsx7(
|
|
694
1310
|
CommentScopeContext.Provider,
|
|
695
1311
|
{
|
|
696
1312
|
value: { comment, isActive, draft, setDraft },
|
|
697
|
-
children: /* @__PURE__ */
|
|
1313
|
+
children: /* @__PURE__ */ jsx7(
|
|
698
1314
|
"div",
|
|
699
1315
|
{
|
|
700
1316
|
...rest,
|
|
@@ -716,7 +1332,7 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
716
1332
|
const { config } = useComments();
|
|
717
1333
|
if (!comment.indicator) return null;
|
|
718
1334
|
if (config?.indicatorVisibility === "active" && !isActive) return null;
|
|
719
|
-
return /* @__PURE__ */
|
|
1335
|
+
return /* @__PURE__ */ jsx7(
|
|
720
1336
|
"div",
|
|
721
1337
|
{
|
|
722
1338
|
...rest,
|
|
@@ -738,12 +1354,12 @@ var CommentIndicator = ({ ...rest }) => {
|
|
|
738
1354
|
var CommentContent = ({ asChild, ...rest }) => {
|
|
739
1355
|
const { draft } = useCommentScope();
|
|
740
1356
|
const Comp = asChild ? Slot2 : "p";
|
|
741
|
-
return /* @__PURE__ */
|
|
1357
|
+
return /* @__PURE__ */ jsx7(Comp, { ...rest, children: draft });
|
|
742
1358
|
};
|
|
743
1359
|
var CommentEdit = ({ asChild, ...rest }) => {
|
|
744
1360
|
const { draft, setDraft } = useCommentScope();
|
|
745
1361
|
const Comp = asChild ? Slot2 : "textarea";
|
|
746
|
-
return /* @__PURE__ */
|
|
1362
|
+
return /* @__PURE__ */ jsx7(
|
|
747
1363
|
Comp,
|
|
748
1364
|
{
|
|
749
1365
|
...rest,
|
|
@@ -761,7 +1377,7 @@ var CommentConfirm = ({ asChild, ...rest }) => {
|
|
|
761
1377
|
const { updateComment } = useComments();
|
|
762
1378
|
const { comment, draft } = useCommentScope();
|
|
763
1379
|
const Comp = asChild ? Slot2 : "button";
|
|
764
|
-
return /* @__PURE__ */
|
|
1380
|
+
return /* @__PURE__ */ jsx7(
|
|
765
1381
|
Comp,
|
|
766
1382
|
{
|
|
767
1383
|
...rest,
|
|
@@ -777,7 +1393,7 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
777
1393
|
const { deleteComment } = useComments();
|
|
778
1394
|
const { comment } = useCommentScope();
|
|
779
1395
|
const Comp = asChild ? Slot2 : "button";
|
|
780
|
-
return /* @__PURE__ */
|
|
1396
|
+
return /* @__PURE__ */ jsx7(
|
|
781
1397
|
Comp,
|
|
782
1398
|
{
|
|
783
1399
|
...rest,
|
|
@@ -789,27 +1405,54 @@ var CommentDelete = ({ asChild, ...rest }) => {
|
|
|
789
1405
|
);
|
|
790
1406
|
};
|
|
791
1407
|
var CommentResolve = ({ asChild, ...rest }) => {
|
|
792
|
-
const {
|
|
1408
|
+
const { resolveComment } = useComments();
|
|
793
1409
|
const { comment } = useCommentScope();
|
|
794
1410
|
const Comp = asChild ? Slot2 : "button";
|
|
795
1411
|
if (comment.status === "draft") {
|
|
796
1412
|
console.error(
|
|
797
|
-
`A draft comment can not be
|
|
1413
|
+
`A draft comment can not be resolved, remove this button from this comment: ${comment.id}`
|
|
798
1414
|
);
|
|
799
1415
|
return null;
|
|
800
1416
|
}
|
|
801
1417
|
if (comment.status === "resolved") {
|
|
802
1418
|
console.error(
|
|
803
|
-
`A resolved comment can not be
|
|
1419
|
+
`A resolved comment can not be resolved again, remove this button from this comment: ${comment.id}`
|
|
804
1420
|
);
|
|
805
1421
|
return null;
|
|
806
1422
|
}
|
|
807
|
-
return /* @__PURE__ */
|
|
1423
|
+
return /* @__PURE__ */ jsx7(
|
|
808
1424
|
Comp,
|
|
809
1425
|
{
|
|
810
1426
|
...rest,
|
|
811
1427
|
onClick: (e) => {
|
|
812
|
-
|
|
1428
|
+
resolveComment(comment.id);
|
|
1429
|
+
rest.onClick?.(e);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
);
|
|
1433
|
+
};
|
|
1434
|
+
var CommentReopen = ({ asChild, ...rest }) => {
|
|
1435
|
+
const { reopenComment } = useComments();
|
|
1436
|
+
const { comment } = useCommentScope();
|
|
1437
|
+
const Comp = asChild ? Slot2 : "button";
|
|
1438
|
+
if (comment.status === "draft") {
|
|
1439
|
+
console.error(
|
|
1440
|
+
`A draft comment can not be reopened, remove this button from this comment: ${comment.id}`
|
|
1441
|
+
);
|
|
1442
|
+
return null;
|
|
1443
|
+
}
|
|
1444
|
+
if (comment.status === "published") {
|
|
1445
|
+
console.error(
|
|
1446
|
+
`A published comment can not be reopened, remove this button from this comment: ${comment.id}`
|
|
1447
|
+
);
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
return /* @__PURE__ */ jsx7(
|
|
1451
|
+
Comp,
|
|
1452
|
+
{
|
|
1453
|
+
...rest,
|
|
1454
|
+
onClick: (e) => {
|
|
1455
|
+
reopenComment(comment.id);
|
|
813
1456
|
rest.onClick?.(e);
|
|
814
1457
|
}
|
|
815
1458
|
}
|
|
@@ -865,13 +1508,81 @@ var Comment = {
|
|
|
865
1508
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
866
1509
|
Delete: CommentDelete,
|
|
867
1510
|
/**
|
|
868
|
-
*
|
|
1511
|
+
* Resolves a comment
|
|
1512
|
+
*
|
|
1513
|
+
* @description Calls `resolveComment` for this comment. Renders nothing (and logs an error) for draft and resolved comments
|
|
1514
|
+
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
1515
|
+
*/
|
|
1516
|
+
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
1517
|
+
Resolve: CommentResolve,
|
|
1518
|
+
/**
|
|
1519
|
+
* Reopens a resolved comment
|
|
869
1520
|
*
|
|
870
|
-
* @description
|
|
1521
|
+
* @description Calls `reopenComment` for this comment. Renders nothing (and logs an error) for draft and published comments
|
|
871
1522
|
* @param asChild as whether to use the child as the base element instead of the default `<button>` tag. This allows for more flexibility
|
|
872
1523
|
*/
|
|
873
1524
|
// biome-ignore lint/style/useNamingConvention: Modular export
|
|
874
|
-
|
|
1525
|
+
Reopen: CommentReopen
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
// src/components/session-actions.tsx
|
|
1529
|
+
import { Slot as Slot3 } from "@radix-ui/react-slot";
|
|
1530
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1531
|
+
var CreateSession = ({ asChild, ...rest }) => {
|
|
1532
|
+
const { createSession } = useFeedbackSession();
|
|
1533
|
+
const Comp = asChild ? Slot3 : "button";
|
|
1534
|
+
return /* @__PURE__ */ jsx8(
|
|
1535
|
+
Comp,
|
|
1536
|
+
{
|
|
1537
|
+
...rest,
|
|
1538
|
+
onClick: (e) => {
|
|
1539
|
+
void createSession();
|
|
1540
|
+
rest.onClick?.(e);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
);
|
|
1544
|
+
};
|
|
1545
|
+
var ConfirmSession = ({ asChild, ...rest }) => {
|
|
1546
|
+
const { confirmSession } = useFeedbackSession();
|
|
1547
|
+
const Comp = asChild ? Slot3 : "button";
|
|
1548
|
+
return /* @__PURE__ */ jsx8(
|
|
1549
|
+
Comp,
|
|
1550
|
+
{
|
|
1551
|
+
...rest,
|
|
1552
|
+
onClick: (e) => {
|
|
1553
|
+
void confirmSession();
|
|
1554
|
+
rest.onClick?.(e);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
);
|
|
1558
|
+
};
|
|
1559
|
+
var StartResolving = ({ asChild, ...rest }) => {
|
|
1560
|
+
const { startResolving } = useFeedbackSession();
|
|
1561
|
+
const Comp = asChild ? Slot3 : "button";
|
|
1562
|
+
return /* @__PURE__ */ jsx8(
|
|
1563
|
+
Comp,
|
|
1564
|
+
{
|
|
1565
|
+
...rest,
|
|
1566
|
+
onClick: (e) => {
|
|
1567
|
+
void startResolving();
|
|
1568
|
+
rest.onClick?.(e);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
);
|
|
1572
|
+
};
|
|
1573
|
+
var ResolveSession = ({ asChild, ...rest }) => {
|
|
1574
|
+
const { resolveSession } = useFeedbackSession();
|
|
1575
|
+
const Comp = asChild ? Slot3 : "button";
|
|
1576
|
+
return /* @__PURE__ */ jsx8(
|
|
1577
|
+
Comp,
|
|
1578
|
+
{
|
|
1579
|
+
...rest,
|
|
1580
|
+
onClick: (e) => {
|
|
1581
|
+
void resolveSession();
|
|
1582
|
+
rest.onClick?.(e);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
);
|
|
875
1586
|
};
|
|
876
1587
|
export {
|
|
877
1588
|
Comment,
|
|
@@ -879,9 +1590,15 @@ export {
|
|
|
879
1590
|
CommentOverlay,
|
|
880
1591
|
CommentRenderer,
|
|
881
1592
|
CommentScopeContext,
|
|
882
|
-
|
|
883
|
-
|
|
1593
|
+
ConfirmSession,
|
|
1594
|
+
CreateSession,
|
|
1595
|
+
FeedbackSessionProvider,
|
|
1596
|
+
ResolveSession,
|
|
1597
|
+
StartResolving,
|
|
884
1598
|
ToggleOverlayButton,
|
|
1599
|
+
UserProvider,
|
|
885
1600
|
useCommentScope,
|
|
886
|
-
useComments
|
|
1601
|
+
useComments,
|
|
1602
|
+
useCurrentUser,
|
|
1603
|
+
useFeedbackSession
|
|
887
1604
|
};
|