@matija2209/payload-plugin-admin-feedback 1.0.0 → 1.0.3
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 +47 -106
- package/dist/client/index.cjs +2851 -0
- package/dist/client/index.d.cts +140 -0
- package/dist/client/index.d.ts +140 -0
- package/dist/client/index.js +2838 -0
- package/dist/index.cjs +646 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +643 -0
- package/dist/routeMatcher-CmCMn_gT.d.cts +54 -0
- package/dist/routeMatcher-CmCMn_gT.d.ts +54 -0
- package/package.json +25 -5
- package/src/client/AdminFeedbackWidget.tsx +0 -63
- package/src/client/FeedbackWidget.tsx +0 -1438
- package/src/client/FrontendFeedbackWidget.tsx +0 -100
- package/src/client/index.ts +0 -4
- package/src/client/routeMatcher.ts +0 -18
- package/src/collections/AdminFeedback.ts +0 -325
- package/src/index.ts +0 -108
- package/src/server/sendFeedbackEmail.ts +0 -141
- package/src/types.ts +0 -73
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -19
- package/tsup.config.ts +0 -29
|
@@ -0,0 +1,2838 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { ArrowLeft, PencilLine, Trash2, ImageIcon, Camera, Upload, X, Save, ExternalLink, MapPin, CalendarClock, RefreshCw, MessageSquareText, Clock3, ChevronLeft, ChevronRight, MessageSquarePlus, Sparkles, MessageSquare, History, MousePointerClick, CheckCircle2, SendHorizontal, PenTool, Square, ArrowRight, Type, Undo2, Redo2, Eraser, RotateCcw } from 'lucide-react';
|
|
3
|
+
import React2 from 'react';
|
|
4
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
import { usePathname } from 'next/navigation';
|
|
6
|
+
|
|
7
|
+
// src/client/FeedbackWidget.tsx
|
|
8
|
+
|
|
9
|
+
// src/client/ui.ts
|
|
10
|
+
var theme = {
|
|
11
|
+
accent: "#5eead4",
|
|
12
|
+
text: "#f8fafc",
|
|
13
|
+
textSoft: "rgba(226, 232, 240, 0.78)",
|
|
14
|
+
textMuted: "rgba(148, 163, 184, 0.78)",
|
|
15
|
+
dangerSoft: "rgba(248, 113, 113, 0.18)",
|
|
16
|
+
border: "rgba(148, 163, 184, 0.18)",
|
|
17
|
+
borderStrong: "rgba(148, 163, 184, 0.28)",
|
|
18
|
+
panel: "linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(6, 13, 24, 0.96) 100%)",
|
|
19
|
+
card: "linear-gradient(180deg, rgba(30, 41, 59, 0.54) 0%, rgba(15, 23, 42, 0.7) 100%)",
|
|
20
|
+
inset: "rgba(15, 23, 42, 0.82)",
|
|
21
|
+
shadow: "0 28px 70px rgba(2, 8, 23, 0.48)",
|
|
22
|
+
subtleShadow: "0 18px 40px rgba(2, 8, 23, 0.24)"
|
|
23
|
+
};
|
|
24
|
+
var floatingLauncherStyle = {
|
|
25
|
+
position: "fixed",
|
|
26
|
+
right: "20px",
|
|
27
|
+
bottom: "20px",
|
|
28
|
+
zIndex: 9999,
|
|
29
|
+
display: "inline-flex",
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
gap: "8px",
|
|
32
|
+
borderRadius: "999px",
|
|
33
|
+
border: `1px solid ${theme.borderStrong}`,
|
|
34
|
+
background: "linear-gradient(135deg, rgba(45, 212, 191, 0.96) 0%, rgba(15, 118, 110, 0.96) 100%)",
|
|
35
|
+
color: "#03131f",
|
|
36
|
+
padding: "10px 14px",
|
|
37
|
+
fontWeight: 700,
|
|
38
|
+
fontSize: "13px",
|
|
39
|
+
letterSpacing: "-0.01em",
|
|
40
|
+
cursor: "pointer",
|
|
41
|
+
boxShadow: "0 24px 55px rgba(15, 118, 110, 0.34)"
|
|
42
|
+
};
|
|
43
|
+
var panelStyle = {
|
|
44
|
+
position: "fixed",
|
|
45
|
+
right: "12px",
|
|
46
|
+
bottom: "calc(12px + env(safe-area-inset-bottom, 0px))",
|
|
47
|
+
width: "min(396px, calc(100vw - 24px))",
|
|
48
|
+
maxHeight: "min(780px, calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)))",
|
|
49
|
+
height: "min(780px, calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)))",
|
|
50
|
+
overflow: "hidden",
|
|
51
|
+
display: "flex",
|
|
52
|
+
flexDirection: "column",
|
|
53
|
+
overscrollBehavior: "contain",
|
|
54
|
+
background: theme.panel,
|
|
55
|
+
color: theme.text,
|
|
56
|
+
borderRadius: "22px",
|
|
57
|
+
border: `1px solid ${theme.border}`,
|
|
58
|
+
zIndex: 9999,
|
|
59
|
+
boxShadow: theme.shadow,
|
|
60
|
+
backdropFilter: "blur(18px)"
|
|
61
|
+
};
|
|
62
|
+
var panelHeaderStyle = {
|
|
63
|
+
padding: "14px 14px 12px",
|
|
64
|
+
borderBottom: `1px solid ${theme.border}`,
|
|
65
|
+
background: "radial-gradient(circle at top right, rgba(45, 212, 191, 0.14), transparent 38%), transparent"
|
|
66
|
+
};
|
|
67
|
+
var surfaceCardStyle = {
|
|
68
|
+
background: theme.card,
|
|
69
|
+
border: `1px solid ${theme.border}`,
|
|
70
|
+
borderRadius: "16px",
|
|
71
|
+
boxShadow: theme.subtleShadow
|
|
72
|
+
};
|
|
73
|
+
var innerCardStyle = {
|
|
74
|
+
background: theme.inset,
|
|
75
|
+
border: `1px solid ${theme.border}`,
|
|
76
|
+
borderRadius: "14px"
|
|
77
|
+
};
|
|
78
|
+
var fieldStyle = {
|
|
79
|
+
width: "100%",
|
|
80
|
+
borderRadius: "14px",
|
|
81
|
+
border: `1px solid ${theme.border}`,
|
|
82
|
+
background: "rgba(15, 23, 42, 0.86)",
|
|
83
|
+
color: theme.text,
|
|
84
|
+
padding: "12px 14px",
|
|
85
|
+
fontSize: "13px",
|
|
86
|
+
lineHeight: 1.5,
|
|
87
|
+
outline: "none",
|
|
88
|
+
boxSizing: "border-box",
|
|
89
|
+
boxShadow: "inset 0 1px 0 rgba(255,255,255,0.03)"
|
|
90
|
+
};
|
|
91
|
+
var metaTextStyle = {
|
|
92
|
+
margin: 0,
|
|
93
|
+
fontSize: "12px",
|
|
94
|
+
lineHeight: 1.5,
|
|
95
|
+
color: theme.textMuted
|
|
96
|
+
};
|
|
97
|
+
var sectionLabelStyle = {
|
|
98
|
+
margin: 0,
|
|
99
|
+
fontSize: "11px",
|
|
100
|
+
fontWeight: 700,
|
|
101
|
+
letterSpacing: "0.08em",
|
|
102
|
+
textTransform: "uppercase",
|
|
103
|
+
color: theme.textMuted
|
|
104
|
+
};
|
|
105
|
+
var statusTextStyle = {
|
|
106
|
+
margin: 0,
|
|
107
|
+
fontSize: "12px",
|
|
108
|
+
lineHeight: 1.5,
|
|
109
|
+
color: theme.textSoft
|
|
110
|
+
};
|
|
111
|
+
function buttonStyle(variant, options = {}) {
|
|
112
|
+
const { active = false, disabled = false, iconOnly = false, compact = false, justify = "center" } = options;
|
|
113
|
+
const base = {
|
|
114
|
+
display: "inline-flex",
|
|
115
|
+
alignItems: "center",
|
|
116
|
+
justifyContent: justify,
|
|
117
|
+
gap: "8px",
|
|
118
|
+
minHeight: compact ? "32px" : "38px",
|
|
119
|
+
padding: iconOnly ? compact ? "7px" : "9px" : compact ? "7px 11px" : "9px 13px",
|
|
120
|
+
borderRadius: iconOnly ? "12px" : "14px",
|
|
121
|
+
border: `1px solid ${theme.border}`,
|
|
122
|
+
color: theme.text,
|
|
123
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
124
|
+
fontSize: compact ? "12px" : "13px",
|
|
125
|
+
fontWeight: 600,
|
|
126
|
+
letterSpacing: "-0.01em",
|
|
127
|
+
transition: "transform 0.18s ease, opacity 0.18s ease, border-color 0.18s ease",
|
|
128
|
+
opacity: disabled ? 0.45 : 1,
|
|
129
|
+
boxSizing: "border-box"
|
|
130
|
+
};
|
|
131
|
+
const variants = {
|
|
132
|
+
primary: {
|
|
133
|
+
background: "linear-gradient(135deg, rgba(94, 234, 212, 0.98) 0%, rgba(20, 184, 166, 0.98) 100%)",
|
|
134
|
+
borderColor: "rgba(153, 246, 228, 0.38)",
|
|
135
|
+
color: "#04111c",
|
|
136
|
+
boxShadow: "0 18px 35px rgba(20, 184, 166, 0.22)"
|
|
137
|
+
},
|
|
138
|
+
secondary: {
|
|
139
|
+
background: active ? "rgba(94, 234, 212, 0.14)" : theme.card,
|
|
140
|
+
borderColor: active ? "rgba(94, 234, 212, 0.34)" : theme.border,
|
|
141
|
+
color: active ? "#d1fae5" : theme.text
|
|
142
|
+
},
|
|
143
|
+
ghost: {
|
|
144
|
+
background: active ? "rgba(94, 234, 212, 0.12)" : "transparent",
|
|
145
|
+
borderColor: active ? "rgba(94, 234, 212, 0.28)" : "transparent",
|
|
146
|
+
color: active ? theme.text : theme.textSoft
|
|
147
|
+
},
|
|
148
|
+
danger: {
|
|
149
|
+
background: active ? "rgba(248, 113, 113, 0.18)" : theme.dangerSoft,
|
|
150
|
+
borderColor: "rgba(248, 113, 113, 0.28)",
|
|
151
|
+
color: "#fecaca"
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return { ...base, ...variants[variant] };
|
|
155
|
+
}
|
|
156
|
+
function pillStyle(variant) {
|
|
157
|
+
const variants = {
|
|
158
|
+
neutral: {
|
|
159
|
+
background: "rgba(148, 163, 184, 0.16)",
|
|
160
|
+
color: theme.textSoft,
|
|
161
|
+
border: `1px solid ${theme.border}`
|
|
162
|
+
},
|
|
163
|
+
success: {
|
|
164
|
+
background: "rgba(34, 197, 94, 0.16)",
|
|
165
|
+
color: "#86efac",
|
|
166
|
+
border: "1px solid rgba(34, 197, 94, 0.24)"
|
|
167
|
+
},
|
|
168
|
+
warning: {
|
|
169
|
+
background: "rgba(234, 179, 8, 0.18)",
|
|
170
|
+
color: "#fde68a",
|
|
171
|
+
border: "1px solid rgba(234, 179, 8, 0.24)"
|
|
172
|
+
},
|
|
173
|
+
muted: {
|
|
174
|
+
background: "rgba(148, 163, 184, 0.16)",
|
|
175
|
+
color: "#cbd5e1",
|
|
176
|
+
border: `1px solid ${theme.border}`
|
|
177
|
+
},
|
|
178
|
+
danger: {
|
|
179
|
+
background: theme.dangerSoft,
|
|
180
|
+
color: "#fecaca",
|
|
181
|
+
border: "1px solid rgba(248, 113, 113, 0.24)"
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
display: "inline-flex",
|
|
186
|
+
alignItems: "center",
|
|
187
|
+
gap: "6px",
|
|
188
|
+
borderRadius: "999px",
|
|
189
|
+
padding: "5px 10px",
|
|
190
|
+
fontSize: "11px",
|
|
191
|
+
fontWeight: 700,
|
|
192
|
+
letterSpacing: "0.01em",
|
|
193
|
+
...variants[variant]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
var formatDate = (iso) => {
|
|
197
|
+
try {
|
|
198
|
+
return new Date(iso).toLocaleString("en-US", {
|
|
199
|
+
month: "short",
|
|
200
|
+
day: "numeric",
|
|
201
|
+
year: "numeric",
|
|
202
|
+
hour: "2-digit",
|
|
203
|
+
minute: "2-digit"
|
|
204
|
+
});
|
|
205
|
+
} catch {
|
|
206
|
+
return iso;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var getScreenshotInfo = (feedback) => {
|
|
210
|
+
if (!feedback.screenshot || typeof feedback.screenshot !== "object") return null;
|
|
211
|
+
const screenshot = feedback.screenshot;
|
|
212
|
+
if (screenshot.url) return { id: screenshot.id, url: screenshot.url };
|
|
213
|
+
if (screenshot.filename) return { id: screenshot.id, url: screenshot.filename };
|
|
214
|
+
return null;
|
|
215
|
+
};
|
|
216
|
+
var getCreatorId = (feedback) => {
|
|
217
|
+
if (!feedback.createdBy) return null;
|
|
218
|
+
if (typeof feedback.createdBy === "object") return feedback.createdBy.id;
|
|
219
|
+
return feedback.createdBy;
|
|
220
|
+
};
|
|
221
|
+
var canvasToFile = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
|
|
222
|
+
const blob = await new Promise((resolve) => {
|
|
223
|
+
canvas.toBlob((nextBlob) => resolve(nextBlob), "image/png");
|
|
224
|
+
});
|
|
225
|
+
if (!blob) throw new Error("Failed to prepare screenshot.");
|
|
226
|
+
return new File([blob], fileName.replace(/\.[a-z0-9]+$/i, "") + ".png", { type: "image/png" });
|
|
227
|
+
};
|
|
228
|
+
var captureScreenshotFile = async () => {
|
|
229
|
+
if (!navigator.mediaDevices?.getDisplayMedia) {
|
|
230
|
+
throw new Error("Browser does not support screen capture.");
|
|
231
|
+
}
|
|
232
|
+
const stream = await navigator.mediaDevices.getDisplayMedia({
|
|
233
|
+
video: { displaySurface: "browser" },
|
|
234
|
+
audio: false,
|
|
235
|
+
preferCurrentTab: true
|
|
236
|
+
});
|
|
237
|
+
const track = stream.getVideoTracks()[0];
|
|
238
|
+
if (!track) {
|
|
239
|
+
stream.getTracks().forEach((nextTrack) => nextTrack.stop());
|
|
240
|
+
throw new Error("Screen capture failed.");
|
|
241
|
+
}
|
|
242
|
+
const video = document.createElement("video");
|
|
243
|
+
try {
|
|
244
|
+
video.srcObject = stream;
|
|
245
|
+
video.muted = true;
|
|
246
|
+
video.playsInline = true;
|
|
247
|
+
await video.play();
|
|
248
|
+
await new Promise((resolve) => {
|
|
249
|
+
if ("requestVideoFrameCallback" in video) {
|
|
250
|
+
video.requestVideoFrameCallback(() => resolve());
|
|
251
|
+
} else {
|
|
252
|
+
requestAnimationFrame(() => resolve());
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const width = video.videoWidth || window.innerWidth;
|
|
256
|
+
const height = video.videoHeight || window.innerHeight;
|
|
257
|
+
if (!width || !height) throw new Error("Screen capture failed.");
|
|
258
|
+
const canvas = document.createElement("canvas");
|
|
259
|
+
canvas.width = width;
|
|
260
|
+
canvas.height = height;
|
|
261
|
+
const context = canvas.getContext("2d");
|
|
262
|
+
if (!context) throw new Error("Browser does not support canvas context.");
|
|
263
|
+
context.drawImage(video, 0, 0, width, height);
|
|
264
|
+
return canvasToFile(canvas);
|
|
265
|
+
} finally {
|
|
266
|
+
video.pause();
|
|
267
|
+
video.srcObject = null;
|
|
268
|
+
stream.getTracks().forEach((nextTrack) => nextTrack.stop());
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
function FeedbackDetail({
|
|
272
|
+
feedback,
|
|
273
|
+
currentUserId,
|
|
274
|
+
capturePolicy: _capturePolicy,
|
|
275
|
+
onBack,
|
|
276
|
+
onUpdate,
|
|
277
|
+
onDelete,
|
|
278
|
+
onUpload,
|
|
279
|
+
onDeleteScreenshot
|
|
280
|
+
}) {
|
|
281
|
+
const [editing, setEditing] = React2.useState(false);
|
|
282
|
+
const [message, setMessage] = React2.useState(feedback.message);
|
|
283
|
+
const [screenshotId, setScreenshotId] = React2.useState(getScreenshotInfo(feedback)?.id ?? null);
|
|
284
|
+
const [screenshotUrl, setScreenshotUrl] = React2.useState(getScreenshotInfo(feedback)?.url ?? null);
|
|
285
|
+
const [uploading, setUploading] = React2.useState(false);
|
|
286
|
+
const [removing, setRemoving] = React2.useState(false);
|
|
287
|
+
const [saving, setSaving] = React2.useState(false);
|
|
288
|
+
const [deleting, setDeleting] = React2.useState(false);
|
|
289
|
+
const [error, setError] = React2.useState(null);
|
|
290
|
+
const isOwner = getCreatorId(feedback) === currentUserId;
|
|
291
|
+
const screenshot = getScreenshotInfo(feedback);
|
|
292
|
+
const currentScreenshotId = screenshotId ?? screenshot?.id ?? null;
|
|
293
|
+
const uploadFile = async (file) => {
|
|
294
|
+
setUploading(true);
|
|
295
|
+
setError(null);
|
|
296
|
+
try {
|
|
297
|
+
const formData = new FormData();
|
|
298
|
+
formData.append("file", file);
|
|
299
|
+
formData.append("alt", file.name);
|
|
300
|
+
const result = await onUpload(formData);
|
|
301
|
+
if (!result.success) {
|
|
302
|
+
setError(result.error);
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
setScreenshotId(result.mediaId);
|
|
306
|
+
setScreenshotUrl(URL.createObjectURL(file));
|
|
307
|
+
return result.mediaId;
|
|
308
|
+
} catch (nextError) {
|
|
309
|
+
setError(nextError instanceof Error ? nextError.message : "Upload failed.");
|
|
310
|
+
return null;
|
|
311
|
+
} finally {
|
|
312
|
+
setUploading(false);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const handleRemoveScreenshot = async () => {
|
|
316
|
+
if (!currentScreenshotId) return;
|
|
317
|
+
setRemoving(true);
|
|
318
|
+
setError(null);
|
|
319
|
+
try {
|
|
320
|
+
const result = await onDeleteScreenshot(currentScreenshotId);
|
|
321
|
+
if (!result.success) {
|
|
322
|
+
setError(result.error);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
setScreenshotId(null);
|
|
326
|
+
setScreenshotUrl(null);
|
|
327
|
+
} catch (nextError) {
|
|
328
|
+
setError(nextError instanceof Error ? nextError.message : "Failed to remove screenshot.");
|
|
329
|
+
} finally {
|
|
330
|
+
setRemoving(false);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const handleCapture = async () => {
|
|
334
|
+
try {
|
|
335
|
+
const file = await captureScreenshotFile();
|
|
336
|
+
await uploadFile(file);
|
|
337
|
+
} catch (nextError) {
|
|
338
|
+
setError(nextError instanceof Error ? nextError.message : "Screen capture failed.");
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const handleFileUpload = async (event) => {
|
|
342
|
+
const file = event.target.files?.[0];
|
|
343
|
+
if (file) await uploadFile(file);
|
|
344
|
+
event.target.value = "";
|
|
345
|
+
};
|
|
346
|
+
React2.useEffect(() => {
|
|
347
|
+
if (!editing) return;
|
|
348
|
+
const onPaste = async (event) => {
|
|
349
|
+
const file = Array.from(event.clipboardData?.items || []).find((item) => item.type.startsWith("image/"))?.getAsFile();
|
|
350
|
+
if (file) {
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
await uploadFile(file);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
window.addEventListener("paste", onPaste);
|
|
356
|
+
return () => window.removeEventListener("paste", onPaste);
|
|
357
|
+
}, [editing]);
|
|
358
|
+
const handleSave = async () => {
|
|
359
|
+
if (!message.trim()) {
|
|
360
|
+
setError("Message cannot be empty.");
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
setSaving(true);
|
|
364
|
+
setError(null);
|
|
365
|
+
try {
|
|
366
|
+
const updateData = {};
|
|
367
|
+
if (message.trim() !== feedback.message) {
|
|
368
|
+
updateData.message = message.trim();
|
|
369
|
+
}
|
|
370
|
+
if ((screenshotId ?? null) !== (feedback.screenshot && typeof feedback.screenshot === "object" ? feedback.screenshot.id : feedback.screenshot)) {
|
|
371
|
+
updateData.screenshotId = screenshotId ?? null;
|
|
372
|
+
}
|
|
373
|
+
const success = await onUpdate(feedback.id, updateData);
|
|
374
|
+
if (success) {
|
|
375
|
+
setEditing(false);
|
|
376
|
+
} else {
|
|
377
|
+
setError("Failed to save changes.");
|
|
378
|
+
}
|
|
379
|
+
} catch (nextError) {
|
|
380
|
+
setError(nextError instanceof Error ? nextError.message : "Save failed.");
|
|
381
|
+
} finally {
|
|
382
|
+
setSaving(false);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const handleDelete = async () => {
|
|
386
|
+
if (!window.confirm("Delete this feedback? This cannot be undone.")) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
setDeleting(true);
|
|
390
|
+
setError(null);
|
|
391
|
+
try {
|
|
392
|
+
const success = await onDelete(feedback.id);
|
|
393
|
+
if (!success) {
|
|
394
|
+
setError("Failed to delete feedback.");
|
|
395
|
+
}
|
|
396
|
+
} catch (nextError) {
|
|
397
|
+
setError(nextError instanceof Error ? nextError.message : "Delete failed.");
|
|
398
|
+
} finally {
|
|
399
|
+
setDeleting(false);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
return /* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: "12px" }, children: [
|
|
403
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "10px" }, children: [
|
|
404
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: onBack, style: buttonStyle("ghost", { compact: true }), children: [
|
|
405
|
+
/* @__PURE__ */ jsx(ArrowLeft, { size: 15 }),
|
|
406
|
+
"Back"
|
|
407
|
+
] }),
|
|
408
|
+
isOwner && !editing ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", justifyContent: "flex-end" }, children: [
|
|
409
|
+
/* @__PURE__ */ jsxs(
|
|
410
|
+
"button",
|
|
411
|
+
{
|
|
412
|
+
type: "button",
|
|
413
|
+
onClick: () => {
|
|
414
|
+
setEditing(true);
|
|
415
|
+
setError(null);
|
|
416
|
+
},
|
|
417
|
+
style: buttonStyle("secondary", { compact: true }),
|
|
418
|
+
children: [
|
|
419
|
+
/* @__PURE__ */ jsx(PencilLine, { size: 15 }),
|
|
420
|
+
"Edit"
|
|
421
|
+
]
|
|
422
|
+
}
|
|
423
|
+
),
|
|
424
|
+
/* @__PURE__ */ jsxs(
|
|
425
|
+
"button",
|
|
426
|
+
{
|
|
427
|
+
type: "button",
|
|
428
|
+
onClick: handleDelete,
|
|
429
|
+
disabled: deleting,
|
|
430
|
+
style: buttonStyle("danger", { compact: true, disabled: deleting }),
|
|
431
|
+
children: [
|
|
432
|
+
/* @__PURE__ */ jsx(Trash2, { size: 15 }),
|
|
433
|
+
deleting ? "Deleting..." : "Delete"
|
|
434
|
+
]
|
|
435
|
+
}
|
|
436
|
+
)
|
|
437
|
+
] }) : null
|
|
438
|
+
] }),
|
|
439
|
+
editing ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
440
|
+
/* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "16px" }, children: [
|
|
441
|
+
/* @__PURE__ */ jsx("p", { style: { ...sectionLabelStyle, marginBottom: "10px" }, children: "Message" }),
|
|
442
|
+
/* @__PURE__ */ jsx(
|
|
443
|
+
"textarea",
|
|
444
|
+
{
|
|
445
|
+
value: message,
|
|
446
|
+
onChange: (event) => setMessage(event.target.value),
|
|
447
|
+
rows: 6,
|
|
448
|
+
style: { ...fieldStyle, resize: "vertical", minHeight: "140px" },
|
|
449
|
+
placeholder: "Describe what changed or what still needs attention..."
|
|
450
|
+
}
|
|
451
|
+
)
|
|
452
|
+
] }),
|
|
453
|
+
/* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "16px" }, children: [
|
|
454
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", marginBottom: "12px" }, children: [
|
|
455
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
456
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "Screenshot" }),
|
|
457
|
+
/* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, marginTop: "4px" }, children: "Paste an image, capture the current tab, or upload a replacement." })
|
|
458
|
+
] }),
|
|
459
|
+
screenshotId ? /* @__PURE__ */ jsxs("span", { style: pillStyle("neutral"), children: [
|
|
460
|
+
"Media #",
|
|
461
|
+
screenshotId
|
|
462
|
+
] }) : null
|
|
463
|
+
] }),
|
|
464
|
+
/* @__PURE__ */ jsx("div", { style: { ...innerCardStyle, overflow: "hidden" }, children: screenshotUrl ? (
|
|
465
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
466
|
+
/* @__PURE__ */ jsx(
|
|
467
|
+
"img",
|
|
468
|
+
{
|
|
469
|
+
src: screenshotUrl,
|
|
470
|
+
alt: "Screenshot",
|
|
471
|
+
style: { width: "100%", height: "auto", display: "block", maxHeight: "280px", objectFit: "cover" }
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
) : /* @__PURE__ */ jsx(
|
|
475
|
+
"div",
|
|
476
|
+
{
|
|
477
|
+
style: {
|
|
478
|
+
minHeight: "180px",
|
|
479
|
+
display: "grid",
|
|
480
|
+
placeItems: "center",
|
|
481
|
+
color: theme.textMuted,
|
|
482
|
+
background: "rgba(15, 23, 42, 0.72)"
|
|
483
|
+
},
|
|
484
|
+
children: /* @__PURE__ */ jsxs("div", { style: { textAlign: "center" }, children: [
|
|
485
|
+
/* @__PURE__ */ jsx(ImageIcon, { size: 24, style: { marginBottom: "8px" } }),
|
|
486
|
+
/* @__PURE__ */ jsx("p", { style: metaTextStyle, children: "No screenshot attached." })
|
|
487
|
+
] })
|
|
488
|
+
}
|
|
489
|
+
) }),
|
|
490
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", marginTop: "12px" }, children: [
|
|
491
|
+
/* @__PURE__ */ jsx(
|
|
492
|
+
"button",
|
|
493
|
+
{
|
|
494
|
+
type: "button",
|
|
495
|
+
onClick: handleCapture,
|
|
496
|
+
disabled: uploading,
|
|
497
|
+
"aria-label": uploading ? "Capturing screen" : "Capture screen",
|
|
498
|
+
title: uploading ? "Capturing screen" : "Capture screen",
|
|
499
|
+
style: buttonStyle("secondary", { compact: true, disabled: uploading, iconOnly: true }),
|
|
500
|
+
children: /* @__PURE__ */ jsx(Camera, { size: 15 })
|
|
501
|
+
}
|
|
502
|
+
),
|
|
503
|
+
/* @__PURE__ */ jsxs(
|
|
504
|
+
"label",
|
|
505
|
+
{
|
|
506
|
+
"aria-label": "Upload image",
|
|
507
|
+
title: "Upload image",
|
|
508
|
+
style: buttonStyle("secondary", { compact: true, iconOnly: true }),
|
|
509
|
+
children: [
|
|
510
|
+
/* @__PURE__ */ jsx(Upload, { size: 15 }),
|
|
511
|
+
/* @__PURE__ */ jsx("input", { type: "file", accept: "image/png,image/jpeg,image/webp", onChange: handleFileUpload, hidden: true })
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
),
|
|
515
|
+
currentScreenshotId && screenshotUrl ? /* @__PURE__ */ jsxs("button", { type: "button", onClick: handleRemoveScreenshot, disabled: removing, style: buttonStyle("danger", { compact: true, disabled: removing }), children: [
|
|
516
|
+
/* @__PURE__ */ jsx(Trash2, { size: 15 }),
|
|
517
|
+
removing ? "Removing..." : "Remove"
|
|
518
|
+
] }) : null
|
|
519
|
+
] })
|
|
520
|
+
] }),
|
|
521
|
+
error ? /* @__PURE__ */ jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(248, 113, 113, 0.24)" }, children: /* @__PURE__ */ jsx("p", { style: { ...statusTextStyle, color: "#fecaca" }, children: error }) }) : null,
|
|
522
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "flex-end", gap: "8px", flexWrap: "wrap" }, children: [
|
|
523
|
+
/* @__PURE__ */ jsxs(
|
|
524
|
+
"button",
|
|
525
|
+
{
|
|
526
|
+
type: "button",
|
|
527
|
+
onClick: () => {
|
|
528
|
+
setEditing(false);
|
|
529
|
+
setMessage(feedback.message);
|
|
530
|
+
setScreenshotId(screenshot?.id ?? null);
|
|
531
|
+
setScreenshotUrl(screenshot?.url ?? null);
|
|
532
|
+
setError(null);
|
|
533
|
+
},
|
|
534
|
+
style: buttonStyle("ghost"),
|
|
535
|
+
children: [
|
|
536
|
+
/* @__PURE__ */ jsx(X, { size: 15 }),
|
|
537
|
+
"Cancel"
|
|
538
|
+
]
|
|
539
|
+
}
|
|
540
|
+
),
|
|
541
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: handleSave, disabled: saving, style: buttonStyle("primary", { disabled: saving }), children: [
|
|
542
|
+
/* @__PURE__ */ jsx(Save, { size: 15 }),
|
|
543
|
+
saving ? "Saving..." : "Save changes"
|
|
544
|
+
] })
|
|
545
|
+
] })
|
|
546
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
547
|
+
/* @__PURE__ */ jsx("div", { style: { ...surfaceCardStyle, padding: "18px" }, children: /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "15px", lineHeight: 1.7, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: feedback.message }) }),
|
|
548
|
+
screenshot ? /* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "12px" }, children: [
|
|
549
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: "8px", marginBottom: "10px" }, children: [
|
|
550
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "Screenshot" }),
|
|
551
|
+
/* @__PURE__ */ jsxs(
|
|
552
|
+
"button",
|
|
553
|
+
{
|
|
554
|
+
type: "button",
|
|
555
|
+
onClick: () => window.open(screenshot.url, "_blank"),
|
|
556
|
+
style: buttonStyle("ghost", { compact: true }),
|
|
557
|
+
children: [
|
|
558
|
+
/* @__PURE__ */ jsx(ExternalLink, { size: 14 }),
|
|
559
|
+
"Open full size"
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
] }),
|
|
564
|
+
/* @__PURE__ */ jsx("div", { style: { ...innerCardStyle, overflow: "hidden" }, children: /* @__PURE__ */ jsx(
|
|
565
|
+
"img",
|
|
566
|
+
{
|
|
567
|
+
src: screenshot.url,
|
|
568
|
+
alt: "Feedback screenshot",
|
|
569
|
+
style: { width: "100%", height: "auto", display: "block", cursor: "pointer" },
|
|
570
|
+
onClick: () => window.open(screenshot.url, "_blank")
|
|
571
|
+
}
|
|
572
|
+
) })
|
|
573
|
+
] }) : null,
|
|
574
|
+
/* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "16px", display: "grid", gap: "12px" }, children: [
|
|
575
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
576
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "Page" }),
|
|
577
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "6px" }, children: [
|
|
578
|
+
/* @__PURE__ */ jsx(MapPin, { size: 15, color: theme.textMuted }),
|
|
579
|
+
/* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, wordBreak: "break-all" }, children: feedback.pagePath })
|
|
580
|
+
] })
|
|
581
|
+
] }),
|
|
582
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
583
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "Created" }),
|
|
584
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "6px" }, children: [
|
|
585
|
+
/* @__PURE__ */ jsx(CalendarClock, { size: 15, color: theme.textMuted }),
|
|
586
|
+
/* @__PURE__ */ jsx("p", { style: metaTextStyle, children: formatDate(feedback.createdAt) })
|
|
587
|
+
] })
|
|
588
|
+
] })
|
|
589
|
+
] }),
|
|
590
|
+
error ? /* @__PURE__ */ jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(248, 113, 113, 0.24)" }, children: /* @__PURE__ */ jsx("p", { style: { ...statusTextStyle, color: "#fecaca" }, children: error }) }) : null
|
|
591
|
+
] })
|
|
592
|
+
] });
|
|
593
|
+
}
|
|
594
|
+
var STATUS_VARIANTS = {
|
|
595
|
+
new: "success",
|
|
596
|
+
triaged: "warning",
|
|
597
|
+
resolved: "muted"
|
|
598
|
+
};
|
|
599
|
+
var STATUS_LABELS = {
|
|
600
|
+
new: "New",
|
|
601
|
+
triaged: "Triaged",
|
|
602
|
+
resolved: "Resolved"
|
|
603
|
+
};
|
|
604
|
+
var formatRelativeTime = (iso) => {
|
|
605
|
+
const now = Date.now();
|
|
606
|
+
const then = new Date(iso).getTime();
|
|
607
|
+
const diff = now - then;
|
|
608
|
+
const minutes = Math.floor(diff / 6e4);
|
|
609
|
+
if (minutes < 1) return "Just now";
|
|
610
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
611
|
+
const hours = Math.floor(minutes / 60);
|
|
612
|
+
if (hours < 24) return `${hours}h ago`;
|
|
613
|
+
const days = Math.floor(hours / 24);
|
|
614
|
+
if (days < 7) return `${days}d ago`;
|
|
615
|
+
const weeks = Math.floor(days / 7);
|
|
616
|
+
if (weeks < 5) return `${weeks}w ago`;
|
|
617
|
+
return new Date(iso).toLocaleDateString();
|
|
618
|
+
};
|
|
619
|
+
var getScreenshotThumb = (item) => {
|
|
620
|
+
if (!item.screenshot || typeof item.screenshot !== "object") return null;
|
|
621
|
+
return item.screenshot.url || null;
|
|
622
|
+
};
|
|
623
|
+
var getCreatorId2 = (createdBy) => {
|
|
624
|
+
if (!createdBy) return null;
|
|
625
|
+
if (typeof createdBy === "object") return createdBy.id;
|
|
626
|
+
return createdBy;
|
|
627
|
+
};
|
|
628
|
+
function FeedbackHistory({
|
|
629
|
+
feedbacks,
|
|
630
|
+
totalPages,
|
|
631
|
+
currentPage,
|
|
632
|
+
loading,
|
|
633
|
+
error,
|
|
634
|
+
currentUserId,
|
|
635
|
+
onSelectFeedback,
|
|
636
|
+
onPageChange,
|
|
637
|
+
onRefetch
|
|
638
|
+
}) {
|
|
639
|
+
if (loading) {
|
|
640
|
+
return /* @__PURE__ */ jsx("div", { style: { display: "grid", gap: "10px" }, children: [1, 2, 3].map((item) => /* @__PURE__ */ jsx(
|
|
641
|
+
"div",
|
|
642
|
+
{
|
|
643
|
+
style: {
|
|
644
|
+
...surfaceCardStyle,
|
|
645
|
+
padding: "14px"
|
|
646
|
+
},
|
|
647
|
+
children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "12px", alignItems: "center" }, children: [
|
|
648
|
+
/* @__PURE__ */ jsx(
|
|
649
|
+
"div",
|
|
650
|
+
{
|
|
651
|
+
style: {
|
|
652
|
+
width: "52px",
|
|
653
|
+
height: "52px",
|
|
654
|
+
borderRadius: "14px",
|
|
655
|
+
background: "rgba(148, 163, 184, 0.14)",
|
|
656
|
+
flexShrink: 0
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
),
|
|
660
|
+
/* @__PURE__ */ jsxs("div", { style: { flex: 1 }, children: [
|
|
661
|
+
/* @__PURE__ */ jsx(
|
|
662
|
+
"div",
|
|
663
|
+
{
|
|
664
|
+
style: {
|
|
665
|
+
height: "14px",
|
|
666
|
+
width: "72%",
|
|
667
|
+
borderRadius: "999px",
|
|
668
|
+
background: "rgba(148, 163, 184, 0.18)",
|
|
669
|
+
marginBottom: "10px"
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
),
|
|
673
|
+
/* @__PURE__ */ jsx(
|
|
674
|
+
"div",
|
|
675
|
+
{
|
|
676
|
+
style: {
|
|
677
|
+
height: "10px",
|
|
678
|
+
width: "48%",
|
|
679
|
+
borderRadius: "999px",
|
|
680
|
+
background: "rgba(148, 163, 184, 0.12)"
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
)
|
|
684
|
+
] })
|
|
685
|
+
] })
|
|
686
|
+
},
|
|
687
|
+
item
|
|
688
|
+
)) });
|
|
689
|
+
}
|
|
690
|
+
if (error) {
|
|
691
|
+
return /* @__PURE__ */ jsxs(
|
|
692
|
+
"div",
|
|
693
|
+
{
|
|
694
|
+
style: {
|
|
695
|
+
...surfaceCardStyle,
|
|
696
|
+
padding: "18px",
|
|
697
|
+
textAlign: "center"
|
|
698
|
+
},
|
|
699
|
+
children: [
|
|
700
|
+
/* @__PURE__ */ jsx("p", { style: { ...statusTextStyle, color: "#fecaca", marginBottom: "12px" }, children: error }),
|
|
701
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: onRefetch, style: buttonStyle("secondary"), children: [
|
|
702
|
+
/* @__PURE__ */ jsx(RefreshCw, { size: 15 }),
|
|
703
|
+
"Retry"
|
|
704
|
+
] })
|
|
705
|
+
]
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
if (feedbacks.length === 0) {
|
|
710
|
+
return /* @__PURE__ */ jsxs(
|
|
711
|
+
"div",
|
|
712
|
+
{
|
|
713
|
+
style: {
|
|
714
|
+
...surfaceCardStyle,
|
|
715
|
+
padding: "26px 18px",
|
|
716
|
+
textAlign: "center"
|
|
717
|
+
},
|
|
718
|
+
children: [
|
|
719
|
+
/* @__PURE__ */ jsx(
|
|
720
|
+
"div",
|
|
721
|
+
{
|
|
722
|
+
style: {
|
|
723
|
+
width: "44px",
|
|
724
|
+
height: "44px",
|
|
725
|
+
borderRadius: "14px",
|
|
726
|
+
margin: "0 auto 12px",
|
|
727
|
+
display: "grid",
|
|
728
|
+
placeItems: "center",
|
|
729
|
+
background: "rgba(94, 234, 212, 0.12)",
|
|
730
|
+
color: theme.accent
|
|
731
|
+
},
|
|
732
|
+
children: /* @__PURE__ */ jsx(MessageSquareText, { size: 20 })
|
|
733
|
+
}
|
|
734
|
+
),
|
|
735
|
+
/* @__PURE__ */ jsx("p", { style: { margin: "0 0 4px", fontSize: "14px", fontWeight: 600 }, children: "No feedback yet" }),
|
|
736
|
+
/* @__PURE__ */ jsx("p", { style: metaTextStyle, children: "New reports will appear here with screenshots, status, and page context." })
|
|
737
|
+
]
|
|
738
|
+
}
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
return /* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: "10px" }, children: [
|
|
742
|
+
feedbacks.map((item) => {
|
|
743
|
+
const thumb = getScreenshotThumb(item);
|
|
744
|
+
const preview = item.message.length > 110 ? `${item.message.slice(0, 110)}...` : item.message;
|
|
745
|
+
const isMine = currentUserId !== null && getCreatorId2(item.createdBy) === currentUserId;
|
|
746
|
+
return /* @__PURE__ */ jsxs(
|
|
747
|
+
"button",
|
|
748
|
+
{
|
|
749
|
+
type: "button",
|
|
750
|
+
onClick: () => onSelectFeedback(item.id),
|
|
751
|
+
style: {
|
|
752
|
+
...surfaceCardStyle,
|
|
753
|
+
display: "flex",
|
|
754
|
+
width: "100%",
|
|
755
|
+
gap: "12px",
|
|
756
|
+
padding: "14px",
|
|
757
|
+
color: theme.text,
|
|
758
|
+
textAlign: "left",
|
|
759
|
+
cursor: "pointer"
|
|
760
|
+
},
|
|
761
|
+
children: [
|
|
762
|
+
/* @__PURE__ */ jsx(
|
|
763
|
+
"div",
|
|
764
|
+
{
|
|
765
|
+
style: {
|
|
766
|
+
...innerCardStyle,
|
|
767
|
+
width: "56px",
|
|
768
|
+
height: "56px",
|
|
769
|
+
overflow: "hidden",
|
|
770
|
+
flexShrink: 0,
|
|
771
|
+
display: "grid",
|
|
772
|
+
placeItems: "center",
|
|
773
|
+
color: theme.textMuted
|
|
774
|
+
},
|
|
775
|
+
children: thumb ? (
|
|
776
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
777
|
+
/* @__PURE__ */ jsx(
|
|
778
|
+
"img",
|
|
779
|
+
{
|
|
780
|
+
src: thumb,
|
|
781
|
+
alt: "",
|
|
782
|
+
style: {
|
|
783
|
+
width: "100%",
|
|
784
|
+
height: "100%",
|
|
785
|
+
objectFit: "cover",
|
|
786
|
+
display: "block"
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
)
|
|
790
|
+
) : /* @__PURE__ */ jsx(ImageIcon, { size: 18 })
|
|
791
|
+
}
|
|
792
|
+
),
|
|
793
|
+
/* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
794
|
+
/* @__PURE__ */ jsxs(
|
|
795
|
+
"div",
|
|
796
|
+
{
|
|
797
|
+
style: {
|
|
798
|
+
display: "flex",
|
|
799
|
+
alignItems: "flex-start",
|
|
800
|
+
gap: "8px",
|
|
801
|
+
justifyContent: "space-between",
|
|
802
|
+
marginBottom: "8px"
|
|
803
|
+
},
|
|
804
|
+
children: [
|
|
805
|
+
/* @__PURE__ */ jsx(
|
|
806
|
+
"p",
|
|
807
|
+
{
|
|
808
|
+
style: {
|
|
809
|
+
margin: 0,
|
|
810
|
+
fontSize: "14px",
|
|
811
|
+
lineHeight: 1.5,
|
|
812
|
+
color: theme.text,
|
|
813
|
+
overflow: "hidden",
|
|
814
|
+
display: "-webkit-box",
|
|
815
|
+
WebkitBoxOrient: "vertical",
|
|
816
|
+
WebkitLineClamp: 2
|
|
817
|
+
},
|
|
818
|
+
children: preview
|
|
819
|
+
}
|
|
820
|
+
),
|
|
821
|
+
/* @__PURE__ */ jsx("span", { style: pillStyle(STATUS_VARIANTS[item.status] || "success"), children: STATUS_LABELS[item.status] || "New" })
|
|
822
|
+
]
|
|
823
|
+
}
|
|
824
|
+
),
|
|
825
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" }, children: [
|
|
826
|
+
/* @__PURE__ */ jsxs("span", { style: pillStyle("neutral"), children: [
|
|
827
|
+
/* @__PURE__ */ jsx(Clock3, { size: 12 }),
|
|
828
|
+
formatRelativeTime(item.createdAt)
|
|
829
|
+
] }),
|
|
830
|
+
/* @__PURE__ */ jsxs("span", { style: pillStyle("neutral"), children: [
|
|
831
|
+
/* @__PURE__ */ jsx(MapPin, { size: 12 }),
|
|
832
|
+
item.pagePath
|
|
833
|
+
] }),
|
|
834
|
+
isMine ? /* @__PURE__ */ jsx("span", { style: pillStyle("success"), children: "Mine" }) : null
|
|
835
|
+
] })
|
|
836
|
+
] })
|
|
837
|
+
]
|
|
838
|
+
},
|
|
839
|
+
item.id
|
|
840
|
+
);
|
|
841
|
+
}),
|
|
842
|
+
totalPages > 1 ? /* @__PURE__ */ jsxs(
|
|
843
|
+
"div",
|
|
844
|
+
{
|
|
845
|
+
style: {
|
|
846
|
+
...surfaceCardStyle,
|
|
847
|
+
padding: "12px",
|
|
848
|
+
display: "flex",
|
|
849
|
+
alignItems: "center",
|
|
850
|
+
justifyContent: "space-between",
|
|
851
|
+
gap: "10px"
|
|
852
|
+
},
|
|
853
|
+
children: [
|
|
854
|
+
/* @__PURE__ */ jsxs(
|
|
855
|
+
"button",
|
|
856
|
+
{
|
|
857
|
+
type: "button",
|
|
858
|
+
disabled: currentPage <= 1,
|
|
859
|
+
onClick: () => onPageChange(currentPage - 1),
|
|
860
|
+
style: buttonStyle("secondary", { compact: true, disabled: currentPage <= 1 }),
|
|
861
|
+
children: [
|
|
862
|
+
/* @__PURE__ */ jsx(ChevronLeft, { size: 15 }),
|
|
863
|
+
"Previous"
|
|
864
|
+
]
|
|
865
|
+
}
|
|
866
|
+
),
|
|
867
|
+
/* @__PURE__ */ jsxs("div", { style: { textAlign: "center" }, children: [
|
|
868
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "Page" }),
|
|
869
|
+
/* @__PURE__ */ jsxs("p", { style: { ...metaTextStyle, marginTop: "2px" }, children: [
|
|
870
|
+
currentPage,
|
|
871
|
+
" of ",
|
|
872
|
+
totalPages
|
|
873
|
+
] })
|
|
874
|
+
] }),
|
|
875
|
+
/* @__PURE__ */ jsxs(
|
|
876
|
+
"button",
|
|
877
|
+
{
|
|
878
|
+
type: "button",
|
|
879
|
+
disabled: currentPage >= totalPages,
|
|
880
|
+
onClick: () => onPageChange(currentPage + 1),
|
|
881
|
+
style: buttonStyle("secondary", { compact: true, disabled: currentPage >= totalPages }),
|
|
882
|
+
children: [
|
|
883
|
+
"Next",
|
|
884
|
+
/* @__PURE__ */ jsx(ChevronRight, { size: 15 })
|
|
885
|
+
]
|
|
886
|
+
}
|
|
887
|
+
)
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
) : null
|
|
891
|
+
] });
|
|
892
|
+
}
|
|
893
|
+
var DEFAULT_COLORS = ["#ef4444", "#f97316", "#eab308", "#22c55e", "#06b6d4", "#3b82f6", "#a855f7"];
|
|
894
|
+
var DEFAULT_HISTORY = {
|
|
895
|
+
operations: [],
|
|
896
|
+
redoStack: [],
|
|
897
|
+
undoStack: []
|
|
898
|
+
};
|
|
899
|
+
var createOperationId = () => `annotation-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
900
|
+
var getCssSelector = (element) => {
|
|
901
|
+
if (element.id) {
|
|
902
|
+
return `#${CSS.escape(element.id)}`;
|
|
903
|
+
}
|
|
904
|
+
const parts = [];
|
|
905
|
+
let current = element;
|
|
906
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && current !== document.body) {
|
|
907
|
+
const tag = current.tagName.toLowerCase();
|
|
908
|
+
if (tag === "body" || tag === "html") {
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
let part = tag;
|
|
912
|
+
const className = current.className;
|
|
913
|
+
if (typeof className === "string") {
|
|
914
|
+
const firstClass = className.split(" ").map((value) => value.trim()).filter(Boolean)[0];
|
|
915
|
+
if (firstClass) {
|
|
916
|
+
part += `.${CSS.escape(firstClass)}`;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
const parent = current.parentElement;
|
|
920
|
+
if (parent) {
|
|
921
|
+
const siblings = Array.from(parent.children).filter(
|
|
922
|
+
(candidate) => candidate.tagName === current?.tagName
|
|
923
|
+
);
|
|
924
|
+
if (siblings.length > 1) {
|
|
925
|
+
const index = siblings.indexOf(current);
|
|
926
|
+
part += `:nth-of-type(${index + 1})`;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
parts.unshift(part);
|
|
930
|
+
current = current.parentElement;
|
|
931
|
+
}
|
|
932
|
+
return parts.join(" > ");
|
|
933
|
+
};
|
|
934
|
+
var fileToDataUrl = async (file) => new Promise((resolve, reject) => {
|
|
935
|
+
const reader = new FileReader();
|
|
936
|
+
reader.onload = () => {
|
|
937
|
+
if (typeof reader.result === "string") {
|
|
938
|
+
resolve(reader.result);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
reject(new Error("Unsupported image format."));
|
|
942
|
+
};
|
|
943
|
+
reader.onerror = () => reject(new Error("Could not read image."));
|
|
944
|
+
reader.readAsDataURL(file);
|
|
945
|
+
});
|
|
946
|
+
var loadImage = async (src) => new Promise((resolve, reject) => {
|
|
947
|
+
const image = new Image();
|
|
948
|
+
image.onload = () => resolve(image);
|
|
949
|
+
image.onerror = () => reject(new Error("Could not load image."));
|
|
950
|
+
image.src = src;
|
|
951
|
+
});
|
|
952
|
+
var createEditorImage = async (file) => {
|
|
953
|
+
const src = await fileToDataUrl(file);
|
|
954
|
+
const element = await loadImage(src);
|
|
955
|
+
return {
|
|
956
|
+
element,
|
|
957
|
+
fileName: file.name,
|
|
958
|
+
height: element.naturalHeight || element.height,
|
|
959
|
+
src,
|
|
960
|
+
width: element.naturalWidth || element.width
|
|
961
|
+
};
|
|
962
|
+
};
|
|
963
|
+
var canvasToFile2 = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
|
|
964
|
+
const blob = await new Promise((resolve) => {
|
|
965
|
+
canvas.toBlob((nextBlob) => resolve(nextBlob), "image/png");
|
|
966
|
+
});
|
|
967
|
+
if (!blob) {
|
|
968
|
+
throw new Error("Failed to prepare annotated screenshot.");
|
|
969
|
+
}
|
|
970
|
+
return new File([blob], fileName.replace(/\.[a-z0-9]+$/i, "") + ".png", { type: "image/png" });
|
|
971
|
+
};
|
|
972
|
+
var waitForRenderedVideoFrame = async (video) => {
|
|
973
|
+
if ("requestVideoFrameCallback" in video) {
|
|
974
|
+
await new Promise((resolve) => {
|
|
975
|
+
video.requestVideoFrameCallback(() => resolve());
|
|
976
|
+
});
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
await new Promise((resolve) => {
|
|
980
|
+
window.requestAnimationFrame(() => resolve());
|
|
981
|
+
});
|
|
982
|
+
};
|
|
983
|
+
var captureScreenshotFile2 = async (capturePolicy) => {
|
|
984
|
+
if (!navigator.mediaDevices?.getDisplayMedia) {
|
|
985
|
+
throw new Error("Browser does not support screen capture.");
|
|
986
|
+
}
|
|
987
|
+
const options = capturePolicy === "any-surface" ? {
|
|
988
|
+
video: true,
|
|
989
|
+
audio: false
|
|
990
|
+
} : {
|
|
991
|
+
video: {
|
|
992
|
+
displaySurface: "browser"
|
|
993
|
+
},
|
|
994
|
+
audio: false,
|
|
995
|
+
preferCurrentTab: true,
|
|
996
|
+
selfBrowserSurface: "include",
|
|
997
|
+
surfaceSwitching: "exclude"
|
|
998
|
+
};
|
|
999
|
+
const stream = await navigator.mediaDevices.getDisplayMedia(options);
|
|
1000
|
+
const track = stream.getVideoTracks()[0];
|
|
1001
|
+
if (!track) {
|
|
1002
|
+
stream.getTracks().forEach((item) => item.stop());
|
|
1003
|
+
throw new Error("Screen capture failed.");
|
|
1004
|
+
}
|
|
1005
|
+
const settings = track.getSettings();
|
|
1006
|
+
const surface = typeof settings.displaySurface === "string" ? settings.displaySurface : null;
|
|
1007
|
+
if (capturePolicy === "strict-current-tab" && surface !== "browser") {
|
|
1008
|
+
stream.getTracks().forEach((item) => item.stop());
|
|
1009
|
+
throw new Error("Please share the current browser tab to capture a screenshot.");
|
|
1010
|
+
}
|
|
1011
|
+
const video = document.createElement("video");
|
|
1012
|
+
try {
|
|
1013
|
+
video.srcObject = stream;
|
|
1014
|
+
video.muted = true;
|
|
1015
|
+
video.playsInline = true;
|
|
1016
|
+
await video.play();
|
|
1017
|
+
await waitForRenderedVideoFrame(video);
|
|
1018
|
+
const width = video.videoWidth || window.innerWidth;
|
|
1019
|
+
const height = video.videoHeight || window.innerHeight;
|
|
1020
|
+
if (!width || !height) {
|
|
1021
|
+
throw new Error("Screen capture failed.");
|
|
1022
|
+
}
|
|
1023
|
+
const canvas = document.createElement("canvas");
|
|
1024
|
+
canvas.width = width;
|
|
1025
|
+
canvas.height = height;
|
|
1026
|
+
const context = canvas.getContext("2d");
|
|
1027
|
+
if (!context) {
|
|
1028
|
+
throw new Error("Browser does not support canvas context.");
|
|
1029
|
+
}
|
|
1030
|
+
context.drawImage(video, 0, 0, width, height);
|
|
1031
|
+
return {
|
|
1032
|
+
file: await canvasToFile2(canvas),
|
|
1033
|
+
surface
|
|
1034
|
+
};
|
|
1035
|
+
} finally {
|
|
1036
|
+
video.pause();
|
|
1037
|
+
video.srcObject = null;
|
|
1038
|
+
stream.getTracks().forEach((item) => item.stop());
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
var getCanvasPoint = (event, canvas) => {
|
|
1042
|
+
const bounds = canvas.getBoundingClientRect();
|
|
1043
|
+
const scaleX = bounds.width === 0 ? 1 : canvas.width / bounds.width;
|
|
1044
|
+
const scaleY = bounds.height === 0 ? 1 : canvas.height / bounds.height;
|
|
1045
|
+
return {
|
|
1046
|
+
x: (event.clientX - bounds.left) * scaleX,
|
|
1047
|
+
y: (event.clientY - bounds.top) * scaleY
|
|
1048
|
+
};
|
|
1049
|
+
};
|
|
1050
|
+
var drawPenOperation = (context, operation) => {
|
|
1051
|
+
if (operation.points.length === 0) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
context.save();
|
|
1055
|
+
context.strokeStyle = operation.style.color;
|
|
1056
|
+
context.lineWidth = operation.style.size;
|
|
1057
|
+
context.lineCap = "round";
|
|
1058
|
+
context.lineJoin = "round";
|
|
1059
|
+
context.beginPath();
|
|
1060
|
+
context.moveTo(operation.points[0].x, operation.points[0].y);
|
|
1061
|
+
for (const point of operation.points.slice(1)) {
|
|
1062
|
+
context.lineTo(point.x, point.y);
|
|
1063
|
+
}
|
|
1064
|
+
if (operation.points.length === 1) {
|
|
1065
|
+
const point = operation.points[0];
|
|
1066
|
+
context.lineTo(point.x + 0.01, point.y + 0.01);
|
|
1067
|
+
}
|
|
1068
|
+
context.stroke();
|
|
1069
|
+
context.restore();
|
|
1070
|
+
};
|
|
1071
|
+
var drawRectangleOperation = (context, operation) => {
|
|
1072
|
+
const left = Math.min(operation.start.x, operation.end.x);
|
|
1073
|
+
const top = Math.min(operation.start.y, operation.end.y);
|
|
1074
|
+
const width = Math.abs(operation.end.x - operation.start.x);
|
|
1075
|
+
const height = Math.abs(operation.end.y - operation.start.y);
|
|
1076
|
+
context.save();
|
|
1077
|
+
context.strokeStyle = operation.style.color;
|
|
1078
|
+
context.lineWidth = operation.style.size;
|
|
1079
|
+
context.strokeRect(left, top, width, height);
|
|
1080
|
+
context.restore();
|
|
1081
|
+
};
|
|
1082
|
+
var drawArrowOperation = (context, operation) => {
|
|
1083
|
+
const angle = Math.atan2(operation.end.y - operation.start.y, operation.end.x - operation.start.x);
|
|
1084
|
+
const headLength = Math.max(14, operation.style.size * 4);
|
|
1085
|
+
context.save();
|
|
1086
|
+
context.strokeStyle = operation.style.color;
|
|
1087
|
+
context.fillStyle = operation.style.color;
|
|
1088
|
+
context.lineWidth = operation.style.size;
|
|
1089
|
+
context.lineCap = "round";
|
|
1090
|
+
context.lineJoin = "round";
|
|
1091
|
+
context.beginPath();
|
|
1092
|
+
context.moveTo(operation.start.x, operation.start.y);
|
|
1093
|
+
context.lineTo(operation.end.x, operation.end.y);
|
|
1094
|
+
context.stroke();
|
|
1095
|
+
context.beginPath();
|
|
1096
|
+
context.moveTo(operation.end.x, operation.end.y);
|
|
1097
|
+
context.lineTo(
|
|
1098
|
+
operation.end.x - headLength * Math.cos(angle - Math.PI / 6),
|
|
1099
|
+
operation.end.y - headLength * Math.sin(angle - Math.PI / 6)
|
|
1100
|
+
);
|
|
1101
|
+
context.lineTo(
|
|
1102
|
+
operation.end.x - headLength * Math.cos(angle + Math.PI / 6),
|
|
1103
|
+
operation.end.y - headLength * Math.sin(angle + Math.PI / 6)
|
|
1104
|
+
);
|
|
1105
|
+
context.closePath();
|
|
1106
|
+
context.fill();
|
|
1107
|
+
context.restore();
|
|
1108
|
+
};
|
|
1109
|
+
var drawTextOperation = (context, operation) => {
|
|
1110
|
+
const fontSize = Math.max(16, operation.style.size * 6);
|
|
1111
|
+
context.save();
|
|
1112
|
+
context.fillStyle = operation.style.color;
|
|
1113
|
+
context.font = `600 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
|
|
1114
|
+
context.textBaseline = "top";
|
|
1115
|
+
context.fillText(operation.text, operation.point.x, operation.point.y);
|
|
1116
|
+
context.restore();
|
|
1117
|
+
};
|
|
1118
|
+
var drawOperation = (context, operation) => {
|
|
1119
|
+
switch (operation.type) {
|
|
1120
|
+
case "pen":
|
|
1121
|
+
drawPenOperation(context, operation);
|
|
1122
|
+
return;
|
|
1123
|
+
case "rectangle":
|
|
1124
|
+
drawRectangleOperation(context, operation);
|
|
1125
|
+
return;
|
|
1126
|
+
case "arrow":
|
|
1127
|
+
drawArrowOperation(context, operation);
|
|
1128
|
+
return;
|
|
1129
|
+
case "text":
|
|
1130
|
+
drawTextOperation(context, operation);
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
var isShapeMeaningful = (start, end) => Math.abs(end.x - start.x) > 3 || Math.abs(end.y - start.y) > 3;
|
|
1135
|
+
function FeedbackWidget({
|
|
1136
|
+
title = "Admin feedback",
|
|
1137
|
+
submitLabel = "Send",
|
|
1138
|
+
uploadLabel = "Upload image",
|
|
1139
|
+
allowScreenshotUpload = true,
|
|
1140
|
+
screenshotMaxFileSizeBytes = 5 * 1024 * 1024,
|
|
1141
|
+
screenshotAllowedMimeTypes = ["image/png", "image/jpeg", "image/webp"],
|
|
1142
|
+
capturePolicy = "current-tab-first",
|
|
1143
|
+
onSubmit,
|
|
1144
|
+
onUpload,
|
|
1145
|
+
onDeleteScreenshot,
|
|
1146
|
+
onDeleteFeedback,
|
|
1147
|
+
showHistory,
|
|
1148
|
+
currentUserId,
|
|
1149
|
+
onUpdateFeedback,
|
|
1150
|
+
history
|
|
1151
|
+
}) {
|
|
1152
|
+
const [open, setOpen] = React2.useState(false);
|
|
1153
|
+
const [view, setView] = React2.useState("form");
|
|
1154
|
+
const [selectedFeedback, setSelectedFeedback] = React2.useState(null);
|
|
1155
|
+
const [message, setMessage] = React2.useState("");
|
|
1156
|
+
const [captureMode, setCaptureMode] = React2.useState(false);
|
|
1157
|
+
const [captureData, setCaptureData] = React2.useState(null);
|
|
1158
|
+
const [screenshotId, setScreenshotId] = React2.useState(null);
|
|
1159
|
+
const [screenshotPreviewUrl, setScreenshotPreviewUrl] = React2.useState(null);
|
|
1160
|
+
const [uploading, setUploading] = React2.useState(false);
|
|
1161
|
+
const [deletingScreenshot, setDeletingScreenshot] = React2.useState(false);
|
|
1162
|
+
const [submitting, setSubmitting] = React2.useState(false);
|
|
1163
|
+
const [error, setError] = React2.useState(null);
|
|
1164
|
+
const [notice, setNotice] = React2.useState(null);
|
|
1165
|
+
const [annotating, setAnnotating] = React2.useState(false);
|
|
1166
|
+
const [editorImage, setEditorImage] = React2.useState(null);
|
|
1167
|
+
const [editorHistory, setEditorHistory] = React2.useState(DEFAULT_HISTORY);
|
|
1168
|
+
const [draftOperation, setDraftOperation] = React2.useState(null);
|
|
1169
|
+
const [annotationTool, setAnnotationTool] = React2.useState("pen");
|
|
1170
|
+
const [annotationColor, setAnnotationColor] = React2.useState(DEFAULT_COLORS[0]);
|
|
1171
|
+
const [annotationSize, setAnnotationSize] = React2.useState(4);
|
|
1172
|
+
const [annotationText, setAnnotationText] = React2.useState("");
|
|
1173
|
+
const hoverTargetRef = React2.useRef(null);
|
|
1174
|
+
const annotationCanvasRef = React2.useRef(null);
|
|
1175
|
+
const pointerIdRef = React2.useRef(null);
|
|
1176
|
+
const draftOperationRef = React2.useRef(null);
|
|
1177
|
+
React2.useEffect(() => {
|
|
1178
|
+
draftOperationRef.current = draftOperation;
|
|
1179
|
+
}, [draftOperation]);
|
|
1180
|
+
React2.useEffect(() => {
|
|
1181
|
+
if (!captureMode) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
const clearOutline = () => {
|
|
1185
|
+
if (hoverTargetRef.current instanceof HTMLElement) {
|
|
1186
|
+
hoverTargetRef.current.style.outline = "";
|
|
1187
|
+
}
|
|
1188
|
+
hoverTargetRef.current = null;
|
|
1189
|
+
};
|
|
1190
|
+
const onMouseMove = (event) => {
|
|
1191
|
+
const target = event.target;
|
|
1192
|
+
if (!(target instanceof HTMLElement)) {
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (hoverTargetRef.current !== target) {
|
|
1196
|
+
clearOutline();
|
|
1197
|
+
target.style.outline = "2px dashed #22c55e";
|
|
1198
|
+
hoverTargetRef.current = target;
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
const onClick = (event) => {
|
|
1202
|
+
event.preventDefault();
|
|
1203
|
+
event.stopPropagation();
|
|
1204
|
+
const target = event.target;
|
|
1205
|
+
if (!(target instanceof HTMLElement)) {
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
setCaptureData({
|
|
1209
|
+
selector: getCssSelector(target),
|
|
1210
|
+
selectedText: target.textContent?.trim().slice(0, 200) || ""
|
|
1211
|
+
});
|
|
1212
|
+
clearOutline();
|
|
1213
|
+
setCaptureMode(false);
|
|
1214
|
+
};
|
|
1215
|
+
document.addEventListener("mousemove", onMouseMove, true);
|
|
1216
|
+
document.addEventListener("click", onClick, true);
|
|
1217
|
+
return () => {
|
|
1218
|
+
clearOutline();
|
|
1219
|
+
document.removeEventListener("mousemove", onMouseMove, true);
|
|
1220
|
+
document.removeEventListener("click", onClick, true);
|
|
1221
|
+
};
|
|
1222
|
+
}, [captureMode]);
|
|
1223
|
+
React2.useEffect(() => {
|
|
1224
|
+
if (!annotating) {
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
const previousOverflow = document.body.style.overflow;
|
|
1228
|
+
document.body.style.overflow = "hidden";
|
|
1229
|
+
return () => {
|
|
1230
|
+
document.body.style.overflow = previousOverflow;
|
|
1231
|
+
};
|
|
1232
|
+
}, [annotating]);
|
|
1233
|
+
React2.useEffect(() => {
|
|
1234
|
+
if (!annotating || !editorImage || !annotationCanvasRef.current) {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
const canvas = annotationCanvasRef.current;
|
|
1238
|
+
canvas.width = editorImage.width;
|
|
1239
|
+
canvas.height = editorImage.height;
|
|
1240
|
+
const context = canvas.getContext("2d");
|
|
1241
|
+
if (!context) {
|
|
1242
|
+
setError("Browser does not support canvas context.");
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
1246
|
+
context.drawImage(editorImage.element, 0, 0, canvas.width, canvas.height);
|
|
1247
|
+
for (const operation of editorHistory.operations) {
|
|
1248
|
+
drawOperation(context, operation);
|
|
1249
|
+
}
|
|
1250
|
+
if (draftOperation) {
|
|
1251
|
+
drawOperation(context, draftOperation);
|
|
1252
|
+
}
|
|
1253
|
+
}, [annotating, draftOperation, editorHistory.operations, editorImage]);
|
|
1254
|
+
const validateImageFile = React2.useCallback(
|
|
1255
|
+
(file) => {
|
|
1256
|
+
if (!screenshotAllowedMimeTypes.includes(file.type)) {
|
|
1257
|
+
return `Supported image types: ${screenshotAllowedMimeTypes.join(", ")}`;
|
|
1258
|
+
}
|
|
1259
|
+
if (file.size > screenshotMaxFileSizeBytes) {
|
|
1260
|
+
return `Image is too large. Maximum size: ${Math.round(screenshotMaxFileSizeBytes / 1024 / 1024)}MB.`;
|
|
1261
|
+
}
|
|
1262
|
+
return null;
|
|
1263
|
+
},
|
|
1264
|
+
[screenshotAllowedMimeTypes, screenshotMaxFileSizeBytes]
|
|
1265
|
+
);
|
|
1266
|
+
const uploadImageFile = React2.useCallback(
|
|
1267
|
+
async (file) => {
|
|
1268
|
+
if (!onUpload) {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
setError(null);
|
|
1272
|
+
setUploading(true);
|
|
1273
|
+
try {
|
|
1274
|
+
const formData = new FormData();
|
|
1275
|
+
formData.append("file", file);
|
|
1276
|
+
formData.append("alt", file.name);
|
|
1277
|
+
const result = await onUpload(formData);
|
|
1278
|
+
if (result.success) {
|
|
1279
|
+
setScreenshotId(result.mediaId);
|
|
1280
|
+
setNotice("Annotated screenshot uploaded.");
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
setError(result.error);
|
|
1284
|
+
return false;
|
|
1285
|
+
} finally {
|
|
1286
|
+
setUploading(false);
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
[onUpload]
|
|
1290
|
+
);
|
|
1291
|
+
const closeAnnotationEditor = React2.useCallback(() => {
|
|
1292
|
+
setAnnotating(false);
|
|
1293
|
+
setEditorImage(null);
|
|
1294
|
+
setEditorHistory(DEFAULT_HISTORY);
|
|
1295
|
+
setDraftOperation(null);
|
|
1296
|
+
draftOperationRef.current = null;
|
|
1297
|
+
}, []);
|
|
1298
|
+
const handleStartAnnotation = React2.useCallback(
|
|
1299
|
+
async (file) => {
|
|
1300
|
+
const validationError = validateImageFile(file);
|
|
1301
|
+
if (validationError) {
|
|
1302
|
+
setError(validationError);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
try {
|
|
1306
|
+
const nextImage = await createEditorImage(file);
|
|
1307
|
+
setEditorImage(nextImage);
|
|
1308
|
+
setEditorHistory(DEFAULT_HISTORY);
|
|
1309
|
+
setDraftOperation(null);
|
|
1310
|
+
draftOperationRef.current = null;
|
|
1311
|
+
setAnnotating(true);
|
|
1312
|
+
setError(null);
|
|
1313
|
+
} catch (nextError) {
|
|
1314
|
+
setError(nextError instanceof Error ? nextError.message : "Failed to process image.");
|
|
1315
|
+
}
|
|
1316
|
+
},
|
|
1317
|
+
[validateImageFile]
|
|
1318
|
+
);
|
|
1319
|
+
React2.useEffect(() => {
|
|
1320
|
+
if (!open || !allowScreenshotUpload) {
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
const onPaste = async (event) => {
|
|
1324
|
+
const file = Array.from(event.clipboardData?.items || []).find((item) => item.type.startsWith("image/"))?.getAsFile();
|
|
1325
|
+
if (!file) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
event.preventDefault();
|
|
1329
|
+
await handleStartAnnotation(file);
|
|
1330
|
+
};
|
|
1331
|
+
window.addEventListener("paste", onPaste);
|
|
1332
|
+
return () => window.removeEventListener("paste", onPaste);
|
|
1333
|
+
}, [allowScreenshotUpload, handleStartAnnotation, open]);
|
|
1334
|
+
const handleSelectFeedback = React2.useCallback(
|
|
1335
|
+
async (id) => {
|
|
1336
|
+
const found = history?.feedbacks.find((f) => f.id === id);
|
|
1337
|
+
if (found) {
|
|
1338
|
+
setSelectedFeedback(found);
|
|
1339
|
+
setView("detail");
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
try {
|
|
1343
|
+
const res = await fetch(`/api/admin-feedback/${id}?depth=2`, { credentials: "include" });
|
|
1344
|
+
if (res.ok) {
|
|
1345
|
+
const data = await res.json();
|
|
1346
|
+
setSelectedFeedback(data);
|
|
1347
|
+
setView("detail");
|
|
1348
|
+
}
|
|
1349
|
+
} catch {
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
[history?.feedbacks]
|
|
1353
|
+
);
|
|
1354
|
+
React2.useEffect(() => {
|
|
1355
|
+
const handler = (e) => {
|
|
1356
|
+
const detail = e.detail;
|
|
1357
|
+
if (detail?.feedbackId) {
|
|
1358
|
+
setOpen(true);
|
|
1359
|
+
handleSelectFeedback(detail.feedbackId);
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
window.addEventListener("feedback:show-detail", handler);
|
|
1363
|
+
return () => window.removeEventListener("feedback:show-detail", handler);
|
|
1364
|
+
}, [handleSelectFeedback]);
|
|
1365
|
+
const commitOperations = React2.useCallback((nextOperations) => {
|
|
1366
|
+
setEditorHistory((current) => ({
|
|
1367
|
+
operations: nextOperations,
|
|
1368
|
+
redoStack: [],
|
|
1369
|
+
undoStack: [...current.undoStack, current.operations]
|
|
1370
|
+
}));
|
|
1371
|
+
}, []);
|
|
1372
|
+
const appendOperation = React2.useCallback((operation) => {
|
|
1373
|
+
setEditorHistory((current) => ({
|
|
1374
|
+
operations: [...current.operations, operation],
|
|
1375
|
+
redoStack: [],
|
|
1376
|
+
undoStack: [...current.undoStack, current.operations]
|
|
1377
|
+
}));
|
|
1378
|
+
}, []);
|
|
1379
|
+
const handleUpload = async (event) => {
|
|
1380
|
+
const file = event.target.files?.[0];
|
|
1381
|
+
if (file) {
|
|
1382
|
+
await handleStartAnnotation(file);
|
|
1383
|
+
}
|
|
1384
|
+
event.target.value = "";
|
|
1385
|
+
};
|
|
1386
|
+
const handleCaptureScreenshot = async () => {
|
|
1387
|
+
try {
|
|
1388
|
+
setError(null);
|
|
1389
|
+
const { file, surface } = await captureScreenshotFile2(capturePolicy);
|
|
1390
|
+
if (capturePolicy === "current-tab-first") {
|
|
1391
|
+
if (surface === "browser") {
|
|
1392
|
+
setNotice("Captured the current tab.");
|
|
1393
|
+
} else if (surface) {
|
|
1394
|
+
setNotice(`Captured a ${surface} surface because the browser allowed a broader selection.`);
|
|
1395
|
+
} else {
|
|
1396
|
+
setNotice("Captured a screenshot.");
|
|
1397
|
+
}
|
|
1398
|
+
} else if (capturePolicy === "strict-current-tab") {
|
|
1399
|
+
setNotice("Captured the current tab.");
|
|
1400
|
+
} else {
|
|
1401
|
+
setNotice("Captured a screenshot.");
|
|
1402
|
+
}
|
|
1403
|
+
await handleStartAnnotation(file);
|
|
1404
|
+
} catch (nextError) {
|
|
1405
|
+
setError(nextError instanceof Error ? nextError.message : "Screen capture failed.");
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
const handleUndo = () => {
|
|
1409
|
+
setEditorHistory((current) => {
|
|
1410
|
+
if (current.undoStack.length === 0) {
|
|
1411
|
+
return current;
|
|
1412
|
+
}
|
|
1413
|
+
const previousOperations = current.undoStack[current.undoStack.length - 1];
|
|
1414
|
+
return {
|
|
1415
|
+
operations: previousOperations,
|
|
1416
|
+
redoStack: [current.operations, ...current.redoStack],
|
|
1417
|
+
undoStack: current.undoStack.slice(0, -1)
|
|
1418
|
+
};
|
|
1419
|
+
});
|
|
1420
|
+
};
|
|
1421
|
+
const handleRedo = () => {
|
|
1422
|
+
setEditorHistory((current) => {
|
|
1423
|
+
if (current.redoStack.length === 0) {
|
|
1424
|
+
return current;
|
|
1425
|
+
}
|
|
1426
|
+
const [nextOperations, ...remainingRedo] = current.redoStack;
|
|
1427
|
+
return {
|
|
1428
|
+
operations: nextOperations,
|
|
1429
|
+
redoStack: remainingRedo,
|
|
1430
|
+
undoStack: [...current.undoStack, current.operations]
|
|
1431
|
+
};
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
const handleClearAnnotations = () => {
|
|
1435
|
+
if (editorHistory.operations.length === 0) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
commitOperations([]);
|
|
1439
|
+
};
|
|
1440
|
+
const handleRevertLastAnnotation = () => {
|
|
1441
|
+
setDraftOperation(null);
|
|
1442
|
+
draftOperationRef.current = null;
|
|
1443
|
+
pointerIdRef.current = null;
|
|
1444
|
+
setEditorHistory((current) => {
|
|
1445
|
+
if (current.operations.length === 0) {
|
|
1446
|
+
return current;
|
|
1447
|
+
}
|
|
1448
|
+
return {
|
|
1449
|
+
operations: current.operations.slice(0, -1),
|
|
1450
|
+
redoStack: [],
|
|
1451
|
+
undoStack: [...current.undoStack, current.operations]
|
|
1452
|
+
};
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
const handleCanvasPointerDown = (event) => {
|
|
1456
|
+
if (!annotationCanvasRef.current) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
setError(null);
|
|
1460
|
+
const canvas = annotationCanvasRef.current;
|
|
1461
|
+
const point = getCanvasPoint(event, canvas);
|
|
1462
|
+
if (annotationTool === "text") {
|
|
1463
|
+
const text = annotationText.trim();
|
|
1464
|
+
if (!text) {
|
|
1465
|
+
setError("Enter text before placing it on the image.");
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
const operation = {
|
|
1469
|
+
id: createOperationId(),
|
|
1470
|
+
type: "text",
|
|
1471
|
+
style: { color: annotationColor, size: annotationSize },
|
|
1472
|
+
point,
|
|
1473
|
+
text
|
|
1474
|
+
};
|
|
1475
|
+
appendOperation(operation);
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
event.preventDefault();
|
|
1479
|
+
canvas.setPointerCapture(event.pointerId);
|
|
1480
|
+
pointerIdRef.current = event.pointerId;
|
|
1481
|
+
const style = { color: annotationColor, size: annotationSize };
|
|
1482
|
+
const nextDraft = annotationTool === "pen" ? {
|
|
1483
|
+
id: createOperationId(),
|
|
1484
|
+
type: "pen",
|
|
1485
|
+
style,
|
|
1486
|
+
points: [point]
|
|
1487
|
+
} : annotationTool === "rectangle" ? {
|
|
1488
|
+
id: createOperationId(),
|
|
1489
|
+
type: "rectangle",
|
|
1490
|
+
style,
|
|
1491
|
+
start: point,
|
|
1492
|
+
end: point
|
|
1493
|
+
} : {
|
|
1494
|
+
id: createOperationId(),
|
|
1495
|
+
type: "arrow",
|
|
1496
|
+
style,
|
|
1497
|
+
start: point,
|
|
1498
|
+
end: point
|
|
1499
|
+
};
|
|
1500
|
+
draftOperationRef.current = nextDraft;
|
|
1501
|
+
setDraftOperation(nextDraft);
|
|
1502
|
+
};
|
|
1503
|
+
const handleCanvasPointerMove = (event) => {
|
|
1504
|
+
if (!annotationCanvasRef.current || pointerIdRef.current !== event.pointerId) {
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
const activeDraft = draftOperationRef.current;
|
|
1508
|
+
if (!activeDraft) {
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
const point = getCanvasPoint(event, annotationCanvasRef.current);
|
|
1512
|
+
const nextDraft = activeDraft.type === "pen" ? {
|
|
1513
|
+
...activeDraft,
|
|
1514
|
+
points: [...activeDraft.points, point]
|
|
1515
|
+
} : {
|
|
1516
|
+
...activeDraft,
|
|
1517
|
+
end: point
|
|
1518
|
+
};
|
|
1519
|
+
draftOperationRef.current = nextDraft;
|
|
1520
|
+
setDraftOperation(nextDraft);
|
|
1521
|
+
};
|
|
1522
|
+
const handleCanvasPointerUp = (event) => {
|
|
1523
|
+
if (!annotationCanvasRef.current || pointerIdRef.current !== event.pointerId) {
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
const canvas = annotationCanvasRef.current;
|
|
1527
|
+
if (canvas.hasPointerCapture(event.pointerId)) {
|
|
1528
|
+
canvas.releasePointerCapture(event.pointerId);
|
|
1529
|
+
}
|
|
1530
|
+
pointerIdRef.current = null;
|
|
1531
|
+
const activeDraft = draftOperationRef.current;
|
|
1532
|
+
draftOperationRef.current = null;
|
|
1533
|
+
setDraftOperation(null);
|
|
1534
|
+
if (!activeDraft) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
if (activeDraft.type === "pen") {
|
|
1538
|
+
const points = activeDraft.points.length === 1 ? [...activeDraft.points, activeDraft.points[0]] : activeDraft.points;
|
|
1539
|
+
appendOperation({ ...activeDraft, points });
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
if (!isShapeMeaningful(activeDraft.start, activeDraft.end)) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
appendOperation(activeDraft);
|
|
1546
|
+
};
|
|
1547
|
+
const handleCanvasPointerCancel = (event) => {
|
|
1548
|
+
if (annotationCanvasRef.current && pointerIdRef.current === event.pointerId && annotationCanvasRef.current.hasPointerCapture(event.pointerId)) {
|
|
1549
|
+
annotationCanvasRef.current.releasePointerCapture(event.pointerId);
|
|
1550
|
+
}
|
|
1551
|
+
pointerIdRef.current = null;
|
|
1552
|
+
draftOperationRef.current = null;
|
|
1553
|
+
setDraftOperation(null);
|
|
1554
|
+
};
|
|
1555
|
+
const handleApplyAnnotation = async () => {
|
|
1556
|
+
if (!annotationCanvasRef.current || !editorImage) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
try {
|
|
1560
|
+
const previewUrl = annotationCanvasRef.current.toDataURL("image/png");
|
|
1561
|
+
const file = await canvasToFile2(annotationCanvasRef.current, editorImage.fileName);
|
|
1562
|
+
const uploaded = await uploadImageFile(file);
|
|
1563
|
+
if (uploaded) {
|
|
1564
|
+
setScreenshotPreviewUrl(previewUrl);
|
|
1565
|
+
closeAnnotationEditor();
|
|
1566
|
+
}
|
|
1567
|
+
} catch (nextError) {
|
|
1568
|
+
setError(nextError instanceof Error ? nextError.message : "Failed to export image.");
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
const handleRemoveScreenshot = async () => {
|
|
1572
|
+
if (!screenshotId) {
|
|
1573
|
+
setScreenshotPreviewUrl(null);
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
if (!onDeleteScreenshot) {
|
|
1577
|
+
setScreenshotId(null);
|
|
1578
|
+
setScreenshotPreviewUrl(null);
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
setDeletingScreenshot(true);
|
|
1582
|
+
setError(null);
|
|
1583
|
+
try {
|
|
1584
|
+
const result = await onDeleteScreenshot(screenshotId);
|
|
1585
|
+
if (!result.success) {
|
|
1586
|
+
setError(result.error);
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
setScreenshotId(null);
|
|
1590
|
+
setScreenshotPreviewUrl(null);
|
|
1591
|
+
setNotice("Screenshot removed.");
|
|
1592
|
+
} finally {
|
|
1593
|
+
setDeletingScreenshot(false);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
const handleSubmit = async () => {
|
|
1597
|
+
if (!message.trim()) {
|
|
1598
|
+
setError("Please enter a message.");
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
setSubmitting(true);
|
|
1602
|
+
setError(null);
|
|
1603
|
+
const result = await onSubmit({
|
|
1604
|
+
message: message.trim(),
|
|
1605
|
+
pagePath: typeof window !== "undefined" ? window.location.pathname : "/",
|
|
1606
|
+
selector: captureData?.selector,
|
|
1607
|
+
selectedText: captureData?.selectedText,
|
|
1608
|
+
screenshotId,
|
|
1609
|
+
meta: {
|
|
1610
|
+
userAgent: window.navigator.userAgent,
|
|
1611
|
+
locale: window.navigator.language,
|
|
1612
|
+
viewport: `${window.innerWidth}x${window.innerHeight}`
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
setSubmitting(false);
|
|
1616
|
+
if (!result.success) {
|
|
1617
|
+
setError(result.error);
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
setMessage("");
|
|
1621
|
+
setCaptureData(null);
|
|
1622
|
+
setScreenshotId(null);
|
|
1623
|
+
setScreenshotPreviewUrl(null);
|
|
1624
|
+
setNotice(null);
|
|
1625
|
+
setView("form");
|
|
1626
|
+
setOpen(false);
|
|
1627
|
+
};
|
|
1628
|
+
const currentHasUndo = editorHistory.undoStack.length > 0;
|
|
1629
|
+
const currentHasRedo = editorHistory.redoStack.length > 0;
|
|
1630
|
+
const hasAnnotations = editorHistory.operations.length > 0;
|
|
1631
|
+
const currentPath = typeof window !== "undefined" ? window.location.pathname : "/";
|
|
1632
|
+
const canManageScreenshots = allowScreenshotUpload && onUpload;
|
|
1633
|
+
const annotationTools = [
|
|
1634
|
+
{ tool: "pen", label: "Pen", icon: PenTool },
|
|
1635
|
+
{ tool: "rectangle", label: "Box", icon: Square },
|
|
1636
|
+
{ tool: "arrow", label: "Arrow", icon: ArrowRight },
|
|
1637
|
+
{ tool: "text", label: "Text", icon: Type }
|
|
1638
|
+
];
|
|
1639
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1640
|
+
/* @__PURE__ */ jsxs(
|
|
1641
|
+
"button",
|
|
1642
|
+
{
|
|
1643
|
+
type: "button",
|
|
1644
|
+
onClick: () => {
|
|
1645
|
+
setOpen((value) => !value);
|
|
1646
|
+
if (!open) setView("form");
|
|
1647
|
+
},
|
|
1648
|
+
style: floatingLauncherStyle,
|
|
1649
|
+
children: [
|
|
1650
|
+
/* @__PURE__ */ jsx(MessageSquarePlus, { size: 18 }),
|
|
1651
|
+
"Feedback"
|
|
1652
|
+
]
|
|
1653
|
+
}
|
|
1654
|
+
),
|
|
1655
|
+
open ? /* @__PURE__ */ jsxs("div", { style: panelStyle, children: [
|
|
1656
|
+
/* @__PURE__ */ jsxs("div", { style: panelHeaderStyle, children: [
|
|
1657
|
+
/* @__PURE__ */ jsxs(
|
|
1658
|
+
"div",
|
|
1659
|
+
{
|
|
1660
|
+
style: {
|
|
1661
|
+
display: "flex",
|
|
1662
|
+
alignItems: "flex-start",
|
|
1663
|
+
justifyContent: "space-between",
|
|
1664
|
+
gap: "12px",
|
|
1665
|
+
marginBottom: showHistory ? "14px" : 0
|
|
1666
|
+
},
|
|
1667
|
+
children: [
|
|
1668
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1669
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginBottom: "8px" }, children: /* @__PURE__ */ jsxs("span", { style: pillStyle("success"), children: [
|
|
1670
|
+
/* @__PURE__ */ jsx(Sparkles, { size: 12 }),
|
|
1671
|
+
"Feedback"
|
|
1672
|
+
] }) }),
|
|
1673
|
+
/* @__PURE__ */ jsx("h3", { style: { margin: 0, fontSize: "16px", lineHeight: 1.2, letterSpacing: "-0.02em" }, children: title }),
|
|
1674
|
+
/* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, marginTop: "6px" }, children: "Collect issues, context, and screenshots without leaving the current page." })
|
|
1675
|
+
] }),
|
|
1676
|
+
/* @__PURE__ */ jsx(
|
|
1677
|
+
"button",
|
|
1678
|
+
{
|
|
1679
|
+
type: "button",
|
|
1680
|
+
onClick: () => {
|
|
1681
|
+
setOpen(false);
|
|
1682
|
+
setCaptureMode(false);
|
|
1683
|
+
},
|
|
1684
|
+
"aria-label": "Close feedback panel",
|
|
1685
|
+
style: buttonStyle("ghost", { compact: true, iconOnly: true }),
|
|
1686
|
+
children: /* @__PURE__ */ jsx(X, { size: 16 })
|
|
1687
|
+
}
|
|
1688
|
+
)
|
|
1689
|
+
]
|
|
1690
|
+
}
|
|
1691
|
+
),
|
|
1692
|
+
showHistory ? /* @__PURE__ */ jsxs(
|
|
1693
|
+
"div",
|
|
1694
|
+
{
|
|
1695
|
+
style: {
|
|
1696
|
+
...surfaceCardStyle,
|
|
1697
|
+
padding: "5px",
|
|
1698
|
+
display: "flex",
|
|
1699
|
+
gap: "6px"
|
|
1700
|
+
},
|
|
1701
|
+
children: [
|
|
1702
|
+
/* @__PURE__ */ jsxs(
|
|
1703
|
+
"button",
|
|
1704
|
+
{
|
|
1705
|
+
type: "button",
|
|
1706
|
+
onClick: () => setView("form"),
|
|
1707
|
+
style: { ...buttonStyle("secondary", { active: view === "form", compact: true }), flex: 1 },
|
|
1708
|
+
children: [
|
|
1709
|
+
/* @__PURE__ */ jsx(MessageSquare, { size: 15 }),
|
|
1710
|
+
"New"
|
|
1711
|
+
]
|
|
1712
|
+
}
|
|
1713
|
+
),
|
|
1714
|
+
/* @__PURE__ */ jsxs(
|
|
1715
|
+
"button",
|
|
1716
|
+
{
|
|
1717
|
+
type: "button",
|
|
1718
|
+
onClick: () => setView("history"),
|
|
1719
|
+
style: {
|
|
1720
|
+
...buttonStyle("secondary", {
|
|
1721
|
+
active: view === "history" || view === "detail",
|
|
1722
|
+
compact: true
|
|
1723
|
+
}),
|
|
1724
|
+
flex: 1
|
|
1725
|
+
},
|
|
1726
|
+
children: [
|
|
1727
|
+
/* @__PURE__ */ jsx(History, { size: 15 }),
|
|
1728
|
+
"History"
|
|
1729
|
+
]
|
|
1730
|
+
}
|
|
1731
|
+
)
|
|
1732
|
+
]
|
|
1733
|
+
}
|
|
1734
|
+
) : null
|
|
1735
|
+
] }),
|
|
1736
|
+
/* @__PURE__ */ jsx(
|
|
1737
|
+
"div",
|
|
1738
|
+
{
|
|
1739
|
+
style: {
|
|
1740
|
+
padding: "14px",
|
|
1741
|
+
display: "grid",
|
|
1742
|
+
gap: "10px",
|
|
1743
|
+
flex: 1,
|
|
1744
|
+
minHeight: 0,
|
|
1745
|
+
overflowY: "auto",
|
|
1746
|
+
overflowX: "hidden"
|
|
1747
|
+
},
|
|
1748
|
+
children: view === "form" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1749
|
+
/* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "14px" }, children: [
|
|
1750
|
+
/* @__PURE__ */ jsxs(
|
|
1751
|
+
"div",
|
|
1752
|
+
{
|
|
1753
|
+
style: {
|
|
1754
|
+
display: "flex",
|
|
1755
|
+
alignItems: "flex-start",
|
|
1756
|
+
justifyContent: "space-between",
|
|
1757
|
+
gap: "10px",
|
|
1758
|
+
flexWrap: "wrap",
|
|
1759
|
+
marginBottom: "10px"
|
|
1760
|
+
},
|
|
1761
|
+
children: [
|
|
1762
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1763
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "New report" }),
|
|
1764
|
+
/* @__PURE__ */ jsx("p", { style: { margin: "4px 0 0", fontSize: "13px", lineHeight: 1.5, color: theme.textSoft }, children: "Describe the issue, attach context, and send it with the current page path." })
|
|
1765
|
+
] }),
|
|
1766
|
+
/* @__PURE__ */ jsxs("span", { style: { ...pillStyle("neutral"), maxWidth: "100%", overflow: "hidden" }, children: [
|
|
1767
|
+
/* @__PURE__ */ jsx(MapPin, { size: 12 }),
|
|
1768
|
+
/* @__PURE__ */ jsx(
|
|
1769
|
+
"span",
|
|
1770
|
+
{
|
|
1771
|
+
style: {
|
|
1772
|
+
overflow: "hidden",
|
|
1773
|
+
textOverflow: "ellipsis",
|
|
1774
|
+
whiteSpace: "nowrap",
|
|
1775
|
+
display: "inline-block"
|
|
1776
|
+
},
|
|
1777
|
+
children: currentPath
|
|
1778
|
+
}
|
|
1779
|
+
)
|
|
1780
|
+
] })
|
|
1781
|
+
]
|
|
1782
|
+
}
|
|
1783
|
+
),
|
|
1784
|
+
/* @__PURE__ */ jsx(
|
|
1785
|
+
"textarea",
|
|
1786
|
+
{
|
|
1787
|
+
value: message,
|
|
1788
|
+
onChange: (event) => setMessage(event.target.value),
|
|
1789
|
+
rows: 5,
|
|
1790
|
+
placeholder: "Describe the issue, the expected behavior, and what you were doing...",
|
|
1791
|
+
style: { ...fieldStyle, resize: "vertical", minHeight: "116px" }
|
|
1792
|
+
}
|
|
1793
|
+
)
|
|
1794
|
+
] }),
|
|
1795
|
+
/* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "14px" }, children: [
|
|
1796
|
+
/* @__PURE__ */ jsxs("div", { style: { marginBottom: "10px" }, children: [
|
|
1797
|
+
/* @__PURE__ */ jsx("p", { style: sectionLabelStyle, children: "Context and attachments" }),
|
|
1798
|
+
/* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, marginTop: "4px" }, children: "Paste an image with Ctrl/Cmd+V or attach a screenshot from the current tab." })
|
|
1799
|
+
] }),
|
|
1800
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
|
|
1801
|
+
canManageScreenshots ? /* @__PURE__ */ jsx(
|
|
1802
|
+
"button",
|
|
1803
|
+
{
|
|
1804
|
+
type: "button",
|
|
1805
|
+
onClick: handleCaptureScreenshot,
|
|
1806
|
+
"aria-label": "Capture screen",
|
|
1807
|
+
title: "Capture screen",
|
|
1808
|
+
style: buttonStyle("secondary", { compact: true, iconOnly: true }),
|
|
1809
|
+
children: /* @__PURE__ */ jsx(Camera, { size: 15 })
|
|
1810
|
+
}
|
|
1811
|
+
) : null,
|
|
1812
|
+
/* @__PURE__ */ jsx(
|
|
1813
|
+
"button",
|
|
1814
|
+
{
|
|
1815
|
+
type: "button",
|
|
1816
|
+
onClick: () => setCaptureMode((value) => !value),
|
|
1817
|
+
"aria-label": captureMode ? "Capture element: click target" : "Capture element",
|
|
1818
|
+
title: captureMode ? "Capture element: click target" : "Capture element",
|
|
1819
|
+
style: buttonStyle("secondary", { compact: true, active: captureMode, iconOnly: true }),
|
|
1820
|
+
children: /* @__PURE__ */ jsx(MousePointerClick, { size: 15 })
|
|
1821
|
+
}
|
|
1822
|
+
),
|
|
1823
|
+
canManageScreenshots ? /* @__PURE__ */ jsxs(
|
|
1824
|
+
"label",
|
|
1825
|
+
{
|
|
1826
|
+
"aria-label": uploading ? "Uploading image" : uploadLabel,
|
|
1827
|
+
title: uploading ? "Uploading image" : uploadLabel,
|
|
1828
|
+
style: buttonStyle("secondary", { compact: true, iconOnly: true }),
|
|
1829
|
+
children: [
|
|
1830
|
+
/* @__PURE__ */ jsx(Upload, { size: 15 }),
|
|
1831
|
+
/* @__PURE__ */ jsx(
|
|
1832
|
+
"input",
|
|
1833
|
+
{
|
|
1834
|
+
type: "file",
|
|
1835
|
+
accept: screenshotAllowedMimeTypes.join(","),
|
|
1836
|
+
onChange: handleUpload,
|
|
1837
|
+
hidden: true
|
|
1838
|
+
}
|
|
1839
|
+
)
|
|
1840
|
+
]
|
|
1841
|
+
}
|
|
1842
|
+
) : null
|
|
1843
|
+
] })
|
|
1844
|
+
] }),
|
|
1845
|
+
captureMode || captureData ? /* @__PURE__ */ jsxs(
|
|
1846
|
+
"div",
|
|
1847
|
+
{
|
|
1848
|
+
style: {
|
|
1849
|
+
...surfaceCardStyle,
|
|
1850
|
+
padding: "12px 14px",
|
|
1851
|
+
borderColor: captureMode ? "rgba(94, 234, 212, 0.3)" : theme.border
|
|
1852
|
+
},
|
|
1853
|
+
children: [
|
|
1854
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" }, children: [
|
|
1855
|
+
/* @__PURE__ */ jsxs("span", { style: pillStyle(captureMode ? "success" : "neutral"), title: captureData?.selector || void 0, children: [
|
|
1856
|
+
/* @__PURE__ */ jsx(MousePointerClick, { size: 12 }),
|
|
1857
|
+
captureMode ? "Element capture active" : "Element captured"
|
|
1858
|
+
] }),
|
|
1859
|
+
captureData?.selectedText ? /* @__PURE__ */ jsxs("span", { style: pillStyle("neutral"), title: captureData.selectedText, children: [
|
|
1860
|
+
/* @__PURE__ */ jsx(MessageSquare, { size: 12 }),
|
|
1861
|
+
"Text preview"
|
|
1862
|
+
] }) : null
|
|
1863
|
+
] }),
|
|
1864
|
+
!captureData ? /* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, marginTop: "8px" }, children: "Click any visible element to attach its selector." }) : null
|
|
1865
|
+
]
|
|
1866
|
+
}
|
|
1867
|
+
) : null,
|
|
1868
|
+
screenshotId ? /* @__PURE__ */ jsxs("div", { style: { ...surfaceCardStyle, padding: "10px" }, children: [
|
|
1869
|
+
/* @__PURE__ */ jsxs(
|
|
1870
|
+
"div",
|
|
1871
|
+
{
|
|
1872
|
+
style: {
|
|
1873
|
+
display: "flex",
|
|
1874
|
+
alignItems: "center",
|
|
1875
|
+
justifyContent: "space-between",
|
|
1876
|
+
gap: "10px",
|
|
1877
|
+
marginBottom: screenshotPreviewUrl ? "10px" : 0
|
|
1878
|
+
},
|
|
1879
|
+
children: [
|
|
1880
|
+
/* @__PURE__ */ jsxs("span", { style: pillStyle("neutral"), children: [
|
|
1881
|
+
/* @__PURE__ */ jsx(ImageIcon, { size: 12 }),
|
|
1882
|
+
"Media #",
|
|
1883
|
+
screenshotId
|
|
1884
|
+
] }),
|
|
1885
|
+
/* @__PURE__ */ jsxs(
|
|
1886
|
+
"button",
|
|
1887
|
+
{
|
|
1888
|
+
type: "button",
|
|
1889
|
+
onClick: handleRemoveScreenshot,
|
|
1890
|
+
disabled: deletingScreenshot,
|
|
1891
|
+
style: buttonStyle("danger", { compact: true, disabled: deletingScreenshot }),
|
|
1892
|
+
children: [
|
|
1893
|
+
/* @__PURE__ */ jsx(Trash2, { size: 15 }),
|
|
1894
|
+
deletingScreenshot ? "Removing..." : "Remove"
|
|
1895
|
+
]
|
|
1896
|
+
}
|
|
1897
|
+
)
|
|
1898
|
+
]
|
|
1899
|
+
}
|
|
1900
|
+
),
|
|
1901
|
+
screenshotPreviewUrl ? /* @__PURE__ */ jsx("div", { style: { ...innerCardStyle, overflow: "hidden" }, children: /* @__PURE__ */ jsx(
|
|
1902
|
+
"img",
|
|
1903
|
+
{
|
|
1904
|
+
src: screenshotPreviewUrl,
|
|
1905
|
+
alt: "Annotated screenshot preview",
|
|
1906
|
+
style: { width: "100%", height: "auto", display: "block", maxHeight: "180px", objectFit: "cover" }
|
|
1907
|
+
}
|
|
1908
|
+
) }) : null
|
|
1909
|
+
] }) : null,
|
|
1910
|
+
notice ? /* @__PURE__ */ jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(94, 234, 212, 0.28)" }, children: /* @__PURE__ */ jsxs("p", { style: { ...metaTextStyle, color: "#ccfbf1" }, children: [
|
|
1911
|
+
/* @__PURE__ */ jsx(CheckCircle2, { size: 14, style: { verticalAlign: "text-bottom", marginRight: "6px" } }),
|
|
1912
|
+
notice
|
|
1913
|
+
] }) }) : null,
|
|
1914
|
+
error ? /* @__PURE__ */ jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(248, 113, 113, 0.24)" }, children: /* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, color: "#fecaca" }, children: error }) }) : null
|
|
1915
|
+
] }) : view === "history" && history ? /* @__PURE__ */ jsx(
|
|
1916
|
+
FeedbackHistory,
|
|
1917
|
+
{
|
|
1918
|
+
feedbacks: history.feedbacks,
|
|
1919
|
+
totalPages: history.totalPages,
|
|
1920
|
+
currentPage: history.currentPage,
|
|
1921
|
+
loading: history.loading,
|
|
1922
|
+
error: history.error,
|
|
1923
|
+
currentUserId: currentUserId ?? null,
|
|
1924
|
+
onSelectFeedback: (id) => handleSelectFeedback(id),
|
|
1925
|
+
onPageChange: history.onPageChange,
|
|
1926
|
+
onRefetch: history.refetch
|
|
1927
|
+
}
|
|
1928
|
+
) : view === "detail" && selectedFeedback && onUpload && onDeleteScreenshot ? /* @__PURE__ */ jsx(
|
|
1929
|
+
FeedbackDetail,
|
|
1930
|
+
{
|
|
1931
|
+
feedback: selectedFeedback,
|
|
1932
|
+
currentUserId: currentUserId ?? null,
|
|
1933
|
+
capturePolicy,
|
|
1934
|
+
onBack: () => setView("history"),
|
|
1935
|
+
onUpdate: async (id, data) => {
|
|
1936
|
+
if (!onUpdateFeedback) return false;
|
|
1937
|
+
const result = await onUpdateFeedback(id, data);
|
|
1938
|
+
if (result && history) {
|
|
1939
|
+
history.refetch();
|
|
1940
|
+
setSelectedFeedback((prev) => {
|
|
1941
|
+
if (!prev) return prev;
|
|
1942
|
+
return {
|
|
1943
|
+
...prev,
|
|
1944
|
+
message: data.message ?? prev.message,
|
|
1945
|
+
screenshot: data.screenshotId !== void 0 ? data.screenshotId ? { id: data.screenshotId, url: void 0 } : null : prev.screenshot
|
|
1946
|
+
};
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
return result;
|
|
1950
|
+
},
|
|
1951
|
+
onDelete: async (id) => {
|
|
1952
|
+
if (!onDeleteFeedback) return false;
|
|
1953
|
+
const result = await onDeleteFeedback(id);
|
|
1954
|
+
if (result.success) {
|
|
1955
|
+
setSelectedFeedback(null);
|
|
1956
|
+
setView("history");
|
|
1957
|
+
history?.refetch();
|
|
1958
|
+
return true;
|
|
1959
|
+
}
|
|
1960
|
+
setError(result.error);
|
|
1961
|
+
return false;
|
|
1962
|
+
},
|
|
1963
|
+
onUpload,
|
|
1964
|
+
onDeleteScreenshot
|
|
1965
|
+
}
|
|
1966
|
+
) : null
|
|
1967
|
+
}
|
|
1968
|
+
),
|
|
1969
|
+
view === "form" ? /* @__PURE__ */ jsxs(
|
|
1970
|
+
"div",
|
|
1971
|
+
{
|
|
1972
|
+
style: {
|
|
1973
|
+
display: "flex",
|
|
1974
|
+
justifyContent: "space-between",
|
|
1975
|
+
alignItems: "stretch",
|
|
1976
|
+
gap: "8px",
|
|
1977
|
+
flexWrap: "wrap",
|
|
1978
|
+
flexShrink: 0,
|
|
1979
|
+
padding: "12px 14px",
|
|
1980
|
+
paddingBottom: "calc(12px + env(safe-area-inset-bottom, 0px))",
|
|
1981
|
+
borderTop: `1px solid ${theme.border}`,
|
|
1982
|
+
background: "linear-gradient(180deg, rgba(8, 15, 30, 0.94) 0%, rgba(15, 23, 42, 0.96) 100%)"
|
|
1983
|
+
},
|
|
1984
|
+
children: [
|
|
1985
|
+
/* @__PURE__ */ jsxs(
|
|
1986
|
+
"button",
|
|
1987
|
+
{
|
|
1988
|
+
type: "button",
|
|
1989
|
+
onClick: () => {
|
|
1990
|
+
setOpen(false);
|
|
1991
|
+
setView("form");
|
|
1992
|
+
},
|
|
1993
|
+
style: {
|
|
1994
|
+
...buttonStyle("ghost", { compact: true }),
|
|
1995
|
+
flex: "1 1 132px"
|
|
1996
|
+
},
|
|
1997
|
+
children: [
|
|
1998
|
+
/* @__PURE__ */ jsx(X, { size: 15 }),
|
|
1999
|
+
"Close"
|
|
2000
|
+
]
|
|
2001
|
+
}
|
|
2002
|
+
),
|
|
2003
|
+
/* @__PURE__ */ jsxs(
|
|
2004
|
+
"button",
|
|
2005
|
+
{
|
|
2006
|
+
type: "button",
|
|
2007
|
+
onClick: handleSubmit,
|
|
2008
|
+
disabled: submitting,
|
|
2009
|
+
style: {
|
|
2010
|
+
...buttonStyle("primary", { compact: true, disabled: submitting }),
|
|
2011
|
+
flex: "1 1 132px"
|
|
2012
|
+
},
|
|
2013
|
+
children: [
|
|
2014
|
+
/* @__PURE__ */ jsx(SendHorizontal, { size: 15 }),
|
|
2015
|
+
submitting ? "Sending..." : submitLabel
|
|
2016
|
+
]
|
|
2017
|
+
}
|
|
2018
|
+
)
|
|
2019
|
+
]
|
|
2020
|
+
}
|
|
2021
|
+
) : null
|
|
2022
|
+
] }) : null,
|
|
2023
|
+
annotating && editorImage ? /* @__PURE__ */ jsxs(
|
|
2024
|
+
"div",
|
|
2025
|
+
{
|
|
2026
|
+
style: {
|
|
2027
|
+
position: "fixed",
|
|
2028
|
+
inset: "0",
|
|
2029
|
+
zIndex: 1e4,
|
|
2030
|
+
background: "rgba(2, 8, 23, 0.96)",
|
|
2031
|
+
color: theme.text,
|
|
2032
|
+
display: "flex",
|
|
2033
|
+
flexDirection: "column"
|
|
2034
|
+
},
|
|
2035
|
+
children: [
|
|
2036
|
+
/* @__PURE__ */ jsxs(
|
|
2037
|
+
"div",
|
|
2038
|
+
{
|
|
2039
|
+
style: {
|
|
2040
|
+
display: "flex",
|
|
2041
|
+
flexWrap: "wrap",
|
|
2042
|
+
gap: "12px",
|
|
2043
|
+
alignItems: "flex-start",
|
|
2044
|
+
justifyContent: "space-between",
|
|
2045
|
+
padding: "16px 18px",
|
|
2046
|
+
borderBottom: `1px solid ${theme.border}`,
|
|
2047
|
+
background: "linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(8, 15, 30, 0.94) 100%)"
|
|
2048
|
+
},
|
|
2049
|
+
children: [
|
|
2050
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: "12px", flex: 1, minWidth: 0 }, children: [
|
|
2051
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "10px", flexWrap: "wrap" }, children: [
|
|
2052
|
+
/* @__PURE__ */ jsxs("span", { style: pillStyle("success"), children: [
|
|
2053
|
+
/* @__PURE__ */ jsx(Sparkles, { size: 12 }),
|
|
2054
|
+
"Annotate screenshot"
|
|
2055
|
+
] }),
|
|
2056
|
+
/* @__PURE__ */ jsx("span", { style: pillStyle("neutral"), children: editorImage.fileName })
|
|
2057
|
+
] }),
|
|
2058
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: annotationTools.map(({ tool, label, icon: Icon }) => /* @__PURE__ */ jsxs(
|
|
2059
|
+
"button",
|
|
2060
|
+
{
|
|
2061
|
+
type: "button",
|
|
2062
|
+
onClick: () => setAnnotationTool(tool),
|
|
2063
|
+
"aria-label": label,
|
|
2064
|
+
style: buttonStyle("secondary", {
|
|
2065
|
+
compact: true,
|
|
2066
|
+
active: annotationTool === tool
|
|
2067
|
+
}),
|
|
2068
|
+
children: [
|
|
2069
|
+
/* @__PURE__ */ jsx(Icon, { size: 15 }),
|
|
2070
|
+
label
|
|
2071
|
+
]
|
|
2072
|
+
},
|
|
2073
|
+
tool
|
|
2074
|
+
)) })
|
|
2075
|
+
] }),
|
|
2076
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: "10px", justifyItems: "start" }, children: [
|
|
2077
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px", alignItems: "center", flexWrap: "wrap" }, children: [
|
|
2078
|
+
DEFAULT_COLORS.map((color) => /* @__PURE__ */ jsx(
|
|
2079
|
+
"button",
|
|
2080
|
+
{
|
|
2081
|
+
type: "button",
|
|
2082
|
+
onClick: () => setAnnotationColor(color),
|
|
2083
|
+
"aria-label": `Select ${color} color`,
|
|
2084
|
+
style: {
|
|
2085
|
+
width: "28px",
|
|
2086
|
+
height: "28px",
|
|
2087
|
+
borderRadius: "999px",
|
|
2088
|
+
border: annotationColor === color ? "2px solid #f8fafc" : `1px solid ${theme.borderStrong}`,
|
|
2089
|
+
background: color,
|
|
2090
|
+
cursor: "pointer"
|
|
2091
|
+
}
|
|
2092
|
+
},
|
|
2093
|
+
color
|
|
2094
|
+
)),
|
|
2095
|
+
/* @__PURE__ */ jsx(
|
|
2096
|
+
"input",
|
|
2097
|
+
{
|
|
2098
|
+
type: "color",
|
|
2099
|
+
value: annotationColor,
|
|
2100
|
+
onChange: (event) => setAnnotationColor(event.target.value),
|
|
2101
|
+
"aria-label": "Annotation color",
|
|
2102
|
+
style: { width: "36px", height: "36px", border: "none", background: "transparent" }
|
|
2103
|
+
}
|
|
2104
|
+
)
|
|
2105
|
+
] }),
|
|
2106
|
+
/* @__PURE__ */ jsxs("label", { style: { display: "flex", alignItems: "center", gap: "10px", fontSize: "12px", color: theme.textSoft }, children: [
|
|
2107
|
+
"Size ",
|
|
2108
|
+
annotationSize,
|
|
2109
|
+
/* @__PURE__ */ jsx(
|
|
2110
|
+
"input",
|
|
2111
|
+
{
|
|
2112
|
+
type: "range",
|
|
2113
|
+
min: 1,
|
|
2114
|
+
max: 18,
|
|
2115
|
+
value: annotationSize,
|
|
2116
|
+
onChange: (event) => setAnnotationSize(Number(event.target.value)),
|
|
2117
|
+
"aria-label": "Annotation size"
|
|
2118
|
+
}
|
|
2119
|
+
)
|
|
2120
|
+
] }),
|
|
2121
|
+
annotationTool === "text" ? /* @__PURE__ */ jsx(
|
|
2122
|
+
"input",
|
|
2123
|
+
{
|
|
2124
|
+
type: "text",
|
|
2125
|
+
value: annotationText,
|
|
2126
|
+
onChange: (event) => setAnnotationText(event.target.value),
|
|
2127
|
+
placeholder: "Text to place",
|
|
2128
|
+
"aria-label": "Annotation text",
|
|
2129
|
+
style: {
|
|
2130
|
+
...fieldStyle,
|
|
2131
|
+
minWidth: "220px",
|
|
2132
|
+
padding: "10px 12px"
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
) : null,
|
|
2136
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
|
|
2137
|
+
/* @__PURE__ */ jsxs(
|
|
2138
|
+
"button",
|
|
2139
|
+
{
|
|
2140
|
+
type: "button",
|
|
2141
|
+
onClick: handleUndo,
|
|
2142
|
+
disabled: !currentHasUndo,
|
|
2143
|
+
style: buttonStyle("secondary", { compact: true, disabled: !currentHasUndo }),
|
|
2144
|
+
children: [
|
|
2145
|
+
/* @__PURE__ */ jsx(Undo2, { size: 15 }),
|
|
2146
|
+
"Undo"
|
|
2147
|
+
]
|
|
2148
|
+
}
|
|
2149
|
+
),
|
|
2150
|
+
/* @__PURE__ */ jsxs(
|
|
2151
|
+
"button",
|
|
2152
|
+
{
|
|
2153
|
+
type: "button",
|
|
2154
|
+
onClick: handleRedo,
|
|
2155
|
+
disabled: !currentHasRedo,
|
|
2156
|
+
style: buttonStyle("secondary", { compact: true, disabled: !currentHasRedo }),
|
|
2157
|
+
children: [
|
|
2158
|
+
/* @__PURE__ */ jsx(Redo2, { size: 15 }),
|
|
2159
|
+
"Redo"
|
|
2160
|
+
]
|
|
2161
|
+
}
|
|
2162
|
+
),
|
|
2163
|
+
/* @__PURE__ */ jsxs(
|
|
2164
|
+
"button",
|
|
2165
|
+
{
|
|
2166
|
+
type: "button",
|
|
2167
|
+
onClick: handleClearAnnotations,
|
|
2168
|
+
disabled: !hasAnnotations,
|
|
2169
|
+
style: buttonStyle("secondary", { compact: true, disabled: !hasAnnotations }),
|
|
2170
|
+
children: [
|
|
2171
|
+
/* @__PURE__ */ jsx(Eraser, { size: 15 }),
|
|
2172
|
+
"Clear"
|
|
2173
|
+
]
|
|
2174
|
+
}
|
|
2175
|
+
),
|
|
2176
|
+
/* @__PURE__ */ jsxs(
|
|
2177
|
+
"button",
|
|
2178
|
+
{
|
|
2179
|
+
type: "button",
|
|
2180
|
+
onClick: handleRevertLastAnnotation,
|
|
2181
|
+
disabled: !hasAnnotations,
|
|
2182
|
+
style: buttonStyle("secondary", { compact: true, disabled: !hasAnnotations }),
|
|
2183
|
+
children: [
|
|
2184
|
+
/* @__PURE__ */ jsx(RotateCcw, { size: 15 }),
|
|
2185
|
+
"Revert last"
|
|
2186
|
+
]
|
|
2187
|
+
}
|
|
2188
|
+
)
|
|
2189
|
+
] })
|
|
2190
|
+
] })
|
|
2191
|
+
]
|
|
2192
|
+
}
|
|
2193
|
+
),
|
|
2194
|
+
/* @__PURE__ */ jsx(
|
|
2195
|
+
"div",
|
|
2196
|
+
{
|
|
2197
|
+
style: {
|
|
2198
|
+
flex: 1,
|
|
2199
|
+
overflow: "auto",
|
|
2200
|
+
padding: "18px",
|
|
2201
|
+
display: "flex",
|
|
2202
|
+
alignItems: "center",
|
|
2203
|
+
justifyContent: "center"
|
|
2204
|
+
},
|
|
2205
|
+
children: /* @__PURE__ */ jsx(
|
|
2206
|
+
"canvas",
|
|
2207
|
+
{
|
|
2208
|
+
ref: annotationCanvasRef,
|
|
2209
|
+
onPointerDown: handleCanvasPointerDown,
|
|
2210
|
+
onPointerMove: handleCanvasPointerMove,
|
|
2211
|
+
onPointerUp: handleCanvasPointerUp,
|
|
2212
|
+
onPointerCancel: handleCanvasPointerCancel,
|
|
2213
|
+
style: {
|
|
2214
|
+
width: "min(100%, 1400px)",
|
|
2215
|
+
height: "auto",
|
|
2216
|
+
display: "block",
|
|
2217
|
+
borderRadius: "22px",
|
|
2218
|
+
background: "#ffffff",
|
|
2219
|
+
boxShadow: "0 34px 90px rgba(2, 8, 23, 0.5)",
|
|
2220
|
+
touchAction: "none",
|
|
2221
|
+
cursor: annotationTool === "text" ? "copy" : "crosshair"
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
)
|
|
2225
|
+
}
|
|
2226
|
+
),
|
|
2227
|
+
/* @__PURE__ */ jsxs(
|
|
2228
|
+
"div",
|
|
2229
|
+
{
|
|
2230
|
+
style: {
|
|
2231
|
+
display: "flex",
|
|
2232
|
+
justifyContent: "space-between",
|
|
2233
|
+
alignItems: "center",
|
|
2234
|
+
gap: "12px",
|
|
2235
|
+
flexWrap: "wrap",
|
|
2236
|
+
padding: "16px 18px",
|
|
2237
|
+
borderTop: `1px solid ${theme.border}`,
|
|
2238
|
+
background: "linear-gradient(180deg, rgba(8, 15, 30, 0.94) 0%, rgba(15, 23, 42, 0.96) 100%)"
|
|
2239
|
+
},
|
|
2240
|
+
children: [
|
|
2241
|
+
/* @__PURE__ */ jsx("p", { style: { ...metaTextStyle, maxWidth: "720px" }, children: "Use mouse, touch, or pen input. Text is placed where you click on the image." }),
|
|
2242
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
|
|
2243
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: closeAnnotationEditor, style: buttonStyle("ghost"), children: [
|
|
2244
|
+
/* @__PURE__ */ jsx(X, { size: 15 }),
|
|
2245
|
+
"Cancel"
|
|
2246
|
+
] }),
|
|
2247
|
+
/* @__PURE__ */ jsxs(
|
|
2248
|
+
"button",
|
|
2249
|
+
{
|
|
2250
|
+
type: "button",
|
|
2251
|
+
onClick: handleApplyAnnotation,
|
|
2252
|
+
disabled: uploading,
|
|
2253
|
+
style: buttonStyle("primary", { disabled: uploading }),
|
|
2254
|
+
children: [
|
|
2255
|
+
/* @__PURE__ */ jsx(Upload, { size: 15 }),
|
|
2256
|
+
uploading ? "Uploading..." : "Save screenshot"
|
|
2257
|
+
]
|
|
2258
|
+
}
|
|
2259
|
+
)
|
|
2260
|
+
] })
|
|
2261
|
+
]
|
|
2262
|
+
}
|
|
2263
|
+
)
|
|
2264
|
+
]
|
|
2265
|
+
}
|
|
2266
|
+
) : null
|
|
2267
|
+
] });
|
|
2268
|
+
}
|
|
2269
|
+
function useFeedbackQuery(params) {
|
|
2270
|
+
const { pagePath, page = 1, limit = 20 } = params;
|
|
2271
|
+
const [feedbacks, setFeedbacks] = React2.useState([]);
|
|
2272
|
+
const [totalPages, setTotalPages] = React2.useState(0);
|
|
2273
|
+
const [loading, setLoading] = React2.useState(true);
|
|
2274
|
+
const [error, setError] = React2.useState(null);
|
|
2275
|
+
const [fetchKey, setFetchKey] = React2.useState(0);
|
|
2276
|
+
const refetch = React2.useCallback(() => {
|
|
2277
|
+
setFetchKey((key) => key + 1);
|
|
2278
|
+
}, []);
|
|
2279
|
+
React2.useEffect(() => {
|
|
2280
|
+
let cancelled = false;
|
|
2281
|
+
const fetchFeedbacks = async () => {
|
|
2282
|
+
setLoading(true);
|
|
2283
|
+
setError(null);
|
|
2284
|
+
try {
|
|
2285
|
+
const url = new URL("/api/admin-feedback", window.location.origin);
|
|
2286
|
+
url.searchParams.set("depth", "2");
|
|
2287
|
+
url.searchParams.set("sort", "-createdAt");
|
|
2288
|
+
url.searchParams.set("limit", String(limit));
|
|
2289
|
+
url.searchParams.set("page", String(page));
|
|
2290
|
+
if (pagePath) {
|
|
2291
|
+
url.searchParams.set("where[pagePath][equals]", pagePath);
|
|
2292
|
+
}
|
|
2293
|
+
const response = await fetch(url.toString(), {
|
|
2294
|
+
credentials: "include"
|
|
2295
|
+
});
|
|
2296
|
+
if (!response.ok) {
|
|
2297
|
+
if (response.status === 401 || response.status === 403) {
|
|
2298
|
+
if (!cancelled) {
|
|
2299
|
+
setFeedbacks([]);
|
|
2300
|
+
setTotalPages(0);
|
|
2301
|
+
setLoading(false);
|
|
2302
|
+
}
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
throw new Error(`Failed to fetch feedback (${response.status})`);
|
|
2306
|
+
}
|
|
2307
|
+
const data = await response.json();
|
|
2308
|
+
if (!cancelled) {
|
|
2309
|
+
setFeedbacks(data.docs);
|
|
2310
|
+
setTotalPages(data.totalPages);
|
|
2311
|
+
setLoading(false);
|
|
2312
|
+
}
|
|
2313
|
+
} catch (err) {
|
|
2314
|
+
if (!cancelled) {
|
|
2315
|
+
setError(err instanceof Error ? err.message : "Failed to load feedback.");
|
|
2316
|
+
setLoading(false);
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
fetchFeedbacks();
|
|
2321
|
+
return () => {
|
|
2322
|
+
cancelled = true;
|
|
2323
|
+
};
|
|
2324
|
+
}, [pagePath, page, limit, fetchKey]);
|
|
2325
|
+
return {
|
|
2326
|
+
feedbacks,
|
|
2327
|
+
totalPages,
|
|
2328
|
+
currentPage: page,
|
|
2329
|
+
loading,
|
|
2330
|
+
error,
|
|
2331
|
+
refetch
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
function useCurrentUser() {
|
|
2335
|
+
const [userId, setUserId] = React2.useState(null);
|
|
2336
|
+
const [loading, setLoading] = React2.useState(true);
|
|
2337
|
+
React2.useEffect(() => {
|
|
2338
|
+
let cancelled = false;
|
|
2339
|
+
const fetchUser = async () => {
|
|
2340
|
+
try {
|
|
2341
|
+
const response = await fetch("/api/users/me", {
|
|
2342
|
+
credentials: "include"
|
|
2343
|
+
});
|
|
2344
|
+
if (!response.ok) {
|
|
2345
|
+
if (!cancelled) {
|
|
2346
|
+
setUserId(null);
|
|
2347
|
+
setLoading(false);
|
|
2348
|
+
}
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
const data = await response.json();
|
|
2352
|
+
if (!cancelled) {
|
|
2353
|
+
setUserId(data.user?.id ?? data.id ?? null);
|
|
2354
|
+
setLoading(false);
|
|
2355
|
+
}
|
|
2356
|
+
} catch {
|
|
2357
|
+
if (!cancelled) {
|
|
2358
|
+
setUserId(null);
|
|
2359
|
+
setLoading(false);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
fetchUser();
|
|
2364
|
+
return () => {
|
|
2365
|
+
cancelled = true;
|
|
2366
|
+
};
|
|
2367
|
+
}, []);
|
|
2368
|
+
return { userId, loading };
|
|
2369
|
+
}
|
|
2370
|
+
function AdminFeedbackWidget() {
|
|
2371
|
+
const { userId, loading: userLoading } = useCurrentUser();
|
|
2372
|
+
const [page, setPage] = React2.useState(1);
|
|
2373
|
+
const query = useFeedbackQuery({ page });
|
|
2374
|
+
const handleUpdateFeedback = React2.useCallback(
|
|
2375
|
+
async (id, data) => {
|
|
2376
|
+
const response = await fetch(`/api/admin-feedback/update/${id}`, {
|
|
2377
|
+
method: "PATCH",
|
|
2378
|
+
credentials: "include",
|
|
2379
|
+
headers: { "content-type": "application/json" },
|
|
2380
|
+
body: JSON.stringify(data)
|
|
2381
|
+
});
|
|
2382
|
+
const result = await response.json();
|
|
2383
|
+
if (!result.success) {
|
|
2384
|
+
return false;
|
|
2385
|
+
}
|
|
2386
|
+
return true;
|
|
2387
|
+
},
|
|
2388
|
+
[]
|
|
2389
|
+
);
|
|
2390
|
+
return /* @__PURE__ */ jsx(
|
|
2391
|
+
FeedbackWidget,
|
|
2392
|
+
{
|
|
2393
|
+
title: "Admin feedback",
|
|
2394
|
+
submitLabel: "Send",
|
|
2395
|
+
uploadLabel: "Upload image",
|
|
2396
|
+
allowScreenshotUpload: true,
|
|
2397
|
+
showHistory: true,
|
|
2398
|
+
currentUserId: userLoading ? null : userId,
|
|
2399
|
+
onUpdateFeedback: handleUpdateFeedback,
|
|
2400
|
+
history: {
|
|
2401
|
+
feedbacks: query.feedbacks,
|
|
2402
|
+
totalPages: query.totalPages,
|
|
2403
|
+
currentPage: query.currentPage,
|
|
2404
|
+
loading: query.loading,
|
|
2405
|
+
error: query.error,
|
|
2406
|
+
refetch: query.refetch,
|
|
2407
|
+
onPageChange: setPage
|
|
2408
|
+
},
|
|
2409
|
+
onSubmit: async (payload) => {
|
|
2410
|
+
const response = await fetch("/api/admin-feedback/submit", {
|
|
2411
|
+
method: "POST",
|
|
2412
|
+
credentials: "include",
|
|
2413
|
+
headers: { "content-type": "application/json" },
|
|
2414
|
+
body: JSON.stringify(payload)
|
|
2415
|
+
});
|
|
2416
|
+
const result = await response.json();
|
|
2417
|
+
if (!result.success) {
|
|
2418
|
+
return { success: false, error: result.error || "Submit failed." };
|
|
2419
|
+
}
|
|
2420
|
+
query.refetch();
|
|
2421
|
+
return { success: true };
|
|
2422
|
+
},
|
|
2423
|
+
onDeleteFeedback: async (id) => {
|
|
2424
|
+
const response = await fetch(`/api/admin-feedback/delete/${id}`, {
|
|
2425
|
+
method: "DELETE",
|
|
2426
|
+
credentials: "include"
|
|
2427
|
+
});
|
|
2428
|
+
const result = await response.json();
|
|
2429
|
+
if (!result.success) {
|
|
2430
|
+
return { success: false, error: result.error || "Delete failed." };
|
|
2431
|
+
}
|
|
2432
|
+
query.refetch();
|
|
2433
|
+
return { success: true };
|
|
2434
|
+
},
|
|
2435
|
+
onUpload: async (formData) => {
|
|
2436
|
+
const response = await fetch("/api/admin-feedback/upload", {
|
|
2437
|
+
method: "POST",
|
|
2438
|
+
credentials: "include",
|
|
2439
|
+
body: formData
|
|
2440
|
+
});
|
|
2441
|
+
const result = await response.json();
|
|
2442
|
+
if (!result.success || typeof result.mediaId !== "number") {
|
|
2443
|
+
return { success: false, error: result.error || "Upload failed." };
|
|
2444
|
+
}
|
|
2445
|
+
return { success: true, mediaId: result.mediaId };
|
|
2446
|
+
},
|
|
2447
|
+
onDeleteScreenshot: async (mediaId) => {
|
|
2448
|
+
const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
|
|
2449
|
+
method: "DELETE",
|
|
2450
|
+
credentials: "include"
|
|
2451
|
+
});
|
|
2452
|
+
const result = await response.json();
|
|
2453
|
+
if (!result.success) {
|
|
2454
|
+
return { success: false, error: result.error || "Delete failed." };
|
|
2455
|
+
}
|
|
2456
|
+
return { success: true };
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
);
|
|
2460
|
+
}
|
|
2461
|
+
var DOT_SIZE = 14;
|
|
2462
|
+
var DOT_OFFSET = 8;
|
|
2463
|
+
var STATUS_COLORS = {
|
|
2464
|
+
new: "#5eead4",
|
|
2465
|
+
triaged: "#facc15",
|
|
2466
|
+
resolved: "#cbd5e1"
|
|
2467
|
+
};
|
|
2468
|
+
var STATUS_LABELS2 = {
|
|
2469
|
+
new: "New",
|
|
2470
|
+
triaged: "Triaged",
|
|
2471
|
+
resolved: "Resolved"
|
|
2472
|
+
};
|
|
2473
|
+
var formatRelativeTime2 = (iso) => {
|
|
2474
|
+
const now = Date.now();
|
|
2475
|
+
const diff = now - new Date(iso).getTime();
|
|
2476
|
+
const minutes = Math.floor(diff / 6e4);
|
|
2477
|
+
if (minutes < 1) return "Just now";
|
|
2478
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
2479
|
+
const hours = Math.floor(minutes / 60);
|
|
2480
|
+
if (hours < 24) return `${hours}h ago`;
|
|
2481
|
+
const days = Math.floor(hours / 24);
|
|
2482
|
+
if (days < 7) return `${days}d ago`;
|
|
2483
|
+
return new Date(iso).toLocaleDateString();
|
|
2484
|
+
};
|
|
2485
|
+
function FeedbackIndicators({ pagePath }) {
|
|
2486
|
+
const containerRef = React2.useRef(null);
|
|
2487
|
+
const dotsRef = React2.useRef(/* @__PURE__ */ new Map());
|
|
2488
|
+
const tooltipRef = React2.useRef(null);
|
|
2489
|
+
const rafRef = React2.useRef(0);
|
|
2490
|
+
const indicatorDataRef = React2.useRef([]);
|
|
2491
|
+
const createContainer = React2.useCallback(() => {
|
|
2492
|
+
if (containerRef.current) return containerRef.current;
|
|
2493
|
+
const element = document.createElement("div");
|
|
2494
|
+
element.style.cssText = "position:fixed;inset:0;pointer-events:none;z-index:9998;";
|
|
2495
|
+
document.body.appendChild(element);
|
|
2496
|
+
containerRef.current = element;
|
|
2497
|
+
return element;
|
|
2498
|
+
}, []);
|
|
2499
|
+
const createTooltip = React2.useCallback(() => {
|
|
2500
|
+
if (tooltipRef.current) return tooltipRef.current;
|
|
2501
|
+
const element = document.createElement("div");
|
|
2502
|
+
element.style.cssText = `
|
|
2503
|
+
position:fixed;
|
|
2504
|
+
z-index:9999;
|
|
2505
|
+
pointer-events:none;
|
|
2506
|
+
opacity:0;
|
|
2507
|
+
max-width:260px;
|
|
2508
|
+
padding:12px 14px;
|
|
2509
|
+
border-radius:16px;
|
|
2510
|
+
border:1px solid rgba(148, 163, 184, 0.18);
|
|
2511
|
+
background:linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(6, 13, 24, 0.96) 100%);
|
|
2512
|
+
color:#f8fafc;
|
|
2513
|
+
box-shadow:0 18px 40px rgba(2, 8, 23, 0.4);
|
|
2514
|
+
backdrop-filter:blur(16px);
|
|
2515
|
+
transition:opacity 0.15s ease;
|
|
2516
|
+
white-space:normal;
|
|
2517
|
+
`;
|
|
2518
|
+
document.body.appendChild(element);
|
|
2519
|
+
tooltipRef.current = element;
|
|
2520
|
+
return element;
|
|
2521
|
+
}, []);
|
|
2522
|
+
const renderTooltip = React2.useCallback((tooltip, indicator) => {
|
|
2523
|
+
tooltip.replaceChildren();
|
|
2524
|
+
const message = document.createElement("p");
|
|
2525
|
+
message.textContent = indicator.message.length > 80 ? `${indicator.message.slice(0, 80)}...` : indicator.message;
|
|
2526
|
+
message.style.cssText = "margin:0 0 8px;font-size:12px;line-height:1.5;word-break:break-word;";
|
|
2527
|
+
const metaRow = document.createElement("div");
|
|
2528
|
+
metaRow.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap;";
|
|
2529
|
+
const status = document.createElement("span");
|
|
2530
|
+
status.textContent = STATUS_LABELS2[indicator.status] || "New";
|
|
2531
|
+
status.style.cssText = `
|
|
2532
|
+
display:inline-flex;
|
|
2533
|
+
align-items:center;
|
|
2534
|
+
border-radius:999px;
|
|
2535
|
+
padding:4px 8px;
|
|
2536
|
+
font-size:10px;
|
|
2537
|
+
font-weight:700;
|
|
2538
|
+
background:rgba(148, 163, 184, 0.12);
|
|
2539
|
+
color:${STATUS_COLORS[indicator.status] || STATUS_COLORS.new};
|
|
2540
|
+
border:1px solid rgba(148, 163, 184, 0.18);
|
|
2541
|
+
`;
|
|
2542
|
+
const time = document.createElement("span");
|
|
2543
|
+
time.textContent = formatRelativeTime2(indicator.createdAt);
|
|
2544
|
+
time.style.cssText = "font-size:10px;color:rgba(148, 163, 184, 0.86);";
|
|
2545
|
+
metaRow.append(status, time);
|
|
2546
|
+
tooltip.append(message, metaRow);
|
|
2547
|
+
}, []);
|
|
2548
|
+
const positionDot = React2.useCallback((dot, selector) => {
|
|
2549
|
+
let target = null;
|
|
2550
|
+
try {
|
|
2551
|
+
target = document.querySelector(selector);
|
|
2552
|
+
} catch {
|
|
2553
|
+
dot.style.display = "none";
|
|
2554
|
+
return false;
|
|
2555
|
+
}
|
|
2556
|
+
if (!(target instanceof HTMLElement)) {
|
|
2557
|
+
dot.style.display = "none";
|
|
2558
|
+
return false;
|
|
2559
|
+
}
|
|
2560
|
+
const rect = target.getBoundingClientRect();
|
|
2561
|
+
if (rect.width > window.innerWidth * 0.9 || rect.height > window.innerHeight * 0.9) {
|
|
2562
|
+
dot.style.display = "none";
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
dot.style.display = "";
|
|
2566
|
+
dot.style.left = `${rect.right + DOT_OFFSET}px`;
|
|
2567
|
+
dot.style.top = `${rect.top - DOT_OFFSET - DOT_SIZE / 2}px`;
|
|
2568
|
+
return true;
|
|
2569
|
+
}, []);
|
|
2570
|
+
const repositionAll = React2.useCallback(() => {
|
|
2571
|
+
dotsRef.current.forEach((dot, id) => {
|
|
2572
|
+
const indicator = indicatorDataRef.current.find((item) => item.id === id);
|
|
2573
|
+
if (indicator) {
|
|
2574
|
+
positionDot(dot, indicator.selector);
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
}, [positionDot]);
|
|
2578
|
+
React2.useEffect(() => {
|
|
2579
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
2580
|
+
let cancelled = false;
|
|
2581
|
+
const fetchAndRender = async () => {
|
|
2582
|
+
try {
|
|
2583
|
+
const authCheck = await fetch("/api/admin-feedback?limit=1", {
|
|
2584
|
+
credentials: "include"
|
|
2585
|
+
});
|
|
2586
|
+
if (!authCheck.ok) return;
|
|
2587
|
+
} catch {
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2590
|
+
const path = pagePath || window.location.pathname;
|
|
2591
|
+
const url = new URL("/api/admin-feedback", window.location.origin);
|
|
2592
|
+
url.searchParams.set("where[selector][exists]", "true");
|
|
2593
|
+
url.searchParams.set("depth", "2");
|
|
2594
|
+
url.searchParams.set("limit", "50");
|
|
2595
|
+
url.searchParams.set("sort", "-createdAt");
|
|
2596
|
+
try {
|
|
2597
|
+
const response = await fetch(url.toString(), { credentials: "include" });
|
|
2598
|
+
if (!response.ok) return;
|
|
2599
|
+
const data = await response.json();
|
|
2600
|
+
if (cancelled) return;
|
|
2601
|
+
const indicators = data.docs.filter((item) => item.selector && item.pagePath === path).map((item) => ({
|
|
2602
|
+
id: item.id,
|
|
2603
|
+
message: item.message,
|
|
2604
|
+
status: item.status,
|
|
2605
|
+
createdAt: item.createdAt,
|
|
2606
|
+
selector: item.selector
|
|
2607
|
+
}));
|
|
2608
|
+
indicatorDataRef.current = indicators;
|
|
2609
|
+
const container = createContainer();
|
|
2610
|
+
const tooltip = createTooltip();
|
|
2611
|
+
const currentIds = new Set(indicators.map((item) => item.id));
|
|
2612
|
+
dotsRef.current.forEach((dot, id) => {
|
|
2613
|
+
if (!currentIds.has(id)) {
|
|
2614
|
+
dot.remove();
|
|
2615
|
+
dotsRef.current.delete(id);
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
for (const indicator of indicators) {
|
|
2619
|
+
let dot = dotsRef.current.get(indicator.id);
|
|
2620
|
+
if (!dot) {
|
|
2621
|
+
const element = document.createElement("div");
|
|
2622
|
+
element.style.cssText = `
|
|
2623
|
+
position:fixed;
|
|
2624
|
+
width:${DOT_SIZE}px;
|
|
2625
|
+
height:${DOT_SIZE}px;
|
|
2626
|
+
border-radius:999px;
|
|
2627
|
+
cursor:pointer;
|
|
2628
|
+
pointer-events:auto;
|
|
2629
|
+
z-index:9999;
|
|
2630
|
+
border:2px solid rgba(255,255,255,0.95);
|
|
2631
|
+
box-shadow:0 0 0 6px rgba(15, 23, 42, 0.2), 0 10px 22px rgba(2, 8, 23, 0.34);
|
|
2632
|
+
transition:transform 0.15s ease, box-shadow 0.15s ease;
|
|
2633
|
+
`;
|
|
2634
|
+
element.addEventListener("mouseenter", () => {
|
|
2635
|
+
element.style.transform = "scale(1.25)";
|
|
2636
|
+
element.style.boxShadow = "0 0 0 8px rgba(15, 23, 42, 0.28), 0 14px 28px rgba(2, 8, 23, 0.42)";
|
|
2637
|
+
renderTooltip(tooltip, indicator);
|
|
2638
|
+
const dotRect = element.getBoundingClientRect();
|
|
2639
|
+
tooltip.style.left = `${dotRect.right + 10}px`;
|
|
2640
|
+
tooltip.style.top = `${Math.max(12, dotRect.top - 6)}px`;
|
|
2641
|
+
tooltip.style.opacity = "1";
|
|
2642
|
+
});
|
|
2643
|
+
element.addEventListener("mouseleave", () => {
|
|
2644
|
+
element.style.transform = "";
|
|
2645
|
+
element.style.boxShadow = "0 0 0 6px rgba(15, 23, 42, 0.2), 0 10px 22px rgba(2, 8, 23, 0.34)";
|
|
2646
|
+
tooltip.style.opacity = "0";
|
|
2647
|
+
});
|
|
2648
|
+
element.addEventListener("click", (event) => {
|
|
2649
|
+
event.stopPropagation();
|
|
2650
|
+
window.dispatchEvent(
|
|
2651
|
+
new CustomEvent("feedback:show-detail", {
|
|
2652
|
+
detail: { feedbackId: indicator.id }
|
|
2653
|
+
})
|
|
2654
|
+
);
|
|
2655
|
+
});
|
|
2656
|
+
container.appendChild(element);
|
|
2657
|
+
dotsRef.current.set(indicator.id, element);
|
|
2658
|
+
dot = element;
|
|
2659
|
+
}
|
|
2660
|
+
dot.style.background = STATUS_COLORS[indicator.status] || STATUS_COLORS.new;
|
|
2661
|
+
positionDot(dot, indicator.selector);
|
|
2662
|
+
}
|
|
2663
|
+
} catch {
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
const onScroll = () => {
|
|
2667
|
+
if (rafRef.current) return;
|
|
2668
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
2669
|
+
rafRef.current = 0;
|
|
2670
|
+
repositionAll();
|
|
2671
|
+
});
|
|
2672
|
+
};
|
|
2673
|
+
fetchAndRender();
|
|
2674
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
2675
|
+
window.addEventListener("resize", onScroll);
|
|
2676
|
+
return () => {
|
|
2677
|
+
cancelled = true;
|
|
2678
|
+
window.removeEventListener("scroll", onScroll);
|
|
2679
|
+
window.removeEventListener("resize", onScroll);
|
|
2680
|
+
if (rafRef.current) {
|
|
2681
|
+
cancelAnimationFrame(rafRef.current);
|
|
2682
|
+
rafRef.current = 0;
|
|
2683
|
+
}
|
|
2684
|
+
};
|
|
2685
|
+
}, [pagePath, createContainer, createTooltip, positionDot, renderTooltip, repositionAll]);
|
|
2686
|
+
React2.useEffect(() => {
|
|
2687
|
+
return () => {
|
|
2688
|
+
dotsRef.current.forEach((dot) => dot.remove());
|
|
2689
|
+
dotsRef.current.clear();
|
|
2690
|
+
if (containerRef.current) {
|
|
2691
|
+
containerRef.current.remove();
|
|
2692
|
+
containerRef.current = null;
|
|
2693
|
+
}
|
|
2694
|
+
if (tooltipRef.current) {
|
|
2695
|
+
tooltipRef.current.remove();
|
|
2696
|
+
tooltipRef.current = null;
|
|
2697
|
+
}
|
|
2698
|
+
};
|
|
2699
|
+
}, []);
|
|
2700
|
+
return null;
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
// src/client/routeMatcher.ts
|
|
2704
|
+
var escapeRegex = (input) => input.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
2705
|
+
var toRegExp = (pattern) => {
|
|
2706
|
+
const escaped = pattern.split("*").map((segment) => escapeRegex(segment)).join(".*");
|
|
2707
|
+
return new RegExp(`^${escaped}$`);
|
|
2708
|
+
};
|
|
2709
|
+
var pathMatchesAllowlist = (pathname, patterns) => {
|
|
2710
|
+
if (patterns.length === 0) {
|
|
2711
|
+
return false;
|
|
2712
|
+
}
|
|
2713
|
+
return patterns.some((pattern) => toRegExp(pattern).test(pathname));
|
|
2714
|
+
};
|
|
2715
|
+
var normalizePathname = (pathname, locales) => {
|
|
2716
|
+
if (locales.length === 0) {
|
|
2717
|
+
return pathname;
|
|
2718
|
+
}
|
|
2719
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
2720
|
+
const maybeLocale = segments[0];
|
|
2721
|
+
if (maybeLocale && locales.includes(maybeLocale)) {
|
|
2722
|
+
return `/${segments.slice(1).join("/")}`;
|
|
2723
|
+
}
|
|
2724
|
+
return pathname;
|
|
2725
|
+
};
|
|
2726
|
+
function FrontendFeedbackWidget({
|
|
2727
|
+
include,
|
|
2728
|
+
locales = [],
|
|
2729
|
+
title = "Feedback",
|
|
2730
|
+
submitLabel = "Send",
|
|
2731
|
+
uploadLabel = "Upload image",
|
|
2732
|
+
showIndicators = false,
|
|
2733
|
+
showHistory = false
|
|
2734
|
+
}) {
|
|
2735
|
+
const pathname = usePathname();
|
|
2736
|
+
const normalizedPathname = normalizePathname(pathname, locales);
|
|
2737
|
+
const { userId, loading: userLoading } = useCurrentUser();
|
|
2738
|
+
const [page, setPage] = React2.useState(1);
|
|
2739
|
+
const query = useFeedbackQuery({ pagePath: normalizedPathname, page });
|
|
2740
|
+
const handleUpdateFeedback = React2.useCallback(
|
|
2741
|
+
async (id, data) => {
|
|
2742
|
+
const response = await fetch(`/api/admin-feedback/update/${id}`, {
|
|
2743
|
+
method: "PATCH",
|
|
2744
|
+
credentials: "include",
|
|
2745
|
+
headers: { "content-type": "application/json" },
|
|
2746
|
+
body: JSON.stringify(data)
|
|
2747
|
+
});
|
|
2748
|
+
const result = await response.json();
|
|
2749
|
+
if (!result.success) {
|
|
2750
|
+
return false;
|
|
2751
|
+
}
|
|
2752
|
+
return true;
|
|
2753
|
+
},
|
|
2754
|
+
[]
|
|
2755
|
+
);
|
|
2756
|
+
if (!pathMatchesAllowlist(normalizedPathname, include)) {
|
|
2757
|
+
return null;
|
|
2758
|
+
}
|
|
2759
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2760
|
+
showIndicators ? /* @__PURE__ */ jsx(FeedbackIndicators, { pagePath: normalizedPathname }) : null,
|
|
2761
|
+
/* @__PURE__ */ jsx(
|
|
2762
|
+
FeedbackWidget,
|
|
2763
|
+
{
|
|
2764
|
+
title,
|
|
2765
|
+
submitLabel,
|
|
2766
|
+
uploadLabel,
|
|
2767
|
+
allowScreenshotUpload: true,
|
|
2768
|
+
showHistory,
|
|
2769
|
+
currentUserId: userLoading ? null : userId,
|
|
2770
|
+
onUpdateFeedback: showHistory ? handleUpdateFeedback : void 0,
|
|
2771
|
+
history: showHistory ? {
|
|
2772
|
+
feedbacks: query.feedbacks,
|
|
2773
|
+
totalPages: query.totalPages,
|
|
2774
|
+
currentPage: query.currentPage,
|
|
2775
|
+
loading: query.loading,
|
|
2776
|
+
error: query.error,
|
|
2777
|
+
refetch: query.refetch,
|
|
2778
|
+
onPageChange: setPage
|
|
2779
|
+
} : void 0,
|
|
2780
|
+
onSubmit: async (payload) => {
|
|
2781
|
+
const response = await fetch("/api/admin-feedback/submit", {
|
|
2782
|
+
method: "POST",
|
|
2783
|
+
credentials: "include",
|
|
2784
|
+
headers: { "content-type": "application/json" },
|
|
2785
|
+
body: JSON.stringify(payload)
|
|
2786
|
+
});
|
|
2787
|
+
const result = await response.json();
|
|
2788
|
+
if (!result.success) {
|
|
2789
|
+
return { success: false, error: result.error || "Submit failed." };
|
|
2790
|
+
}
|
|
2791
|
+
if (showHistory) {
|
|
2792
|
+
query.refetch();
|
|
2793
|
+
}
|
|
2794
|
+
return { success: true };
|
|
2795
|
+
},
|
|
2796
|
+
onDeleteFeedback: async (id) => {
|
|
2797
|
+
const response = await fetch(`/api/admin-feedback/delete/${id}`, {
|
|
2798
|
+
method: "DELETE",
|
|
2799
|
+
credentials: "include"
|
|
2800
|
+
});
|
|
2801
|
+
const result = await response.json();
|
|
2802
|
+
if (!result.success) {
|
|
2803
|
+
return { success: false, error: result.error || "Delete failed." };
|
|
2804
|
+
}
|
|
2805
|
+
if (showHistory) {
|
|
2806
|
+
query.refetch();
|
|
2807
|
+
}
|
|
2808
|
+
return { success: true };
|
|
2809
|
+
},
|
|
2810
|
+
onUpload: async (formData) => {
|
|
2811
|
+
const response = await fetch("/api/admin-feedback/upload", {
|
|
2812
|
+
method: "POST",
|
|
2813
|
+
credentials: "include",
|
|
2814
|
+
body: formData
|
|
2815
|
+
});
|
|
2816
|
+
const result = await response.json();
|
|
2817
|
+
if (!result.success || typeof result.mediaId !== "number") {
|
|
2818
|
+
return { success: false, error: result.error || "Upload failed." };
|
|
2819
|
+
}
|
|
2820
|
+
return { success: true, mediaId: result.mediaId };
|
|
2821
|
+
},
|
|
2822
|
+
onDeleteScreenshot: async (mediaId) => {
|
|
2823
|
+
const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
|
|
2824
|
+
method: "DELETE",
|
|
2825
|
+
credentials: "include"
|
|
2826
|
+
});
|
|
2827
|
+
const result = await response.json();
|
|
2828
|
+
if (!result.success) {
|
|
2829
|
+
return { success: false, error: result.error || "Delete failed." };
|
|
2830
|
+
}
|
|
2831
|
+
return { success: true };
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
)
|
|
2835
|
+
] });
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
export { AdminFeedbackWidget, FeedbackDetail, FeedbackHistory, FeedbackIndicators, FeedbackWidget, FrontendFeedbackWidget, pathMatchesAllowlist, useCurrentUser, useFeedbackQuery };
|