@eifi1/ui-kit 0.23.0 → 0.24.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 (101) hide show
  1. package/README.md +6 -6
  2. package/dist/chart.d.ts +2 -4
  3. package/dist/components/amount-input.d.ts +16 -9
  4. package/dist/components/amount-input.js +13 -11
  5. package/dist/components/amount-input.js.map +1 -1
  6. package/dist/components/autocomplete.d.ts +5 -0
  7. package/dist/components/autocomplete.js +39 -37
  8. package/dist/components/autocomplete.js.map +1 -1
  9. package/dist/components/button-group.d.ts +2 -4
  10. package/dist/components/calculator.d.ts +2 -4
  11. package/dist/components/column-mapper.d.ts +62 -9
  12. package/dist/components/column-mapper.js +85 -49
  13. package/dist/components/column-mapper.js.map +1 -1
  14. package/dist/components/combobox.d.ts +33 -1
  15. package/dist/components/combobox.js +8 -2
  16. package/dist/components/combobox.js.map +1 -1
  17. package/dist/components/confirm-dialog.d.ts +2 -4
  18. package/dist/components/copy-button.d.ts +2 -4
  19. package/dist/components/danger-confirm.d.ts +2 -4
  20. package/dist/components/danger-confirm.js +52 -5
  21. package/dist/components/danger-confirm.js.map +1 -1
  22. package/dist/components/entity-combobox.d.ts +13 -1
  23. package/dist/components/entity-combobox.js +13 -4
  24. package/dist/components/entity-combobox.js.map +1 -1
  25. package/dist/components/facing-pair.d.ts +2 -4
  26. package/dist/components/file-button.d.ts +2 -4
  27. package/dist/components/file-dropzone.d.ts +2 -4
  28. package/dist/components/form-actions.d.ts +1 -3
  29. package/dist/components/form-actions.js +15 -1
  30. package/dist/components/form-actions.js.map +1 -1
  31. package/dist/components/iban-input.d.ts +2 -4
  32. package/dist/components/language-select.d.ts +2 -4
  33. package/dist/components/money-field.d.ts +2 -4
  34. package/dist/components/multi-entity-combobox.d.ts +5 -1
  35. package/dist/components/multi-entity-combobox.js +11 -3
  36. package/dist/components/multi-entity-combobox.js.map +1 -1
  37. package/dist/components/number-field.d.ts +2 -4
  38. package/dist/components/number-input.d.ts +2 -4
  39. package/dist/components/numpad-sheet.d.ts +2 -4
  40. package/dist/components/phone-input.d.ts +2 -4
  41. package/dist/components/series-chart.d.ts +2 -4
  42. package/dist/components/settings-fields.d.ts +2 -4
  43. package/dist/components/share-card.d.ts +1 -3
  44. package/dist/components/text-link.d.ts +1 -3
  45. package/dist/components/time-input.d.ts +2 -4
  46. package/dist/components/ui.d.ts +2 -4
  47. package/dist/components/ui.js +55 -17
  48. package/dist/components/ui.js.map +1 -1
  49. package/dist/feedback/feedback-attachment.d.ts +66 -1
  50. package/dist/feedback/feedback-attachment.js +32 -12
  51. package/dist/feedback/feedback-attachment.js.map +1 -1
  52. package/dist/feedback/feedback-dialog.d.ts +66 -1
  53. package/dist/feedback/feedback-inbox.d.ts +67 -253
  54. package/dist/feedback/feedback-thread.d.ts +1 -3
  55. package/dist/feedback/feedback-thread.js +8 -2
  56. package/dist/feedback/feedback-thread.js.map +1 -1
  57. package/dist/{feedback-BxeQVzwq.d.ts → feedback-DOwPu-Il.d.ts} +878 -18
  58. package/dist/feedback.d.ts +2 -4
  59. package/dist/hooks/use-file-drop.d.ts +2 -4
  60. package/dist/i18n/defaults.d.ts +2 -4
  61. package/dist/i18n/german.d.ts +2 -4
  62. package/dist/i18n/kit-labels.d.ts +1 -3
  63. package/dist/i18n/languages.d.ts +2 -4
  64. package/dist/i18n/locales/de-CH.d.ts +2 -4
  65. package/dist/i18n/locales/en.d.ts +2 -4
  66. package/dist/i18n/locales/es.d.ts +2 -4
  67. package/dist/i18n/locales/fr.d.ts +2 -4
  68. package/dist/i18n/locales/hu.d.ts +2 -4
  69. package/dist/i18n/locales/it.d.ts +2 -4
  70. package/dist/i18n/locales/zh.d.ts +2 -4
  71. package/dist/i18n/review.d.ts +2 -4
  72. package/dist/index.d.ts +2 -4
  73. package/dist/lib/strip-fade.d.ts +2 -2
  74. package/dist/lib/strip-fade.js.map +1 -1
  75. package/dist/rhf/fields.d.ts +59 -8
  76. package/dist/rhf/fields.js +61 -3
  77. package/dist/rhf/fields.js.map +1 -1
  78. package/dist/rhf/form.d.ts +2 -4
  79. package/dist/rhf.d.ts +3 -5
  80. package/dist/rhf.js.map +1 -1
  81. package/dist/shell/app-shell.d.ts +1 -3
  82. package/dist/shell/top-bar-brand.d.ts +2 -4
  83. package/dist/shell.d.ts +1 -3
  84. package/dist/wizard/stepper-nav.d.ts +2 -4
  85. package/dist/wizard.d.ts +2 -4
  86. package/package.json +1 -1
  87. package/src/components/amount-input.tsx +37 -20
  88. package/src/components/autocomplete.tsx +16 -5
  89. package/src/components/column-mapper.tsx +181 -79
  90. package/src/components/combobox.tsx +41 -3
  91. package/src/components/danger-confirm.tsx +193 -22
  92. package/src/components/entity-combobox.tsx +28 -5
  93. package/src/components/form-actions.tsx +20 -1
  94. package/src/components/multi-entity-combobox.tsx +16 -3
  95. package/src/components/ui.tsx +107 -0
  96. package/src/feedback/feedback-attachment.tsx +65 -12
  97. package/src/feedback/feedback-thread.tsx +66 -6
  98. package/src/lib/strip-fade.ts +2 -2
  99. package/src/rhf/fields.tsx +167 -6
  100. package/src/rhf.ts +1 -1
  101. package/dist/feedback-attachment-fGAzZPf0.d.ts +0 -469
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { forwardRef, useCallback, useEffect, useId, useRef, useState } from "react";
3
+ import { Children, forwardRef, useCallback, useEffect, useId, useRef, useState } from "react";
4
4
  import { cn } from "../lib/cn.js";
5
5
  import { useKitLabels } from "../i18n/kit-labels.js";
6
6
  import { Button, Input, Label, Spinner } from "./ui.js";
@@ -133,6 +133,27 @@ const DEFAULT_DANGER_CONFIRM_LABELS = {
133
133
  needsAcknowledge: "Tick the box to confirm",
134
134
  needsPassword: "Enter your password to confirm"
135
135
  };
136
+ const SLOT_FIELD = [
137
+ 'input:not([type="hidden"])',
138
+ "select",
139
+ "textarea",
140
+ ...["combobox", "listbox", "radio", "checkbox", "switch", "slider", "spinbutton", "textbox"].map(
141
+ (role) => `[role="${role}"]`
142
+ )
143
+ ].map((selector) => `${selector}:not(:disabled):not([tabindex="-1"]):not([aria-hidden="true"])`).join(", ");
144
+ function firstSlotField(slot) {
145
+ if (!slot) return null;
146
+ for (const el of slot.querySelectorAll(SLOT_FIELD)) {
147
+ if (el.closest("[hidden], [inert]")) continue;
148
+ if (el instanceof HTMLInputElement && el.type === "radio" && !el.checked && el.name) {
149
+ const group = el.form?.elements.namedItem(el.name);
150
+ const checked = group instanceof RadioNodeList && Array.from(group).some((r) => r instanceof HTMLInputElement && r.checked);
151
+ if (checked) continue;
152
+ }
153
+ return el;
154
+ }
155
+ return null;
156
+ }
136
157
  function DangerConfirm({
137
158
  onConfirm,
138
159
  requirePassword,
@@ -142,6 +163,9 @@ function DangerConfirm({
142
163
  phraseMatch = "trim",
143
164
  prompt,
144
165
  tone = "danger",
166
+ confirmVariant,
167
+ confirmDisabledReason,
168
+ children,
145
169
  armLabel,
146
170
  confirmLabel,
147
171
  busy: busyProp,
@@ -168,8 +192,11 @@ function DangerConfirm({
168
192
  const reasonId = useId();
169
193
  const armId = useId();
170
194
  const cancelId = useId();
195
+ const confirmId = useId();
171
196
  const firstFieldRef = useRef(null);
197
+ const slotRef = useRef(null);
172
198
  const moveFocus = useRef(false);
199
+ const confirmed = useRef(false);
173
200
  const [wasArmed, setWasArmed] = useState(armed);
174
201
  if (wasArmed !== armed) {
175
202
  setWasArmed(armed);
@@ -187,12 +214,27 @@ function DangerConfirm({
187
214
  moveFocus.current = false;
188
215
  if (!changed) return;
189
216
  if (armed) {
190
- if (byUser) (firstFieldRef.current ?? document.getElementById(cancelId))?.focus();
217
+ if (byUser) {
218
+ (firstSlotField(slotRef.current) ?? firstFieldRef.current ?? document.getElementById(cancelId))?.focus();
219
+ }
191
220
  return;
192
221
  }
222
+ confirmed.current = false;
193
223
  const lost = document.activeElement === null || document.activeElement === document.body;
194
224
  if (byUser || lost) document.getElementById(armId)?.focus();
195
225
  }, [armed, armId, cancelId]);
226
+ const wasBusy = useRef(busy);
227
+ useEffect(() => {
228
+ const settled = wasBusy.current && !busy;
229
+ wasBusy.current = busy;
230
+ if (!settled) return;
231
+ const ours = confirmed.current;
232
+ confirmed.current = false;
233
+ if (!ours || !armed) return;
234
+ if (document.activeElement === null || document.activeElement === document.body) {
235
+ document.getElementById(confirmId)?.focus();
236
+ }
237
+ }, [busy, armed, confirmId]);
196
238
  const setArmed = (next) => {
197
239
  moveFocus.current = true;
198
240
  if (armedProp === void 0) setArmedState(next);
@@ -204,9 +246,11 @@ function DangerConfirm({
204
246
  const passwordOk = !requirePassword || password !== "";
205
247
  const phraseOk = phrase === void 0 || typedMatches(typed, phrase, phraseMatch);
206
248
  const acknowledgeOk = !asksAcknowledge || acknowledged;
207
- const canConfirm = passwordOk && phraseOk && acknowledgeOk && !busy;
249
+ const callerHeld = hasContent(confirmDisabledReason);
250
+ const hasFields = Children.toArray(children).some(hasContent);
251
+ const canConfirm = passwordOk && phraseOk && acknowledgeOk && !callerHeld && !busy;
208
252
  const guardReason = !acknowledgeOk ? labels.needsAcknowledge : !phraseOk ? typeof labels.needsPhrase === "function" ? labels.needsPhrase(phrase ?? "") : labels.needsPhrase : !passwordOk ? labels.needsPassword : void 0;
209
- const confirmReason = locked ? lockedReason : busy ? void 0 : guardReason;
253
+ const confirmReason = locked ? lockedReason : busy ? void 0 : callerHeld ? confirmDisabledReason : guardReason;
210
254
  const submit = (e) => {
211
255
  e.preventDefault();
212
256
  if (!canConfirm || locked) return;
@@ -215,6 +259,7 @@ function DangerConfirm({
215
259
  ...requirePassword && { password },
216
260
  ...asksAcknowledge && { acknowledged: true }
217
261
  };
262
+ confirmed.current = true;
218
263
  run(onConfirm(values.password, values), () => setArmed(false));
219
264
  };
220
265
  const firstField = asksAcknowledge ? "acknowledge" : phrase !== void 0 ? "phrase" : "password";
@@ -265,6 +310,7 @@ function DangerConfirm({
265
310
  children: [
266
311
  /* @__PURE__ */ jsx("p", { id: promptId, className: cn("text-xs font-medium", toneText), children: prompt ?? labels.prompt }),
267
312
  lines.length > 0 && /* @__PURE__ */ jsx("ul", { id: consequencesId, className: "list-disc space-y-1 ps-5 text-xs text-[var(--text-secondary)]", children: lines.map((line) => /* @__PURE__ */ jsx("li", { className: line.severe ? "text-[var(--danger)]" : void 0, children: line.text }, line.key)) }),
313
+ hasFields && /* @__PURE__ */ jsx("div", { ref: slotRef, className: "space-y-2", children }),
268
314
  asksAcknowledge && /* @__PURE__ */ jsx(
269
315
  Checkbox,
270
316
  {
@@ -303,8 +349,9 @@ function DangerConfirm({
303
349
  /* @__PURE__ */ jsxs(
304
350
  Button,
305
351
  {
352
+ id: confirmId,
306
353
  type: "submit",
307
- variant: tone === "warning" ? "primary" : "danger",
354
+ variant: confirmVariant ?? (tone === "warning" ? "primary" : "danger"),
308
355
  disabled: !canConfirm,
309
356
  disabledReason: confirmReason,
310
357
  "aria-busy": busy || void 0,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/danger-confirm.tsx"],"sourcesContent":["import { forwardRef, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button, Input, Label, Spinner } from \"./ui\";\nimport type { InputProps } from \"./ui\";\nimport { Checkbox } from \"./checkbox\";\nimport { Tooltip } from \"./tooltip\";\nimport { useCommitReason } from \"./write-lock\";\n\n/**\n * How typed text is compared with the text it has to repeat — shared by\n * `DangerConfirm`'s `phraseMatch` and `useConfirm`'s `typedMatch`.\n *\n * - `\"trim\"` ignores spaces around the typed text — a phone keyboard's autocomplete\n * likes to add one. Case counts: \"delete\" is not \"DELETE\".\n * - `\"exact\"` compares character for character, spaces included.\n * - `\"caseless\"` trims AND ignores case: for an e-mail address, whose domain is\n * case-insensitive and whose local part every real mail server treats so. Both apps'\n * \"type the account's address\" rules (keksdose's `TYPE_EMAIL`, Kurvenschmiede's\n * `TypedConfirm`) compared `trim().toLowerCase()`, and a capital the user's keyboard\n * put at the start must not make the right row look like the wrong one.\n */\nexport type TypedMatch = \"trim\" | \"exact\" | \"caseless\";\n\n/** Whether `typed` repeats `target` under `mode` — see {@link TypedMatch}. Exported for\n * a caller that draws its own field (a dialog that also picks a recipient) and wants\n * the same rule as the kit's. */\nexport function typedMatches(typed: string, target: string, mode: TypedMatch = \"trim\"): boolean {\n if (mode === \"exact\") return typed === target;\n if (mode === \"trim\") return typed.trim() === target;\n // `toLowerCase`, not `toLocaleLowerCase`: the comparison must not change with the\n // reader's locale (a Turkish dotless i would otherwise fail an ASCII address).\n return typed.trim().toLowerCase() === target.trim().toLowerCase();\n}\n\n/**\n * Busy-while-a-promise-runs, for an action that MAY return one: `run(result, onResolved)`\n * marks the caller pending until `result` settles, calls `onResolved` if it fulfilled,\n * and only clears the flag if it rejected — the caller shows why and the user retries.\n * Nothing runs after unmount. Shared by `DangerConfirm` and `ReauthDialog`, whose\n * contract is the same: resolve = done, reject = stay put.\n *\n * @internal\n */\nexport function usePromisePending() {\n const [pending, setPending] = useState(false);\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n const run = useCallback((result: unknown, onResolved: () => void): boolean => {\n if (!result || typeof (result as Promise<unknown>).then !== \"function\") return false;\n setPending(true);\n (result as Promise<unknown>).then(\n () => {\n if (!mounted.current) return;\n setPending(false);\n onResolved();\n },\n () => {\n if (mounted.current) setPending(false);\n },\n );\n return true;\n }, []);\n return { pending, run };\n}\n\n/** A label that is really there — `null`, `false` and `\"\"` are what a caller's\n * `cond && reason` evaluates to on the path where there is none. */\nfunction hasContent(node: ReactNode): boolean {\n return node !== undefined && node !== null && node !== false && node !== \"\";\n}\n\n/** The one word {@link CurrentPasswordInput} says on its own behalf — the\n * `dangerConfirm.password` label, shared with DangerConfirm's password field, so an\n * app translates \"Password\" once. */\nexport type CurrentPasswordInputLabels = Pick<DangerConfirmLabels, \"password\">;\n\n/**\n * Everything {@link Input} takes except what makes this field what it is: `type` is\n * always `\"password\"` and `autoComplete` always `\"current-password\"`.\n */\nexport interface CurrentPasswordInputProps extends Omit<InputProps, \"type\" | \"autoComplete\" | \"label\"> {\n /**\n * The visible label. Default `dangerConfirm.password` (\"Password\") — unless the field\n * is named another way (`aria-label` / `aria-labelledby`), which then stays the only\n * name. Pass the app's own word on a sign-in form (\"Password\", \"Your password\"), or\n * `null` for a field whose `<label htmlFor>` is drawn elsewhere (a form library's\n * `FormLabel`), which would otherwise be labelled twice.\n */\n label?: ReactNode;\n /** The value as a string — the `(next) => …` shape, so a caller holding it in\n * `useState` need not unwrap `event.target.value`. Fires alongside `onChange`,\n * never instead of it, so a form library's `onChange` keeps working. */\n onValueChange?: (value: string) => void;\n /**\n * A check is running (the sign-in request, the re-auth). The field turns `readOnly`,\n * NOT `disabled`: the field being submitted is usually the focused one (Enter was\n * pressed in it), and disabling a focused field drops focus to `<body>` — the user\n * lands nowhere when the \"wrong password\" answer comes back.\n */\n busy?: boolean;\n /** Per-instance override of `dangerConfirm.password`. */\n labels?: Partial<CurrentPasswordInputLabels>;\n}\n\n/**\n * The \"prove it is you\" field: a password input that a password manager fills with\n * the CURRENT password and never offers to generate a new one for.\n *\n * It is the field of a sign-in form, a re-auth step ({@link ReauthDialog} draws the same\n * field), and {@link DangerConfirm}'s `requirePassword`. Public since 0.22 for kastlan's\n * sign-in and re-auth (kastlan 1), which wrote `type=\"password\"` +\n * `autoComplete=\"current-password\"` by hand — and a sign-in field that forgets the\n * second half gets the browser's \"suggest a strong password\" offer on the one form where\n * a NEW password is never what is wanted. The reverse matters as much: a field that sets\n * a NEW password (a passphrase, a sign-up) must NOT be this one — keksdose #170 keeps\n * its passphrase doors on `new-password` / `off` for that reason.\n *\n * Everything else is {@link Input}: the reveal toggle, `error` (under the field,\n * `aria-describedby`, `aria-invalid`), `invalid`, `name`, `id`, `autoFocus`, `required`.\n * The ref is the `<input>`, so it works with `@eifi1/ui-kit/rhf`'s `FormControl` /\n * a `register()` spread, and controlled or uncontrolled.\n *\n * ```tsx\n * <CurrentPasswordInput name=\"password\" label={t(\"password\")} error={errors.password?.message}\n * busy={isSubmitting} {...register(\"password\")} />\n * ```\n */\nexport const CurrentPasswordInput = forwardRef<HTMLInputElement, CurrentPasswordInputProps>(\n function CurrentPasswordInput({ label, onValueChange, onChange, busy, readOnly, labels: labelsProp, ...rest }, ref) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const namedOtherwise = rest[\"aria-label\"] !== undefined || rest[\"aria-labelledby\"] !== undefined;\n return (\n <Input\n {...rest}\n ref={ref}\n // After the spread: a props object spread at the field must not turn it into a\n // text field, or into one the password manager offers a new password for.\n type=\"password\"\n autoComplete=\"current-password\"\n label={label === undefined ? (namedOtherwise ? undefined : labels.password) : hasContent(label) ? label : undefined}\n readOnly={Boolean(busy) || readOnly}\n onChange={(e) => {\n onChange?.(e);\n onValueChange?.(e.target.value);\n }}\n />\n );\n },\n);\nCurrentPasswordInput.displayName = \"CurrentPasswordInput\";\n\n/** The words {@link TypedConfirmField} says on its own behalf — the `dangerConfirm`\n * namespace's `phrase` and `phrasePlaceholder`, shared with DangerConfirm's own field,\n * so the sentence \"Type “X” to confirm\" is translated once. */\nexport type TypedConfirmFieldLabels = Pick<DangerConfirmLabels, \"phrase\" | \"phrasePlaceholder\">;\n\nexport interface TypedConfirmFieldProps\n extends Omit<InputProps, \"type\" | \"value\" | \"defaultValue\" | \"label\" | \"placeholder\"> {\n /** The text to repeat — a word (\"DELETE\"), a name, an e-mail address. */\n target: string;\n /** How the typed text is compared with `target` — {@link TypedMatch}. Default\n * `\"trim\"`, as {@link typedMatches}; `\"caseless\"` for an address or an\n * acknowledgement word a user may type in any case. */\n match?: TypedMatch;\n /** Controlled value. Left out, the field keeps its own (start: `defaultValue`). */\n value?: string;\n defaultValue?: string;\n /** The typed text as a string, on every keystroke. Fires alongside `onChange`. */\n onValueChange?: (value: string) => void;\n /**\n * The typed text started or stopped matching `target` — fired from the keystroke\n * that flipped it, so an uncontrolled field can still drive the button it guards. A\n * controlled caller that resets the value itself (on a close) knows the answer\n * already, and gets no call for that; it can also compute it with {@link typedMatches}.\n */\n onMatchedChange?: (matched: boolean) => void;\n /** The label. Default `dangerConfirm.phrase(target)` — \"Type “DELETE” to confirm\". */\n label?: ReactNode;\n /** Text inside the empty field. Default `dangerConfirm.phrasePlaceholder` (unset).\n * Given, the label moves ABOVE the field: a floating label occupies the empty\n * field, which is exactly where a placeholder shows. `\"\"` means none. */\n placeholder?: string;\n /** The guarded action is running: the field turns `readOnly` (not `disabled`, which\n * would drop the focus Enter left in it). */\n busy?: boolean;\n labels?: Partial<TypedConfirmFieldLabels>;\n}\n\n/**\n * The \"type this to confirm\" field — {@link DangerConfirm}'s `phrase` field and\n * `useConfirm({ requireTyped })`'s, on its own (keksdose K7).\n *\n * keksdose writes it by hand four times: the privacy enrol, upgrade and sweep dialogs\n * (type the acknowledgement word, then the key doors appear) and the admin's \"type the\n * user's address\" (`UserActionConfirm`), each an `Input` plus its own\n * `trim().toUpperCase()` / `toLowerCase()` comparison. None of those places is an\n * arm → confirm tile or a modal confirm — what is guarded is a whole form, or the\n * next step of a dialog — so the field had to stand alone. What it brings over a plain\n * `Input`: one match rule ({@link typedMatches}, which lower-cases locale-independently\n * on purpose), the label worded from the target in the app's language, and the\n * attributes a phone keyboard needs to leave the text alone (no autocomplete, no\n * auto-capital, no autocorrect, no spellcheck — a keyboard that \"corrects\" an e-mail\n * address makes the guard unpassable).\n *\n * The field reports whether it matches (`onMatchedChange`, and `data-matched` on the\n * `<input>` for styling); what the match unlocks is the caller's. The ref is the\n * `<input>`.\n *\n * ```tsx\n * const [ok, setOk] = useState(false);\n * <TypedConfirmField target={t(\"privacy.enroll_ack_word\")} match=\"caseless\" onMatchedChange={setOk} />\n * {ok && <KeyDoorsForm … />}\n * ```\n */\nexport const TypedConfirmField = forwardRef<HTMLInputElement, TypedConfirmFieldProps>(function TypedConfirmField(\n {\n target,\n match = \"trim\",\n value: valueProp,\n defaultValue = \"\",\n onValueChange,\n onMatchedChange,\n onChange,\n label: labelProp,\n placeholder: placeholderProp,\n busy,\n readOnly,\n labels: labelsProp,\n id,\n className,\n ...rest\n },\n ref,\n) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const [own, setOwn] = useState(defaultValue);\n const value = valueProp ?? own;\n const matched = typedMatches(value, target, match);\n const generated = useId();\n const fieldId = id ?? generated;\n const label =\n labelProp !== undefined\n ? labelProp\n : typeof labels.phrase === \"function\"\n ? labels.phrase(target)\n : labels.phrase;\n const fromLabels =\n labels.phrasePlaceholder === undefined\n ? undefined\n : typeof labels.phrasePlaceholder === \"function\"\n ? labels.phrasePlaceholder(target)\n : labels.phrasePlaceholder;\n const placeholder = placeholderProp ?? fromLabels;\n\n const fieldProps = {\n ...rest,\n ref,\n id: fieldId,\n value,\n autoComplete: \"off\",\n autoCapitalize: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n readOnly: Boolean(busy) || readOnly,\n \"data-matched\": matched || undefined,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n const next = e.target.value;\n if (valueProp === undefined) setOwn(next);\n onValueChange?.(next);\n const nextMatched = typedMatches(next, target, match);\n if (nextMatched !== matched) onMatchedChange?.(nextMatched);\n },\n };\n\n if (placeholder) {\n return (\n // A static label above, so the placeholder has the empty field to itself.\n <div className={cn(\"space-y-1.5\", className)}>\n <Label htmlFor={fieldId}>{label}</Label>\n <Input {...fieldProps} placeholder={placeholder} />\n </div>\n );\n }\n return <Input {...fieldProps} label={label} className={className} />;\n});\nTypedConfirmField.displayName = \"TypedConfirmField\";\n\n/**\n * Every string the tile renders — the `dangerConfirm` namespace of\n * `<UiKitProvider labels>`, overridable per instance through `labels`. The arm and\n * confirm buttons are usually worded per action (\"Delete budget\"), which is what the\n * `armLabel` / `confirmLabel` props are for; these are the fallbacks.\n */\nexport interface DangerConfirmLabels {\n /** The button that arms the tile. */\n arm: string;\n /** The button that runs the action once the guards are satisfied. */\n confirm: string;\n cancel: string;\n /** The warning above the fields, when no `prompt` is given. */\n prompt: string;\n /** Label of the password field (`requirePassword`). */\n password: string;\n /** Label of the type-to-confirm field. A FUNCTION of the phrase by default, like\n * every message that carries a value: where the phrase sits in the sentence moves\n * with the language. A plain STRING is taken as the finished label — for an app\n * whose catalogue already words it (\"Type DELETE to confirm\") and would otherwise\n * wrap it as `() => label`. */\n phrase: string | ((phrase: string) => string);\n /** Placeholder of the type-to-confirm field — a string, or a function of the\n * phrase (`(p) => p` echoes it). Optional and unset by default: the field keeps its\n * floating label, as before. Given, the label moves ABOVE the field (a floating\n * label occupies the empty field, which is exactly where a placeholder shows) and\n * the placeholder fills the field. An empty string means none. */\n phrasePlaceholder?: string | ((phrase: string) => string);\n /** 0.22: the checkbox `requireAcknowledge={true}` shows — \"I have read what this does\n * and want to continue\" (keksdose's `admin.users.confirm_ack`). */\n acknowledge: string;\n /**\n * 0.23: why the armed confirm is held while the typed phrase does not match yet — in\n * the confirm's tooltip and its description (keksdose G4a). A FUNCTION of the phrase\n * by default (\"Type “DELETE” to confirm\"), or a finished STRING, as `phrase`.\n */\n needsPhrase: string | ((phrase: string) => string);\n /** 0.23: why the armed confirm is held while the `requireAcknowledge` box is unticked\n * — \"Tick the box to confirm\". */\n needsAcknowledge: string;\n /** 0.23: why the armed confirm is held while the `requirePassword` field is empty —\n * \"Enter your password to confirm\". */\n needsPassword: string;\n}\n\n/** `satisfies` rather than a type annotation, so `DEFAULT_DANGER_CONFIRM_LABELS.phrase`\n * stays callable for a caller that composes its own label from it. */\nexport const DEFAULT_DANGER_CONFIRM_LABELS = {\n arm: \"Delete…\",\n confirm: \"Delete\",\n cancel: \"Cancel\",\n prompt: \"This cannot be undone.\",\n password: \"Password\",\n phrase: (phrase: string) => `Type “${phrase}” to confirm`,\n acknowledge: \"I have read what this does and want to continue.\",\n needsPhrase: (phrase: string) => `Type “${phrase}” to confirm`,\n needsAcknowledge: \"Tick the box to confirm\",\n needsPassword: \"Enter your password to confirm\",\n} satisfies DangerConfirmLabels;\n\n/**\n * What the guards were answered with — the second argument of\n * {@link DangerConfirmProps.onConfirm} (0.23, keksdose G4b). A key is there only when its\n * guard was asked for, so the object can go into a request body as it is.\n */\nexport interface DangerConfirmValues {\n /**\n * The text typed into the `phrase` field — as the match rule compared it: trimmed\n * under `phraseMatch` `\"trim\"` and `\"caseless\"` (the spaces a phone keyboard adds are\n * not part of it), exactly as typed under `\"exact\"`. The case is the user's, even\n * under `\"caseless\"`: a server that re-checks applies its own rule to it. Absent\n * without a `phrase`.\n */\n typed?: string;\n /** The entered password — the same value as the first argument. Absent without\n * `requirePassword`. */\n password?: string;\n /** `true` when the `requireAcknowledge` box was shown — it was ticked, since the\n * confirm is held until it is. Absent without one. */\n acknowledged?: true;\n}\n\n/**\n * One line of {@link DangerConfirmProps.consequences}: what the action will do. A plain\n * string, or this, for a key of its own and the `severe` mark.\n */\nexport interface DangerConsequence {\n /** React key — keksdose keys its lines by what they say (\"api_tokens\", \"only_door\").\n * Default: the text when it is a string, else the position. */\n key?: string;\n text: ReactNode;\n /** \"There is no way back\" — painted in the danger colour rather than the list's\n * muted one. keksdose reserves it for the one line that loses something for good. */\n severe?: boolean;\n}\n\nexport interface DangerConfirmProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /**\n * Runs the action, with the entered password when `requirePassword` is on.\n *\n * Return a promise and the tile manages itself: busy until it settles, disarmed\n * (fields wiped) when it resolves, still armed when it rejects — so the user can\n * correct a wrong password and retry. The rejection is not swallowed for you to\n * miss: handle it (and show why) in the caller, as with any mutation.\n *\n * 0.23: the second argument is what every guard was answered with — the typed phrase,\n * the password, the tick ({@link DangerConfirmValues}). keksdose G4b: its admin\n * actions send the address the admin TYPED, and the server re-checks it against the\n * account (`assert_confirmed`), so a client that put the wrong row's id in the request\n * is refused rather than obeyed; the tile kept the text to itself.\n *\n * onConfirm={(_password, { typed }) =>\n * reset.mutateAsync({ id, confirm: { acknowledged: true, confirm_email: typed ?? null } })}\n *\n * A second argument rather than one object in place of the password: every\n * `(password) => …` and `() => …` handler, and a `mutation.mutate` passed as it is,\n * keeps working unchanged, and a handler that needs one guard's answer names it.\n */\n onConfirm: (password: string | undefined, values: DangerConfirmValues) => void | Promise<unknown>;\n /** Show a password field; confirm is held until it is filled. */\n requirePassword?: boolean;\n /**\n * Show an \"I understand\" checkbox; confirm is held until it is ticked\n * (keksdose K7). `true` words it with `labels.acknowledge`; any other node IS the\n * checkbox's label (\"I understand Anna will be signed out everywhere\").\n *\n * The guard for an action whose risk is MIS-TARGETING less than carelessness:\n * keksdose's admin password reset asks for a typed address when the account has an\n * encrypted door to lose, and a tick otherwise (`UserActionConfirm`), and its plan\n * editor asks for the tick alone (`UserPlanEditor`). Both were hand-built beside this\n * tile because it had no tick. It combines with `phrase` and `requirePassword`: every\n * guard given must be satisfied.\n */\n requireAcknowledge?: ReactNode;\n /**\n * What the action will do, said before it happens — a list under the prompt, shown\n * once armed (keksdose K7, `UserActionConfirm`'s consequences). Strings, or\n * {@link DangerConsequence}s for a `severe` line in the danger colour.\n *\n * Derive them from the row's own facts rather than reciting the worst case: an admin\n * who reads the same paragraph on every row stops reading it (keksdose dev#488).\n */\n consequences?: readonly (string | DangerConsequence)[];\n /** Show a \"type <phrase> to confirm\" field; confirm is held until the field matches\n * (case-sensitive; surrounding spaces ignored unless `phraseMatch=\"exact\"`). */\n phrase?: string;\n /**\n * How the typed text is compared with `phrase`. `\"trim\"` (default) ignores spaces\n * around it — a phone keyboard's autocomplete likes to add one. `\"exact\"` compares\n * character for character, spaces included, for an app whose contract is \"type\n * exactly this\". `\"caseless\"` (0.18) also ignores case — for a phrase that is an\n * e-mail address (keksdose's \"type the user's address\" admin rule). See\n * {@link TypedMatch}.\n */\n phraseMatch?: TypedMatch;\n /** The warning above the fields. Defaults to `labels.prompt`. */\n prompt?: ReactNode;\n /** `\"danger\"` (default) for what cannot be undone; `\"warning\"` for what can, at a\n * cost (loading demo data over your own). Colours the prompt and the confirm. */\n tone?: \"danger\" | \"warning\";\n /** Visible text of the arm button; defaults to `labels.arm`. */\n armLabel?: ReactNode;\n /** Visible text of the confirm button; defaults to `labels.confirm`. */\n confirmLabel?: ReactNode;\n /** The action is running: confirm shows a spinner and nothing can be pressed. For a\n * caller that tracks the mutation itself (a `useMutation`'s `isPending`); a\n * promise returned from `onConfirm` does the same on its own. */\n busy?: boolean;\n /** The arm button is disabled. */\n disabled?: boolean;\n /**\n * Why the action is not available — a read-only demo, a write lock, a missing\n * permission. Disables the arm button like `disabled`, and SAYS so: the sentence is\n * shown under the button and attached to it with `aria-describedby`, and the button\n * stays focusable (`aria-disabled`) so a keyboard user can land on it and hear why.\n *\n * On the ARM button rather than the confirm: arming asks for a password, and asking\n * for a password for a write that can never land is the worse of the two. A tile that\n * is ALREADY armed when the reason arrives (controlled `armed`, or a lock that landed\n * while it was open) keeps its fields but its confirm takes the reason the same way\n * — focusable, `aria-disabled`, the reason in its tooltip — and Enter does nothing.\n */\n lockedReason?: ReactNode;\n /**\n * This tile COMMITS — the 0.18 write-lock opt-in that {@link Button} has (keksdose\n * K3). Under a locked {@link WriteLockProvider} the lock's reason becomes\n * `lockedReason` (and wins over one of the tile's own), so a page that mounts the\n * provider no longer threads `lockedReason={lock.locked ? lock.reason : undefined}`\n * into every tile. No provider, or an unlocked one: no effect.\n */\n commit?: boolean;\n /** Controlled armed state. The parent can then collapse the tile from a mutation's\n * own `onSuccess` without returning a promise. */\n armed?: boolean;\n /** Called with the next armed state — on arm, cancel, and a resolved `onConfirm`. */\n onArmedChange?: (armed: boolean) => void;\n /** User-facing strings; see {@link DangerConfirmLabels}. */\n labels?: Partial<DangerConfirmLabels>;\n}\n\n/**\n * An \"arm → confirm\" tile for destructive actions: one button, which expands into a\n * warning, an optional list of consequences, an optional \"I understand\" tick, an\n * optional type-to-confirm field, an optional password field and a confirm that is held\n * until every guard is satisfied.\n *\n * A held confirm SAYS which guard is still open (0.23, keksdose G4a): it is\n * `aria-disabled` rather than `disabled` — still focusable, so a keyboard user can land\n * on it — with the reason in the kit {@link Tooltip} and its description (\"Type\n * “DELETE” to confirm\", \"Tick the box to confirm\", \"Enter your password to confirm\";\n * `labels.needs*`), the first open guard in the order they are drawn. FormActions'\n * `submitDisabledReason` does the same for a form's Save. Pressing it, or Enter in a\n * field, does nothing. A lock's reason wins over a guard's; while the action runs the\n * confirm is plainly disabled, its spinner saying why.\n *\n * Keksdose hand-rolled it three times (load demo data, wipe everything, reset a\n * budget) and then as `shared/components/danger-confirm.tsx`; the only app-specific\n * part was its write-lock hook, which is `lockedReason` here.\n *\n * The fields are a `<form>`, so Enter confirms once the guards allow it. They are\n * wiped every time the tile disarms — a password must not sit in a collapsed tile.\n * Arming moves focus to the first field (or Cancel, when there is none — never to the\n * destructive button itself), and disarming moves it back to the arm button, so the\n * keyboard user is never left on an element that just vanished.\n */\nexport function DangerConfirm({\n onConfirm,\n requirePassword,\n requireAcknowledge,\n consequences,\n phrase,\n phraseMatch = \"trim\",\n prompt,\n tone = \"danger\",\n armLabel,\n confirmLabel,\n busy: busyProp,\n disabled,\n lockedReason: ownLockedReason,\n commit,\n armed: armedProp,\n onArmedChange,\n labels: labelsProp,\n className,\n ...rest\n}: DangerConfirmProps) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const lockedReason = useCommitReason(commit, ownLockedReason);\n const [armedState, setArmedState] = useState(false);\n const armed = armedProp ?? armedState;\n const [password, setPassword] = useState(\"\");\n const [typed, setTyped] = useState(\"\");\n const [acknowledged, setAcknowledged] = useState(false);\n const { pending, run } = usePromisePending();\n const busy = Boolean(busyProp) || pending;\n // `readOnly` rather than `disabled` on the fields while busy: disabling the field\n // that has focus (Enter was pressed in it) drops focus to <body>.\n const promptId = useId();\n const consequencesId = useId();\n const reasonId = useId();\n\n // The kit's Button takes no ref, so the two buttons focus is moved to are found by id.\n const armId = useId();\n const cancelId = useId();\n const firstFieldRef = useRef<HTMLInputElement>(null);\n // Focus moves only after a transition — never on mount, so a tile that renders armed\n // (controlled) does not take the page's focus merely by existing.\n const moveFocus = useRef(false);\n\n // A disarm from anywhere (cancel, a resolved confirm, the parent) wipes the fields.\n // During render, like NumberField's draft, so no frame shows a collapsed tile that\n // still holds a password.\n const [wasArmed, setWasArmed] = useState(armed);\n if (wasArmed !== armed) {\n setWasArmed(armed);\n if (!armed) {\n setPassword(\"\");\n setTyped(\"\");\n setAcknowledged(false);\n }\n }\n\n const prevArmed = useRef(armed);\n useEffect(() => {\n const changed = prevArmed.current !== armed;\n prevArmed.current = armed;\n const byUser = moveFocus.current;\n moveFocus.current = false;\n if (!changed) return;\n if (armed) {\n if (byUser) (firstFieldRef.current ?? document.getElementById(cancelId))?.focus();\n return;\n }\n // A controlled parent collapsing the tile from its own `onSuccess` did not go\n // through `setArmed`; if focus went down with the form, bring it back too.\n const lost = document.activeElement === null || document.activeElement === document.body;\n if (byUser || lost) document.getElementById(armId)?.focus();\n }, [armed, armId, cancelId]);\n\n const setArmed = (next: boolean) => {\n moveFocus.current = true;\n if (armedProp === undefined) setArmedState(next);\n onArmedChange?.(next);\n };\n\n const locked = hasContent(lockedReason);\n // `true` words the tick with the namespace; any other node is its label; `false`,\n // `null` and `\"\"` are no tick at all.\n const acknowledgeLabel: ReactNode =\n requireAcknowledge === true ? labels.acknowledge : hasContent(requireAcknowledge) ? requireAcknowledge : null;\n const asksAcknowledge = acknowledgeLabel !== null;\n const passwordOk = !requirePassword || password !== \"\";\n const phraseOk = phrase === undefined || typedMatches(typed, phrase, phraseMatch);\n const acknowledgeOk = !asksAcknowledge || acknowledged;\n const canConfirm = passwordOk && phraseOk && acknowledgeOk && !busy;\n // The first guard still open, in the order the fields are drawn — the one the user\n // meets next, so the sentence points at it.\n const guardReason: string | undefined = !acknowledgeOk\n ? labels.needsAcknowledge\n : !phraseOk\n ? typeof labels.needsPhrase === \"function\"\n ? labels.needsPhrase(phrase ?? \"\")\n : labels.needsPhrase\n : !passwordOk\n ? labels.needsPassword\n : undefined;\n // The lock first (no guard can lift it); none while busy, when the guards were met and\n // the spinner is the state.\n const confirmReason: ReactNode = locked ? lockedReason : busy ? undefined : guardReason;\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n // `locked` too: Enter in a field submits the form without the button's say.\n if (!canConfirm || locked) return;\n const values: DangerConfirmValues = {\n ...(phrase !== undefined && { typed: phraseMatch === \"exact\" ? typed : typed.trim() }),\n ...(requirePassword && { password }),\n ...(asksAcknowledge && { acknowledged: true as const }),\n };\n // Disarms when it resolves; a rejection leaves it armed, fields kept: the caller\n // shows why, the user retries.\n run(onConfirm(values.password, values), () => setArmed(false));\n };\n\n // The first field takes focus on arm: the tick, then the phrase, then the password —\n // the order they are drawn in.\n const firstField = asksAcknowledge ? \"acknowledge\" : phrase !== undefined ? \"phrase\" : \"password\";\n const lines = (consequences ?? []).map((item, index) =>\n typeof item === \"string\"\n ? { key: item, text: item as ReactNode, severe: false }\n : { key: item.key ?? String(index), text: item.text, severe: Boolean(item.severe) },\n );\n\n const toneText = tone === \"warning\" ? \"text-[var(--warning)]\" : \"text-[var(--danger)]\";\n\n if (!armed) {\n const arm = (\n <Button\n id={armId}\n type=\"button\"\n variant={tone === \"warning\" ? \"secondary\" : \"danger\"}\n disabled={disabled}\n aria-disabled={locked || undefined}\n aria-describedby={locked ? reasonId : undefined}\n onClick={() => {\n if (!locked) setArmed(true);\n }}\n className=\"aria-disabled:cursor-not-allowed aria-disabled:opacity-50\"\n >\n {armLabel ?? labels.arm}\n </Button>\n );\n return (\n <div {...rest} className={cn(\"space-y-1\", className)}>\n {locked ? (\n // The reason on the button itself too, where the pointer that tried it is —\n // the line below can sit out of view in a long settings card. Portalled, so\n // a card that scrolls neither clips it nor grows by it.\n //\n // The button in a FRAGMENT on purpose: Tooltip clones an element child to\n // add the bubble to its `aria-describedby`, and the button is already\n // described by the visible line below — the same sentence twice, read out\n // on every focus. A fragment is left as it is, so the bubble stays visual.\n <Tooltip label={lockedReason} portal>\n <>{arm}</>\n </Tooltip>\n ) : (\n arm\n )}\n {locked && (\n <p id={reasonId} className=\"text-xs text-[var(--text-muted)]\">\n {lockedReason}\n </p>\n )}\n </div>\n );\n }\n\n return (\n <div {...rest} className={cn(\"space-y-2\", className)}>\n <form\n className=\"space-y-2\"\n aria-describedby={lines.length > 0 ? `${promptId} ${consequencesId}` : promptId}\n aria-busy={busy || undefined}\n onSubmit={submit}\n noValidate\n >\n <p id={promptId} className={cn(\"text-xs font-medium\", toneText)}>\n {prompt ?? labels.prompt}\n </p>\n {lines.length > 0 && (\n <ul id={consequencesId} className=\"list-disc space-y-1 ps-5 text-xs text-[var(--text-secondary)]\">\n {lines.map((line) => (\n <li key={line.key} className={line.severe ? \"text-[var(--danger)]\" : undefined}>\n {line.text}\n </li>\n ))}\n </ul>\n )}\n {asksAcknowledge && (\n <Checkbox\n ref={firstField === \"acknowledge\" ? firstFieldRef : undefined}\n label={acknowledgeLabel}\n checked={acknowledged}\n // Not `disabled` while busy, for the same reason the fields are readOnly:\n // the box may hold the focus. A change while busy is simply not taken.\n onCheckedChange={(next) => {\n if (!busy) setAcknowledged(next);\n }}\n />\n )}\n {phrase !== undefined && (\n <TypedConfirmField\n ref={firstField === \"phrase\" ? firstFieldRef : undefined}\n target={phrase}\n match={phraseMatch}\n value={typed}\n onValueChange={setTyped}\n busy={busy}\n // Already resolved through this tile's own `labels` prop; handed on so a\n // per-instance phrase wording reaches the field.\n labels={{ phrase: labels.phrase, phrasePlaceholder: labels.phrasePlaceholder }}\n />\n )}\n {requirePassword && (\n <CurrentPasswordInput\n ref={firstField === \"password\" ? firstFieldRef : undefined}\n label={labels.password}\n value={password}\n busy={busy}\n onValueChange={setPassword}\n />\n )}\n <div className=\"flex flex-wrap gap-2\">\n <Button id={cancelId} type=\"button\" variant=\"ghost\" disabled={busy} onClick={() => setArmed(false)}>\n {labels.cancel}\n </Button>\n <Button\n type=\"submit\"\n variant={tone === \"warning\" ? \"primary\" : \"danger\"}\n disabled={!canConfirm}\n // Held by a guard, or armed and then locked (or rendered armed under a lock):\n // the confirm says why the way Button does — focusable, `aria-disabled`, the\n // reason in its tooltip and description, a press swallowed (the submit with\n // it) — and the fields stay as typed. Only busy is the native `disabled`.\n disabledReason={confirmReason}\n aria-busy={busy || undefined}\n >\n {busy && <Spinner label={null} className=\"h-4 w-4\" />}\n {confirmLabel ?? labels.confirm}\n </Button>\n </div>\n {locked && <p className=\"text-xs text-[var(--text-muted)]\">{lockedReason}</p>}\n </form>\n </div>\n );\n}\n"],"mappings":";AA2IM,SA4hBM,UA5hBN,KAkJA,YAlJA;AA3IN,SAAS,YAAY,aAAa,WAAW,OAAO,QAAQ,gBAAgB;AAE5E,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,OAAO,OAAO,eAAe;AAE9C,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAoBzB,SAAS,aAAa,OAAe,QAAgB,OAAmB,QAAiB;AAC9F,MAAI,SAAS,QAAS,QAAO,UAAU;AACvC,MAAI,SAAS,OAAQ,QAAO,MAAM,KAAK,MAAM;AAG7C,SAAO,MAAM,KAAK,EAAE,YAAY,MAAM,OAAO,KAAK,EAAE,YAAY;AAClE;AAWO,SAAS,oBAAoB;AAClC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,UAAU,OAAO,IAAI;AAC3B,YAAU,MAAM;AACd,YAAQ,UAAU;AAClB,WAAO,MAAM;AACX,cAAQ,UAAU;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,CAAC;AACL,QAAM,MAAM,YAAY,CAAC,QAAiB,eAAoC;AAC5E,QAAI,CAAC,UAAU,OAAQ,OAA4B,SAAS,WAAY,QAAO;AAC/E,eAAW,IAAI;AACf,IAAC,OAA4B;AAAA,MAC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AAAA,cAC1C,UAAU,CAAC;AAAA,cAKX,gBAAgB;AAAA,cAChB,aAAW,QAAQ;AAAA,cAElB;AAAA,wBAAQ,oBAAC,WAAQ,OAAO,MAAM,WAAU,WAAU;AAAA,gBAClD,gBAAgB,OAAO;AAAA;AAAA;AAAA,UAC1B;AAAA,WACF;AAAA,QACC,UAAU,oBAAC,OAAE,WAAU,oCAAoC,wBAAa;AAAA;AAAA;AAAA,EAC3E,GACF;AAEJ;","names":["CurrentPasswordInput","TypedConfirmField"]}
1
+ {"version":3,"sources":["../../src/components/danger-confirm.tsx"],"sourcesContent":["import { Children, forwardRef, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithoutRef, FormEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels } from \"../i18n/kit-labels\";\nimport { Button, Input, Label, Spinner } from \"./ui\";\nimport type { ButtonVariant, InputProps } from \"./ui\";\nimport { Checkbox } from \"./checkbox\";\nimport { Tooltip } from \"./tooltip\";\nimport { useCommitReason } from \"./write-lock\";\n\n/**\n * How typed text is compared with the text it has to repeat — shared by\n * `DangerConfirm`'s `phraseMatch` and `useConfirm`'s `typedMatch`.\n *\n * - `\"trim\"` ignores spaces around the typed text — a phone keyboard's autocomplete\n * likes to add one. Case counts: \"delete\" is not \"DELETE\".\n * - `\"exact\"` compares character for character, spaces included.\n * - `\"caseless\"` trims AND ignores case: for an e-mail address, whose domain is\n * case-insensitive and whose local part every real mail server treats so. Both apps'\n * \"type the account's address\" rules (keksdose's `TYPE_EMAIL`, Kurvenschmiede's\n * `TypedConfirm`) compared `trim().toLowerCase()`, and a capital the user's keyboard\n * put at the start must not make the right row look like the wrong one.\n */\nexport type TypedMatch = \"trim\" | \"exact\" | \"caseless\";\n\n/** Whether `typed` repeats `target` under `mode` — see {@link TypedMatch}. Exported for\n * a caller that draws its own field (a dialog that also picks a recipient) and wants\n * the same rule as the kit's. */\nexport function typedMatches(typed: string, target: string, mode: TypedMatch = \"trim\"): boolean {\n if (mode === \"exact\") return typed === target;\n if (mode === \"trim\") return typed.trim() === target;\n // `toLowerCase`, not `toLocaleLowerCase`: the comparison must not change with the\n // reader's locale (a Turkish dotless i would otherwise fail an ASCII address).\n return typed.trim().toLowerCase() === target.trim().toLowerCase();\n}\n\n/**\n * Busy-while-a-promise-runs, for an action that MAY return one: `run(result, onResolved)`\n * marks the caller pending until `result` settles, calls `onResolved` if it fulfilled,\n * and only clears the flag if it rejected — the caller shows why and the user retries.\n * Nothing runs after unmount. Shared by `DangerConfirm` and `ReauthDialog`, whose\n * contract is the same: resolve = done, reject = stay put.\n *\n * @internal\n */\nexport function usePromisePending() {\n const [pending, setPending] = useState(false);\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n const run = useCallback((result: unknown, onResolved: () => void): boolean => {\n if (!result || typeof (result as Promise<unknown>).then !== \"function\") return false;\n setPending(true);\n (result as Promise<unknown>).then(\n () => {\n if (!mounted.current) return;\n setPending(false);\n onResolved();\n },\n () => {\n if (mounted.current) setPending(false);\n },\n );\n return true;\n }, []);\n return { pending, run };\n}\n\n/** A label that is really there — `null`, `false` and `\"\"` are what a caller's\n * `cond && reason` evaluates to on the path where there is none. */\nfunction hasContent(node: ReactNode): boolean {\n return node !== undefined && node !== null && node !== false && node !== \"\";\n}\n\n/** The one word {@link CurrentPasswordInput} says on its own behalf — the\n * `dangerConfirm.password` label, shared with DangerConfirm's password field, so an\n * app translates \"Password\" once. */\nexport type CurrentPasswordInputLabels = Pick<DangerConfirmLabels, \"password\">;\n\n/**\n * Everything {@link Input} takes except what makes this field what it is: `type` is\n * always `\"password\"` and `autoComplete` always `\"current-password\"`.\n */\nexport interface CurrentPasswordInputProps extends Omit<InputProps, \"type\" | \"autoComplete\" | \"label\"> {\n /**\n * The visible label. Default `dangerConfirm.password` (\"Password\") — unless the field\n * is named another way (`aria-label` / `aria-labelledby`), which then stays the only\n * name. Pass the app's own word on a sign-in form (\"Password\", \"Your password\"), or\n * `null` for a field whose `<label htmlFor>` is drawn elsewhere (a form library's\n * `FormLabel`), which would otherwise be labelled twice.\n */\n label?: ReactNode;\n /** The value as a string — the `(next) => …` shape, so a caller holding it in\n * `useState` need not unwrap `event.target.value`. Fires alongside `onChange`,\n * never instead of it, so a form library's `onChange` keeps working. */\n onValueChange?: (value: string) => void;\n /**\n * A check is running (the sign-in request, the re-auth). The field turns `readOnly`,\n * NOT `disabled`: the field being submitted is usually the focused one (Enter was\n * pressed in it), and disabling a focused field drops focus to `<body>` — the user\n * lands nowhere when the \"wrong password\" answer comes back.\n */\n busy?: boolean;\n /** Per-instance override of `dangerConfirm.password`. */\n labels?: Partial<CurrentPasswordInputLabels>;\n}\n\n/**\n * The \"prove it is you\" field: a password input that a password manager fills with\n * the CURRENT password and never offers to generate a new one for.\n *\n * It is the field of a sign-in form, a re-auth step ({@link ReauthDialog} draws the same\n * field), and {@link DangerConfirm}'s `requirePassword`. Public since 0.22 for kastlan's\n * sign-in and re-auth (kastlan 1), which wrote `type=\"password\"` +\n * `autoComplete=\"current-password\"` by hand — and a sign-in field that forgets the\n * second half gets the browser's \"suggest a strong password\" offer on the one form where\n * a NEW password is never what is wanted. The reverse matters as much: a field that sets\n * a NEW password (a passphrase, a sign-up) must NOT be this one — keksdose #170 keeps\n * its passphrase doors on `new-password` / `off` for that reason.\n *\n * Everything else is {@link Input}: the reveal toggle, `error` (under the field,\n * `aria-describedby`, `aria-invalid`), `invalid`, `name`, `id`, `autoFocus`, `required`.\n * The ref is the `<input>`, so it works with `@eifi1/ui-kit/rhf`'s `FormControl` /\n * a `register()` spread, and controlled or uncontrolled.\n *\n * ```tsx\n * <CurrentPasswordInput name=\"password\" label={t(\"password\")} error={errors.password?.message}\n * busy={isSubmitting} {...register(\"password\")} />\n * ```\n */\nexport const CurrentPasswordInput = forwardRef<HTMLInputElement, CurrentPasswordInputProps>(\n function CurrentPasswordInput({ label, onValueChange, onChange, busy, readOnly, labels: labelsProp, ...rest }, ref) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const namedOtherwise = rest[\"aria-label\"] !== undefined || rest[\"aria-labelledby\"] !== undefined;\n return (\n <Input\n {...rest}\n ref={ref}\n // After the spread: a props object spread at the field must not turn it into a\n // text field, or into one the password manager offers a new password for.\n type=\"password\"\n autoComplete=\"current-password\"\n label={label === undefined ? (namedOtherwise ? undefined : labels.password) : hasContent(label) ? label : undefined}\n readOnly={Boolean(busy) || readOnly}\n onChange={(e) => {\n onChange?.(e);\n onValueChange?.(e.target.value);\n }}\n />\n );\n },\n);\nCurrentPasswordInput.displayName = \"CurrentPasswordInput\";\n\n/** The words {@link TypedConfirmField} says on its own behalf — the `dangerConfirm`\n * namespace's `phrase` and `phrasePlaceholder`, shared with DangerConfirm's own field,\n * so the sentence \"Type “X” to confirm\" is translated once. */\nexport type TypedConfirmFieldLabels = Pick<DangerConfirmLabels, \"phrase\" | \"phrasePlaceholder\">;\n\nexport interface TypedConfirmFieldProps\n extends Omit<InputProps, \"type\" | \"value\" | \"defaultValue\" | \"label\" | \"placeholder\"> {\n /** The text to repeat — a word (\"DELETE\"), a name, an e-mail address. */\n target: string;\n /** How the typed text is compared with `target` — {@link TypedMatch}. Default\n * `\"trim\"`, as {@link typedMatches}; `\"caseless\"` for an address or an\n * acknowledgement word a user may type in any case. */\n match?: TypedMatch;\n /** Controlled value. Left out, the field keeps its own (start: `defaultValue`). */\n value?: string;\n defaultValue?: string;\n /** The typed text as a string, on every keystroke. Fires alongside `onChange`. */\n onValueChange?: (value: string) => void;\n /**\n * The typed text started or stopped matching `target` — fired from the keystroke\n * that flipped it, so an uncontrolled field can still drive the button it guards. A\n * controlled caller that resets the value itself (on a close) knows the answer\n * already, and gets no call for that; it can also compute it with {@link typedMatches}.\n */\n onMatchedChange?: (matched: boolean) => void;\n /** The label. Default `dangerConfirm.phrase(target)` — \"Type “DELETE” to confirm\". */\n label?: ReactNode;\n /** Text inside the empty field. Default `dangerConfirm.phrasePlaceholder` (unset).\n * Given, the label moves ABOVE the field: a floating label occupies the empty\n * field, which is exactly where a placeholder shows. `\"\"` means none. */\n placeholder?: string;\n /** The guarded action is running: the field turns `readOnly` (not `disabled`, which\n * would drop the focus Enter left in it). */\n busy?: boolean;\n labels?: Partial<TypedConfirmFieldLabels>;\n}\n\n/**\n * The \"type this to confirm\" field — {@link DangerConfirm}'s `phrase` field and\n * `useConfirm({ requireTyped })`'s, on its own (keksdose K7).\n *\n * keksdose writes it by hand four times: the privacy enrol, upgrade and sweep dialogs\n * (type the acknowledgement word, then the key doors appear) and the admin's \"type the\n * user's address\" (`UserActionConfirm`), each an `Input` plus its own\n * `trim().toUpperCase()` / `toLowerCase()` comparison. None of those places is an\n * arm → confirm tile or a modal confirm — what is guarded is a whole form, or the\n * next step of a dialog — so the field had to stand alone. What it brings over a plain\n * `Input`: one match rule ({@link typedMatches}, which lower-cases locale-independently\n * on purpose), the label worded from the target in the app's language, and the\n * attributes a phone keyboard needs to leave the text alone (no autocomplete, no\n * auto-capital, no autocorrect, no spellcheck — a keyboard that \"corrects\" an e-mail\n * address makes the guard unpassable).\n *\n * The field reports whether it matches (`onMatchedChange`, and `data-matched` on the\n * `<input>` for styling); what the match unlocks is the caller's. The ref is the\n * `<input>`.\n *\n * ```tsx\n * const [ok, setOk] = useState(false);\n * <TypedConfirmField target={t(\"privacy.enroll_ack_word\")} match=\"caseless\" onMatchedChange={setOk} />\n * {ok && <KeyDoorsForm … />}\n * ```\n */\nexport const TypedConfirmField = forwardRef<HTMLInputElement, TypedConfirmFieldProps>(function TypedConfirmField(\n {\n target,\n match = \"trim\",\n value: valueProp,\n defaultValue = \"\",\n onValueChange,\n onMatchedChange,\n onChange,\n label: labelProp,\n placeholder: placeholderProp,\n busy,\n readOnly,\n labels: labelsProp,\n id,\n className,\n ...rest\n },\n ref,\n) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const [own, setOwn] = useState(defaultValue);\n const value = valueProp ?? own;\n const matched = typedMatches(value, target, match);\n const generated = useId();\n const fieldId = id ?? generated;\n const label =\n labelProp !== undefined\n ? labelProp\n : typeof labels.phrase === \"function\"\n ? labels.phrase(target)\n : labels.phrase;\n const fromLabels =\n labels.phrasePlaceholder === undefined\n ? undefined\n : typeof labels.phrasePlaceholder === \"function\"\n ? labels.phrasePlaceholder(target)\n : labels.phrasePlaceholder;\n const placeholder = placeholderProp ?? fromLabels;\n\n const fieldProps = {\n ...rest,\n ref,\n id: fieldId,\n value,\n autoComplete: \"off\",\n autoCapitalize: \"off\",\n autoCorrect: \"off\",\n spellCheck: false,\n readOnly: Boolean(busy) || readOnly,\n \"data-matched\": matched || undefined,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(e);\n const next = e.target.value;\n if (valueProp === undefined) setOwn(next);\n onValueChange?.(next);\n const nextMatched = typedMatches(next, target, match);\n if (nextMatched !== matched) onMatchedChange?.(nextMatched);\n },\n };\n\n if (placeholder) {\n return (\n // A static label above, so the placeholder has the empty field to itself.\n <div className={cn(\"space-y-1.5\", className)}>\n <Label htmlFor={fieldId}>{label}</Label>\n <Input {...fieldProps} placeholder={placeholder} />\n </div>\n );\n }\n return <Input {...fieldProps} label={label} className={className} />;\n});\nTypedConfirmField.displayName = \"TypedConfirmField\";\n\n/**\n * Every string the tile renders — the `dangerConfirm` namespace of\n * `<UiKitProvider labels>`, overridable per instance through `labels`. The arm and\n * confirm buttons are usually worded per action (\"Delete budget\"), which is what the\n * `armLabel` / `confirmLabel` props are for; these are the fallbacks.\n */\nexport interface DangerConfirmLabels {\n /** The button that arms the tile. */\n arm: string;\n /** The button that runs the action once the guards are satisfied. */\n confirm: string;\n cancel: string;\n /** The warning above the fields, when no `prompt` is given. */\n prompt: string;\n /** Label of the password field (`requirePassword`). */\n password: string;\n /** Label of the type-to-confirm field. A FUNCTION of the phrase by default, like\n * every message that carries a value: where the phrase sits in the sentence moves\n * with the language. A plain STRING is taken as the finished label — for an app\n * whose catalogue already words it (\"Type DELETE to confirm\") and would otherwise\n * wrap it as `() => label`. */\n phrase: string | ((phrase: string) => string);\n /** Placeholder of the type-to-confirm field — a string, or a function of the\n * phrase (`(p) => p` echoes it). Optional and unset by default: the field keeps its\n * floating label, as before. Given, the label moves ABOVE the field (a floating\n * label occupies the empty field, which is exactly where a placeholder shows) and\n * the placeholder fills the field. An empty string means none. */\n phrasePlaceholder?: string | ((phrase: string) => string);\n /** 0.22: the checkbox `requireAcknowledge={true}` shows — \"I have read what this does\n * and want to continue\" (keksdose's `admin.users.confirm_ack`). */\n acknowledge: string;\n /**\n * 0.23: why the armed confirm is held while the typed phrase does not match yet — in\n * the confirm's tooltip and its description (keksdose G4a). A FUNCTION of the phrase\n * by default (\"Type “DELETE” to confirm\"), or a finished STRING, as `phrase`.\n */\n needsPhrase: string | ((phrase: string) => string);\n /** 0.23: why the armed confirm is held while the `requireAcknowledge` box is unticked\n * — \"Tick the box to confirm\". */\n needsAcknowledge: string;\n /** 0.23: why the armed confirm is held while the `requirePassword` field is empty —\n * \"Enter your password to confirm\". */\n needsPassword: string;\n}\n\n/** `satisfies` rather than a type annotation, so `DEFAULT_DANGER_CONFIRM_LABELS.phrase`\n * stays callable for a caller that composes its own label from it. */\nexport const DEFAULT_DANGER_CONFIRM_LABELS = {\n arm: \"Delete…\",\n confirm: \"Delete\",\n cancel: \"Cancel\",\n prompt: \"This cannot be undone.\",\n password: \"Password\",\n phrase: (phrase: string) => `Type “${phrase}” to confirm`,\n acknowledge: \"I have read what this does and want to continue.\",\n needsPhrase: (phrase: string) => `Type “${phrase}” to confirm`,\n needsAcknowledge: \"Tick the box to confirm\",\n needsPassword: \"Enter your password to confirm\",\n} satisfies DangerConfirmLabels;\n\n/**\n * What the guards were answered with — the second argument of\n * {@link DangerConfirmProps.onConfirm} (0.23, keksdose G4b). A key is there only when its\n * guard was asked for, so the object can go into a request body as it is.\n */\nexport interface DangerConfirmValues {\n /**\n * The text typed into the `phrase` field — as the match rule compared it: trimmed\n * under `phraseMatch` `\"trim\"` and `\"caseless\"` (the spaces a phone keyboard adds are\n * not part of it), exactly as typed under `\"exact\"`. The case is the user's, even\n * under `\"caseless\"`: a server that re-checks applies its own rule to it. Absent\n * without a `phrase`.\n */\n typed?: string;\n /** The entered password — the same value as the first argument. Absent without\n * `requirePassword`. */\n password?: string;\n /** `true` when the `requireAcknowledge` box was shown — it was ticked, since the\n * confirm is held until it is. Absent without one. */\n acknowledged?: true;\n}\n\n/**\n * One line of {@link DangerConfirmProps.consequences}: what the action will do. A plain\n * string, or this, for a key of its own and the `severe` mark.\n */\nexport interface DangerConsequence {\n /** React key — keksdose keys its lines by what they say (\"api_tokens\", \"only_door\").\n * Default: the text when it is a string, else the position. */\n key?: string;\n text: ReactNode;\n /** \"There is no way back\" — painted in the danger colour rather than the list's\n * muted one. keksdose reserves it for the one line that loses something for good. */\n severe?: boolean;\n}\n\nexport interface DangerConfirmProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /**\n * Runs the action, with the entered password when `requirePassword` is on.\n *\n * Return a promise and the tile manages itself: busy until it settles, disarmed\n * (fields wiped) when it resolves, still armed when it rejects — so the user can\n * correct a wrong password and retry. The rejection is not swallowed for you to\n * miss: handle it (and show why) in the caller, as with any mutation.\n *\n * 0.23: the second argument is what every guard was answered with — the typed phrase,\n * the password, the tick ({@link DangerConfirmValues}). keksdose G4b: its admin\n * actions send the address the admin TYPED, and the server re-checks it against the\n * account (`assert_confirmed`), so a client that put the wrong row's id in the request\n * is refused rather than obeyed; the tile kept the text to itself.\n *\n * onConfirm={(_password, { typed }) =>\n * reset.mutateAsync({ id, confirm: { acknowledged: true, confirm_email: typed ?? null } })}\n *\n * A second argument rather than one object in place of the password: every\n * `(password) => …` and `() => …` handler, and a `mutation.mutate` passed as it is,\n * keeps working unchanged, and a handler that needs one guard's answer names it.\n */\n onConfirm: (password: string | undefined, values: DangerConfirmValues) => void | Promise<unknown>;\n /** Show a password field; confirm is held until it is filled. */\n requirePassword?: boolean;\n /**\n * Show an \"I understand\" checkbox; confirm is held until it is ticked\n * (keksdose K7). `true` words it with `labels.acknowledge`; any other node IS the\n * checkbox's label (\"I understand Anna will be signed out everywhere\").\n *\n * The guard for an action whose risk is MIS-TARGETING less than carelessness:\n * keksdose's admin password reset asks for a typed address when the account has an\n * encrypted door to lose, and a tick otherwise (`UserActionConfirm`), and its plan\n * editor asks for the tick alone (`UserPlanEditor`). Both were hand-built beside this\n * tile because it had no tick. It combines with `phrase` and `requirePassword`: every\n * guard given must be satisfied.\n */\n requireAcknowledge?: ReactNode;\n /**\n * What the action will do, said before it happens — a list under the prompt, shown\n * once armed (keksdose K7, `UserActionConfirm`'s consequences). Strings, or\n * {@link DangerConsequence}s for a `severe` line in the danger colour.\n *\n * Derive them from the row's own facts rather than reciting the worst case: an admin\n * who reads the same paragraph on every row stops reading it (keksdose dev#488).\n */\n consequences?: readonly (string | DangerConsequence)[];\n /** Show a \"type <phrase> to confirm\" field; confirm is held until the field matches\n * (case-sensitive; surrounding spaces ignored unless `phraseMatch=\"exact\"`). */\n phrase?: string;\n /**\n * How the typed text is compared with `phrase`. `\"trim\"` (default) ignores spaces\n * around it — a phone keyboard's autocomplete likes to add one. `\"exact\"` compares\n * character for character, spaces included, for an app whose contract is \"type\n * exactly this\". `\"caseless\"` (0.18) also ignores case — for a phrase that is an\n * e-mail address (keksdose's \"type the user's address\" admin rule). See\n * {@link TypedMatch}.\n */\n phraseMatch?: TypedMatch;\n /** The warning above the fields. Defaults to `labels.prompt`. */\n prompt?: ReactNode;\n /** `\"danger\"` (default) for what cannot be undone; `\"warning\"` for what can, at a\n * cost (loading demo data over your own). Colours the prompt, and picks the arm\n * button's variant and — unless {@link DangerConfirmProps.confirmVariant} is\n * given — the confirm's. */\n tone?: \"danger\" | \"warning\";\n /**\n * The confirm button's variant, apart from `tone` (0.24, keksdose). Default: what\n * `tone` picks, as before — `\"danger\"` for `\"danger\"`, `\"primary\"` for `\"warning\"`.\n *\n * `tone` says how bad the outcome is; this says how loud the last press is, and the two\n * need not agree. keksdose's `UserActionConfirm` (an admin resets somebody else's\n * password) asks an AMBER question — what it guards against is mis-targeting, not data\n * loss, so the danger colour stays its one `severe` consequence's — and ends in a RED\n * Go, as its hand-built panel did before it moved onto this tile in 0.23; with only\n * `tone`, the amber question made Go the neutral primary fill. `tone=\"warning\"\n * confirmVariant=\"danger\"` is that panel again.\n */\n confirmVariant?: ButtonVariant;\n /**\n * Hold the armed confirm for a reason of the CALLER's own (0.24, keksdose) — the\n * tile's counterpart of FormActions' `submitDisabledReason`. While it has content the\n * confirm is held exactly as by the built-in guards: `aria-disabled` but focusable,\n * the reason in the kit {@link Tooltip} and its description, a press — or Enter in a\n * field — does nothing. Nothing else changes: the arm button stays usable, and no\n * line is printed under the buttons.\n *\n * keksdose's `UserPlanEditor` (\"move this account onto another plan\") must not confirm\n * the plan the account already holds — the request would only write FREE → FREE into\n * the audit trail. With no guard of its own to give, it passed \"Pick a different plan\"\n * as `lockedReason`, which is a LOCK: documented as \"the action is not available\",\n * spelled out under the buttons as well as in the tooltip, and meant for a write the\n * user cannot make land. A guard the user lifts by changing a field is this prop.\n *\n * Which reason the held confirm names: a write lock's first (`lockedReason`, `commit`\n * — nothing in the tile lifts it), then this one, then the built-in guards in the\n * order they are drawn (the tick, the phrase, the password). This one before the\n * built-ins because it is usually about a field in\n * {@link DangerConfirmProps.children}, which is drawn ABOVE them — the rule since 0.23\n * is \"the first open guard in the order the user meets it\" — and because it is about\n * WHAT is being confirmed (which plan), which has to be settled before acknowledging\n * it means anything. It is also the order keksdose's plan editor had, its\n * `lockedReason` winning over the tick.\n */\n confirmDisabledReason?: ReactNode;\n /**\n * Fields of the caller's own, drawn INSIDE the armed tile (0.24, keksdose): after the\n * prompt and the consequences, before the tick, the typed phrase and the password —\n * the order is \"what this does, what to do it with, then prove you mean it\". Nothing\n * is drawn for them while the tile is disarmed, and nothing at all without them, so a\n * tile without children is laid out exactly as before.\n *\n * keksdose's `UserPlanEditor` asks WHICH plan before it asks for the tick; with no\n * place inside the tile for the picker, the `Select` sat above it, and the tile's\n * prompt — the panel's title by rights — became the \"FREE → PRO\" line under the\n * picker. With the picker here, the prompt is the title again.\n *\n * The fields are the caller's: their values are not wiped on disarm (an uncontrolled\n * field starts over anyway — the slot unmounts), not passed to `onConfirm`, and a\n * guard on them is {@link DangerConfirmProps.confirmDisabledReason}. Arming moves\n * focus to their first form field (an input, a select, a combobox, a radio…), else to\n * the tile's own first field as before; Tab then goes on through the tick, the phrase\n * and the password to Cancel and the confirm. They sit inside the tile's `<form>`:\n * Enter in a text field confirms once every guard allows, and a {@link Button} among\n * them needs `type=\"button\"` — without one it SUBMITS the form, as a native button\n * does.\n */\n children?: ReactNode;\n /** Visible text of the arm button; defaults to `labels.arm`. */\n armLabel?: ReactNode;\n /** Visible text of the confirm button; defaults to `labels.confirm`. */\n confirmLabel?: ReactNode;\n /**\n * The action is running: confirm shows a spinner and nothing can be pressed — Cancel\n * included. For a caller that tracks the mutation itself (a `useMutation`'s\n * `isPending`); a promise returned from `onConfirm` does the same on its own.\n *\n * Cancel stays disabled ON PURPOSE, unlike FormActions' (keksdose asked in 0.24 why the\n * two differ). Once the request has left, nothing on the client can call it back —\n * not even an `AbortSignal`, which only stops the waiting, not the server — so a usable\n * Cancel could only collapse the tile while the action went on: \"Cancel\" pressed, and\n * the account reset anyway. Every way of settling what comes back is wrong somewhere: a\n * resolve after the Cancel did what the user called off; a reject finds the fields\n * wiped (a collapsed tile holds no password), so the 0.23 \"stay armed and retry\" is\n * gone; and re-arming while the first request runs is either a busy tile with empty\n * fields or — if the busy state went with the Cancel — a second destructive request\n * beside the first. FormActions' Cancel leaves an editor whose save is the user's own\n * edit landing, and a form can be edited again; the tile's action is the one that\n * cannot be undone, so it says nothing it cannot keep and waits — the wait is one\n * request long.\n *\n * When the action settles still armed (it failed) and the press on the confirm had\n * dropped the focus — a natively disabled button loses it — focus comes back to the\n * confirm, so a keyboard user can retry or Shift+Tab to the field to correct (0.24).\n */\n busy?: boolean;\n /** The arm button is disabled. */\n disabled?: boolean;\n /**\n * Why the action is not available — a read-only demo, a write lock, a missing\n * permission. Disables the arm button like `disabled`, and SAYS so: the sentence is\n * shown under the button and attached to it with `aria-describedby`, and the button\n * stays focusable (`aria-disabled`) so a keyboard user can land on it and hear why.\n *\n * On the ARM button rather than the confirm: arming asks for a password, and asking\n * for a password for a write that can never land is the worse of the two. A tile that\n * is ALREADY armed when the reason arrives (controlled `armed`, or a lock that landed\n * while it was open) keeps its fields but its confirm takes the reason the same way\n * — focusable, `aria-disabled`, the reason in its tooltip — and Enter does nothing.\n */\n lockedReason?: ReactNode;\n /**\n * This tile COMMITS — the 0.18 write-lock opt-in that {@link Button} has (keksdose\n * K3). Under a locked {@link WriteLockProvider} the lock's reason becomes\n * `lockedReason` (and wins over one of the tile's own), so a page that mounts the\n * provider no longer threads `lockedReason={lock.locked ? lock.reason : undefined}`\n * into every tile. No provider, or an unlocked one: no effect.\n */\n commit?: boolean;\n /** Controlled armed state. The parent can then collapse the tile from a mutation's\n * own `onSuccess` without returning a promise. */\n armed?: boolean;\n /** Called with the next armed state — on arm, cancel, and a resolved `onConfirm`. */\n onArmedChange?: (armed: boolean) => void;\n /** User-facing strings; see {@link DangerConfirmLabels}. */\n labels?: Partial<DangerConfirmLabels>;\n}\n\n/** What counts as a FIELD among the caller's `children` — what arming focuses. Not\n * any tabbable element: a \"see the plans\" link or a disclosure button before the\n * picker is not where the user starts. `[tabindex=\"-1\"]` is a roving radio group's\n * unselected option; the selected one (`0`) is the group's stop. */\nconst SLOT_FIELD = [\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n ...[\"combobox\", \"listbox\", \"radio\", \"checkbox\", \"switch\", \"slider\", \"spinbutton\", \"textbox\"].map(\n (role) => `[role=\"${role}\"]`,\n ),\n]\n .map((selector) => `${selector}:not(:disabled):not([tabindex=\"-1\"]):not([aria-hidden=\"true\"])`)\n .join(\", \");\n\n/** The first field among the caller's `children`, skipping a native radio that is not\n * the checked one of its group (Tab lands on the checked one). */\nfunction firstSlotField(slot: HTMLElement | null): HTMLElement | null {\n if (!slot) return null;\n for (const el of slot.querySelectorAll<HTMLElement>(SLOT_FIELD)) {\n if (el.closest(\"[hidden], [inert]\")) continue;\n if (el instanceof HTMLInputElement && el.type === \"radio\" && !el.checked && el.name) {\n const group = el.form?.elements.namedItem(el.name);\n const checked =\n group instanceof RadioNodeList && Array.from(group).some((r) => r instanceof HTMLInputElement && r.checked);\n if (checked) continue;\n }\n return el;\n }\n return null;\n}\n\n/**\n * An \"arm → confirm\" tile for destructive actions: one button, which expands into a\n * warning, an optional list of consequences, optional fields of the caller's own\n * (`children`, 0.24), an optional \"I understand\" tick, an optional type-to-confirm\n * field, an optional password field and a confirm that is held until every guard is\n * satisfied — the built-in ones, and the caller's `confirmDisabledReason` (0.24).\n *\n * A held confirm SAYS which guard is still open (0.23, keksdose G4a): it is\n * `aria-disabled` rather than `disabled` — still focusable, so a keyboard user can land\n * on it — with the reason in the kit {@link Tooltip} and its description (\"Type\n * “DELETE” to confirm\", \"Tick the box to confirm\", \"Enter your password to confirm\";\n * `labels.needs*`), the first open guard in the order they are drawn. FormActions'\n * `submitDisabledReason` does the same for a form's Save. Pressing it, or Enter in a\n * field, does nothing. A lock's reason wins over a guard's, the caller's guard over the\n * built-in ones; while the action runs the confirm is plainly disabled, its spinner\n * saying why — and so is Cancel, which cannot call back a request that has left (see\n * `busy`).\n *\n * Keksdose hand-rolled it three times (load demo data, wipe everything, reset a\n * budget) and then as `shared/components/danger-confirm.tsx`; the only app-specific\n * part was its write-lock hook, which is `lockedReason` here.\n *\n * The fields are a `<form>`, so Enter confirms once the guards allow it. They are\n * wiped every time the tile disarms — a password must not sit in a collapsed tile.\n * Arming moves focus to the first field (or Cancel, when there is none — never to the\n * destructive button itself), and disarming moves it back to the arm button, so the\n * keyboard user is never left on an element that just vanished.\n */\nexport function DangerConfirm({\n onConfirm,\n requirePassword,\n requireAcknowledge,\n consequences,\n phrase,\n phraseMatch = \"trim\",\n prompt,\n tone = \"danger\",\n confirmVariant,\n confirmDisabledReason,\n children,\n armLabel,\n confirmLabel,\n busy: busyProp,\n disabled,\n lockedReason: ownLockedReason,\n commit,\n armed: armedProp,\n onArmedChange,\n labels: labelsProp,\n className,\n ...rest\n}: DangerConfirmProps) {\n const labels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS, labelsProp);\n const lockedReason = useCommitReason(commit, ownLockedReason);\n const [armedState, setArmedState] = useState(false);\n const armed = armedProp ?? armedState;\n const [password, setPassword] = useState(\"\");\n const [typed, setTyped] = useState(\"\");\n const [acknowledged, setAcknowledged] = useState(false);\n const { pending, run } = usePromisePending();\n const busy = Boolean(busyProp) || pending;\n // `readOnly` rather than `disabled` on the fields while busy: disabling the field\n // that has focus (Enter was pressed in it) drops focus to <body>.\n const promptId = useId();\n const consequencesId = useId();\n const reasonId = useId();\n\n // The buttons focus is moved to are found by id.\n const armId = useId();\n const cancelId = useId();\n const confirmId = useId();\n const firstFieldRef = useRef<HTMLInputElement>(null);\n // The caller's fields (`children`), searched for their first form field on arm.\n const slotRef = useRef<HTMLDivElement>(null);\n // Focus moves only after a transition — never on mount, so a tile that renders armed\n // (controlled) does not take the page's focus merely by existing.\n const moveFocus = useRef(false);\n // A confirm from this tile is under way — see the focus return after a failure below.\n const confirmed = useRef(false);\n\n // A disarm from anywhere (cancel, a resolved confirm, the parent) wipes the fields.\n // During render, like NumberField's draft, so no frame shows a collapsed tile that\n // still holds a password.\n const [wasArmed, setWasArmed] = useState(armed);\n if (wasArmed !== armed) {\n setWasArmed(armed);\n if (!armed) {\n setPassword(\"\");\n setTyped(\"\");\n setAcknowledged(false);\n }\n }\n\n const prevArmed = useRef(armed);\n useEffect(() => {\n const changed = prevArmed.current !== armed;\n prevArmed.current = armed;\n const byUser = moveFocus.current;\n moveFocus.current = false;\n if (!changed) return;\n if (armed) {\n if (byUser) {\n // The caller's fields come first on the page, so first in focus too.\n (firstSlotField(slotRef.current) ?? firstFieldRef.current ?? document.getElementById(cancelId))?.focus();\n }\n return;\n }\n confirmed.current = false;\n // A controlled parent collapsing the tile from its own `onSuccess` did not go\n // through `setArmed`; if focus went down with the form, bring it back too.\n const lost = document.activeElement === null || document.activeElement === document.body;\n if (byUser || lost) document.getElementById(armId)?.focus();\n }, [armed, armId, cancelId]);\n\n // The action settled and the tile is still armed — it failed, and the user retries.\n // The confirm was natively disabled while it ran, and a focused button that turns\n // disabled drops the focus to <body>: bring it back to the button that was pressed.\n // Only after a confirm from THIS tile (`confirmed`), so a `busy` that comes and goes\n // on its own never pulls the page's focus in. (A resolve disarms, and the effect\n // above takes the focus to the arm button.)\n const wasBusy = useRef(busy);\n useEffect(() => {\n const settled = wasBusy.current && !busy;\n wasBusy.current = busy;\n if (!settled) return;\n const ours = confirmed.current;\n confirmed.current = false;\n if (!ours || !armed) return;\n if (document.activeElement === null || document.activeElement === document.body) {\n document.getElementById(confirmId)?.focus();\n }\n }, [busy, armed, confirmId]);\n\n const setArmed = (next: boolean) => {\n moveFocus.current = true;\n if (armedProp === undefined) setArmedState(next);\n onArmedChange?.(next);\n };\n\n const locked = hasContent(lockedReason);\n // `true` words the tick with the namespace; any other node is its label; `false`,\n // `null` and `\"\"` are no tick at all.\n const acknowledgeLabel: ReactNode =\n requireAcknowledge === true ? labels.acknowledge : hasContent(requireAcknowledge) ? requireAcknowledge : null;\n const asksAcknowledge = acknowledgeLabel !== null;\n const passwordOk = !requirePassword || password !== \"\";\n const phraseOk = phrase === undefined || typedMatches(typed, phrase, phraseMatch);\n const acknowledgeOk = !asksAcknowledge || acknowledged;\n const callerHeld = hasContent(confirmDisabledReason);\n // `{cond && <Select />}` and `[null, false]` are no fields: no wrapper, no gap.\n const hasFields = Children.toArray(children).some(hasContent);\n const canConfirm = passwordOk && phraseOk && acknowledgeOk && !callerHeld && !busy;\n // The first guard still open, in the order the fields are drawn — the one the user\n // meets next, so the sentence points at it.\n const guardReason: string | undefined = !acknowledgeOk\n ? labels.needsAcknowledge\n : !phraseOk\n ? typeof labels.needsPhrase === \"function\"\n ? labels.needsPhrase(phrase ?? \"\")\n : labels.needsPhrase\n : !passwordOk\n ? labels.needsPassword\n : undefined;\n // The lock first (no guard can lift it); none while busy, when the guards were met and\n // the spinner is the state; then the caller's guard — about the fields drawn above the\n // built-in ones, and about WHAT is confirmed — then the first built-in guard still open.\n const confirmReason: ReactNode = locked\n ? lockedReason\n : busy\n ? undefined\n : callerHeld\n ? confirmDisabledReason\n : guardReason;\n\n const submit = (e: FormEvent) => {\n e.preventDefault();\n // `locked` too: Enter in a field submits the form without the button's say (and\n // `canConfirm` holds the caller's guard the same way).\n if (!canConfirm || locked) return;\n const values: DangerConfirmValues = {\n ...(phrase !== undefined && { typed: phraseMatch === \"exact\" ? typed : typed.trim() }),\n ...(requirePassword && { password }),\n ...(asksAcknowledge && { acknowledged: true as const }),\n };\n confirmed.current = true;\n // Disarms when it resolves; a rejection leaves it armed, fields kept: the caller\n // shows why, the user retries.\n run(onConfirm(values.password, values), () => setArmed(false));\n };\n\n // The first field takes focus on arm: the tick, then the phrase, then the password —\n // the order they are drawn in.\n const firstField = asksAcknowledge ? \"acknowledge\" : phrase !== undefined ? \"phrase\" : \"password\";\n const lines = (consequences ?? []).map((item, index) =>\n typeof item === \"string\"\n ? { key: item, text: item as ReactNode, severe: false }\n : { key: item.key ?? String(index), text: item.text, severe: Boolean(item.severe) },\n );\n\n const toneText = tone === \"warning\" ? \"text-[var(--warning)]\" : \"text-[var(--danger)]\";\n\n if (!armed) {\n const arm = (\n <Button\n id={armId}\n type=\"button\"\n variant={tone === \"warning\" ? \"secondary\" : \"danger\"}\n disabled={disabled}\n aria-disabled={locked || undefined}\n aria-describedby={locked ? reasonId : undefined}\n onClick={() => {\n if (!locked) setArmed(true);\n }}\n className=\"aria-disabled:cursor-not-allowed aria-disabled:opacity-50\"\n >\n {armLabel ?? labels.arm}\n </Button>\n );\n return (\n <div {...rest} className={cn(\"space-y-1\", className)}>\n {locked ? (\n // The reason on the button itself too, where the pointer that tried it is —\n // the line below can sit out of view in a long settings card. Portalled, so\n // a card that scrolls neither clips it nor grows by it.\n //\n // The button in a FRAGMENT on purpose: Tooltip clones an element child to\n // add the bubble to its `aria-describedby`, and the button is already\n // described by the visible line below — the same sentence twice, read out\n // on every focus. A fragment is left as it is, so the bubble stays visual.\n <Tooltip label={lockedReason} portal>\n <>{arm}</>\n </Tooltip>\n ) : (\n arm\n )}\n {locked && (\n <p id={reasonId} className=\"text-xs text-[var(--text-muted)]\">\n {lockedReason}\n </p>\n )}\n </div>\n );\n }\n\n return (\n <div {...rest} className={cn(\"space-y-2\", className)}>\n <form\n className=\"space-y-2\"\n aria-describedby={lines.length > 0 ? `${promptId} ${consequencesId}` : promptId}\n aria-busy={busy || undefined}\n onSubmit={submit}\n noValidate\n >\n <p id={promptId} className={cn(\"text-xs font-medium\", toneText)}>\n {prompt ?? labels.prompt}\n </p>\n {lines.length > 0 && (\n <ul id={consequencesId} className=\"list-disc space-y-1 ps-5 text-xs text-[var(--text-secondary)]\">\n {lines.map((line) => (\n <li key={line.key} className={line.severe ? \"text-[var(--danger)]\" : undefined}>\n {line.text}\n </li>\n ))}\n </ul>\n )}\n {/* The caller's fields: after what the action does, before the proof that it is\n meant. No wrapper without them — a 0.23 tile's markup is unchanged. */}\n {hasFields && (\n <div ref={slotRef} className=\"space-y-2\">\n {children}\n </div>\n )}\n {asksAcknowledge && (\n <Checkbox\n ref={firstField === \"acknowledge\" ? firstFieldRef : undefined}\n label={acknowledgeLabel}\n checked={acknowledged}\n // Not `disabled` while busy, for the same reason the fields are readOnly:\n // the box may hold the focus. A change while busy is simply not taken.\n onCheckedChange={(next) => {\n if (!busy) setAcknowledged(next);\n }}\n />\n )}\n {phrase !== undefined && (\n <TypedConfirmField\n ref={firstField === \"phrase\" ? firstFieldRef : undefined}\n target={phrase}\n match={phraseMatch}\n value={typed}\n onValueChange={setTyped}\n busy={busy}\n // Already resolved through this tile's own `labels` prop; handed on so a\n // per-instance phrase wording reaches the field.\n labels={{ phrase: labels.phrase, phrasePlaceholder: labels.phrasePlaceholder }}\n />\n )}\n {requirePassword && (\n <CurrentPasswordInput\n ref={firstField === \"password\" ? firstFieldRef : undefined}\n label={labels.password}\n value={password}\n busy={busy}\n onValueChange={setPassword}\n />\n )}\n <div className=\"flex flex-wrap gap-2\">\n <Button id={cancelId} type=\"button\" variant=\"ghost\" disabled={busy} onClick={() => setArmed(false)}>\n {labels.cancel}\n </Button>\n <Button\n id={confirmId}\n type=\"submit\"\n variant={confirmVariant ?? (tone === \"warning\" ? \"primary\" : \"danger\")}\n disabled={!canConfirm}\n // Held by a guard (the caller's or a built-in one), or armed and then locked\n // (or rendered armed under a lock): the confirm says why the way Button\n // does — focusable, `aria-disabled`, the reason in its tooltip and\n // description, a press swallowed (the submit with it) — and the fields stay\n // as typed. Only busy is the native `disabled`.\n disabledReason={confirmReason}\n aria-busy={busy || undefined}\n >\n {busy && <Spinner label={null} className=\"h-4 w-4\" />}\n {confirmLabel ?? labels.confirm}\n </Button>\n </div>\n {locked && <p className=\"text-xs text-[var(--text-muted)]\">{lockedReason}</p>}\n </form>\n </div>\n );\n}\n"],"mappings":";AA2IM,SA8rBM,UA9rBN,KAkJA,YAlJA;AA3IN,SAAS,UAAU,YAAY,aAAa,WAAW,OAAO,QAAQ,gBAAgB;AAEtF,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,OAAO,OAAO,eAAe;AAE9C,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAoBzB,SAAS,aAAa,OAAe,QAAgB,OAAmB,QAAiB;AAC9F,MAAI,SAAS,QAAS,QAAO,UAAU;AACvC,MAAI,SAAS,OAAQ,QAAO,MAAM,KAAK,MAAM;AAG7C,SAAO,MAAM,KAAK,EAAE,YAAY,MAAM,OA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AK,eAAe,WAAW,gBAAgB;AAAA,YAC/C,QAAQ;AAAA,YACR,OAAO;AAAA,YACP,OAAO;AAAA,YACP,eAAe;AAAA,YACf;AAAA,YAGA,QAAQ,EAAE,QAAQ,OAAO,QAAQ,mBAAmB,OAAO,kBAAkB;AAAA;AAAA,QAC/E;AAAA,QAED,mBACC;AAAA,UAAC;AAAA;AAAA,YACC,KAAK,eAAe,aAAa,gBAAgB;AAAA,YACjD,OAAO,OAAO;AAAA,YACd,OAAO;AAAA,YACP;AAAA,YACA,eAAe;AAAA;AAAA,QACjB;AAAA,QAEF,qBAAC,SAAI,WAAU,wBACb;AAAA,8BAAC,UAAO,IAAI,UAAU,MAAK,UAAS,SAAQ,SAAQ,UAAU,MAAM,SAAS,MAAM,SAAS,KAAK,GAC9F,iBAAO,QACV;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACC,IAAI;AAAA,cACJ,MAAK;AAAA,cACL,SAAS,mBAAmB,SAAS,YAAY,YAAY;AAAA,cAC7D,UAAU,CAAC;AAAA,cAMX,gBAAgB;AAAA,cAChB,aAAW,QAAQ;AAAA,cAElB;AAAA,wBAAQ,oBAAC,WAAQ,OAAO,MAAM,WAAU,WAAU;AAAA,gBAClD,gBAAgB,OAAO;AAAA;AAAA;AAAA,UAC1B;AAAA,WACF;AAAA,QACC,UAAU,oBAAC,OAAE,WAAU,oCAAoC,wBAAa;AAAA;AAAA;AAAA,EAC3E,GACF;AAEJ;","names":["CurrentPasswordInput","TypedConfirmField"]}
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ComponentPropsWithoutRef, ReactNode } from 'react';
2
+ import { ComponentPropsWithoutRef, ReactNode, Ref } from 'react';
3
3
  import { ComboClearValue, ComboOption } from './combobox-core.js';
4
4
  import '../hooks/use-anchored-rect.js';
5
5
  import '../hooks/use-anchored-panel.js';
@@ -45,6 +45,10 @@ interface EntityComboboxProps<V extends string | number, C extends ComboClearVal
45
45
  * actions, and on a full-screen sheet the close button is the only way out —
46
46
  * so it is the one control here that MUST be in the reader's language. */
47
47
  closeLabel?: string;
48
+ /** The phone sheet's heading (and, as a string, its accessible name) for a picker
49
+ * whose label is drawn by someone else — a form's `FormLabel`; `RhfCombobox`
50
+ * hands its label over here (0.24). Default: `label`, then `placeholder`. */
51
+ sheetTitle?: ReactNode;
48
52
  disabled?: boolean;
49
53
  /**
50
54
  * Why the choice cannot be changed — {@link Button}'s `disabledReason`, for a picker
@@ -101,6 +105,14 @@ interface EntityComboboxProps<V extends string | number, C extends ComboClearVal
101
105
  debounceMs?: number;
102
106
  /** Shown when `loadOptions` rejects. Default: `combobox.loadError`. */
103
107
  loadErrorLabel?: string;
108
+ /**
109
+ * The TRIGGER — the focusable `<button>` a reader meets — as a React 19 ref prop, as
110
+ * on {@link CountrySelect}, which is built on the same core (0.24, kastlan: react-hook-
111
+ * form's focus-on-error calls `focus()` on whatever `field.ref` is handed, and a
112
+ * picker with no ref gave it nothing to focus). Not the wrapper: focus belongs on the
113
+ * trigger, which is also where the panel hands it back after a pick.
114
+ */
115
+ ref?: Ref<HTMLButtonElement>;
104
116
  }
105
117
  /**
106
118
  * An id-keyed, searchable entity picker: a field-styled trigger showing the
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useId } from "react";
3
+ import { useCallback, useId } from "react";
4
4
  import { X } from "lucide-react";
5
5
  import { cn } from "../lib/cn.js";
6
6
  import { FieldChevron, FieldLabel, FIELD_TRIGGER, FIELD_FLOATING_PAD, FIELD_INVALID } from "./ui.js";
@@ -21,7 +21,7 @@ import {
21
21
  useFieldHint,
22
22
  useLockReason
23
23
  } from "./field-parts.js";
24
- import { mergeDescribedBy } from "./choice-parts.js";
24
+ import { assignRef, mergeDescribedBy } from "./choice-parts.js";
25
25
  import { useCommitReason } from "./write-lock.js";
26
26
  function EntityCombobox(props) {
27
27
  const {
@@ -38,6 +38,7 @@ function EntityCombobox(props) {
38
38
  clearable,
39
39
  clearLabel,
40
40
  closeLabel,
41
+ sheetTitle,
41
42
  disabled,
42
43
  disabledReason,
43
44
  commit,
@@ -53,6 +54,7 @@ function EntityCombobox(props) {
53
54
  minChars,
54
55
  debounceMs,
55
56
  loadErrorLabel,
57
+ ref,
56
58
  "aria-label": ariaLabel,
57
59
  // The control's own wiring, taken off `rest` so it lands on the TRIGGER rather than
58
60
  // the wrapper — see MultiEntityCombobox: `Field`'s render-prop spreads `{ id,
@@ -86,6 +88,13 @@ function EntityCombobox(props) {
86
88
  });
87
89
  const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
88
90
  const { open, results, resolve, setOpen, rememberOption, query, triggerRef } = core;
91
+ const setTrigger = useCallback(
92
+ (el) => {
93
+ triggerRef.current = el;
94
+ assignRef(ref, el);
95
+ },
96
+ [ref, triggerRef]
97
+ );
89
98
  const lock = useLockReason(commit, disabledReason);
90
99
  const inert = lock.locked || Boolean(disabled);
91
100
  if (lock.locked && open) setOpen(false);
@@ -120,7 +129,7 @@ function EntityCombobox(props) {
120
129
  /* @__PURE__ */ jsxs(
121
130
  "button",
122
131
  {
123
- ref: triggerRef,
132
+ ref: setTrigger,
124
133
  id,
125
134
  type: "button",
126
135
  role: "combobox",
@@ -201,7 +210,7 @@ function EntityCombobox(props) {
201
210
  {
202
211
  core,
203
212
  listboxId,
204
- sheetTitle: label ?? placeholder,
213
+ sheetTitle: sheetTitle ?? label ?? placeholder,
205
214
  searchPlaceholder: labels.search,
206
215
  emptyLabel: labels.noResults,
207
216
  closeLabel,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/entity-combobox.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { FieldChevron, FieldLabel, FIELD_TRIGGER, FIELD_FLOATING_PAD, FIELD_INVALID } from \"./ui\";\nimport {\n ComboboxPanel,\n endHintRowProps,\n offersCreate,\n useComboboxCore,\n useComboboxFieldError,\n type ComboClearValue,\n type ComboOption,\n} from \"./combobox-core\";\nimport { DEFAULT_COMBOBOX_LABELS, DEFAULT_COMMON_LABELS, useKitLabels } from \"../i18n/kit-labels\";\nimport {\n EndHintRow,\n FieldCaption,\n LABEL_IN_ROW,\n LockedReason,\n StaticLabelRow,\n useFieldHint,\n useLockReason,\n} from \"./field-parts\";\nimport { mergeDescribedBy } from \"./choice-parts\";\nimport { useCommitReason } from \"./write-lock\";\n\nexport type { ComboClearValue, ComboOption } from \"./combobox-core\";\n\n/** `onChange` is the kit's — \"a selection was made\", carrying values — rather\n * than the div's form event, so the DOM's spelling of it is omitted. */\nexport interface EntityComboboxProps<V extends string | number, C extends ComboClearValue = null>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /** Selected id; `null`, `undefined` or `clearValue` when nothing is selected. */\n value: V | C | null | undefined;\n /** Selecting an option emits its value; the clear button emits `clearValue`. */\n onChange: (value: V | C) => void;\n /**\n * What the clear button emits. Default `null`. Pass `\"\"` for a form whose schema\n * wants an empty string for \"no choice\" (a zod `z.string()` field), rather than\n * mapping `null` in every `onChange` — the type of `onChange` follows it, so the\n * mapping cannot be forgotten on one field and not another. The picker also reads\n * the value back as empty, so `value=\"\"` shows the placeholder and no \"×\".\n * See {@link ComboClearValue} for why the choice is closed.\n */\n clearValue?: C;\n /** Already-loaded options (client-side filtered). Also used to resolve the\n * trigger label for the current `value`. */\n options?: ComboOption<V>[];\n /** Async option source, debounced and called on open + as the query changes\n * (at `minChars` and up). Stale responses are ignored; a rejection empties the\n * list and says `loadErrorLabel` instead of leaving the last query's rows up. When set, `options` is used only for label\n * resolution, not as the result list. */\n loadOptions?: (query: string) => Promise<ComboOption<V>[]>;\n /** External loading flag (OR-ed with the internal async state). */\n loading?: boolean;\n label?: ReactNode;\n placeholder?: string;\n searchPlaceholder?: string;\n emptyLabel?: string;\n /** Offer a clear \"×\" in place of the chevron while something is chosen; it emits\n * `clearValue`. A pointer shortcut inside the trigger, out of the tab order — the\n * keyboard's way is Delete or Backspace on the CLOSED trigger (0.23, as\n * {@link CountrySelect}). Not offered while `disabled` or locked. */\n clearable?: boolean;\n clearLabel?: string;\n /** The phone sheet's close button. Its own prop rather than a reuse of\n * `clearLabel`: \"clear the selection\" and \"close this screen\" are different\n * actions, and on a full-screen sheet the close button is the only way out —\n * so it is the one control here that MUST be in the reader's language. */\n closeLabel?: string;\n disabled?: boolean;\n /**\n * Why the choice cannot be changed — {@link Button}'s `disabledReason`, for a picker\n * that SAVES on change (keksdose G2: the statement's account, where picking IS the\n * write). The trigger stays focusable and `aria-disabled`, the list does not open,\n * the clear \"×\" is gone and `onChange` never fires; the reason is in the kit\n * {@link Tooltip} and on the trigger's `aria-describedby`. Wins over `disabled`.\n * {@link CountrySelect}'s lock, which is built on the same core.\n */\n disabledReason?: ReactNode;\n /**\n * This picker COMMITS — choosing saves. Under a locked {@link WriteLockProvider} it is\n * locked the `disabledReason` way with the lock's reason (which wins over its own).\n * A picker inside a form with its own Save stays editable under the lock: leave this\n * off there and put `commit` on the Save. No provider, or an unlocked one: no effect.\n */\n commit?: boolean;\n /** When set, a \"create\" row appears for a non-empty query with no exact match. */\n onCreate?: (query: string) => void;\n createLabel?: (query: string) => string;\n /**\n * Offer the create row with NOTHING typed too, worded as this — keksdose G9's\n * \"Create cash account\", which mints a record under a default name and so needs no\n * query. `onCreate` then receives `\"\"`. Left out, the row needs a query, as before.\n * See {@link InlineEntityCombobox}'s `createEmptyLabel`.\n */\n createEmptyLabel?: string;\n /**\n * The create row WRITES (it mints the record on the server) while picking does not.\n * Under a locked {@link WriteLockProvider} the row stays in the list but cannot be\n * taken, with the lock's reason as its second line — the picker itself stays live.\n * keksdose dev#496: on the read-only demo choosing is draft state, minting is not.\n */\n createCommit?: boolean;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /** What is wrong with the value, as {@link Input}'s `error`: rendered under the\n * field, on the trigger's `aria-describedby`, and implies `invalid`. */\n error?: ReactNode;\n /**\n * Standing advice — {@link Combobox}'s `hint`, so the pickers read like every other\n * field (keksdose K4): plain TEXT is a caption under the field on the trigger's\n * `aria-describedby`, before any error; a {@link FieldHint} \"?\" rides the label line,\n * or with no label sits at the trigger's end edge, outside the box.\n */\n hint?: ReactNode;\n /** Narrow `options` client-side by the query. Default `true`; `false` shows them\n * as given (a server-ranked list). */\n filter?: boolean;\n /** Offer nothing, and call no `loadOptions`, below this many characters. Default\n * `0`, i.e. the list loads as the panel opens. */\n minChars?: number;\n /** `loadOptions` debounce. Default 150 ms. */\n debounceMs?: number;\n /** Shown when `loadOptions` rejects. Default: `combobox.loadError`. */\n loadErrorLabel?: string;\n}\n\n/**\n * An id-keyed, searchable entity picker: a field-styled trigger showing the\n * selected item's label, and a portalled dropdown of `{label, sublabel, icon}`\n * options — loaded up front via `options` or lazily via `loadOptions`. Built on\n * the shared field/anchor/dismiss/search primitives (no cmdk/Radix). For picking\n * several entities use {@link MultiEntityCombobox}.\n */\nexport function EntityCombobox<V extends string | number, C extends ComboClearValue = null>(\n props: EntityComboboxProps<V, C>,\n) {\n const {\n value,\n onChange,\n clearValue = null as C,\n options,\n loadOptions,\n loading,\n label,\n placeholder,\n searchPlaceholder,\n emptyLabel,\n clearable,\n clearLabel,\n closeLabel,\n disabled,\n disabledReason,\n commit,\n onCreate,\n createLabel,\n createEmptyLabel,\n createCommit,\n className,\n invalid,\n error,\n hint,\n filter,\n minChars,\n debounceMs,\n loadErrorLabel,\n \"aria-label\": ariaLabel,\n // The control's own wiring, taken off `rest` so it lands on the TRIGGER rather than\n // the wrapper — see MultiEntityCombobox: `Field`'s render-prop spreads `{ id,\n // aria-describedby, aria-invalid, aria-required }`, and on the role-less wrapper\n // div the label's `htmlFor` named nothing and the hint described nothing.\n id,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n \"aria-required\": ariaRequired,\n ...rest\n } = props;\n const core = useComboboxCore<V>({\n options,\n loadOptions,\n loading,\n filter,\n minChars,\n debounceMs,\n });\n const hintParts = useFieldHint(hint, ariaDescribedBy);\n const field = useComboboxFieldError(\n error,\n invalid || ariaInvalid === true || ariaInvalid === \"true\",\n hintParts.describedBy,\n );\n // The props are the per-instance overrides, the provider the app-wide ones; a\n // prop left `undefined` falls through to the provider rather than masking it.\n const labels = useKitLabels(\"combobox\", DEFAULT_COMBOBOX_LABELS, {\n search: searchPlaceholder,\n noResults: emptyLabel,\n clear: clearLabel,\n create: createLabel,\n });\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const { open, results, resolve, setOpen, rememberOption, query, triggerRef } = core;\n // The lock: this picker's own reason, or the provider's under `commit`.\n const lock = useLockReason(commit, disabledReason);\n const inert = lock.locked || Boolean(disabled);\n // A lock arriving while the list is up closes it — adjusted while\n // rendering, as the core adjusts its own query, so no frame offers a pick that would\n // be thrown away.\n if (lock.locked && open) setOpen(false);\n // The create row's own lock, for a picker whose choosing is draft and whose create\n // is the write (`createCommit`).\n const createReason = useCommitReason(createCommit, undefined);\n // One id per instance, generated here rather than in the core: `aria-controls` on\n // the trigger has to name the list while the list is still closed, so the id\n // belongs to whoever renders both ends of it.\n const listboxId = useId();\n\n // The clear value is \"nothing selected\" too, whichever one the caller picked.\n const chosen: V | null = value == null || value === clearValue ? null : (value as V);\n const selectedOption = chosen == null ? null : resolve(chosen);\n const q = query.trim();\n const showCreate = offersCreate(\n onCreate,\n q,\n results.map((o) => o.label),\n createEmptyLabel,\n );\n const showClear = Boolean(clearable && chosen != null && !inert);\n /** What the closed control is showing — the second half of its accessible name. */\n const triggerText = selectedOption?.label ?? placeholder ?? \"\";\n // While locked the trigger sits in the reason's Tooltip — in a fragment with a hidden\n // copy of the reason, Button's anatomy — `block` so a full-width field stays full width.\n const withLock = (trigger: ReactNode) =>\n lock.locked ? (\n <LockedReason lock={lock} className=\"block\">\n {trigger}\n </LockedReason>\n ) : (\n trigger\n );\n\n const choose = (o: ComboOption<V>) => {\n if (lock.locked) return;\n rememberOption(o);\n onChange(o.value);\n // Back to the trigger, not to <body>: the panel that held focus is about to\n // unmount, and a keyboard user who just answered this field should be standing\n // on it, ready to Tab to the next one.\n core.closeToTrigger();\n };\n\n return (\n // `rest` dresses the wrapper, which has no role; the accessible NAME — and the\n // id, description, invalid and required state above — go on the trigger, which\n // has one. Spread FIRST so the trigger's ARIA and the\n // handlers that open the panel cannot be clobbered from outside.\n <div {...rest} className={cn(\"relative\", className)}>\n {label !== undefined && hintParts.labelHint === undefined && <FieldLabel>{label}</FieldLabel>}\n <EndHintRow {...endHintRowProps(\"hint\" in props, label !== undefined, hintParts.labelHint)}>\n {withLock(\n <button\n ref={triggerRef}\n id={id}\n type=\"button\"\n // A combobox, not a button. The distinction is not pedantry: this control\n // carried `aria-invalid`, which `button` does not support, so a required\n // field left empty painted a rose border and told a reader nothing at all —\n // and ESLint flagged it as exactly that (`role-supports-aria-props`). The\n // fix the audit asked for is the role that describes what this IS: a closed\n // choice that expands into the list named below. `combobox` supports\n // `aria-invalid`, so the border and the announcement finally agree.\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={listboxId}\n aria-haspopup=\"listbox\"\n // The label is a floating <span>, not a <label for>, so without this the\n // trigger's accessible name is whatever value happens to be selected —\n // \"Checking\" with nothing saying it is the account. The label AND the\n // value, because `aria-label` replaces the content rather than adding to\n // it, and a control that announces only its name has lost the answer.\n // A caller's own name wins over the composition: two fields labelled\n // \"Account\" on a transfer form are the from and the to, and only the\n // caller knows which is which.\n aria-label={\n ariaLabel ??\n (typeof label === \"string\" ? common.fieldValue(label, triggerText) : undefined)\n }\n // The focusable kind of disabled while locked (Button's rule): a native\n // `disabled` would take the field out of the tab order, and the reason with it.\n disabled={lock.locked ? undefined : disabled}\n aria-disabled={lock.locked || undefined}\n aria-invalid={field.isInvalid || undefined}\n aria-describedby={mergeDescribedBy(field.describedBy, lock.locked && lock.reasonId)}\n aria-required={ariaRequired}\n onClick={() => !inert && setOpen((o) => !o)}\n // Down/Up opens the list from the closed trigger, per the APG. Enter and\n // Space already do it through the button's own click.\n onKeyDown={(e) => {\n if (inert) return;\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n setOpen(true);\n } else if (showClear && !open && (e.key === \"Delete\" || e.key === \"Backspace\")) {\n // The keyboard's clear: the \"×\" is a pointer shortcut out of the tab\n // order, so without this a cleared-by-mouse field was set-only from the\n // keyboard. The closed trigger only — CountrySelect's rule (0.23).\n e.preventDefault();\n onChange(clearValue);\n }\n }}\n className={cn(\n FIELD_TRIGGER,\n \"pe-9\",\n label !== undefined && FIELD_FLOATING_PAD,\n inert && \"cursor-not-allowed opacity-50\",\n field.isInvalid && FIELD_INVALID,\n )}\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n {selectedOption?.icon && <span className=\"shrink-0\">{selectedOption.icon}</span>}\n <span\n className={cn(\n \"truncate\",\n // A chosen value is the field's VALUE, so it is set in the same ink an\n // <input>'s value is — FIELD_BASE's own text colour, inherited rather\n // than restated (Keksdose dev#477). It used to be one notch lighter\n // than the typeahead fields beside it, which is visible when a picker\n // and a text field share a form row. Nothing selected keeps the\n // placeholder tone (`--text-placeholder`), which every field here\n // agrees on.\n !selectedOption && \"text-[var(--text-placeholder)]\",\n )}\n >\n {selectedOption?.label ?? placeholder ?? \"\"}\n </span>\n </span>\n {showClear ? (\n /* eslint-disable-next-line jsx-a11y/click-events-have-key-events -- tabIndex -1 inside\n the trigger <button>, so it never holds focus and a key handler here could\n never fire; the keys go to the trigger, where Delete and Backspace clear. */\n <span\n role=\"button\"\n tabIndex={-1}\n aria-label={labels.clear}\n onClick={(e) => {\n e.stopPropagation();\n onChange(clearValue);\n }}\n className=\"absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]\"\n >\n <X className=\"size-4\" />\n </span>\n ) : (\n <FieldChevron />\n )}\n </button>,\n )}\n </EndHintRow>\n {/* With a \"?\" the label shares the top strip with it — after the trigger, so the\n \"?\" follows the control in the tab order, as on Input and Select. */}\n {label !== undefined && hintParts.labelHint !== undefined && (\n <StaticLabelRow hint={hintParts.labelHint}>\n <FieldLabel className={LABEL_IN_ROW}>{label}</FieldLabel>\n </StaticLabelRow>\n )}\n <ComboboxPanel\n core={core}\n listboxId={listboxId}\n // On a phone the panel becomes a full-screen sheet, which needs the field's\n // own label to say what it is asking for (live #200).\n sheetTitle={label ?? placeholder}\n searchPlaceholder={labels.search}\n emptyLabel={labels.noResults}\n closeLabel={closeLabel}\n loadErrorLabel={loadErrorLabel}\n isSelected={(v) => v === value}\n onChoose={choose}\n showCreate={showCreate}\n onCreate={() => {\n if (lock.locked) return;\n onCreate?.(q);\n core.closeToTrigger();\n }}\n createContent={q ? labels.create(q) : createEmptyLabel}\n createDisabledReason={createReason}\n />\n <FieldCaption parts={hintParts} />\n {field.errorEl}\n </div>\n );\n}\n"],"mappings":";AA2OM,cAoFM,YApFN;AA3ON,SAAS,aAAa;AAEtB,SAAS,SAAS;AAClB,SAAS,UAAU;AACnB,SAAS,cAAc,YAAY,eAAe,oBAAoB,qBAAqB;AAC3F;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,yBAAyB,uBAAuB,oBAAoB;AAC7E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AA+GzB,SAAS,eACd,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,I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AAsB;AAAA;AAAA,MACxB;AAAA,MACA,oBAAC,gBAAa,OAAO,WAAW;AAAA,MAC/B,MAAM;AAAA,OACT;AAAA;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/entity-combobox.tsx"],"sourcesContent":["import { useCallback, useId } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode, Ref } from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { FieldChevron, FieldLabel, FIELD_TRIGGER, FIELD_FLOATING_PAD, FIELD_INVALID } from \"./ui\";\nimport {\n ComboboxPanel,\n endHintRowProps,\n offersCreate,\n useComboboxCore,\n useComboboxFieldError,\n type ComboClearValue,\n type ComboOption,\n} from \"./combobox-core\";\nimport { DEFAULT_COMBOBOX_LABELS, DEFAULT_COMMON_LABELS, useKitLabels } from \"../i18n/kit-labels\";\nimport {\n EndHintRow,\n FieldCaption,\n LABEL_IN_ROW,\n LockedReason,\n StaticLabelRow,\n useFieldHint,\n useLockReason,\n} from \"./field-parts\";\nimport { assignRef, mergeDescribedBy } from \"./choice-parts\";\nimport { useCommitReason } from \"./write-lock\";\n\nexport type { ComboClearValue, ComboOption } from \"./combobox-core\";\n\n/** `onChange` is the kit's — \"a selection was made\", carrying values — rather\n * than the div's form event, so the DOM's spelling of it is omitted. */\nexport interface EntityComboboxProps<V extends string | number, C extends ComboClearValue = null>\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\"> {\n /** Selected id; `null`, `undefined` or `clearValue` when nothing is selected. */\n value: V | C | null | undefined;\n /** Selecting an option emits its value; the clear button emits `clearValue`. */\n onChange: (value: V | C) => void;\n /**\n * What the clear button emits. Default `null`. Pass `\"\"` for a form whose schema\n * wants an empty string for \"no choice\" (a zod `z.string()` field), rather than\n * mapping `null` in every `onChange` — the type of `onChange` follows it, so the\n * mapping cannot be forgotten on one field and not another. The picker also reads\n * the value back as empty, so `value=\"\"` shows the placeholder and no \"×\".\n * See {@link ComboClearValue} for why the choice is closed.\n */\n clearValue?: C;\n /** Already-loaded options (client-side filtered). Also used to resolve the\n * trigger label for the current `value`. */\n options?: ComboOption<V>[];\n /** Async option source, debounced and called on open + as the query changes\n * (at `minChars` and up). Stale responses are ignored; a rejection empties the\n * list and says `loadErrorLabel` instead of leaving the last query's rows up. When set, `options` is used only for label\n * resolution, not as the result list. */\n loadOptions?: (query: string) => Promise<ComboOption<V>[]>;\n /** External loading flag (OR-ed with the internal async state). */\n loading?: boolean;\n label?: ReactNode;\n placeholder?: string;\n searchPlaceholder?: string;\n emptyLabel?: string;\n /** Offer a clear \"×\" in place of the chevron while something is chosen; it emits\n * `clearValue`. A pointer shortcut inside the trigger, out of the tab order — the\n * keyboard's way is Delete or Backspace on the CLOSED trigger (0.23, as\n * {@link CountrySelect}). Not offered while `disabled` or locked. */\n clearable?: boolean;\n clearLabel?: string;\n /** The phone sheet's close button. Its own prop rather than a reuse of\n * `clearLabel`: \"clear the selection\" and \"close this screen\" are different\n * actions, and on a full-screen sheet the close button is the only way out —\n * so it is the one control here that MUST be in the reader's language. */\n closeLabel?: string;\n /** The phone sheet's heading (and, as a string, its accessible name) for a picker\n * whose label is drawn by someone else — a form's `FormLabel`; `RhfCombobox`\n * hands its label over here (0.24). Default: `label`, then `placeholder`. */\n sheetTitle?: ReactNode;\n disabled?: boolean;\n /**\n * Why the choice cannot be changed — {@link Button}'s `disabledReason`, for a picker\n * that SAVES on change (keksdose G2: the statement's account, where picking IS the\n * write). The trigger stays focusable and `aria-disabled`, the list does not open,\n * the clear \"×\" is gone and `onChange` never fires; the reason is in the kit\n * {@link Tooltip} and on the trigger's `aria-describedby`. Wins over `disabled`.\n * {@link CountrySelect}'s lock, which is built on the same core.\n */\n disabledReason?: ReactNode;\n /**\n * This picker COMMITS — choosing saves. Under a locked {@link WriteLockProvider} it is\n * locked the `disabledReason` way with the lock's reason (which wins over its own).\n * A picker inside a form with its own Save stays editable under the lock: leave this\n * off there and put `commit` on the Save. No provider, or an unlocked one: no effect.\n */\n commit?: boolean;\n /** When set, a \"create\" row appears for a non-empty query with no exact match. */\n onCreate?: (query: string) => void;\n createLabel?: (query: string) => string;\n /**\n * Offer the create row with NOTHING typed too, worded as this — keksdose G9's\n * \"Create cash account\", which mints a record under a default name and so needs no\n * query. `onCreate` then receives `\"\"`. Left out, the row needs a query, as before.\n * See {@link InlineEntityCombobox}'s `createEmptyLabel`.\n */\n createEmptyLabel?: string;\n /**\n * The create row WRITES (it mints the record on the server) while picking does not.\n * Under a locked {@link WriteLockProvider} the row stays in the list but cannot be\n * taken, with the lock's reason as its second line — the picker itself stays live.\n * keksdose dev#496: on the read-only demo choosing is draft state, minting is not.\n */\n createCommit?: boolean;\n /** Required and unanswered — {@link FIELD_INVALID}. See {@link Input}'s `invalid`. */\n invalid?: boolean;\n /** What is wrong with the value, as {@link Input}'s `error`: rendered under the\n * field, on the trigger's `aria-describedby`, and implies `invalid`. */\n error?: ReactNode;\n /**\n * Standing advice — {@link Combobox}'s `hint`, so the pickers read like every other\n * field (keksdose K4): plain TEXT is a caption under the field on the trigger's\n * `aria-describedby`, before any error; a {@link FieldHint} \"?\" rides the label line,\n * or with no label sits at the trigger's end edge, outside the box.\n */\n hint?: ReactNode;\n /** Narrow `options` client-side by the query. Default `true`; `false` shows them\n * as given (a server-ranked list). */\n filter?: boolean;\n /** Offer nothing, and call no `loadOptions`, below this many characters. Default\n * `0`, i.e. the list loads as the panel opens. */\n minChars?: number;\n /** `loadOptions` debounce. Default 150 ms. */\n debounceMs?: number;\n /** Shown when `loadOptions` rejects. Default: `combobox.loadError`. */\n loadErrorLabel?: string;\n /**\n * The TRIGGER — the focusable `<button>` a reader meets — as a React 19 ref prop, as\n * on {@link CountrySelect}, which is built on the same core (0.24, kastlan: react-hook-\n * form's focus-on-error calls `focus()` on whatever `field.ref` is handed, and a\n * picker with no ref gave it nothing to focus). Not the wrapper: focus belongs on the\n * trigger, which is also where the panel hands it back after a pick.\n */\n ref?: Ref<HTMLButtonElement>;\n}\n\n/**\n * An id-keyed, searchable entity picker: a field-styled trigger showing the\n * selected item's label, and a portalled dropdown of `{label, sublabel, icon}`\n * options — loaded up front via `options` or lazily via `loadOptions`. Built on\n * the shared field/anchor/dismiss/search primitives (no cmdk/Radix). For picking\n * several entities use {@link MultiEntityCombobox}.\n */\nexport function EntityCombobox<V extends string | number, C extends ComboClearValue = null>(\n props: EntityComboboxProps<V, C>,\n) {\n const {\n value,\n onChange,\n clearValue = null as C,\n options,\n loadOptions,\n loading,\n label,\n placeholder,\n searchPlaceholder,\n emptyLabel,\n clearable,\n clearLabel,\n closeLabel,\n sheetTitle,\n disabled,\n disabledReason,\n commit,\n onCreate,\n createLabel,\n createEmptyLabel,\n createCommit,\n className,\n invalid,\n error,\n hint,\n filter,\n minChars,\n debounceMs,\n loadErrorLabel,\n ref,\n \"aria-label\": ariaLabel,\n // The control's own wiring, taken off `rest` so it lands on the TRIGGER rather than\n // the wrapper — see MultiEntityCombobox: `Field`'s render-prop spreads `{ id,\n // aria-describedby, aria-invalid, aria-required }`, and on the role-less wrapper\n // div the label's `htmlFor` named nothing and the hint described nothing.\n id,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n \"aria-required\": ariaRequired,\n ...rest\n } = props;\n const core = useComboboxCore<V>({\n options,\n loadOptions,\n loading,\n filter,\n minChars,\n debounceMs,\n });\n const hintParts = useFieldHint(hint, ariaDescribedBy);\n const field = useComboboxFieldError(\n error,\n invalid || ariaInvalid === true || ariaInvalid === \"true\",\n hintParts.describedBy,\n );\n // The props are the per-instance overrides, the provider the app-wide ones; a\n // prop left `undefined` falls through to the provider rather than masking it.\n const labels = useKitLabels(\"combobox\", DEFAULT_COMBOBOX_LABELS, {\n search: searchPlaceholder,\n noResults: emptyLabel,\n clear: clearLabel,\n create: createLabel,\n });\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const { open, results, resolve, setOpen, rememberOption, query, triggerRef } = core;\n // The core anchors the panel to the trigger and hands focus back to it; the caller's\n // `ref` wants the same element. One callback feeds both — CountrySelect's.\n const setTrigger = useCallback(\n (el: HTMLButtonElement | null) => {\n triggerRef.current = el;\n assignRef(ref, el);\n },\n [ref, triggerRef],\n );\n // The lock: this picker's own reason, or the provider's under `commit`.\n const lock = useLockReason(commit, disabledReason);\n const inert = lock.locked || Boolean(disabled);\n // A lock arriving while the list is up closes it — adjusted while\n // rendering, as the core adjusts its own query, so no frame offers a pick that would\n // be thrown away.\n if (lock.locked && open) setOpen(false);\n // The create row's own lock, for a picker whose choosing is draft and whose create\n // is the write (`createCommit`).\n const createReason = useCommitReason(createCommit, undefined);\n // One id per instance, generated here rather than in the core: `aria-controls` on\n // the trigger has to name the list while the list is still closed, so the id\n // belongs to whoever renders both ends of it.\n const listboxId = useId();\n\n // The clear value is \"nothing selected\" too, whichever one the caller picked.\n const chosen: V | null = value == null || value === clearValue ? null : (value as V);\n const selectedOption = chosen == null ? null : resolve(chosen);\n const q = query.trim();\n const showCreate = offersCreate(\n onCreate,\n q,\n results.map((o) => o.label),\n createEmptyLabel,\n );\n const showClear = Boolean(clearable && chosen != null && !inert);\n /** What the closed control is showing — the second half of its accessible name. */\n const triggerText = selectedOption?.label ?? placeholder ?? \"\";\n // While locked the trigger sits in the reason's Tooltip — in a fragment with a hidden\n // copy of the reason, Button's anatomy — `block` so a full-width field stays full width.\n const withLock = (trigger: ReactNode) =>\n lock.locked ? (\n <LockedReason lock={lock} className=\"block\">\n {trigger}\n </LockedReason>\n ) : (\n trigger\n );\n\n const choose = (o: ComboOption<V>) => {\n if (lock.locked) return;\n rememberOption(o);\n onChange(o.value);\n // Back to the trigger, not to <body>: the panel that held focus is about to\n // unmount, and a keyboard user who just answered this field should be standing\n // on it, ready to Tab to the next one.\n core.closeToTrigger();\n };\n\n return (\n // `rest` dresses the wrapper, which has no role; the accessible NAME — and the\n // id, description, invalid and required state above — go on the trigger, which\n // has one. Spread FIRST so the trigger's ARIA and the\n // handlers that open the panel cannot be clobbered from outside.\n <div {...rest} className={cn(\"relative\", className)}>\n {label !== undefined && hintParts.labelHint === undefined && <FieldLabel>{label}</FieldLabel>}\n <EndHintRow {...endHintRowProps(\"hint\" in props, label !== undefined, hintParts.labelHint)}>\n {withLock(\n <button\n ref={setTrigger}\n id={id}\n type=\"button\"\n // A combobox, not a button. The distinction is not pedantry: this control\n // carried `aria-invalid`, which `button` does not support, so a required\n // field left empty painted a rose border and told a reader nothing at all —\n // and ESLint flagged it as exactly that (`role-supports-aria-props`). The\n // fix the audit asked for is the role that describes what this IS: a closed\n // choice that expands into the list named below. `combobox` supports\n // `aria-invalid`, so the border and the announcement finally agree.\n role=\"combobox\"\n aria-expanded={open}\n aria-controls={listboxId}\n aria-haspopup=\"listbox\"\n // The label is a floating <span>, not a <label for>, so without this the\n // trigger's accessible name is whatever value happens to be selected —\n // \"Checking\" with nothing saying it is the account. The label AND the\n // value, because `aria-label` replaces the content rather than adding to\n // it, and a control that announces only its name has lost the answer.\n // A caller's own name wins over the composition: two fields labelled\n // \"Account\" on a transfer form are the from and the to, and only the\n // caller knows which is which.\n aria-label={\n ariaLabel ??\n (typeof label === \"string\" ? common.fieldValue(label, triggerText) : undefined)\n }\n // The focusable kind of disabled while locked (Button's rule): a native\n // `disabled` would take the field out of the tab order, and the reason with it.\n disabled={lock.locked ? undefined : disabled}\n aria-disabled={lock.locked || undefined}\n aria-invalid={field.isInvalid || undefined}\n aria-describedby={mergeDescribedBy(field.describedBy, lock.locked && lock.reasonId)}\n aria-required={ariaRequired}\n onClick={() => !inert && setOpen((o) => !o)}\n // Down/Up opens the list from the closed trigger, per the APG. Enter and\n // Space already do it through the button's own click.\n onKeyDown={(e) => {\n if (inert) return;\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n setOpen(true);\n } else if (showClear && !open && (e.key === \"Delete\" || e.key === \"Backspace\")) {\n // The keyboard's clear: the \"×\" is a pointer shortcut out of the tab\n // order, so without this a cleared-by-mouse field was set-only from the\n // keyboard. The closed trigger only — CountrySelect's rule (0.23).\n e.preventDefault();\n onChange(clearValue);\n }\n }}\n className={cn(\n FIELD_TRIGGER,\n \"pe-9\",\n label !== undefined && FIELD_FLOATING_PAD,\n inert && \"cursor-not-allowed opacity-50\",\n field.isInvalid && FIELD_INVALID,\n )}\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n {selectedOption?.icon && <span className=\"shrink-0\">{selectedOption.icon}</span>}\n <span\n className={cn(\n \"truncate\",\n // A chosen value is the field's VALUE, so it is set in the same ink an\n // <input>'s value is — FIELD_BASE's own text colour, inherited rather\n // than restated (Keksdose dev#477). It used to be one notch lighter\n // than the typeahead fields beside it, which is visible when a picker\n // and a text field share a form row. Nothing selected keeps the\n // placeholder tone (`--text-placeholder`), which every field here\n // agrees on.\n !selectedOption && \"text-[var(--text-placeholder)]\",\n )}\n >\n {selectedOption?.label ?? placeholder ?? \"\"}\n </span>\n </span>\n {showClear ? (\n /* eslint-disable-next-line jsx-a11y/click-events-have-key-events -- tabIndex -1 inside\n the trigger <button>, so it never holds focus and a key handler here could\n never fire; the keys go to the trigger, where Delete and Backspace clear. */\n <span\n role=\"button\"\n tabIndex={-1}\n aria-label={labels.clear}\n onClick={(e) => {\n e.stopPropagation();\n onChange(clearValue);\n }}\n className=\"absolute end-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-[var(--text-placeholder)] hover:text-[var(--text-secondary)]\"\n >\n <X className=\"size-4\" />\n </span>\n ) : (\n <FieldChevron />\n )}\n </button>,\n )}\n </EndHintRow>\n {/* With a \"?\" the label shares the top strip with it — after the trigger, so the\n \"?\" follows the control in the tab order, as on Input and Select. */}\n {label !== undefined && hintParts.labelHint !== undefined && (\n <StaticLabelRow hint={hintParts.labelHint}>\n <FieldLabel className={LABEL_IN_ROW}>{label}</FieldLabel>\n </StaticLabelRow>\n )}\n <ComboboxPanel\n core={core}\n listboxId={listboxId}\n // On a phone the panel becomes a full-screen sheet, which needs the field's\n // own label to say what it is asking for (live #200).\n sheetTitle={sheetTitle ?? label ?? placeholder}\n searchPlaceholder={labels.search}\n emptyLabel={labels.noResults}\n closeLabel={closeLabel}\n loadErrorLabel={loadErrorLabel}\n isSelected={(v) => v === value}\n onChoose={choose}\n showCreate={showCreate}\n onCreate={() => {\n if (lock.locked) return;\n onCreate?.(q);\n core.closeToTrigger();\n }}\n createContent={q ? labels.create(q) : createEmptyLabel}\n createDisabledReason={createReason}\n />\n <FieldCaption parts={hintParts} />\n {field.errorEl}\n </div>\n );\n}\n"],"mappings":";AAkQM,cAoFM,YApFN;AAlQN,SAAS,aAAa,aAAa;AAEnC,SAAS,SAAS;AAClB,SAAS,UAAU;AACnB,SAAS,cAAc,YAAY,eAAe,oBAAoB,qBAAqB;AAC3F;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,yBAAyB,uBAAuB,oBAAoB;AAC7E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,wBAAwB;AAC5C,SAAS,uBAAuB;AA2HzB,SAAS,eACd,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,IAKd;AAAA,IACA,oBAAoB;AAAA,IACpB,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,OAAO,gBAAmB;A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OACT;AAAA;AAEJ;","names":[]}
@@ -6,10 +6,7 @@ import './series-chart-labels.js';
6
6
  import './toggle-legend.js';
7
7
  import './series-chart-ticks.js';
8
8
  import './series-chart-budget.js';
9
- import '../feedback-BxeQVzwq.js';
10
- import '../feedback-attachment-fGAzZPf0.js';
11
- import '../feedback/feedback-inbox.js';
12
- import 'lucide-react';
9
+ import '../feedback-DOwPu-Il.js';
13
10
  import './tooltip.js';
14
11
  import '../hooks/use-anchored-rect.js';
15
12
  import '../lib/clipping.js';
@@ -20,6 +17,7 @@ import './mini-calendar.js';
20
17
  import './calendar-heatmap.js';
21
18
  import './popover.js';
22
19
  import './chip.js';
20
+ import 'lucide-react';
23
21
  import './field-sync.js';
24
22
  import '../wizard/types.js';
25
23
  import '../tour/tour.js';