@david-xpn/llm-ui-feedback 0.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.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/index.d.mts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +992 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +952 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
// src/components/FeedbackWidget.tsx
|
|
2
|
+
import { useReducer, useCallback as useCallback3, useState as useState3, useEffect as useEffect2 } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
|
|
5
|
+
// src/utils/color.ts
|
|
6
|
+
function getContrastColor(hexColor) {
|
|
7
|
+
const hex = hexColor.replace("#", "");
|
|
8
|
+
const fullHex = hex.length === 3 ? hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] : hex;
|
|
9
|
+
const r = parseInt(fullHex.substring(0, 2), 16) / 255;
|
|
10
|
+
const g = parseInt(fullHex.substring(2, 4), 16) / 255;
|
|
11
|
+
const b = parseInt(fullHex.substring(4, 6), 16) / 255;
|
|
12
|
+
const toLinear = (c) => c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
13
|
+
const luminance = 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
14
|
+
return luminance > 0.179 ? "#000000" : "#ffffff";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/components/FloatingButton.tsx
|
|
18
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
|
+
function FloatingButton({ onClick, active, position, buttonColor }) {
|
|
20
|
+
const isBottom = position.includes("bottom");
|
|
21
|
+
const isRight = position.includes("right");
|
|
22
|
+
return /* @__PURE__ */ jsx(
|
|
23
|
+
"button",
|
|
24
|
+
{
|
|
25
|
+
onClick,
|
|
26
|
+
"aria-label": active ? "Cancel feedback" : "Add feedback",
|
|
27
|
+
style: {
|
|
28
|
+
position: "fixed",
|
|
29
|
+
[isBottom ? "bottom" : "top"]: 24,
|
|
30
|
+
[isRight ? "right" : "left"]: 24,
|
|
31
|
+
zIndex: 99999,
|
|
32
|
+
width: 48,
|
|
33
|
+
height: 48,
|
|
34
|
+
borderRadius: "50%",
|
|
35
|
+
border: "none",
|
|
36
|
+
background: active ? "#ef4444" : buttonColor,
|
|
37
|
+
color: active ? "#fff" : getContrastColor(buttonColor),
|
|
38
|
+
fontSize: 24,
|
|
39
|
+
cursor: "pointer",
|
|
40
|
+
display: "flex",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
justifyContent: "center",
|
|
43
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.25)",
|
|
44
|
+
transition: "background 0.15s, transform 0.15s",
|
|
45
|
+
transform: active ? "rotate(45deg)" : "none"
|
|
46
|
+
},
|
|
47
|
+
children: "+"
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/components/PickOverlay.tsx
|
|
53
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
54
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
55
|
+
var WIDGET_CONTAINER_ID = "llm-ui-feedback-root";
|
|
56
|
+
function getElementBeneath(x, y) {
|
|
57
|
+
const container = document.getElementById(WIDGET_CONTAINER_ID);
|
|
58
|
+
if (container) container.style.display = "none";
|
|
59
|
+
const el = document.elementFromPoint(x, y);
|
|
60
|
+
if (container) container.style.display = "";
|
|
61
|
+
if (el && container?.contains(el)) return null;
|
|
62
|
+
return el;
|
|
63
|
+
}
|
|
64
|
+
function PickOverlay({ onPick, onCancel }) {
|
|
65
|
+
const lastOutlinedRef = useRef(null);
|
|
66
|
+
const clearOutline = useCallback(() => {
|
|
67
|
+
if (lastOutlinedRef.current) {
|
|
68
|
+
lastOutlinedRef.current.style.outline = "";
|
|
69
|
+
lastOutlinedRef.current = null;
|
|
70
|
+
}
|
|
71
|
+
}, []);
|
|
72
|
+
const handleMouseMove = useCallback((e) => {
|
|
73
|
+
const el = getElementBeneath(e.clientX, e.clientY);
|
|
74
|
+
clearOutline();
|
|
75
|
+
if (el && el instanceof HTMLElement) {
|
|
76
|
+
el.style.outline = "2px solid #3b82f6";
|
|
77
|
+
lastOutlinedRef.current = el;
|
|
78
|
+
}
|
|
79
|
+
}, [clearOutline]);
|
|
80
|
+
const handleClick = useCallback(
|
|
81
|
+
(e) => {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
e.stopPropagation();
|
|
84
|
+
clearOutline();
|
|
85
|
+
const el = getElementBeneath(e.clientX, e.clientY);
|
|
86
|
+
if (el) {
|
|
87
|
+
onPick(el, e.clientX, e.clientY);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
[onPick, clearOutline]
|
|
91
|
+
);
|
|
92
|
+
const handleKeyDown = useCallback(
|
|
93
|
+
(e) => {
|
|
94
|
+
if (e.key === "Escape") {
|
|
95
|
+
clearOutline();
|
|
96
|
+
onCancel();
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
[onCancel, clearOutline]
|
|
100
|
+
);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
document.addEventListener("mousemove", handleMouseMove, true);
|
|
103
|
+
document.addEventListener("click", handleClick, true);
|
|
104
|
+
document.addEventListener("keydown", handleKeyDown, true);
|
|
105
|
+
return () => {
|
|
106
|
+
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
107
|
+
document.removeEventListener("click", handleClick, true);
|
|
108
|
+
document.removeEventListener("keydown", handleKeyDown, true);
|
|
109
|
+
if (lastOutlinedRef.current) {
|
|
110
|
+
lastOutlinedRef.current.style.outline = "";
|
|
111
|
+
lastOutlinedRef.current = null;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}, [handleMouseMove, handleClick, handleKeyDown]);
|
|
115
|
+
return /* @__PURE__ */ jsxs(
|
|
116
|
+
"div",
|
|
117
|
+
{
|
|
118
|
+
style: {
|
|
119
|
+
position: "fixed",
|
|
120
|
+
top: 0,
|
|
121
|
+
left: 0,
|
|
122
|
+
right: 0,
|
|
123
|
+
zIndex: 99998,
|
|
124
|
+
background: "rgba(59, 130, 246, 0.08)",
|
|
125
|
+
padding: "8px 16px",
|
|
126
|
+
textAlign: "center",
|
|
127
|
+
fontSize: 14,
|
|
128
|
+
color: "#1e40af",
|
|
129
|
+
fontFamily: "system-ui, sans-serif",
|
|
130
|
+
pointerEvents: "none"
|
|
131
|
+
},
|
|
132
|
+
children: [
|
|
133
|
+
"Click on any element to leave feedback. Press ",
|
|
134
|
+
/* @__PURE__ */ jsx2("strong", { children: "Esc" }),
|
|
135
|
+
" to cancel."
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/components/FeedbackDialog.tsx
|
|
142
|
+
import { useState } from "react";
|
|
143
|
+
|
|
144
|
+
// src/utils/prompt.ts
|
|
145
|
+
function buildPrompt(context, comment) {
|
|
146
|
+
const propsStr = context.components.filter((c) => Object.keys(c.props).length > 0).map((c) => ` ${c.name}: ${JSON.stringify(c.props)}`).join("\n");
|
|
147
|
+
const lines = [
|
|
148
|
+
`Page: ${context.url}`,
|
|
149
|
+
`Component: ${context.componentPath}`
|
|
150
|
+
];
|
|
151
|
+
if (propsStr) {
|
|
152
|
+
lines.push(`Props:
|
|
153
|
+
${propsStr}`);
|
|
154
|
+
}
|
|
155
|
+
if (context.elementText) {
|
|
156
|
+
lines.push(`Element text: "${context.elementText}"`);
|
|
157
|
+
}
|
|
158
|
+
lines.push("", `User feedback: "${comment}"`, "", "Screenshot attached with red X marking the clicked element.");
|
|
159
|
+
return lines.join("\n");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/utils/storage.ts
|
|
163
|
+
var STORAGE_KEY = "llm_ui_feedback_items";
|
|
164
|
+
function loadEntries() {
|
|
165
|
+
try {
|
|
166
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
167
|
+
return raw ? JSON.parse(raw) : [];
|
|
168
|
+
} catch {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function saveEntry(entry) {
|
|
173
|
+
const entries = loadEntries();
|
|
174
|
+
entries.push(entry);
|
|
175
|
+
try {
|
|
176
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(entries));
|
|
177
|
+
return { ok: true };
|
|
178
|
+
} catch (e) {
|
|
179
|
+
if (e instanceof DOMException && (e.name === "QuotaExceededError" || e.code === 22)) {
|
|
180
|
+
const oldestWithScreenshot = entries.findIndex((ent) => ent.screenshot !== null);
|
|
181
|
+
if (oldestWithScreenshot >= 0) {
|
|
182
|
+
entries[oldestWithScreenshot] = { ...entries[oldestWithScreenshot], screenshot: null };
|
|
183
|
+
try {
|
|
184
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(entries));
|
|
185
|
+
return { ok: true };
|
|
186
|
+
} catch {
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { ok: false, error: "Storage is full. Delete old feedback entries to free space." };
|
|
190
|
+
}
|
|
191
|
+
return { ok: false, error: "Failed to save feedback entry." };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function deleteEntry(id) {
|
|
195
|
+
const entries = loadEntries().filter((e) => e.id !== id);
|
|
196
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(entries));
|
|
197
|
+
}
|
|
198
|
+
function clearEntries() {
|
|
199
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/components/FeedbackDialog.tsx
|
|
203
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
204
|
+
async function copyToClipboard(text) {
|
|
205
|
+
if (navigator.clipboard?.writeText) {
|
|
206
|
+
try {
|
|
207
|
+
await navigator.clipboard.writeText(text);
|
|
208
|
+
return "success";
|
|
209
|
+
} catch {
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const textarea = document.createElement("textarea");
|
|
214
|
+
textarea.value = text;
|
|
215
|
+
textarea.style.cssText = "position:fixed;left:-9999px;top:-9999px";
|
|
216
|
+
document.body.appendChild(textarea);
|
|
217
|
+
textarea.focus();
|
|
218
|
+
textarea.select();
|
|
219
|
+
const ok = document.execCommand("copy");
|
|
220
|
+
document.body.removeChild(textarea);
|
|
221
|
+
if (ok) return "fallback-success";
|
|
222
|
+
} catch {
|
|
223
|
+
}
|
|
224
|
+
return "failed";
|
|
225
|
+
}
|
|
226
|
+
function FeedbackDialog({ context, screenshot, onClose }) {
|
|
227
|
+
const [comment, setComment] = useState("");
|
|
228
|
+
const [saved, setSaved] = useState(false);
|
|
229
|
+
const [copyStatus, setCopyStatus] = useState("idle");
|
|
230
|
+
const [saveError, setSaveError] = useState(null);
|
|
231
|
+
const [showPromptText, setShowPromptText] = useState(false);
|
|
232
|
+
const handleSubmit = () => {
|
|
233
|
+
if (!comment.trim()) return;
|
|
234
|
+
const prompt = buildPrompt(context, comment);
|
|
235
|
+
const entry = {
|
|
236
|
+
id: `f_${Date.now()}`,
|
|
237
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
238
|
+
url: context.url,
|
|
239
|
+
componentPath: context.componentPath,
|
|
240
|
+
components: context.components,
|
|
241
|
+
elementText: context.elementText,
|
|
242
|
+
comment,
|
|
243
|
+
screenshot,
|
|
244
|
+
prompt
|
|
245
|
+
};
|
|
246
|
+
const result = saveEntry(entry);
|
|
247
|
+
if (result.ok) {
|
|
248
|
+
setSaved(true);
|
|
249
|
+
setSaveError(null);
|
|
250
|
+
} else {
|
|
251
|
+
setSaveError(result.error || "Failed to save.");
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const handleCopyPrompt = async () => {
|
|
255
|
+
const prompt = buildPrompt(context, comment || "(no comment)");
|
|
256
|
+
const result = await copyToClipboard(prompt);
|
|
257
|
+
if (result === "failed") {
|
|
258
|
+
setCopyStatus("failed");
|
|
259
|
+
setShowPromptText(true);
|
|
260
|
+
} else {
|
|
261
|
+
setCopyStatus("copied");
|
|
262
|
+
setTimeout(() => setCopyStatus("idle"), 2e3);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const handleDownloadScreenshot = () => {
|
|
266
|
+
if (!screenshot) return;
|
|
267
|
+
const link = document.createElement("a");
|
|
268
|
+
link.download = `feedback_${Date.now()}.png`;
|
|
269
|
+
link.href = screenshot;
|
|
270
|
+
link.click();
|
|
271
|
+
};
|
|
272
|
+
const copyButtonLabel = copyStatus === "copied" ? "Copied!" : copyStatus === "failed" ? "Copy failed" : "Copy Prompt";
|
|
273
|
+
const copyButtonBg = copyStatus === "copied" ? "#dcfce7" : copyStatus === "failed" ? "#fee2e2" : "#f3f4f6";
|
|
274
|
+
const copyButtonColor = copyStatus === "copied" ? "#16a34a" : copyStatus === "failed" ? "#dc2626" : "#374151";
|
|
275
|
+
return /* @__PURE__ */ jsx3(
|
|
276
|
+
"div",
|
|
277
|
+
{
|
|
278
|
+
style: {
|
|
279
|
+
position: "fixed",
|
|
280
|
+
inset: 0,
|
|
281
|
+
zIndex: 99999,
|
|
282
|
+
display: "flex",
|
|
283
|
+
alignItems: "center",
|
|
284
|
+
justifyContent: "center",
|
|
285
|
+
background: "rgba(0,0,0,0.4)",
|
|
286
|
+
fontFamily: "system-ui, sans-serif"
|
|
287
|
+
},
|
|
288
|
+
onClick: (e) => {
|
|
289
|
+
if (e.target === e.currentTarget) onClose();
|
|
290
|
+
},
|
|
291
|
+
children: /* @__PURE__ */ jsxs2(
|
|
292
|
+
"div",
|
|
293
|
+
{
|
|
294
|
+
style: {
|
|
295
|
+
background: "#fff",
|
|
296
|
+
borderRadius: 12,
|
|
297
|
+
padding: 24,
|
|
298
|
+
width: 480,
|
|
299
|
+
maxWidth: "90vw",
|
|
300
|
+
maxHeight: "80vh",
|
|
301
|
+
overflow: "auto",
|
|
302
|
+
boxShadow: "0 8px 32px rgba(0,0,0,0.2)"
|
|
303
|
+
},
|
|
304
|
+
children: [
|
|
305
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 16 }, children: [
|
|
306
|
+
/* @__PURE__ */ jsx3("h3", { style: { margin: 0, fontSize: 16 }, children: "Leave Feedback" }),
|
|
307
|
+
/* @__PURE__ */ jsx3(
|
|
308
|
+
"button",
|
|
309
|
+
{
|
|
310
|
+
onClick: onClose,
|
|
311
|
+
style: {
|
|
312
|
+
background: "none",
|
|
313
|
+
border: "none",
|
|
314
|
+
fontSize: 20,
|
|
315
|
+
cursor: "pointer",
|
|
316
|
+
color: "#666"
|
|
317
|
+
},
|
|
318
|
+
children: "x"
|
|
319
|
+
}
|
|
320
|
+
)
|
|
321
|
+
] }),
|
|
322
|
+
/* @__PURE__ */ jsxs2("div", { style: { fontSize: 12, color: "#666", marginBottom: 12 }, children: [
|
|
323
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
324
|
+
/* @__PURE__ */ jsx3("strong", { children: "Page:" }),
|
|
325
|
+
" ",
|
|
326
|
+
context.url
|
|
327
|
+
] }),
|
|
328
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
329
|
+
/* @__PURE__ */ jsx3("strong", { children: "Component:" }),
|
|
330
|
+
" ",
|
|
331
|
+
context.componentPath
|
|
332
|
+
] }),
|
|
333
|
+
context.elementText && /* @__PURE__ */ jsxs2("div", { children: [
|
|
334
|
+
/* @__PURE__ */ jsx3("strong", { children: "Element:" }),
|
|
335
|
+
' "',
|
|
336
|
+
context.elementText.slice(0, 100),
|
|
337
|
+
'"'
|
|
338
|
+
] })
|
|
339
|
+
] }),
|
|
340
|
+
screenshot && /* @__PURE__ */ jsx3(
|
|
341
|
+
"img",
|
|
342
|
+
{
|
|
343
|
+
src: screenshot,
|
|
344
|
+
alt: "Screenshot",
|
|
345
|
+
style: {
|
|
346
|
+
width: "100%",
|
|
347
|
+
borderRadius: 8,
|
|
348
|
+
border: "1px solid #e5e7eb",
|
|
349
|
+
marginBottom: 12
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
),
|
|
353
|
+
!saved ? /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
354
|
+
/* @__PURE__ */ jsx3(
|
|
355
|
+
"textarea",
|
|
356
|
+
{
|
|
357
|
+
value: comment,
|
|
358
|
+
onChange: (e) => setComment(e.target.value),
|
|
359
|
+
placeholder: "Describe the issue or suggestion...",
|
|
360
|
+
autoFocus: true,
|
|
361
|
+
style: {
|
|
362
|
+
width: "100%",
|
|
363
|
+
minHeight: 80,
|
|
364
|
+
padding: 10,
|
|
365
|
+
borderRadius: 8,
|
|
366
|
+
border: "1px solid #d1d5db",
|
|
367
|
+
fontSize: 14,
|
|
368
|
+
resize: "vertical",
|
|
369
|
+
boxSizing: "border-box"
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
),
|
|
373
|
+
saveError && /* @__PURE__ */ jsx3("div", { style: { color: "#dc2626", fontSize: 13, marginTop: 8 }, children: saveError }),
|
|
374
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", gap: 8, marginTop: 12 }, children: [
|
|
375
|
+
/* @__PURE__ */ jsx3("button", { onClick: handleSubmit, style: btnStyle("#3b82f6", "#fff"), children: "Save" }),
|
|
376
|
+
/* @__PURE__ */ jsx3("button", { onClick: handleCopyPrompt, style: btnStyle(copyButtonBg, copyButtonColor), children: copyButtonLabel }),
|
|
377
|
+
screenshot && /* @__PURE__ */ jsx3("button", { onClick: handleDownloadScreenshot, style: btnStyle("#f3f4f6", "#374151"), children: "Download Screenshot" })
|
|
378
|
+
] })
|
|
379
|
+
] }) : /* @__PURE__ */ jsxs2("div", { style: { textAlign: "center", padding: 16, color: "#16a34a" }, children: [
|
|
380
|
+
"Saved to localStorage.",
|
|
381
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", gap: 8, marginTop: 12, justifyContent: "center" }, children: [
|
|
382
|
+
/* @__PURE__ */ jsx3("button", { onClick: handleCopyPrompt, style: btnStyle(copyButtonBg, copyButtonColor), children: copyButtonLabel }),
|
|
383
|
+
screenshot && /* @__PURE__ */ jsx3("button", { onClick: handleDownloadScreenshot, style: btnStyle("#f3f4f6", "#374151"), children: "Download Screenshot" }),
|
|
384
|
+
/* @__PURE__ */ jsx3("button", { onClick: onClose, style: btnStyle("#3b82f6", "#fff"), children: "Done" })
|
|
385
|
+
] })
|
|
386
|
+
] }),
|
|
387
|
+
showPromptText && /* @__PURE__ */ jsxs2("div", { style: { marginTop: 12 }, children: [
|
|
388
|
+
/* @__PURE__ */ jsx3("div", { style: { fontSize: 12, color: "#666", marginBottom: 4 }, children: "Could not copy automatically. Select and copy manually:" }),
|
|
389
|
+
/* @__PURE__ */ jsx3(
|
|
390
|
+
"textarea",
|
|
391
|
+
{
|
|
392
|
+
readOnly: true,
|
|
393
|
+
value: buildPrompt(context, comment || "(no comment)"),
|
|
394
|
+
style: {
|
|
395
|
+
width: "100%",
|
|
396
|
+
minHeight: 120,
|
|
397
|
+
padding: 10,
|
|
398
|
+
borderRadius: 8,
|
|
399
|
+
border: "1px solid #d1d5db",
|
|
400
|
+
fontSize: 12,
|
|
401
|
+
fontFamily: "monospace",
|
|
402
|
+
resize: "vertical",
|
|
403
|
+
boxSizing: "border-box",
|
|
404
|
+
background: "#f9fafb"
|
|
405
|
+
},
|
|
406
|
+
onClick: (e) => e.target.select()
|
|
407
|
+
}
|
|
408
|
+
)
|
|
409
|
+
] })
|
|
410
|
+
]
|
|
411
|
+
}
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
function btnStyle(bg, color) {
|
|
417
|
+
return {
|
|
418
|
+
padding: "8px 16px",
|
|
419
|
+
borderRadius: 6,
|
|
420
|
+
border: "1px solid #d1d5db",
|
|
421
|
+
background: bg,
|
|
422
|
+
color,
|
|
423
|
+
fontSize: 13,
|
|
424
|
+
cursor: "pointer"
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/components/FeedbackListPanel.tsx
|
|
429
|
+
import { useState as useState2, useCallback as useCallback2 } from "react";
|
|
430
|
+
|
|
431
|
+
// src/utils/time.ts
|
|
432
|
+
function relativeTime(iso) {
|
|
433
|
+
const seconds = Math.floor((Date.now() - new Date(iso).getTime()) / 1e3);
|
|
434
|
+
if (seconds < 0) return "just now";
|
|
435
|
+
if (seconds < 60) return "just now";
|
|
436
|
+
const minutes = Math.floor(seconds / 60);
|
|
437
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
438
|
+
const hours = Math.floor(minutes / 60);
|
|
439
|
+
if (hours < 24) return `${hours}h ago`;
|
|
440
|
+
const days = Math.floor(hours / 24);
|
|
441
|
+
if (days < 30) return `${days}d ago`;
|
|
442
|
+
return new Date(iso).toLocaleDateString();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/components/EntryCard.tsx
|
|
446
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
447
|
+
function EntryCard({ entry, onDelete, onCopyPrompt }) {
|
|
448
|
+
const truncatedComment = entry.comment.length > 80 ? entry.comment.slice(0, 80) + "..." : entry.comment;
|
|
449
|
+
return /* @__PURE__ */ jsxs3(
|
|
450
|
+
"div",
|
|
451
|
+
{
|
|
452
|
+
style: {
|
|
453
|
+
padding: 12,
|
|
454
|
+
borderBottom: "1px solid #e5e7eb",
|
|
455
|
+
fontFamily: "system-ui, sans-serif"
|
|
456
|
+
},
|
|
457
|
+
children: [
|
|
458
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", marginBottom: 6 }, children: [
|
|
459
|
+
/* @__PURE__ */ jsx4("span", { style: { fontSize: 13, color: "#111827", flex: 1, marginRight: 8 }, children: truncatedComment || "(no comment)" }),
|
|
460
|
+
/* @__PURE__ */ jsx4("span", { style: { fontSize: 11, color: "#9ca3af", whiteSpace: "nowrap", flexShrink: 0 }, children: relativeTime(entry.timestamp) })
|
|
461
|
+
] }),
|
|
462
|
+
/* @__PURE__ */ jsx4("div", { style: { fontSize: 11, color: "#6b7280", marginBottom: 4 }, children: entry.url }),
|
|
463
|
+
/* @__PURE__ */ jsx4("div", { style: { fontSize: 11, color: "#9ca3af", marginBottom: 8 }, children: entry.componentPath }),
|
|
464
|
+
entry.screenshot && /* @__PURE__ */ jsx4(
|
|
465
|
+
"img",
|
|
466
|
+
{
|
|
467
|
+
src: entry.screenshot,
|
|
468
|
+
alt: "Screenshot thumbnail",
|
|
469
|
+
style: {
|
|
470
|
+
width: 60,
|
|
471
|
+
height: 40,
|
|
472
|
+
objectFit: "cover",
|
|
473
|
+
borderRadius: 4,
|
|
474
|
+
border: "1px solid #e5e7eb",
|
|
475
|
+
marginBottom: 8,
|
|
476
|
+
display: "block"
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
),
|
|
480
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", gap: 6 }, children: [
|
|
481
|
+
/* @__PURE__ */ jsx4(
|
|
482
|
+
"button",
|
|
483
|
+
{
|
|
484
|
+
onClick: () => onCopyPrompt(entry.prompt),
|
|
485
|
+
style: {
|
|
486
|
+
padding: "4px 10px",
|
|
487
|
+
fontSize: 11,
|
|
488
|
+
borderRadius: 4,
|
|
489
|
+
border: "1px solid #d1d5db",
|
|
490
|
+
background: "#f9fafb",
|
|
491
|
+
color: "#374151",
|
|
492
|
+
cursor: "pointer"
|
|
493
|
+
},
|
|
494
|
+
children: "Copy Prompt"
|
|
495
|
+
}
|
|
496
|
+
),
|
|
497
|
+
/* @__PURE__ */ jsx4(
|
|
498
|
+
"button",
|
|
499
|
+
{
|
|
500
|
+
onClick: () => onDelete(entry.id),
|
|
501
|
+
style: {
|
|
502
|
+
padding: "4px 10px",
|
|
503
|
+
fontSize: 11,
|
|
504
|
+
borderRadius: 4,
|
|
505
|
+
border: "1px solid #fecaca",
|
|
506
|
+
background: "#fef2f2",
|
|
507
|
+
color: "#dc2626",
|
|
508
|
+
cursor: "pointer"
|
|
509
|
+
},
|
|
510
|
+
children: "Delete"
|
|
511
|
+
}
|
|
512
|
+
)
|
|
513
|
+
] })
|
|
514
|
+
]
|
|
515
|
+
}
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// src/components/FeedbackListPanel.tsx
|
|
520
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
521
|
+
async function copyToClipboard2(text) {
|
|
522
|
+
if (navigator.clipboard?.writeText) {
|
|
523
|
+
try {
|
|
524
|
+
await navigator.clipboard.writeText(text);
|
|
525
|
+
return true;
|
|
526
|
+
} catch {
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
try {
|
|
530
|
+
const textarea = document.createElement("textarea");
|
|
531
|
+
textarea.value = text;
|
|
532
|
+
textarea.style.cssText = "position:fixed;left:-9999px;top:-9999px";
|
|
533
|
+
document.body.appendChild(textarea);
|
|
534
|
+
textarea.focus();
|
|
535
|
+
textarea.select();
|
|
536
|
+
const ok = document.execCommand("copy");
|
|
537
|
+
document.body.removeChild(textarea);
|
|
538
|
+
return ok;
|
|
539
|
+
} catch {
|
|
540
|
+
}
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
function FeedbackListPanel({ onClose, position }) {
|
|
544
|
+
const [entries, setEntries] = useState2(() => loadEntries());
|
|
545
|
+
const [confirmClear, setConfirmClear] = useState2(false);
|
|
546
|
+
const [copiedId, setCopiedId] = useState2(null);
|
|
547
|
+
const isRight = position.includes("right");
|
|
548
|
+
const refreshEntries = useCallback2(() => {
|
|
549
|
+
setEntries(loadEntries());
|
|
550
|
+
}, []);
|
|
551
|
+
const handleDelete = useCallback2(
|
|
552
|
+
(id) => {
|
|
553
|
+
deleteEntry(id);
|
|
554
|
+
refreshEntries();
|
|
555
|
+
},
|
|
556
|
+
[refreshEntries]
|
|
557
|
+
);
|
|
558
|
+
const handleCopyPrompt = useCallback2(async (prompt) => {
|
|
559
|
+
const ok = await copyToClipboard2(prompt);
|
|
560
|
+
if (ok) {
|
|
561
|
+
}
|
|
562
|
+
}, []);
|
|
563
|
+
const handleClear = useCallback2(() => {
|
|
564
|
+
if (!confirmClear) {
|
|
565
|
+
setConfirmClear(true);
|
|
566
|
+
setTimeout(() => setConfirmClear(false), 3e3);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
clearEntries();
|
|
570
|
+
setConfirmClear(false);
|
|
571
|
+
refreshEntries();
|
|
572
|
+
}, [confirmClear, refreshEntries]);
|
|
573
|
+
const sortedEntries = [...entries].reverse();
|
|
574
|
+
return /* @__PURE__ */ jsxs4(
|
|
575
|
+
"div",
|
|
576
|
+
{
|
|
577
|
+
style: {
|
|
578
|
+
position: "fixed",
|
|
579
|
+
top: 0,
|
|
580
|
+
[isRight ? "right" : "left"]: 0,
|
|
581
|
+
bottom: 0,
|
|
582
|
+
width: 380,
|
|
583
|
+
maxWidth: "90vw",
|
|
584
|
+
zIndex: 99999,
|
|
585
|
+
background: "#fff",
|
|
586
|
+
boxShadow: isRight ? "-4px 0 24px rgba(0,0,0,0.15)" : "4px 0 24px rgba(0,0,0,0.15)",
|
|
587
|
+
display: "flex",
|
|
588
|
+
flexDirection: "column",
|
|
589
|
+
fontFamily: "system-ui, sans-serif"
|
|
590
|
+
},
|
|
591
|
+
children: [
|
|
592
|
+
/* @__PURE__ */ jsxs4(
|
|
593
|
+
"div",
|
|
594
|
+
{
|
|
595
|
+
style: {
|
|
596
|
+
padding: 16,
|
|
597
|
+
borderBottom: "1px solid #e5e7eb",
|
|
598
|
+
display: "flex",
|
|
599
|
+
justifyContent: "space-between",
|
|
600
|
+
alignItems: "center",
|
|
601
|
+
flexShrink: 0
|
|
602
|
+
},
|
|
603
|
+
children: [
|
|
604
|
+
/* @__PURE__ */ jsxs4("h3", { style: { margin: 0, fontSize: 15, color: "#111827" }, children: [
|
|
605
|
+
"Feedback (",
|
|
606
|
+
entries.length,
|
|
607
|
+
")"
|
|
608
|
+
] }),
|
|
609
|
+
/* @__PURE__ */ jsx5(
|
|
610
|
+
"button",
|
|
611
|
+
{
|
|
612
|
+
onClick: onClose,
|
|
613
|
+
style: {
|
|
614
|
+
background: "none",
|
|
615
|
+
border: "none",
|
|
616
|
+
fontSize: 20,
|
|
617
|
+
cursor: "pointer",
|
|
618
|
+
color: "#666",
|
|
619
|
+
padding: "0 4px"
|
|
620
|
+
},
|
|
621
|
+
children: "\xD7"
|
|
622
|
+
}
|
|
623
|
+
)
|
|
624
|
+
]
|
|
625
|
+
}
|
|
626
|
+
),
|
|
627
|
+
/* @__PURE__ */ jsx5("div", { style: { flex: 1, overflowY: "auto", padding: 0 }, children: sortedEntries.length === 0 ? /* @__PURE__ */ jsx5(
|
|
628
|
+
"div",
|
|
629
|
+
{
|
|
630
|
+
style: {
|
|
631
|
+
textAlign: "center",
|
|
632
|
+
padding: 32,
|
|
633
|
+
color: "#9ca3af",
|
|
634
|
+
fontSize: 13
|
|
635
|
+
},
|
|
636
|
+
children: "No feedback entries yet"
|
|
637
|
+
}
|
|
638
|
+
) : sortedEntries.map((entry) => /* @__PURE__ */ jsx5(
|
|
639
|
+
EntryCard,
|
|
640
|
+
{
|
|
641
|
+
entry,
|
|
642
|
+
onDelete: handleDelete,
|
|
643
|
+
onCopyPrompt: handleCopyPrompt
|
|
644
|
+
},
|
|
645
|
+
entry.id
|
|
646
|
+
)) }),
|
|
647
|
+
/* @__PURE__ */ jsx5(
|
|
648
|
+
"div",
|
|
649
|
+
{
|
|
650
|
+
style: {
|
|
651
|
+
padding: "12px 16px",
|
|
652
|
+
borderTop: "1px solid #e5e7eb",
|
|
653
|
+
flexShrink: 0
|
|
654
|
+
},
|
|
655
|
+
children: /* @__PURE__ */ jsx5(
|
|
656
|
+
"button",
|
|
657
|
+
{
|
|
658
|
+
onClick: handleClear,
|
|
659
|
+
disabled: entries.length === 0,
|
|
660
|
+
style: {
|
|
661
|
+
width: "100%",
|
|
662
|
+
padding: "8px 16px",
|
|
663
|
+
borderRadius: 6,
|
|
664
|
+
border: "1px solid #d1d5db",
|
|
665
|
+
background: confirmClear ? "#fef2f2" : "#f9fafb",
|
|
666
|
+
color: confirmClear ? "#dc2626" : entries.length === 0 ? "#9ca3af" : "#374151",
|
|
667
|
+
fontSize: 13,
|
|
668
|
+
cursor: entries.length === 0 ? "default" : "pointer"
|
|
669
|
+
},
|
|
670
|
+
children: confirmClear ? "Are you sure? Clear" : "Clear All"
|
|
671
|
+
}
|
|
672
|
+
)
|
|
673
|
+
}
|
|
674
|
+
)
|
|
675
|
+
]
|
|
676
|
+
}
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/components/ListButton.tsx
|
|
681
|
+
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
682
|
+
function ListButton({ onClick, count, position, buttonColor }) {
|
|
683
|
+
if (count === 0) return null;
|
|
684
|
+
const isBottom = position.includes("bottom");
|
|
685
|
+
const isRight = position.includes("right");
|
|
686
|
+
return /* @__PURE__ */ jsxs5(
|
|
687
|
+
"button",
|
|
688
|
+
{
|
|
689
|
+
onClick,
|
|
690
|
+
"aria-label": `View ${count} feedback entries`,
|
|
691
|
+
style: {
|
|
692
|
+
position: "fixed",
|
|
693
|
+
[isBottom ? "bottom" : "top"]: 80,
|
|
694
|
+
[isRight ? "right" : "left"]: 24,
|
|
695
|
+
zIndex: 99999,
|
|
696
|
+
width: 36,
|
|
697
|
+
height: 36,
|
|
698
|
+
borderRadius: "50%",
|
|
699
|
+
border: "1px solid #d1d5db",
|
|
700
|
+
background: "#f3f4f6",
|
|
701
|
+
color: "#374151",
|
|
702
|
+
fontSize: 16,
|
|
703
|
+
cursor: "pointer",
|
|
704
|
+
display: "flex",
|
|
705
|
+
alignItems: "center",
|
|
706
|
+
justifyContent: "center",
|
|
707
|
+
boxShadow: "0 2px 6px rgba(0,0,0,0.15)",
|
|
708
|
+
padding: 0
|
|
709
|
+
},
|
|
710
|
+
children: [
|
|
711
|
+
/* @__PURE__ */ jsx6("span", { style: { lineHeight: 1 }, children: "\u2630" }),
|
|
712
|
+
/* @__PURE__ */ jsx6(
|
|
713
|
+
"span",
|
|
714
|
+
{
|
|
715
|
+
style: {
|
|
716
|
+
position: "absolute",
|
|
717
|
+
top: -4,
|
|
718
|
+
[isRight ? "right" : "left"]: -4,
|
|
719
|
+
background: buttonColor,
|
|
720
|
+
color: getContrastColor(buttonColor),
|
|
721
|
+
fontSize: 10,
|
|
722
|
+
fontWeight: 600,
|
|
723
|
+
borderRadius: "50%",
|
|
724
|
+
width: 18,
|
|
725
|
+
height: 18,
|
|
726
|
+
display: "flex",
|
|
727
|
+
alignItems: "center",
|
|
728
|
+
justifyContent: "center",
|
|
729
|
+
lineHeight: 1
|
|
730
|
+
},
|
|
731
|
+
children: count > 99 ? "99+" : count
|
|
732
|
+
}
|
|
733
|
+
)
|
|
734
|
+
]
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// src/utils/fiber.ts
|
|
740
|
+
var minificationWarned = false;
|
|
741
|
+
function getFiber(el) {
|
|
742
|
+
const key = Object.keys(el).find((k) => k.startsWith("__reactFiber$"));
|
|
743
|
+
return key ? el[key] : null;
|
|
744
|
+
}
|
|
745
|
+
function pickShortProps(props) {
|
|
746
|
+
const short = {};
|
|
747
|
+
for (const [key, value] of Object.entries(props)) {
|
|
748
|
+
if (key === "children") continue;
|
|
749
|
+
if (typeof value === "function") continue;
|
|
750
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
751
|
+
short[key] = value;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return short;
|
|
755
|
+
}
|
|
756
|
+
function getComponentPath(el, maxDepth = 8) {
|
|
757
|
+
const fiber = getFiber(el);
|
|
758
|
+
if (!fiber) return [];
|
|
759
|
+
const path = [];
|
|
760
|
+
let current = fiber;
|
|
761
|
+
while (current && path.length < maxDepth) {
|
|
762
|
+
if (typeof current.type === "function" || typeof current.type === "object") {
|
|
763
|
+
const name = current.type?.displayName || current.type?.name || null;
|
|
764
|
+
if (name) {
|
|
765
|
+
if (!minificationWarned && name.length <= 2 && /^[a-z]/.test(name)) {
|
|
766
|
+
minificationWarned = true;
|
|
767
|
+
console.warn(
|
|
768
|
+
'[llm-ui-feedback] Component names appear minified (e.g., "' + name + '"). The generated LLM prompts will lack meaningful component paths. To fix, configure your bundler to preserve function names. See: https://github.com/user/llm-ui-feedback/blob/main/docs/production-setup.md'
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
path.push({
|
|
772
|
+
name,
|
|
773
|
+
props: pickShortProps(current.memoizedProps || {})
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
current = current.return;
|
|
778
|
+
}
|
|
779
|
+
return path.reverse();
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/utils/screenshot.ts
|
|
783
|
+
import html2canvas from "html2canvas-pro";
|
|
784
|
+
async function captureScreenshot(clickX, clickY) {
|
|
785
|
+
const docX = clickX + window.scrollX;
|
|
786
|
+
const docY = clickY + window.scrollY;
|
|
787
|
+
const canvas = await html2canvas(document.body, {
|
|
788
|
+
logging: false,
|
|
789
|
+
useCORS: true
|
|
790
|
+
});
|
|
791
|
+
const ctx = canvas.getContext("2d");
|
|
792
|
+
if (ctx) {
|
|
793
|
+
ctx.strokeStyle = "red";
|
|
794
|
+
ctx.lineWidth = 3;
|
|
795
|
+
const size = 14;
|
|
796
|
+
ctx.beginPath();
|
|
797
|
+
ctx.moveTo(docX - size, docY - size);
|
|
798
|
+
ctx.lineTo(docX + size, docY + size);
|
|
799
|
+
ctx.moveTo(docX + size, docY - size);
|
|
800
|
+
ctx.lineTo(docX - size, docY + size);
|
|
801
|
+
ctx.stroke();
|
|
802
|
+
ctx.beginPath();
|
|
803
|
+
ctx.arc(docX, docY, size + 4, 0, Math.PI * 2);
|
|
804
|
+
ctx.stroke();
|
|
805
|
+
}
|
|
806
|
+
return canvas.toDataURL("image/png");
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/components/FeedbackWidget.tsx
|
|
810
|
+
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
811
|
+
var CONTAINER_ID = "llm-ui-feedback-root";
|
|
812
|
+
function getOrCreateContainer() {
|
|
813
|
+
let el = document.getElementById(CONTAINER_ID);
|
|
814
|
+
if (!el) {
|
|
815
|
+
el = document.createElement("div");
|
|
816
|
+
el.id = CONTAINER_ID;
|
|
817
|
+
document.body.appendChild(el);
|
|
818
|
+
}
|
|
819
|
+
return el;
|
|
820
|
+
}
|
|
821
|
+
function widgetReducer(state, action) {
|
|
822
|
+
switch (action.type) {
|
|
823
|
+
case "START_PICKING":
|
|
824
|
+
return state.mode === "idle" ? { mode: "picking" } : state;
|
|
825
|
+
case "CANCEL":
|
|
826
|
+
case "CLOSE":
|
|
827
|
+
return { mode: "idle" };
|
|
828
|
+
case "ELEMENT_PICKED":
|
|
829
|
+
return { mode: "dialog", context: action.context, screenshot: action.screenshot };
|
|
830
|
+
case "OPEN_LIST":
|
|
831
|
+
return state.mode === "idle" ? { mode: "list" } : state;
|
|
832
|
+
default:
|
|
833
|
+
return state;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function parseHotkey(hotkey) {
|
|
837
|
+
const parts = hotkey.split("+").map((p) => p.trim().toLowerCase());
|
|
838
|
+
const key = parts.pop();
|
|
839
|
+
return {
|
|
840
|
+
key,
|
|
841
|
+
ctrl: parts.includes("ctrl"),
|
|
842
|
+
alt: parts.includes("alt"),
|
|
843
|
+
shift: parts.includes("shift"),
|
|
844
|
+
meta: parts.includes("meta")
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
function isEditableTarget(el) {
|
|
848
|
+
if (!el) return false;
|
|
849
|
+
const tag = el.tagName;
|
|
850
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
851
|
+
if (el.isContentEditable) return true;
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
function FeedbackWidget({
|
|
855
|
+
position = "bottom-right",
|
|
856
|
+
buttonColor = "#3b82f6",
|
|
857
|
+
hotkey
|
|
858
|
+
} = {}) {
|
|
859
|
+
const [state, dispatch] = useReducer(widgetReducer, { mode: "idle" });
|
|
860
|
+
const [entryCount, setEntryCount] = useState3(0);
|
|
861
|
+
useEffect2(() => {
|
|
862
|
+
if (state.mode === "idle") {
|
|
863
|
+
setEntryCount(loadEntries().length);
|
|
864
|
+
}
|
|
865
|
+
}, [state.mode]);
|
|
866
|
+
useEffect2(() => {
|
|
867
|
+
setEntryCount(loadEntries().length);
|
|
868
|
+
}, []);
|
|
869
|
+
useEffect2(() => {
|
|
870
|
+
if (!hotkey) return;
|
|
871
|
+
const parsed = parseHotkey(hotkey);
|
|
872
|
+
function handler(e) {
|
|
873
|
+
if (isEditableTarget(document.activeElement)) return;
|
|
874
|
+
if (e.key.toLowerCase() === parsed.key && e.ctrlKey === parsed.ctrl && e.altKey === parsed.alt && e.shiftKey === parsed.shift && e.metaKey === parsed.meta) {
|
|
875
|
+
e.preventDefault();
|
|
876
|
+
dispatch(
|
|
877
|
+
state.mode === "picking" ? { type: "CANCEL" } : state.mode === "idle" ? { type: "START_PICKING" } : { type: "CLOSE" }
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
window.addEventListener("keydown", handler);
|
|
882
|
+
return () => window.removeEventListener("keydown", handler);
|
|
883
|
+
}, [hotkey, state.mode]);
|
|
884
|
+
const handleToggle = useCallback3(() => {
|
|
885
|
+
dispatch({ type: "START_PICKING" });
|
|
886
|
+
}, []);
|
|
887
|
+
const handlePick = useCallback3(async (element, x, y) => {
|
|
888
|
+
const components = getComponentPath(element);
|
|
889
|
+
const componentPath = components.map((c) => c.name).join(" > ") || "(no React component found)";
|
|
890
|
+
const rawText = (element.innerText || element.textContent || "").trim();
|
|
891
|
+
const elementText = rawText.length > 100 ? rawText.slice(0, 100) + "..." : rawText;
|
|
892
|
+
const context = {
|
|
893
|
+
url: window.location.href,
|
|
894
|
+
componentPath,
|
|
895
|
+
components,
|
|
896
|
+
elementText,
|
|
897
|
+
clickX: x,
|
|
898
|
+
clickY: y
|
|
899
|
+
};
|
|
900
|
+
let screenshot = null;
|
|
901
|
+
try {
|
|
902
|
+
screenshot = await captureScreenshot(x, y);
|
|
903
|
+
} catch {
|
|
904
|
+
}
|
|
905
|
+
dispatch({ type: "ELEMENT_PICKED", context, screenshot });
|
|
906
|
+
}, []);
|
|
907
|
+
const handleCancel = useCallback3(() => {
|
|
908
|
+
dispatch({ type: "CANCEL" });
|
|
909
|
+
}, []);
|
|
910
|
+
const handleClose = useCallback3(() => {
|
|
911
|
+
dispatch({ type: "CLOSE" });
|
|
912
|
+
}, []);
|
|
913
|
+
const handleOpenList = useCallback3(() => {
|
|
914
|
+
dispatch({ type: "OPEN_LIST" });
|
|
915
|
+
}, []);
|
|
916
|
+
const handleCloseList = useCallback3(() => {
|
|
917
|
+
dispatch({ type: "CLOSE" });
|
|
918
|
+
}, []);
|
|
919
|
+
return createPortal(
|
|
920
|
+
/* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
921
|
+
state.mode === "idle" && /* @__PURE__ */ jsx7(
|
|
922
|
+
ListButton,
|
|
923
|
+
{
|
|
924
|
+
onClick: handleOpenList,
|
|
925
|
+
count: entryCount,
|
|
926
|
+
position,
|
|
927
|
+
buttonColor
|
|
928
|
+
}
|
|
929
|
+
),
|
|
930
|
+
/* @__PURE__ */ jsx7(
|
|
931
|
+
FloatingButton,
|
|
932
|
+
{
|
|
933
|
+
onClick: state.mode === "picking" ? handleCancel : handleToggle,
|
|
934
|
+
active: state.mode === "picking",
|
|
935
|
+
position,
|
|
936
|
+
buttonColor
|
|
937
|
+
}
|
|
938
|
+
),
|
|
939
|
+
state.mode === "picking" && /* @__PURE__ */ jsx7(PickOverlay, { onPick: handlePick, onCancel: handleCancel }),
|
|
940
|
+
state.mode === "dialog" && /* @__PURE__ */ jsx7(FeedbackDialog, { context: state.context, screenshot: state.screenshot, onClose: handleClose }),
|
|
941
|
+
state.mode === "list" && /* @__PURE__ */ jsx7(FeedbackListPanel, { onClose: handleCloseList, position })
|
|
942
|
+
] }),
|
|
943
|
+
getOrCreateContainer()
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
export {
|
|
947
|
+
FeedbackWidget,
|
|
948
|
+
clearEntries,
|
|
949
|
+
deleteEntry,
|
|
950
|
+
loadEntries
|
|
951
|
+
};
|
|
952
|
+
//# sourceMappingURL=index.mjs.map
|