@eifi1/ui-kit 0.35.0 → 0.36.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 (265) hide show
  1. package/README.md +35 -5
  2. package/dist/admin/role-select.d.ts +3 -2
  3. package/dist/admin/role-select.js +2 -0
  4. package/dist/admin/role-select.js.map +1 -1
  5. package/dist/components/amount-input.d.ts +2 -2
  6. package/dist/components/amount-input.js.map +1 -1
  7. package/dist/components/autocomplete.d.ts +2 -2
  8. package/dist/components/autocomplete.js +2 -1
  9. package/dist/components/autocomplete.js.map +1 -1
  10. package/dist/components/button-look.d.ts +1 -1
  11. package/dist/components/button-look.js +9 -4
  12. package/dist/components/button-look.js.map +1 -1
  13. package/dist/components/checkbox-group.d.ts +5 -2
  14. package/dist/components/checkbox-group.js +15 -4
  15. package/dist/components/checkbox-group.js.map +1 -1
  16. package/dist/components/column-mapper.d.ts +5 -3
  17. package/dist/components/column-mapper.js +2 -0
  18. package/dist/components/column-mapper.js.map +1 -1
  19. package/dist/components/combobox.d.ts +2 -2
  20. package/dist/components/combobox.js +2 -1
  21. package/dist/components/combobox.js.map +1 -1
  22. package/dist/components/country-select.d.ts +3 -3
  23. package/dist/components/country-select.js +3 -0
  24. package/dist/components/country-select.js.map +1 -1
  25. package/dist/components/currency-select.d.ts +3 -2
  26. package/dist/components/currency-select.js +10 -1
  27. package/dist/components/currency-select.js.map +1 -1
  28. package/dist/components/date-field.d.ts +2 -1
  29. package/dist/components/date-field.js.map +1 -1
  30. package/dist/components/date-picker.js +3 -0
  31. package/dist/components/date-picker.js.map +1 -1
  32. package/dist/components/date-range-picker.js +3 -0
  33. package/dist/components/date-range-picker.js.map +1 -1
  34. package/dist/components/entity-combobox.d.ts +2 -2
  35. package/dist/components/entity-combobox.js +2 -1
  36. package/dist/components/entity-combobox.js.map +1 -1
  37. package/dist/components/field-parts.d.ts +66 -11
  38. package/dist/components/field-parts.js +32 -10
  39. package/dist/components/field-parts.js.map +1 -1
  40. package/dist/components/field-strip.d.ts +3 -2
  41. package/dist/components/field-strip.js +2 -1
  42. package/dist/components/field-strip.js.map +1 -1
  43. package/dist/components/field.d.ts +3 -2
  44. package/dist/components/field.js +24 -15
  45. package/dist/components/field.js.map +1 -1
  46. package/dist/components/help-popover.d.ts +9 -7
  47. package/dist/components/help-popover.js.map +1 -1
  48. package/dist/components/icon-picker.d.ts +3 -2
  49. package/dist/components/icon-picker.js +3 -0
  50. package/dist/components/icon-picker.js.map +1 -1
  51. package/dist/components/inline-entity-combobox.d.ts +2 -2
  52. package/dist/components/inline-entity-combobox.js +2 -1
  53. package/dist/components/inline-entity-combobox.js.map +1 -1
  54. package/dist/components/input.d.ts +2 -2
  55. package/dist/components/input.js +2 -1
  56. package/dist/components/input.js.map +1 -1
  57. package/dist/components/month-picker.d.ts +2 -1
  58. package/dist/components/month-picker.js +8 -1
  59. package/dist/components/month-picker.js.map +1 -1
  60. package/dist/components/multi-entity-combobox.d.ts +2 -2
  61. package/dist/components/multi-entity-combobox.js +2 -1
  62. package/dist/components/multi-entity-combobox.js.map +1 -1
  63. package/dist/components/multi-select.d.ts +2 -2
  64. package/dist/components/multi-select.js +3 -0
  65. package/dist/components/multi-select.js.map +1 -1
  66. package/dist/components/number-input.d.ts +2 -2
  67. package/dist/components/number-input.js.map +1 -1
  68. package/dist/components/numeric-field.d.ts +5 -2
  69. package/dist/components/numeric-field.js +4 -1
  70. package/dist/components/numeric-field.js.map +1 -1
  71. package/dist/components/one-time-code-input.d.ts +2 -1
  72. package/dist/components/one-time-code-input.js +2 -1
  73. package/dist/components/one-time-code-input.js.map +1 -1
  74. package/dist/components/phone-input.d.ts +1 -1
  75. package/dist/components/phone-input.js +4 -0
  76. package/dist/components/phone-input.js.map +1 -1
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/popover.js.map +1 -1
  79. package/dist/components/select.d.ts +4 -3
  80. package/dist/components/select.js +2 -1
  81. package/dist/components/select.js.map +1 -1
  82. package/dist/components/slider.d.ts +3 -2
  83. package/dist/components/slider.js +7 -1
  84. package/dist/components/slider.js.map +1 -1
  85. package/dist/components/stat-tile.js +2 -11
  86. package/dist/components/stat-tile.js.map +1 -1
  87. package/dist/components/swatch-picker.d.ts +3 -2
  88. package/dist/components/swatch-picker.js +3 -0
  89. package/dist/components/swatch-picker.js.map +1 -1
  90. package/dist/components/text-link.js +3 -1
  91. package/dist/components/text-link.js.map +1 -1
  92. package/dist/components/textarea.d.ts +2 -1
  93. package/dist/components/textarea.js +9 -3
  94. package/dist/components/textarea.js.map +1 -1
  95. package/dist/components/toggle-group.d.ts +2 -2
  96. package/dist/components/toggle-group.js +7 -3
  97. package/dist/components/toggle-group.js.map +1 -1
  98. package/dist/eslint/index.js +1 -1
  99. package/dist/i18n/defaults.js +5 -1
  100. package/dist/i18n/defaults.js.map +1 -1
  101. package/dist/i18n/german.js +97 -1
  102. package/dist/i18n/german.js.map +1 -1
  103. package/dist/i18n/kit-labels.d.ts +15 -0
  104. package/dist/i18n/kit-labels.js +21 -1
  105. package/dist/i18n/kit-labels.js.map +1 -1
  106. package/dist/i18n/locales/en.js +103 -2
  107. package/dist/i18n/locales/en.js.map +3 -3
  108. package/dist/i18n/locales/es.js +95 -1
  109. package/dist/i18n/locales/es.js.map +1 -1
  110. package/dist/i18n/locales/fr.js +96 -1
  111. package/dist/i18n/locales/fr.js.map +1 -1
  112. package/dist/i18n/locales/hu.js +95 -1
  113. package/dist/i18n/locales/hu.js.map +1 -1
  114. package/dist/i18n/locales/it.js +96 -1
  115. package/dist/i18n/locales/it.js.map +1 -1
  116. package/dist/i18n/locales/zh.js +95 -1
  117. package/dist/i18n/locales/zh.js.map +1 -1
  118. package/dist/i18n/review.js +13 -0
  119. package/dist/i18n/review.js.map +1 -1
  120. package/dist/i18n/shared-labels.js +3 -1
  121. package/dist/i18n/shared-labels.js.map +1 -1
  122. package/dist/index.d.ts +21 -0
  123. package/dist/index.js +38 -0
  124. package/dist/index.js.map +1 -1
  125. package/dist/lib/device-settings.d.ts +72 -0
  126. package/dist/lib/device-settings.js +64 -0
  127. package/dist/lib/device-settings.js.map +1 -0
  128. package/dist/lib/plain-text.d.ts +11 -0
  129. package/dist/lib/plain-text.js +16 -0
  130. package/dist/lib/plain-text.js.map +1 -0
  131. package/dist/lib/safe-storage.d.ts +6 -0
  132. package/dist/lib/safe-storage.js +11 -0
  133. package/dist/lib/safe-storage.js.map +1 -1
  134. package/dist/notifications/notification-parts.d.ts +39 -0
  135. package/dist/notifications/notification-parts.js +47 -0
  136. package/dist/notifications/notification-parts.js.map +1 -0
  137. package/dist/notifications/notification-types-setting.d.ts +62 -0
  138. package/dist/notifications/notification-types-setting.js +192 -0
  139. package/dist/notifications/notification-types-setting.js.map +1 -0
  140. package/dist/notifications/notification-types.d.ts +75 -0
  141. package/dist/notifications/notification-types.js +2 -0
  142. package/dist/notifications/notification-types.js.map +1 -0
  143. package/dist/notifications/notifications-labels.d.ts +131 -0
  144. package/dist/notifications/notifications-labels.js +83 -0
  145. package/dist/notifications/notifications-labels.js.map +1 -0
  146. package/dist/notifications/push-device-setting.d.ts +37 -0
  147. package/dist/notifications/push-device-setting.js +164 -0
  148. package/dist/notifications/push-device-setting.js.map +1 -0
  149. package/dist/notifications/push-devices-setting.d.ts +44 -0
  150. package/dist/notifications/push-devices-setting.js +203 -0
  151. package/dist/notifications/push-devices-setting.js.map +1 -0
  152. package/dist/notifications/quiet-hours-setting.d.ts +47 -0
  153. package/dist/notifications/quiet-hours-setting.js +131 -0
  154. package/dist/notifications/quiet-hours-setting.js.map +1 -0
  155. package/dist/notifications/time-zone-select.d.ts +50 -0
  156. package/dist/notifications/time-zone-select.js +76 -0
  157. package/dist/notifications/time-zone-select.js.map +1 -0
  158. package/dist/notifications/unsubscribe-panel.d.ts +53 -0
  159. package/dist/notifications/unsubscribe-panel.js +139 -0
  160. package/dist/notifications/unsubscribe-panel.js.map +1 -0
  161. package/dist/notifications/use-push-device.d.ts +122 -0
  162. package/dist/notifications/use-push-device.js +230 -0
  163. package/dist/notifications/use-push-device.js.map +1 -0
  164. package/dist/rhf/fields.d.ts +26 -19
  165. package/dist/rhf/fields.js +51 -22
  166. package/dist/rhf/fields.js.map +1 -1
  167. package/dist/settings/device-reset-setting-labels.d.ts +3 -0
  168. package/dist/settings/device-reset-setting-labels.js +15 -0
  169. package/dist/settings/device-reset-setting-labels.js.map +1 -0
  170. package/dist/settings/device-reset-setting.d.ts +58 -0
  171. package/dist/settings/device-reset-setting.js +51 -0
  172. package/dist/settings/device-reset-setting.js.map +1 -0
  173. package/dist/shell/app-shell.js +5 -0
  174. package/dist/shell/app-shell.js.map +1 -1
  175. package/dist/theme/contrast-tokens.d.ts +42 -4
  176. package/dist/theme/contrast-tokens.js +56 -9
  177. package/dist/theme/contrast-tokens.js.map +1 -1
  178. package/dist/theme/contrast.d.ts +4 -2
  179. package/dist/theme/contrast.js +13 -0
  180. package/dist/theme/contrast.js.map +1 -1
  181. package/dist/theme/palette-derive.d.ts +15 -1
  182. package/dist/theme/palette-derive.js +37 -8
  183. package/dist/theme/palette-derive.js.map +1 -1
  184. package/dist/theme/palette-presets.d.ts +2 -1
  185. package/dist/theme/palette-presets.js +5 -5
  186. package/dist/theme/palette-presets.js.map +1 -1
  187. package/dist/theme/palette-store.js +6 -0
  188. package/dist/theme/palette-store.js.map +1 -1
  189. package/dist/theme/text-size.js +6 -0
  190. package/dist/theme/text-size.js.map +1 -1
  191. package/dist/theme/theme-store.js +6 -0
  192. package/dist/theme/theme-store.js.map +1 -1
  193. package/package.json +1 -1
  194. package/src/admin/role-select.tsx +4 -1
  195. package/src/components/amount-input.tsx +2 -1
  196. package/src/components/autocomplete.tsx +5 -2
  197. package/src/components/button-look.ts +15 -5
  198. package/src/components/checkbox-group.tsx +22 -4
  199. package/src/components/column-mapper.tsx +6 -2
  200. package/src/components/combobox.tsx +5 -2
  201. package/src/components/country-select.tsx +6 -1
  202. package/src/components/currency-select.tsx +12 -3
  203. package/src/components/date-field.tsx +2 -2
  204. package/src/components/date-picker.tsx +3 -0
  205. package/src/components/date-range-picker.tsx +3 -0
  206. package/src/components/entity-combobox.tsx +5 -2
  207. package/src/components/field-parts.tsx +107 -19
  208. package/src/components/field-strip.tsx +4 -3
  209. package/src/components/field.tsx +28 -15
  210. package/src/components/help-popover.tsx +9 -7
  211. package/src/components/icon-picker.tsx +8 -3
  212. package/src/components/inline-entity-combobox.tsx +5 -2
  213. package/src/components/input.tsx +4 -2
  214. package/src/components/month-picker.tsx +10 -3
  215. package/src/components/multi-entity-combobox.tsx +5 -2
  216. package/src/components/multi-select.tsx +6 -1
  217. package/src/components/number-input.tsx +2 -2
  218. package/src/components/numeric-field.ts +10 -2
  219. package/src/components/one-time-code-input.tsx +5 -3
  220. package/src/components/phone-input.tsx +4 -0
  221. package/src/components/popover.tsx +3 -1
  222. package/src/components/select.tsx +6 -3
  223. package/src/components/slider.tsx +10 -3
  224. package/src/components/stat-tile.tsx +3 -18
  225. package/src/components/swatch-picker.tsx +9 -4
  226. package/src/components/text-link.tsx +3 -1
  227. package/src/components/textarea.tsx +11 -4
  228. package/src/components/toggle-group.tsx +21 -5
  229. package/src/i18n/defaults.ts +4 -0
  230. package/src/i18n/german.ts +113 -0
  231. package/src/i18n/kit-labels.tsx +51 -1
  232. package/src/i18n/locales/en.ts +6 -0
  233. package/src/i18n/locales/es.ts +106 -0
  234. package/src/i18n/locales/fr.ts +106 -0
  235. package/src/i18n/locales/hu.ts +104 -0
  236. package/src/i18n/locales/it.ts +105 -0
  237. package/src/i18n/locales/zh.ts +96 -0
  238. package/src/i18n/review.ts +13 -0
  239. package/src/i18n/shared-labels.ts +2 -0
  240. package/src/index.ts +50 -0
  241. package/src/lib/device-settings.ts +146 -0
  242. package/src/lib/plain-text.ts +22 -0
  243. package/src/lib/safe-storage.ts +16 -0
  244. package/src/notifications/notification-parts.tsx +83 -0
  245. package/src/notifications/notification-types-setting.tsx +309 -0
  246. package/src/notifications/notification-types.ts +80 -0
  247. package/src/notifications/notifications-labels.ts +238 -0
  248. package/src/notifications/push-device-setting.tsx +224 -0
  249. package/src/notifications/push-devices-setting.tsx +306 -0
  250. package/src/notifications/quiet-hours-setting.tsx +185 -0
  251. package/src/notifications/time-zone-select.tsx +126 -0
  252. package/src/notifications/unsubscribe-panel.tsx +203 -0
  253. package/src/notifications/use-push-device.ts +392 -0
  254. package/src/rhf/fields.tsx +77 -29
  255. package/src/settings/device-reset-setting-labels.ts +20 -0
  256. package/src/settings/device-reset-setting.tsx +119 -0
  257. package/src/shell/app-shell.tsx +8 -0
  258. package/src/theme/contrast-tokens.ts +106 -12
  259. package/src/theme/contrast.ts +30 -4
  260. package/src/theme/palette-derive.ts +68 -7
  261. package/src/theme/palette-presets.ts +9 -6
  262. package/src/theme/palette-store.ts +12 -0
  263. package/src/theme/text-size.ts +8 -0
  264. package/src/theme/theme-store.ts +10 -0
  265. package/tokens.css +38 -4
@@ -0,0 +1,80 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ /**
4
+ * The shapes the notification cards share (docs/notifications-harmonization.md §3.2,
5
+ * §3.5, §4.2): the server's `GET /notifications/settings` answer, the parts of its
6
+ * `PATCH` the cards send, one push device, and the app's words for its types.
7
+ *
8
+ * Types only — the kit keeps no list of notification types and no defaults (§2.1): the
9
+ * server's registry is the one list, and the cards draw what it answers.
10
+ */
11
+
12
+ /** The digest's cadence, one for the account (§2.5): Monday, or the 1st, in its zone. */
13
+ export type DigestCadence = "weekly" | "monthly";
14
+
15
+ /**
16
+ * One type's two switches in the `GET` (§3.2). `null` where the type does not offer
17
+ * that channel: `email` for a type with no mail, `app` in an app with no "in the app"
18
+ * channel (Kurvenschmiede: `{app: null, email: true}`). An unset switch already reads as
19
+ * its default — the server fills it in.
20
+ */
21
+ export interface NotificationSwitches {
22
+ app: boolean | null;
23
+ email: boolean | null;
24
+ }
25
+
26
+ /** The `GET`'s `types`: every type the account can receive, in the registry's order. */
27
+ export type NotificationTypesValue = Readonly<Record<string, NotificationSwitches>>;
28
+
29
+ /**
30
+ * The app's words for one of its types — where an app TYPES its ids, so its own maps
31
+ * (keksdose's inbox icons) are keyed on the same list (§5.1). The kit draws the type
32
+ * only when the server answered it.
33
+ */
34
+ export interface NotificationTypeEntry<Id extends string = string> {
35
+ id: Id;
36
+ /** The switch's label: what the person hears about. */
37
+ label: string;
38
+ /** The line under it, attached to the switch. */
39
+ description?: ReactNode;
40
+ }
41
+
42
+ /** A heading over some of the types, in the app's words (keksdose's "Budget", "Scans &
43
+ * sharing", "Summaries & news"). */
44
+ export interface NotificationTypeGroup<Id extends string = string> {
45
+ /** A stable key for the group. */
46
+ id: string;
47
+ label: ReactNode;
48
+ /** The group's types, in the order they are drawn. */
49
+ types: readonly Id[];
50
+ }
51
+
52
+ /**
53
+ * The parts of `PATCH /notifications/settings` (§3.2) the cards send. Omitted keeps; a
54
+ * type's `null` puts both its switches back to their defaults; `quiet_hours_*: null`
55
+ * clears a time. One switch per call from the types card (`{types: {digest: {app:
56
+ * true}}}`), or `{digest_cadence}`; quiet hours send a time, with the device's zone the
57
+ * first time; the zone picker sends `{timezone}`.
58
+ */
59
+ export interface NotificationSettingsPatch<Id extends string = string> {
60
+ types?: Partial<Record<Id, { app?: boolean; email?: boolean } | null>>;
61
+ digest_cadence?: DigestCadence;
62
+ quiet_hours_start?: string | null;
63
+ quiet_hours_end?: string | null;
64
+ timezone?: string;
65
+ }
66
+
67
+ /** One registered push device, as `GET /notifications/devices` lists it (§3.5), oldest
68
+ * first. The owner gets the whole endpoint, which marks "this device". */
69
+ export interface PushDeviceItem<Id extends string | number = string> {
70
+ id: Id;
71
+ endpoint: string;
72
+ /** The browser's user agent at registration; `null` when it sent none. */
73
+ user_agent: string | null;
74
+ /** ISO date-time. */
75
+ created_at: string;
76
+ /** ISO date-time of the last delivery the push service accepted, or `null`. */
77
+ last_success_at: string | null;
78
+ /** Failed deliveries in a row; the server removes the device at 10. */
79
+ failure_count: number;
80
+ }
@@ -0,0 +1,238 @@
1
+ // The words of the notification cards (docs/notifications-harmonization.md §4.2), in a
2
+ // module with no component code: the English catalogue (src/i18n/defaults.ts) imports
3
+ // them without the components, so `en` loads as one chunk like the other languages
4
+ // (0.34, KS U8). The cards read it through `useKitLabels("notifications", …)`.
5
+
6
+ /** The ten IANA regions `Intl` lists zones under — keksdose's `tz_region_*` — in the
7
+ * kit's words. A region a runtime adds later keeps its IANA name. */
8
+ export interface NotificationRegionLabels {
9
+ Africa: string;
10
+ America: string;
11
+ Antarctica: string;
12
+ Arctic: string;
13
+ Asia: string;
14
+ Atlantic: string;
15
+ Australia: string;
16
+ Europe: string;
17
+ Indian: string;
18
+ Pacific: string;
19
+ }
20
+
21
+ /**
22
+ * Every string the notification parts render — the `notifications` namespace of
23
+ * `<UiKitProvider labels>`, overridable per instance through `labels`: the types card,
24
+ * quiet hours and the zone picker, this device's push, the device list, and the
25
+ * unsubscribe page. Cancel is `common.cancel`.
26
+ */
27
+ export interface NotificationsLabels {
28
+ /* ── The types card ─────────────────────────────────────────────────── */
29
+ /** The types card's title. */
30
+ typesTitle: string;
31
+ /** The line under it. */
32
+ typesDescription: string;
33
+ /** The e-mail switch under a type that offers mail. */
34
+ byEmail: string;
35
+ /** Under every e-mail switch while the account's address is unverified (decision 16):
36
+ * no notification mail goes to an unverified address. */
37
+ emailUnverified: string;
38
+ /** The digest's cadence select. */
39
+ digestCadence: string;
40
+ digestWeekly: string;
41
+ digestMonthly: string;
42
+ /** While the settings load. */
43
+ typesLoading: string;
44
+ /** The server answered no types for this account. */
45
+ typesEmpty: string;
46
+
47
+ /* ── Quiet hours ────────────────────────────────────────────────────── */
48
+ quietTitle: string;
49
+ /** The line under the title; `inbox`: the app keeps an inbox, which a held push still
50
+ * reaches. */
51
+ quietDescription: (inbox: boolean) => string;
52
+ /** The start time's label. */
53
+ quietFrom: string;
54
+ /** The end time's label. */
55
+ quietUntil: string;
56
+ /** One time set, the other not: quiet hours fail open until both are. */
57
+ quietIncomplete: string;
58
+ /** The zone picker's label. */
59
+ timeZone: string;
60
+ /** Given the device's zone, as the picker names it, when it differs from the one the
61
+ * server applies. */
62
+ deviceZone: (zone: string) => string;
63
+ /** The button that takes the device's zone. */
64
+ useDeviceZone: string;
65
+ /** The zone picker's region headings. */
66
+ regions: NotificationRegionLabels;
67
+
68
+ /* ── This device ────────────────────────────────────────────────────── */
69
+ pushTitle: string;
70
+ pushDescription: string;
71
+ /** The browser has no push. */
72
+ unsupported: string;
73
+ /** iOS outside the installed app, given the app's name. */
74
+ iosInstall: (app: string) => string;
75
+ /** The server has no VAPID keys. */
76
+ notConfigured: string;
77
+ /** The browser's permission is denied. */
78
+ blocked: string;
79
+ /** This device gets notifications for the signed-in account. */
80
+ on: string;
81
+ off: string;
82
+ /** This browser's subscription belongs to another account. */
83
+ otherAccount: string;
84
+ enable: string;
85
+ disable: string;
86
+ sendTest: string;
87
+ /** Turning on did not finish (the permission prompt dismissed, a refusal). */
88
+ enableFailed: string;
89
+ /** No service worker, or one that is not ready in 10 s. */
90
+ noServiceWorker: string;
91
+ /** The browser's push service did not answer in 15 s. */
92
+ pushTimeout: string;
93
+ /** Given how many devices the push service accepted the test for (≥ 1). */
94
+ testSent: (count: number) => string;
95
+ /** The test reached no device. */
96
+ testNone: string;
97
+ testFailed: string;
98
+ /** The explainer before the browser's one permission prompt. */
99
+ explainerTitle: string;
100
+ explainerBody: (app: string) => string;
101
+ explainerHint: string;
102
+ explainerContinue: string;
103
+
104
+ /* ── The device list ────────────────────────────────────────────────── */
105
+ devicesTitle: string;
106
+ devicesDescription: string;
107
+ devicesLoading: string;
108
+ devicesEmpty: string;
109
+ /** A device whose user agent says nothing the kit recognises. */
110
+ unknownDevice: string;
111
+ /** The chip on this browser's row. */
112
+ thisDevice: string;
113
+ /** Given the registration date, formatted. */
114
+ added: (date: string) => string;
115
+ /** Given the last accepted delivery, formatted. */
116
+ lastDelivery: (date: string) => string;
117
+ noDelivery: string;
118
+ /** Given the failed deliveries in a row (≥ 1). */
119
+ failures: (count: number) => string;
120
+ /** A row's button, visible text — and the confirm's answer. */
121
+ remove: string;
122
+ /** The same button's accessible name, given the device: it starts with `remove`. */
123
+ removeItem: (device: string) => string;
124
+ /** The question the row asks before it removes. */
125
+ removePrompt: string;
126
+
127
+ /* ── The unsubscribe page ───────────────────────────────────────────── */
128
+ unsubscribeTitle: string;
129
+ /** Given the type's name in the app's words. */
130
+ unsubscribeAbout: (type: string) => string;
131
+ /** No type name to give. */
132
+ unsubscribeGeneric: string;
133
+ stopThese: string;
134
+ stopAll: (app: string) => string;
135
+ stoppedThese: string;
136
+ stoppedAll: (app: string) => string;
137
+ /** Account mail is not a notification, and keeps coming. */
138
+ accountMail: string;
139
+ turnBackOn: string;
140
+ openSettings: string;
141
+ /** A token the server refused, or one that does not parse. */
142
+ invalidLink: string;
143
+
144
+ /* ── Every card ─────────────────────────────────────────────────────── */
145
+ /** A request failed, and the app had no words of its own. */
146
+ failed: string;
147
+ }
148
+
149
+ export const DEFAULT_NOTIFICATIONS_LABELS: NotificationsLabels = {
150
+ typesTitle: "Notify me about",
151
+ typesDescription: "Choose what you hear about, and how.",
152
+ byEmail: "By e-mail",
153
+ emailUnverified: "Confirm your address to receive these.",
154
+ digestCadence: "Frequency",
155
+ digestWeekly: "Weekly",
156
+ digestMonthly: "Monthly",
157
+ typesLoading: "Loading notification settings…",
158
+ typesEmpty: "There are no notifications for this account.",
159
+
160
+ quietTitle: "Quiet hours",
161
+ quietDescription: (inbox) =>
162
+ inbox
163
+ ? "No push notifications during this window. They still reach your inbox."
164
+ : "No push notifications during this window.",
165
+ quietFrom: "From",
166
+ quietUntil: "Until",
167
+ quietIncomplete: "Set both a start and an end time. Quiet hours take effect once both are set.",
168
+ timeZone: "Time zone",
169
+ deviceZone: (zone) => `This device is in ${zone}.`,
170
+ useDeviceZone: "Use it",
171
+ regions: {
172
+ Africa: "Africa",
173
+ America: "Americas",
174
+ Antarctica: "Antarctica",
175
+ Arctic: "Arctic",
176
+ Asia: "Asia",
177
+ Atlantic: "Atlantic",
178
+ Australia: "Australia",
179
+ Europe: "Europe",
180
+ Indian: "Indian Ocean",
181
+ Pacific: "Pacific",
182
+ },
183
+
184
+ pushTitle: "Push notifications",
185
+ pushDescription: "Notifications on this device, also while the app is closed.",
186
+ unsupported: "This browser doesn’t support push notifications.",
187
+ iosInstall: (app) =>
188
+ `On iPhone or iPad, add ${app} to your Home Screen first: iOS delivers notifications only to the installed app.`,
189
+ notConfigured: "Push notifications aren’t set up on this server.",
190
+ blocked: "Notifications are blocked in this browser’s settings.",
191
+ on: "Notifications are on for this device.",
192
+ off: "Notifications are off for this device.",
193
+ otherAccount:
194
+ "This browser gets notifications for another account. Turn them on here to get them for the account you’re signed in with.",
195
+ enable: "Turn on notifications",
196
+ disable: "Turn off",
197
+ sendTest: "Send a test",
198
+ enableFailed: "Couldn’t turn on notifications.",
199
+ noServiceWorker: "Couldn’t reach the app’s service worker. Reload the page and try again.",
200
+ pushTimeout: "The browser’s push service didn’t answer. Check your connection and try again.",
201
+ testSent: (count) => (count === 1 ? "Test sent to 1 device" : `Test sent to ${count} devices`),
202
+ testNone: "No device accepted the test. Turn notifications on for this device first.",
203
+ testFailed: "Couldn’t send a test notification.",
204
+ explainerTitle: "Turn on notifications?",
205
+ explainerBody: (app) =>
206
+ `${app} sends a notification only for the kinds you choose, and you can turn them off at any time.`,
207
+ explainerHint: "Your browser asks for permission next.",
208
+ explainerContinue: "Continue",
209
+
210
+ devicesTitle: "Notification devices",
211
+ devicesDescription: "Every device that gets push notifications for your account. Remove any you no longer use.",
212
+ devicesLoading: "Loading devices…",
213
+ devicesEmpty: "No device gets notifications yet.",
214
+ unknownDevice: "Unknown device",
215
+ thisDevice: "This device",
216
+ added: (date) => `Added ${date}`,
217
+ lastDelivery: (date) => `Last delivery ${date}`,
218
+ noDelivery: "No delivery yet",
219
+ failures: (count) =>
220
+ count === 1 ? "1 failed delivery in a row" : `${count} failed deliveries in a row`,
221
+ remove: "Remove",
222
+ removeItem: (device) => `Remove ${device}`,
223
+ removePrompt: "Stop sending notifications to this device?",
224
+
225
+ unsubscribeTitle: "E-mail notifications",
226
+ unsubscribeAbout: (type) => `You get e-mails about: ${type}.`,
227
+ unsubscribeGeneric: "You get notification e-mails.",
228
+ stopThese: "Stop these e-mails",
229
+ stopAll: (app) => `Stop all notification e-mails from ${app}`,
230
+ stoppedThese: "Done. You won’t get these e-mails any more.",
231
+ stoppedAll: (app) => `Done. You won’t get notification e-mails from ${app} any more.`,
232
+ accountMail: "E-mails about your account still come.",
233
+ turnBackOn: "You can turn them back on at any time in Settings.",
234
+ openSettings: "Open Settings",
235
+ invalidLink: "This link doesn’t work any more. You can turn e-mails off in Settings instead.",
236
+
237
+ failed: "That didn’t work. Please try again.",
238
+ };
@@ -0,0 +1,224 @@
1
+ import { useState } from "react";
2
+ import type { ComponentPropsWithRef, ReactNode } from "react";
3
+
4
+ import { useKitLabels, type LabelOverride } from "../i18n/kit-labels";
5
+ import { DEFAULT_COMMON_LABELS } from "../i18n/shared-labels";
6
+ import { cn } from "../lib/cn";
7
+ import { AlertBanner } from "../components/alert-banner";
8
+ import { Button } from "../components/button";
9
+ import { Card } from "../components/card";
10
+ import { DialogFrame } from "../components/dialog-frame";
11
+ import { COMMIT_EXCEPT_BILLING } from "../components/write-lock";
12
+ import { CARD_DESCRIPTION_CLASS } from "../settings/settings-card-classes";
13
+ import { SettingsCardTitle } from "../settings/settings-heading";
14
+ import { useMounted } from "../account/account-parts";
15
+ import { describeFailure, FailureLine, useNotificationsLabels } from "./notification-parts";
16
+ import type { NotificationsLabels } from "./notifications-labels";
17
+ import { PushDeviceError } from "./use-push-device";
18
+ import type { PushDevice } from "./use-push-device";
19
+
20
+ /** Which action failed — {@link PushDeviceSettingProps.describeError}'s second argument. */
21
+ export type PushDeviceAction = "enable" | "disable" | "test";
22
+
23
+ export interface PushDeviceSettingProps extends Omit<ComponentPropsWithRef<"div">, "children"> {
24
+ /** This browser's push, from {@link usePushDevice}. */
25
+ push: PushDevice;
26
+ /** The app's name, for the iOS line and the explainer. */
27
+ appName: string;
28
+ /** The app's own words for a failure, or `undefined` for the kit's. The kit already
29
+ * has words for a missing service worker and an unanswered push service. */
30
+ describeError?: (error: unknown, action: PushDeviceAction) => ReactNode | undefined;
31
+ labels?: LabelOverride<NotificationsLabels>;
32
+ }
33
+
34
+ /** What the line under the buttons says. */
35
+ type Outcome = { tone: "status" | "warning" | "danger"; text: ReactNode } | null;
36
+
37
+ /**
38
+ * Push on THIS device (docs/notifications-harmonization.md §2.2, §2.7, §4.2): keksdose's
39
+ * push block, as a card of its own. Registering the device is the switch — push has no
40
+ * account switch. One state at a time, in keksdose's order
41
+ * (`notifications-card.tsx:333-402`):
42
+ *
43
+ * 1. the browser has no push;
44
+ * 2. iOS outside the installed app (iOS delivers only to the installed app);
45
+ * 3. push is not set up on the server (no VAPID keys);
46
+ * 4. notifications blocked in the browser;
47
+ * 5. on or off — with "another account" when this browser's subscription is someone
48
+ * else's — and "Turn on notifications", or "Send a test" and "Turn off".
49
+ *
50
+ * **The explainer comes before the browser's one prompt**: turning on while the
51
+ * permission is still `"default"` opens a dialog first (what the notifications are for,
52
+ * that the browser asks next); with it granted, it goes straight on. A test that reached
53
+ * no device says so (`testNone`) — a 404/410 removes the row on the server while this
54
+ * browser still holds its subscription. Outcomes are a line under the buttons; nothing
55
+ * toasts.
56
+ */
57
+ export function PushDeviceSetting({
58
+ push,
59
+ appName,
60
+ describeError,
61
+ labels: labelsProp,
62
+ className,
63
+ ...rest
64
+ }: PushDeviceSettingProps) {
65
+ const labels = useNotificationsLabels(labelsProp);
66
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
67
+ const [explainer, setExplainer] = useState(false);
68
+ const [running, setRunning] = useState<PushDeviceAction | null>(null);
69
+ const [outcome, setOutcome] = useState<Outcome>(null);
70
+ const mounted = useMounted();
71
+
72
+ const failureOf = (error: unknown, action: PushDeviceAction, fallback: string): ReactNode => {
73
+ if (error instanceof PushDeviceError) {
74
+ return error.code === "no_service_worker" ? labels.noServiceWorker : labels.pushTimeout;
75
+ }
76
+ return describeFailure(describeError?.(error, action), fallback);
77
+ };
78
+
79
+ const run = <T,>(action: PushDeviceAction, call: () => Promise<T>, done: (value: T) => Outcome, fallback: string) => {
80
+ if (running) return;
81
+ setRunning(action);
82
+ setOutcome(null);
83
+ call().then(
84
+ (value) => {
85
+ if (!mounted.current) return;
86
+ setRunning(null);
87
+ setOutcome(done(value));
88
+ },
89
+ (error: unknown) => {
90
+ if (!mounted.current) return;
91
+ setRunning(null);
92
+ setOutcome({ tone: "danger", text: failureOf(error, action, fallback) });
93
+ },
94
+ );
95
+ };
96
+
97
+ const enable = () =>
98
+ run(
99
+ "enable",
100
+ () => push.enable(),
101
+ (ok): Outcome => (ok ? null : { tone: "danger", text: labels.enableFailed }),
102
+ labels.enableFailed,
103
+ );
104
+ const disable = () => run("disable", () => push.disable(), () => null, labels.failed);
105
+ const test = () =>
106
+ run(
107
+ "test",
108
+ () => push.sendTest(),
109
+ ({ sent }): Outcome =>
110
+ sent > 0 ? { tone: "status", text: labels.testSent(sent) } : { tone: "warning", text: labels.testNone },
111
+ labels.testFailed,
112
+ );
113
+
114
+ const turnOn = () => {
115
+ if (push.permission === "granted") enable();
116
+ else setExplainer(true);
117
+ };
118
+
119
+ let state: ReactNode;
120
+ if (!push.supported) {
121
+ state = <p className={CARD_DESCRIPTION_CLASS}>{labels.unsupported}</p>;
122
+ } else if (push.ios && !push.installed) {
123
+ state = <p className={CARD_DESCRIPTION_CLASS}>{labels.iosInstall(appName)}</p>;
124
+ } else if (push.configured === false) {
125
+ state = <p className={CARD_DESCRIPTION_CLASS}>{labels.notConfigured}</p>;
126
+ } else if (push.permission === "denied") {
127
+ state = <p className="text-xs text-warning">{labels.blocked}</p>;
128
+ } else {
129
+ const busy = push.busy || running !== null;
130
+ state = (
131
+ <>
132
+ <p className={CARD_DESCRIPTION_CLASS} data-push-state={push.subscribed ? "on" : "off"}>
133
+ {push.subscribed ? labels.on : labels.off}
134
+ </p>
135
+ {push.foreignSubscription && <p className="text-xs text-warning">{labels.otherAccount}</p>}
136
+ <div className="flex flex-wrap gap-2">
137
+ {push.subscribed ? (
138
+ <>
139
+ <Button
140
+ type="button"
141
+ size="sm"
142
+ variant="secondary"
143
+ commit={COMMIT_EXCEPT_BILLING}
144
+ pending={running === "test"}
145
+ disabled={busy && running !== "test"}
146
+ onClick={test}
147
+ >
148
+ {labels.sendTest}
149
+ </Button>
150
+ <Button
151
+ type="button"
152
+ size="sm"
153
+ variant="ghost"
154
+ commit={COMMIT_EXCEPT_BILLING}
155
+ pending={running === "disable"}
156
+ disabled={busy && running !== "disable"}
157
+ onClick={disable}
158
+ >
159
+ {labels.disable}
160
+ </Button>
161
+ </>
162
+ ) : (
163
+ <Button
164
+ type="button"
165
+ size="sm"
166
+ commit={COMMIT_EXCEPT_BILLING}
167
+ pending={running === "enable"}
168
+ disabled={busy && running !== "enable"}
169
+ onClick={turnOn}
170
+ >
171
+ {labels.enable}
172
+ </Button>
173
+ )}
174
+ </div>
175
+ {outcome?.tone === "status" && (
176
+ <p role="status" className={CARD_DESCRIPTION_CLASS}>
177
+ {outcome.text}
178
+ </p>
179
+ )}
180
+ {outcome?.tone === "warning" && (
181
+ <AlertBanner tone="warning" size="sm" role="status">
182
+ {outcome.text}
183
+ </AlertBanner>
184
+ )}
185
+ {outcome?.tone === "danger" && <FailureLine>{outcome.text}</FailureLine>}
186
+ </>
187
+ );
188
+ }
189
+
190
+ return (
191
+ <Card {...rest} className={cn("p-4 space-y-3", className)}>
192
+ <div>
193
+ <SettingsCardTitle>{labels.pushTitle}</SettingsCardTitle>
194
+ <div className={CARD_DESCRIPTION_CLASS}>{labels.pushDescription}</div>
195
+ </div>
196
+ {state}
197
+ <DialogFrame
198
+ open={explainer}
199
+ onClose={() => setExplainer(false)}
200
+ title={labels.explainerTitle}
201
+ description={labels.explainerBody(appName)}
202
+ actions={(close) => (
203
+ <div className="flex justify-end gap-2">
204
+ <Button type="button" variant="ghost" onClick={close}>
205
+ {common.cancel}
206
+ </Button>
207
+ <Button
208
+ type="button"
209
+ onClick={() => {
210
+ setExplainer(false);
211
+ // Only now the browser's one permission prompt.
212
+ enable();
213
+ }}
214
+ >
215
+ {labels.explainerContinue}
216
+ </Button>
217
+ </div>
218
+ )}
219
+ >
220
+ <p className={CARD_DESCRIPTION_CLASS}>{labels.explainerHint}</p>
221
+ </DialogFrame>
222
+ </Card>
223
+ );
224
+ }