@classic-homes/feedback-react 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,809 @@
1
+ // src/FeedbackWidget.tsx
2
+ import {
3
+ useCallback,
4
+ useEffect,
5
+ useId,
6
+ useRef,
7
+ useState,
8
+ useSyncExternalStore
9
+ } from "react";
10
+ import { createPortal } from "react-dom";
11
+ import {
12
+ ACCEPT_ATTRIBUTE,
13
+ COMMENT_COUNTER_THRESHOLD,
14
+ FEEDBACK_LIMITS,
15
+ MESSAGES,
16
+ buildPayload,
17
+ capturePage,
18
+ clearPageSelection,
19
+ closeFeedback,
20
+ createClientId,
21
+ createSelectionWatcher,
22
+ errorMessage,
23
+ getServerState,
24
+ getState,
25
+ imageFromClipboardEvent,
26
+ initialCategory,
27
+ isCoarsePointer,
28
+ needsTurnstile,
29
+ openFeedback,
30
+ prepareImage,
31
+ renderTurnstile,
32
+ resolveOptions,
33
+ selectionButtonPosition,
34
+ sendFeedback,
35
+ subscribe,
36
+ validateForm
37
+ } from "@classic-homes/feedback-core";
38
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
39
+ function FeedbackWidget(props) {
40
+ const [mounted, setMounted] = useState(false);
41
+ useEffect(() => setMounted(true), []);
42
+ const state = useSyncExternalStore(subscribe, getState, getServerState);
43
+ const options = resolveOptions(props);
44
+ const tabRef = useRef(null);
45
+ const [selectionUi, setSelectionUi] = useState(null);
46
+ const container = options.selectionContainer;
47
+ useEffect(() => {
48
+ if (!mounted || !container) return;
49
+ const watcher = createSelectionWatcher({
50
+ container,
51
+ onSelect: (data, rect) => {
52
+ if (getState().open) return;
53
+ const pos = rect ? selectionButtonPosition(rect, { preferBelow: isCoarsePointer() }) : { top: 8, left: 8 };
54
+ setSelectionUi({ data, pos });
55
+ },
56
+ onClear: () => setSelectionUi(null)
57
+ });
58
+ return () => watcher.destroy();
59
+ }, [mounted, container]);
60
+ useEffect(() => {
61
+ if (state.open) setSelectionUi(null);
62
+ }, [state.open]);
63
+ const selectionUiRef = useRef(selectionUi);
64
+ selectionUiRef.current = selectionUi;
65
+ const openFromSelection = useCallback(() => {
66
+ const current = selectionUiRef.current;
67
+ if (!current) return;
68
+ selectionUiRef.current = null;
69
+ setSelectionUi(null);
70
+ clearPageSelection();
71
+ openFeedback({ selection: current.data });
72
+ }, []);
73
+ if (!mounted) return null;
74
+ return createPortal(
75
+ /* @__PURE__ */ jsxs(Fragment, { children: [
76
+ options.trigger === "tab" && /* @__PURE__ */ jsxs(
77
+ "button",
78
+ {
79
+ ref: tabRef,
80
+ type: "button",
81
+ className: "chf chf-tab",
82
+ "aria-haspopup": "dialog",
83
+ "aria-label": MESSAGES.tabAria,
84
+ onClick: () => openFeedback(),
85
+ children: [
86
+ /* @__PURE__ */ jsx("span", { className: "chf-tab__icon", "aria-hidden": "true", children: "\u270E" }),
87
+ /* @__PURE__ */ jsx("span", { className: "chf-tab__label", children: options.tabLabel })
88
+ ]
89
+ }
90
+ ),
91
+ selectionUi && !state.open && /* @__PURE__ */ jsxs(
92
+ "button",
93
+ {
94
+ type: "button",
95
+ className: "chf chf-select-btn",
96
+ style: { top: selectionUi.pos.top, left: selectionUi.pos.left },
97
+ "aria-label": MESSAGES.commentOnSelectionAria,
98
+ onPointerDown: (e) => {
99
+ e.preventDefault();
100
+ e.stopPropagation();
101
+ openFromSelection();
102
+ },
103
+ onMouseDown: (e) => e.preventDefault(),
104
+ onClick: openFromSelection,
105
+ children: [
106
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u270E" }),
107
+ /* @__PURE__ */ jsx("span", { children: MESSAGES.commentOnSelection })
108
+ ]
109
+ }
110
+ ),
111
+ /* @__PURE__ */ jsx(
112
+ FeedbackDialog,
113
+ {
114
+ config: props,
115
+ options,
116
+ open: state.open,
117
+ initialSelection: state.selection,
118
+ launchContext: state.context,
119
+ fallbackFocus: tabRef
120
+ },
121
+ state.nonce
122
+ )
123
+ ] }),
124
+ document.body
125
+ );
126
+ }
127
+ function FeedbackDialog({
128
+ config,
129
+ options,
130
+ open,
131
+ initialSelection,
132
+ launchContext,
133
+ fallbackFocus
134
+ }) {
135
+ const id = useId();
136
+ const ids = {
137
+ title: `${id}-title`,
138
+ desc: `${id}-desc`,
139
+ category: `${id}-category`,
140
+ comment: `${id}-comment`,
141
+ commentError: `${id}-comment-error`,
142
+ counter: `${id}-counter`,
143
+ name: `${id}-name`,
144
+ email: `${id}-email`,
145
+ emailError: `${id}-email-error`,
146
+ attachments: `${id}-attachments`
147
+ };
148
+ const [category, setCategory] = useState(
149
+ () => initialCategory(options.categories, !!initialSelection)
150
+ );
151
+ const [comment, setComment] = useState("");
152
+ const [name, setName] = useState(config.user?.name ?? "");
153
+ const [email, setEmail] = useState(config.user?.email ?? "");
154
+ const [selection, setSelection] = useState(initialSelection);
155
+ const [attachments, setAttachments] = useState([]);
156
+ const [status, setStatus] = useState("idle");
157
+ const [error, setError] = useState(null);
158
+ const [fieldErrors, setFieldErrors] = useState({});
159
+ const [confirming, setConfirming] = useState(false);
160
+ const [picking, setPicking] = useState(false);
161
+ const [capturing, setCapturing] = useState(false);
162
+ const [processing, setProcessing] = useState(false);
163
+ const [attachError, setAttachError] = useState(null);
164
+ const [dragActive, setDragActive] = useState(false);
165
+ const [showTurnstile, setShowTurnstile] = useState(false);
166
+ const dialogRef = useRef(null);
167
+ const textareaRef = useRef(null);
168
+ const emailRef = useRef(null);
169
+ const fileRef = useRef(null);
170
+ const keepEditingRef = useRef(null);
171
+ const doneRef = useRef(null);
172
+ const turnstileElRef = useRef(null);
173
+ const turnstileRef = useRef(null);
174
+ const clientIdRef = useRef(createClientId());
175
+ const returnFocusRef = useRef(null);
176
+ const closingRef = useRef(false);
177
+ const pointerOnBackdropRef = useRef(false);
178
+ const attachmentsRef = useRef([]);
179
+ attachmentsRef.current = attachments;
180
+ const done = status === "success" || status === "queued";
181
+ const dirty = !done && (comment.trim().length > 0 || attachments.length > 0);
182
+ const stateRef = useRef({ dirty, status, picking });
183
+ stateRef.current = { dirty, status, picking };
184
+ const requestClose = useCallback(() => {
185
+ const s = stateRef.current;
186
+ if (s.status === "submitting") return;
187
+ if (s.dirty) setConfirming(true);
188
+ else closeFeedback();
189
+ }, []);
190
+ const wasOpenRef = useRef(false);
191
+ useEffect(() => {
192
+ const dialog = dialogRef.current;
193
+ if (!dialog) return;
194
+ const show = open && !picking;
195
+ if (show && !dialog.open) {
196
+ if (!wasOpenRef.current) {
197
+ returnFocusRef.current = document.activeElement;
198
+ }
199
+ dialog.showModal();
200
+ textareaRef.current?.focus();
201
+ } else if (!show && dialog.open) {
202
+ closingRef.current = true;
203
+ dialog.close();
204
+ }
205
+ if (!open && wasOpenRef.current) {
206
+ const target = returnFocusRef.current;
207
+ const fallback = fallbackFocus.current;
208
+ if (target && target.isConnected && target !== document.body) target.focus();
209
+ else fallback?.focus();
210
+ }
211
+ wasOpenRef.current = open;
212
+ }, [open, picking, fallbackFocus]);
213
+ useEffect(() => {
214
+ const dialog = dialogRef.current;
215
+ if (!dialog) return;
216
+ const onCancel = (e) => {
217
+ e.preventDefault();
218
+ requestClose();
219
+ };
220
+ const onClose = () => {
221
+ if (closingRef.current) {
222
+ closingRef.current = false;
223
+ return;
224
+ }
225
+ const s = stateRef.current;
226
+ if (!getState().open || s.picking) return;
227
+ if (s.dirty) {
228
+ dialog.showModal();
229
+ setConfirming(true);
230
+ } else {
231
+ closeFeedback();
232
+ }
233
+ };
234
+ dialog.addEventListener("cancel", onCancel);
235
+ dialog.addEventListener("close", onClose);
236
+ return () => {
237
+ dialog.removeEventListener("cancel", onCancel);
238
+ dialog.removeEventListener("close", onClose);
239
+ };
240
+ }, [requestClose]);
241
+ useEffect(() => {
242
+ if (confirming) keepEditingRef.current?.focus();
243
+ }, [confirming]);
244
+ useEffect(() => {
245
+ if (done) doneRef.current?.focus();
246
+ }, [done]);
247
+ useEffect(() => {
248
+ if (!open) return;
249
+ let cancelled = false;
250
+ void needsTurnstile(config).then((needed) => {
251
+ if (!cancelled) setShowTurnstile(needed);
252
+ });
253
+ return () => {
254
+ cancelled = true;
255
+ };
256
+ }, [open]);
257
+ useEffect(() => {
258
+ const el = turnstileElRef.current;
259
+ if (!showTurnstile || !el || !config.turnstileSiteKey || turnstileRef.current) return;
260
+ turnstileRef.current = renderTurnstile(el, config.turnstileSiteKey);
261
+ }, [showTurnstile, config.turnstileSiteKey]);
262
+ useEffect(
263
+ () => () => {
264
+ turnstileRef.current?.remove();
265
+ turnstileRef.current = null;
266
+ for (const a of attachmentsRef.current) URL.revokeObjectURL(a.url);
267
+ },
268
+ []
269
+ );
270
+ useEffect(() => {
271
+ if (!picking || !options.selectionContainer) return;
272
+ const watcher = createSelectionWatcher({
273
+ container: options.selectionContainer,
274
+ onSelect: (data) => {
275
+ setSelection(data);
276
+ setPicking(false);
277
+ clearPageSelection();
278
+ },
279
+ onClear: () => {
280
+ }
281
+ });
282
+ const onKey = (e) => {
283
+ if (e.key === "Escape") setPicking(false);
284
+ };
285
+ document.addEventListener("keydown", onKey);
286
+ return () => {
287
+ watcher.destroy();
288
+ document.removeEventListener("keydown", onKey);
289
+ };
290
+ }, [picking, options.selectionContainer]);
291
+ const startPicking = () => {
292
+ clearPageSelection();
293
+ setPicking(true);
294
+ };
295
+ const addFiles = async (files) => {
296
+ setAttachError(null);
297
+ const room = options.maxAttachments - attachmentsRef.current.length;
298
+ if (room <= 0 || files.length > room) {
299
+ setAttachError(MESSAGES.attachmentLimit(options.maxAttachments));
300
+ }
301
+ const accepted = files.slice(0, Math.max(0, room));
302
+ if (!accepted.length) return;
303
+ setProcessing(true);
304
+ for (const file of accepted) {
305
+ try {
306
+ const blob = await prepareImage(file);
307
+ const attachment = {
308
+ id: createClientId(),
309
+ blob,
310
+ url: URL.createObjectURL(blob)
311
+ };
312
+ setAttachments((prev) => {
313
+ if (prev.length >= options.maxAttachments) {
314
+ URL.revokeObjectURL(attachment.url);
315
+ return prev;
316
+ }
317
+ return [...prev, attachment];
318
+ });
319
+ } catch (err) {
320
+ setAttachError(errorMessage(err));
321
+ }
322
+ }
323
+ setProcessing(false);
324
+ };
325
+ const removeAttachment = (attachmentId) => {
326
+ setAttachments((prev) => {
327
+ const target = prev.find((a) => a.id === attachmentId);
328
+ if (target) URL.revokeObjectURL(target.url);
329
+ return prev.filter((a) => a.id !== attachmentId);
330
+ });
331
+ setAttachError(null);
332
+ };
333
+ const onCapture = async () => {
334
+ setCapturing(true);
335
+ setAttachError(null);
336
+ try {
337
+ const blob = await capturePage();
338
+ await addFiles([blob]);
339
+ } catch {
340
+ setAttachError(MESSAGES.captureFailed);
341
+ } finally {
342
+ setCapturing(false);
343
+ }
344
+ };
345
+ const onFileChange = (e) => {
346
+ const files = Array.from(e.target.files ?? []);
347
+ e.target.value = "";
348
+ void addFiles(files);
349
+ };
350
+ const onDrop = (e) => {
351
+ e.preventDefault();
352
+ setDragActive(false);
353
+ const files = Array.from(e.dataTransfer?.files ?? []).filter(
354
+ (f) => f.type.startsWith("image/")
355
+ );
356
+ void addFiles(files);
357
+ };
358
+ const onPaste = (e) => {
359
+ if (options.maxAttachments === 0 || done) return;
360
+ const file = imageFromClipboardEvent(e.nativeEvent);
361
+ if (!file) return;
362
+ e.preventDefault();
363
+ void addFiles([file]);
364
+ };
365
+ const onSubmit = async (e) => {
366
+ e.preventDefault();
367
+ if (status === "submitting") return;
368
+ const errors = validateForm({ comment, email });
369
+ setFieldErrors(errors);
370
+ if (errors.comment) {
371
+ textareaRef.current?.focus();
372
+ return;
373
+ }
374
+ if (errors.email) {
375
+ emailRef.current?.focus();
376
+ return;
377
+ }
378
+ setStatus("submitting");
379
+ setError(null);
380
+ setConfirming(false);
381
+ try {
382
+ const payload = buildPayload(
383
+ config,
384
+ { category, comment, name, email, selection },
385
+ { context: launchContext, clientId: clientIdRef.current }
386
+ );
387
+ const result = await sendFeedback(
388
+ config,
389
+ payload,
390
+ attachments.map((a) => a.blob),
391
+ turnstileRef.current
392
+ );
393
+ setStatus(result.queued ? "queued" : "success");
394
+ config.onSubmitted?.(result);
395
+ } catch (err) {
396
+ setStatus("error");
397
+ setError(errorMessage(err));
398
+ }
399
+ };
400
+ const submitting = status === "submitting";
401
+ const counterVisible = comment.length >= COMMENT_COUNTER_THRESHOLD;
402
+ const anonymous = !config.user;
403
+ const canAttachMore = attachments.length < options.maxAttachments;
404
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
405
+ /* @__PURE__ */ jsx(
406
+ "dialog",
407
+ {
408
+ ref: dialogRef,
409
+ className: "chf chf-dialog",
410
+ "aria-labelledby": ids.title,
411
+ "aria-describedby": done ? void 0 : ids.desc,
412
+ onPointerDown: (e) => {
413
+ pointerOnBackdropRef.current = e.target === e.currentTarget;
414
+ },
415
+ onClick: (e) => {
416
+ if (e.target === e.currentTarget && pointerOnBackdropRef.current) requestClose();
417
+ pointerOnBackdropRef.current = false;
418
+ },
419
+ onPaste,
420
+ children: /* @__PURE__ */ jsxs("div", { className: "chf-dialog__panel", children: [
421
+ /* @__PURE__ */ jsxs("div", { className: "chf-dialog__header", children: [
422
+ /* @__PURE__ */ jsx("h2", { id: ids.title, className: "chf-dialog__title", children: selection ? MESSAGES.titleSelection : MESSAGES.titlePage }),
423
+ /* @__PURE__ */ jsx(
424
+ "button",
425
+ {
426
+ type: "button",
427
+ className: "chf-icon-btn chf-dialog__close",
428
+ "aria-label": MESSAGES.close,
429
+ onClick: requestClose,
430
+ children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xD7" })
431
+ }
432
+ )
433
+ ] }),
434
+ done ? /* @__PURE__ */ jsxs("div", { className: `chf-result chf-result--${status}`, role: "status", "aria-live": "polite", children: [
435
+ /* @__PURE__ */ jsx("span", { className: "chf-result__icon", "aria-hidden": "true", children: status === "queued" ? "\u21E1" : "\u2713" }),
436
+ /* @__PURE__ */ jsx("p", { className: "chf-result__title", children: status === "queued" ? MESSAGES.queuedTitle : MESSAGES.successTitle }),
437
+ /* @__PURE__ */ jsx("p", { className: "chf-result__body", children: status === "queued" ? MESSAGES.queuedBody : MESSAGES.successBody }),
438
+ /* @__PURE__ */ jsx(
439
+ "button",
440
+ {
441
+ ref: doneRef,
442
+ type: "button",
443
+ className: "chf-btn chf-btn--primary",
444
+ onClick: () => closeFeedback(),
445
+ children: MESSAGES.done
446
+ }
447
+ )
448
+ ] }) : /* @__PURE__ */ jsxs("form", { className: "chf-form", noValidate: true, onSubmit, children: [
449
+ /* @__PURE__ */ jsx("p", { id: ids.desc, className: "chf-dialog__desc", children: selection ? MESSAGES.descSelection : MESSAGES.descPage }),
450
+ selection ? /* @__PURE__ */ jsxs("figure", { className: "chf-quote", children: [
451
+ /* @__PURE__ */ jsx("blockquote", { className: "chf-quote__text", children: selection.quote }),
452
+ selection.headingText && /* @__PURE__ */ jsxs("figcaption", { className: "chf-quote__cite", children: [
453
+ MESSAGES.quoteUnder,
454
+ " \u201C",
455
+ selection.headingText,
456
+ "\u201D"
457
+ ] }),
458
+ /* @__PURE__ */ jsxs("div", { className: "chf-quote__actions", children: [
459
+ options.selectionContainer && /* @__PURE__ */ jsx(
460
+ "button",
461
+ {
462
+ type: "button",
463
+ className: "chf-link-btn",
464
+ "aria-label": "Change the attached passage",
465
+ onClick: startPicking,
466
+ children: MESSAGES.quoteChange
467
+ }
468
+ ),
469
+ /* @__PURE__ */ jsx(
470
+ "button",
471
+ {
472
+ type: "button",
473
+ className: "chf-link-btn",
474
+ "aria-label": "Remove the attached passage",
475
+ onClick: () => setSelection(null),
476
+ children: MESSAGES.quoteRemove
477
+ }
478
+ )
479
+ ] })
480
+ ] }) : options.selectionContainer && /* @__PURE__ */ jsxs("button", { type: "button", className: "chf-attach-btn", onClick: startPicking, children: [
481
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u270E" }),
482
+ " ",
483
+ MESSAGES.attachPassage
484
+ ] }),
485
+ /* @__PURE__ */ jsxs("fieldset", { className: "chf-field", children: [
486
+ /* @__PURE__ */ jsx("legend", { id: ids.category, className: "chf-label", children: MESSAGES.categoryLegend }),
487
+ /* @__PURE__ */ jsx("div", { className: "chf-chips", role: "radiogroup", "aria-labelledby": ids.category, children: options.categories.map((c) => /* @__PURE__ */ jsxs(
488
+ "label",
489
+ {
490
+ className: "chf-chip",
491
+ "data-checked": category === c.value ? "true" : void 0,
492
+ children: [
493
+ /* @__PURE__ */ jsx(
494
+ "input",
495
+ {
496
+ type: "radio",
497
+ className: "chf-chip__input",
498
+ name: `${id}-category-input`,
499
+ value: c.value,
500
+ checked: category === c.value,
501
+ onChange: () => setCategory(c.value)
502
+ }
503
+ ),
504
+ c.label
505
+ ]
506
+ },
507
+ c.value
508
+ )) })
509
+ ] }),
510
+ /* @__PURE__ */ jsxs("div", { className: "chf-field", children: [
511
+ /* @__PURE__ */ jsxs("label", { htmlFor: ids.comment, className: "chf-label", children: [
512
+ MESSAGES.commentLabel,
513
+ " ",
514
+ /* @__PURE__ */ jsx("span", { className: "chf-required", "aria-hidden": "true", children: "*" })
515
+ ] }),
516
+ /* @__PURE__ */ jsx(
517
+ "textarea",
518
+ {
519
+ ref: textareaRef,
520
+ id: ids.comment,
521
+ className: "chf-textarea",
522
+ rows: 5,
523
+ required: true,
524
+ "aria-required": "true",
525
+ maxLength: FEEDBACK_LIMITS.commentMax,
526
+ placeholder: MESSAGES.commentPlaceholder,
527
+ "aria-invalid": fieldErrors.comment ? "true" : void 0,
528
+ "aria-describedby": [fieldErrors.comment ? ids.commentError : "", counterVisible ? ids.counter : ""].filter(Boolean).join(" ") || void 0,
529
+ value: comment,
530
+ onChange: (e) => {
531
+ setComment(e.target.value);
532
+ if (fieldErrors.comment) setFieldErrors((f) => ({ ...f, comment: void 0 }));
533
+ }
534
+ }
535
+ ),
536
+ (fieldErrors.comment || counterVisible) && /* @__PURE__ */ jsxs("div", { className: "chf-field__meta", children: [
537
+ fieldErrors.comment && /* @__PURE__ */ jsx("p", { id: ids.commentError, className: "chf-field-error", children: fieldErrors.comment }),
538
+ counterVisible && /* @__PURE__ */ jsxs(
539
+ "span",
540
+ {
541
+ id: ids.counter,
542
+ className: "chf-counter",
543
+ "data-over": comment.length >= FEEDBACK_LIMITS.commentMax ? "true" : void 0,
544
+ children: [
545
+ comment.length,
546
+ " / ",
547
+ FEEDBACK_LIMITS.commentMax
548
+ ]
549
+ }
550
+ )
551
+ ] })
552
+ ] }),
553
+ options.maxAttachments > 0 && /* @__PURE__ */ jsxs(
554
+ "div",
555
+ {
556
+ className: "chf-field chf-attachments",
557
+ role: "group",
558
+ "aria-labelledby": ids.attachments,
559
+ children: [
560
+ /* @__PURE__ */ jsxs("span", { id: ids.attachments, className: "chf-label", children: [
561
+ MESSAGES.attachmentsLabel,
562
+ " ",
563
+ /* @__PURE__ */ jsxs("span", { className: "chf-hint", children: [
564
+ "(",
565
+ MESSAGES.optional,
566
+ options.maxAttachments > 1 ? `, up to ${options.maxAttachments}` : "",
567
+ ")"
568
+ ] })
569
+ ] }),
570
+ attachments.length > 0 && /* @__PURE__ */ jsx("ul", { className: "chf-thumbs", children: attachments.map((a, i) => /* @__PURE__ */ jsxs("li", { className: "chf-thumb", children: [
571
+ /* @__PURE__ */ jsx(
572
+ "img",
573
+ {
574
+ className: "chf-thumb__img",
575
+ src: a.url,
576
+ alt: MESSAGES.attachmentAlt(i + 1)
577
+ }
578
+ ),
579
+ /* @__PURE__ */ jsx(
580
+ "button",
581
+ {
582
+ type: "button",
583
+ className: "chf-thumb__remove",
584
+ "aria-label": MESSAGES.removeAttachment(i + 1),
585
+ onClick: () => removeAttachment(a.id),
586
+ children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xD7" })
587
+ }
588
+ )
589
+ ] }, a.id)) }),
590
+ canAttachMore && /* @__PURE__ */ jsxs(
591
+ "div",
592
+ {
593
+ className: "chf-dropzone",
594
+ "data-active": dragActive ? "true" : void 0,
595
+ onDragOver: (e) => {
596
+ e.preventDefault();
597
+ setDragActive(true);
598
+ },
599
+ onDragLeave: () => setDragActive(false),
600
+ onDrop,
601
+ children: [
602
+ /* @__PURE__ */ jsx("p", { className: "chf-dropzone__prompt", children: MESSAGES.dropPrompt }),
603
+ /* @__PURE__ */ jsxs("div", { className: "chf-dropzone__actions", children: [
604
+ /* @__PURE__ */ jsx(
605
+ "input",
606
+ {
607
+ ref: fileRef,
608
+ type: "file",
609
+ className: "chf-visually-hidden",
610
+ tabIndex: -1,
611
+ "aria-hidden": "true",
612
+ accept: ACCEPT_ATTRIBUTE,
613
+ multiple: options.maxAttachments - attachments.length > 1,
614
+ onChange: onFileChange
615
+ }
616
+ ),
617
+ /* @__PURE__ */ jsx(
618
+ "button",
619
+ {
620
+ type: "button",
621
+ className: "chf-btn chf-btn--secondary chf-btn--sm",
622
+ disabled: processing,
623
+ onClick: () => fileRef.current?.click(),
624
+ children: MESSAGES.chooseImage
625
+ }
626
+ ),
627
+ options.allowScreenshotCapture && /* @__PURE__ */ jsxs(
628
+ "button",
629
+ {
630
+ type: "button",
631
+ className: "chf-btn chf-btn--secondary chf-btn--sm",
632
+ disabled: capturing || processing,
633
+ "aria-busy": capturing || void 0,
634
+ onClick: () => void onCapture(),
635
+ children: [
636
+ capturing && /* @__PURE__ */ jsx("span", { className: "chf-spinner", "aria-hidden": "true" }),
637
+ capturing ? MESSAGES.capturing : MESSAGES.capturePage
638
+ ]
639
+ }
640
+ )
641
+ ] })
642
+ ]
643
+ }
644
+ ),
645
+ /* @__PURE__ */ jsx("p", { className: "chf-hint", "aria-live": "polite", children: processing ? MESSAGES.processing : "" }),
646
+ attachError && /* @__PURE__ */ jsx("p", { className: "chf-field-error", children: attachError })
647
+ ]
648
+ }
649
+ ),
650
+ /* @__PURE__ */ jsxs("div", { className: "chf-row", children: [
651
+ /* @__PURE__ */ jsxs("div", { className: "chf-field", children: [
652
+ /* @__PURE__ */ jsxs("label", { htmlFor: ids.name, className: "chf-label", children: [
653
+ MESSAGES.name,
654
+ anonymous && /* @__PURE__ */ jsxs("span", { className: "chf-hint", children: [
655
+ " (",
656
+ MESSAGES.optional,
657
+ ")"
658
+ ] })
659
+ ] }),
660
+ /* @__PURE__ */ jsx(
661
+ "input",
662
+ {
663
+ id: ids.name,
664
+ className: "chf-input",
665
+ type: "text",
666
+ autoComplete: "name",
667
+ maxLength: FEEDBACK_LIMITS.nameMax,
668
+ value: name,
669
+ onChange: (e) => setName(e.target.value)
670
+ }
671
+ )
672
+ ] }),
673
+ /* @__PURE__ */ jsxs("div", { className: "chf-field", children: [
674
+ /* @__PURE__ */ jsxs("label", { htmlFor: ids.email, className: "chf-label", children: [
675
+ MESSAGES.email,
676
+ anonymous && /* @__PURE__ */ jsxs("span", { className: "chf-hint", children: [
677
+ " (",
678
+ MESSAGES.optional,
679
+ ")"
680
+ ] })
681
+ ] }),
682
+ /* @__PURE__ */ jsx(
683
+ "input",
684
+ {
685
+ ref: emailRef,
686
+ id: ids.email,
687
+ className: "chf-input",
688
+ type: "email",
689
+ autoComplete: "email",
690
+ maxLength: FEEDBACK_LIMITS.emailMax,
691
+ "aria-invalid": fieldErrors.email ? "true" : void 0,
692
+ "aria-describedby": fieldErrors.email ? ids.emailError : void 0,
693
+ value: email,
694
+ onChange: (e) => {
695
+ setEmail(e.target.value);
696
+ if (fieldErrors.email) setFieldErrors((f) => ({ ...f, email: void 0 }));
697
+ }
698
+ }
699
+ ),
700
+ fieldErrors.email && /* @__PURE__ */ jsx("p", { id: ids.emailError, className: "chf-field-error", children: fieldErrors.email })
701
+ ] })
702
+ ] }),
703
+ showTurnstile && /* @__PURE__ */ jsx("div", { ref: turnstileElRef, className: "chf-turnstile" }),
704
+ error && /* @__PURE__ */ jsx("div", { className: "chf-alert", role: "alert", children: error }),
705
+ confirming ? /* @__PURE__ */ jsxs("div", { className: "chf-confirm", role: "group", "aria-labelledby": `${id}-confirm`, children: [
706
+ /* @__PURE__ */ jsx("p", { id: `${id}-confirm`, className: "chf-confirm__text", children: MESSAGES.discardPrompt }),
707
+ /* @__PURE__ */ jsxs("div", { className: "chf-confirm__actions", children: [
708
+ /* @__PURE__ */ jsx(
709
+ "button",
710
+ {
711
+ ref: keepEditingRef,
712
+ type: "button",
713
+ className: "chf-btn chf-btn--secondary chf-btn--sm",
714
+ onClick: () => {
715
+ setConfirming(false);
716
+ textareaRef.current?.focus();
717
+ },
718
+ children: MESSAGES.keepEditing
719
+ }
720
+ ),
721
+ /* @__PURE__ */ jsx(
722
+ "button",
723
+ {
724
+ type: "button",
725
+ className: "chf-btn chf-btn--primary chf-btn--sm",
726
+ onClick: () => closeFeedback(),
727
+ children: MESSAGES.discard
728
+ }
729
+ )
730
+ ] })
731
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "chf-actions", children: [
732
+ /* @__PURE__ */ jsx(
733
+ "button",
734
+ {
735
+ type: "button",
736
+ className: "chf-btn chf-btn--ghost",
737
+ disabled: submitting,
738
+ onClick: requestClose,
739
+ children: MESSAGES.cancel
740
+ }
741
+ ),
742
+ /* @__PURE__ */ jsxs(
743
+ "button",
744
+ {
745
+ type: "submit",
746
+ className: "chf-btn chf-btn--primary",
747
+ disabled: submitting,
748
+ "aria-busy": submitting || void 0,
749
+ children: [
750
+ submitting && /* @__PURE__ */ jsx("span", { className: "chf-spinner", "aria-hidden": "true" }),
751
+ submitting ? MESSAGES.submitting : MESSAGES.submit
752
+ ]
753
+ }
754
+ )
755
+ ] })
756
+ ] })
757
+ ] })
758
+ }
759
+ ),
760
+ picking && /* @__PURE__ */ jsxs("div", { className: "chf chf-picking-bar", role: "status", children: [
761
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u270E" }),
762
+ /* @__PURE__ */ jsx("span", { children: MESSAGES.pickingPrompt }),
763
+ /* @__PURE__ */ jsx(
764
+ "button",
765
+ {
766
+ type: "button",
767
+ className: "chf-picking-bar__cancel",
768
+ onMouseDown: (e) => e.preventDefault(),
769
+ onClick: () => setPicking(false),
770
+ children: MESSAGES.pickingCancel
771
+ }
772
+ )
773
+ ] })
774
+ ] });
775
+ }
776
+
777
+ // src/useFeedback.ts
778
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
779
+ import {
780
+ closeFeedback as closeFeedback2,
781
+ getServerState as getServerState2,
782
+ getState as getState2,
783
+ openFeedback as openFeedback2,
784
+ subscribe as subscribe2
785
+ } from "@classic-homes/feedback-core";
786
+ function useFeedback() {
787
+ const state = useSyncExternalStore2(subscribe2, getState2, getServerState2);
788
+ return { open: openFeedback2, close: closeFeedback2, isOpen: state.open };
789
+ }
790
+
791
+ // src/index.ts
792
+ import {
793
+ openFeedback as openFeedback3,
794
+ closeFeedback as closeFeedback3,
795
+ submitFeedback,
796
+ FeedbackError,
797
+ isFeedbackError,
798
+ DEFAULT_CATEGORIES
799
+ } from "@classic-homes/feedback-core";
800
+ export {
801
+ DEFAULT_CATEGORIES,
802
+ FeedbackError,
803
+ FeedbackWidget,
804
+ closeFeedback3 as closeFeedback,
805
+ isFeedbackError,
806
+ openFeedback3 as openFeedback,
807
+ submitFeedback,
808
+ useFeedback
809
+ };