@matija2209/payload-plugin-admin-feedback 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,895 +1,9 @@
1
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';
2
+ import React from 'react';
3
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
+ import { useAuth, useConfig } from '@payloadcms/ui';
5
5
  import { usePathname } from 'next/navigation';
6
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
7
  var DEFAULT_COLORS = ["#ef4444", "#f97316", "#eab308", "#22c55e", "#06b6d4", "#3b82f6", "#a855f7"];
894
8
  var DEFAULT_HISTORY = {
895
9
  operations: [],
@@ -899,21 +13,17 @@ var DEFAULT_HISTORY = {
899
13
  var createOperationId = () => `annotation-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
900
14
  var getCssSelector = (element) => {
901
15
  if (element.id) {
902
- return `#${CSS.escape(element.id)}`;
16
+ return `#${element.id}`;
903
17
  }
904
18
  const parts = [];
905
19
  let current = element;
906
20
  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;
21
+ let part = current.tagName.toLowerCase();
912
22
  const className = current.className;
913
23
  if (typeof className === "string") {
914
24
  const firstClass = className.split(" ").map((value) => value.trim()).filter(Boolean)[0];
915
25
  if (firstClass) {
916
- part += `.${CSS.escape(firstClass)}`;
26
+ part += `.${firstClass}`;
917
27
  }
918
28
  }
919
29
  const parent = current.parentElement;
@@ -960,7 +70,7 @@ var createEditorImage = async (file) => {
960
70
  width: element.naturalWidth || element.width
961
71
  };
962
72
  };
963
- var canvasToFile2 = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
73
+ var canvasToFile = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
964
74
  const blob = await new Promise((resolve) => {
965
75
  canvas.toBlob((nextBlob) => resolve(nextBlob), "image/png");
966
76
  });
@@ -980,7 +90,7 @@ var waitForRenderedVideoFrame = async (video) => {
980
90
  window.requestAnimationFrame(() => resolve());
981
91
  });
982
92
  };
983
- var captureScreenshotFile2 = async (capturePolicy) => {
93
+ var captureScreenshotFile = async (capturePolicy) => {
984
94
  if (!navigator.mediaDevices?.getDisplayMedia) {
985
95
  throw new Error("Browser does not support screen capture.");
986
96
  }
@@ -1029,7 +139,7 @@ var captureScreenshotFile2 = async (capturePolicy) => {
1029
139
  }
1030
140
  context.drawImage(video, 0, 0, width, height);
1031
141
  return {
1032
- file: await canvasToFile2(canvas),
142
+ file: await canvasToFile(canvas),
1033
143
  surface
1034
144
  };
1035
145
  } finally {
@@ -1132,6 +242,87 @@ var drawOperation = (context, operation) => {
1132
242
  }
1133
243
  };
1134
244
  var isShapeMeaningful = (start, end) => Math.abs(end.x - start.x) > 3 || Math.abs(end.y - start.y) > 3;
245
+ function ChatIcon() {
246
+ return /* @__PURE__ */ jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
247
+ }
248
+ function XIcon({ size = 18 }) {
249
+ return /* @__PURE__ */ jsxs("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
250
+ /* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
251
+ /* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
252
+ ] });
253
+ }
254
+ function CameraIcon() {
255
+ return /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
256
+ /* @__PURE__ */ jsx("path", { d: "M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" }),
257
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "13", r: "4" })
258
+ ] });
259
+ }
260
+ function CursorIcon() {
261
+ return /* @__PURE__ */ jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("path", { d: "M4 4l7.07 17 2.51-7.39L21 11.07z" }) });
262
+ }
263
+ function UploadIcon() {
264
+ return /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
265
+ /* @__PURE__ */ jsx("polyline", { points: "16 16 12 12 8 16" }),
266
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "12", x2: "12", y2: "21" }),
267
+ /* @__PURE__ */ jsx("path", { d: "M20.39 18.39A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.3" })
268
+ ] });
269
+ }
270
+ function SendIcon() {
271
+ return /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
272
+ /* @__PURE__ */ jsx("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
273
+ /* @__PURE__ */ jsx("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
274
+ ] });
275
+ }
276
+ function CheckCircleIcon() {
277
+ return /* @__PURE__ */ jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
278
+ /* @__PURE__ */ jsx("path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14" }),
279
+ /* @__PURE__ */ jsx("polyline", { points: "22 4 12 14.01 9 11.01" })
280
+ ] });
281
+ }
282
+ function PenIcon() {
283
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
284
+ /* @__PURE__ */ jsx("path", { d: "M12 19l7-7 3 3-7 7-3-3z" }),
285
+ /* @__PURE__ */ jsx("path", { d: "M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z" }),
286
+ /* @__PURE__ */ jsx("path", { d: "M2 2l7.586 7.586" }),
287
+ /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "2" })
288
+ ] });
289
+ }
290
+ function RectIcon() {
291
+ return /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }) });
292
+ }
293
+ function ArrowIcon() {
294
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
295
+ /* @__PURE__ */ jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }),
296
+ /* @__PURE__ */ jsx("polyline", { points: "13 5 19 5 19 11" })
297
+ ] });
298
+ }
299
+ function TextIcon() {
300
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
301
+ /* @__PURE__ */ jsx("polyline", { points: "4 7 4 4 20 4 20 7" }),
302
+ /* @__PURE__ */ jsx("line", { x1: "9", y1: "20", x2: "15", y2: "20" }),
303
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "4", x2: "12", y2: "20" })
304
+ ] });
305
+ }
306
+ function UndoIcon() {
307
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
308
+ /* @__PURE__ */ jsx("polyline", { points: "9 14 4 9 9 4" }),
309
+ /* @__PURE__ */ jsx("path", { d: "M20 20v-7a4 4 0 0 0-4-4H4" })
310
+ ] });
311
+ }
312
+ function RedoIcon() {
313
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
314
+ /* @__PURE__ */ jsx("polyline", { points: "15 14 20 9 15 4" }),
315
+ /* @__PURE__ */ jsx("path", { d: "M4 20v-7a4 4 0 0 1 4-4h12" })
316
+ ] });
317
+ }
318
+ function TrashIcon() {
319
+ return /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
320
+ /* @__PURE__ */ jsx("polyline", { points: "3 6 5 6 21 6" }),
321
+ /* @__PURE__ */ jsx("path", { d: "M19 6l-1 14H6L5 6" }),
322
+ /* @__PURE__ */ jsx("path", { d: "M10 11v6M14 11v6" }),
323
+ /* @__PURE__ */ jsx("path", { d: "M9 6V4h6v2" })
324
+ ] });
325
+ }
1135
326
  function FeedbackWidget({
1136
327
  title = "Admin feedback",
1137
328
  submitLabel = "Send",
@@ -1142,42 +333,57 @@ function FeedbackWidget({
1142
333
  capturePolicy = "current-tab-first",
1143
334
  onSubmit,
1144
335
  onUpload,
1145
- onDeleteScreenshot,
1146
- onDeleteFeedback,
1147
- showHistory,
1148
- currentUserId,
1149
- onUpdateFeedback,
1150
- history
336
+ onDeleteScreenshot
1151
337
  }) {
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(() => {
338
+ const [open, setOpen] = React.useState(false);
339
+ const [message, setMessage] = React.useState("");
340
+ const [captureMode, setCaptureMode] = React.useState(false);
341
+ const [captureData, setCaptureData] = React.useState(null);
342
+ const [screenshotId, setScreenshotId] = React.useState(null);
343
+ const [screenshotPreviewUrl, setScreenshotPreviewUrl] = React.useState(null);
344
+ const [uploading, setUploading] = React.useState(false);
345
+ const [deletingScreenshot, setDeletingScreenshot] = React.useState(false);
346
+ const [submitting, setSubmitting] = React.useState(false);
347
+ const [submitted, setSubmitted] = React.useState(false);
348
+ const [currentPath, setCurrentPath] = React.useState("");
349
+ const [capturingScreen, setCapturingScreen] = React.useState(false);
350
+ const [error, setError] = React.useState(null);
351
+ const [notice, setNotice] = React.useState(null);
352
+ const [annotating, setAnnotating] = React.useState(false);
353
+ const [editorImage, setEditorImage] = React.useState(null);
354
+ const [editorHistory, setEditorHistory] = React.useState(DEFAULT_HISTORY);
355
+ const [draftOperation, setDraftOperation] = React.useState(null);
356
+ const [annotationTool, setAnnotationTool] = React.useState("pen");
357
+ const [annotationColor, setAnnotationColor] = React.useState(DEFAULT_COLORS[0]);
358
+ const [annotationSize, setAnnotationSize] = React.useState(4);
359
+ const [textCursor, setTextCursor] = React.useState(null);
360
+ const [inlineText, setInlineText] = React.useState("");
361
+ const hoverTargetRef = React.useRef(null);
362
+ const annotationCanvasRef = React.useRef(null);
363
+ const annotationScrollRef = React.useRef(null);
364
+ const textInputRef = React.useRef(null);
365
+ const pointerIdRef = React.useRef(null);
366
+ const draftOperationRef = React.useRef(null);
367
+ const inlineTextRef = React.useRef("");
368
+ const textCursorRef = React.useRef(null);
369
+ const annotationColorRef = React.useRef(DEFAULT_COLORS[0]);
370
+ const annotationSizeRef = React.useRef(4);
371
+ React.useEffect(() => {
1178
372
  draftOperationRef.current = draftOperation;
1179
373
  }, [draftOperation]);
1180
- React2.useEffect(() => {
374
+ React.useEffect(() => {
375
+ inlineTextRef.current = inlineText;
376
+ }, [inlineText]);
377
+ React.useEffect(() => {
378
+ textCursorRef.current = textCursor;
379
+ }, [textCursor]);
380
+ React.useEffect(() => {
381
+ annotationColorRef.current = annotationColor;
382
+ }, [annotationColor]);
383
+ React.useEffect(() => {
384
+ annotationSizeRef.current = annotationSize;
385
+ }, [annotationSize]);
386
+ React.useEffect(() => {
1181
387
  if (!captureMode) {
1182
388
  return;
1183
389
  }
@@ -1220,7 +426,7 @@ function FeedbackWidget({
1220
426
  document.removeEventListener("click", onClick, true);
1221
427
  };
1222
428
  }, [captureMode]);
1223
- React2.useEffect(() => {
429
+ React.useEffect(() => {
1224
430
  if (!annotating) {
1225
431
  return;
1226
432
  }
@@ -1230,7 +436,7 @@ function FeedbackWidget({
1230
436
  document.body.style.overflow = previousOverflow;
1231
437
  };
1232
438
  }, [annotating]);
1233
- React2.useEffect(() => {
439
+ React.useEffect(() => {
1234
440
  if (!annotating || !editorImage || !annotationCanvasRef.current) {
1235
441
  return;
1236
442
  }
@@ -1251,7 +457,18 @@ function FeedbackWidget({
1251
457
  drawOperation(context, draftOperation);
1252
458
  }
1253
459
  }, [annotating, draftOperation, editorHistory.operations, editorImage]);
1254
- const validateImageFile = React2.useCallback(
460
+ React.useEffect(() => {
461
+ setCurrentPath(window.location.pathname);
462
+ }, []);
463
+ React.useEffect(() => {
464
+ if (!submitted) return;
465
+ const timer = setTimeout(() => {
466
+ setOpen(false);
467
+ setSubmitted(false);
468
+ }, 2500);
469
+ return () => clearTimeout(timer);
470
+ }, [submitted]);
471
+ const validateImageFile = React.useCallback(
1255
472
  (file) => {
1256
473
  if (!screenshotAllowedMimeTypes.includes(file.type)) {
1257
474
  return `Supported image types: ${screenshotAllowedMimeTypes.join(", ")}`;
@@ -1263,7 +480,7 @@ function FeedbackWidget({
1263
480
  },
1264
481
  [screenshotAllowedMimeTypes, screenshotMaxFileSizeBytes]
1265
482
  );
1266
- const uploadImageFile = React2.useCallback(
483
+ const uploadImageFile = React.useCallback(
1267
484
  async (file) => {
1268
485
  if (!onUpload) {
1269
486
  return false;
@@ -1288,14 +505,16 @@ function FeedbackWidget({
1288
505
  },
1289
506
  [onUpload]
1290
507
  );
1291
- const closeAnnotationEditor = React2.useCallback(() => {
508
+ const closeAnnotationEditor = React.useCallback(() => {
1292
509
  setAnnotating(false);
1293
510
  setEditorImage(null);
1294
511
  setEditorHistory(DEFAULT_HISTORY);
1295
512
  setDraftOperation(null);
513
+ setTextCursor(null);
514
+ setInlineText("");
1296
515
  draftOperationRef.current = null;
1297
516
  }, []);
1298
- const handleStartAnnotation = React2.useCallback(
517
+ const handleStartAnnotation = React.useCallback(
1299
518
  async (file) => {
1300
519
  const validationError = validateImageFile(file);
1301
520
  if (validationError) {
@@ -1307,6 +526,8 @@ function FeedbackWidget({
1307
526
  setEditorImage(nextImage);
1308
527
  setEditorHistory(DEFAULT_HISTORY);
1309
528
  setDraftOperation(null);
529
+ setTextCursor(null);
530
+ setInlineText("");
1310
531
  draftOperationRef.current = null;
1311
532
  setAnnotating(true);
1312
533
  setError(null);
@@ -1316,7 +537,7 @@ function FeedbackWidget({
1316
537
  },
1317
538
  [validateImageFile]
1318
539
  );
1319
- React2.useEffect(() => {
540
+ React.useEffect(() => {
1320
541
  if (!open || !allowScreenshotUpload) {
1321
542
  return;
1322
543
  }
@@ -1331,51 +552,37 @@ function FeedbackWidget({
1331
552
  window.addEventListener("paste", onPaste);
1332
553
  return () => window.removeEventListener("paste", onPaste);
1333
554
  }, [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) => {
555
+ const commitOperations = React.useCallback((nextOperations) => {
1366
556
  setEditorHistory((current) => ({
1367
557
  operations: nextOperations,
1368
558
  redoStack: [],
1369
559
  undoStack: [...current.undoStack, current.operations]
1370
560
  }));
1371
561
  }, []);
1372
- const appendOperation = React2.useCallback((operation) => {
562
+ const appendOperation = React.useCallback((operation) => {
1373
563
  setEditorHistory((current) => ({
1374
564
  operations: [...current.operations, operation],
1375
565
  redoStack: [],
1376
566
  undoStack: [...current.undoStack, current.operations]
1377
567
  }));
1378
568
  }, []);
569
+ const commitTextInput = React.useCallback(() => {
570
+ const text = inlineTextRef.current.trim();
571
+ const cursor = textCursorRef.current;
572
+ if (text && cursor) {
573
+ const operation = {
574
+ id: createOperationId(),
575
+ type: "text",
576
+ style: { color: annotationColorRef.current, size: annotationSizeRef.current },
577
+ point: cursor.canvasPoint,
578
+ text
579
+ };
580
+ appendOperation(operation);
581
+ }
582
+ textCursorRef.current = null;
583
+ setTextCursor(null);
584
+ setInlineText("");
585
+ }, [appendOperation]);
1379
586
  const handleUpload = async (event) => {
1380
587
  const file = event.target.files?.[0];
1381
588
  if (file) {
@@ -1386,7 +593,9 @@ function FeedbackWidget({
1386
593
  const handleCaptureScreenshot = async () => {
1387
594
  try {
1388
595
  setError(null);
1389
- const { file, surface } = await captureScreenshotFile2(capturePolicy);
596
+ setCapturingScreen(true);
597
+ await new Promise((resolve) => setTimeout(resolve, 120));
598
+ const { file, surface } = await captureScreenshotFile(capturePolicy);
1390
599
  if (capturePolicy === "current-tab-first") {
1391
600
  if (surface === "browser") {
1392
601
  setNotice("Captured the current tab.");
@@ -1403,6 +612,8 @@ function FeedbackWidget({
1403
612
  await handleStartAnnotation(file);
1404
613
  } catch (nextError) {
1405
614
  setError(nextError instanceof Error ? nextError.message : "Screen capture failed.");
615
+ } finally {
616
+ setCapturingScreen(false);
1406
617
  }
1407
618
  };
1408
619
  const handleUndo = () => {
@@ -1437,42 +648,31 @@ function FeedbackWidget({
1437
648
  }
1438
649
  commitOperations([]);
1439
650
  };
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
651
  const handleCanvasPointerDown = (event) => {
1456
652
  if (!annotationCanvasRef.current) {
1457
653
  return;
1458
654
  }
1459
655
  setError(null);
1460
656
  const canvas = annotationCanvasRef.current;
1461
- const point = getCanvasPoint(event, canvas);
657
+ const canvasPoint = getCanvasPoint(event, canvas);
1462
658
  if (annotationTool === "text") {
1463
- const text = annotationText.trim();
1464
- if (!text) {
1465
- setError("Enter text before placing it on the image.");
1466
- return;
659
+ const existingText = inlineTextRef.current.trim();
660
+ const existingCursor = textCursorRef.current;
661
+ if (existingText && existingCursor) {
662
+ appendOperation({
663
+ id: createOperationId(),
664
+ type: "text",
665
+ style: { color: annotationColorRef.current, size: annotationSizeRef.current },
666
+ point: existingCursor.canvasPoint,
667
+ text: existingText
668
+ });
1467
669
  }
1468
- const operation = {
1469
- id: createOperationId(),
1470
- type: "text",
1471
- style: { color: annotationColor, size: annotationSize },
1472
- point,
1473
- text
1474
- };
1475
- appendOperation(operation);
670
+ const domX = event.clientX;
671
+ const domY = event.clientY;
672
+ inlineTextRef.current = "";
673
+ textCursorRef.current = { domX, domY, canvasPoint };
674
+ setInlineText("");
675
+ setTextCursor({ domX, domY, canvasPoint });
1476
676
  return;
1477
677
  }
1478
678
  event.preventDefault();
@@ -1483,19 +683,19 @@ function FeedbackWidget({
1483
683
  id: createOperationId(),
1484
684
  type: "pen",
1485
685
  style,
1486
- points: [point]
686
+ points: [canvasPoint]
1487
687
  } : annotationTool === "rectangle" ? {
1488
688
  id: createOperationId(),
1489
689
  type: "rectangle",
1490
690
  style,
1491
- start: point,
1492
- end: point
691
+ start: canvasPoint,
692
+ end: canvasPoint
1493
693
  } : {
1494
694
  id: createOperationId(),
1495
695
  type: "arrow",
1496
696
  style,
1497
- start: point,
1498
- end: point
697
+ start: canvasPoint,
698
+ end: canvasPoint
1499
699
  };
1500
700
  draftOperationRef.current = nextDraft;
1501
701
  setDraftOperation(nextDraft);
@@ -1558,7 +758,7 @@ function FeedbackWidget({
1558
758
  }
1559
759
  try {
1560
760
  const previewUrl = annotationCanvasRef.current.toDataURL("image/png");
1561
- const file = await canvasToFile2(annotationCanvasRef.current, editorImage.fileName);
761
+ const file = await canvasToFile(annotationCanvasRef.current, editorImage.fileName);
1562
762
  const uploaded = await uploadImageFile(file);
1563
763
  if (uploaded) {
1564
764
  setScreenshotPreviewUrl(previewUrl);
@@ -1602,7 +802,7 @@ function FeedbackWidget({
1602
802
  setError(null);
1603
803
  const result = await onSubmit({
1604
804
  message: message.trim(),
1605
- pagePath: typeof window !== "undefined" ? window.location.pathname : "/",
805
+ pagePath: currentPath,
1606
806
  selector: captureData?.selector,
1607
807
  selectedText: captureData?.selectedText,
1608
808
  screenshotId,
@@ -1622,92 +822,235 @@ function FeedbackWidget({
1622
822
  setScreenshotId(null);
1623
823
  setScreenshotPreviewUrl(null);
1624
824
  setNotice(null);
1625
- setView("form");
1626
- setOpen(false);
825
+ setSubmitted(true);
1627
826
  };
1628
827
  const currentHasUndo = editorHistory.undoStack.length > 0;
1629
828
  const currentHasRedo = editorHistory.redoStack.length > 0;
1630
829
  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
- ];
830
+ const toolBtn = (tool, icon, label) => /* @__PURE__ */ jsxs(
831
+ "button",
832
+ {
833
+ type: "button",
834
+ title: label,
835
+ onClick: () => setAnnotationTool(tool),
836
+ style: {
837
+ display: "flex",
838
+ alignItems: "center",
839
+ gap: "5px",
840
+ borderRadius: "6px",
841
+ border: annotationTool === tool ? "1px solid #4ade80" : "1px solid #334155",
842
+ background: annotationTool === tool ? "rgba(74,222,128,0.12)" : "#0f172a",
843
+ color: annotationTool === tool ? "#4ade80" : "#94a3b8",
844
+ padding: "5px 9px",
845
+ cursor: "pointer",
846
+ fontSize: "12px",
847
+ fontWeight: 500
848
+ },
849
+ children: [
850
+ icon,
851
+ label
852
+ ]
853
+ },
854
+ tool
855
+ );
856
+ const iconBtn = (onClick, icon, label, disabled = false) => /* @__PURE__ */ jsxs(
857
+ "button",
858
+ {
859
+ type: "button",
860
+ title: label,
861
+ onClick,
862
+ disabled,
863
+ style: {
864
+ display: "flex",
865
+ alignItems: "center",
866
+ gap: "4px",
867
+ borderRadius: "6px",
868
+ border: "1px solid #334155",
869
+ background: "#0f172a",
870
+ color: disabled ? "#475569" : "#94a3b8",
871
+ padding: "5px 9px",
872
+ cursor: disabled ? "not-allowed" : "pointer",
873
+ fontSize: "12px"
874
+ },
875
+ children: [
876
+ icon,
877
+ label
878
+ ]
879
+ }
880
+ );
1639
881
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1640
- /* @__PURE__ */ jsxs(
882
+ /* @__PURE__ */ jsx("style", { children: `
883
+ @keyframes afb-spin-in {
884
+ from { transform: rotate(-90deg) scale(0.7); opacity: 0; }
885
+ to { transform: rotate(0deg) scale(1); opacity: 1; }
886
+ }
887
+ .afb-icon-enter {
888
+ animation: afb-spin-in 0.18s ease forwards;
889
+ }
890
+ ` }),
891
+ /* @__PURE__ */ jsx(
1641
892
  "button",
1642
893
  {
1643
894
  type: "button",
1644
895
  onClick: () => {
1645
- setOpen((value) => !value);
1646
- if (!open) setView("form");
896
+ if (submitted) return;
897
+ setOpen((v) => !v);
1647
898
  },
1648
- style: floatingLauncherStyle,
1649
- children: [
1650
- /* @__PURE__ */ jsx(MessageSquarePlus, { size: 18 }),
1651
- "Feedback"
1652
- ]
899
+ title: open ? "Close feedback" : "Send feedback",
900
+ style: {
901
+ position: "fixed",
902
+ right: "20px",
903
+ bottom: "20px",
904
+ zIndex: 9999,
905
+ width: "48px",
906
+ height: "48px",
907
+ borderRadius: "50%",
908
+ backgroundColor: open ? "#374151" : "#15803d",
909
+ color: "#ffffff",
910
+ border: "none",
911
+ display: "flex",
912
+ alignItems: "center",
913
+ justifyContent: "center",
914
+ cursor: "pointer",
915
+ boxShadow: "0 4px 14px rgba(0,0,0,0.4)",
916
+ transition: "background-color 0.2s ease, transform 0.15s ease",
917
+ visibility: capturingScreen ? "hidden" : "visible"
918
+ },
919
+ children: /* @__PURE__ */ jsx("span", { className: "afb-icon-enter", children: open ? /* @__PURE__ */ jsx(XIcon, { size: 20 }) : /* @__PURE__ */ jsx(ChatIcon, {}) }, open ? "x" : "chat")
1653
920
  }
1654
921
  ),
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 })
922
+ /* @__PURE__ */ jsx(
923
+ "div",
924
+ {
925
+ style: {
926
+ position: "fixed",
927
+ right: "20px",
928
+ bottom: "80px",
929
+ width: "360px",
930
+ background: "#0f172a",
931
+ color: "#f1f5f9",
932
+ borderRadius: "14px",
933
+ border: "1px solid #1e293b",
934
+ padding: "0",
935
+ zIndex: 9999,
936
+ boxShadow: "0 16px 48px rgba(0,0,0,0.55)",
937
+ display: "flex",
938
+ flexDirection: "column",
939
+ maxHeight: "calc(100vh - 110px)",
940
+ opacity: open ? 1 : 0,
941
+ transform: open ? "scale(1) translateY(0)" : "scale(0.92) translateY(8px)",
942
+ pointerEvents: open ? "auto" : "none",
943
+ transformOrigin: "bottom right",
944
+ transition: "opacity 0.18s ease, transform 0.18s ease",
945
+ visibility: capturingScreen ? "hidden" : "visible",
946
+ overflow: "hidden"
947
+ },
948
+ children: submitted ? (
949
+ /* ── Success screen ── */
950
+ /* @__PURE__ */ jsxs(
951
+ "div",
952
+ {
953
+ style: {
954
+ display: "flex",
955
+ flexDirection: "column",
956
+ alignItems: "center",
957
+ justifyContent: "center",
958
+ gap: "12px",
959
+ padding: "40px 24px",
960
+ textAlign: "center",
961
+ color: "#4ade80"
962
+ },
963
+ children: [
964
+ /* @__PURE__ */ jsx(CheckCircleIcon, {}),
965
+ /* @__PURE__ */ jsxs("div", { children: [
966
+ /* @__PURE__ */ jsx("p", { style: { margin: "0 0 4px", fontSize: "16px", fontWeight: 600, color: "#f1f5f9" }, children: "Feedback sent!" }),
967
+ /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "13px", color: "#94a3b8" }, children: "Thank you \u2014 we'll take a look." })
968
+ ] })
969
+ ]
970
+ }
971
+ )
972
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
973
+ /* @__PURE__ */ jsxs(
974
+ "div",
975
+ {
976
+ style: {
977
+ display: "flex",
978
+ alignItems: "center",
979
+ justifyContent: "space-between",
980
+ padding: "12px 14px 10px",
981
+ borderBottom: "1px solid #1e293b"
982
+ },
983
+ children: [
984
+ /* @__PURE__ */ jsxs("div", { children: [
985
+ /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "14px", fontWeight: 600, color: "#f1f5f9" }, children: title }),
986
+ /* @__PURE__ */ jsx("p", { style: { margin: "2px 0 0", fontSize: "11px", color: "#64748b" }, children: currentPath })
987
+ ] }),
988
+ /* @__PURE__ */ jsx(
989
+ "button",
990
+ {
991
+ type: "button",
992
+ onClick: () => setOpen(false),
993
+ title: "Close",
994
+ style: {
995
+ background: "none",
996
+ border: "none",
997
+ color: "#64748b",
998
+ cursor: "pointer",
999
+ padding: "4px",
1000
+ display: "flex",
1001
+ alignItems: "center",
1002
+ borderRadius: "6px"
1003
+ },
1004
+ children: /* @__PURE__ */ jsx(XIcon, { size: 16 })
1005
+ }
1006
+ )
1007
+ ]
1008
+ }
1009
+ ),
1010
+ /* @__PURE__ */ jsxs("div", { style: { padding: "12px 14px", display: "flex", flexDirection: "column", gap: "10px", overflowY: "auto", minHeight: 0 }, children: [
1011
+ /* @__PURE__ */ jsx(
1012
+ "textarea",
1013
+ {
1014
+ value: message,
1015
+ onChange: (event) => setMessage(event.target.value),
1016
+ rows: 5,
1017
+ placeholder: "Describe the issue or share your thoughts\u2026",
1018
+ style: {
1019
+ width: "100%",
1020
+ borderRadius: "8px",
1021
+ border: "1px solid #1e293b",
1022
+ background: "#1e293b",
1023
+ color: "#f1f5f9",
1024
+ padding: "10px",
1025
+ resize: "vertical",
1026
+ fontSize: "13px",
1027
+ lineHeight: "1.5",
1028
+ outline: "none",
1029
+ boxSizing: "border-box"
1687
1030
  }
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: [
1031
+ }
1032
+ ),
1033
+ allowScreenshotUpload && onUpload ? /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" }, children: [
1702
1034
  /* @__PURE__ */ jsxs(
1703
1035
  "button",
1704
1036
  {
1705
1037
  type: "button",
1706
- onClick: () => setView("form"),
1707
- style: { ...buttonStyle("secondary", { active: view === "form", compact: true }), flex: 1 },
1038
+ onClick: handleCaptureScreenshot,
1039
+ style: {
1040
+ display: "flex",
1041
+ alignItems: "center",
1042
+ gap: "5px",
1043
+ borderRadius: "7px",
1044
+ border: "1px solid #1e293b",
1045
+ background: "#1e293b",
1046
+ color: "#94a3b8",
1047
+ padding: "5px 9px",
1048
+ cursor: "pointer",
1049
+ fontSize: "12px"
1050
+ },
1708
1051
  children: [
1709
- /* @__PURE__ */ jsx(MessageSquare, { size: 15 }),
1710
- "New"
1052
+ /* @__PURE__ */ jsx(CameraIcon, {}),
1053
+ "Capture screen"
1711
1054
  ]
1712
1055
  }
1713
1056
  ),
@@ -1715,311 +1058,186 @@ function FeedbackWidget({
1715
1058
  "button",
1716
1059
  {
1717
1060
  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
- {
1061
+ onClick: () => setCaptureMode((v) => !v),
1753
1062
  style: {
1754
1063
  display: "flex",
1755
- alignItems: "flex-start",
1756
- justifyContent: "space-between",
1757
- gap: "10px",
1758
- flexWrap: "wrap",
1759
- marginBottom: "10px"
1064
+ alignItems: "center",
1065
+ gap: "5px",
1066
+ borderRadius: "7px",
1067
+ border: captureMode ? "1px solid #4ade80" : "1px solid #1e293b",
1068
+ background: captureMode ? "rgba(74,222,128,0.08)" : "#1e293b",
1069
+ color: captureMode ? "#4ade80" : "#94a3b8",
1070
+ padding: "5px 9px",
1071
+ cursor: "pointer",
1072
+ fontSize: "12px"
1760
1073
  },
1761
1074
  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
- ] })
1075
+ /* @__PURE__ */ jsx(CursorIcon, {}),
1076
+ captureMode ? "Click an element\u2026" : "Capture element"
1781
1077
  ]
1782
1078
  }
1783
1079
  ),
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
1080
  /* @__PURE__ */ jsxs(
1870
- "div",
1081
+ "label",
1871
1082
  {
1872
1083
  style: {
1873
1084
  display: "flex",
1874
1085
  alignItems: "center",
1875
- justifyContent: "space-between",
1876
- gap: "10px",
1877
- marginBottom: screenshotPreviewUrl ? "10px" : 0
1086
+ gap: "5px",
1087
+ borderRadius: "7px",
1088
+ border: "1px solid #1e293b",
1089
+ background: "#1e293b",
1090
+ color: "#94a3b8",
1091
+ padding: "5px 9px",
1092
+ cursor: "pointer",
1093
+ fontSize: "12px"
1878
1094
  },
1879
1095
  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;
1096
+ /* @__PURE__ */ jsx(UploadIcon, {}),
1097
+ uploading ? "Uploading\u2026" : uploadLabel,
1098
+ /* @__PURE__ */ jsx(
1099
+ "input",
1100
+ {
1101
+ type: "file",
1102
+ accept: screenshotAllowedMimeTypes.join(","),
1103
+ onChange: handleUpload,
1104
+ hidden: true
1105
+ }
1106
+ )
1107
+ ]
1959
1108
  }
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(
1109
+ )
1110
+ ] }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" }, children: /* @__PURE__ */ jsxs(
1986
1111
  "button",
1987
1112
  {
1988
1113
  type: "button",
1989
- onClick: () => {
1990
- setOpen(false);
1991
- setView("form");
1992
- },
1114
+ onClick: () => setCaptureMode((v) => !v),
1993
1115
  style: {
1994
- ...buttonStyle("ghost", { compact: true }),
1995
- flex: "1 1 132px"
1116
+ display: "flex",
1117
+ alignItems: "center",
1118
+ gap: "5px",
1119
+ borderRadius: "7px",
1120
+ border: captureMode ? "1px solid #4ade80" : "1px solid #1e293b",
1121
+ background: captureMode ? "rgba(74,222,128,0.08)" : "#1e293b",
1122
+ color: captureMode ? "#4ade80" : "#94a3b8",
1123
+ padding: "5px 9px",
1124
+ cursor: "pointer",
1125
+ fontSize: "12px"
1996
1126
  },
1997
1127
  children: [
1998
- /* @__PURE__ */ jsx(X, { size: 15 }),
1999
- "Close"
1128
+ /* @__PURE__ */ jsx(CursorIcon, {}),
1129
+ captureMode ? "Click an element\u2026" : "Capture element"
2000
1130
  ]
2001
1131
  }
2002
- ),
2003
- /* @__PURE__ */ jsxs(
2004
- "button",
1132
+ ) }),
1133
+ allowScreenshotUpload && onUpload ? /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "11px", color: "#475569" }, children: "Paste an image with Ctrl/Cmd+V or capture the current tab first." }) : null,
1134
+ captureData ? /* @__PURE__ */ jsxs("p", { style: { margin: 0, fontSize: "11px", color: "#64748b", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: [
1135
+ "Element: ",
1136
+ /* @__PURE__ */ jsx("code", { style: { color: "#94a3b8" }, children: captureData.selector })
1137
+ ] }) : null,
1138
+ screenshotId ? /* @__PURE__ */ jsxs(
1139
+ "div",
2005
1140
  {
2006
- type: "button",
2007
- onClick: handleSubmit,
2008
- disabled: submitting,
2009
1141
  style: {
2010
- ...buttonStyle("primary", { compact: true, disabled: submitting }),
2011
- flex: "1 1 132px"
1142
+ borderRadius: "10px",
1143
+ border: "1px solid #1e293b",
1144
+ background: "#0a0f1e",
1145
+ padding: "8px"
2012
1146
  },
2013
1147
  children: [
2014
- /* @__PURE__ */ jsx(SendHorizontal, { size: 15 }),
2015
- submitting ? "Sending..." : submitLabel
1148
+ screenshotPreviewUrl ? /* @__PURE__ */ jsx("div", { style: { marginBottom: "8px", borderRadius: "6px", overflow: "hidden" }, children: /* @__PURE__ */ jsx(
1149
+ "img",
1150
+ {
1151
+ src: screenshotPreviewUrl,
1152
+ alt: "Annotated screenshot preview",
1153
+ style: { width: "100%", height: "auto", display: "block" }
1154
+ }
1155
+ ) }) : null,
1156
+ /* @__PURE__ */ jsxs(
1157
+ "div",
1158
+ {
1159
+ style: {
1160
+ display: "flex",
1161
+ justifyContent: "space-between",
1162
+ alignItems: "center"
1163
+ },
1164
+ children: [
1165
+ /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "11px", color: "#64748b" }, children: "Screenshot attached" }),
1166
+ /* @__PURE__ */ jsxs(
1167
+ "button",
1168
+ {
1169
+ type: "button",
1170
+ onClick: handleRemoveScreenshot,
1171
+ disabled: deletingScreenshot,
1172
+ style: {
1173
+ display: "flex",
1174
+ alignItems: "center",
1175
+ gap: "4px",
1176
+ borderRadius: "6px",
1177
+ border: "1px solid #7f1d1d",
1178
+ background: "#450a0a",
1179
+ color: "#fca5a5",
1180
+ padding: "3px 8px",
1181
+ cursor: deletingScreenshot ? "wait" : "pointer",
1182
+ opacity: deletingScreenshot ? 0.7 : 1,
1183
+ fontSize: "11px"
1184
+ },
1185
+ children: [
1186
+ /* @__PURE__ */ jsx(TrashIcon, {}),
1187
+ deletingScreenshot ? "Removing\u2026" : "Remove"
1188
+ ]
1189
+ }
1190
+ )
1191
+ ]
1192
+ }
1193
+ )
2016
1194
  ]
2017
1195
  }
2018
- )
2019
- ]
2020
- }
2021
- ) : null
2022
- ] }) : null,
1196
+ ) : null,
1197
+ notice ? /* @__PURE__ */ jsx("p", { style: { margin: 0, color: "#93c5fd", fontSize: "12px" }, children: notice }) : null,
1198
+ error ? /* @__PURE__ */ jsx("p", { style: { margin: 0, color: "#fca5a5", fontSize: "12px" }, children: error }) : null
1199
+ ] }),
1200
+ /* @__PURE__ */ jsx(
1201
+ "div",
1202
+ {
1203
+ style: {
1204
+ display: "flex",
1205
+ justifyContent: "flex-end",
1206
+ padding: "10px 14px 14px",
1207
+ borderTop: "1px solid #1e293b"
1208
+ },
1209
+ children: /* @__PURE__ */ jsxs(
1210
+ "button",
1211
+ {
1212
+ type: "button",
1213
+ onClick: handleSubmit,
1214
+ disabled: submitting,
1215
+ style: {
1216
+ display: "flex",
1217
+ alignItems: "center",
1218
+ gap: "7px",
1219
+ borderRadius: "8px",
1220
+ border: "none",
1221
+ background: "#15803d",
1222
+ color: "#f1f5f9",
1223
+ padding: "8px 16px",
1224
+ cursor: submitting ? "wait" : "pointer",
1225
+ fontWeight: 600,
1226
+ fontSize: "13px",
1227
+ opacity: submitting ? 0.75 : 1,
1228
+ transition: "opacity 0.15s ease"
1229
+ },
1230
+ children: [
1231
+ /* @__PURE__ */ jsx(SendIcon, {}),
1232
+ submitting ? "Sending\u2026" : submitLabel
1233
+ ]
1234
+ }
1235
+ )
1236
+ }
1237
+ )
1238
+ ] })
1239
+ }
1240
+ ),
2023
1241
  annotating && editorImage ? /* @__PURE__ */ jsxs(
2024
1242
  "div",
2025
1243
  {
@@ -2027,8 +1245,8 @@ function FeedbackWidget({
2027
1245
  position: "fixed",
2028
1246
  inset: "0",
2029
1247
  zIndex: 1e4,
2030
- background: "rgba(2, 8, 23, 0.96)",
2031
- color: theme.text,
1248
+ background: "rgba(3, 7, 18, 0.96)",
1249
+ color: "#f8fafc",
2032
1250
  display: "flex",
2033
1251
  flexDirection: "column"
2034
1252
  },
@@ -2039,42 +1257,24 @@ function FeedbackWidget({
2039
1257
  style: {
2040
1258
  display: "flex",
2041
1259
  flexWrap: "wrap",
2042
- gap: "12px",
2043
- alignItems: "flex-start",
1260
+ gap: "10px",
1261
+ alignItems: "center",
2044
1262
  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%)"
1263
+ padding: "10px 16px",
1264
+ borderBottom: "1px solid rgba(148, 163, 184, 0.15)",
1265
+ background: "rgba(15, 23, 42, 0.97)"
2048
1266
  },
2049
1267
  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
- )) })
1268
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "12px" }, children: [
1269
+ /* @__PURE__ */ jsx("strong", { style: { fontSize: "14px", color: "#f1f5f9" }, children: "Annotate screenshot" }),
1270
+ /* @__PURE__ */ jsx("span", { style: { fontSize: "11px", color: "#475569" }, children: editorImage.fileName })
2075
1271
  ] }),
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: [
1272
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: "6px", alignItems: "center" }, children: [
1273
+ toolBtn("pen", /* @__PURE__ */ jsx(PenIcon, {}), "Pen"),
1274
+ toolBtn("rectangle", /* @__PURE__ */ jsx(RectIcon, {}), "Rect"),
1275
+ toolBtn("arrow", /* @__PURE__ */ jsx(ArrowIcon, {}), "Arrow"),
1276
+ toolBtn("text", /* @__PURE__ */ jsx(TextIcon, {}), "Text"),
1277
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "4px", alignItems: "center" }, children: [
2078
1278
  DEFAULT_COLORS.map((color) => /* @__PURE__ */ jsx(
2079
1279
  "button",
2080
1280
  {
@@ -2082,12 +1282,13 @@ function FeedbackWidget({
2082
1282
  onClick: () => setAnnotationColor(color),
2083
1283
  "aria-label": `Select ${color} color`,
2084
1284
  style: {
2085
- width: "28px",
2086
- height: "28px",
2087
- borderRadius: "999px",
2088
- border: annotationColor === color ? "2px solid #f8fafc" : `1px solid ${theme.borderStrong}`,
1285
+ width: "20px",
1286
+ height: "20px",
1287
+ borderRadius: "50%",
1288
+ border: annotationColor === color ? "2px solid #f8fafc" : "1px solid #334155",
2089
1289
  background: color,
2090
- cursor: "pointer"
1290
+ cursor: "pointer",
1291
+ flexShrink: 0
2091
1292
  }
2092
1293
  },
2093
1294
  color
@@ -2097,15 +1298,15 @@ function FeedbackWidget({
2097
1298
  {
2098
1299
  type: "color",
2099
1300
  value: annotationColor,
2100
- onChange: (event) => setAnnotationColor(event.target.value),
2101
- "aria-label": "Annotation color",
2102
- style: { width: "36px", height: "36px", border: "none", background: "transparent" }
1301
+ onChange: (e) => setAnnotationColor(e.target.value),
1302
+ "aria-label": "Custom color",
1303
+ title: "Custom color",
1304
+ style: { width: "28px", height: "28px", border: "none", background: "transparent", cursor: "pointer" }
2103
1305
  }
2104
1306
  )
2105
1307
  ] }),
2106
- /* @__PURE__ */ jsxs("label", { style: { display: "flex", alignItems: "center", gap: "10px", fontSize: "12px", color: theme.textSoft }, children: [
2107
- "Size ",
2108
- annotationSize,
1308
+ /* @__PURE__ */ jsxs("label", { style: { display: "flex", alignItems: "center", gap: "6px", fontSize: "11px", color: "#64748b" }, children: [
1309
+ "Size",
2109
1310
  /* @__PURE__ */ jsx(
2110
1311
  "input",
2111
1312
  {
@@ -2113,115 +1314,97 @@ function FeedbackWidget({
2113
1314
  min: 1,
2114
1315
  max: 18,
2115
1316
  value: annotationSize,
2116
- onChange: (event) => setAnnotationSize(Number(event.target.value)),
2117
- "aria-label": "Annotation size"
1317
+ onChange: (e) => setAnnotationSize(Number(e.target.value)),
1318
+ "aria-label": "Stroke size",
1319
+ style: { width: "72px" }
2118
1320
  }
2119
1321
  )
2120
1322
  ] }),
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
- ] })
1323
+ iconBtn(handleUndo, /* @__PURE__ */ jsx(UndoIcon, {}), "Undo", !currentHasUndo),
1324
+ iconBtn(handleRedo, /* @__PURE__ */ jsx(RedoIcon, {}), "Redo", !currentHasRedo),
1325
+ iconBtn(handleClearAnnotations, /* @__PURE__ */ jsx(TrashIcon, {}), "Clear", !hasAnnotations)
2190
1326
  ] })
2191
1327
  ]
2192
1328
  }
2193
1329
  ),
2194
- /* @__PURE__ */ jsx(
1330
+ /* @__PURE__ */ jsxs(
2195
1331
  "div",
2196
1332
  {
1333
+ ref: annotationScrollRef,
2197
1334
  style: {
2198
1335
  flex: 1,
2199
1336
  overflow: "auto",
2200
- padding: "18px",
1337
+ padding: "16px",
2201
1338
  display: "flex",
2202
- alignItems: "center",
2203
- justifyContent: "center"
1339
+ alignItems: "flex-start",
1340
+ justifyContent: "center",
1341
+ position: "relative"
2204
1342
  },
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"
1343
+ children: [
1344
+ /* @__PURE__ */ jsx(
1345
+ "canvas",
1346
+ {
1347
+ ref: annotationCanvasRef,
1348
+ onPointerDown: handleCanvasPointerDown,
1349
+ onPointerMove: handleCanvasPointerMove,
1350
+ onPointerUp: handleCanvasPointerUp,
1351
+ onPointerCancel: handleCanvasPointerCancel,
1352
+ style: {
1353
+ width: "min(100%, 1400px)",
1354
+ height: "auto",
1355
+ display: "block",
1356
+ borderRadius: "12px",
1357
+ background: "#ffffff",
1358
+ boxShadow: "0 24px 80px rgba(15, 23, 42, 0.6)",
1359
+ touchAction: "none",
1360
+ cursor: annotationTool === "text" ? "text" : "crosshair"
1361
+ }
2222
1362
  }
2223
- }
2224
- )
1363
+ ),
1364
+ textCursor ? /* @__PURE__ */ jsx(
1365
+ "input",
1366
+ {
1367
+ autoFocus: true,
1368
+ ref: textInputRef,
1369
+ type: "text",
1370
+ value: inlineText,
1371
+ onChange: (e) => {
1372
+ inlineTextRef.current = e.target.value;
1373
+ setInlineText(e.target.value);
1374
+ },
1375
+ onKeyDown: (e) => {
1376
+ if (e.key === "Enter") {
1377
+ e.preventDefault();
1378
+ commitTextInput();
1379
+ }
1380
+ if (e.key === "Escape") {
1381
+ textCursorRef.current = null;
1382
+ setTextCursor(null);
1383
+ setInlineText("");
1384
+ inlineTextRef.current = "";
1385
+ }
1386
+ },
1387
+ placeholder: "Type \u2192 Enter to place",
1388
+ style: {
1389
+ position: "fixed",
1390
+ left: textCursor.domX,
1391
+ top: textCursor.domY,
1392
+ minWidth: "180px",
1393
+ background: "rgba(15, 23, 42, 0.92)",
1394
+ color: annotationColor,
1395
+ border: "1px dashed rgba(255,255,255,0.6)",
1396
+ borderRadius: "4px",
1397
+ padding: "4px 8px",
1398
+ fontSize: `${Math.max(14, annotationSize * 4)}px`,
1399
+ fontWeight: 600,
1400
+ outline: "none",
1401
+ zIndex: 10002,
1402
+ backdropFilter: "blur(6px)",
1403
+ boxShadow: "0 2px 12px rgba(0,0,0,0.4)"
1404
+ }
1405
+ }
1406
+ ) : null
1407
+ ]
2225
1408
  }
2226
1409
  ),
2227
1410
  /* @__PURE__ */ jsxs(
@@ -2233,27 +1416,53 @@ function FeedbackWidget({
2233
1416
  alignItems: "center",
2234
1417
  gap: "12px",
2235
1418
  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%)"
1419
+ padding: "10px 16px",
1420
+ borderTop: "1px solid rgba(148, 163, 184, 0.15)",
1421
+ background: "rgba(15, 23, 42, 0.97)"
2239
1422
  },
2240
1423
  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
- ] }),
1424
+ annotationTool === "text" ? /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: "Click on the image to place text at that position." }) : /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: "Draw on the image, then save when done." }),
1425
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "8px" }, children: [
1426
+ /* @__PURE__ */ jsx(
1427
+ "button",
1428
+ {
1429
+ type: "button",
1430
+ onClick: closeAnnotationEditor,
1431
+ style: {
1432
+ borderRadius: "8px",
1433
+ border: "1px solid #334155",
1434
+ background: "#0f172a",
1435
+ color: "#94a3b8",
1436
+ padding: "7px 14px",
1437
+ cursor: "pointer",
1438
+ fontSize: "13px"
1439
+ },
1440
+ children: "Cancel"
1441
+ }
1442
+ ),
2247
1443
  /* @__PURE__ */ jsxs(
2248
1444
  "button",
2249
1445
  {
2250
1446
  type: "button",
2251
1447
  onClick: handleApplyAnnotation,
2252
1448
  disabled: uploading,
2253
- style: buttonStyle("primary", { disabled: uploading }),
1449
+ style: {
1450
+ display: "flex",
1451
+ alignItems: "center",
1452
+ gap: "6px",
1453
+ borderRadius: "8px",
1454
+ border: "none",
1455
+ background: "#15803d",
1456
+ color: "#f1f5f9",
1457
+ padding: "7px 14px",
1458
+ cursor: uploading ? "wait" : "pointer",
1459
+ opacity: uploading ? 0.8 : 1,
1460
+ fontWeight: 600,
1461
+ fontSize: "13px"
1462
+ },
2254
1463
  children: [
2255
- /* @__PURE__ */ jsx(Upload, { size: 15 }),
2256
- uploading ? "Uploading..." : "Save screenshot"
1464
+ /* @__PURE__ */ jsx(SendIcon, {}),
1465
+ uploading ? "Uploading\u2026" : "Save screenshot"
2257
1466
  ]
2258
1467
  }
2259
1468
  )
@@ -2266,439 +1475,125 @@ function FeedbackWidget({
2266
1475
  ) : null
2267
1476
  ] });
2268
1477
  }
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]);
1478
+
1479
+ // src/client/api.ts
1480
+ var readJson = async (response) => {
1481
+ try {
1482
+ return await response.json();
1483
+ } catch {
1484
+ return { success: false, error: `Request failed (${response.status}).` };
1485
+ }
1486
+ };
1487
+ var errorOf = (body, fallback) => typeof body.error === "string" && body.error ? body.error : fallback;
1488
+ var createFeedbackApi = (apiBase = "/api") => {
1489
+ const base = `${apiBase.replace(/\/+$/, "")}/admin-feedback`;
1490
+ const deleteTokens = /* @__PURE__ */ new Map();
2325
1491
  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",
1492
+ submit: async (payload) => {
1493
+ const response = await fetch(`${base}/submit`, {
1494
+ method: "POST",
2378
1495
  credentials: "include",
2379
1496
  headers: { "content-type": "application/json" },
2380
- body: JSON.stringify(data)
1497
+ body: JSON.stringify(payload)
2381
1498
  });
2382
- const result = await response.json();
2383
- if (!result.success) {
2384
- return false;
1499
+ const body = await readJson(response);
1500
+ if (!response.ok || body.success !== true) {
1501
+ return { success: false, error: errorOf(body, "Submit failed.") };
2385
1502
  }
2386
- return true;
1503
+ deleteTokens.clear();
1504
+ return { success: true };
2387
1505
  },
2388
- []
2389
- );
1506
+ upload: async (formData) => {
1507
+ const response = await fetch(`${base}/upload`, {
1508
+ method: "POST",
1509
+ credentials: "include",
1510
+ body: formData
1511
+ });
1512
+ const body = await readJson(response);
1513
+ if (!response.ok || body.success !== true || typeof body.mediaId !== "number") {
1514
+ return { success: false, error: errorOf(body, "Upload failed.") };
1515
+ }
1516
+ if (typeof body.deleteToken === "string") {
1517
+ deleteTokens.set(body.mediaId, body.deleteToken);
1518
+ }
1519
+ return { success: true, mediaId: body.mediaId };
1520
+ },
1521
+ deleteScreenshot: async (mediaId) => {
1522
+ const token = deleteTokens.get(mediaId);
1523
+ if (!token) {
1524
+ return { success: false, error: "This screenshot can no longer be removed." };
1525
+ }
1526
+ const response = await fetch(`${base}/upload/${mediaId}`, {
1527
+ method: "DELETE",
1528
+ credentials: "include",
1529
+ headers: { "x-feedback-delete-token": token }
1530
+ });
1531
+ const body = await readJson(response);
1532
+ if (!response.ok || body.success !== true) {
1533
+ return { success: false, error: errorOf(body, "Delete failed.") };
1534
+ }
1535
+ deleteTokens.delete(mediaId);
1536
+ return { success: true };
1537
+ }
1538
+ };
1539
+ };
1540
+ function AdminFeedbackWidget({
1541
+ title = "Admin feedback",
1542
+ submitLabel = "Send",
1543
+ uploadLabel = "Upload image",
1544
+ allowScreenshotUpload = true,
1545
+ screenshotMaxFileSizeBytes,
1546
+ screenshotAllowedMimeTypes,
1547
+ capturePolicy,
1548
+ apiRoute = "/api"
1549
+ }) {
1550
+ const api = React.useMemo(() => createFeedbackApi(apiRoute), [apiRoute]);
2390
1551
  return /* @__PURE__ */ jsx(
2391
1552
  FeedbackWidget,
2392
1553
  {
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
- }
1554
+ title,
1555
+ submitLabel,
1556
+ uploadLabel,
1557
+ allowScreenshotUpload,
1558
+ screenshotMaxFileSizeBytes,
1559
+ screenshotAllowedMimeTypes,
1560
+ capturePolicy,
1561
+ onSubmit: api.submit,
1562
+ onUpload: allowScreenshotUpload ? api.upload : void 0,
1563
+ onDeleteScreenshot: api.deleteScreenshot
2458
1564
  }
2459
1565
  );
2460
1566
  }
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;
1567
+ function AdminFeedbackProvider({
1568
+ children,
1569
+ collectionSlug = "admin-feedback",
1570
+ ...widgetProps
1571
+ }) {
1572
+ const { permissions, user } = useAuth();
1573
+ const { config } = useConfig();
1574
+ const canCreate = Boolean(
1575
+ user && permissions?.collections?.[collectionSlug]?.create
1576
+ );
1577
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1578
+ children,
1579
+ canCreate ? /* @__PURE__ */ jsx(AdminFeedbackWidget, { ...widgetProps, apiRoute: config.routes?.api || "/api" }) : null
1580
+ ] });
1581
+ }
1582
+
1583
+ // src/tenant/extractTenantSlug.ts
1584
+ var extractTenantSlugFromPathname = (pathname, pathMarkers) => {
1585
+ if (pathMarkers.length === 0) {
1586
+ return null;
1587
+ }
1588
+ const segments = pathname.split("?")[0].split("/").filter(Boolean);
1589
+ for (const marker of pathMarkers) {
1590
+ const markerIndex = segments.indexOf(marker);
1591
+ if (markerIndex > 0) {
1592
+ return segments[markerIndex - 1] ?? null;
2564
1593
  }
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
- }, []);
1594
+ }
2700
1595
  return null;
2701
- }
1596
+ };
2702
1597
 
2703
1598
  // src/client/routeMatcher.ts
2704
1599
  var escapeRegex = (input) => input.replace(/[.+^${}()|[\]\\]/g, "\\$&");
@@ -2729,110 +1624,36 @@ function FrontendFeedbackWidget({
2729
1624
  title = "Feedback",
2730
1625
  submitLabel = "Send",
2731
1626
  uploadLabel = "Upload image",
2732
- showIndicators = false,
2733
- showHistory = false
1627
+ tenantPathMarkers = [],
1628
+ tenantFormDataKey = "tenant",
1629
+ apiRoute = "/api"
2734
1630
  }) {
2735
1631
  const pathname = usePathname();
1632
+ const api = React.useMemo(() => createFeedbackApi(apiRoute), [apiRoute]);
2736
1633
  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
1634
  if (!pathMatchesAllowlist(normalizedPathname, include)) {
2757
1635
  return null;
2758
1636
  }
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." };
1637
+ return /* @__PURE__ */ jsx(
1638
+ FeedbackWidget,
1639
+ {
1640
+ title,
1641
+ submitLabel,
1642
+ uploadLabel,
1643
+ allowScreenshotUpload: true,
1644
+ onSubmit: api.submit,
1645
+ onUpload: async (formData) => {
1646
+ if (tenantPathMarkers.length > 0) {
1647
+ const tenantSlug = extractTenantSlugFromPathname(pathname, tenantPathMarkers);
1648
+ if (tenantSlug) {
1649
+ formData.set(tenantFormDataKey, tenantSlug);
2830
1650
  }
2831
- return { success: true };
2832
1651
  }
2833
- }
2834
- )
2835
- ] });
1652
+ return api.upload(formData);
1653
+ },
1654
+ onDeleteScreenshot: api.deleteScreenshot
1655
+ }
1656
+ );
2836
1657
  }
2837
1658
 
2838
- export { AdminFeedbackWidget, FeedbackDetail, FeedbackHistory, FeedbackIndicators, FeedbackWidget, FrontendFeedbackWidget, pathMatchesAllowlist, useCurrentUser, useFeedbackQuery };
1659
+ export { AdminFeedbackProvider, AdminFeedbackWidget, FeedbackWidget, FrontendFeedbackWidget };