@eifi1/ui-kit 0.48.2 → 0.50.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 (377) hide show
  1. package/README.md +34 -16
  2. package/dist/admin/admin-action-confirm.js +1 -1
  3. package/dist/admin/admin-action-confirm.js.map +1 -1
  4. package/dist/admin/invitations-panel.js +5 -1
  5. package/dist/admin/invitations-panel.js.map +1 -1
  6. package/dist/admin/user-roster.d.ts +24 -12
  7. package/dist/admin/user-roster.js +21 -6
  8. package/dist/admin/user-roster.js.map +1 -1
  9. package/dist/auth/accept-invitation.js +2 -2
  10. package/dist/auth/accept-invitation.js.map +1 -1
  11. package/dist/auth/not-found-page.js +1 -1
  12. package/dist/auth/not-found-page.js.map +1 -1
  13. package/dist/auth/reset-password-form.js +2 -2
  14. package/dist/auth/reset-password-form.js.map +1 -1
  15. package/dist/auth/verify-email.d.ts +9 -1
  16. package/dist/auth/verify-email.js +5 -3
  17. package/dist/auth/verify-email.js.map +1 -1
  18. package/dist/billing/plan-card.js +2 -2
  19. package/dist/billing/plan-card.js.map +1 -1
  20. package/dist/components/amount-input.d.ts +2 -1
  21. package/dist/components/amount-input.js +3 -2
  22. package/dist/components/amount-input.js.map +1 -1
  23. package/dist/components/autocomplete.js +1 -0
  24. package/dist/components/autocomplete.js.map +1 -1
  25. package/dist/components/breadcrumbs.d.ts +19 -1
  26. package/dist/components/breadcrumbs.js +11 -4
  27. package/dist/components/breadcrumbs.js.map +1 -1
  28. package/dist/components/button-look.d.ts +37 -7
  29. package/dist/components/button-look.js +33 -6
  30. package/dist/components/button-look.js.map +1 -1
  31. package/dist/components/button.d.ts +4 -1
  32. package/dist/components/button.js +2 -2
  33. package/dist/components/button.js.map +1 -1
  34. package/dist/components/calendar-heatmap.js +2 -1
  35. package/dist/components/calendar-heatmap.js.map +1 -1
  36. package/dist/components/chart-edge.d.ts +10 -0
  37. package/dist/components/chart-edge.js +57 -0
  38. package/dist/components/chart-edge.js.map +1 -0
  39. package/dist/components/chart.js +2 -1
  40. package/dist/components/chart.js.map +1 -1
  41. package/dist/components/chip.d.ts +8 -1
  42. package/dist/components/chip.js +4 -1
  43. package/dist/components/chip.js.map +1 -1
  44. package/dist/components/combobox-core.js +1 -0
  45. package/dist/components/combobox-core.js.map +1 -1
  46. package/dist/components/combobox-suggestions.js +1 -0
  47. package/dist/components/combobox-suggestions.js.map +1 -1
  48. package/dist/components/confirm-context.d.ts +5 -0
  49. package/dist/components/confirm-context.js +7 -0
  50. package/dist/components/confirm-context.js.map +1 -0
  51. package/dist/components/confirm-dialog.js +3 -3
  52. package/dist/components/confirm-dialog.js.map +1 -1
  53. package/dist/components/currency-select.d.ts +28 -2
  54. package/dist/components/currency-select.js +56 -10
  55. package/dist/components/currency-select.js.map +1 -1
  56. package/dist/components/danger-confirm.d.ts +2 -2
  57. package/dist/components/danger-confirm.js +1 -1
  58. package/dist/components/danger-confirm.js.map +1 -1
  59. package/dist/components/data-table-fit.js +21 -3
  60. package/dist/components/data-table-fit.js.map +1 -1
  61. package/dist/components/data-table-mobile.d.ts +58 -3
  62. package/dist/components/data-table-mobile.js +147 -16
  63. package/dist/components/data-table-mobile.js.map +1 -1
  64. package/dist/components/data-table-row-actions.d.ts +2 -1
  65. package/dist/components/data-table-row-actions.js +7 -0
  66. package/dist/components/data-table-row-actions.js.map +1 -1
  67. package/dist/components/data-table-row.d.ts +1 -1
  68. package/dist/components/data-table-row.js.map +1 -1
  69. package/dist/components/data-table.d.ts +34 -1
  70. package/dist/components/data-table.js +37 -10
  71. package/dist/components/data-table.js.map +1 -1
  72. package/dist/components/dropdown.js +1 -0
  73. package/dist/components/dropdown.js.map +1 -1
  74. package/dist/components/error-boundary.js +2 -2
  75. package/dist/components/error-boundary.js.map +1 -1
  76. package/dist/components/floating-panel.d.ts +36 -13
  77. package/dist/components/floating-panel.js +27 -7
  78. package/dist/components/floating-panel.js.map +1 -1
  79. package/dist/components/form-actions.d.ts +1 -1
  80. package/dist/components/form-actions.js +1 -1
  81. package/dist/components/form-actions.js.map +1 -1
  82. package/dist/components/full-bleed-dialog.js +1 -0
  83. package/dist/components/full-bleed-dialog.js.map +1 -1
  84. package/dist/components/icon-button.d.ts +11 -0
  85. package/dist/components/icon-button.js +7 -5
  86. package/dist/components/icon-button.js.map +1 -1
  87. package/dist/components/modal.js +1 -0
  88. package/dist/components/modal.js.map +1 -1
  89. package/dist/components/nav-pills.d.ts +8 -1
  90. package/dist/components/nav-pills.js +61 -38
  91. package/dist/components/nav-pills.js.map +1 -1
  92. package/dist/components/number-input.d.ts +2 -1
  93. package/dist/components/number-input.js +6 -2
  94. package/dist/components/number-input.js.map +1 -1
  95. package/dist/components/numpad-sheet.js +2 -0
  96. package/dist/components/numpad-sheet.js.map +1 -1
  97. package/dist/components/page-header-context.d.ts +8 -0
  98. package/dist/components/page-header-context.js +7 -0
  99. package/dist/components/page-header-context.js.map +1 -0
  100. package/dist/components/page-header.d.ts +14 -2
  101. package/dist/components/page-header.js +10 -1
  102. package/dist/components/page-header.js.map +1 -1
  103. package/dist/components/picker-sheet.js +2 -0
  104. package/dist/components/picker-sheet.js.map +1 -1
  105. package/dist/components/pie-chart.js +2 -1
  106. package/dist/components/pie-chart.js.map +1 -1
  107. package/dist/components/popover.js +1 -0
  108. package/dist/components/popover.js.map +1 -1
  109. package/dist/components/progress-bar.js +5 -4
  110. package/dist/components/progress-bar.js.map +1 -1
  111. package/dist/components/reauth-dialog.js +1 -1
  112. package/dist/components/reauth-dialog.js.map +1 -1
  113. package/dist/components/row-actions-labels.js +3 -1
  114. package/dist/components/row-actions-labels.js.map +1 -1
  115. package/dist/components/row-actions.d.ts +43 -9
  116. package/dist/components/row-actions.js +78 -15
  117. package/dist/components/row-actions.js.map +1 -1
  118. package/dist/components/section-nav.d.ts +37 -0
  119. package/dist/components/section-nav.js +33 -0
  120. package/dist/components/section-nav.js.map +1 -0
  121. package/dist/components/series-chart.js +8 -3
  122. package/dist/components/series-chart.js.map +1 -1
  123. package/dist/components/share-card.js +1 -1
  124. package/dist/components/share-card.js.map +1 -1
  125. package/dist/components/signature-pad.js +1 -1
  126. package/dist/components/signature-pad.js.map +1 -1
  127. package/dist/components/sparkline.js +2 -1
  128. package/dist/components/sparkline.js.map +1 -1
  129. package/dist/components/stat-tile.js +14 -7
  130. package/dist/components/stat-tile.js.map +1 -1
  131. package/dist/components/status-dot.d.ts +5 -1
  132. package/dist/components/status-dot.js +4 -1
  133. package/dist/components/status-dot.js.map +1 -1
  134. package/dist/components/tooltip.js +1 -1
  135. package/dist/components/tooltip.js.map +1 -1
  136. package/dist/components/translation-review-editor.js +2 -2
  137. package/dist/components/translation-review-editor.js.map +1 -1
  138. package/dist/components/translation-review.js +2 -2
  139. package/dist/components/translation-review.js.map +1 -1
  140. package/dist/components/treemap.d.ts +5 -2
  141. package/dist/components/treemap.js +26 -6
  142. package/dist/components/treemap.js.map +1 -1
  143. package/dist/components/use-table-state.js +37 -6
  144. package/dist/components/use-table-state.js.map +1 -1
  145. package/dist/data-table.js.map +1 -1
  146. package/dist/demo/demo-banner.js +1 -1
  147. package/dist/demo/demo-banner.js.map +1 -1
  148. package/dist/demo/demo-ended.js +1 -1
  149. package/dist/demo/demo-ended.js.map +1 -1
  150. package/dist/demo/demo-start.js +1 -1
  151. package/dist/demo/demo-start.js.map +1 -1
  152. package/dist/eslint/index.js +1 -1
  153. package/dist/feedback/feedback-inbox.js +1 -1
  154. package/dist/feedback/feedback-inbox.js.map +1 -1
  155. package/dist/hooks/use-dismiss.d.ts +9 -1
  156. package/dist/hooks/use-dismiss.js +25 -5
  157. package/dist/hooks/use-dismiss.js.map +1 -1
  158. package/dist/hooks/use-document-title.d.ts +14 -0
  159. package/dist/hooks/use-document-title.js +22 -0
  160. package/dist/hooks/use-document-title.js.map +1 -0
  161. package/dist/i18n/defaults.js +2 -0
  162. package/dist/i18n/defaults.js.map +1 -1
  163. package/dist/i18n/german.js +20 -3
  164. package/dist/i18n/german.js.map +1 -1
  165. package/dist/i18n/kit-labels.d.ts +34 -1
  166. package/dist/i18n/kit-labels.js +43 -2
  167. package/dist/i18n/kit-labels.js.map +1 -1
  168. package/dist/i18n/locales/en.js +22 -3
  169. package/dist/i18n/locales/en.js.map +3 -3
  170. package/dist/i18n/locales/es.js +20 -3
  171. package/dist/i18n/locales/es.js.map +1 -1
  172. package/dist/i18n/locales/fr.js +20 -3
  173. package/dist/i18n/locales/fr.js.map +1 -1
  174. package/dist/i18n/locales/hu.js +20 -3
  175. package/dist/i18n/locales/hu.js.map +1 -1
  176. package/dist/i18n/locales/it.js +20 -3
  177. package/dist/i18n/locales/it.js.map +1 -1
  178. package/dist/i18n/locales/zh.js +20 -3
  179. package/dist/i18n/locales/zh.js.map +1 -1
  180. package/dist/i18n/review.js +3 -0
  181. package/dist/i18n/review.js.map +1 -1
  182. package/dist/i18n/shared-labels.js +1 -0
  183. package/dist/i18n/shared-labels.js.map +1 -1
  184. package/dist/index.d.ts +8 -1
  185. package/dist/index.js +11 -0
  186. package/dist/index.js.map +1 -1
  187. package/dist/landing/landing-actions.js +2 -2
  188. package/dist/landing/landing-actions.js.map +1 -1
  189. package/dist/landing/public-header.js +2 -2
  190. package/dist/landing/public-header.js.map +1 -1
  191. package/dist/lib/clipboard-minus.d.ts +27 -0
  192. package/dist/lib/clipboard-minus.js +63 -0
  193. package/dist/lib/clipboard-minus.js.map +1 -0
  194. package/dist/lib/data-attributes.d.ts +11 -0
  195. package/dist/lib/data-attributes.js +10 -0
  196. package/dist/lib/data-attributes.js.map +1 -0
  197. package/dist/lib/document-title.d.ts +17 -0
  198. package/dist/lib/document-title.js +29 -0
  199. package/dist/lib/document-title.js.map +1 -0
  200. package/dist/lib/float-clearance.js +8 -2
  201. package/dist/lib/float-clearance.js.map +1 -1
  202. package/dist/lib/format.d.ts +36 -10
  203. package/dist/lib/format.js +57 -11
  204. package/dist/lib/format.js.map +1 -1
  205. package/dist/lib/minus.d.ts +32 -0
  206. package/dist/lib/minus.js +14 -0
  207. package/dist/lib/minus.js.map +1 -0
  208. package/dist/lib/status-tone.d.ts +30 -0
  209. package/dist/lib/status-tone.js +17 -0
  210. package/dist/lib/status-tone.js.map +1 -0
  211. package/dist/settings/settings-layout.js +3 -2
  212. package/dist/settings/settings-layout.js.map +1 -1
  213. package/dist/shell/account-menu-language.d.ts +1 -1
  214. package/dist/shell/account-menu-language.js +9 -1
  215. package/dist/shell/account-menu-language.js.map +1 -1
  216. package/dist/shell/app-shell-labels.js +2 -1
  217. package/dist/shell/app-shell-labels.js.map +1 -1
  218. package/dist/shell/app-shell.d.ts +58 -16
  219. package/dist/shell/app-shell.js +151 -43
  220. package/dist/shell/app-shell.js.map +1 -1
  221. package/dist/shell/language-code.d.ts +3 -0
  222. package/dist/shell/language-code.js +8 -0
  223. package/dist/shell/language-code.js.map +1 -0
  224. package/dist/shell/topbar-controls.d.ts +14 -6
  225. package/dist/shell/topbar-controls.js +14 -17
  226. package/dist/shell/topbar-controls.js.map +1 -1
  227. package/dist/testing/css-variables.generated.d.ts +1 -1
  228. package/dist/testing/css-variables.generated.js +1 -1
  229. package/dist/testing/css-variables.generated.js.map +1 -1
  230. package/dist/testing/react.d.ts +25 -0
  231. package/dist/testing/react.js +19 -0
  232. package/dist/testing/react.js.map +1 -0
  233. package/dist/theme/chart-palette.d.ts +82 -15
  234. package/dist/theme/chart-palette.js +51 -24
  235. package/dist/theme/chart-palette.js.map +1 -1
  236. package/dist/theme/palette-presets.d.ts +9 -0
  237. package/dist/theme/palette-presets.js +77 -62
  238. package/dist/theme/palette-presets.js.map +1 -1
  239. package/dist/tour/tour-dock.d.ts +42 -0
  240. package/dist/tour/tour-dock.js +80 -0
  241. package/dist/tour/tour-dock.js.map +1 -0
  242. package/dist/tour/tour-gates.d.ts +71 -0
  243. package/dist/tour/tour-gates.js +114 -0
  244. package/dist/tour/tour-gates.js.map +1 -0
  245. package/dist/tour/tour-guide-button.d.ts +27 -0
  246. package/dist/tour/tour-guide-button.js +45 -0
  247. package/dist/tour/tour-guide-button.js.map +1 -0
  248. package/dist/tour/tour-guide-labels.d.ts +8 -0
  249. package/dist/tour/tour-guide-labels.js +9 -0
  250. package/dist/tour/tour-guide-labels.js.map +1 -0
  251. package/dist/tour/tour-labels.js +9 -1
  252. package/dist/tour/tour-labels.js.map +1 -1
  253. package/dist/tour/tour.d.ts +133 -9
  254. package/dist/tour/tour.js +594 -70
  255. package/dist/tour/tour.js.map +1 -1
  256. package/dist/tour/use-tour-url-sync.d.ts +5 -2
  257. package/dist/tour/use-tour-url-sync.js +7 -1
  258. package/dist/tour/use-tour-url-sync.js.map +1 -1
  259. package/dist/tour.d.ts +2 -0
  260. package/dist/tour.js +3 -0
  261. package/dist/tour.js.map +1 -1
  262. package/dist/wizard/stepper-nav.d.ts +1 -1
  263. package/dist/wizard/stepper-nav.js +18 -5
  264. package/dist/wizard/stepper-nav.js.map +1 -1
  265. package/dist/wizard/types.d.ts +11 -0
  266. package/dist/wizard/types.js.map +1 -1
  267. package/dist/wizard/use-wizard.js +11 -5
  268. package/dist/wizard/use-wizard.js.map +1 -1
  269. package/package.json +9 -1
  270. package/src/admin/admin-action-confirm.tsx +1 -1
  271. package/src/admin/invitations-panel.tsx +7 -3
  272. package/src/admin/user-roster.tsx +41 -14
  273. package/src/auth/accept-invitation.tsx +3 -3
  274. package/src/auth/not-found-page.tsx +1 -1
  275. package/src/auth/reset-password-form.tsx +3 -3
  276. package/src/auth/verify-email.tsx +13 -3
  277. package/src/billing/plan-card.tsx +2 -2
  278. package/src/components/amount-input.tsx +5 -4
  279. package/src/components/autocomplete.tsx +2 -0
  280. package/src/components/breadcrumbs.tsx +32 -4
  281. package/src/components/button-look.ts +86 -15
  282. package/src/components/button.tsx +6 -3
  283. package/src/components/calendar-heatmap.tsx +2 -1
  284. package/src/components/chart-edge.ts +73 -0
  285. package/src/components/chart.tsx +3 -1
  286. package/src/components/chip.tsx +10 -1
  287. package/src/components/combobox-core.tsx +2 -0
  288. package/src/components/combobox-suggestions.tsx +2 -0
  289. package/src/components/confirm-context.ts +7 -0
  290. package/src/components/confirm-dialog.tsx +3 -3
  291. package/src/components/currency-select.tsx +95 -6
  292. package/src/components/danger-confirm.tsx +3 -3
  293. package/src/components/data-table-fit.ts +41 -6
  294. package/src/components/data-table-mobile.tsx +259 -17
  295. package/src/components/data-table-row-actions.tsx +9 -1
  296. package/src/components/data-table-row.tsx +3 -0
  297. package/src/components/data-table.tsx +91 -19
  298. package/src/components/dropdown.tsx +2 -0
  299. package/src/components/error-boundary.tsx +2 -2
  300. package/src/components/floating-panel.tsx +67 -16
  301. package/src/components/form-actions.tsx +2 -2
  302. package/src/components/full-bleed-dialog.tsx +3 -0
  303. package/src/components/icon-button.tsx +21 -8
  304. package/src/components/modal.tsx +3 -0
  305. package/src/components/nav-pills.tsx +29 -2
  306. package/src/components/number-input.tsx +8 -3
  307. package/src/components/numpad-sheet.tsx +4 -0
  308. package/src/components/page-header-context.ts +8 -0
  309. package/src/components/page-header.tsx +34 -2
  310. package/src/components/picker-sheet.tsx +4 -0
  311. package/src/components/pie-chart.tsx +2 -1
  312. package/src/components/popover.tsx +2 -0
  313. package/src/components/progress-bar.tsx +6 -3
  314. package/src/components/reauth-dialog.tsx +1 -1
  315. package/src/components/row-actions-labels.ts +2 -0
  316. package/src/components/row-actions.tsx +154 -33
  317. package/src/components/section-nav.tsx +65 -0
  318. package/src/components/series-chart.tsx +12 -3
  319. package/src/components/share-card.tsx +1 -1
  320. package/src/components/signature-pad.tsx +1 -1
  321. package/src/components/sparkline.tsx +2 -1
  322. package/src/components/stat-tile.tsx +19 -7
  323. package/src/components/status-dot.tsx +7 -1
  324. package/src/components/tooltip.tsx +3 -1
  325. package/src/components/translation-review-editor.tsx +2 -2
  326. package/src/components/translation-review.tsx +2 -2
  327. package/src/components/treemap.tsx +34 -8
  328. package/src/components/use-table-state.ts +63 -8
  329. package/src/data-table.ts +3 -3
  330. package/src/demo/demo-banner.tsx +1 -1
  331. package/src/demo/demo-ended.tsx +1 -1
  332. package/src/demo/demo-start.tsx +1 -1
  333. package/src/feedback/feedback-inbox.tsx +1 -1
  334. package/src/hooks/use-dismiss.ts +43 -4
  335. package/src/hooks/use-document-title.ts +31 -0
  336. package/src/i18n/defaults.ts +2 -0
  337. package/src/i18n/german.ts +17 -0
  338. package/src/i18n/kit-labels.tsx +79 -1
  339. package/src/i18n/locales/es.ts +17 -0
  340. package/src/i18n/locales/fr.ts +17 -0
  341. package/src/i18n/locales/hu.ts +17 -0
  342. package/src/i18n/locales/it.ts +17 -0
  343. package/src/i18n/locales/zh.ts +17 -0
  344. package/src/i18n/review.ts +3 -0
  345. package/src/i18n/shared-labels.ts +1 -0
  346. package/src/index.ts +13 -0
  347. package/src/landing/landing-actions.tsx +2 -2
  348. package/src/landing/public-header.tsx +2 -2
  349. package/src/lib/clipboard-minus.ts +94 -0
  350. package/src/lib/data-attributes.ts +14 -0
  351. package/src/lib/document-title.ts +41 -0
  352. package/src/lib/float-clearance.ts +19 -3
  353. package/src/lib/format.ts +117 -30
  354. package/src/lib/minus.ts +50 -0
  355. package/src/lib/status-tone.ts +43 -0
  356. package/src/settings/settings-layout.tsx +3 -2
  357. package/src/shell/account-menu-language.tsx +14 -2
  358. package/src/shell/app-shell-labels.ts +1 -0
  359. package/src/shell/app-shell.tsx +291 -68
  360. package/src/shell/language-code.ts +5 -0
  361. package/src/shell/topbar-controls.tsx +35 -15
  362. package/src/testing/css-variables.generated.ts +6 -6
  363. package/src/testing/react.ts +59 -0
  364. package/src/theme/chart-palette.ts +102 -20
  365. package/src/theme/palette-presets.ts +121 -84
  366. package/src/tour/tour-dock.ts +132 -0
  367. package/src/tour/tour-gates.ts +195 -0
  368. package/src/tour/tour-guide-button.tsx +64 -0
  369. package/src/tour/tour-guide-labels.ts +15 -0
  370. package/src/tour/tour-labels.ts +8 -0
  371. package/src/tour/tour.tsx +949 -86
  372. package/src/tour/use-tour-url-sync.ts +14 -4
  373. package/src/tour.ts +3 -0
  374. package/src/wizard/stepper-nav.tsx +27 -7
  375. package/src/wizard/types.ts +12 -0
  376. package/src/wizard/use-wizard.ts +16 -9
  377. package/tokens.css +28 -18
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/danger-confirm.tsx"],"sourcesContent":["import { Children, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithRef, FormEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { hasContent } from \"../lib/presence\";\nimport { useKitLabels, type LabelOverride } from \"../i18n/kit-labels\";\nimport { Button } from \"./button\";\nimport { Input } from \"./input\";\nimport { Label } from \"./field-base\";\nimport { Spinner } from \"./spinner\";\nimport type { ButtonVariant } from \"./button-look\";\nimport type { InputProps } from \"./input\";\nimport { Checkbox } from \"./checkbox\";\nimport { Tooltip } from \"./tooltip\";\nimport { useCommitReason, type CommitScope } from \"./write-lock\";\nimport { DEFAULT_DANGER_CONFIRM_LABELS } from \"./danger-confirm-labels\";\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\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 * label), 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?: LabelOverride<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 `RhfField` / a\n * `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 function CurrentPasswordInput({\n label,\n onValueChange,\n onChange,\n busy,\n readOnly,\n labels: labelsProp,\n ...rest\n}: CurrentPasswordInputProps) {\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 // `ref` (the `<input>`) rides along: a React 19 ref prop since 0.34 (MOD-4, refactor\n // audit 2026-10), where this was `forwardRef`.\n {...rest}\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\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?: LabelOverride<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 function TypedConfirmField({\n ref,\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}: TypedConfirmFieldProps) {\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}\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// Defined in ./danger-confirm-labels, which holds no component code (0.34, KS U8).\nexport { DEFAULT_DANGER_CONFIRM_LABELS };\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<ComponentPropsWithRef<\"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?: CommitScope;\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?: LabelOverride<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-warning\" : \"text-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-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-secondary\">\n {lines.map((line) => (\n <li key={line.key} className={line.severe ? \"text-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-muted\">{lockedReason}</p>}\n </form>\n </div>\n );\n}\n"],"mappings":";AAmJI,SA8qBQ,UA9qBR,KA+IE,YA/IF;AAnJJ,SAAS,UAAU,aAAa,WAAW,OAAO,QAAQ,gBAAgB;AAE1E,SAAS,UAAU;AACnB,SAAS,kBAAkB;AAC3B,SAAS,oBAAwC;AACjD,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,eAAe;AAGxB,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,uBAAyC;AAClD,SAAS,qCAAqC;AAoBvC,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,MAC3B,MAAM;AACJ,YAAI,CAAC,QAAQ,QAAS;AACtB,mBAAW,KAAK;AAChB,mBAAW;AAAA,MACb;AAAA,MACA,MAAM;AACJ,YAAI,QAAQ,QAAS,YAAW,KAAK;AAAA,MACvC;AAAA,IACF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,QAED,mBACC;AAAA,UAAC;AAAA;AAAA,YACC,KAAK,eAAe,gBAAgB,gBAAgB;AAAA,YACpD,OAAO;AAAA,YACP,SAAS;AAAA,YAGT,iBAAiB,CAAC,SAAS;AACzB,kBAAI,CAAC,KAAM,iBAAgB,IAAI;AAAA,YACjC;AAAA;AAAA,QACF;AAAA,QAED,WAAW,UACV;AAAA,UAAC;AAAA;AAAA,YACC,KAAK,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,sBAAsB,wBAAa;AAAA;AAAA;AAAA,EAC7D,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/danger-confirm.tsx"],"sourcesContent":["import { Children, useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { ChangeEvent, ComponentPropsWithRef, FormEvent, ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { hasContent } from \"../lib/presence\";\nimport { useKitLabels, type LabelOverride } from \"../i18n/kit-labels\";\nimport { Button } from \"./button\";\nimport { Input } from \"./input\";\nimport { Label } from \"./field-base\";\nimport { Spinner } from \"./spinner\";\nimport type { ButtonVariant } from \"./button-look\";\nimport type { InputProps } from \"./input\";\nimport { Checkbox } from \"./checkbox\";\nimport { Tooltip } from \"./tooltip\";\nimport { useCommitReason, type CommitScope } from \"./write-lock\";\nimport { DEFAULT_DANGER_CONFIRM_LABELS } from \"./danger-confirm-labels\";\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\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 * label), 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?: LabelOverride<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 `RhfField` / a\n * `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 function CurrentPasswordInput({\n label,\n onValueChange,\n onChange,\n busy,\n readOnly,\n labels: labelsProp,\n ...rest\n}: CurrentPasswordInputProps) {\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 // `ref` (the `<input>`) rides along: a React 19 ref prop since 0.34 (MOD-4, refactor\n // audit 2026-10), where this was `forwardRef`.\n {...rest}\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\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?: LabelOverride<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 function TypedConfirmField({\n ref,\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}: TypedConfirmFieldProps) {\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}\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// Defined in ./danger-confirm-labels, which holds no component code (0.34, KS U8).\nexport { DEFAULT_DANGER_CONFIRM_LABELS };\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<ComponentPropsWithRef<\"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\"`, `\"default\"` 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 `default` 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?: CommitScope;\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?: LabelOverride<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-warning\" : \"text-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-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-secondary\">\n {lines.map((line) => (\n <li key={line.key} className={line.severe ? \"text-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\" ? \"default\" : \"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-muted\">{lockedReason}</p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M,iBAAgB,IAAI;AAAA,YACjC;AAAA;AAAA,QACF;AAAA,QAED,WAAW,UACV;AAAA,UAAC;AAAA;AAAA,YACC,KAAK,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,sBAAsB,wBAAa;AAAA;AAAA;AAAA,EAC7D,GACF;AAEJ;","names":[]}
@@ -18,6 +18,8 @@ function useColumnFit({
18
18
  const [kept, setKept] = useState(() => /* @__PURE__ */ new Set());
19
19
  const [hidden, setHidden] = useState([]);
20
20
  const ownWidth = useRef(/* @__PURE__ */ new Map());
21
+ const stuck = useRef(/* @__PURE__ */ new Map());
22
+ const lastShown = useRef(null);
21
23
  const hasFit = columns.some((c) => c.fitPriority != null);
22
24
  const active = enabled && hasFit;
23
25
  const order = useMemo(
@@ -35,6 +37,9 @@ function useColumnFit({
35
37
  });
36
38
  const measure = useCallback(() => {
37
39
  const { order: order2, current: current2, growKey: growKey2, active: active2, scroller: scroller2 } = latest.current;
40
+ const flip = lastShown.current;
41
+ lastShown.current = null;
42
+ for (const k of stuck.current.keys()) if (!current2.includes(k)) stuck.current.delete(k);
38
43
  const el = scroller2();
39
44
  if (!active2 || !el) return;
40
45
  const table = el.querySelector("table");
@@ -59,17 +64,30 @@ function useColumnFit({
59
64
  need -= w;
60
65
  next.push(col.key);
61
66
  }
62
- if (next.length !== current2.length) setHidden(next);
67
+ if (next.length === current2.length) return;
68
+ if (flip && Math.abs(flip.avail - avail) <= 0.5)
69
+ for (const k of next.slice(current2.length)) {
70
+ const room = flip.rooms.get(k);
71
+ if (room != null) stuck.current.set(k, room);
72
+ }
73
+ setHidden(next);
63
74
  return;
64
75
  }
65
76
  let n = current2.length;
77
+ const rooms = /* @__PURE__ */ new Map();
66
78
  while (n > 0) {
67
- const w = ownWidth.current.get(current2[n - 1]);
79
+ const k = current2[n - 1];
80
+ const w = ownWidth.current.get(k);
68
81
  if (w == null || need + w > avail + 0.5) break;
82
+ const room = stuck.current.get(k);
83
+ if (room != null && avail - need <= room + 0.5) break;
84
+ rooms.set(k, avail - need);
69
85
  need += w;
70
86
  n--;
71
87
  }
72
- if (n !== current2.length) setHidden(current2.slice(0, n));
88
+ if (n === current2.length) return;
89
+ lastShown.current = { avail, rooms };
90
+ setHidden(current2.slice(0, n));
73
91
  }, [headRefs]);
74
92
  const lastContent = useRef(null);
75
93
  useLayoutEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/data-table-fit.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { DataTableColumn } from \"./data-table\";\n\n// DataTable's fit to its own width (0.48, keksdose live #451: \"On expanded sidebar for\n// desktop the table scrolls horizontally. On collapsed sidebar it fits […] Compute the\n// width selectively\"). Two column options, both opt-in:\n//\n// - `grow`: the column takes what the others leave and ellipsises (`w-full max-w-0` on\n// its cells: in an auto table layout that is \"the rest of the row\", never its content's\n// width), so one long title can no longer widen the table.\n// - `fitPriority`: while the table is wider than its scroller — or, with a `grow` column,\n// while that column would get less than {@link GROW_MIN_REM} — the table leaves out\n// its `fitPriority` columns, the LOWEST number first (ties: the later column first),\n// and brings them back in the reverse order as soon as the table, as it is NOW, has\n// room for them (its need re-measured, plus the column's own header width from when\n// it was left out), so narrower content (a filter, another page) counts as much as a\n// wider scroller. The scroller's own width, through a ResizeObserver: a sidebar, a\n// narrower window, the Columns drawer and Large text all count the same.\n\n/** The least a `grow` column keeps before the table starts leaving columns out: about\n * a sentence of a title. In rem, so Large text asks for more. */\nexport const GROW_MIN_REM = 10;\n\n/** The `<th>`/`<td>` classes of a `grow` column. `truncate-until-large`: one line and an\n * ellipsis at Normal, a wrap from Large up (text size §10.17), as every kit title. The\n * header's `min-w-[10rem]` ({@link GROW_MIN_REM}) is the floor once no `fitPriority`\n * column is left to leave out: the table then scrolls sideways rather than crushing the\n * column it exists for (Kurvenschmiede S1, 0.48: Subject was 24px at 1100px). */\nexport const GROW_HEAD_CLASS = \"w-full max-w-0 min-w-[10rem]\";\nexport const GROW_CELL_CLASS = \"w-full max-w-0 truncate-until-large\";\n\n/** Every OTHER cell of a table with a `grow` column (kastlan S2, 0.48). A `w-full` column\n * squeezes the rest to their min-content width, so any text with a space broke in two\n * even at 1920px (\"CHF 2'568.38\", \"Peter Mueller\", a date with its time). One line at\n * Normal, so a column is never narrower than its text and `fitPriority` measures what\n * the columns really need; from Large up the cell wraps as before (§10.17). The headers\n * are `whitespace-nowrap` already. A column whose prose should wrap anyway passes\n * `not-large:whitespace-normal` in its `className`. */\nexport const GROW_PEER_CELL_CLASS = \"not-large:whitespace-nowrap\";\n\n// A cell's own flex-wrap row (chips) is left to wrap beside a `grow` column: a row of\n// badges reads as well stacked, and held to one line it widened the user roster's Status\n// until kastlan's admin pane scrolled 21px at 1280px (0.48 build review 2, kastlan S1).\n\n/** The auto-hide order: lowest `fitPriority` first, the later column first on a tie. */\nexport function fitHideOrder<T>(columns: DataTableColumn<T>[]): DataTableColumn<T>[] {\n return columns\n .map((col, index) => ({ col, index }))\n .filter(({ col }) => col.fitPriority != null)\n .sort((a, b) => a.col.fitPriority! - b.col.fitPriority! || b.index - a.index)\n .map(({ col }) => col);\n}\n\n/**\n * Which columns the table leaves out for width, and the Columns panel's \"keep it\".\n *\n * A column the user TICKS in the Columns panel is theirs: it is never left out for width\n * again while the table is mounted (`keep`): the table makes room by leaving out the next\n * candidate, and scrolls sideways once none is left — what they asked for. Unticking it hides it as before (the persisted `hiddenCols`) and\n * drops the keep. Keeps are not persisted: on the next visit the table fits again.\n */\nexport function useColumnFit<T>({\n columns,\n hiddenCols,\n headRefs,\n scroller,\n enabled,\n content,\n}: {\n columns: DataTableColumn<T>[];\n /** The user's hidden columns: never candidates (they are out already). */\n hiddenCols: Set<string>;\n headRefs: Map<string, HTMLTableCellElement>;\n /** The desktop scroller, read after render (it is declared below the call). */\n scroller: () => HTMLElement | null;\n /** The wide layout. On a phone (the card list) nothing is left out for width. */\n enabled: boolean;\n /**\n * What can change the columns' widths besides the scroller (0.48.2): the rows on\n * screen, the columns, the stored widths, the text size. Compared item by item after\n * each render, and the table is measured only when one changed — a selection tick no\n * longer forces a layout of the whole table. Without it, every render measures.\n */\n content?: readonly unknown[];\n}): {\n /** The columns left out for width now — empty while off. */\n autoHidden: Set<string>;\n /** The user's choice in the Columns panel: `true` keeps the column in whatever the width. */\n keep: (key: string, on: boolean) => void;\n} {\n const [kept, setKept] = useState<ReadonlySet<string>>(() => new Set());\n const [hidden, setHidden] = useState<string[]>([]);\n // A column's own header width, written when it is left out: it comes back once the\n // table's need as it is now, plus this, fits the scroller (keksdose S3, 0.48: not the\n // whole table's need at hide time, which went stale when the content narrowed).\n const ownWidth = useRef(new Map<string, number>());\n\n const hasFit = columns.some((c) => c.fitPriority != null);\n const active = enabled && hasFit;\n const order = useMemo(\n () => fitHideOrder(columns).filter((c) => !hiddenCols.has(c.key) && !kept.has(c.key)),\n [columns, hiddenCols, kept],\n );\n // Only the candidates still in play, in hide order — a column the user hid or kept\n // since, or one the app dropped, is no longer \"hidden for width\".\n const current = useMemo(\n () => (active ? order.filter((c) => hidden.includes(c.key)).map((c) => c.key) : []),\n [active, order, hidden],\n );\n const growKey = columns.find((c) => c.grow && !hiddenCols.has(c.key))?.key;\n\n // What `measure` reads, refreshed after each render (before the measure below runs):\n // the ResizeObserver's callback is set up once and must see the current columns.\n const latest = useRef({ order, current, growKey, active, scroller });\n useLayoutEffect(() => {\n latest.current = { order, current, growKey, active, scroller };\n });\n\n const measure = useCallback(() => {\n const { order, current, growKey, active, scroller } = latest.current;\n const el = scroller();\n if (!active || !el) return;\n const table = el.querySelector(\"table\");\n const avail = el.clientWidth;\n // Not laid out (display:none, jsdom): nothing to fit to.\n if (!table || avail <= 0) return;\n const growTh = growKey ? headRefs.get(growKey) : undefined;\n const rem = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;\n let need = growTh\n ? table.offsetWidth - growTh.offsetWidth + GROW_MIN_REM * rem\n : table.offsetWidth;\n if (!growTh && need <= avail + 0.5 && current.length > 0) {\n // A `w-full` table is at least the scroller's width, which says nothing about how\n // much room its content leaves: probe its content's width (what it takes once it\n // overflows) for the bring-back below. Read and put back in one layout pass.\n const before = table.style.width;\n table.style.width = \"min-content\";\n need = table.offsetWidth;\n table.style.width = before;\n }\n if (need > avail + 0.5) {\n // Leave out, in order, until the rest fits: each column saves its header's width\n // (the others are at their content's width while a `grow` column takes the rest).\n const next = [...current];\n for (const col of order) {\n if (need <= avail + 0.5) break;\n if (next.includes(col.key)) continue;\n const w = headRefs.get(col.key)?.offsetWidth ?? 0;\n ownWidth.current.set(col.key, w);\n need -= w;\n next.push(col.key);\n }\n if (next.length !== current.length) setHidden(next);\n return;\n }\n // Bring back, the last left out first, while the table as it is now has room for\n // them. Should the column have grown since (wider content), the next measure leaves\n // it out again before paint and records its new width, so it cannot flicker.\n let n = current.length;\n while (n > 0) {\n const w = ownWidth.current.get(current[n - 1]);\n if (w == null || need + w > avail + 0.5) break;\n need += w;\n n--;\n }\n if (n !== current.length) setHidden(current.slice(0, n));\n }, [headRefs]);\n\n // After a render that changed what is drawn: rows, a filter or a page can widen a\n // column as much as a resize. Before paint, so a column the table cannot hold is never\n // drawn first. A render that changed none of it (a ticked box, a focused row) skips the\n // measure, which forces a layout of the whole table (0.48.2, keksdose dev #632).\n const lastContent = useRef<readonly unknown[] | null>(null);\n useLayoutEffect(() => {\n const now = content ? [...content, order, current, growKey, active] : null;\n const prev = lastContent.current;\n lastContent.current = now;\n if (now && prev && prev.length === now.length && prev.every((v, i) => Object.is(v, now[i]))) return;\n measure();\n });\n\n useEffect(() => {\n const el = latest.current.scroller();\n if (!active || !el || typeof ResizeObserver === \"undefined\") return;\n const ro = new ResizeObserver(() => measure());\n ro.observe(el);\n return () => ro.disconnect();\n }, [active, measure]);\n\n const keep = useCallback((key: string, on: boolean) => {\n setKept((s) => {\n if (s.has(key) === on) return s;\n const next = new Set(s);\n if (on) next.add(key);\n else next.delete(key);\n return next;\n });\n }, []);\n\n const autoHidden = useMemo(() => new Set(current), [current]);\n return { autoHidden, keep };\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,iBAAiB,SAAS,QAAQ,gBAAgB;AAqB5E,MAAM,eAAe;AAOrB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AASxB,MAAM,uBAAuB;AAO7B,SAAS,aAAgB,SAAqD;AACnF,SAAO,QACJ,IAAI,CAAC,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,EACpC,OAAO,CAAC,EAAE,IAAI,MAAM,IAAI,eAAe,IAAI,EAC3C,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,cAAe,EAAE,IAAI,eAAgB,EAAE,QAAQ,EAAE,KAAK,EAC3E,IA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AAC,GAAG,SAAS,OAAO,SAAS,SAAS,MAAM,IAAI;AACtE,UAAM,OAAO,YAAY;AACzB,gBAAY,UAAU;AACtB,QAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,UAAU,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAG;AAC7F,YAAQ;AAAA,EACV,CAAC;AAED,YAAU,MAAM;AACd,UAAM,KAAK,OAAO,QAAQ,SAAS;AACnC,QAAI,CAAC,UAAU,CAAC,MAAM,OAAO,mBAAmB,YAAa;AAC7D,UAAM,KAAK,IAAI,eAAe,MAAM,QAAQ,CAAC;AAC7C,OAAG,QAAQ,EAAE;AACb,WAAO,MAAM,GAAG,WAAW;AAAA,EAC7B,GAAG,CAAC,QAAQ,OAAO,CAAC;AAEpB,QAAM,OAAO,YAAY,CAAC,KAAa,OAAgB;AACrD,YAAQ,CAAC,MAAM;AACb,UAAI,EAAE,IAAI,GAAG,MAAM,GAAI,QAAO;AAC9B,YAAM,OAAO,IAAI,IAAI,CAAC;AACtB,UAAI,GAAI,MAAK,IAAI,GAAG;AAAA,UACf,MAAK,OAAO,GAAG;AACpB,aAAO;AAAA,IACT,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,QAAQ,MAAM,IAAI,IAAI,OAAO,GAAG,CAAC,OAAO,CAAC;AAC5D,SAAO,EAAE,YAAY,KAAK;AAC5B;","names":["order","current","growKey","active","scroller"]}
1
+ {"version":3,"sources":["../../src/components/data-table-fit.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { DataTableColumn } from \"./data-table\";\n\n// DataTable's fit to its own width (0.48, keksdose live #451: \"On expanded sidebar for\n// desktop the table scrolls horizontally. On collapsed sidebar it fits […] Compute the\n// width selectively\"). Two column options, both opt-in:\n//\n// - `grow`: the column takes what the others leave and ellipsises (`w-full max-w-0` on\n// its cells: in an auto table layout that is \"the rest of the row\", never its content's\n// width), so one long title can no longer widen the table.\n// - `fitPriority`: while the table is wider than its scroller — or, with a `grow` column,\n// while that column would get less than {@link GROW_MIN_REM} — the table leaves out\n// its `fitPriority` columns, the LOWEST number first (ties: the later column first),\n// and brings them back in the reverse order as soon as the table, as it is NOW, has\n// room for them (its need re-measured, plus the column's own header width from when\n// it was left out), so narrower content (a filter, another page) counts as much as a\n// wider scroller. The scroller's own width, through a ResizeObserver: a sidebar, a\n// narrower window, the Columns drawer and Large text all count the same. A column\n// whose return the very next measure undoes stays out until the table has more room\n// for it than it had then (0.48.3, keksdose B2: see the bring-back in `measure`).\n\n/** The least a `grow` column keeps before the table starts leaving columns out: about\n * a sentence of a title. In rem, so Large text asks for more. */\nexport const GROW_MIN_REM = 10;\n\n/** The `<th>`/`<td>` classes of a `grow` column. `truncate-until-large`: one line and an\n * ellipsis at Normal, a wrap from Large up (text size §10.17), as every kit title. The\n * header's `min-w-[10rem]` ({@link GROW_MIN_REM}) is the floor once no `fitPriority`\n * column is left to leave out: the table then scrolls sideways rather than crushing the\n * column it exists for (Kurvenschmiede S1, 0.48: Subject was 24px at 1100px). */\nexport const GROW_HEAD_CLASS = \"w-full max-w-0 min-w-[10rem]\";\nexport const GROW_CELL_CLASS = \"w-full max-w-0 truncate-until-large\";\n\n/** Every OTHER cell of a table with a `grow` column (kastlan S2, 0.48). A `w-full` column\n * squeezes the rest to their min-content width, so any text with a space broke in two\n * even at 1920px (\"CHF 2'568.38\", \"Peter Mueller\", a date with its time). One line at\n * Normal, so a column is never narrower than its text and `fitPriority` measures what\n * the columns really need; from Large up the cell wraps as before (§10.17). The headers\n * are `whitespace-nowrap` already. A column whose prose should wrap anyway passes\n * `not-large:whitespace-normal` in its `className`. */\nexport const GROW_PEER_CELL_CLASS = \"not-large:whitespace-nowrap\";\n\n// A cell's own flex-wrap row (chips) is left to wrap beside a `grow` column: a row of\n// badges reads as well stacked, and held to one line it widened the user roster's Status\n// until kastlan's admin pane scrolled 21px at 1280px (0.48 build review 2, kastlan S1).\n\n/** The auto-hide order: lowest `fitPriority` first, the later column first on a tie. */\nexport function fitHideOrder<T>(columns: DataTableColumn<T>[]): DataTableColumn<T>[] {\n return columns\n .map((col, index) => ({ col, index }))\n .filter(({ col }) => col.fitPriority != null)\n .sort((a, b) => a.col.fitPriority! - b.col.fitPriority! || b.index - a.index)\n .map(({ col }) => col);\n}\n\n/**\n * Which columns the table leaves out for width, and the Columns panel's \"keep it\".\n *\n * A column the user TICKS in the Columns panel is theirs: it is never left out for width\n * again while the table is mounted (`keep`): the table makes room by leaving out the next\n * candidate, and scrolls sideways once none is left — what they asked for. Unticking it hides it as before (the persisted `hiddenCols`) and\n * drops the keep. Keeps are not persisted: on the next visit the table fits again.\n */\nexport function useColumnFit<T>({\n columns,\n hiddenCols,\n headRefs,\n scroller,\n enabled,\n content,\n}: {\n columns: DataTableColumn<T>[];\n /** The user's hidden columns: never candidates (they are out already). */\n hiddenCols: Set<string>;\n headRefs: Map<string, HTMLTableCellElement>;\n /** The desktop scroller, read after render (it is declared below the call). */\n scroller: () => HTMLElement | null;\n /** The wide layout. On a phone (the card list) nothing is left out for width. */\n enabled: boolean;\n /**\n * What can change the columns' widths besides the scroller (0.48.2): the rows on\n * screen, the columns, the stored widths, the text size. Compared item by item after\n * each render, and the table is measured only when one changed — a selection tick no\n * longer forces a layout of the whole table. Without it, every render measures.\n */\n content?: readonly unknown[];\n}): {\n /** The columns left out for width now — empty while off. */\n autoHidden: Set<string>;\n /** The user's choice in the Columns panel: `true` keeps the column in whatever the width. */\n keep: (key: string, on: boolean) => void;\n} {\n const [kept, setKept] = useState<ReadonlySet<string>>(() => new Set());\n const [hidden, setHidden] = useState<string[]>([]);\n // A column's own header width, written when it is left out: it comes back once the\n // table's need as it is now, plus this, fits the scroller (keksdose S3, 0.48: not the\n // whole table's need at hide time, which went stale when the content narrowed).\n const ownWidth = useRef(new Map<string, number>());\n // A column whose return the very next measure undid, at the same scroller width: the\n // room the table had for it when it came back (keksdose B2, 0.48.3). It stays out\n // until the table has more. Dropped once the column is no longer left out for width.\n const stuck = useRef(new Map<string, number>());\n // What the last measure brought back, each column with the room it had then, and at\n // which scroller width: read (and cleared) by the measure right after it.\n const lastShown = useRef<{ avail: number; rooms: Map<string, number> } | null>(null);\n\n const hasFit = columns.some((c) => c.fitPriority != null);\n const active = enabled && hasFit;\n const order = useMemo(\n () => fitHideOrder(columns).filter((c) => !hiddenCols.has(c.key) && !kept.has(c.key)),\n [columns, hiddenCols, kept],\n );\n // Only the candidates still in play, in hide order — a column the user hid or kept\n // since, or one the app dropped, is no longer \"hidden for width\".\n const current = useMemo(\n () => (active ? order.filter((c) => hidden.includes(c.key)).map((c) => c.key) : []),\n [active, order, hidden],\n );\n const growKey = columns.find((c) => c.grow && !hiddenCols.has(c.key))?.key;\n\n // What `measure` reads, refreshed after each render (before the measure below runs):\n // the ResizeObserver's callback is set up once and must see the current columns.\n const latest = useRef({ order, current, growKey, active, scroller });\n useLayoutEffect(() => {\n latest.current = { order, current, growKey, active, scroller };\n });\n\n const measure = useCallback(() => {\n const { order, current, growKey, active, scroller } = latest.current;\n // Only the measure right after a bring-back can undo it.\n const flip = lastShown.current;\n lastShown.current = null;\n for (const k of stuck.current.keys()) if (!current.includes(k)) stuck.current.delete(k);\n const el = scroller();\n if (!active || !el) return;\n const table = el.querySelector(\"table\");\n const avail = el.clientWidth;\n // Not laid out (display:none, jsdom): nothing to fit to.\n if (!table || avail <= 0) return;\n const growTh = growKey ? headRefs.get(growKey) : undefined;\n const rem = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;\n let need = growTh\n ? table.offsetWidth - growTh.offsetWidth + GROW_MIN_REM * rem\n : table.offsetWidth;\n if (!growTh && need <= avail + 0.5 && current.length > 0) {\n // A `w-full` table is at least the scroller's width, which says nothing about how\n // much room its content leaves: probe its content's width (what it takes once it\n // overflows) for the bring-back below. Read and put back in one layout pass.\n const before = table.style.width;\n table.style.width = \"min-content\";\n need = table.offsetWidth;\n table.style.width = before;\n }\n if (need > avail + 0.5) {\n // Leave out, in order, until the rest fits: each column saves its header's width\n // (the others are at their content's width while a `grow` column takes the rest).\n const next = [...current];\n for (const col of order) {\n if (need <= avail + 0.5) break;\n if (next.includes(col.key)) continue;\n const w = headRefs.get(col.key)?.offsetWidth ?? 0;\n ownWidth.current.set(col.key, w);\n need -= w;\n next.push(col.key);\n }\n if (next.length === current.length) return;\n // The last measure brought these back at this same width, and the table cannot\n // hold them: their header width fell short of what they cost drawn (see below).\n if (flip && Math.abs(flip.avail - avail) <= 0.5)\n for (const k of next.slice(current.length)) {\n const room = flip.rooms.get(k);\n if (room != null) stuck.current.set(k, room);\n }\n setHidden(next);\n return;\n }\n // Bring back, the last left out first, while the table as it is now has room for\n // them by their recorded header width. A column that costs more drawn than that is\n // left out again by the next measure, before paint. That alone does not settle it:\n // the re-hide records its header's width again, and the header can measure the same\n // while the column costs more (`virtualize`'s locked widths, keksdose B2, 0.48.3: the\n // drawn column cost the table ~80–110px more than its header), so it came back, went, came back … until React's\n // update limit (#185). So a column whose return the next measure undid, at the same\n // scroller width, waits for more room than it had then: a wider scroller or narrower\n // content. Whatever the error in its width, that is one invisible flip per room it is\n // tried at.\n let n = current.length;\n const rooms = new Map<string, number>();\n while (n > 0) {\n const k = current[n - 1];\n const w = ownWidth.current.get(k);\n if (w == null || need + w > avail + 0.5) break;\n const room = stuck.current.get(k);\n if (room != null && avail - need <= room + 0.5) break;\n rooms.set(k, avail - need);\n need += w;\n n--;\n }\n if (n === current.length) return;\n lastShown.current = { avail, rooms };\n setHidden(current.slice(0, n));\n }, [headRefs]);\n\n // After a render that changed what is drawn: rows, a filter or a page can widen a\n // column as much as a resize. Before paint, so a column the table cannot hold is never\n // drawn first. A render that changed none of it (a ticked box, a focused row) skips the\n // measure, which forces a layout of the whole table (0.48.2, keksdose dev #632).\n const lastContent = useRef<readonly unknown[] | null>(null);\n useLayoutEffect(() => {\n const now = content ? [...content, order, current, growKey, active] : null;\n const prev = lastContent.current;\n lastContent.current = now;\n if (now && prev && prev.length === now.length && prev.every((v, i) => Object.is(v, now[i]))) return;\n measure();\n });\n\n useEffect(() => {\n const el = latest.current.scroller();\n if (!active || !el || typeof ResizeObserver === \"undefined\") return;\n const ro = new ResizeObserver(() => measure());\n ro.observe(el);\n return () => ro.disconnect();\n }, [active, measure]);\n\n const keep = useCallback((key: string, on: boolean) => {\n setKept((s) => {\n if (s.has(key) === on) return s;\n const next = new Set(s);\n if (on) next.add(key);\n else next.delete(key);\n return next;\n });\n }, []);\n\n const autoHidden = useMemo(() => new Set(current), [current]);\n return { autoHidden, keep };\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,iBAAiB,SAAS,QAAQ,gBAAgB;AAuB5E,MAAM,eAAe;AAOrB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AASxB,MAAM,uBAAuB;AAO7B,SAAS,aAAgB,SAAqD;AACnF,SAAO,QACJ,IAAI,CAAC,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,EACpC,OAAO,CAAC,EAAE,IAAI,MAAM,IAAI,eAAe,IAAI,EAC3C,KAAK,CAAC,GAAG,MAAM,EAAE,IAAI,cAAe,EAAE,IAAI,eAAgB,EAAE,QAAQ,EAAE,KAAK,EAC3E,IAAI,CAAC,EAAE,IAAI,MAAM,GAAG;AACzB;AAUO,SAAS,aAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAqBE;AACA,QAAM,CAAC,MAAM,OAAO,IAAI,SAA8B,MAAM,oBAAI,IAAI,CAAC;AACrE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAmB,CAAC,CAAC;AAIjD,QAAM,WAAW,OAAO,oBAAI,IAAoB,CAAC;AAIjD,QAAM,QAAQ,OAAO,oBAAI,IAAoB,CAAC;AAG9C,QAAM,YAAY,OAA6D,IAAI;AAEnF,QAAM,SAAS,QAAQ,KAAK,CAAC,MAAM,EAAE,eAAe,IAAI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A,IACF;AACA,QAAI,MAAMA,SAAQ,OAAQ;AAC1B,cAAU,UAAU,EAAE,OAAO,MAAM;AACnC,cAAUA,SAAQ,MAAM,GAAG,CAAC,CAAC;AAAA,EAC/B,GAAG,CAAC,QAAQ,CAAC;AAMb,QAAM,cAAc,OAAkC,IAAI;AAC1D,kBAAgB,MAAM;AACpB,UAAM,MAAM,UAAU,CAAC,GAAG,SAAS,OAAO,SAAS,SAAS,MAAM,IAAI;AACtE,UAAM,OAAO,YAAY;AACzB,gBAAY,UAAU;AACtB,QAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,UAAU,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAG;AAC7F,YAAQ;AAAA,EACV,CAAC;AAED,YAAU,MAAM;AACd,UAAM,KAAK,OAAO,QAAQ,SAAS;AACnC,QAAI,CAAC,UAAU,CAAC,MAAM,OAAO,mBAAmB,YAAa;AAC7D,UAAM,KAAK,IAAI,eAAe,MAAM,QAAQ,CAAC;AAC7C,OAAG,QAAQ,EAAE;AACb,WAAO,MAAM,GAAG,WAAW;AAAA,EAC7B,GAAG,CAAC,QAAQ,OAAO,CAAC;AAEpB,QAAM,OAAO,YAAY,CAAC,KAAa,OAAgB;AACrD,YAAQ,CAAC,MAAM;AACb,UAAI,EAAE,IAAI,GAAG,MAAM,GAAI,QAAO;AAC9B,YAAM,OAAO,IAAI,IAAI,CAAC;AACtB,UAAI,GAAI,MAAK,IAAI,GAAG;AAAA,UACf,MAAK,OAAO,GAAG;AACpB,aAAO;AAAA,IACT,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,QAAQ,MAAM,IAAI,IAAI,OAAO,GAAG,CAAC,OAAO,CAAC;AAC5D,SAAO,EAAE,YAAY,KAAK;AAC5B;","names":["order","current","growKey","active","scroller"]}
@@ -11,11 +11,55 @@ import type { DataTableColumn, DataTableProps, FilterState, MobileSwipeActions }
11
11
  * BETWEEN facts rather than between a label and its own value. `relative` holds a
12
12
  * header's `sr-only` text (an actions column's), as every kit container must.
13
13
  */
14
- export declare function StackedFields<T>({ columns, row, compact }: {
14
+ export declare function StackedFields<T>({ columns, row, compact, liftOwnClicks, }: {
15
15
  columns: DataTableColumn<T>[];
16
16
  row: T;
17
17
  compact: boolean;
18
- }): import("react").JSX.Element;
18
+ /** On a stretched card (0.50 K4): lift the own-click fields above its title link. */
19
+ liftOwnClicks?: boolean;
20
+ }): import("react").JSX.Element | null;
21
+ /** The most fields the default phone card shows under its title (0.49 KIT-7). */
22
+ export declare const MOBILE_CARD_FIELDS = 3;
23
+ /**
24
+ * The default phone card's columns (0.49 KIT-7), out of the phone's columns (visible,
25
+ * not `mobileHidden`): the title — `mobile: "primary"` or `mobilePrimary`, else the
26
+ * first that is not a status — the `role: "status"` columns for beside it, at most
27
+ * {@link MOBILE_CARD_FIELDS} fields: those marked `mobile: "secondary"` when any is,
28
+ * else the first after the title, and the `role: "actions"` columns, drawn after the
29
+ * fields. An actions column is never the title and never one of the fields, so the
30
+ * fields and the marks leave it on the card; only `mobileHidden` / `mobile: "hidden"`
31
+ * (which keep it out of `columns`) remove it.
32
+ */
33
+ export declare function mobileCardColumns<T>(columns: DataTableColumn<T>[]): {
34
+ primary: DataTableColumn<T> | null;
35
+ status: DataTableColumn<T>[];
36
+ fields: DataTableColumn<T>[];
37
+ actions: DataTableColumn<T>[];
38
+ };
39
+ /** A column whose cell keeps its own clicks — `noRowLink`, or `role: "actions"`: no row
40
+ * link may wrap it, and a card that draws it is not a link itself. */
41
+ export declare function keepsOwnClicks<T>(col: DataTableColumn<T>): boolean;
42
+ /**
43
+ * A development build's note on the default phone card (0.49 KIT-7): a `noRowLink`
44
+ * column past its three fields. Such a column holds the cell's own controls — a per-row
45
+ * delete, a link — and the card leaves it out with them, so on a phone the action is
46
+ * gone. Never for a `role: "actions"` column, which the card draws after its fields.
47
+ * Read off the declared `columns` (not the ones a person or the width hid), and only
48
+ * while the table lets the card choose: `enabled` is false with a `mobileCard` or
49
+ * `mobileDetailsInRow` (the column is then in the opened row), and a column marked
50
+ * `mobile: "secondary"` means the app chose. Once per table and column key; `name`
51
+ * (the table's `storageKey` or `urlSync` prefix) says which table, else its title
52
+ * column does.
53
+ */
54
+ export declare function useCardColumnWarnings<T>(columns: DataTableColumn<T>[], enabled: boolean, name?: string): void;
55
+ /**
56
+ * Whether a rendered cell shows nothing worth a line (0.49 KIT-7): `null`, `undefined`,
57
+ * a boolean (React draws neither), `""` or blank text, and the formatters' empty value
58
+ * "—" ({@link EMPTY_FORMATTED_VALUE}), and `booleanColumn`'s mark for an unset value.
59
+ * Any other element is never empty here — its output is the component's — so a column
60
+ * whose empty value should drop off the card returns `null` (or "—") from `cell` for it.
61
+ */
62
+ export declare function isEmptyCell(value: ReactNode): boolean;
19
63
  /**
20
64
  * The card list's sort control: a "Sort by" select and a direction button.
21
65
  *
@@ -63,9 +107,20 @@ export interface MobileRowProps<T> {
63
107
  mobileDir: Direction;
64
108
  /** No column the card renders owns a link, so the card itself may be one. */
65
109
  mobileCardLinkable: boolean;
110
+ /**
111
+ * The card draws cells that keep their own clicks, so it cannot be one control (0.50
112
+ * K4): its TITLE is the row's link (`rowHref`) or button (`onRowClick`), stretched over
113
+ * the card, and those cells sit above it. Only for the default card, never a
114
+ * `mobileCard`, and never when the title itself keeps its own clicks.
115
+ */
116
+ mobileCardStretched: boolean;
66
117
  mobileCard: DataTableProps<T>["mobileCard"];
67
118
  mobilePrimaryCol: DataTableColumn<T> | null;
119
+ /** The `role: "status"` columns, drawn as chips beside the title (0.49 KIT-7). */
120
+ mobileStatusColumns: DataTableColumn<T>[];
68
121
  mobileSecondaryColumns: DataTableColumn<T>[];
122
+ /** The `role: "actions"` columns, drawn after the fields at the card's end (0.49 KIT-7). */
123
+ mobileActionColumns: DataTableColumn<T>[];
69
124
  mobileExpandAsDialog: boolean;
70
125
  compact: boolean;
71
126
  /** The text size is Large or Extra large (§4). */
@@ -86,7 +141,7 @@ export interface MobileRowSelect {
86
141
  }
87
142
  /** One mobile card. Shared by the flat list and the grouped list, so both draw
88
143
  * identical row markup. */
89
- export declare function MobileRow<T>({ row, isExpanded, openedRowContent, opensRow, rowClassName, rowAttributes, onRowClick, rowHref, swipeActionsFor, mobileDir, mobileCardLinkable, mobileCard, mobilePrimaryCol, mobileSecondaryColumns, mobileExpandAsDialog, compact, large, select, }: MobileRowProps<T>): import("react").JSX.Element;
144
+ export declare function MobileRow<T>({ row, isExpanded, openedRowContent, opensRow, rowClassName, rowAttributes, onRowClick, rowHref, swipeActionsFor, mobileDir, mobileCardLinkable, mobileCardStretched, mobileCard, mobilePrimaryCol, mobileStatusColumns, mobileSecondaryColumns, mobileActionColumns, mobileExpandAsDialog, compact, large, select, }: MobileRowProps<T>): import("react").JSX.Element;
90
145
  /**
91
146
  * The card list's way into and out of selection mode for a keyboard and a screen
92
147
  * reader — the long press is a touch gesture, and a gesture alone is no path at all.