@terreno/ui 57.20.0 → 58.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/CHANGELOG.md +93 -0
  3. package/dist/ActionSheet.d.ts +9 -9
  4. package/dist/ActionSheet.d.ts.map +1 -1
  5. package/dist/ActionSheet.js +11 -4
  6. package/dist/ActionSheet.js.map +1 -1
  7. package/dist/AnnouncementNavigator.d.ts +7 -1
  8. package/dist/AnnouncementNavigator.d.ts.map +1 -1
  9. package/dist/AnnouncementNavigator.js +15 -16
  10. package/dist/AnnouncementNavigator.js.map +1 -1
  11. package/dist/Avatar.d.ts.map +1 -1
  12. package/dist/Avatar.js +1 -1
  13. package/dist/Avatar.js.map +1 -1
  14. package/dist/Box.d.ts.map +1 -1
  15. package/dist/Box.js +3 -1
  16. package/dist/Box.js.map +1 -1
  17. package/dist/Common.d.ts +71 -39
  18. package/dist/Common.d.ts.map +1 -1
  19. package/dist/Common.js.map +1 -1
  20. package/dist/ConsentFormScreen.d.ts.map +1 -1
  21. package/dist/ConsentFormScreen.js.map +1 -1
  22. package/dist/ConsentNavigator.d.ts +5 -3
  23. package/dist/ConsentNavigator.d.ts.map +1 -1
  24. package/dist/ConsentNavigator.js +4 -4
  25. package/dist/ConsentNavigator.js.map +1 -1
  26. package/dist/CustomSelectField.js.map +1 -1
  27. package/dist/DataTable.d.ts.map +1 -1
  28. package/dist/DataTable.js +37 -12
  29. package/dist/DataTable.js.map +1 -1
  30. package/dist/DateTimeField.js +6 -6
  31. package/dist/DateTimeField.js.map +1 -1
  32. package/dist/DropdownPanel.d.ts +0 -5
  33. package/dist/DropdownPanel.d.ts.map +1 -1
  34. package/dist/DropdownPanel.js +0 -5
  35. package/dist/DropdownPanel.js.map +1 -1
  36. package/dist/FilterAccordion.d.ts.map +1 -1
  37. package/dist/FilterAccordion.js.map +1 -1
  38. package/dist/FilterBoolean.d.ts.map +1 -1
  39. package/dist/FilterBoolean.js.map +1 -1
  40. package/dist/FilterSelectMenu.js +1 -1
  41. package/dist/FilterSelectMenu.js.map +1 -1
  42. package/dist/GPTChat.d.ts.map +1 -1
  43. package/dist/GPTChat.js.map +1 -1
  44. package/dist/Heading.d.ts.map +1 -1
  45. package/dist/Heading.js +6 -12
  46. package/dist/Heading.js.map +1 -1
  47. package/dist/HeightField.d.ts.map +1 -1
  48. package/dist/HeightField.js +9 -9
  49. package/dist/HeightField.js.map +1 -1
  50. package/dist/Hyperlink.d.ts.map +1 -1
  51. package/dist/Hyperlink.js +6 -1
  52. package/dist/Hyperlink.js.map +1 -1
  53. package/dist/Image.d.ts +1 -1
  54. package/dist/MarkdownEditorField.d.ts.map +1 -1
  55. package/dist/MarkdownEditorField.js +1 -1
  56. package/dist/MarkdownEditorField.js.map +1 -1
  57. package/dist/OfflineBanner.d.ts +3 -2
  58. package/dist/OfflineBanner.d.ts.map +1 -1
  59. package/dist/OfflineBanner.js +3 -2
  60. package/dist/OfflineBanner.js.map +1 -1
  61. package/dist/OtpField.d.ts.map +1 -1
  62. package/dist/OtpField.js +4 -4
  63. package/dist/OtpField.js.map +1 -1
  64. package/dist/PickerSelect.d.ts +4 -4
  65. package/dist/PickerSelect.d.ts.map +1 -1
  66. package/dist/PickerSelect.js +9 -9
  67. package/dist/PickerSelect.js.map +1 -1
  68. package/dist/ProvisionalConsentSigner.d.ts +3 -2
  69. package/dist/ProvisionalConsentSigner.d.ts.map +1 -1
  70. package/dist/ProvisionalConsentSigner.js +2 -2
  71. package/dist/ProvisionalConsentSigner.js.map +1 -1
  72. package/dist/SidebarNavigation.js +2 -2
  73. package/dist/SidebarNavigation.js.map +1 -1
  74. package/dist/SidebarNavigation.native.js +2 -2
  75. package/dist/SidebarNavigation.native.js.map +1 -1
  76. package/dist/Skeleton.js.map +1 -1
  77. package/dist/TapToEdit.d.ts +1 -1
  78. package/dist/TapToEdit.d.ts.map +1 -1
  79. package/dist/TapToEdit.js.map +1 -1
  80. package/dist/Text.d.ts.map +1 -1
  81. package/dist/Text.js +27 -50
  82. package/dist/Text.js.map +1 -1
  83. package/dist/TextField.d.ts.map +1 -1
  84. package/dist/TextField.js +4 -4
  85. package/dist/TextField.js.map +1 -1
  86. package/dist/Theme.d.ts.map +1 -1
  87. package/dist/Theme.js +16 -0
  88. package/dist/Theme.js.map +1 -1
  89. package/dist/ThumbsUpDownFeedback.d.ts.map +1 -1
  90. package/dist/ThumbsUpDownFeedback.js.map +1 -1
  91. package/dist/ToastNotifications.d.ts.map +1 -1
  92. package/dist/ToastNotifications.js.map +1 -1
  93. package/dist/Tooltip.d.ts.map +1 -1
  94. package/dist/Tooltip.js.map +1 -1
  95. package/dist/Unifier.d.ts +1 -1
  96. package/dist/WebAddressAutocomplete.js.map +1 -1
  97. package/dist/WebDropdownMenu.d.ts +3 -3
  98. package/dist/WebDropdownMenu.d.ts.map +1 -1
  99. package/dist/WebDropdownMenu.js +1 -1
  100. package/dist/WebDropdownMenu.js.map +1 -1
  101. package/dist/announcementPlatform.d.ts +5 -0
  102. package/dist/announcementPlatform.d.ts.map +1 -1
  103. package/dist/announcementPlatform.js +9 -0
  104. package/dist/announcementPlatform.js.map +1 -1
  105. package/dist/asks/AskCard.d.ts +2 -2
  106. package/dist/asks/AskCard.d.ts.map +1 -1
  107. package/dist/dataTableColumnWidths.d.ts +76 -0
  108. package/dist/dataTableColumnWidths.d.ts.map +1 -0
  109. package/dist/dataTableColumnWidths.js +181 -0
  110. package/dist/dataTableColumnWidths.js.map +1 -0
  111. package/dist/index.d.ts +2 -1
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js.map +1 -1
  114. package/dist/login/LoginScreen.js.map +1 -1
  115. package/dist/requestClient.d.ts +71 -0
  116. package/dist/requestClient.d.ts.map +1 -0
  117. package/dist/requestClient.js +139 -0
  118. package/dist/requestClient.js.map +1 -0
  119. package/dist/security/PasswordCard.d.ts.map +1 -1
  120. package/dist/security/PasswordCard.js.map +1 -1
  121. package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -1
  122. package/dist/security/TwoFactorSettingsCard.js +1 -1
  123. package/dist/security/TwoFactorSettingsCard.js.map +1 -1
  124. package/dist/signUp/SignUpScreen.js.map +1 -1
  125. package/dist/table/Table.d.ts.map +1 -1
  126. package/dist/table/Table.js.map +1 -1
  127. package/dist/table/TableTitle.d.ts.map +1 -1
  128. package/dist/table/TableTitle.js +2 -1
  129. package/dist/table/TableTitle.js.map +1 -1
  130. package/dist/textFontSizes.d.ts +12 -0
  131. package/dist/textFontSizes.d.ts.map +1 -0
  132. package/dist/textFontSizes.js +21 -0
  133. package/dist/textFontSizes.js.map +1 -0
  134. package/dist/useAcknowledgeAnnouncement.d.ts +8 -63
  135. package/dist/useAcknowledgeAnnouncement.d.ts.map +1 -1
  136. package/dist/useAcknowledgeAnnouncement.js +31 -80
  137. package/dist/useAcknowledgeAnnouncement.js.map +1 -1
  138. package/dist/useAnnouncements.d.ts +14 -47
  139. package/dist/useAnnouncements.d.ts.map +1 -1
  140. package/dist/useAnnouncements.js +30 -57
  141. package/dist/useAnnouncements.js.map +1 -1
  142. package/dist/useConsentForms.d.ts +6 -38
  143. package/dist/useConsentForms.d.ts.map +1 -1
  144. package/dist/useConsentForms.js +25 -48
  145. package/dist/useConsentForms.js.map +1 -1
  146. package/dist/useProvisionalConsent.d.ts +7 -58
  147. package/dist/useProvisionalConsent.d.ts.map +1 -1
  148. package/dist/useProvisionalConsent.js +57 -67
  149. package/dist/useProvisionalConsent.js.map +1 -1
  150. package/dist/useSubmitConsent.d.ts +9 -39
  151. package/dist/useSubmitConsent.d.ts.map +1 -1
  152. package/dist/useSubmitConsent.js +10 -39
  153. package/dist/useSubmitConsent.js.map +1 -1
  154. package/package.json +40 -38
  155. package/src/ActionSheet.test.tsx +13 -13
  156. package/src/ActionSheet.tsx +18 -5
  157. package/src/AddressField.test.tsx +9 -3
  158. package/src/AnnouncementNavigator.test.tsx +219 -319
  159. package/src/AnnouncementNavigator.tsx +25 -20
  160. package/src/Avatar.tsx +2 -9
  161. package/src/Badge.test.tsx +1 -1
  162. package/src/Banner.test.tsx +0 -1
  163. package/src/Box.test.tsx +85 -77
  164. package/src/Box.tsx +4 -2
  165. package/src/Button.test.tsx +11 -6
  166. package/src/Card.test.tsx +2 -2
  167. package/src/Common.ts +79 -44
  168. package/src/ConflictSheet.test.tsx +5 -5
  169. package/src/ConsentFormScreen.test.tsx +3 -1
  170. package/src/ConsentFormScreen.tsx +2 -1
  171. package/src/ConsentNavigator.test.tsx +166 -243
  172. package/src/ConsentNavigator.tsx +9 -13
  173. package/src/CustomSelectField.test.tsx +16 -4
  174. package/src/CustomSelectField.tsx +3 -3
  175. package/src/DataTable.test.tsx +73 -5
  176. package/src/DataTable.tsx +72 -19
  177. package/src/DataTableVirtualizationRegression.test.tsx +1 -0
  178. package/src/DateTimeActionSheet.test.tsx +2 -0
  179. package/src/DateTimeField.test.tsx +3 -12
  180. package/src/DateTimeField.tsx +10 -10
  181. package/src/DismissButton.test.tsx +22 -4
  182. package/src/DropdownPanel.tsx +0 -6
  183. package/src/EmailField.test.tsx +13 -22
  184. package/src/EmojiSelector.test.tsx +2 -2
  185. package/src/ErrorBoundary.test.tsx +5 -3
  186. package/src/Field.test.tsx +20 -44
  187. package/src/FilterAccordion.tsx +3 -3
  188. package/src/FilterBoolean.tsx +3 -3
  189. package/src/FilterSelectMenu.tsx +1 -1
  190. package/src/GPTChat.test.tsx +24 -16
  191. package/src/GPTChat.tsx +10 -9
  192. package/src/Heading.test.tsx +1 -1
  193. package/src/Heading.tsx +7 -14
  194. package/src/HeightField.tsx +17 -10
  195. package/src/Hyperlink.tsx +6 -3
  196. package/src/Icon.test.tsx +2 -2
  197. package/src/Image.test.tsx +1 -1
  198. package/src/Link.test.tsx +13 -6
  199. package/src/MarkdownEditorField.tsx +10 -2
  200. package/src/MarkdownView.test.tsx +10 -6
  201. package/src/MobileAddressAutoComplete.test.tsx +2 -1
  202. package/src/Modal.test.tsx +10 -3
  203. package/src/ModalSheet.test.tsx +11 -10
  204. package/src/MultiselectField.test.tsx +17 -3
  205. package/src/NumberField.test.tsx +14 -14
  206. package/src/NumberPickerActionSheet.test.tsx +1 -1
  207. package/src/OfflineBanner.tsx +3 -2
  208. package/src/OpenAPIContext.test.tsx +4 -4
  209. package/src/OpenAPIRenderRegression.test.tsx +1 -1
  210. package/src/OtpField.tsx +6 -5
  211. package/src/P0RenderRegression.test.tsx +7 -1
  212. package/src/P1RenderRegression.test.tsx +1 -0
  213. package/src/P2ButtonRenderRegression.test.tsx +1 -0
  214. package/src/Page.test.tsx +1 -1
  215. package/src/PhoneNumberField.test.tsx +14 -38
  216. package/src/PickerSelect.tsx +12 -11
  217. package/src/Popover.test.tsx +2 -2
  218. package/src/ProvisionalConsentSigner.test.tsx +140 -113
  219. package/src/ProvisionalConsentSigner.tsx +5 -4
  220. package/src/RadioField.test.tsx +7 -2
  221. package/src/SegmentedControl.test.tsx +21 -12
  222. package/src/SidebarNavigation.native.tsx +2 -2
  223. package/src/SidebarNavigation.test.tsx +18 -6
  224. package/src/SidebarNavigation.tsx +2 -2
  225. package/src/Signature.test.tsx +20 -23
  226. package/src/Skeleton.tsx +1 -1
  227. package/src/Slider.test.tsx +1 -1
  228. package/src/SplitPage.test.tsx +15 -5
  229. package/src/TapToEdit.test.tsx +40 -17
  230. package/src/TapToEdit.tsx +1 -1
  231. package/src/TerrenoFontProvider.test.tsx +1 -1
  232. package/src/Text.test.tsx +4 -4
  233. package/src/Text.tsx +25 -51
  234. package/src/TextField.test.tsx +82 -9
  235. package/src/TextField.tsx +6 -5
  236. package/src/Theme.test.tsx +49 -0
  237. package/src/Theme.tsx +16 -0
  238. package/src/ThumbsUpDownFeedback.tsx +3 -3
  239. package/src/Toast.test.tsx +5 -5
  240. package/src/ToastNotifications.test.tsx +73 -70
  241. package/src/ToastNotifications.tsx +3 -2
  242. package/src/ToastNotifications.webModal.test.tsx +6 -3
  243. package/src/Tooltip.test.tsx +3 -3
  244. package/src/Tooltip.tsx +2 -1
  245. package/src/UnifiedAddressAutoComplete.test.tsx +1 -1
  246. package/src/UserInactivity.test.tsx +1 -0
  247. package/src/WebAddressAutocomplete.test.tsx +12 -12
  248. package/src/WebAddressAutocomplete.tsx +3 -3
  249. package/src/WebDropdownMenu.test.tsx +16 -15
  250. package/src/WebDropdownMenu.tsx +16 -5
  251. package/src/__snapshots__/Card.test.tsx.snap +1 -1
  252. package/src/__snapshots__/DataTable.test.tsx.snap +13 -0
  253. package/src/__snapshots__/DismissButton.test.tsx.snap +3 -3
  254. package/src/__snapshots__/Field.test.tsx.snap +4 -2
  255. package/src/__snapshots__/Heading.test.tsx.snap +1 -1
  256. package/src/__snapshots__/Image.test.tsx.snap +1 -1
  257. package/src/__snapshots__/Page.test.tsx.snap +2 -2
  258. package/src/__snapshots__/Text.test.tsx.snap +1 -1
  259. package/src/announcementPlatform.ts +10 -0
  260. package/src/asks/AskCard.test.tsx +20 -15
  261. package/src/asks/AskCard.tsx +2 -2
  262. package/src/asks/AskFiles.test.tsx +5 -1
  263. package/src/asks/askFileRefs.test.ts +1 -1
  264. package/src/asks/askSummary.test.ts +2 -2
  265. package/src/benchmarks/importTiming.ts +1 -1
  266. package/src/blocks/BlocksView.test.tsx +20 -11
  267. package/src/bunSetup.ts +43 -1
  268. package/src/dataTableColumnWidths.test.ts +266 -0
  269. package/src/dataTableColumnWidths.ts +272 -0
  270. package/src/dataTableFilters.test.tsx +1 -1
  271. package/src/index.tsx +9 -2
  272. package/src/isolated/ListDetailLayout.isolated.tsx +2 -4
  273. package/src/login/LoginScreen.test.tsx +6 -6
  274. package/src/login/LoginScreen.tsx +2 -2
  275. package/src/requestClient.test.ts +288 -0
  276. package/src/requestClient.ts +228 -0
  277. package/src/security/PasswordCard.test.tsx +3 -3
  278. package/src/security/PasswordCard.tsx +7 -5
  279. package/src/security/TwoFactorSettingsCard.tsx +10 -3
  280. package/src/signUp/SignUpScreen.test.tsx +4 -4
  281. package/src/signUp/SignUpScreen.tsx +2 -2
  282. package/src/table/Table.tsx +1 -2
  283. package/src/table/TableTitle.tsx +2 -1
  284. package/src/table/tableContext.test.tsx +5 -5
  285. package/src/test-utils.tsx +132 -1
  286. package/src/testing/reactDomServer.d.ts +7 -0
  287. package/src/textFontSizes.ts +31 -0
  288. package/src/useAcknowledgeAnnouncement.test.ts +101 -193
  289. package/src/useAcknowledgeAnnouncement.ts +69 -147
  290. package/src/useAnnouncements.test.ts +122 -186
  291. package/src/useAnnouncements.ts +49 -105
  292. package/src/useConsentForms.test.ts +59 -112
  293. package/src/useConsentForms.ts +37 -87
  294. package/src/useProvisionalConsent.test.ts +74 -150
  295. package/src/useProvisionalConsent.ts +79 -125
  296. package/src/useSubmitConsent.test.ts +59 -85
  297. package/src/useSubmitConsent.ts +22 -77
@@ -0,0 +1,228 @@
1
+ import {useCallback, useEffect, useRef, useState} from "react";
2
+
3
+ /**
4
+ * One request made through a {@link TerrenoRequestClient}. A narrow subset of the
5
+ * `@terreno/syncdb/api` `ApiRequestArgs` shape, so a syncdb `ApiClient` satisfies
6
+ * {@link TerrenoRequestClient} without `@terreno/ui` depending on syncdb.
7
+ */
8
+ export interface TerrenoRequestArgs {
9
+ /** Path or absolute URL. Relative paths are resolved against the client's base URL. */
10
+ url: string;
11
+ /** HTTP method; defaults to `GET`. */
12
+ method?: string;
13
+ /** Query-string parameters. `undefined` values are omitted. */
14
+ params?: Record<string, unknown>;
15
+ /** JSON request body. */
16
+ body?: Record<string, unknown> | null;
17
+ headers?: Record<string, string>;
18
+ /** Unwrap `{data}` response envelopes (default `true`). */
19
+ unwrap?: boolean;
20
+ }
21
+
22
+ /**
23
+ * Minimal request client the consent and announcement components use. Pass the app's
24
+ * `@terreno/syncdb/api` client (`createApiClient(...)`), or any object with a matching
25
+ * `request` method. Failed requests should reject with an error carrying the HTTP
26
+ * `status` so 401/403 responses fall through to the app's auth handling.
27
+ */
28
+ export interface TerrenoRequestClient {
29
+ request: <T = unknown>(args: TerrenoRequestArgs) => Promise<T>;
30
+ }
31
+
32
+ type TagListener = () => void;
33
+
34
+ const tagListenersByClient = new WeakMap<TerrenoRequestClient, Map<string, Set<TagListener>>>();
35
+
36
+ /** Listen for invalidations of `tag` on `client`. Returns unsubscribe. */
37
+ const subscribeClientTag = ({
38
+ client,
39
+ listener,
40
+ tag,
41
+ }: {
42
+ client: TerrenoRequestClient;
43
+ listener: TagListener;
44
+ tag: string;
45
+ }): (() => void) => {
46
+ let byTag = tagListenersByClient.get(client);
47
+ if (!byTag) {
48
+ byTag = new Map();
49
+ tagListenersByClient.set(client, byTag);
50
+ }
51
+ let listeners = byTag.get(tag);
52
+ if (!listeners) {
53
+ listeners = new Set();
54
+ byTag.set(tag, listeners);
55
+ }
56
+ listeners.add(listener);
57
+ return (): void => {
58
+ listeners.delete(listener);
59
+ };
60
+ };
61
+
62
+ /**
63
+ * Refetch every mounted {@link useClientQuery} on `client` that provides one of `tags`.
64
+ * Mutations call this after success, the way RTK `invalidatesTags` did.
65
+ */
66
+ export const invalidateClientTags = ({
67
+ client,
68
+ tags,
69
+ }: {
70
+ client: TerrenoRequestClient;
71
+ tags: readonly string[];
72
+ }): void => {
73
+ const byTag = tagListenersByClient.get(client);
74
+ if (!byTag) {
75
+ return;
76
+ }
77
+ for (const tag of tags) {
78
+ for (const listener of [...(byTag.get(tag) ?? [])]) {
79
+ listener();
80
+ }
81
+ }
82
+ };
83
+
84
+ export interface ClientQueryResult<T> {
85
+ data: T | undefined;
86
+ error: unknown;
87
+ /** True while a request is in flight and none has succeeded yet. */
88
+ isLoading: boolean;
89
+ /** True while any request is in flight. */
90
+ isFetching: boolean;
91
+ /** Fetch again. Joins a request that is already in flight. */
92
+ refetch: () => Promise<void>;
93
+ }
94
+
95
+ /**
96
+ * Run `fetcher` on mount and whenever its identity changes, keeping loading / error /
97
+ * data in React state. `providesTag` refetches the query when a mutation invalidates it.
98
+ */
99
+ export const useClientQuery = <T>({
100
+ client,
101
+ fetcher,
102
+ providesTag,
103
+ }: {
104
+ client: TerrenoRequestClient;
105
+ /** Memoize with `useCallback`; a new identity triggers a new request. */
106
+ fetcher: () => Promise<T>;
107
+ providesTag?: string;
108
+ }): ClientQueryResult<T> => {
109
+ const [data, setData] = useState<T | undefined>(undefined);
110
+ const [hasData, setHasData] = useState(false);
111
+ const [error, setError] = useState<unknown>(undefined);
112
+ const [isFetching, setIsFetching] = useState(true);
113
+ const generationRef = useRef(0);
114
+ const inFlightRef = useRef<Promise<void> | undefined>(undefined);
115
+ const isMountedRef = useRef(true);
116
+
117
+ const run = useCallback((): Promise<void> => {
118
+ generationRef.current += 1;
119
+ const generation = generationRef.current;
120
+ setIsFetching(true);
121
+ setError(undefined);
122
+ const promise = fetcher().then(
123
+ (result) => {
124
+ if (generation !== generationRef.current || !isMountedRef.current) {
125
+ return;
126
+ }
127
+ setData(result);
128
+ setHasData(true);
129
+ setIsFetching(false);
130
+ },
131
+ (fetchError: unknown) => {
132
+ if (generation !== generationRef.current || !isMountedRef.current) {
133
+ return;
134
+ }
135
+ setError(fetchError);
136
+ setIsFetching(false);
137
+ }
138
+ );
139
+ const tracked = promise.finally(() => {
140
+ if (inFlightRef.current === tracked) {
141
+ inFlightRef.current = undefined;
142
+ }
143
+ });
144
+ inFlightRef.current = tracked;
145
+ return tracked;
146
+ }, [fetcher]);
147
+
148
+ const refetch = useCallback((): Promise<void> => {
149
+ return inFlightRef.current ?? run();
150
+ }, [run]);
151
+
152
+ // Fetch on mount and whenever the fetcher (client, URL, or params) changes.
153
+ useEffect(() => {
154
+ isMountedRef.current = true;
155
+ void run();
156
+ return (): void => {
157
+ isMountedRef.current = false;
158
+ inFlightRef.current = undefined;
159
+ };
160
+ }, [run]);
161
+
162
+ // Refetch with a fresh request when a mutation invalidates this query's tag.
163
+ useEffect(() => {
164
+ if (!providesTag) {
165
+ return undefined;
166
+ }
167
+ return subscribeClientTag({
168
+ client,
169
+ listener: () => {
170
+ void run();
171
+ },
172
+ tag: providesTag,
173
+ });
174
+ }, [client, providesTag, run]);
175
+
176
+ return {
177
+ data,
178
+ error,
179
+ isFetching,
180
+ isLoading: isFetching && !hasData,
181
+ refetch,
182
+ };
183
+ };
184
+
185
+ export interface ClientMutationResult<A> {
186
+ /** Run the mutation; rejects with the request error. */
187
+ mutate: (args: A) => Promise<void>;
188
+ error: unknown;
189
+ isLoading: boolean;
190
+ }
191
+
192
+ /**
193
+ * Track loading / error state for a request that changes server state. `mutate` keeps a
194
+ * stable identity across renders so it is safe in effect dependency lists.
195
+ */
196
+ export const useClientMutation = <A>({
197
+ run,
198
+ }: {
199
+ run: (args: A) => Promise<void>;
200
+ }): ClientMutationResult<A> => {
201
+ const [error, setError] = useState<unknown>(undefined);
202
+ const [pendingCount, setPendingCount] = useState(0);
203
+ const runRef = useRef(run);
204
+ runRef.current = run;
205
+
206
+ const mutate = useCallback(async (args: A): Promise<void> => {
207
+ setPendingCount((count) => count + 1);
208
+ setError(undefined);
209
+ try {
210
+ await runRef.current(args);
211
+ } catch (mutationError) {
212
+ setError(mutationError);
213
+ throw mutationError;
214
+ } finally {
215
+ setPendingCount((count) => count - 1);
216
+ }
217
+ }, []);
218
+
219
+ return {error, isLoading: pendingCount > 0, mutate};
220
+ };
221
+
222
+ /** Accept both bare payloads and `{data}` envelopes (when a client does not unwrap). */
223
+ export const unwrapDataEnvelope = <T>(value: unknown): T | undefined => {
224
+ if (value && typeof value === "object" && !Array.isArray(value) && "data" in value) {
225
+ return (value as {data?: T}).data;
226
+ }
227
+ return value as T | undefined;
228
+ };
@@ -2,7 +2,7 @@ import {describe, expect, it, mock, spyOn} from "bun:test";
2
2
  import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
3
  import type {ReactElement} from "react";
4
4
  import {ThemeProvider} from "../Theme";
5
- import {renderWithTheme} from "../test-utils";
5
+ import {elementProps, renderWithTheme} from "../test-utils";
6
6
  import {PasswordCard} from "./PasswordCard";
7
7
  import type {PasswordCardSubmission} from "./securityTypes";
8
8
 
@@ -18,11 +18,11 @@ const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<vo
18
18
  const renderTrackingFocus = (ui: ReactElement): ReturnType<typeof render> & {focused: string[]} => {
19
19
  const focused: string[] = [];
20
20
  const result = render(ui, {
21
- createNodeMock: (element: ReactElement<{testID?: string}>) => ({
21
+ createNodeMock: (element: ReactElement) => ({
22
22
  blur: (): void => {},
23
23
  clear: (): void => {},
24
24
  focus: (): void => {
25
- focused.push(element.props.testID ?? "");
25
+ focused.push(elementProps<{testID?: string}>(element).testID ?? "");
26
26
  },
27
27
  isFocused: (): boolean => false,
28
28
  }),
@@ -1,5 +1,5 @@
1
1
  import {type FC, useCallback, useEffect, useRef, useState} from "react";
2
- import {type TextInput, View} from "react-native";
2
+ import {type TextInputInstance, View} from "react-native";
3
3
 
4
4
  import {Box} from "../Box";
5
5
  import {Button} from "../Button";
@@ -98,16 +98,18 @@ export const PasswordCard: FC<PasswordCardProps> = ({
98
98
  const [successMessage, setSuccessMessage] = useState<string | undefined>(undefined);
99
99
  const isSubmittingRef = useRef(false);
100
100
  const previousModeRef = useRef(mode);
101
- const inputRefs = useRef<Partial<Record<keyof PasswordFieldErrors, TextInput | null>>>({});
101
+ const inputRefs = useRef<Partial<Record<keyof PasswordFieldErrors, TextInputInstance | null>>>(
102
+ {}
103
+ );
102
104
  const formRef = useRef<FormContainerHandle>(null);
103
105
 
104
- const setCurrentInputRef = useCallback((ref: TextInput | null): void => {
106
+ const setCurrentInputRef = useCallback((ref: TextInputInstance | null): void => {
105
107
  inputRefs.current.currentPassword = ref;
106
108
  }, []);
107
- const setNewInputRef = useCallback((ref: TextInput | null): void => {
109
+ const setNewInputRef = useCallback((ref: TextInputInstance | null): void => {
108
110
  inputRefs.current.newPassword = ref;
109
111
  }, []);
110
- const setConfirmInputRef = useCallback((ref: TextInput | null): void => {
112
+ const setConfirmInputRef = useCallback((ref: TextInputInstance | null): void => {
111
113
  inputRefs.current.confirmPassword = ref;
112
114
  }, []);
113
115
 
@@ -1,6 +1,13 @@
1
1
  import * as Clipboard from "expo-clipboard";
2
2
  import {type FC, type ReactElement, useCallback, useEffect, useRef, useState} from "react";
3
- import {AccessibilityInfo, Platform, Share, type TextInput, View} from "react-native";
3
+ import {
4
+ AccessibilityInfo,
5
+ Platform,
6
+ Share,
7
+ type TextInputInstance,
8
+ View,
9
+ type ViewInstance,
10
+ } from "react-native";
4
11
  import QRCode from "react-native-qrcode-svg";
5
12
 
6
13
  import {Box} from "../Box";
@@ -223,8 +230,8 @@ export const TwoFactorSettingsCard: FC<TwoFactorSettingsCardProps> = ({
223
230
  const [pendingAction, setPendingAction] = useState<PendingAction | undefined>(undefined);
224
231
  const [actionError, setActionError] = useState<string | undefined>(undefined);
225
232
  const [copyFeedback, setCopyFeedback] = useState<CopyFeedback | undefined>(undefined);
226
- const passwordInputRef = useRef<TextInput | null>(null);
227
- const stepHeadingRef = useRef<View | null>(null);
233
+ const passwordInputRef = useRef<TextInputInstance | null>(null);
234
+ const stepHeadingRef = useRef<ViewInstance | null>(null);
228
235
  const isFirstRenderRef = useRef(true);
229
236
 
230
237
  const isBusy = disabled || pendingAction !== undefined;
@@ -4,7 +4,7 @@ import type {ReactElement} from "react";
4
4
  import {Platform} from "react-native";
5
5
  import {TextField} from "../TextField";
6
6
  import {ThemeProvider} from "../Theme";
7
- import {renderWithTheme} from "../test-utils";
7
+ import {elementProps, renderWithTheme} from "../test-utils";
8
8
  import {defaultPasswordRequirements} from "./passwordPresets";
9
9
  import {SignUpScreen} from "./SignUpScreen";
10
10
 
@@ -177,14 +177,14 @@ const renderWithHostMocks = (
177
177
  ): ReturnType<typeof render> & {focused: string[]} => {
178
178
  const focused: string[] = [];
179
179
  const result = render(ui, {
180
- createNodeMock: (element: ReactElement<{testID?: string}>) => {
180
+ createNodeMock: (element: ReactElement) => {
181
181
  if (element.type === "form") {
182
182
  return requestSubmit ? {requestSubmit} : {};
183
183
  }
184
184
  return {
185
185
  blur: (): void => {},
186
186
  focus: (): void => {
187
- focused.push(element.props.testID ?? "");
187
+ focused.push(elementProps<{testID?: string}>(element).testID ?? "");
188
188
  },
189
189
  };
190
190
  },
@@ -216,7 +216,7 @@ describe("SignUpScreen keyboard", () => {
216
216
  });
217
217
 
218
218
  it("submits once on Enter in the last field", async () => {
219
- const onSubmit = mock(() => Promise.resolve());
219
+ const onSubmit = mock((_values: Record<string, string>) => Promise.resolve());
220
220
  const {getByTestId} = renderWithTheme(
221
221
  <SignUpScreen
222
222
  fields={defaultFields}
@@ -1,6 +1,6 @@
1
1
  import type {FC} from "react";
2
2
  import {useCallback, useRef, useState} from "react";
3
- import type {TextInput} from "react-native";
3
+ import type {TextInputInstance} from "react-native";
4
4
 
5
5
  import {Box} from "../Box";
6
6
  import {Button} from "../Button";
@@ -94,7 +94,7 @@ export const SignUpScreen: FC<SignUpScreenProps> = ({
94
94
  const isSubmitDisabled = loading || !requiredFieldsFilled || !allRequirementsMet;
95
95
 
96
96
  const formRef = useRef<FormContainerHandle>(null);
97
- const inputRefs = useRef<Record<string, TextInput | null>>({});
97
+ const inputRefs = useRef<Record<string, TextInputInstance | null>>({});
98
98
  // Blocks a second submission (Enter plus a press, or a double Enter) before `loading` lands.
99
99
  const isSubmittingRef = useRef(false);
100
100
 
@@ -1,6 +1,5 @@
1
1
  import React, {Children, type ReactElement, useEffect} from "react";
2
- import {ScrollView} from "react-native";
3
- import type {DimensionValue} from "react-native/Libraries/StyleSheet/StyleSheetTypes";
2
+ import {type DimensionValue, ScrollView} from "react-native";
4
3
 
5
4
  import {Box} from "../Box";
6
5
  import type {ColumnSortInterface, TableProps, TableRowProps} from "../Common";
@@ -2,6 +2,7 @@ import type {FC} from "react";
2
2
  import {Text} from "react-native";
3
3
 
4
4
  import type {TableTitleProps} from "../Common";
5
+ import {DATA_TABLE_HEADER_FONT_SIZE} from "../dataTableColumnWidths";
5
6
  import {useTheme} from "../Theme";
6
7
 
7
8
  export const TableTitle: FC<TableTitleProps> = ({title, align = "left"}) => {
@@ -17,7 +18,7 @@ export const TableTitle: FC<TableTitleProps> = ({title, align = "left"}) => {
17
18
  color: theme.text.primary,
18
19
  flexWrap: "wrap",
19
20
  fontFamily: "text",
20
- fontSize: 10,
21
+ fontSize: DATA_TABLE_HEADER_FONT_SIZE,
21
22
  fontWeight: "700",
22
23
  lineHeight: 16,
23
24
  overflow: "hidden",
@@ -37,7 +37,7 @@ describe("tableContext", () => {
37
37
  expect(ctx.hasDrawerContents).toBe(false);
38
38
  expect(typeof ctx.setSortColumn).toBe("function");
39
39
  // Invoke default setSortColumn to cover the no-op default
40
- expect(() => ctx.setSortColumn({column: 0, direction: "asc"})).not.toThrow();
40
+ expect(() => ctx.setSortColumn!({column: 0, direction: "asc"})).not.toThrow();
41
41
  });
42
42
 
43
43
  it("passes provided values through the provider", () => {
@@ -46,7 +46,7 @@ describe("tableContext", () => {
46
46
  render(
47
47
  <TableContextProvider
48
48
  alternateRowBackground={false}
49
- borderStyle="lg"
49
+ borderStyle="none"
50
50
  columns={[100, 200]}
51
51
  hasDrawerContents
52
52
  page={3}
@@ -62,9 +62,9 @@ describe("tableContext", () => {
62
62
  expect(ctx.hasDrawerContents).toBe(true);
63
63
  expect(ctx.stickyHeader).toBe(false);
64
64
  expect(ctx.alternateRowBackground).toBe(false);
65
- expect(ctx.borderStyle).toBe("lg");
65
+ expect(ctx.borderStyle).toBe("none");
66
66
  expect(ctx.sortColumn).toEqual({column: 1, direction: "desc"});
67
- ctx.setSortColumn({column: 0, direction: "asc"});
67
+ ctx.setSortColumn!({column: 0, direction: "asc"});
68
68
  expect(setSortColumn).toHaveBeenCalled();
69
69
  });
70
70
 
@@ -73,7 +73,7 @@ describe("tableContext", () => {
73
73
  const Consumer = () => {
74
74
  const {setSortColumn: setter} = useTableContext();
75
75
  useEffect(() => {
76
- setter({column: 2, direction: "desc"});
76
+ setter!({column: 2, direction: "desc"});
77
77
  }, [setter]);
78
78
  return <Text>ok</Text>;
79
79
  };
@@ -1,10 +1,13 @@
1
1
  import {mock} from "bun:test";
2
2
  import {render} from "@testing-library/react-native";
3
+ import type {JestNativeMatchers} from "@testing-library/react-native/build/matchers/types";
3
4
  import type React from "react";
4
5
  import {View} from "react-native";
6
+ import type {ReactTestInstance, ReactTestRendererJSON} from "react-test-renderer";
5
7
 
6
8
  import type {CustomIconProps, IconRegistryMap} from "./Common";
7
9
  import {IconRegistryProvider} from "./IconRegistry";
10
+ import type {TerrenoRequestArgs, TerrenoRequestClient} from "./requestClient";
8
11
  import {ThemeProvider} from "./Theme";
9
12
 
10
13
  // Register a custom icon name for tests. test-utils.tsx is excluded from the
@@ -15,6 +18,12 @@ declare module "./Common" {
15
18
  }
16
19
  }
17
20
 
21
+ // @testing-library/react-native registers its matchers (toHaveStyle, toHaveProp, ...) on the
22
+ // global expect at import time; expose their types on bun:test's expect as well.
23
+ declare module "bun:test" {
24
+ interface Matchers<T> extends JestNativeMatchers<void> {}
25
+ }
26
+
18
27
  export const TEST_CUSTOM_ICON_TEST_ID = "test-custom-icon";
19
28
 
20
29
  export const TestCustomIcon: React.FC<CustomIconProps> = ({size, testID}) => {
@@ -42,7 +51,7 @@ export const renderWithIcons = (
42
51
 
43
52
  export const createCommonMocks = () => ({
44
53
  onBlur: mock(() => {}),
45
- onChange: mock(() => {}),
54
+ onChange: mock((_value: string) => {}),
46
55
  onEnter: mock(() => {}),
47
56
  onFocus: mock(() => {}),
48
57
  onIconClick: mock(() => {}),
@@ -57,3 +66,125 @@ export const teardownComponentTest = () => {
57
66
  // In Bun, mocks are automatically cleaned up
58
67
  // No-op for compatibility
59
68
  };
69
+
70
+ /** Handler for one fake route; return the response payload or throw to fail the request. */
71
+ export type FakeRouteHandler = (
72
+ args: TerrenoRequestArgs,
73
+ pathParams: Record<string, string>
74
+ ) => unknown | Promise<unknown>;
75
+
76
+ export interface FakeRequestClient {
77
+ client: TerrenoRequestClient;
78
+ /** Every request in call order. */
79
+ calls: TerrenoRequestArgs[];
80
+ /** Requests whose method and URL match `route` (for example `"POST /consents/respond"`). */
81
+ callsTo: (route: string) => TerrenoRequestArgs[];
82
+ }
83
+
84
+ /** Error shaped like a failed request: carries the HTTP `status`. */
85
+ export const fakeHttpError = (status: number, title = `HTTP ${status}`): Error =>
86
+ Object.assign(new Error(title), {data: {title}, status});
87
+
88
+ const routePattern = (route: string): {method: string; regex: RegExp; names: string[]} => {
89
+ const [method, path] = route.split(" ");
90
+ const names: string[] = [];
91
+ const source = path
92
+ .split("/")
93
+ .map((segment) => {
94
+ if (segment.startsWith(":")) {
95
+ names.push(segment.slice(1));
96
+ return "([^/]+)";
97
+ }
98
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
99
+ })
100
+ .join("/");
101
+ return {method: method.toUpperCase(), names, regex: new RegExp(`^${source}$`)};
102
+ };
103
+
104
+ const matchRoute = (
105
+ route: string,
106
+ args: TerrenoRequestArgs
107
+ ): Record<string, string> | undefined => {
108
+ const {method, names, regex} = routePattern(route);
109
+ if ((args.method ?? "GET").toUpperCase() !== method) {
110
+ return undefined;
111
+ }
112
+ const match = regex.exec(args.url);
113
+ if (!match) {
114
+ return undefined;
115
+ }
116
+ return Object.fromEntries(names.map((name, index) => [name, match[index + 1] ?? ""]));
117
+ };
118
+
119
+ /**
120
+ * In-memory {@link TerrenoRequestClient}. Routes are `"METHOD /path/:param"` keys; a request
121
+ * with no matching route rejects with a 404 error.
122
+ */
123
+ export const createFakeRequestClient = (
124
+ routes: Record<string, FakeRouteHandler>
125
+ ): FakeRequestClient => {
126
+ const calls: TerrenoRequestArgs[] = [];
127
+ const request = async <T,>(args: TerrenoRequestArgs): Promise<T> => {
128
+ calls.push(args);
129
+ for (const [route, handler] of Object.entries(routes)) {
130
+ const pathParams = matchRoute(route, args);
131
+ if (pathParams) {
132
+ return (await handler(args, pathParams)) as T;
133
+ }
134
+ }
135
+ throw fakeHttpError(404, `No fake route for ${args.method ?? "GET"} ${args.url}`);
136
+ };
137
+ return {
138
+ calls,
139
+ callsTo: (route: string): TerrenoRequestArgs[] =>
140
+ calls.filter((args) => matchRoute(route, args) !== undefined),
141
+ client: {request},
142
+ };
143
+ };
144
+
145
+ /**
146
+ * Host element name (e.g. "View") of a test-renderer node. The react-native mock in bunSetup.ts
147
+ * renders string host types that React's DOM-only JSX typings do not list, so read it as a string.
148
+ */
149
+ const hostTypeName = (node: ReactTestInstance): string | undefined => {
150
+ const type: unknown = node.type;
151
+ return typeof type === "string" ? type : undefined;
152
+ };
153
+
154
+ const isHostType = (node: ReactTestInstance, name: string): boolean => {
155
+ return hostTypeName(node) === name;
156
+ };
157
+
158
+ /** Typed equivalent of `root.findByType("View")` for string host types. */
159
+ export const findByHostType = (root: ReactTestInstance, name: string): ReactTestInstance => {
160
+ return root.find((node) => isHostType(node, name));
161
+ };
162
+
163
+ /** Typed equivalent of `root.findAllByType("View")` for string host types. */
164
+ export const findAllByHostType = (
165
+ root: ReactTestInstance,
166
+ name: string,
167
+ options?: {deep: boolean}
168
+ ): ReactTestInstance[] => {
169
+ return root.findAll((node) => isHostType(node, name), options);
170
+ };
171
+
172
+ /**
173
+ * Props of a React element handed to `createNodeMock` or returned from a render method. React
174
+ * types element props as `unknown`; tests read the few host props they inspect through this.
175
+ */
176
+ export const elementProps = <P extends object = Record<string, unknown>>(
177
+ element: React.ReactElement
178
+ ): Partial<P> => {
179
+ return (element.props ?? {}) as Partial<P>;
180
+ };
181
+
182
+ /** Narrows a `toJSON()` result to its single root node; fails when the render has several roots. */
183
+ export const rootJSONNode = (
184
+ tree: ReactTestRendererJSON | ReactTestRendererJSON[] | null
185
+ ): ReactTestRendererJSON | null => {
186
+ if (Array.isArray(tree)) {
187
+ throw new Error(`Expected a single root node, got ${tree.length}`);
188
+ }
189
+ return tree;
190
+ };
@@ -0,0 +1,7 @@
1
+ // ResponsiveBreakpoint.test.tsx renders through react-dom/server to cover the SSR path, and the
2
+ // workspace does not install @types/react-dom. Declare only the entry point the tests use.
3
+ declare module "react-dom/server" {
4
+ import type {ReactNode} from "react";
5
+
6
+ export const renderToString: (element: ReactNode) => string;
7
+ }
@@ -0,0 +1,31 @@
1
+ import {Platform} from "react-native";
2
+
3
+ import type {TextSize} from "./Common";
4
+
5
+ interface TextFontSizeAndWeight {
6
+ size: number;
7
+ weight: "regular" | "medium";
8
+ }
9
+
10
+ const fontSizeAndWeightWeb: Record<TextSize, TextFontSizeAndWeight> = {
11
+ "2xl": {size: 48, weight: "medium"},
12
+ lg: {size: 18, weight: "medium"},
13
+ md: {size: 16, weight: "regular"},
14
+ sm: {size: 12, weight: "regular"},
15
+ xl: {size: 20, weight: "medium"},
16
+ };
17
+
18
+ const fontSizeAndWeightMobile: Record<TextSize, TextFontSizeAndWeight> = {
19
+ "2xl": {size: 40, weight: "medium"},
20
+ lg: {size: 16, weight: "medium"},
21
+ md: {size: 14, weight: "regular"},
22
+ sm: {size: 10, weight: "regular"},
23
+ xl: {size: 18, weight: "medium"},
24
+ };
25
+
26
+ /**
27
+ * Font size and weight for each `Text` size on the current platform. Shared by `Text` and by
28
+ * anything that has to predict how wide `Text` will render, such as DataTable auto widths.
29
+ */
30
+ export const textFontSizes: Record<TextSize, TextFontSizeAndWeight> =
31
+ Platform.OS === "web" ? fontSizeAndWeightWeb : fontSizeAndWeightMobile;