@eifi1/ui-kit 0.25.1 → 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 (174) hide show
  1. package/README.md +16 -5
  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 +3 -2
  17. package/dist/components/data-table.js.map +1 -1
  18. package/dist/components/facing-pair.d.ts +13 -9
  19. package/dist/components/file-button.d.ts +13 -9
  20. package/dist/components/file-dropzone.d.ts +13 -9
  21. package/dist/components/form-actions.d.ts +13 -9
  22. package/dist/components/iban-input.d.ts +13 -9
  23. package/dist/components/language-select.d.ts +13 -9
  24. package/dist/components/money-field.d.ts +13 -9
  25. package/dist/components/number-field.d.ts +13 -9
  26. package/dist/components/number-input.d.ts +13 -9
  27. package/dist/components/numpad-sheet.d.ts +13 -9
  28. package/dist/components/phone-input.d.ts +13 -9
  29. package/dist/components/series-chart.d.ts +13 -9
  30. package/dist/components/settings-fields.d.ts +13 -9
  31. package/dist/components/share-card.d.ts +13 -9
  32. package/dist/components/swipeable-row.d.ts +5 -1
  33. package/dist/components/swipeable-row.js.map +1 -1
  34. package/dist/components/text-link.d.ts +13 -9
  35. package/dist/components/time-input.d.ts +13 -9
  36. package/dist/components/translation-review-labels.d.ts +4 -0
  37. package/dist/components/translation-review-labels.js +2 -1
  38. package/dist/components/translation-review-labels.js.map +1 -1
  39. package/dist/components/translation-review.d.ts +27 -3
  40. package/dist/components/translation-review.js +50 -21
  41. package/dist/components/translation-review.js.map +1 -1
  42. package/dist/components/ui.d.ts +10 -6
  43. package/dist/components/use-table-state.d.ts +1 -1
  44. package/dist/{data-table-labels-Cdn1QS2k.d.ts → data-table-labels-DUELeXpa.d.ts} +5 -0
  45. package/dist/data-table.d.ts +1 -1
  46. package/dist/feedback/feedback-attachment.d.ts +13 -9
  47. package/dist/feedback/feedback-attachment.js +3 -3
  48. package/dist/feedback/feedback-attachment.js.map +1 -1
  49. package/dist/feedback/feedback-capture.d.ts +71 -0
  50. package/dist/feedback/feedback-capture.js +194 -0
  51. package/dist/feedback/feedback-capture.js.map +1 -0
  52. package/dist/feedback/feedback-context.d.ts +71 -0
  53. package/dist/feedback/feedback-context.js +96 -0
  54. package/dist/feedback/feedback-context.js.map +1 -0
  55. package/dist/feedback/feedback-crash.d.ts +276 -0
  56. package/dist/feedback/feedback-crash.js +225 -0
  57. package/dist/feedback/feedback-crash.js.map +1 -0
  58. package/dist/feedback/feedback-dialog.d.ts +13 -9
  59. package/dist/feedback/feedback-dialog.js +5 -3
  60. package/dist/feedback/feedback-dialog.js.map +1 -1
  61. package/dist/feedback/feedback-inbox.d.ts +13 -9
  62. package/dist/feedback/feedback-inbox.js +89 -49
  63. package/dist/feedback/feedback-inbox.js.map +1 -1
  64. package/dist/feedback/feedback-labels.d.ts +71 -0
  65. package/dist/feedback/feedback-labels.js +48 -0
  66. package/dist/feedback/feedback-labels.js.map +1 -0
  67. package/dist/feedback/feedback-menu.d.ts +71 -0
  68. package/dist/feedback/feedback-menu.js +61 -0
  69. package/dist/feedback/feedback-menu.js.map +1 -0
  70. package/dist/feedback/feedback-record.d.ts +71 -0
  71. package/dist/feedback/feedback-record.js +104 -0
  72. package/dist/feedback/feedback-record.js.map +1 -0
  73. package/dist/feedback/feedback-row-detail.d.ts +71 -0
  74. package/dist/feedback/feedback-row-detail.js +437 -0
  75. package/dist/feedback/feedback-row-detail.js.map +1 -0
  76. package/dist/feedback/feedback-status-undo.d.ts +71 -0
  77. package/dist/feedback/feedback-status-undo.js +40 -0
  78. package/dist/feedback/feedback-status-undo.js.map +1 -0
  79. package/dist/feedback/feedback-submit.d.ts +182 -0
  80. package/dist/feedback/feedback-submit.js +101 -0
  81. package/dist/feedback/feedback-submit.js.map +1 -0
  82. package/dist/feedback/feedback-swipe.d.ts +152 -0
  83. package/dist/feedback/feedback-swipe.js +73 -0
  84. package/dist/feedback/feedback-swipe.js.map +1 -0
  85. package/dist/feedback/feedback-table.d.ts +71 -0
  86. package/dist/feedback/feedback-table.js +357 -0
  87. package/dist/feedback/feedback-table.js.map +1 -0
  88. package/dist/feedback/feedback-thread.d.ts +13 -9
  89. package/dist/feedback.d.ts +17 -9
  90. package/dist/feedback.js +11 -0
  91. package/dist/feedback.js.map +1 -1
  92. package/dist/hooks/use-file-drop.d.ts +13 -9
  93. package/dist/i18n/defaults.d.ts +13 -9
  94. package/dist/i18n/defaults.js +16 -0
  95. package/dist/i18n/defaults.js.map +1 -1
  96. package/dist/i18n/german.d.ts +13 -9
  97. package/dist/i18n/german.js +92 -5
  98. package/dist/i18n/german.js.map +1 -1
  99. package/dist/i18n/kit-labels.d.ts +7 -3
  100. package/dist/i18n/kit-labels.js.map +1 -1
  101. package/dist/i18n/languages.d.ts +13 -9
  102. package/dist/i18n/locales/de-CH.d.ts +13 -9
  103. package/dist/i18n/locales/en.d.ts +13 -9
  104. package/dist/i18n/locales/en.js +11 -1
  105. package/dist/i18n/locales/en.js.map +1 -1
  106. package/dist/i18n/locales/es.d.ts +13 -9
  107. package/dist/i18n/locales/es.js +90 -5
  108. package/dist/i18n/locales/es.js.map +1 -1
  109. package/dist/i18n/locales/fr.d.ts +13 -9
  110. package/dist/i18n/locales/fr.js +90 -5
  111. package/dist/i18n/locales/fr.js.map +1 -1
  112. package/dist/i18n/locales/hu.d.ts +13 -9
  113. package/dist/i18n/locales/hu.js +91 -5
  114. package/dist/i18n/locales/hu.js.map +1 -1
  115. package/dist/i18n/locales/it.d.ts +13 -9
  116. package/dist/i18n/locales/it.js +90 -5
  117. package/dist/i18n/locales/it.js.map +1 -1
  118. package/dist/i18n/locales/zh.d.ts +13 -9
  119. package/dist/i18n/locales/zh.js +90 -5
  120. package/dist/i18n/locales/zh.js.map +1 -1
  121. package/dist/i18n/review.d.ts +16 -11
  122. package/dist/i18n/review.js +12 -0
  123. package/dist/i18n/review.js.map +1 -1
  124. package/dist/i18n/swiss.js +3 -1
  125. package/dist/i18n/swiss.js.map +1 -1
  126. package/dist/index.d.ts +7 -3
  127. package/dist/index.js +18 -1
  128. package/dist/index.js.map +1 -1
  129. package/dist/{feedback-BXKH-ToU.d.ts → kit-labels-DQg82eHB.d.ts} +1275 -25
  130. package/dist/lib/translation-review.d.ts +76 -1
  131. package/dist/lib/translation-review.js +30 -0
  132. package/dist/lib/translation-review.js.map +1 -1
  133. package/dist/rhf/fields.d.ts +13 -9
  134. package/dist/rhf/form.d.ts +13 -9
  135. package/dist/rhf.d.ts +13 -9
  136. package/dist/shell/app-shell.d.ts +13 -9
  137. package/dist/shell/top-bar-brand.d.ts +13 -9
  138. package/dist/shell.d.ts +11 -11
  139. package/dist/wizard/stepper-nav.d.ts +13 -9
  140. package/dist/wizard.d.ts +13 -9
  141. package/package.json +6 -1
  142. package/src/components/data-table.tsx +14 -2
  143. package/src/components/swipeable-row.tsx +5 -1
  144. package/src/components/translation-review-labels.ts +5 -0
  145. package/src/components/translation-review.tsx +102 -35
  146. package/src/feedback/feedback-attachment.tsx +19 -3
  147. package/src/feedback/feedback-capture.ts +285 -0
  148. package/src/feedback/feedback-context.tsx +217 -0
  149. package/src/feedback/feedback-crash.ts +547 -0
  150. package/src/feedback/feedback-dialog.tsx +29 -6
  151. package/src/feedback/feedback-inbox.tsx +131 -27
  152. package/src/feedback/feedback-labels.ts +127 -0
  153. package/src/feedback/feedback-menu.tsx +132 -0
  154. package/src/feedback/feedback-record.ts +345 -0
  155. package/src/feedback/feedback-row-detail.tsx +825 -0
  156. package/src/feedback/feedback-status-undo.ts +111 -0
  157. package/src/feedback/feedback-submit.tsx +224 -0
  158. package/src/feedback/feedback-swipe.tsx +170 -0
  159. package/src/feedback/feedback-table.tsx +757 -0
  160. package/src/feedback.ts +13 -0
  161. package/src/i18n/defaults.ts +16 -0
  162. package/src/i18n/german.ts +99 -5
  163. package/src/i18n/kit-labels.tsx +20 -0
  164. package/src/i18n/locales/en.ts +16 -1
  165. package/src/i18n/locales/es.ts +97 -5
  166. package/src/i18n/locales/fr.ts +96 -5
  167. package/src/i18n/locales/hu.ts +95 -5
  168. package/src/i18n/locales/it.ts +98 -5
  169. package/src/i18n/locales/zh.ts +91 -5
  170. package/src/i18n/review.ts +15 -2
  171. package/src/i18n/swiss.ts +5 -1
  172. package/src/index.ts +19 -0
  173. package/src/lib/translation-review.ts +109 -0
  174. package/tokens.css +8 -0
@@ -0,0 +1,345 @@
1
+ import { DEFAULT_ATTACHMENT_ACCEPT } from "./feedback-attachment";
2
+ import { FEEDBACK_CATEGORY_ORDER } from "./feedback-inbox";
3
+ import type { FeedbackCategory, FeedbackStatus } from "./feedback-inbox";
4
+
5
+ /**
6
+ * One feedback report as the three apps send it, and the facts the kit reads off it.
7
+ *
8
+ * Until 0.27 the inbox parts took no report at all ("no `Feedback` type in this file",
9
+ * feedback-inbox.tsx): keksdose kept its reporter context in a JSON column, kastlan a
10
+ * thinner copy of it, Kurvenschmiede a `page_path` and the bytes in the row. Marcel's
11
+ * feedback round (2026-10-04, docs/feedback-harmonization.md) settled one API contract
12
+ * for all three — keksdose's, read off its code — so the apps now share one shape and the
13
+ * kit can take a row instead of a dozen loose values. This file is that shape (§3.1,
14
+ * §3.2), the contract's constants (§3.4, §3.5, §4.3) and the readers and writers of the
15
+ * one field whose format is itself contract: the body, which carries the rework rounds
16
+ * (§3.4) — lifted from keksdose `frontend/src/features/feedback/body-attachments.ts`.
17
+ *
18
+ * Plain functions and data, no components: everything here is as usable from a loop
19
+ * script's helper or a test as from a page.
20
+ */
21
+
22
+ /* ── The resource (§3.1, §3.2) ────────────────────────────────────────────── */
23
+
24
+ /** Which copy of an app a report came from — keksdose `app/deploy-environment.ts`.
25
+ * Any other string is read as "not prod" (the admin list shows it upper-cased as a
26
+ * chip, §4.3), so an app with a `staging` loses nothing. */
27
+ export type FeedbackEnvironment = "prod" | "dev" | "local";
28
+
29
+ /**
30
+ * The reporter's context, written by the submit dialog (keksdose
31
+ * `use-feedback-dialog.tsx:105`) — §3.2 of the contract.
32
+ *
33
+ * **Every key is optional on read**, and a reader treats a missing one as "unknown":
34
+ * kastlan's client sends six of them (no email, no version), Kurvenschmiede's old rows are
35
+ * backfilled from two columns with a path-only `url`, crash rows add their own (and
36
+ * `origin` / `environment` from the crash payload, §3.6 — older crash rows have neither),
37
+ * and an erased account's row keeps only an allow-list (§3.2: `environment` stays,
38
+ * `origin` goes). Extra keys are allowed — a server may add its own — hence the index
39
+ * signature.
40
+ */
41
+ export interface FeedbackContext {
42
+ /** The full `location.href` at open time; `""` when "Attach current page URL" was off.
43
+ * Readers also accept a path-only value (Kurvenschmiede's backfilled rows). */
44
+ url?: string;
45
+ /** Its pathname; `""` when the URL was withheld. */
46
+ route?: string;
47
+ /** `location.origin` — which copy of the app, not personal; never withheld. */
48
+ origin?: string;
49
+ /** {@link FeedbackEnvironment}, or whatever the app calls its other copies. */
50
+ environment?: FeedbackEnvironment | (string & {});
51
+ /** The submitter, as a snapshot. The server should overwrite the three `user_*` keys
52
+ * from the session (Kurvenschmiede does), so nobody files in someone else's name. */
53
+ user_id?: number | null;
54
+ user_email?: string | null;
55
+ user_display_name?: string | null;
56
+ /** `"406x816"`. */
57
+ viewport?: string;
58
+ /** `navigator.userAgent`. */
59
+ ua?: string;
60
+ /** The app build (`__APP_VERSION__`). */
61
+ version?: string;
62
+ // Crash rows (server-written, keksdose `feedback_service.py:346`).
63
+ fingerprint?: string;
64
+ /** Which error boundary caught it. */
65
+ boundary?: "app" | "page" | (string & {});
66
+ online?: boolean;
67
+ occurrences?: number;
68
+ first_seen_at?: string;
69
+ last_seen_at?: string;
70
+ auto_reported?: boolean;
71
+ [key: string]: unknown;
72
+ }
73
+
74
+ /**
75
+ * One report — `FeedbackResponse`, keksdose `schemas/feedback.py:117`, §3.1 of the
76
+ * contract. What `GET /feedback`, `GET /feedback/my`, `POST /feedback` and
77
+ * `PATCH /feedback/{id}` answer in all three apps.
78
+ *
79
+ * Extra fields are allowed and ignored (kastlan's `company_id`, `user_name`): an app's
80
+ * own row type with more fields is assignable to this one as it stands.
81
+ *
82
+ * There is **no rework counter field** — {@link reworkCount} reads it off the body, so
83
+ * nothing can forget to set it.
84
+ */
85
+ export interface FeedbackRecord {
86
+ id: number;
87
+ /** `null`: the author's account was erased (keksdose live #275). */
88
+ user_id: number | null;
89
+ /** The admin list only (joined); `null` — or absent — on `/my`, create and update. */
90
+ user_email?: string | null;
91
+ /** 1–255 characters, never blank. */
92
+ title: string;
93
+ /** `""` when none. Rework rounds are appended here (§3.4) — read it with
94
+ * {@link splitDescription} / {@link splitBodyAttachments}, write it with
95
+ * {@link appendRework} / {@link replaceDescription}. */
96
+ body: string;
97
+ category: FeedbackCategory;
98
+ status: FeedbackStatus;
99
+ /** §3.2; `null` on rows that have none. */
100
+ context: FeedbackContext | null;
101
+ /** The ONE captured screenshot's attachment URL, or `null`. */
102
+ screenshot_url: string | null;
103
+ /** Up to 5 other files; `null` = none. Optional because a server older than the
104
+ * column sends no key at all (keksdose dev #578 met exactly that). */
105
+ attachment_urls?: string[] | null;
106
+ /** The team's answer; `null` = none written. */
107
+ outcome: string | null;
108
+ /** Set on ENTERING `DONE` / `WONT_DO`, cleared on leaving them. ISO 8601. */
109
+ resolved_at: string | null;
110
+ /** ISO 8601. */
111
+ created_at: string;
112
+ /** ISO 8601. */
113
+ updated_at: string;
114
+ }
115
+
116
+ /* ── Constants (§3.4, §3.5, §4.3) ─────────────────────────────────────────── */
117
+
118
+ /**
119
+ * What a report may carry (§3.5, keksdose `upload_guards.py:197` and its
120
+ * `attachment-options.ts`): the kit's four image types plus a PDF and a plain-text log
121
+ * (keksdose feedback #87). SVG and HTML stay out — both are script-carrying documents in
122
+ * an image's clothing. For `FeedbackAttachmentField` / `FeedbackDialog`'s `accept`, with
123
+ * `DEFAULT_MAX_ATTACHMENTS` (5) and `DEFAULT_MAX_ATTACHMENT_BYTES` (10 MB) from
124
+ * feedback-attachment.tsx, which already are the contract's limits.
125
+ *
126
+ * A plain array (not frozen) because `accept` takes `string[]`, as
127
+ * `DEFAULT_ATTACHMENT_ACCEPT` does — copy it before changing it.
128
+ */
129
+ export const FEEDBACK_ATTACHMENT_ACCEPT: string[] = [
130
+ ...DEFAULT_ATTACHMENT_ACCEPT,
131
+ "application/pdf",
132
+ "text/plain",
133
+ ];
134
+
135
+ /**
136
+ * The categories a person can pick — every one but `CRASH`, in triage order (Bug, Idea,
137
+ * Question, Other: the feedback menu's rows, §4.1). `CRASH` is filed by an error boundary
138
+ * and the server refuses it by hand with a 422 (keksdose `_reject_manual_crash`), so no
139
+ * picker may offer it.
140
+ */
141
+ export const FEEDBACK_PICKABLE_CATEGORIES: readonly FeedbackCategory[] = Object.freeze(
142
+ FEEDBACK_CATEGORY_ORDER.filter((category) => category !== "CRASH"),
143
+ );
144
+
145
+ /**
146
+ * The statuses a report can be sent back for **rework** from (§3.4): everything the team
147
+ * has answered — `IN_EVALUATION`, `NEEDS_LIVE_TEST`, `POSTPONED`, `DONE`, `WONT_DO`. On
148
+ * these the server reopens the row when the body grows by a rework block; on `OPEN` /
149
+ * `IN_PROGRESS` there is nothing to send back yet.
150
+ */
151
+ export const FEEDBACK_REWORKABLE_STATUSES: readonly FeedbackStatus[] = Object.freeze([
152
+ "IN_EVALUATION",
153
+ "NEEDS_LIVE_TEST",
154
+ "POSTPONED",
155
+ "DONE",
156
+ "WONT_DO",
157
+ ] as const);
158
+
159
+ /**
160
+ * The statuses in which the AUTHOR may still edit title, body and category (§3.4,
161
+ * keksdose `canAuthorEdit`, `feedback-page.tsx:398`): `OPEN` and `IN_PROGRESS`. Once the
162
+ * team has answered, the description is what they answered and stays as it was; a
163
+ * correction goes in as a rework.
164
+ */
165
+ export const FEEDBACK_AUTHOR_EDITABLE_STATUSES: readonly FeedbackStatus[] = Object.freeze([
166
+ "OPEN",
167
+ "IN_PROGRESS",
168
+ ] as const);
169
+
170
+ /**
171
+ * The two statuses that wait on the person triaging: answered and handed back for a
172
+ * verdict, or answered and only checkable on a deployed build (keksdose
173
+ * `AWAITING_VERDICT`, live #330). The phone's "Only what is waiting for you" toggle
174
+ * narrows the inbox to exactly these (§4.3).
175
+ */
176
+ export const FEEDBACK_AWAITING_STATUSES: readonly FeedbackStatus[] = Object.freeze([
177
+ "IN_EVALUATION",
178
+ "NEEDS_LIVE_TEST",
179
+ ] as const);
180
+
181
+ /* ── The body (§3.4) ──────────────────────────────────────────────────────── */
182
+
183
+ /**
184
+ * The path every app serves attachments under (§3.3), and a key after it. Keys are
185
+ * OPAQUE (§3.5): keksdose and Kurvenschmiede content-address (`<sha12>.<ext>`), kastlan's
186
+ * storage keys are `<uuid32>_<sha12>.<ext>` — so `[\w.-]+`, never a fixed hex shape.
187
+ */
188
+ const ATTACHMENT_URL = /^\/api\/v1\/feedback\/attachments\/[\w.-]+$/;
189
+
190
+ /**
191
+ * One file line in a body. The marker is deliberately narrow — this path and nothing
192
+ * else, alone on its line — so no sentence a user writes can be mistaken for one
193
+ * (keksdose live #291). It says `[screenshot]` for a PDF or a text log too: the name is
194
+ * history, the format is contract.
195
+ */
196
+ const ATTACHMENT_LINE = /^\[screenshot\]\s+(\/api\/v1\/feedback\/attachments\/[\w.-]+)\s*$/;
197
+
198
+ /**
199
+ * The `--- REWORK <stamp> ---` rule a rework opens with. Anchored and whole-line for the
200
+ * same reason as the file marker: "I did a REWORK --- honestly" is a sentence, not a
201
+ * round. kastlan's folded `--- COMMENT <stamp> · <name> ---` blocks (§7.7) never match.
202
+ */
203
+ const REWORK_RULE = /^---\s*REWORK\b.*---$/;
204
+
205
+ /** Any appended block's opening rule: a rework round, or a kastlan comment folded into
206
+ * the body by its one-time migration (§7.7). */
207
+ const BLOCK_RULE = /^---\s*(?:REWORK|COMMENT)\b.*---$/;
208
+
209
+ /** The body line for one uploaded attachment — what {@link appendRework} writes under
210
+ * the note. */
211
+ export function feedbackAttachmentLine(url: string): string {
212
+ return `[screenshot] ${url}`;
213
+ }
214
+
215
+ /**
216
+ * A rework round appended to a body — the exact text `PATCH /feedback/{id}` takes as the
217
+ * new `body` (§3.4; keksdose `submitRework`, `feedback-page.tsx:350`):
218
+ *
219
+ * ```text
220
+ * <old body>\n\n--- REWORK 2026-10-04 09:12 ---\n<note>\n[screenshot] /api/v1/feedback/attachments/<key>
221
+ * ```
222
+ *
223
+ * - The stamp is UTC, `YYYY-MM-DD HH:MM` (`toISOString().slice(0, 16)`), from `now`.
224
+ * - The old body is kept byte for byte, so the result STRICTLY EXTENDS it — which is
225
+ * how the server recognises an append and reopens an answered row (keksdose
226
+ * `_is_rework_append`, live #331). `\n\n` is left out when the old body is `""`.
227
+ * - ONE file per round (`url`), uploaded first by the caller: a body appended without
228
+ * it would be a rework whose evidence never arrived.
229
+ *
230
+ * **Returns `null` when the trimmed note is empty** — a file alone cannot be sent
231
+ * (keksdose `:577`). Null rather than a throw because an empty note is something a
232
+ * person does, not a bug, and the type then makes every caller decide what an empty
233
+ * box means before anything can reach the PATCH.
234
+ *
235
+ * **Throws a `TypeError` when `url` is not an attachment URL** of the contract's shape
236
+ * (`/api/v1/feedback/attachments/<key>`): that one IS a bug — the upload handed back
237
+ * something foreign — and written anyway it would sit in the body as prose that no
238
+ * reader recognises as a file.
239
+ */
240
+ export function appendRework(
241
+ body: string,
242
+ note: string,
243
+ url?: string | null,
244
+ now: Date = new Date(),
245
+ ): string | null {
246
+ const text = note.trim();
247
+ if (!text) return null;
248
+ if (url && !ATTACHMENT_URL.test(url)) {
249
+ throw new TypeError(`appendRework: not a feedback attachment URL: ${url}`);
250
+ }
251
+ const stamp = now.toISOString().slice(0, 16).replace("T", " ");
252
+ const block = `--- REWORK ${stamp} ---\n${url ? `${text}\n${feedbackAttachmentLine(url)}` : text}`;
253
+ return body ? `${body}\n\n${block}` : block;
254
+ }
255
+
256
+ /**
257
+ * How many times a report has been sent back — the count of `--- REWORK … ---` rule
258
+ * lines in its body (keksdose live #331: the "category for items in rework", derived
259
+ * rather than stored, so nothing can forget to set it or leave it set). Folded kastlan
260
+ * comments do not count.
261
+ */
262
+ export function reworkCount(body: string): number {
263
+ let n = 0;
264
+ for (const line of body.split("\n")) if (REWORK_RULE.test(line.trim())) n += 1;
265
+ return n;
266
+ }
267
+
268
+ /**
269
+ * A body split into the prose to render and the files to show beside it, in body order.
270
+ *
271
+ * The file lines are stripped from the text: they are a location, not something anybody
272
+ * wrote, and left in they would put a raw URL in the middle of a sentence. Trailing blank
273
+ * lines go (what a stripped marker leaves at the end of a note); every blank line between
274
+ * paragraphs stays.
275
+ */
276
+ export function splitBodyAttachments(body: string): { text: string; urls: string[] } {
277
+ const urls: string[] = [];
278
+ const kept: string[] = [];
279
+ for (const line of body.split("\n")) {
280
+ const match = ATTACHMENT_LINE.exec(line.trim());
281
+ if (match) urls.push(match[1]);
282
+ else kept.push(line);
283
+ }
284
+ return { text: kept.join("\n").replace(/\n+$/, ""), urls };
285
+ }
286
+
287
+ /** A body cut where its first appended block begins. */
288
+ function cutAtFirstBlock(body: string): { head: string; appended: string } {
289
+ const lines = body.split("\n");
290
+ const at = lines.findIndex((line) => BLOCK_RULE.test(line.trim()));
291
+ if (at === -1) return { head: body, appended: "" };
292
+ return { head: lines.slice(0, at).join("\n"), appended: lines.slice(at).join("\n") };
293
+ }
294
+
295
+ /**
296
+ * The ORIGINAL description, apart from everything appended to it since (§4.4.1).
297
+ *
298
+ * - `description` — what the author wrote when filing, without its file lines and
299
+ * trailing blank lines: the text the "Edit description" editor holds.
300
+ * - `appended` — every `--- REWORK … ---` round and folded `--- COMMENT … ---` block,
301
+ * from the first one's rule line to the end, verbatim (`""` when there are none).
302
+ *
303
+ * keksdose's editor edits the raw body (`initial={fb.body}`, `feedback-page.tsx:420`), so
304
+ * an author tidying a typo could delete the rework history and the file lines with it.
305
+ * The kit's editor holds `description` only and saves through
306
+ * {@link replaceDescription}, which puts the rest back unchanged.
307
+ */
308
+ export function splitDescription(body: string): { description: string; appended: string } {
309
+ const { head, appended } = cutAtFirstBlock(body);
310
+ return { description: splitBodyAttachments(head).text, appended };
311
+ }
312
+
313
+ /**
314
+ * The body with its original description replaced and everything else kept — the file
315
+ * lines of the original part (after the new text, in their order) and the appended
316
+ * blocks (verbatim, after a blank line). The new text is trimmed; clearing it saves the
317
+ * rest alone (`""` when there is no rest).
318
+ *
319
+ * `replaceDescription(body, splitDescription(body).description)` gives back a canonical
320
+ * body unchanged — a trimmed description, then each block after one blank line, as the
321
+ * dialog and {@link appendRework} write them.
322
+ */
323
+ export function replaceDescription(body: string, description: string): string {
324
+ const { head, appended } = cutAtFirstBlock(body);
325
+ const files = splitBodyAttachments(head).urls.map(feedbackAttachmentLine);
326
+ const text = description.trim();
327
+ const top = [...(text ? [text] : []), ...files].join("\n");
328
+ if (!appended) return top;
329
+ return top ? `${top}\n\n${appended}` : appended;
330
+ }
331
+
332
+ /**
333
+ * Whether an attachment URL is a picture (keksdose dev #578). The upload route takes
334
+ * PDFs and text logs too and serves them as downloads, never inline, so an `<img>` on
335
+ * one shows a broken icon. The key's extension is the server's own statement of the
336
+ * type (minted from the sniffed content), so it is the thing to read.
337
+ */
338
+ export function isImageAttachment(url: string): boolean {
339
+ return /\.(png|jpe?g|webp|gif)$/i.test(url);
340
+ }
341
+
342
+ /** The file name an attachment downloads as — its key, the last segment of the URL. */
343
+ export function attachmentName(url: string): string {
344
+ return url.slice(url.lastIndexOf("/") + 1);
345
+ }