@eifi1/ui-kit 0.12.0 → 0.13.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.
Files changed (197) hide show
  1. package/README.md +10 -10
  2. package/dist/components/amount-input.d.ts +23 -1
  3. package/dist/components/amount-input.js +78 -13
  4. package/dist/components/amount-input.js.map +1 -1
  5. package/dist/components/bulk-action-bar.d.ts +10 -2
  6. package/dist/components/bulk-action-bar.js.map +1 -1
  7. package/dist/components/button-group.d.ts +1 -1
  8. package/dist/components/calculator.d.ts +1 -1
  9. package/dist/components/chart.js +14 -8
  10. package/dist/components/chart.js.map +1 -1
  11. package/dist/components/chip.js +20 -15
  12. package/dist/components/chip.js.map +1 -1
  13. package/dist/components/combobox-core.d.ts +3 -1
  14. package/dist/components/combobox-core.js +16 -5
  15. package/dist/components/combobox-core.js.map +1 -1
  16. package/dist/components/combobox.js.map +1 -1
  17. package/dist/components/copy-button.d.ts +1 -1
  18. package/dist/components/data-table-filter-popover.js +8 -1
  19. package/dist/components/data-table-filter-popover.js.map +1 -1
  20. package/dist/components/data-table.js +28 -20
  21. package/dist/components/data-table.js.map +1 -1
  22. package/dist/components/entity-combobox.js +22 -17
  23. package/dist/components/entity-combobox.js.map +1 -1
  24. package/dist/components/error-boundary.d.ts +202 -13
  25. package/dist/components/error-boundary.js +225 -21
  26. package/dist/components/error-boundary.js.map +1 -1
  27. package/dist/components/field-sync.js +90 -83
  28. package/dist/components/field-sync.js.map +1 -1
  29. package/dist/components/file-button.d.ts +1 -1
  30. package/dist/components/file-dropzone.d.ts +1 -1
  31. package/dist/components/form-actions.d.ts +1 -1
  32. package/dist/components/full-bleed-dialog.js +4 -0
  33. package/dist/components/full-bleed-dialog.js.map +1 -1
  34. package/dist/components/hover-menu.js +64 -56
  35. package/dist/components/hover-menu.js.map +1 -1
  36. package/dist/components/list.d.ts +14 -2
  37. package/dist/components/list.js +3 -1
  38. package/dist/components/list.js.map +1 -1
  39. package/dist/components/modal.js.map +1 -1
  40. package/dist/components/multi-entity-combobox.js +23 -17
  41. package/dist/components/multi-entity-combobox.js.map +1 -1
  42. package/dist/components/number-field.d.ts +1 -1
  43. package/dist/components/number-input.d.ts +1 -1
  44. package/dist/components/number-input.js.map +1 -1
  45. package/dist/components/numpad-sheet.d.ts +10 -2
  46. package/dist/components/numpad-sheet.js +6 -4
  47. package/dist/components/numpad-sheet.js.map +1 -1
  48. package/dist/components/page-header.d.ts +35 -6
  49. package/dist/components/page-header.js +7 -1
  50. package/dist/components/page-header.js.map +1 -1
  51. package/dist/components/picker-sheet.js +3 -0
  52. package/dist/components/picker-sheet.js.map +1 -1
  53. package/dist/components/popover.js +3 -0
  54. package/dist/components/popover.js.map +1 -1
  55. package/dist/components/settings-fields.d.ts +1 -1
  56. package/dist/components/signed-amount.d.ts +2 -1
  57. package/dist/components/signed-amount.js +1 -1
  58. package/dist/components/signed-amount.js.map +1 -1
  59. package/dist/components/stat-tile.js +1 -1
  60. package/dist/components/stat-tile.js.map +1 -1
  61. package/dist/components/swipeable-row.js +4 -3
  62. package/dist/components/swipeable-row.js.map +1 -1
  63. package/dist/components/text-link.d.ts +73 -11
  64. package/dist/components/text-link.js +45 -10
  65. package/dist/components/text-link.js.map +1 -1
  66. package/dist/components/text.d.ts +26 -2
  67. package/dist/components/text.js +16 -2
  68. package/dist/components/text.js.map +1 -1
  69. package/dist/components/time-input.d.ts +1 -1
  70. package/dist/components/toggle-group.d.ts +22 -0
  71. package/dist/components/toggle-group.js +8 -8
  72. package/dist/components/toggle-group.js.map +1 -1
  73. package/dist/components/toggle-legend.d.ts +17 -0
  74. package/dist/components/toggle-legend.js +6 -2
  75. package/dist/components/toggle-legend.js.map +1 -1
  76. package/dist/components/tooltip.d.ts +51 -1
  77. package/dist/components/tooltip.js +59 -35
  78. package/dist/components/tooltip.js.map +1 -1
  79. package/dist/components/ui.d.ts +1 -1
  80. package/dist/components/ui.js +166 -28
  81. package/dist/components/ui.js.map +1 -1
  82. package/dist/feedback/feedback-attachment.js +4 -6
  83. package/dist/feedback/feedback-attachment.js.map +1 -1
  84. package/dist/feedback/feedback-dialog.js +5 -3
  85. package/dist/feedback/feedback-dialog.js.map +1 -1
  86. package/dist/feedback/feedback-inbox.js +86 -75
  87. package/dist/feedback/feedback-inbox.js.map +1 -1
  88. package/dist/feedback/feedback-thread.d.ts +43 -3
  89. package/dist/feedback/feedback-thread.js +53 -26
  90. package/dist/feedback/feedback-thread.js.map +1 -1
  91. package/dist/feedback.d.ts +1 -1
  92. package/dist/hooks/use-file-drop.d.ts +1 -1
  93. package/dist/i18n/defaults.d.ts +1 -1
  94. package/dist/i18n/kit-labels.d.ts +1 -1
  95. package/dist/i18n/kit-labels.js.map +1 -1
  96. package/dist/i18n/locales/de-CH-informal.d.ts +1 -1
  97. package/dist/i18n/locales/de-CH.d.ts +1 -1
  98. package/dist/i18n/locales/de-informal.d.ts +1 -1
  99. package/dist/i18n/locales/de.d.ts +1 -1
  100. package/dist/i18n/locales/de.js +9 -1
  101. package/dist/i18n/locales/de.js.map +1 -1
  102. package/dist/i18n/locales/es.d.ts +1 -1
  103. package/dist/i18n/locales/es.js +9 -1
  104. package/dist/i18n/locales/es.js.map +1 -1
  105. package/dist/i18n/locales/fr.d.ts +1 -1
  106. package/dist/i18n/locales/fr.js +9 -1
  107. package/dist/i18n/locales/fr.js.map +1 -1
  108. package/dist/i18n/locales/hu.d.ts +1 -1
  109. package/dist/i18n/locales/hu.js +9 -1
  110. package/dist/i18n/locales/hu.js.map +1 -1
  111. package/dist/i18n/locales/it.d.ts +1 -1
  112. package/dist/i18n/locales/it.js +9 -1
  113. package/dist/i18n/locales/it.js.map +1 -1
  114. package/dist/i18n/locales/zh.d.ts +1 -1
  115. package/dist/i18n/locales/zh.js +9 -1
  116. package/dist/i18n/locales/zh.js.map +1 -1
  117. package/dist/index.d.ts +6 -6
  118. package/dist/{kit-labels-v3biUF1L.d.ts → kit-labels-Mz8zZHIF.d.ts} +102 -3
  119. package/dist/lib/format.d.ts +23 -5
  120. package/dist/lib/format.js +4 -2
  121. package/dist/lib/format.js.map +1 -1
  122. package/dist/rhf/fields.d.ts +59 -15
  123. package/dist/rhf/fields.js +41 -11
  124. package/dist/rhf/fields.js.map +1 -1
  125. package/dist/rhf/form.d.ts +1 -1
  126. package/dist/rhf.d.ts +2 -2
  127. package/dist/rhf.js.map +1 -1
  128. package/dist/search/command-palette.js +20 -14
  129. package/dist/search/command-palette.js.map +1 -1
  130. package/dist/shell/app-shell.d.ts +1 -1
  131. package/dist/shell/app-shell.js +62 -54
  132. package/dist/shell/app-shell.js.map +1 -1
  133. package/dist/shell/top-bar-brand.d.ts +1 -1
  134. package/dist/shell/topbar-action-menu.d.ts +9 -3
  135. package/dist/shell/topbar-action-menu.js +2 -1
  136. package/dist/shell/topbar-action-menu.js.map +1 -1
  137. package/dist/shell.d.ts +1 -1
  138. package/dist/tour/tour.js +10 -4
  139. package/dist/tour/tour.js.map +1 -1
  140. package/dist/wizard/stepper-nav.d.ts +1 -1
  141. package/dist/wizard/use-wizard.js +4 -2
  142. package/dist/wizard/use-wizard.js.map +1 -1
  143. package/dist/wizard/wizard-step.d.ts +11 -1
  144. package/dist/wizard/wizard-step.js +24 -6
  145. package/dist/wizard/wizard-step.js.map +1 -1
  146. package/dist/wizard.d.ts +1 -1
  147. package/package.json +6 -6
  148. package/src/components/amount-input.tsx +165 -12
  149. package/src/components/bulk-action-bar.tsx +16 -3
  150. package/src/components/chart.tsx +19 -8
  151. package/src/components/chip.tsx +6 -0
  152. package/src/components/combobox-core.tsx +28 -9
  153. package/src/components/combobox.tsx +2 -0
  154. package/src/components/data-table-filter-popover.tsx +13 -5
  155. package/src/components/data-table.tsx +6 -0
  156. package/src/components/entity-combobox.tsx +7 -4
  157. package/src/components/error-boundary.tsx +470 -30
  158. package/src/components/field-sync.tsx +48 -40
  159. package/src/components/full-bleed-dialog.tsx +4 -0
  160. package/src/components/hover-menu.tsx +26 -17
  161. package/src/components/list.tsx +17 -3
  162. package/src/components/modal.tsx +4 -0
  163. package/src/components/multi-entity-combobox.tsx +8 -4
  164. package/src/components/number-input.tsx +1 -0
  165. package/src/components/numpad-sheet.tsx +17 -3
  166. package/src/components/page-header.tsx +42 -5
  167. package/src/components/picker-sheet.tsx +3 -0
  168. package/src/components/popover.tsx +3 -0
  169. package/src/components/signed-amount.tsx +12 -3
  170. package/src/components/stat-tile.tsx +3 -1
  171. package/src/components/swipeable-row.tsx +7 -7
  172. package/src/components/text-link.tsx +126 -18
  173. package/src/components/text.tsx +47 -2
  174. package/src/components/toggle-group.tsx +35 -10
  175. package/src/components/toggle-legend.tsx +22 -1
  176. package/src/components/tooltip.tsx +79 -8
  177. package/src/components/ui.tsx +307 -39
  178. package/src/feedback/feedback-attachment.tsx +10 -7
  179. package/src/feedback/feedback-dialog.tsx +7 -4
  180. package/src/feedback/feedback-inbox.tsx +7 -0
  181. package/src/feedback/feedback-thread.tsx +109 -33
  182. package/src/i18n/kit-labels.tsx +16 -0
  183. package/src/i18n/locales/de.ts +8 -0
  184. package/src/i18n/locales/es.ts +8 -0
  185. package/src/i18n/locales/fr.ts +8 -0
  186. package/src/i18n/locales/hu.ts +8 -0
  187. package/src/i18n/locales/it.ts +8 -0
  188. package/src/i18n/locales/zh.ts +8 -0
  189. package/src/lib/format.ts +32 -7
  190. package/src/rhf/fields.tsx +99 -16
  191. package/src/rhf.ts +1 -1
  192. package/src/search/command-palette.tsx +29 -19
  193. package/src/shell/app-shell.tsx +6 -1
  194. package/src/shell/topbar-action-menu.tsx +11 -4
  195. package/src/tour/tour.tsx +16 -5
  196. package/src/wizard/use-wizard.ts +8 -4
  197. package/src/wizard/wizard-step.tsx +38 -6
@@ -1,15 +1,24 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { Component } from "react";
4
- import { AlertTriangle } from "lucide-react";
4
+ import { AlertTriangle, RefreshCw, WifiOff } from "lucide-react";
5
5
  import { useKitLabels } from "../i18n/kit-labels.js";
6
6
  import { Button, EmptyState } from "./ui.js";
7
+ import { CopyButton } from "./copy-button.js";
7
8
  import { Disclosure } from "./disclosure.js";
8
9
  const DEFAULT_ERROR_BOUNDARY_LABELS = {
9
10
  title: "Something went wrong",
10
11
  message: "This part of the page could not be shown. Try again, or reload the page.",
11
12
  retry: "Try again",
12
- details: "Error details"
13
+ details: "Error details",
14
+ reload: "Reload",
15
+ updateTitle: "A new version is available",
16
+ updateMessage: "Part of the app has changed since this page was loaded. Reload to get the new version.",
17
+ offlineTitle: "You\u2019re offline",
18
+ offlineMessage: "This page could not be loaded without a connection. Reconnect, then reload the page.",
19
+ copyReport: "Copy error report",
20
+ reported: "This error has been reported automatically.",
21
+ reportedAs: (reference) => `Reported as ${reference}`
13
22
  };
14
23
  function read(get) {
15
24
  try {
@@ -19,30 +28,192 @@ function read(get) {
19
28
  return void 0;
20
29
  }
21
30
  }
31
+ function safeJson(value) {
32
+ try {
33
+ const json = JSON.stringify(value);
34
+ if (!json || json === "{}") return "";
35
+ return json.length > 500 ? `${json.slice(0, 499)}\u2026` : json;
36
+ } catch {
37
+ return "";
38
+ }
39
+ }
22
40
  function describeThrown(error) {
23
41
  if (typeof error === "object" && error !== null) {
24
42
  const e = error;
43
+ const message = read(() => e.message) ?? "";
25
44
  return {
26
45
  name: read(() => e.name) ?? "Error",
27
- message: read(() => e.message) ?? "",
46
+ // `throw { code: 500 }` has no message, and an empty line leaves crash triage with
47
+ // nothing (keksdose G3a; its old reporter filed `{"code":500}`). Such a value is
48
+ // quoted as JSON instead, capped, and never at the cost of a throw.
49
+ message: message || (error instanceof Error ? "" : safeJson(error)),
28
50
  stack: read(() => e.stack)
29
51
  };
30
52
  }
31
53
  return { name: "Error", message: read(() => error) ?? "" };
32
54
  }
33
- const CLEAR = { failed: false, error: null, details: null };
55
+ function isChunkLoadError(error) {
56
+ try {
57
+ const s = `${error?.name ?? ""} ${error?.message ?? ""}`;
58
+ return /ChunkLoadError|dynamically imported module|module script failed|Loading chunk|Failed to fetch/i.test(s);
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+ function formatCrashReport(report) {
64
+ const lines = [
65
+ report.message ? `${report.name}: ${report.message}` : report.name,
66
+ `Page: ${report.page}`,
67
+ `Time: ${report.time}`,
68
+ `User agent: ${report.userAgent}`
69
+ ];
70
+ if (report.appVersion) lines.push(`App version: ${report.appVersion}`);
71
+ if (report.online === false) lines.push("Online: no");
72
+ for (const [key, value] of Object.entries(report.extras)) lines.push(`${key}: ${value}`);
73
+ if (report.stack) lines.push("", "Stack:", report.stack.trim());
74
+ if (report.componentStack) lines.push("", "Component stack:", report.componentStack.trim());
75
+ return lines.join("\n");
76
+ }
77
+ function crashFingerprint(report) {
78
+ const frames = (report.stack ?? "").split("\n").slice(0, 4).join("|");
79
+ return `${report.name}::${report.message}::${frames}`;
80
+ }
81
+ const NOT_FILED = { filed: false };
82
+ const MAX_REPORTS_PER_PAGE_LOAD = 5;
83
+ const filings = /* @__PURE__ */ new Map();
84
+ function settle(out) {
85
+ try {
86
+ if (out && typeof out === "object") {
87
+ const o = out;
88
+ if (o.filed === false) return NOT_FILED;
89
+ const reference = typeof o.reference === "string" && o.reference ? o.reference : void 0;
90
+ return { filed: true, reference };
91
+ }
92
+ return { filed: true };
93
+ } catch {
94
+ return NOT_FILED;
95
+ }
96
+ }
97
+ function fileOnce(report, onReport) {
98
+ const key = crashFingerprint(report);
99
+ const known = filings.get(key);
100
+ if (known) return known;
101
+ if (filings.size >= MAX_REPORTS_PER_PAGE_LOAD) return Promise.resolve(NOT_FILED);
102
+ let filing;
103
+ try {
104
+ filing = Promise.resolve(onReport(report)).then(settle, () => NOT_FILED);
105
+ } catch {
106
+ filing = Promise.resolve(NOT_FILED);
107
+ }
108
+ filings.set(key, filing);
109
+ return filing;
110
+ }
111
+ function isOffline() {
112
+ try {
113
+ return typeof navigator !== "undefined" && navigator.onLine === false;
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+ function reloadPage() {
119
+ try {
120
+ window.location.reload();
121
+ } catch {
122
+ }
123
+ }
124
+ const CLEAR = {
125
+ failed: false,
126
+ error: null,
127
+ details: null,
128
+ report: null,
129
+ filing: "none",
130
+ reference: void 0
131
+ };
34
132
  function keysChanged(a, b) {
35
133
  if (a === b) return false;
36
134
  if (!a || !b || a.length !== b.length) return true;
37
135
  return a.some((v, i) => !Object.is(v, b[i]));
38
136
  }
137
+ function currentPage() {
138
+ try {
139
+ const { pathname, search } = window.location;
140
+ return { page: `${pathname}${search}`, path: pathname };
141
+ } catch {
142
+ return { page: "", path: "" };
143
+ }
144
+ }
145
+ function buildReport(details, componentStack, props) {
146
+ const { page, path } = currentPage();
147
+ const extras = {};
148
+ try {
149
+ const more = props.reportExtras?.();
150
+ if (more) for (const [k, v] of Object.entries(more)) extras[k] = String(v);
151
+ } catch {
152
+ }
153
+ let userAgent = "";
154
+ let online;
155
+ try {
156
+ userAgent = navigator.userAgent;
157
+ online = typeof navigator.onLine === "boolean" ? navigator.onLine : void 0;
158
+ } catch {
159
+ }
160
+ const report = {
161
+ name: details.name,
162
+ message: details.message,
163
+ stack: details.stack,
164
+ componentStack: componentStack ?? void 0,
165
+ page,
166
+ time: (/* @__PURE__ */ new Date()).toISOString(),
167
+ userAgent,
168
+ appVersion: props.appVersion,
169
+ online,
170
+ chunkLoad: isChunkLoadError(details),
171
+ extras
172
+ };
173
+ if (!props.redact) return report;
174
+ try {
175
+ return props.redact(report);
176
+ } catch {
177
+ return { ...report, page: path, extras: {} };
178
+ }
179
+ }
39
180
  class ErrorBoundary extends Component {
40
181
  state = CLEAR;
182
+ /** Bumped by every catch and reset, so a filing that settles after the screen moved
183
+ * on (Try again, a route change, a second crash) does not write into it. */
184
+ generation = 0;
185
+ /**
186
+ * Forget which crashes this page load has filed, and the count towards the cap.
187
+ *
188
+ * For tests: the dedupe lives in module scope because a page load is what it spans,
189
+ * and a test file is one page load — so without this, the sixth test that files a
190
+ * report finds the cap reached and `onReport` never called. Call it in `beforeEach`.
191
+ * Never needed in an app: a reload is the reset.
192
+ */
193
+ static forgetReports() {
194
+ filings.clear();
195
+ }
41
196
  static getDerivedStateFromError(error) {
42
- return { failed: true, error, details: describeThrown(error) };
197
+ return { failed: true, error, details: describeThrown(error), report: null, filing: "none", reference: void 0 };
43
198
  }
44
199
  componentDidCatch(error, info) {
45
- this.props.onError?.(error, info);
200
+ try {
201
+ this.props.onError?.(error, info);
202
+ } catch {
203
+ }
204
+ const details = this.state.details ?? describeThrown(error);
205
+ const report = buildReport(details, info.componentStack ?? void 0, this.props);
206
+ const { onReport } = this.props;
207
+ const willFile = onReport !== void 0 && !report.chunkLoad;
208
+ const generation = ++this.generation;
209
+ this.setState({ report, filing: willFile ? "pending" : "none", reference: void 0 });
210
+ if (!willFile) return;
211
+ void fileOnce(report, onReport).then((filing) => {
212
+ if (generation !== this.generation) return;
213
+ this.setState(
214
+ filing.filed ? { filing: "filed", reference: filing.reference } : { filing: "failed", reference: void 0 }
215
+ );
216
+ });
46
217
  }
47
218
  componentDidUpdate(prev, prevState) {
48
219
  if (this.state.failed && prevState.failed && keysChanged(prev.resetKeys, this.props.resetKeys)) {
@@ -50,21 +221,28 @@ class ErrorBoundary extends Component {
50
221
  }
51
222
  }
52
223
  reset = () => {
224
+ this.generation++;
53
225
  this.props.onReset?.();
54
226
  this.setState(CLEAR);
55
227
  };
56
228
  render() {
57
- const { failed, error, details } = this.state;
229
+ const { failed, error, details, report, filing, reference } = this.state;
58
230
  if (!failed || !details) return this.props.children;
59
231
  const { fallback } = this.props;
60
- if (typeof fallback === "function") return fallback({ error, details, reset: this.reset });
232
+ if (typeof fallback === "function") return fallback({ error, details, reset: this.reset, report });
61
233
  if (fallback !== void 0) return fallback;
62
234
  return /* @__PURE__ */ jsx(
63
235
  ErrorFallback,
64
236
  {
65
237
  details,
238
+ report,
239
+ filing,
240
+ reference,
66
241
  reset: this.reset,
67
- showDetails: this.props.showDetails ?? false,
242
+ showMessage: this.props.showMessage ?? true,
243
+ showDetails: this.props.showDetails ?? true,
244
+ copyReport: this.props.copyReport ?? true,
245
+ actions: this.props.actions,
68
246
  headingAs: this.props.headingAs ?? "h2",
69
247
  className: this.props.className,
70
248
  labels: this.props.labels
@@ -74,31 +252,54 @@ class ErrorBoundary extends Component {
74
252
  }
75
253
  function ErrorFallback({
76
254
  details,
255
+ report,
256
+ filing,
257
+ reference,
77
258
  reset,
259
+ showMessage,
78
260
  showDetails,
261
+ copyReport,
262
+ actions,
79
263
  headingAs,
80
264
  className,
81
265
  labels
82
266
  }) {
83
267
  const text = useKitLabels("errorBoundary", DEFAULT_ERROR_BOUNDARY_LABELS, labels);
268
+ const chunk = isChunkLoadError(details);
269
+ const mode = isOffline() ? "offline" : chunk ? "update" : "error";
270
+ const title = mode === "offline" ? text.offlineTitle : mode === "update" ? text.updateTitle : text.title;
271
+ const hint = mode === "offline" ? text.offlineMessage : mode === "update" ? text.updateMessage : text.message;
272
+ const Icon = mode === "offline" ? WifiOff : mode === "update" ? RefreshCw : AlertTriangle;
273
+ const reportText = report ? formatCrashReport(report) : null;
274
+ const errorLine = details.message ? `${details.name}: ${details.message}` : details.name;
275
+ const reloadButton = /* @__PURE__ */ jsx(Button, { variant: mode === "error" ? "secondary" : "primary", onClick: reloadPage, children: text.reload }, "reload");
276
+ const retryButton = chunk ? null : /* @__PURE__ */ jsx(Button, { variant: mode === "error" ? "primary" : "secondary", onClick: reset, children: text.retry }, "retry");
84
277
  return /* @__PURE__ */ jsx(
85
278
  EmptyState,
86
279
  {
87
280
  role: "alert",
88
- tone: "danger",
281
+ tone: mode === "error" ? "danger" : void 0,
89
282
  headingAs,
90
283
  className,
91
- icon: /* @__PURE__ */ jsx(AlertTriangle, {}),
92
- title: text.title,
93
- hint: text.message,
284
+ icon: /* @__PURE__ */ jsx(Icon, {}),
285
+ title,
286
+ hint,
94
287
  action: /* @__PURE__ */ jsxs(Fragment, { children: [
95
- /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: reset, children: text.retry }),
96
- showDetails && /* @__PURE__ */ jsx(Disclosure, { variant: "bare", title: text.details, className: "basis-full text-start", children: /* @__PURE__ */ jsxs("pre", { className: "max-h-60 overflow-auto whitespace-pre-wrap break-words text-xs text-[var(--text-secondary)]", children: [
97
- details.message ? `${details.name}: ${details.message}` : details.name,
98
- details.stack ? `
99
-
100
- ${details.stack}` : null
101
- ] }) })
288
+ showMessage && mode === "error" && // A quotation, not prose: left-aligned and monospaced, so it reads as the
289
+ // program's words and can be read out or screenshotted verbatim.
290
+ /* @__PURE__ */ jsx(
291
+ "p",
292
+ {
293
+ "data-error-message": "",
294
+ className: "-mt-1 mb-1 basis-full whitespace-pre-wrap break-words rounded-md border border-[var(--danger-border)] bg-[var(--danger-bg)] px-3 py-2 text-start font-mono text-xs text-[var(--text-primary)]",
295
+ children: errorLine
296
+ }
297
+ ),
298
+ filing === "filed" && /* @__PURE__ */ jsx("p", { className: "-mt-1 mb-1 basis-full text-xs", children: reference ? text.reportedAs(reference) : text.reported }),
299
+ mode === "error" ? [retryButton, reloadButton] : [reloadButton, retryButton],
300
+ copyReport && reportText !== null && filing !== "filed" && /* @__PURE__ */ jsx(CopyButton, { variant: "label", buttonVariant: "ghost", label: text.copyReport, text: reportText }),
301
+ actions,
302
+ showDetails && reportText !== null && /* @__PURE__ */ jsx(Disclosure, { variant: "bare", title: text.details, className: "basis-full text-start", children: /* @__PURE__ */ jsx("pre", { className: "max-h-60 overflow-auto whitespace-pre-wrap break-words text-xs text-[var(--text-secondary)]", children: reportText }) })
102
303
  ] })
103
304
  }
104
305
  );
@@ -106,6 +307,9 @@ ${details.stack}` : null
106
307
  export {
107
308
  DEFAULT_ERROR_BOUNDARY_LABELS,
108
309
  ErrorBoundary,
109
- describeThrown
310
+ crashFingerprint,
311
+ describeThrown,
312
+ formatCrashReport,
313
+ isChunkLoadError
110
314
  };
111
315
  //# sourceMappingURL=error-boundary.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/error-boundary.tsx"],"sourcesContent":["import { Component } from \"react\";\nimport type { ErrorInfo, ReactNode } from \"react\";\nimport { AlertTriangle } from \"lucide-react\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button, EmptyState } from \"./ui\";\nimport { Disclosure } from \"./disclosure\";\n\n/** The words of the default fallback. */\nexport interface ErrorBoundaryLabels {\n /** The fallback's heading. */\n title: string;\n /** The line under it. */\n message: string;\n /** The button that clears the error and renders the children again. */\n retry: string;\n /** The disclosure that opens the error's own text (`showDetails`). */\n details: string;\n}\n\nexport const DEFAULT_ERROR_BOUNDARY_LABELS: ErrorBoundaryLabels = {\n title: \"Something went wrong\",\n message: \"This part of the page could not be shown. Try again, or reload the page.\",\n retry: \"Try again\",\n details: \"Error details\",\n};\n\n/**\n * What was thrown, as flat strings, read ONCE when it arrives.\n *\n * React stores whatever was thrown, hostile or not — `throw { get message() { throw … } }`,\n * `throw { name: Symbol() }`, `throw undefined` — and reading one of those during the\n * fallback's own render would throw INSIDE the boundary, escalating to the next one up\n * (keksdose's error-boundary.tsx learned this as feedback #160: at the app level there is\n * none, and the result is the white screen the boundary exists to prevent).\n */\nexport interface ErrorBoundaryDetails {\n name: string;\n message: string;\n stack?: string;\n}\n\nfunction read(get: () => unknown): string | undefined {\n try {\n const v = get();\n return typeof v === \"string\" ? v : v === undefined || v === null ? undefined : String(v);\n } catch {\n return undefined;\n }\n}\n\n/** {@link ErrorBoundaryDetails} of any thrown value, without ever throwing. */\nexport function describeThrown(error: unknown): ErrorBoundaryDetails {\n if (typeof error === \"object\" && error !== null) {\n const e = error as { name?: unknown; message?: unknown; stack?: unknown };\n return {\n name: read(() => e.name) ?? \"Error\",\n message: read(() => e.message) ?? \"\",\n stack: read(() => e.stack),\n };\n }\n return { name: \"Error\", message: read(() => error) ?? \"\" };\n}\n\n/** What a render-prop `fallback` is handed. */\nexport interface ErrorBoundaryFallbackProps {\n /** The thrown value, as it was thrown. Read it with care — see {@link describeThrown}. */\n error: unknown;\n details: ErrorBoundaryDetails;\n /** Clear the error and render the children again. */\n reset: () => void;\n}\n\nexport interface ErrorBoundaryProps {\n children?: ReactNode;\n /** Replaces the default fallback: a node, or a render function handed the error and\n * a `reset`. */\n fallback?: ReactNode | ((props: ErrorBoundaryFallbackProps) => ReactNode);\n /** Called once per caught error — log it, file a crash report. */\n onError?: (error: unknown, info: ErrorInfo) => void;\n /** Called when the error is cleared, by Retry, `reset` or a `resetKeys` change —\n * drop a cache, refetch. */\n onReset?: () => void;\n /**\n * When any of these changes (compared with `Object.is`) AFTER an error was caught, the\n * error is cleared and the children render again — a change in the same update that\n * threw does not count (it is what the error was shown under) — pass the route path so leaving a broken page does not\n * carry its fallback to the next one (keksdose's `resetKey`).\n */\n resetKeys?: ReadonlyArray<unknown>;\n /** A disclosure under the message with the error's name, message and stack — for an\n * internal tool, or while developing. Off by default: a stack means nothing to a user. */\n showDetails?: boolean;\n /** The default fallback's heading level. Default `h2`: the fallback often IS the page. */\n headingAs?: \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n /** Classes for the default fallback's box (`m-8 min-h-[400px]`, kastlan). */\n className?: string;\n labels?: Partial<ErrorBoundaryLabels>;\n}\n\ninterface ErrorBoundaryState {\n /** A flag of its own, so `throw undefined` is still an error shown. */\n failed: boolean;\n error: unknown;\n details: ErrorBoundaryDetails | null;\n}\n\nconst CLEAR: ErrorBoundaryState = { failed: false, error: null, details: null };\n\nfunction keysChanged(a: ReadonlyArray<unknown> | undefined, b: ReadonlyArray<unknown> | undefined): boolean {\n if (a === b) return false;\n if (!a || !b || a.length !== b.length) return true;\n return a.some((v, i) => !Object.is(v, b[i]));\n}\n\n/**\n * Catch a render error below it and show a fallback instead of an empty page.\n *\n * kastlan (shared/components/error-boundary.tsx) and keksdose (app/error-boundary.tsx)\n * each built one on `EmptyState tone=\"danger\"`: a warning glyph, a title, a line of\n * explanation and a Retry. This is that fallback, translated through the provider\n * (`errorBoundary.*`), with the hooks an app hangs its own behaviour on — `onError`\n * for the crash report, `resetKeys` for the route change, `fallback` for anything else.\n *\n * The fallback is `role=\"alert\"`: a page replaced by an error is news, and a reader\n * that was on it is told.\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n state: ErrorBoundaryState = CLEAR;\n\n static getDerivedStateFromError(error: unknown): Partial<ErrorBoundaryState> {\n return { failed: true, error, details: describeThrown(error) };\n }\n\n componentDidCatch(error: unknown, info: ErrorInfo): void {\n this.props.onError?.(error, info);\n }\n\n componentDidUpdate(prev: ErrorBoundaryProps, prevState: ErrorBoundaryState): void {\n // Only a change AFTER the error was caught clears it (react-error-boundary's rule).\n // `prevState.failed` is false in the update that caught it: that update may well be\n // the one that changed the keys too — a navigation to a page that throws, with\n // `resetKeys={[pathname]}` — and resetting then would fire `onReset` for nothing and\n // render the failing child a second time. From then on `prev.resetKeys` are the\n // keys the error was shown under, so any change clears it.\n if (this.state.failed && prevState.failed && keysChanged(prev.resetKeys, this.props.resetKeys)) {\n this.reset();\n }\n }\n\n reset = (): void => {\n this.props.onReset?.();\n this.setState(CLEAR);\n };\n\n render(): ReactNode {\n const { failed, error, details } = this.state;\n if (!failed || !details) return this.props.children;\n const { fallback } = this.props;\n if (typeof fallback === \"function\") return fallback({ error, details, reset: this.reset });\n if (fallback !== undefined) return fallback;\n return (\n <ErrorFallback\n details={details}\n reset={this.reset}\n showDetails={this.props.showDetails ?? false}\n headingAs={this.props.headingAs ?? \"h2\"}\n className={this.props.className}\n labels={this.props.labels}\n />\n );\n }\n}\n\nfunction ErrorFallback({\n details,\n reset,\n showDetails,\n headingAs,\n className,\n labels,\n}: {\n details: ErrorBoundaryDetails;\n reset: () => void;\n showDetails: boolean;\n headingAs: NonNullable<ErrorBoundaryProps[\"headingAs\"]>;\n className?: string;\n labels?: Partial<ErrorBoundaryLabels>;\n}) {\n const text = useKitLabels(\"errorBoundary\", DEFAULT_ERROR_BOUNDARY_LABELS, labels);\n return (\n <EmptyState\n role=\"alert\"\n tone=\"danger\"\n headingAs={headingAs}\n className={className}\n icon={<AlertTriangle />}\n title={text.title}\n hint={text.message}\n action={\n <>\n <Button variant=\"secondary\" onClick={reset}>\n {text.retry}\n </Button>\n {showDetails && (\n <Disclosure variant=\"bare\" title={text.details} className=\"basis-full text-start\">\n <pre className=\"max-h-60 overflow-auto whitespace-pre-wrap break-words text-xs text-[var(--text-secondary)]\">\n {details.message ? `${details.name}: ${details.message}` : details.name}\n {details.stack ? `\\n\\n${details.stack}` : null}\n </pre>\n </Disclosure>\n )}\n </>\n }\n />\n );\n}\n"],"mappings":";AAiKM,SAsCE,UAtCF,KA4CQ,YA5CR;AAjKN,SAAS,iBAAiB;AAE1B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,kBAAkB;AACnC,SAAS,kBAAkB;AAcpB,MAAM,gCAAqD;AAAA,EAChE,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACX;AAiBA,SAAS,KAAK,KAAwC;AACpD,MAAI;AACF,UAAM,IAAI,IAAI;AACd,WAAO,OAAO,MAAM,WAAW,IAAI,MAAM,UAAa,MAAM,OAAO,SAAY,OAAO,CAAC;AAAA,EACzF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,eAAe,OAAsC;AACnE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,UAAM,IAAI;AACV,WAAO;AAAA,MACL,MAAM,KAAK,MAAM,EAAE,IAAI,KAAK;AAAA,MAC5B,SAAS,KAAK,MAAM,EAAE,OAAO,KAAK;AAAA,MAClC,OAAO,KAAK,MAAM,EAAE,KAAK;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,EAAE,MAAM,SAAS,SAAS,KAAK,MAAM,KAAK,KAAK,GAAG;AAC3D;AA6CA,MAAM,QAA4B,EAAE,QAAQ,OAAO,OAAO,MAAM,SAAS,KAAK;AAE9E,SAAS,YAAY,GAAuC,GAAgD;AAC1G,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,CAA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ACF,GAOG;AACD,QAAM,OAAO,aAAa,iBAAiB,+BAA+B,MAAM;AAChF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,MAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,MAAM,oBAAC,iBAAc;AAAA,MACrB,OAAO,KAAK;AAAA,MACZ,MAAM,KAAK;AAAA,MACX,QACE,iCACE;AAAA,4BAAC,UAAO,SAAQ,aAAY,SAAS,OAClC,eAAK,OACR;AAAA,QACC,eACC,oBAAC,cAAW,SAAQ,QAAO,OAAO,KAAK,SAAS,WAAU,yBACxD,+BAAC,SAAI,WAAU,+FACZ;AAAA,kBAAQ,UAAU,GAAG,QAAQ,IAAI,KAAK,QAAQ,OAAO,KAAK,QAAQ;AAAA,UAClE,QAAQ,QAAQ;AAAA;AAAA,EAAO,QAAQ,KAAK,KAAK;AAAA,WAC5C,GACF;AAAA,SAEJ;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/error-boundary.tsx"],"sourcesContent":["import { Component } from \"react\";\nimport type { ErrorInfo, ReactNode } from \"react\";\nimport { AlertTriangle, RefreshCw, WifiOff } from \"lucide-react\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button, EmptyState } from \"./ui\";\nimport { CopyButton } from \"./copy-button\";\nimport { Disclosure } from \"./disclosure\";\n\n/** The words of the default fallback. */\nexport interface ErrorBoundaryLabels {\n /** The fallback's heading. */\n title: string;\n /** The line under it. */\n message: string;\n /** The button that clears the error and renders the children again. */\n retry: string;\n /** The disclosure that opens the full error report (`showDetails`). */\n details: string;\n /** The button that reloads the whole page (0.13). */\n reload: string;\n /** Heading when a lazy chunk failed to load while online — a deploy replaced the\n * files this page was built from (0.13). */\n updateTitle: string;\n updateMessage: string;\n /** Heading when the browser says it is offline (0.13). */\n offlineTitle: string;\n offlineMessage: string;\n /** The copy button's words: what it copies is the plain-text report (0.13). */\n copyReport: string;\n /** Shown once `onReport` has filed the crash and returned no reference (0.13). */\n reported: string;\n /** Shown once `onReport` has filed the crash under a reference — rendered as the\n * app returned it, so return `\"#123\"` if the hash belongs to it (0.13). */\n reportedAs: (reference: string) => string;\n}\n\nexport const DEFAULT_ERROR_BOUNDARY_LABELS: ErrorBoundaryLabels = {\n title: \"Something went wrong\",\n message: \"This part of the page could not be shown. Try again, or reload the page.\",\n retry: \"Try again\",\n details: \"Error details\",\n reload: \"Reload\",\n updateTitle: \"A new version is available\",\n updateMessage: \"Part of the app has changed since this page was loaded. Reload to get the new version.\",\n offlineTitle: \"You’re offline\",\n offlineMessage: \"This page could not be loaded without a connection. Reconnect, then reload the page.\",\n copyReport: \"Copy error report\",\n reported: \"This error has been reported automatically.\",\n reportedAs: (reference) => `Reported as ${reference}`,\n};\n\n/**\n * What was thrown, as flat strings, read ONCE when it arrives.\n *\n * React stores whatever was thrown, hostile or not — `throw { get message() { throw … } }`,\n * `throw { name: Symbol() }`, `throw undefined` — and reading one of those during the\n * fallback's own render would throw INSIDE the boundary, escalating to the next one up\n * (keksdose's error-boundary.tsx learned this as feedback #160: at the app level there is\n * none, and the result is the white screen the boundary exists to prevent).\n */\nexport interface ErrorBoundaryDetails {\n name: string;\n message: string;\n stack?: string;\n}\n\nfunction read(get: () => unknown): string | undefined {\n try {\n const v = get();\n return typeof v === \"string\" ? v : v === undefined || v === null ? undefined : String(v);\n } catch {\n return undefined;\n }\n}\n\n/** `JSON.stringify` that never throws (a cycle, a BigInt, a hostile getter) and never\n * returns more than 500 characters. \"\" when there is nothing to say. */\nfunction safeJson(value: unknown): string {\n try {\n const json = JSON.stringify(value);\n if (!json || json === \"{}\") return \"\";\n return json.length > 500 ? `${json.slice(0, 499)}…` : json;\n } catch {\n return \"\";\n }\n}\n\n/** {@link ErrorBoundaryDetails} of any thrown value, without ever throwing. */\nexport function describeThrown(error: unknown): ErrorBoundaryDetails {\n if (typeof error === \"object\" && error !== null) {\n const e = error as { name?: unknown; message?: unknown; stack?: unknown };\n const message = read(() => e.message) ?? \"\";\n return {\n name: read(() => e.name) ?? \"Error\",\n // `throw { code: 500 }` has no message, and an empty line leaves crash triage with\n // nothing (keksdose G3a; its old reporter filed `{\"code\":500}`). Such a value is\n // quoted as JSON instead, capped, and never at the cost of a throw.\n message: message || (error instanceof Error ? \"\" : safeJson(error)),\n stack: read(() => e.stack),\n };\n }\n return { name: \"Error\", message: read(() => error) ?? \"\" };\n}\n\n/**\n * Is this a failed lazy import — a route chunk that did not arrive?\n *\n * Two causes, and neither is a bug in the page: the device is offline and the chunk was\n * never cached, or a deploy replaced the hashed files the running page still points at.\n * Both are cured by a reload and by nothing else — `React.lazy` caches the rejected\n * import, so Try again re-throws the same error without fetching. The patterns are\n * keksdose's (crash-report.ts), which covers Vite (\"dynamically imported module\",\n * \"module script failed\"), webpack (\"ChunkLoadError\", \"Loading chunk\") and the bare\n * `fetch` failure a service worker hands back.\n *\n * Never throws: it runs inside the fallback's own render, where a throw is a white\n * screen. An error it cannot read is not a chunk failure.\n */\nexport function isChunkLoadError(\n error: { name?: string | null; message?: string | null } | null | undefined,\n): boolean {\n try {\n const s = `${error?.name ?? \"\"} ${error?.message ?? \"\"}`;\n return /ChunkLoadError|dynamically imported module|module script failed|Loading chunk|Failed to fetch/i.test(s);\n } catch {\n return false;\n }\n}\n\n/**\n * Everything a crash report carries, read once when the boundary catches.\n *\n * Plain strings only, so it survives `JSON.stringify` into an app's crash endpoint as is\n * and {@link formatCrashReport} can print it without a single guard. The wording of the\n * printed report is English on purpose: it is read by whoever fixes the bug, not by the\n * user who copies it, and a report in nine languages cannot be searched.\n */\nexport interface CrashReport {\n /** The thrown value's `name` (\"TypeError\"), \"Error\" for a non-object. */\n name: string;\n message: string;\n stack?: string;\n /** React's component stack from `componentDidCatch` — the part that names the\n * component, which a minified JS stack no longer does. */\n componentStack?: string;\n /** `pathname + search` at the moment of the crash. The search may carry what the\n * user typed — see `redact`. */\n page: string;\n /** ISO 8601, UTC. */\n time: string;\n userAgent: string;\n /** The boundary's `appVersion` prop. */\n appVersion?: string;\n /** `navigator.onLine` at the moment of the crash; left out where there is none. */\n online?: boolean;\n /** {@link isChunkLoadError} of the thrown value. Such a crash is never handed to\n * `onReport` — it is a deploy or a dropped connection, not a defect — but it is\n * still in the copied report. */\n chunkLoad: boolean;\n /** The boundary's `reportExtras()`, stringified. */\n extras: Record<string, string>;\n}\n\n/**\n * The report as one plain-text block — what the copy button puts on the clipboard and\n * the details disclosure shows.\n *\n * lenkbank's layout, because that is the one that was already being pasted into\n * feedback messages: the error line first (it is what a search for the bug matches),\n * then where / when / what, then the two stacks.\n */\nexport function formatCrashReport(report: CrashReport): string {\n const lines = [\n report.message ? `${report.name}: ${report.message}` : report.name,\n `Page: ${report.page}`,\n `Time: ${report.time}`,\n `User agent: ${report.userAgent}`,\n ];\n if (report.appVersion) lines.push(`App version: ${report.appVersion}`);\n if (report.online === false) lines.push(\"Online: no\");\n for (const [key, value] of Object.entries(report.extras)) lines.push(`${key}: ${value}`);\n if (report.stack) lines.push(\"\", \"Stack:\", report.stack.trim());\n if (report.componentStack) lines.push(\"\", \"Component stack:\", report.componentStack.trim());\n return lines.join(\"\\n\");\n}\n\n/**\n * A key for \"the same crash again\": the error's name and message and the first frames\n * of its stack.\n *\n * Page-load local, not a server-side grouping key (keksdose's crash-report.ts draws the\n * same line): its only job is to stop one page load filing one bug twice — React's dev\n * StrictMode, a Try again that crashes again, a render loop that trips the boundary many\n * times a second. The page and the time are left out on purpose: the same bug on two\n * routes is still one bug.\n */\nexport function crashFingerprint(report: Pick<CrashReport, \"name\" | \"message\" | \"stack\">): string {\n const frames = (report.stack ?? \"\").split(\"\\n\").slice(0, 4).join(\"|\");\n return `${report.name}::${report.message}::${frames}`;\n}\n\n/**\n * What `onReport` may resolve with. `{ reference }` is shown (\"Reported as …\");\n * nothing (or `{}`) means filed without one. `{ filed: false }` says the app decided NOT\n * to file (a demo session, a hot-reload artefact, a report buffered for later): the\n * screen then claims nothing and keeps the copy button — claiming a report that was\n * never sent is the same false statement as hiding one that was.\n */\nexport type CrashReportResult = { reference?: string; filed?: boolean } | void;\n\ninterface Filing {\n filed: boolean;\n reference?: string;\n}\n\nconst NOT_FILED: Filing = { filed: false };\n\n/** A render loop can trip a boundary dozens of times a second with a different message\n * each time (a counter in it); without a ceiling the first bad deploy files hundreds of\n * rows. keksdose's number. */\nconst MAX_REPORTS_PER_PAGE_LOAD = 5;\n\n/** Fingerprint → the one filing for it in this page load. Module scope IS the page\n * load: a reload starts it empty. A duplicate gets the first filing's promise, so the\n * second screen shows the same reference instead of claiming nothing. */\nconst filings = new Map<string, Promise<Filing>>();\n\nfunction settle(out: unknown): Filing {\n try {\n if (out && typeof out === \"object\") {\n const o = out as { filed?: unknown; reference?: unknown };\n if (o.filed === false) return NOT_FILED;\n const reference = typeof o.reference === \"string\" && o.reference ? o.reference : undefined;\n return { filed: true, reference };\n }\n return { filed: true };\n } catch {\n return NOT_FILED;\n }\n}\n\n/** Hand the report to the app, once per fingerprint per page load, and never throw —\n * not for a synchronous throw, a rejection, or a hostile thenable. */\nfunction fileOnce(report: CrashReport, onReport: (report: CrashReport) => unknown): Promise<Filing> {\n const key = crashFingerprint(report);\n const known = filings.get(key);\n if (known) return known;\n if (filings.size >= MAX_REPORTS_PER_PAGE_LOAD) return Promise.resolve(NOT_FILED);\n let filing: Promise<Filing>;\n try {\n filing = Promise.resolve(onReport(report)).then(settle, () => NOT_FILED);\n } catch {\n filing = Promise.resolve(NOT_FILED);\n }\n // Claimed before the first await: two catches in the same tick (StrictMode) must not\n // both get past the lookup above.\n filings.set(key, filing);\n return filing;\n}\n\nfunction isOffline(): boolean {\n try {\n return typeof navigator !== \"undefined\" && navigator.onLine === false;\n } catch {\n return false;\n }\n}\n\nfunction reloadPage(): void {\n try {\n window.location.reload();\n } catch {\n /* nothing left to do from here */\n }\n}\n\n/** What a render-prop `fallback` is handed. */\nexport interface ErrorBoundaryFallbackProps {\n /** The thrown value, as it was thrown. Read it with care — see {@link describeThrown}. */\n error: unknown;\n details: ErrorBoundaryDetails;\n /** Clear the error and render the children again. */\n reset: () => void;\n /** The crash report, once `componentDidCatch` has built it (null on the very first\n * render of the fallback, which happens before it). Already `redact`ed. */\n report: CrashReport | null;\n}\n\nexport interface ErrorBoundaryProps {\n children?: ReactNode;\n /** Replaces the default fallback: a node, or a render function handed the error and\n * a `reset`. The same rule applies to it as to the default: see the component docs. */\n fallback?: ReactNode | ((props: ErrorBoundaryFallbackProps) => ReactNode);\n /** Called once per caught error with the raw value — log it. A throw from it is\n * swallowed: the boundary is the last thing standing. For filing a report, prefer\n * `onReport`, which gets the finished report, dedupe and the reference on screen. */\n onError?: (error: unknown, info: ErrorInfo) => void;\n /** Called when the error is cleared, by Try again, `reset` or a `resetKeys` change —\n * drop a cache, refetch. */\n onReset?: () => void;\n /**\n * When any of these changes (compared with `Object.is`) AFTER an error was caught, the\n * error is cleared and the children render again — a change in the same update that\n * threw does not count (it is what the error was shown under) — pass the route path so leaving a broken page does not\n * carry its fallback to the next one (keksdose's `resetKey`).\n */\n resetKeys?: ReadonlyArray<unknown>;\n /** Quote the error's `name: message` in a monospace box under the hint. Default on\n * (0.13): three sentences true of every crash identify none of them, and the one\n * line that does is what a user can read out or screenshot (lenkbank P7). Not shown\n * for a chunk-load / offline screen, where the message is a URL that explains\n * nothing the title does not. */\n showMessage?: boolean;\n /** A collapsed disclosure holding the full plain-text report. Default on since 0.13\n * (it was an opt-in showing name, message and stack): closed, it costs one line, and\n * it is where a support conversation asks the user to look. */\n showDetails?: boolean;\n /** The copy button for the plain-text report (the kit's CopyButton, which says when\n * the clipboard refused). Default on. Hidden once `onReport` has filed the crash —\n * there is nothing left to paste anywhere — and shown again whenever it did not. */\n copyReport?: boolean;\n /** The app's version, printed in the report — the first question on every crash. */\n appVersion?: string;\n /** More `key: value` lines for the report, read when the boundary catches (a tenant\n * id, the feature flags). A throw from it is swallowed and the lines are left out. */\n reportExtras?: () => Record<string, string>;\n /**\n * Rewrite the report before anything sees it: the screen, the clipboard and\n * `onReport` all get the returned one.\n *\n * THE REPORT IS STRUCTURE, NEVER CONTENT — and only the app knows which of its query\n * params hold content. keksdose's register put the free-text search in `?q=` and payee\n * names in the `f.*` filters, and its crash channel sent them in the clear to a column\n * every admin reads (crash-report.ts `safeUrl`). The cure there is an ALLOW-list, so a\n * param added later is dropped until somebody decides otherwise — rebuild `page`\n * from `new URL(r.page, location.origin)`, keeping only the listed `searchParams`.\n * `extras` are the app's own and need no second pass. A throw from `redact` falls\n * back to the pathname alone and no extras — failing closed.\n *\n * The same holds inside `onReport`, which is the other place to do it: clamp fields\n * to what the endpoint accepts, drop what it must not store. The kit cannot know.\n */\n redact?: (report: CrashReport) => CrashReport;\n /**\n * File the report automatically. Called from `componentDidCatch`, at most once per\n * {@link crashFingerprint} per page load (and at most five times in all), never for a\n * chunk-load error. It can NOT throw into the boundary: a synchronous throw and a\n * rejection both read as \"not filed\", and the copy button stays.\n *\n * Resolve with `{ reference }` and the screen says \"Reported as …\" instead of the copy\n * button; see {@link CrashReportResult} for \"filed without a reference\" and \"decided not\n * to file\". Whatever the app's reporter does, it must do without the router, the query\n * client or the auth store's hooks — a bare `fetch` with `keepalive`, so it survives\n * the reload the user is about to press (keksdose crash-report.ts `post`).\n */\n onReport?: (report: CrashReport) => Promise<CrashReportResult> | CrashReportResult;\n /** The app's own escape hatches, beside Reload / Try again — keksdose's \"Clear local\n * data\" for a poisoned persisted cache that no in-app action could otherwise break.\n * A full-width hint under it: wrap it in `<div className=\"basis-full\">`. */\n actions?: ReactNode;\n /** The default fallback's heading level. Default `h2`: the fallback often IS the page. */\n headingAs?: \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n /** Classes for the default fallback's box (`m-8 min-h-[400px]`, kastlan). */\n className?: string;\n labels?: Partial<ErrorBoundaryLabels>;\n}\n\ntype FilingState = \"none\" | \"pending\" | \"filed\" | \"failed\";\n\ninterface ErrorBoundaryState {\n /** A flag of its own, so `throw undefined` is still an error shown. */\n failed: boolean;\n error: unknown;\n details: ErrorBoundaryDetails | null;\n report: CrashReport | null;\n filing: FilingState;\n reference: string | undefined;\n}\n\nconst CLEAR: ErrorBoundaryState = {\n failed: false,\n error: null,\n details: null,\n report: null,\n filing: \"none\",\n reference: undefined,\n};\n\nfunction keysChanged(a: ReadonlyArray<unknown> | undefined, b: ReadonlyArray<unknown> | undefined): boolean {\n if (a === b) return false;\n if (!a || !b || a.length !== b.length) return true;\n return a.some((v, i) => !Object.is(v, b[i]));\n}\n\nfunction currentPage(): { page: string; path: string } {\n try {\n const { pathname, search } = window.location;\n return { page: `${pathname}${search}`, path: pathname };\n } catch {\n return { page: \"\", path: \"\" };\n }\n}\n\nfunction buildReport(details: ErrorBoundaryDetails, componentStack: string | undefined, props: ErrorBoundaryProps): CrashReport {\n const { page, path } = currentPage();\n const extras: Record<string, string> = {};\n try {\n const more = props.reportExtras?.();\n if (more) for (const [k, v] of Object.entries(more)) extras[k] = String(v);\n } catch {\n /* documented: the lines are left out */\n }\n let userAgent = \"\";\n let online: boolean | undefined;\n try {\n userAgent = navigator.userAgent;\n online = typeof navigator.onLine === \"boolean\" ? navigator.onLine : undefined;\n } catch {\n /* no navigator (SSR, a worker test) */\n }\n const report: CrashReport = {\n name: details.name,\n message: details.message,\n stack: details.stack,\n componentStack: componentStack ?? undefined,\n page,\n time: new Date().toISOString(),\n userAgent,\n appVersion: props.appVersion,\n online,\n chunkLoad: isChunkLoadError(details),\n extras,\n };\n if (!props.redact) return report;\n try {\n return props.redact(report);\n } catch {\n // Fail closed: an app that asked for redaction must not get the unredacted page.\n return { ...report, page: path, extras: {} };\n }\n}\n\n/**\n * Catch a render error below it and show ONE crash screen instead of an empty page.\n *\n * The three apps each built one. kastlan's and keksdose's sat on `EmptyState\n * tone=\"danger\"`; lenkbank's quoted the error and offered a plain-text report to copy;\n * keksdose's filed the crash itself, told a lazy-chunk failure apart as \"offline\", and\n * offered \"clear local data\" when a poisoned cache made Retry useless (feedback #160).\n * This is all of that, so the apps reduce to\n * `<ErrorBoundary resetKeys={[pathname]} appVersion={__VERSION__} />` plus, for an app\n * with a crash endpoint, `onReport` and `actions`:\n *\n * - the error's `name: message`, quoted (`showMessage`);\n * - Try again (reset the boundary) AND Reload (the page) — Try again alone re-renders\n * the same subtree from the same state, which a deterministic crash survives;\n * - a chunk-load error or an offline browser gets its own title and Reload first\n * (\"A new version is available\" / \"You're offline\");\n * - the copy button and the report in a disclosure; `onReport` for filing it, deduped\n * per page load, with its reference on screen.\n *\n * THE RULE for this fallback — and for a `fallback` or `actions` an app passes in: it\n * must not depend on the router, the query client or the auth store. A crash is exactly\n * when those may be what broke, and a fallback that throws escalates to the next\n * boundary up — at the app level there is none, and the user gets the white screen this\n * exists to prevent. So no `useNavigate`, no `useQuery`, no `useAuth()` in it; reload\n * with `window.location`, not the router. The kit's own label hooks are the one context\n * it does read (`errorBoundary.*` from `UiKitProvider`), and they degrade to the English\n * defaults when there is no provider above — which is why the app-level boundary may\n * sit OUTSIDE the provider and still render.\n *\n * The fallback is `role=\"alert\"`: a page replaced by an error is news, and a reader\n * that was on it is told.\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n state: ErrorBoundaryState = CLEAR;\n\n /** Bumped by every catch and reset, so a filing that settles after the screen moved\n * on (Try again, a route change, a second crash) does not write into it. */\n private generation = 0;\n\n /**\n * Forget which crashes this page load has filed, and the count towards the cap.\n *\n * For tests: the dedupe lives in module scope because a page load is what it spans,\n * and a test file is one page load — so without this, the sixth test that files a\n * report finds the cap reached and `onReport` never called. Call it in `beforeEach`.\n * Never needed in an app: a reload is the reset.\n */\n static forgetReports(): void {\n filings.clear();\n }\n\n static getDerivedStateFromError(error: unknown): Partial<ErrorBoundaryState> {\n return { failed: true, error, details: describeThrown(error), report: null, filing: \"none\", reference: undefined };\n }\n\n componentDidCatch(error: unknown, info: ErrorInfo): void {\n try {\n this.props.onError?.(error, info);\n } catch {\n /* documented: a logger must not take the fallback down */\n }\n const details = this.state.details ?? describeThrown(error);\n const report = buildReport(details, info.componentStack ?? undefined, this.props);\n const { onReport } = this.props;\n const willFile = onReport !== undefined && !report.chunkLoad;\n const generation = ++this.generation;\n this.setState({ report, filing: willFile ? \"pending\" : \"none\", reference: undefined });\n if (!willFile) return;\n void fileOnce(report, onReport).then((filing) => {\n if (generation !== this.generation) return;\n this.setState(\n filing.filed ? { filing: \"filed\", reference: filing.reference } : { filing: \"failed\", reference: undefined },\n );\n });\n }\n\n componentDidUpdate(prev: ErrorBoundaryProps, prevState: ErrorBoundaryState): void {\n // Only a change AFTER the error was caught clears it (react-error-boundary's rule).\n // `prevState.failed` is false in the update that caught it: that update may well be\n // the one that changed the keys too — a navigation to a page that throws, with\n // `resetKeys={[pathname]}` — and resetting then would fire `onReset` for nothing and\n // render the failing child a second time. From then on `prev.resetKeys` are the\n // keys the error was shown under, so any change clears it.\n if (this.state.failed && prevState.failed && keysChanged(prev.resetKeys, this.props.resetKeys)) {\n this.reset();\n }\n }\n\n reset = (): void => {\n this.generation++;\n this.props.onReset?.();\n this.setState(CLEAR);\n };\n\n render(): ReactNode {\n const { failed, error, details, report, filing, reference } = this.state;\n if (!failed || !details) return this.props.children;\n const { fallback } = this.props;\n if (typeof fallback === \"function\") return fallback({ error, details, reset: this.reset, report });\n if (fallback !== undefined) return fallback;\n return (\n <ErrorFallback\n details={details}\n report={report}\n filing={filing}\n reference={reference}\n reset={this.reset}\n showMessage={this.props.showMessage ?? true}\n showDetails={this.props.showDetails ?? true}\n copyReport={this.props.copyReport ?? true}\n actions={this.props.actions}\n headingAs={this.props.headingAs ?? \"h2\"}\n className={this.props.className}\n labels={this.props.labels}\n />\n );\n }\n}\n\nfunction ErrorFallback({\n details,\n report,\n filing,\n reference,\n reset,\n showMessage,\n showDetails,\n copyReport,\n actions,\n headingAs,\n className,\n labels,\n}: {\n details: ErrorBoundaryDetails;\n report: CrashReport | null;\n filing: FilingState;\n reference: string | undefined;\n reset: () => void;\n showMessage: boolean;\n showDetails: boolean;\n copyReport: boolean;\n actions?: ReactNode;\n headingAs: NonNullable<ErrorBoundaryProps[\"headingAs\"]>;\n className?: string;\n labels?: Partial<ErrorBoundaryLabels>;\n}) {\n const text = useKitLabels(\"errorBoundary\", DEFAULT_ERROR_BOUNDARY_LABELS, labels);\n const chunk = isChunkLoadError(details);\n // Offline first, as keksdose has it: offline, a chunk failure is the connection, and\n // any other crash most likely a request that could not be made — either way \"reload\n // once you are back\" is the advice, and \"a new version\" would be a false one.\n const mode = isOffline() ? \"offline\" : chunk ? \"update\" : \"error\";\n const title = mode === \"offline\" ? text.offlineTitle : mode === \"update\" ? text.updateTitle : text.title;\n const hint = mode === \"offline\" ? text.offlineMessage : mode === \"update\" ? text.updateMessage : text.message;\n const Icon = mode === \"offline\" ? WifiOff : mode === \"update\" ? RefreshCw : AlertTriangle;\n const reportText = report ? formatCrashReport(report) : null;\n const errorLine = details.message ? `${details.name}: ${details.message}` : details.name;\n\n const reloadButton = (\n <Button key=\"reload\" variant={mode === \"error\" ? \"secondary\" : \"primary\"} onClick={reloadPage}>\n {text.reload}\n </Button>\n );\n // Not after a chunk failure: `React.lazy` keeps the rejected import, so Try again\n // could only throw the same error again.\n const retryButton = chunk ? null : (\n <Button key=\"retry\" variant={mode === \"error\" ? \"primary\" : \"secondary\"} onClick={reset}>\n {text.retry}\n </Button>\n );\n\n return (\n <EmptyState\n role=\"alert\"\n tone={mode === \"error\" ? \"danger\" : undefined}\n headingAs={headingAs}\n className={className}\n icon={<Icon />}\n title={title}\n hint={hint}\n action={\n <>\n {showMessage && mode === \"error\" && (\n // A quotation, not prose: left-aligned and monospaced, so it reads as the\n // program's words and can be read out or screenshotted verbatim.\n <p\n data-error-message=\"\"\n className=\"-mt-1 mb-1 basis-full whitespace-pre-wrap break-words rounded-md border border-[var(--danger-border)] bg-[var(--danger-bg)] px-3 py-2 text-start font-mono text-xs text-[var(--text-primary)]\"\n >\n {errorLine}\n </p>\n )}\n {filing === \"filed\" && (\n <p className=\"-mt-1 mb-1 basis-full text-xs\">\n {reference ? text.reportedAs(reference) : text.reported}\n </p>\n )}\n {mode === \"error\" ? [retryButton, reloadButton] : [reloadButton, retryButton]}\n {copyReport && reportText !== null && filing !== \"filed\" && (\n <CopyButton variant=\"label\" buttonVariant=\"ghost\" label={text.copyReport} text={reportText} />\n )}\n {actions}\n {showDetails && reportText !== null && (\n <Disclosure variant=\"bare\" title={text.details} className=\"basis-full text-start\">\n <pre className=\"max-h-60 overflow-auto whitespace-pre-wrap break-words text-xs text-[var(--text-secondary)]\">\n {reportText}\n </pre>\n </Disclosure>\n )}\n </>\n }\n />\n );\n}\n"],"mappings":";AA+hBM,SAgFE,UAhFF,KAgFE,YAhFF;AA/hBN,SAAS,iBAAiB;AAE1B,SAAS,eAAe,WAAW,eAAe;AAClD,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,kBAAkB;AACnC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AA8BpB,MAAM,gCAAqD;AAAA,EAChE,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,eAAe;AAAA,EACf,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,YAAY,CAAC,cAAc,eAAe,SAAS;AACrD;AAiBA,SAAS,KAAK,KAAwC;AACpD,MAAI;AACF,UAAM,IAAI,IAAI;AACd,WAAO,OAAO,MAAM,WAAW,IAAI,MAAM,UAAa,MAAM,OAAO,SAAY,OAAO,CAAC;AAAA,EACzF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAIA,SAAS,SAAS,OAAwB;AACxC,MAAI;AACF,UAAM,OAAO,KAAK,UAAU,KAAK;AACjC,QAAI,CAAC,QAAQ,SAAS,KAAM,QAAO;AACnC,WAAO,KAAK,SAAS,MAAM,GAAG,KAAK,MAAM,GAAG,GAAG,CAAC,WAAM;AAAA,EACxD,QAAQ;AACN,WAAO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EAEJ;AAEJ;","names":[]}
@@ -49,32 +49,35 @@ function useFieldSync({
49
49
  if (timerRef.current) clearTimeout(timerRef.current);
50
50
  };
51
51
  }, []);
52
- const flush = useCallback(async () => {
53
- if (inFlightRef.current) return;
54
- const next = draftRef.current;
55
- if (equalsRef.current(next, savedRef.current)) return;
56
- inFlightRef.current = true;
57
- setState("pending");
58
- setError(null);
59
- try {
60
- await onSaveRef.current(next);
61
- savedRef.current = next;
62
- inFlightRef.current = false;
63
- if (!mountedRef.current) return;
64
- if (equalsRef.current(draftRef.current, next)) {
65
- setState("synced");
66
- } else {
67
- setState("edited");
68
- void flush();
52
+ const flush = useCallback(() => {
53
+ const run = async () => {
54
+ if (inFlightRef.current) return;
55
+ const next = draftRef.current;
56
+ if (equalsRef.current(next, savedRef.current)) return;
57
+ inFlightRef.current = true;
58
+ setState("pending");
59
+ setError(null);
60
+ try {
61
+ await onSaveRef.current(next);
62
+ savedRef.current = next;
63
+ inFlightRef.current = false;
64
+ if (!mountedRef.current) return;
65
+ if (equalsRef.current(draftRef.current, next)) {
66
+ setState("synced");
67
+ } else {
68
+ setState("edited");
69
+ void run();
70
+ }
71
+ } catch (cause) {
72
+ inFlightRef.current = false;
73
+ const err = toError(cause);
74
+ onErrorRef.current?.(err);
75
+ if (!mountedRef.current) return;
76
+ setState("error");
77
+ setError(err);
69
78
  }
70
- } catch (cause) {
71
- inFlightRef.current = false;
72
- const err = toError(cause);
73
- onErrorRef.current?.(err);
74
- if (!mountedRef.current) return;
75
- setState("error");
76
- setError(err);
77
- }
79
+ };
80
+ return run();
78
81
  }, []);
79
82
  const setValue = useCallback(
80
83
  (next) => {
@@ -187,69 +190,73 @@ function FieldSyncRow({
187
190
  const isError = state === "error";
188
191
  const text = isError ? error?.message?.trim() ? error.message : l.error : l[state];
189
192
  const retry = onRetry ?? sync.retry;
190
- const previous = useRef(state);
193
+ const [previous, setPrevious] = useState(state);
191
194
  const [justSaved, setJustSaved] = useState(false);
195
+ if (state !== previous) {
196
+ setPrevious(state);
197
+ setJustSaved(state === "synced" && previous === "pending");
198
+ }
192
199
  useEffect(() => {
193
- const was = previous.current;
194
- previous.current = state;
195
- if (state === "synced" && was === "pending") {
196
- setJustSaved(true);
197
- const t = setTimeout(() => setJustSaved(false), savedMs);
198
- return () => clearTimeout(t);
199
- }
200
- if (state !== "synced") setJustSaved(false);
201
- }, [state, savedMs]);
200
+ if (!justSaved) return;
201
+ const t = setTimeout(() => setJustSaved(false), savedMs);
202
+ return () => clearTimeout(t);
203
+ }, [justSaved, savedMs]);
202
204
  const shown = state === "synced" ? justSaved ? "synced" : null : state;
203
- return /* @__PURE__ */ jsxs(
204
- "div",
205
- {
206
- "data-field-sync": state,
207
- className: cn(
208
- // `relative` for the icon and for the sr-only live region's containing block.
209
- "relative [&_:is(input,select,textarea)]:pe-9",
210
- shown && FIELD_SYNC_FRAME[shown],
211
- className
212
- ),
213
- onBlur: saveOnBlur ? (e) => {
214
- if (!e.currentTarget.contains(e.relatedTarget)) sync.save();
215
- } : void 0,
216
- children: [
217
- children,
218
- /* @__PURE__ */ jsxs("span", { className: "pointer-events-none absolute inset-y-0 end-0 flex items-center pe-3", children: [
219
- state === "edited" && /* @__PURE__ */ jsx(PencilLine, { "aria-hidden": true, className: "size-4 text-[var(--status-edited)]" }),
220
- state === "pending" && /* @__PURE__ */ jsx(Loader2, { "aria-hidden": true, className: "size-4 animate-spin text-[var(--status-pending)] motion-reduce:animate-none" }),
221
- state === "synced" && /* @__PURE__ */ jsx(
222
- Check,
223
- {
224
- "aria-hidden": true,
225
- className: cn(
226
- "size-4 text-[var(--status-synced)] transition-opacity duration-500 motion-reduce:transition-none",
227
- justSaved ? "opacity-100" : "opacity-0"
228
- )
229
- }
230
- ),
231
- isError && /* @__PURE__ */ jsx(Tooltip, { label: text, portal: true, redact: true, children: /* @__PURE__ */ jsx(
232
- "button",
205
+ return (
206
+ /* eslint-disable-next-line jsx-a11y/no-static-element-interactions -- not an interaction:
207
+ `onBlur` listens for focus leaving the row's own controls (which are the
208
+ interactive elements) to save; the wrapper itself is never focused. */
209
+ /* @__PURE__ */ jsxs(
210
+ "div",
211
+ {
212
+ "data-field-sync": state,
213
+ className: cn(
214
+ // `relative` for the icon and for the sr-only live region's containing block.
215
+ "relative [&_:is(input,select,textarea)]:pe-9",
216
+ shown && FIELD_SYNC_FRAME[shown],
217
+ className
218
+ ),
219
+ onBlur: saveOnBlur ? (e) => {
220
+ if (!e.currentTarget.contains(e.relatedTarget)) sync.save();
221
+ } : void 0,
222
+ children: [
223
+ children,
224
+ /* @__PURE__ */ jsxs("span", { className: "pointer-events-none absolute inset-y-0 end-0 flex items-center pe-3", children: [
225
+ state === "edited" && /* @__PURE__ */ jsx(PencilLine, { "aria-hidden": true, className: "size-4 text-[var(--status-edited)]" }),
226
+ state === "pending" && /* @__PURE__ */ jsx(Loader2, { "aria-hidden": true, className: "size-4 animate-spin text-[var(--status-pending)] motion-reduce:animate-none" }),
227
+ state === "synced" && /* @__PURE__ */ jsx(
228
+ Check,
229
+ {
230
+ "aria-hidden": true,
231
+ className: cn(
232
+ "size-4 text-[var(--status-synced)] transition-opacity duration-500 motion-reduce:transition-none",
233
+ justSaved ? "opacity-100" : "opacity-0"
234
+ )
235
+ }
236
+ ),
237
+ isError && /* @__PURE__ */ jsx(Tooltip, { label: text, portal: true, redact: true, children: /* @__PURE__ */ jsx(
238
+ "button",
239
+ {
240
+ type: "button",
241
+ onClick: retry,
242
+ "aria-label": l.retry,
243
+ className: "pointer-events-auto flex rounded-full text-[var(--status-error)] focus-visible:outline-2 focus-visible:outline-offset-2",
244
+ children: /* @__PURE__ */ jsx(AlertCircle, { "aria-hidden": true, className: "size-4" })
245
+ }
246
+ ) })
247
+ ] }),
248
+ /* @__PURE__ */ jsx(
249
+ "span",
233
250
  {
234
- type: "button",
235
- onClick: retry,
236
- "aria-label": l.retry,
237
- className: "pointer-events-auto flex rounded-full text-[var(--status-error)] focus-visible:outline-2 focus-visible:outline-offset-2",
238
- children: /* @__PURE__ */ jsx(AlertCircle, { "aria-hidden": true, className: "size-4" })
251
+ role: isError ? "alert" : "status",
252
+ "aria-live": isError ? "assertive" : "polite",
253
+ className: "sr-only",
254
+ children: shown === null ? "" : text
239
255
  }
240
- ) })
241
- ] }),
242
- /* @__PURE__ */ jsx(
243
- "span",
244
- {
245
- role: isError ? "alert" : "status",
246
- "aria-live": isError ? "assertive" : "polite",
247
- className: "sr-only",
248
- children: shown === null ? "" : text
249
- }
250
- )
251
- ]
252
- }
256
+ )
257
+ ]
258
+ }
259
+ )
253
260
  );
254
261
  }
255
262
  export {