@eifi1/ui-kit 0.26.0 → 0.27.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.
Files changed (158) hide show
  1. package/README.md +15 -4
  2. package/dist/chart.d.ts +13 -9
  3. package/dist/components/account-chips.d.ts +1 -1
  4. package/dist/components/amount-input.d.ts +13 -9
  5. package/dist/components/button-group.d.ts +13 -9
  6. package/dist/components/calculator.d.ts +13 -9
  7. package/dist/components/confirm-dialog.d.ts +13 -9
  8. package/dist/components/copy-button.d.ts +10 -6
  9. package/dist/components/danger-confirm.d.ts +13 -9
  10. package/dist/components/data-table-cells.d.ts +1 -1
  11. package/dist/components/data-table-filter-popover.d.ts +1 -1
  12. package/dist/components/data-table-filters.d.ts +1 -1
  13. package/dist/components/data-table-labels.d.ts +1 -1
  14. package/dist/components/data-table-pagination.d.ts +1 -1
  15. package/dist/components/data-table.d.ts +1 -1
  16. package/dist/components/data-table.js.map +1 -1
  17. package/dist/components/facing-pair.d.ts +13 -9
  18. package/dist/components/file-button.d.ts +13 -9
  19. package/dist/components/file-dropzone.d.ts +13 -9
  20. package/dist/components/form-actions.d.ts +13 -9
  21. package/dist/components/iban-input.d.ts +13 -9
  22. package/dist/components/language-select.d.ts +13 -9
  23. package/dist/components/money-field.d.ts +13 -9
  24. package/dist/components/number-field.d.ts +13 -9
  25. package/dist/components/number-input.d.ts +13 -9
  26. package/dist/components/numpad-sheet.d.ts +13 -9
  27. package/dist/components/phone-input.d.ts +13 -9
  28. package/dist/components/series-chart.d.ts +13 -9
  29. package/dist/components/settings-fields.d.ts +13 -9
  30. package/dist/components/share-card.d.ts +13 -9
  31. package/dist/components/text-link.d.ts +13 -9
  32. package/dist/components/time-input.d.ts +13 -9
  33. package/dist/components/ui.d.ts +10 -6
  34. package/dist/components/use-table-state.d.ts +1 -1
  35. package/dist/{data-table-labels-Cdn1QS2k.d.ts → data-table-labels-DUELeXpa.d.ts} +5 -0
  36. package/dist/data-table.d.ts +1 -1
  37. package/dist/feedback/feedback-attachment.d.ts +13 -9
  38. package/dist/feedback/feedback-attachment.js +3 -3
  39. package/dist/feedback/feedback-attachment.js.map +1 -1
  40. package/dist/feedback/feedback-capture.d.ts +71 -0
  41. package/dist/feedback/feedback-capture.js +194 -0
  42. package/dist/feedback/feedback-capture.js.map +1 -0
  43. package/dist/feedback/feedback-context.d.ts +71 -0
  44. package/dist/feedback/feedback-context.js +96 -0
  45. package/dist/feedback/feedback-context.js.map +1 -0
  46. package/dist/feedback/feedback-crash.d.ts +276 -0
  47. package/dist/feedback/feedback-crash.js +225 -0
  48. package/dist/feedback/feedback-crash.js.map +1 -0
  49. package/dist/feedback/feedback-dialog.d.ts +13 -9
  50. package/dist/feedback/feedback-dialog.js +5 -3
  51. package/dist/feedback/feedback-dialog.js.map +1 -1
  52. package/dist/feedback/feedback-inbox.d.ts +13 -9
  53. package/dist/feedback/feedback-inbox.js +89 -49
  54. package/dist/feedback/feedback-inbox.js.map +1 -1
  55. package/dist/feedback/feedback-labels.d.ts +71 -0
  56. package/dist/feedback/feedback-labels.js +48 -0
  57. package/dist/feedback/feedback-labels.js.map +1 -0
  58. package/dist/feedback/feedback-menu.d.ts +71 -0
  59. package/dist/feedback/feedback-menu.js +61 -0
  60. package/dist/feedback/feedback-menu.js.map +1 -0
  61. package/dist/feedback/feedback-record.d.ts +71 -0
  62. package/dist/feedback/feedback-record.js +104 -0
  63. package/dist/feedback/feedback-record.js.map +1 -0
  64. package/dist/feedback/feedback-row-detail.d.ts +71 -0
  65. package/dist/feedback/feedback-row-detail.js +437 -0
  66. package/dist/feedback/feedback-row-detail.js.map +1 -0
  67. package/dist/feedback/feedback-status-undo.d.ts +71 -0
  68. package/dist/feedback/feedback-status-undo.js +40 -0
  69. package/dist/feedback/feedback-status-undo.js.map +1 -0
  70. package/dist/feedback/feedback-submit.d.ts +182 -0
  71. package/dist/feedback/feedback-submit.js +101 -0
  72. package/dist/feedback/feedback-submit.js.map +1 -0
  73. package/dist/feedback/feedback-swipe.d.ts +152 -0
  74. package/dist/feedback/feedback-swipe.js +73 -0
  75. package/dist/feedback/feedback-swipe.js.map +1 -0
  76. package/dist/feedback/feedback-table.d.ts +71 -0
  77. package/dist/feedback/feedback-table.js +357 -0
  78. package/dist/feedback/feedback-table.js.map +1 -0
  79. package/dist/feedback/feedback-thread.d.ts +13 -9
  80. package/dist/feedback.d.ts +17 -9
  81. package/dist/feedback.js +11 -0
  82. package/dist/feedback.js.map +1 -1
  83. package/dist/hooks/use-file-drop.d.ts +13 -9
  84. package/dist/i18n/defaults.d.ts +13 -9
  85. package/dist/i18n/defaults.js +16 -0
  86. package/dist/i18n/defaults.js.map +1 -1
  87. package/dist/i18n/german.d.ts +13 -9
  88. package/dist/i18n/german.js +91 -5
  89. package/dist/i18n/german.js.map +1 -1
  90. package/dist/i18n/kit-labels.d.ts +7 -3
  91. package/dist/i18n/kit-labels.js.map +1 -1
  92. package/dist/i18n/languages.d.ts +13 -9
  93. package/dist/i18n/locales/de-CH.d.ts +13 -9
  94. package/dist/i18n/locales/en.d.ts +13 -9
  95. package/dist/i18n/locales/en.js +10 -1
  96. package/dist/i18n/locales/en.js.map +1 -1
  97. package/dist/i18n/locales/es.d.ts +13 -9
  98. package/dist/i18n/locales/es.js +89 -5
  99. package/dist/i18n/locales/es.js.map +1 -1
  100. package/dist/i18n/locales/fr.d.ts +13 -9
  101. package/dist/i18n/locales/fr.js +89 -5
  102. package/dist/i18n/locales/fr.js.map +1 -1
  103. package/dist/i18n/locales/hu.d.ts +13 -9
  104. package/dist/i18n/locales/hu.js +90 -5
  105. package/dist/i18n/locales/hu.js.map +1 -1
  106. package/dist/i18n/locales/it.d.ts +13 -9
  107. package/dist/i18n/locales/it.js +89 -5
  108. package/dist/i18n/locales/it.js.map +1 -1
  109. package/dist/i18n/locales/zh.d.ts +13 -9
  110. package/dist/i18n/locales/zh.js +89 -5
  111. package/dist/i18n/locales/zh.js.map +1 -1
  112. package/dist/i18n/review.d.ts +16 -11
  113. package/dist/i18n/review.js +11 -0
  114. package/dist/i18n/review.js.map +1 -1
  115. package/dist/i18n/swiss.js +3 -1
  116. package/dist/i18n/swiss.js.map +1 -1
  117. package/dist/index.d.ts +6 -2
  118. package/dist/index.js +11 -0
  119. package/dist/index.js.map +1 -1
  120. package/dist/{feedback-BXKH-ToU.d.ts → kit-labels-DQg82eHB.d.ts} +1275 -25
  121. package/dist/rhf/fields.d.ts +13 -9
  122. package/dist/rhf/form.d.ts +13 -9
  123. package/dist/rhf.d.ts +13 -9
  124. package/dist/shell/app-shell.d.ts +13 -9
  125. package/dist/shell/top-bar-brand.d.ts +13 -9
  126. package/dist/shell.d.ts +11 -11
  127. package/dist/wizard/stepper-nav.d.ts +13 -9
  128. package/dist/wizard.d.ts +13 -9
  129. package/package.json +6 -1
  130. package/src/components/data-table.tsx +5 -0
  131. package/src/feedback/feedback-attachment.tsx +19 -3
  132. package/src/feedback/feedback-capture.ts +285 -0
  133. package/src/feedback/feedback-context.tsx +217 -0
  134. package/src/feedback/feedback-crash.ts +547 -0
  135. package/src/feedback/feedback-dialog.tsx +29 -6
  136. package/src/feedback/feedback-inbox.tsx +131 -27
  137. package/src/feedback/feedback-labels.ts +127 -0
  138. package/src/feedback/feedback-menu.tsx +132 -0
  139. package/src/feedback/feedback-record.ts +345 -0
  140. package/src/feedback/feedback-row-detail.tsx +825 -0
  141. package/src/feedback/feedback-status-undo.ts +111 -0
  142. package/src/feedback/feedback-submit.tsx +224 -0
  143. package/src/feedback/feedback-swipe.tsx +170 -0
  144. package/src/feedback/feedback-table.tsx +757 -0
  145. package/src/feedback.ts +13 -0
  146. package/src/i18n/defaults.ts +16 -0
  147. package/src/i18n/german.ts +98 -5
  148. package/src/i18n/kit-labels.tsx +20 -0
  149. package/src/i18n/locales/en.ts +15 -1
  150. package/src/i18n/locales/es.ts +96 -5
  151. package/src/i18n/locales/fr.ts +95 -5
  152. package/src/i18n/locales/hu.ts +94 -5
  153. package/src/i18n/locales/it.ts +97 -5
  154. package/src/i18n/locales/zh.ts +90 -5
  155. package/src/i18n/review.ts +14 -2
  156. package/src/i18n/swiss.ts +5 -1
  157. package/src/index.ts +13 -0
  158. package/tokens.css +4 -0
@@ -0,0 +1,285 @@
1
+ /**
2
+ * `captureAppScreenshot` — the picture of the app a feedback report attaches (0.27.0,
3
+ * docs/feedback-harmonization.md §5).
4
+ *
5
+ * Lifted from keksdose `frontend/src/features/feedback/capture-screenshot.ts` (live #271),
6
+ * which is the canon: Kurvenschmiede carried a second copy (`capture-page.ts`) with none of
7
+ * its speed-ups, and kastlan had no capture at all. Each app wrote the same three awkward
8
+ * decisions — which element, which library, what to do when it throws — and they drifted
9
+ * the moment there were two copies (Kurvenschmiede feedback #128 says exactly that).
10
+ *
11
+ * WHY IT IS FAST (keksdose live #271: *"Capture screenshot — That takes ages in my mobile
12
+ * phone"*). `modern-screenshot` deep-clones the subtree and inlines every node's computed
13
+ * style onto the clone, because the final image is an SVG `foreignObject` that carries no
14
+ * stylesheets. By default it walks the WHOLE computed style (~340 longhands in Chrome) per
15
+ * element; keksdose's /transactions has ~4,800 elements under `#root` at phone width, so
16
+ * that was ~1.6 million `getPropertyValue` calls before a pixel was drawn — 21–52 s on a
17
+ * desktop CPU, 153–160 s with the CPU throttled 4×. Two levers fixed it, both kept here:
18
+ *
19
+ * 1. {@link CAPTURE_STYLE_PROPERTIES} — copy the ~140 longhands a Tailwind v4 app built
20
+ * on this kit actually uses. Alone: 21 s → 1.8 s.
21
+ * 2. {@link inViewport} drops `display: none` subtrees — on a phone most of the
22
+ * document, since `DataTable` renders both layouts and hides one — and anything
23
+ * wholly outside the viewport. Together: 27–52 s → 0.4–1.1 s, the picture
24
+ * 0.05% of pixels different (antialiasing).
25
+ *
26
+ * Plus WebP at 0.9 (222 KB → 46 KB, an upload a phone makes on a mobile connection) with
27
+ * the file named from what the canvas ACTUALLY produced — a browser without WebP encodes
28
+ * PNG, and a "screenshot.webp" that is a PNG is refused by the server on its type — and
29
+ * `font: false`, since the app's faces are same-origin and already in the page.
30
+ *
31
+ * WHY THE PEER IS LOADED DYNAMICALLY. `modern-screenshot` is an OPTIONAL peer
32
+ * (`peerDependenciesMeta.optional`, like `sonner`), and this module is re-exported by the
33
+ * barrel: a static import would make every app that imports a Button install it. It is
34
+ * imported inside the function, so an app pays nothing until somebody presses "Capture
35
+ * screenshot", and an app without it gets a REJECTED promise — which the submit dialog
36
+ * turns into the "Could not capture a screenshot" toast (`feedbackToast.captureFailed`).
37
+ *
38
+ * WHAT IS NOT HERE: Kurvenschmiede's `features: { restoreScrollPosition: true }` (its
39
+ * feedback #153: a capture of a scrolled `<main>` came out as the TOP of the page). The
40
+ * viewport filter already answers that case — what is scrolled out of view is dropped, so
41
+ * what remains is what was on screen, give or take the part of the first row that was
42
+ * scrolled past (checked in Chromium, 0.27.0: an inner `<main>` scrolled to row 20 captures
43
+ * rows 20–26). Both together are worse than either: the clone is translated by the scroll
44
+ * offset AFTER the rows above were dropped, and the picture came out blank below the
45
+ * header (same check).
46
+ */
47
+
48
+ /**
49
+ * The computed properties copied onto the clone (keksdose `capture-screenshot.ts:94`).
50
+ *
51
+ * LONGHANDS only: `getPropertyValue()` resolves a shorthand to `""` whenever its longhands
52
+ * disagree, so `"border"` would silently drop every one-sided border. Chosen by what
53
+ * Tailwind v4 emits rather than by what looks complete: `font-variant-numeric` because
54
+ * money is `tabular-nums`, the SVG paint properties because every icon is a lucide `<svg>`
55
+ * inheriting `stroke: currentColor`.
56
+ */
57
+ const CAPTURE_STYLE_PROPERTIES: readonly string[] = [
58
+ // box
59
+ "display",
60
+ "position",
61
+ "top",
62
+ "right",
63
+ "bottom",
64
+ "left",
65
+ "width",
66
+ "height",
67
+ "min-width",
68
+ "min-height",
69
+ "max-width",
70
+ "max-height",
71
+ "box-sizing",
72
+ "margin-top",
73
+ "margin-right",
74
+ "margin-bottom",
75
+ "margin-left",
76
+ "padding-top",
77
+ "padding-right",
78
+ "padding-bottom",
79
+ "padding-left",
80
+ "overflow-x",
81
+ "overflow-y",
82
+ "z-index",
83
+ "float",
84
+ "clear",
85
+ "aspect-ratio",
86
+ "inset-inline-start",
87
+ "inset-inline-end",
88
+ // flex + grid
89
+ "flex-direction",
90
+ "flex-wrap",
91
+ "flex-grow",
92
+ "flex-shrink",
93
+ "flex-basis",
94
+ "align-items",
95
+ "align-self",
96
+ "align-content",
97
+ "justify-content",
98
+ "justify-items",
99
+ "justify-self",
100
+ "row-gap",
101
+ "column-gap",
102
+ "order",
103
+ "grid-template-columns",
104
+ "grid-template-rows",
105
+ "grid-column-start",
106
+ "grid-column-end",
107
+ "grid-row-start",
108
+ "grid-row-end",
109
+ "grid-auto-flow",
110
+ "grid-auto-rows",
111
+ "grid-auto-columns",
112
+ // type
113
+ "color",
114
+ "font-family",
115
+ "font-size",
116
+ "font-weight",
117
+ "font-style",
118
+ "font-variant-numeric",
119
+ "font-feature-settings",
120
+ "line-height",
121
+ "letter-spacing",
122
+ "word-spacing",
123
+ "text-align",
124
+ "text-indent",
125
+ "text-transform",
126
+ "text-overflow",
127
+ "text-decoration-line",
128
+ "text-decoration-color",
129
+ "text-decoration-style",
130
+ "text-decoration-thickness",
131
+ "text-underline-offset",
132
+ "white-space",
133
+ "word-break",
134
+ "overflow-wrap",
135
+ "vertical-align",
136
+ "direction",
137
+ "list-style-type",
138
+ "list-style-position",
139
+ "-webkit-line-clamp",
140
+ "-webkit-box-orient",
141
+ "-webkit-text-fill-color",
142
+ // paint
143
+ "background-color",
144
+ "background-image",
145
+ "background-position",
146
+ "background-repeat",
147
+ "background-size",
148
+ "background-clip",
149
+ "background-origin",
150
+ "opacity",
151
+ "visibility",
152
+ "box-shadow",
153
+ "filter",
154
+ "backdrop-filter",
155
+ "mix-blend-mode",
156
+ "clip-path",
157
+ // borders + outline
158
+ "border-top-width",
159
+ "border-right-width",
160
+ "border-bottom-width",
161
+ "border-left-width",
162
+ "border-top-style",
163
+ "border-right-style",
164
+ "border-bottom-style",
165
+ "border-left-style",
166
+ "border-top-color",
167
+ "border-right-color",
168
+ "border-bottom-color",
169
+ "border-left-color",
170
+ "border-top-left-radius",
171
+ "border-top-right-radius",
172
+ "border-bottom-right-radius",
173
+ "border-bottom-left-radius",
174
+ "outline-width",
175
+ "outline-style",
176
+ "outline-color",
177
+ "outline-offset",
178
+ // transform
179
+ "transform",
180
+ "transform-origin",
181
+ "rotate",
182
+ "scale",
183
+ "translate",
184
+ // tables
185
+ "border-collapse",
186
+ "border-spacing",
187
+ "table-layout",
188
+ "caption-side",
189
+ // replaced content + svg
190
+ "object-fit",
191
+ "object-position",
192
+ "fill",
193
+ "fill-opacity",
194
+ "fill-rule",
195
+ "stroke",
196
+ "stroke-opacity",
197
+ "stroke-width",
198
+ "stroke-linecap",
199
+ "stroke-linejoin",
200
+ "stroke-dasharray",
201
+ "stroke-dashoffset",
202
+ "shape-rendering",
203
+ "paint-order",
204
+ ];
205
+
206
+ /** The extension that belongs to what the canvas actually produced (keksdose
207
+ * `capture-screenshot.ts:247`). */
208
+ const EXTENSIONS: Record<string, string> = {
209
+ "image/webp": "webp",
210
+ "image/jpeg": "jpg",
211
+ "image/png": "png",
212
+ };
213
+
214
+ /**
215
+ * Keep a node only if it can paint inside the viewport (keksdose `capture-screenshot.ts:267`).
216
+ *
217
+ * - `display: none` goes, with its subtree — it paints nothing and no descendant can.
218
+ * `<style>` and `<link>` are computed `display: none` too but are NOT decoration: a
219
+ * stylesheet inside the captured subtree still applies inside the `foreignObject`.
220
+ * `visibility: hidden` is deliberately not checked: a descendant may set it back.
221
+ * - A box wholly outside the viewport goes: the root is viewport-sized (the app scrolls an
222
+ * inner `<main>`), so it would have been clipped away unseen.
223
+ * - A ZERO box is kept: `display: contents` reports 0×0 while its children paint, and the
224
+ * library's filter drops a rejected node's children too.
225
+ */
226
+ function inViewport(node: Node): boolean {
227
+ if (node.nodeType !== Node.ELEMENT_NODE) return true;
228
+ const el = node as Element;
229
+ const tag = el.tagName;
230
+ if (tag !== "STYLE" && tag !== "LINK") {
231
+ const display = el.ownerDocument?.defaultView?.getComputedStyle(el).display;
232
+ if (display === "none") return false;
233
+ }
234
+ const rect = el.getBoundingClientRect?.();
235
+ if (!rect) return true;
236
+ if (rect.width === 0 && rect.height === 0) return true;
237
+ return !(rect.bottom <= 0 || rect.right <= 0 || rect.top >= window.innerHeight || rect.left >= window.innerWidth);
238
+ }
239
+
240
+ /** What `captureAppScreenshot` takes. */
241
+ export interface CaptureAppScreenshotOptions {
242
+ /**
243
+ * The id of the element to capture. Default `"root"` — the app's mount point, which is
244
+ * right on purpose: the kit's `Modal` portals to `document.body` as a SIBLING of `#root`,
245
+ * so capturing `#root` leaves the feedback dialog and its backdrop out of the picture
246
+ * without a single filter rule.
247
+ */
248
+ rootId?: string;
249
+ }
250
+
251
+ /**
252
+ * Snapshot the app view behind the feedback dialog, as a `File` ready for the upload —
253
+ * `screenshot.webp`, or `screenshot.png` where the browser cannot encode WebP.
254
+ *
255
+ * - Resolves `null` when there is no element with `rootId` — nothing to capture.
256
+ * - **Rejects** when the optional peer `modern-screenshot` is not installed (the error
257
+ * says so), or when the capture itself fails. It never swallows: what to say about a
258
+ * failure is the caller's — `useFeedbackSubmit` toasts `feedbackToast.captureFailed`.
259
+ *
260
+ * Call it from the "Capture screenshot" button's own click and nowhere else (keksdose
261
+ * checked: running it at dialog OPEN was suspected and was never the cause of the wait).
262
+ */
263
+ export async function captureAppScreenshot({ rootId = "root" }: CaptureAppScreenshotOptions = {}): Promise<File | null> {
264
+ let domToBlob: (typeof import("modern-screenshot"))["domToBlob"];
265
+ try {
266
+ ({ domToBlob } = await import("modern-screenshot"));
267
+ } catch (cause) {
268
+ throw new Error(
269
+ "@eifi1/ui-kit: captureAppScreenshot needs the optional peer `modern-screenshot` — install it (npm i modern-screenshot).",
270
+ { cause },
271
+ );
272
+ }
273
+ const el = document.getElementById(rootId);
274
+ if (!el) return null;
275
+ const blob = await domToBlob(el, {
276
+ // Falls back to PNG where WebP cannot be encoded; the File is named from the blob.
277
+ type: "image/webp",
278
+ quality: 0.9,
279
+ font: false,
280
+ includeStyleProperties: [...CAPTURE_STYLE_PROPERTIES],
281
+ filter: inViewport,
282
+ });
283
+ const type = blob.type || "image/png";
284
+ return new File([blob], `screenshot.${EXTENSIONS[type] ?? "png"}`, { type });
285
+ }
@@ -0,0 +1,217 @@
1
+ import { Checkbox } from "../components/checkbox";
2
+ import { DEFAULT_COMMON_LABELS, useKitLabels } from "../i18n/kit-labels";
3
+ import { cn } from "../lib/cn";
4
+ import type { FeedbackContext, FeedbackEnvironment } from "./feedback-record";
5
+
6
+ /**
7
+ * The reporter context of a feedback report: the box the submit dialog shows, and the
8
+ * `context` object `POST /feedback` sends (0.27.0, docs/feedback-harmonization.md §3.2,
9
+ * §4.2). One file for both, so what the box SAYS will be sent and what IS sent cannot
10
+ * drift apart.
11
+ *
12
+ * Each app had written both halves itself (keksdose `use-feedback-dialog.tsx:105` and
13
+ * `:222`, kastlan `feedback-button.tsx:80`, Kurvenschmiede `use-feedback-dialog.tsx:124`),
14
+ * and they had drifted: kastlan sent six keys with `user_email: null` and no version,
15
+ * Kurvenschmiede a `page_path` column and a sentence where keksdose had a labelled box,
16
+ * and only keksdose showed the full URL it was about to send.
17
+ */
18
+
19
+ /* ── Who is filing ───────────────────────────────────────────────────────── */
20
+
21
+ /**
22
+ * The person filing, as the app knows them. Snake case on purpose: keksdose's and
23
+ * Kurvenschmiede's user objects already have this shape (`id`, `email`, `display_name`),
24
+ * so they pass their `user` as it is; kastlan maps its token's `sub` and name parts.
25
+ *
26
+ * A SNAPSHOT for the report and the box. The server should overwrite the three `user_*`
27
+ * keys from the session (§3.2; Kurvenschmiede does), so nobody can file in someone else's
28
+ * name — this is what the reporter is SHOWN, not proof of who they are.
29
+ */
30
+ export interface FeedbackSubmitter {
31
+ id?: number | null;
32
+ email?: string | null;
33
+ display_name?: string | null;
34
+ }
35
+
36
+ /** "Ada Example (ada@example.com)", the name alone, the email alone, or "—" when the app
37
+ * knows neither (keksdose `use-feedback-dialog.tsx:228`). */
38
+ function submitterLine(user: FeedbackSubmitter | null | undefined): string {
39
+ const name = user?.display_name?.trim();
40
+ const email = user?.email?.trim();
41
+ if (name && email) return `${name} (${email})`;
42
+ return name || email || "—";
43
+ }
44
+
45
+ /* ── The object (§3.2) ───────────────────────────────────────────────────── */
46
+
47
+ /** What {@link feedbackContext} is built from. */
48
+ export interface FeedbackContextInput {
49
+ /** The submitter, or `null` when signed out / unknown — the three `user_*` keys are then
50
+ * `null`, as keksdose sends them. */
51
+ user?: FeedbackSubmitter | null;
52
+ /** The box's "Attach current page URL" checkbox. `false` withholds `url` and `route`
53
+ * (both `""`); nothing else is withheld — `origin` says which copy of the app, which is
54
+ * not personal, and triage needs it first (keksdose `use-feedback-dialog.tsx:110`). */
55
+ attachUrl: boolean;
56
+ /** `location.href` when the dialog OPENED — the page the report is about, not the one
57
+ * the reporter may have navigated to while typing. */
58
+ url: string;
59
+ /** Its pathname. Default: read off `url` (a path-only `url` works too). */
60
+ route?: string;
61
+ /** Default `location.origin`. */
62
+ origin?: string;
63
+ /** `"prod"` / `"dev"` / `"local"` — the app's own reading (keksdose
64
+ * `app/deploy-environment.ts`). Left out of the object when not given. */
65
+ environment?: FeedbackEnvironment | (string & {});
66
+ /** The app build (`__APP_VERSION__`). Left out of the object when not given. */
67
+ version?: string;
68
+ /** Default `${innerWidth}x${innerHeight}` at the time of the call — "406x816". */
69
+ viewport?: string;
70
+ /** Default `navigator.userAgent`. */
71
+ ua?: string;
72
+ }
73
+
74
+ /** The pathname of a full or path-only URL; `""` for something that is neither. */
75
+ function pathOf(url: string, base: string | undefined): string {
76
+ if (!url) return "";
77
+ try {
78
+ return new URL(url, base || "http://localhost").pathname;
79
+ } catch {
80
+ return "";
81
+ }
82
+ }
83
+
84
+ /**
85
+ * The `context` object of `POST /feedback` (§3.2), keys in keksdose's order: `url`, `route`,
86
+ * `origin`, `environment`, `user_id`, `user_email`, `user_display_name`, `viewport`, `ua`,
87
+ * `version`.
88
+ *
89
+ * With `attachUrl: false`, `url` and `route` are `""` — present and empty, as keksdose
90
+ * sends them, so a reader can tell "withheld" from "an old row without the key".
91
+ * `environment` and `version` are omitted when the app passes none (kastlan had no
92
+ * version), rather than sent as `undefined`.
93
+ *
94
+ * Reads `window` / `navigator` only for the defaults it was not given, so it is a pure
95
+ * function in a test that passes everything.
96
+ */
97
+ export function feedbackContext(input: FeedbackContextInput): FeedbackContext {
98
+ const { user, attachUrl, url } = input;
99
+ const win = typeof window === "undefined" ? undefined : window;
100
+ const origin = input.origin ?? win?.location.origin ?? "";
101
+ const context: FeedbackContext = {
102
+ url: attachUrl ? url : "",
103
+ route: attachUrl ? (input.route ?? pathOf(url, origin || win?.location.href)) : "",
104
+ origin,
105
+ };
106
+ if (input.environment !== undefined) context.environment = input.environment;
107
+ context.user_id = user?.id ?? null;
108
+ context.user_email = user?.email ?? null;
109
+ context.user_display_name = user?.display_name ?? null;
110
+ context.viewport = input.viewport ?? (win ? `${win.innerWidth}x${win.innerHeight}` : "");
111
+ context.ua = input.ua ?? (typeof navigator === "undefined" ? "" : navigator.userAgent);
112
+ if (input.version !== undefined) context.version = input.version;
113
+ return context;
114
+ }
115
+
116
+ /* ── The box (§4.2) ──────────────────────────────────────────────────────── */
117
+
118
+ /**
119
+ * `feedbackContext` — the context box's words. de-CH canon (keksdose `de-CH.json`):
120
+ * `user` "Nutzer", `attachUrl` "Aktuelle Seiten-URL anhängen".
121
+ */
122
+ export interface FeedbackContextLabels {
123
+ /** The submitter line's label — the box draws "**User:** Ada Example (ada@example.com)".
124
+ * The label alone: the colon between it and the person is the language's
125
+ * `common.fieldValue` (fr "Utilisateur : …", zh "用户:…"). */
126
+ user: string;
127
+ /** The checkbox. The URL it is about is the line beneath it. */
128
+ attachUrl: string;
129
+ }
130
+
131
+ export const DEFAULT_FEEDBACK_CONTEXT_LABELS: FeedbackContextLabels = {
132
+ user: "User",
133
+ attachUrl: "Attach current page URL",
134
+ };
135
+
136
+ export interface FeedbackContextBoxProps {
137
+ /** Who is filing — the same value handed to {@link feedbackContext}. */
138
+ user?: FeedbackSubmitter | null;
139
+ /** The URL that goes with the report — the same `url` handed to {@link feedbackContext}. */
140
+ url: string;
141
+ /** The checkbox, on by default in the dialog (§4.2) — the same `attachUrl`. */
142
+ attachUrl: boolean;
143
+ onAttachUrlChange: (next: boolean) => void;
144
+ /** Prop > `<UiKitProvider labels={{ feedbackContext }}>` > English. */
145
+ labels?: Partial<FeedbackContextLabels>;
146
+ className?: string;
147
+ }
148
+
149
+ /**
150
+ * The submit dialog's context box — the dialog's `contextSlot` (keksdose
151
+ * `use-feedback-dialog.tsx:222`, §4.2): who is filing, and the page URL with a checkbox to
152
+ * leave it out, ON by default.
153
+ *
154
+ * The URL stays visible when the box is off, struck through: the reporter sees what they
155
+ * withheld rather than a line that vanished, and ticking it back on is the same glance.
156
+ * Kurvenschmiede's argument for the checkbox is why it exists at all (its feedback #101):
157
+ * the route is right for a bug and wrong for an idea about a screen one is not on — filed
158
+ * against whatever screen happened to be open, the queue reads as if it were about that
159
+ * screen.
160
+ *
161
+ * Nothing in here is the app's: hand it the values handed to {@link feedbackContext}, and
162
+ * what the box shows is what is sent.
163
+ */
164
+ export function FeedbackContextBox({
165
+ user,
166
+ url,
167
+ attachUrl,
168
+ onAttachUrlChange,
169
+ labels: labelsProp,
170
+ className,
171
+ }: FeedbackContextBoxProps) {
172
+ const labels = useKitLabels("feedbackContext", DEFAULT_FEEDBACK_CONTEXT_LABELS, labelsProp);
173
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
174
+ const submitter = submitterLine(user);
175
+ // "User: Ada …" through `common.fieldValue`, so French gets its space before the colon
176
+ // and Chinese its full-width one; the label and its punctuation are drawn bold, as
177
+ // keksdose's box does. A `fieldValue` that does not end in the value (an app's own
178
+ // order) is shown whole, unbolded, rather than cut in the wrong place.
179
+ const line = common.fieldValue(labels.user, submitter);
180
+ const lead = line.endsWith(submitter) ? line.slice(0, line.length - submitter.length) : null;
181
+ return (
182
+ <div
183
+ className={cn(
184
+ "space-y-1 rounded-md border border-[var(--border)] bg-[var(--bg-surface-2)] px-3 py-2 text-xs text-[var(--text-muted)]",
185
+ className,
186
+ )}
187
+ >
188
+ <div className="[overflow-wrap:anywhere]">
189
+ {lead === null ? (
190
+ line
191
+ ) : (
192
+ <>
193
+ <span className="font-medium text-[var(--text-secondary)]">{lead}</span>
194
+ {submitter}
195
+ </>
196
+ )}
197
+ </div>
198
+ <Checkbox
199
+ checked={attachUrl}
200
+ onCheckedChange={onAttachUrlChange}
201
+ label={<span className="text-xs font-medium text-[var(--text-secondary)]">{labels.attachUrl}</span>}
202
+ description={
203
+ url ? (
204
+ // `break-all`: a URL is one unbreakable word, and at 390px a long query string
205
+ // would otherwise push the dialog sideways.
206
+ <span
207
+ data-withheld={attachUrl ? undefined : ""}
208
+ className={cn("break-all text-xs", !attachUrl && "line-through opacity-60")}
209
+ >
210
+ {url}
211
+ </span>
212
+ ) : undefined
213
+ }
214
+ />
215
+ </div>
216
+ );
217
+ }