@terreno/ui 57.2.0 → 57.3.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 (201) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/README.md +17 -8
  3. package/dist/ActionSheet.d.ts +3 -3
  4. package/dist/ActionSheet.js +2 -2
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/Box.d.ts +1 -1
  7. package/dist/Box.js +219 -177
  8. package/dist/Box.js.map +1 -1
  9. package/dist/Button.js +101 -34
  10. package/dist/Button.js.map +1 -1
  11. package/dist/Common.d.ts +119 -9
  12. package/dist/Common.js.map +1 -1
  13. package/dist/ConsentFormScreen.js +46 -12
  14. package/dist/ConsentFormScreen.js.map +1 -1
  15. package/dist/ConsentNavigator.d.ts +5 -1
  16. package/dist/ConsentNavigator.js.map +1 -1
  17. package/dist/DataTable.d.ts +2 -2
  18. package/dist/DataTable.js +203 -44
  19. package/dist/DataTable.js.map +1 -1
  20. package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
  21. package/dist/DataTableHeaderInfoMarkdown.js +7 -0
  22. package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
  23. package/dist/EmojiSelector.d.ts +2 -46
  24. package/dist/EmojiSelector.js +46 -56
  25. package/dist/EmojiSelector.js.map +1 -1
  26. package/dist/GPTChat.js +1 -1
  27. package/dist/GPTChat.js.map +1 -1
  28. package/dist/Heading.d.ts +5 -2
  29. package/dist/Heading.js +6 -8
  30. package/dist/Heading.js.map +1 -1
  31. package/dist/Hyperlink.js.map +1 -1
  32. package/dist/Icon.d.ts +1 -2
  33. package/dist/Icon.js +4 -1
  34. package/dist/Icon.js.map +1 -1
  35. package/dist/MarkdownView.d.ts +6 -3
  36. package/dist/MarkdownView.js +45 -43
  37. package/dist/MarkdownView.js.map +1 -1
  38. package/dist/MediaQuery.d.ts +5 -3
  39. package/dist/MediaQuery.js +9 -40
  40. package/dist/MediaQuery.js.map +1 -1
  41. package/dist/OpenAPIContext.js +7 -6
  42. package/dist/OpenAPIContext.js.map +1 -1
  43. package/dist/Page.js +7 -1
  44. package/dist/Page.js.map +1 -1
  45. package/dist/PickerSelect.js +8 -1
  46. package/dist/PickerSelect.js.map +1 -1
  47. package/dist/Popover.d.ts +12 -0
  48. package/dist/Popover.js +37 -0
  49. package/dist/Popover.js.map +1 -0
  50. package/dist/PortalHost.js +10 -1
  51. package/dist/PortalHost.js.map +1 -1
  52. package/dist/ResponsiveBreakpoint.d.ts +65 -0
  53. package/dist/ResponsiveBreakpoint.js +111 -0
  54. package/dist/ResponsiveBreakpoint.js.map +1 -0
  55. package/dist/SplitPage.d.ts +2 -2
  56. package/dist/SplitPage.js +7 -12
  57. package/dist/SplitPage.js.map +1 -1
  58. package/dist/SplitPage.native.d.ts +2 -2
  59. package/dist/SplitPage.native.js +1 -6
  60. package/dist/SplitPage.native.js.map +1 -1
  61. package/dist/TapToEdit.js +12 -10
  62. package/dist/TapToEdit.js.map +1 -1
  63. package/dist/TerrenoFontProvider.d.ts +7 -0
  64. package/dist/TerrenoFontProvider.js +27 -0
  65. package/dist/TerrenoFontProvider.js.map +1 -0
  66. package/dist/TerrenoProvider.js +4 -2
  67. package/dist/TerrenoProvider.js.map +1 -1
  68. package/dist/Text.d.ts +5 -2
  69. package/dist/Text.js +6 -11
  70. package/dist/Text.js.map +1 -1
  71. package/dist/TextFieldNumberActionSheet.js +9 -2
  72. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  73. package/dist/Theme.js +10 -8
  74. package/dist/Theme.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts +4 -2
  76. package/dist/ToastNotifications.js.map +1 -1
  77. package/dist/Tooltip.d.ts +4 -3
  78. package/dist/Tooltip.js +14 -3
  79. package/dist/Tooltip.js.map +1 -1
  80. package/dist/Unifier.d.ts +26 -1
  81. package/dist/Unifier.js.map +1 -1
  82. package/dist/WebAddressAutocomplete.js +6 -1
  83. package/dist/WebAddressAutocomplete.js.map +1 -1
  84. package/dist/emojiCategories.d.ts +46 -0
  85. package/dist/emojiCategories.js +47 -0
  86. package/dist/emojiCategories.js.map +1 -0
  87. package/dist/index.d.ts +13 -13
  88. package/dist/index.js +2 -13
  89. package/dist/index.js.map +1 -1
  90. package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
  91. package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
  92. package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
  93. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
  94. package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
  95. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
  96. package/dist/login/LoginScreen.d.ts +1 -0
  97. package/dist/login/LoginScreen.js +4 -2
  98. package/dist/login/LoginScreen.js.map +1 -1
  99. package/dist/login/loginTypes.d.ts +2 -0
  100. package/package.json +40 -1
  101. package/src/AIRequestExplorer.test.tsx +141 -0
  102. package/src/ActionSheet.tsx +9 -7
  103. package/src/AttachmentPreview.test.tsx +80 -0
  104. package/src/Box.test.tsx +97 -10
  105. package/src/Box.tsx +263 -200
  106. package/src/Button.test.tsx +207 -0
  107. package/src/Button.tsx +146 -48
  108. package/src/Common.ts +124 -25
  109. package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
  110. package/src/ConsentFormScreen.test.tsx +145 -8
  111. package/src/ConsentFormScreen.tsx +74 -25
  112. package/src/ConsentNavigator.tsx +13 -5
  113. package/src/DataTable.tsx +418 -147
  114. package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
  115. package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
  116. package/src/DataTableVirtualizationRegression.test.tsx +266 -0
  117. package/src/DateTimeField.test.tsx +54 -0
  118. package/src/EmojiSelector.test.tsx +33 -42
  119. package/src/EmojiSelector.tsx +60 -57
  120. package/src/FilePickerButton.test.tsx +167 -0
  121. package/src/FilterAccordion.test.tsx +37 -0
  122. package/src/FilterBoolean.test.tsx +96 -0
  123. package/src/FilterSelectMenu.test.tsx +23 -0
  124. package/src/GPTChat.test.tsx +696 -0
  125. package/src/GPTChat.tsx +2 -2
  126. package/src/GPTMemoryModal.test.tsx +67 -0
  127. package/src/Heading.tsx +8 -14
  128. package/src/HeightActionSheet.test.tsx +6 -9
  129. package/src/Hyperlink.tsx +5 -18
  130. package/src/Icon.tsx +6 -2
  131. package/src/MarkdownEditor.test.tsx +134 -0
  132. package/src/MarkdownEditorField.test.tsx +124 -0
  133. package/src/MarkdownView.test.tsx +55 -11
  134. package/src/MarkdownView.tsx +149 -150
  135. package/src/MediaQuery.ts +30 -34
  136. package/src/OpenAPIContext.tsx +36 -29
  137. package/src/OpenAPIRenderRegression.test.tsx +200 -0
  138. package/src/P0RenderRegression.test.tsx +214 -0
  139. package/src/P1RenderRegression.test.tsx +141 -0
  140. package/src/P2ButtonRenderRegression.test.tsx +158 -0
  141. package/src/Page.test.tsx +13 -0
  142. package/src/Page.tsx +25 -5
  143. package/src/PickerSelect.test.tsx +38 -0
  144. package/src/PickerSelect.tsx +7 -0
  145. package/src/Popover.test.tsx +151 -0
  146. package/src/Popover.tsx +211 -0
  147. package/src/PortalHost.tsx +12 -6
  148. package/src/ResponsiveBreakpoint.test.tsx +184 -0
  149. package/src/ResponsiveBreakpoint.tsx +195 -0
  150. package/src/RootImportRegression.test.tsx +62 -0
  151. package/src/SplitPage.native.tsx +5 -9
  152. package/src/SplitPage.tsx +16 -19
  153. package/src/TapToEdit.test.tsx +45 -0
  154. package/src/TapToEdit.tsx +23 -18
  155. package/src/TerrenoFontProvider.test.tsx +38 -0
  156. package/src/TerrenoFontProvider.tsx +50 -0
  157. package/src/TerrenoProvider.tsx +6 -1
  158. package/src/Text.tsx +8 -21
  159. package/src/TextFieldNumberActionSheet.test.tsx +100 -0
  160. package/src/TextFieldNumberActionSheet.tsx +11 -2
  161. package/src/Theme.test.tsx +27 -0
  162. package/src/Theme.tsx +15 -10
  163. package/src/Toast.tsx +1 -1
  164. package/src/ToastNotifications.tsx +4 -4
  165. package/src/Tooltip.test.tsx +64 -0
  166. package/src/Tooltip.tsx +18 -4
  167. package/src/Unifier.ts +26 -3
  168. package/src/WebAddressAutocomplete.tsx +6 -2
  169. package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
  170. package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
  171. package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
  172. package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
  173. package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
  174. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
  175. package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
  176. package/src/__snapshots__/Field.test.tsx.snap +7 -0
  177. package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
  178. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
  179. package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
  180. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
  181. package/src/__snapshots__/Page.test.tsx.snap +13 -1
  182. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
  183. package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
  184. package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
  185. package/src/benchmarks/importGraph.test.ts +71 -0
  186. package/src/benchmarks/importGraph.ts +136 -0
  187. package/src/benchmarks/importTiming.test.ts +42 -0
  188. package/src/benchmarks/importTiming.ts +86 -0
  189. package/src/bunSetup.ts +174 -32
  190. package/src/emojiCategories.test.ts +23 -0
  191. package/src/emojiCategories.ts +46 -0
  192. package/src/index.tsx +27 -13
  193. package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
  194. package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
  195. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
  197. package/src/login/LoginScreen.test.tsx +9 -2
  198. package/src/login/LoginScreen.tsx +6 -2
  199. package/src/login/loginTypes.ts +2 -0
  200. package/src/table/TableDate.test.tsx +35 -1
  201. package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
@@ -1,162 +1,161 @@
1
- import {
2
- Nunito_400Regular,
3
- Nunito_500Medium,
4
- Nunito_700Bold,
5
- useFonts as useTextFonts,
6
- } from "@expo-google-fonts/nunito";
7
- import {
8
- TitilliumWeb_600SemiBold,
9
- TitilliumWeb_700Bold,
10
- useFonts as useHeadingFonts,
11
- } from "@expo-google-fonts/titillium-web";
12
- import type React from "react";
1
+ import React, {lazy, Suspense, useEffect, useMemo} from "react";
13
2
  import {Platform} from "react-native";
14
- import Markdown from "react-native-markdown-display";
3
+ import type Markdown from "react-native-markdown-display";
15
4
 
5
+ import {Spinner} from "./Spinner";
6
+ import {useTerrenoFontsLoaded} from "./TerrenoFontProvider";
16
7
  import {useTheme} from "./Theme";
17
8
 
18
- // Takes markdown and renders it with our theme. We should open source this component.
19
- export const MarkdownView: React.FC<{children: React.ReactNode; inverted?: boolean}> = ({
20
- children,
21
- inverted,
22
- }) => {
23
- const {theme} = useTheme();
9
+ const LazyMarkdown = lazy(() =>
10
+ import("react-native-markdown-display").then((moduleNamespace) => ({
11
+ default: moduleNamespace.default,
12
+ }))
13
+ );
24
14
 
25
- const color = {color: inverted ? theme.text.inverted : theme.text.primary};
15
+ const IS_WEB = Platform.OS === "web";
16
+ const MARKDOWN_SIZES = {
17
+ lg: IS_WEB ? 24 : 20,
18
+ md: IS_WEB ? 18 : 16,
19
+ sm: IS_WEB ? 16 : 14,
20
+ xl: IS_WEB ? 32 : 28,
21
+ } as const;
22
+ const MONO_FONT = IS_WEB ? "monospace" : Platform.select({android: "monospace", ios: "Menlo"});
23
+ const TEXT_FONT_SIZE = IS_WEB ? 16 : 14;
24
+ const TEXT_LINE_HEIGHT = IS_WEB ? 24 : 20;
26
25
 
27
- // Match Heading font sizes to Heading component
28
- // Web sizes (see src/Heading.tsx): sm:16, md:18, lg:24, xl:32
29
- // Mobile sizes: sm:14, md:16, lg:20, xl:28
30
- const isWeb = Platform.OS === "web";
31
- const sizes = {
32
- lg: isWeb ? 24 : 20,
33
- md: isWeb ? 18 : 16,
34
- sm: isWeb ? 16 : 14,
35
- xl: isWeb ? 32 : 28,
36
- } as const;
26
+ interface MarkdownViewProps {
27
+ children: React.ReactNode;
28
+ inverted?: boolean;
29
+ onLoad?: () => void;
30
+ }
31
+
32
+ const MarkdownLoadNotifier: React.FC<{onLoad?: () => void}> = ({onLoad}) => {
33
+ // Fire after react-native-markdown-display has resolved so callers can ignore spinner height.
34
+ useEffect(() => {
35
+ onLoad?.();
36
+ }, [onLoad]);
37
+ return null;
38
+ };
37
39
 
38
- // Load fonts similar to Heading/Text components so fontFamily names resolve
39
- useHeadingFonts({
40
- heading: TitilliumWeb_600SemiBold,
41
- "heading-bold": TitilliumWeb_700Bold,
42
- "heading-semibold": TitilliumWeb_600SemiBold,
43
- });
44
- useTextFonts({
45
- text: Nunito_400Regular,
46
- "text-bold": Nunito_700Bold,
47
- "text-medium": Nunito_500Medium,
48
- "text-regular": Nunito_400Regular,
49
- });
40
+ // Takes markdown and renders it with our theme. We should open source this component.
41
+ const MarkdownViewComponent: React.FC<MarkdownViewProps> = ({children, inverted, onLoad}) => {
42
+ const {theme} = useTheme();
43
+ useTerrenoFontsLoaded();
44
+ const textColor = inverted ? theme.text.inverted : theme.text.primary;
45
+ const markdownStyle = useMemo<React.ComponentProps<typeof Markdown>["style"]>(() => {
46
+ const color = {color: textColor};
47
+ const markdownTextStyle = {
48
+ fontFamily: "text-regular",
49
+ fontSize: TEXT_FONT_SIZE,
50
+ lineHeight: TEXT_LINE_HEIGHT,
51
+ ...color,
52
+ };
50
53
 
51
- const monoFont = isWeb ? "monospace" : Platform.select({android: "monospace", ios: "Menlo"});
52
- const textFontSize = isWeb ? 16 : 14;
53
- const textLineHeight = isWeb ? 24 : 20;
54
- const markdownTextStyle = {
55
- fontFamily: "text-regular",
56
- fontSize: textFontSize,
57
- lineHeight: textLineHeight,
58
- ...color,
59
- };
54
+ return {
55
+ body: {width: "100%", ...markdownTextStyle},
56
+ bullet_list: {width: "100%"},
57
+ bullet_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
58
+ bullet_list_icon: {
59
+ flexShrink: 0,
60
+ marginLeft: 0,
61
+ marginRight: 8,
62
+ minWidth: 16,
63
+ textAlign: "center",
64
+ ...markdownTextStyle,
65
+ },
66
+ code_block: {
67
+ backgroundColor: theme.surface.neutralLight,
68
+ borderColor: theme.border.default,
69
+ borderRadius: 4,
70
+ borderWidth: 1,
71
+ fontFamily: MONO_FONT,
72
+ fontSize: 13,
73
+ padding: 8,
74
+ ...color,
75
+ },
76
+ code_inline: {
77
+ backgroundColor: theme.surface.neutralLight,
78
+ borderColor: theme.border.default,
79
+ borderRadius: 3,
80
+ borderWidth: 1,
81
+ fontFamily: MONO_FONT,
82
+ fontSize: 13,
83
+ paddingHorizontal: 4,
84
+ paddingVertical: 1,
85
+ ...color,
86
+ },
87
+ fence: {
88
+ backgroundColor: theme.surface.neutralLight,
89
+ borderColor: theme.border.default,
90
+ borderRadius: 4,
91
+ borderWidth: 1,
92
+ fontFamily: MONO_FONT,
93
+ fontSize: 13,
94
+ padding: 8,
95
+ ...color,
96
+ },
97
+ heading1: {
98
+ fontFamily: "heading-bold",
99
+ fontSize: MARKDOWN_SIZES.xl,
100
+ lineHeight: MARKDOWN_SIZES.xl * 1.25,
101
+ ...color,
102
+ },
103
+ heading2: {
104
+ fontFamily: "heading-bold",
105
+ fontSize: MARKDOWN_SIZES.lg,
106
+ lineHeight: MARKDOWN_SIZES.lg * 1.25,
107
+ ...color,
108
+ },
109
+ heading3: {
110
+ fontFamily: "heading-bold",
111
+ fontSize: MARKDOWN_SIZES.md,
112
+ lineHeight: MARKDOWN_SIZES.md * 1.25,
113
+ ...color,
114
+ },
115
+ heading4: {
116
+ fontFamily: "heading-semibold",
117
+ fontSize: MARKDOWN_SIZES.sm,
118
+ lineHeight: MARKDOWN_SIZES.sm * 1.25,
119
+ ...color,
120
+ },
121
+ // h5/h6 map to small as well for consistency, slightly smaller visually handled by weight
122
+ heading5: {
123
+ fontFamily: "heading-semibold",
124
+ fontSize: MARKDOWN_SIZES.sm,
125
+ lineHeight: MARKDOWN_SIZES.sm * 1.25,
126
+ ...color,
127
+ },
128
+ heading6: {
129
+ fontFamily: "heading-semibold",
130
+ fontSize: MARKDOWN_SIZES.sm,
131
+ lineHeight: MARKDOWN_SIZES.sm * 1.25,
132
+ ...color,
133
+ },
134
+ list_item: {alignItems: "flex-start", flexDirection: "row", width: "100%"},
135
+ ordered_list: {width: "100%"},
136
+ ordered_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
137
+ ordered_list_icon: {
138
+ flexShrink: 0,
139
+ marginLeft: 0,
140
+ marginRight: 8,
141
+ minWidth: 32,
142
+ textAlign: "right",
143
+ ...markdownTextStyle,
144
+ },
145
+ paragraph: {flexShrink: 1, width: "100%", ...markdownTextStyle},
146
+ text: color,
147
+ textgroup: {flexShrink: 1, minWidth: 0},
148
+ };
149
+ }, [textColor, theme.border.default, theme.surface.neutralLight]);
60
150
 
61
151
  return (
62
- <Markdown
63
- style={{
64
- body: {width: "100%", ...markdownTextStyle},
65
- bullet_list: {width: "100%"},
66
- bullet_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
67
- bullet_list_icon: {
68
- flexShrink: 0,
69
- marginLeft: 0,
70
- marginRight: 8,
71
- minWidth: 16,
72
- textAlign: "center",
73
- ...markdownTextStyle,
74
- },
75
- code_block: {
76
- backgroundColor: theme.surface.neutralLight,
77
- borderColor: theme.border.default,
78
- borderRadius: 4,
79
- borderWidth: 1,
80
- fontFamily: monoFont,
81
- fontSize: 13,
82
- padding: 8,
83
- ...color,
84
- },
85
- code_inline: {
86
- backgroundColor: theme.surface.neutralLight,
87
- borderColor: theme.border.default,
88
- borderRadius: 3,
89
- borderWidth: 1,
90
- fontFamily: monoFont,
91
- fontSize: 13,
92
- paddingHorizontal: 4,
93
- paddingVertical: 1,
94
- ...color,
95
- },
96
- fence: {
97
- backgroundColor: theme.surface.neutralLight,
98
- borderColor: theme.border.default,
99
- borderRadius: 4,
100
- borderWidth: 1,
101
- fontFamily: monoFont,
102
- fontSize: 13,
103
- padding: 8,
104
- ...color,
105
- },
106
- heading1: {
107
- fontFamily: "heading-bold",
108
- fontSize: sizes.xl,
109
- lineHeight: sizes.xl * 1.25,
110
- ...color,
111
- },
112
- heading2: {
113
- fontFamily: "heading-bold",
114
- fontSize: sizes.lg,
115
- lineHeight: sizes.lg * 1.25,
116
- ...color,
117
- },
118
- heading3: {
119
- fontFamily: "heading-bold",
120
- fontSize: sizes.md,
121
- lineHeight: sizes.md * 1.25,
122
- ...color,
123
- },
124
- heading4: {
125
- fontFamily: "heading-semibold",
126
- fontSize: sizes.sm,
127
- lineHeight: sizes.sm * 1.25,
128
- ...color,
129
- },
130
- // h5/h6 map to small as well for consistency, slightly smaller visually handled by weight
131
- heading5: {
132
- fontFamily: "heading-semibold",
133
- fontSize: sizes.sm,
134
- lineHeight: sizes.sm * 1.25,
135
- ...color,
136
- },
137
- heading6: {
138
- fontFamily: "heading-semibold",
139
- fontSize: sizes.sm,
140
- lineHeight: sizes.sm * 1.25,
141
- ...color,
142
- },
143
- list_item: {alignItems: "flex-start", flexDirection: "row", width: "100%"},
144
- ordered_list: {width: "100%"},
145
- ordered_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
146
- ordered_list_icon: {
147
- flexShrink: 0,
148
- marginLeft: 0,
149
- marginRight: 8,
150
- minWidth: 32,
151
- textAlign: "right",
152
- ...markdownTextStyle,
153
- },
154
- paragraph: {flexShrink: 1, width: "100%", ...markdownTextStyle},
155
- text: color,
156
- textgroup: {flexShrink: 1, minWidth: 0},
157
- }}
158
- >
159
- {children}
160
- </Markdown>
152
+ <Suspense fallback={<Spinner />}>
153
+ <MarkdownLoadNotifier onLoad={onLoad} />
154
+ <LazyMarkdown style={markdownStyle}>{children}</LazyMarkdown>
155
+ </Suspense>
161
156
  );
162
157
  };
158
+
159
+ MarkdownViewComponent.displayName = "MarkdownView";
160
+
161
+ export const MarkdownView = React.memo(MarkdownViewComponent);
package/src/MediaQuery.ts CHANGED
@@ -1,46 +1,42 @@
1
1
  import {Dimensions} from "react-native";
2
2
 
3
- export const mediaQuery = (): "xs" | "sm" | "md" | "lg" => {
4
- const width = Dimensions.get("window").width;
5
- if (width < 576) {
6
- return "xs";
7
- } else if (width < 768) {
8
- return "sm";
9
- } else if (width < 1312) {
10
- return "md";
11
- } else {
12
- return "lg";
13
- }
3
+ import {
4
+ getBreakpointForWidth,
5
+ getBreakpointSurface,
6
+ isBreakpointAtLeast,
7
+ isSupportedDesktopViewport,
8
+ type ResponsiveBreakpoint,
9
+ } from "./ResponsiveBreakpoint";
10
+
11
+ export {
12
+ type BreakpointSurface,
13
+ getBreakpointForWidth,
14
+ getBreakpointMinWidths,
15
+ getBreakpointSurface,
16
+ isBreakpointAtLeast,
17
+ isSupportedDesktopViewport,
18
+ NATIVE_BREAKPOINT_MIN_WIDTH,
19
+ type ResponsiveBreakpoint,
20
+ WEB_BREAKPOINT_MIN_WIDTH,
21
+ } from "./ResponsiveBreakpoint";
22
+
23
+ export const mediaQuery = (): ResponsiveBreakpoint => {
24
+ return getBreakpointForWidth(Dimensions.get("window").width);
14
25
  };
15
26
 
16
- export const mediaQueryLargerThan = (size: "xs" | "sm" | "md" | "lg"): boolean => {
27
+ export const mediaQueryLargerThan = (size: ResponsiveBreakpoint): boolean => {
17
28
  const media = mediaQuery();
18
- if (size === "xs") {
19
- return true;
20
- } else if (size === "sm") {
21
- return ["sm", "md", "lg"].includes(media);
22
- } else if (size === "md") {
23
- return ["md", "lg"].includes(media);
24
- } else if (size === "lg") {
25
- return ["lg"].includes(media);
26
- }
27
- return false;
29
+ return isBreakpointAtLeast({breakpoint: media, minimum: size});
28
30
  };
29
31
 
30
- export const mediaQuerySmallerThan = (size: "xs" | "sm" | "md" | "lg"): boolean => {
32
+ export const mediaQuerySmallerThan = (size: ResponsiveBreakpoint): boolean => {
31
33
  const media = mediaQuery();
32
- if (size === "lg") {
33
- return true;
34
- } else if (size === "md") {
35
- return ["xs", "sm", "md"].includes(media);
36
- } else if (size === "sm") {
37
- return ["xs", "sm"].includes(media);
38
- } else if (size === "xs") {
39
- return ["xs"].includes(media);
40
- }
41
- return false;
34
+ return !isBreakpointAtLeast({breakpoint: media, minimum: size}) || media === size;
42
35
  };
43
36
 
44
37
  export const isMobileDevice = (): boolean => {
45
- return !mediaQueryLargerThan("sm");
38
+ return !isSupportedDesktopViewport({
39
+ breakpoint: mediaQuery(),
40
+ surface: getBreakpointSurface(),
41
+ });
46
42
  };
@@ -1,6 +1,6 @@
1
1
  import camelCase from "lodash/camelCase";
2
2
  import type React from "react";
3
- import {createContext, useContext, useEffect, useState} from "react";
3
+ import {createContext, useCallback, useContext, useEffect, useMemo, useState} from "react";
4
4
 
5
5
  import type {
6
6
  ModelFieldConfig,
@@ -16,34 +16,45 @@ const OpenAPIContext = createContext<OpenAPIContextType | null>(null);
16
16
  export const OpenAPIProvider = ({children, specUrl}: OpenAPIProviderProps): React.ReactElement => {
17
17
  const [spec, setSpec] = useState<OpenAPISpec | null>(null);
18
18
 
19
- const getModelFields = (modelName: string): ModelFields | null => {
20
- const modelPath = `/${camelCase(modelName.replace(/\s/g, ""))}/`;
21
- const rootConfig = spec?.paths?.[modelPath];
22
- if (!rootConfig) {
23
- if (spec?.paths && modelName) {
24
- console.warn(`No OpenAPI model found for ${modelName}`);
19
+ const getModelFields = useCallback(
20
+ (modelName: string): ModelFields | null => {
21
+ const modelPath = `/${camelCase(modelName.replace(/\s/g, ""))}/`;
22
+ const rootConfig = spec?.paths?.[modelPath];
23
+ if (!rootConfig) {
24
+ if (spec?.paths && modelName) {
25
+ console.warn(`No OpenAPI model found for ${modelName}`);
26
+ }
27
+ return null;
25
28
  }
26
- return null;
27
- }
28
29
 
29
- return rootConfig?.get?.responses?.["200"]?.content?.["application/json"]?.schema?.properties
30
- ?.data?.items;
31
- };
30
+ return rootConfig?.get?.responses?.["200"]?.content?.["application/json"]?.schema?.properties
31
+ ?.data?.items;
32
+ },
33
+ [spec]
34
+ );
32
35
 
33
- const getModelField = (modelName: string, fieldName: string): ModelFieldConfig => {
34
- const fields = getModelFields(modelName);
35
- const dotFields = fieldName.split(".");
36
+ const getModelField = useCallback(
37
+ (modelName: string, fieldName: string): ModelFieldConfig => {
38
+ const fields = getModelFields(modelName);
39
+ const dotFields = fieldName.split(".");
36
40
 
37
- let field = fields?.properties?.[dotFields[0]];
38
- if (!field && fieldName && fields?.properties) {
39
- console.warn(`No OpenAPI field found for ${modelName}:${fieldName}`);
40
- }
41
+ let field = fields?.properties?.[dotFields[0]];
42
+ if (!field && fieldName && fields?.properties) {
43
+ console.warn(`No OpenAPI field found for ${modelName}:${fieldName}`);
44
+ }
41
45
 
42
- for (const dotField of dotFields.slice(1)) {
43
- field = (field?.properties as Record<string, OpenApiProperty> | undefined)?.[dotField];
44
- }
45
- return field;
46
- };
46
+ for (const dotField of dotFields.slice(1)) {
47
+ field = (field?.properties as Record<string, OpenApiProperty> | undefined)?.[dotField];
48
+ }
49
+ return field;
50
+ },
51
+ [getModelFields]
52
+ );
53
+
54
+ const contextValue = useMemo(
55
+ (): OpenAPIContextType => ({getModelField, getModelFields, spec}),
56
+ [getModelField, getModelFields, spec]
57
+ );
47
58
 
48
59
  // Fetch the OpenAPI spec from the provided URL.
49
60
  useEffect((): void => {
@@ -59,11 +70,7 @@ export const OpenAPIProvider = ({children, specUrl}: OpenAPIProviderProps): Reac
59
70
  .catch((error: unknown) => console.error(`Error fetching OpenAPI spec: ${String(error)}`));
60
71
  }, [specUrl]);
61
72
 
62
- return (
63
- <OpenAPIContext.Provider value={{getModelField, getModelFields, spec}}>
64
- {children}
65
- </OpenAPIContext.Provider>
66
- );
73
+ return <OpenAPIContext.Provider value={contextValue}>{children}</OpenAPIContext.Provider>;
67
74
  };
68
75
 
69
76
  export const useOpenAPISpec = () => {
@@ -0,0 +1,200 @@
1
+ import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
2
+ import {act, render, waitFor} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ import React, {useEffect, useState} from "react";
5
+ import {Text, View} from "react-native";
6
+
7
+ import type {OpenAPISpec} from "./Common";
8
+ import {OpenAPIProvider, useOpenAPISpec} from "./OpenAPIContext";
9
+
10
+ const SPEC_V0: OpenAPISpec = {
11
+ paths: {
12
+ "/todoItems/": {
13
+ get: {
14
+ responses: {
15
+ "200": {
16
+ content: {
17
+ "application/json": {
18
+ schema: {
19
+ properties: {
20
+ data: {
21
+ items: {
22
+ properties: {
23
+ title: {description: "Title for the todo", type: "string"},
24
+ },
25
+ required: ["title"],
26
+ type: "object",
27
+ },
28
+ },
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ },
35
+ },
36
+ },
37
+ },
38
+ };
39
+
40
+ const SPEC_V1: OpenAPISpec = {
41
+ paths: {
42
+ "/todoItems/": {
43
+ get: {
44
+ responses: {
45
+ "200": {
46
+ content: {
47
+ "application/json": {
48
+ schema: {
49
+ properties: {
50
+ data: {
51
+ items: {
52
+ properties: {
53
+ title: {description: "Updated title description", type: "string"},
54
+ },
55
+ required: ["title"],
56
+ type: "object",
57
+ },
58
+ },
59
+ },
60
+ },
61
+ },
62
+ },
63
+ },
64
+ },
65
+ },
66
+ },
67
+ },
68
+ };
69
+
70
+ const specByUrl: Record<string, OpenAPISpec> = {
71
+ "https://api.example.com/openapi-v0.json": SPEC_V0,
72
+ "https://api.example.com/openapi-v1.json": SPEC_V1,
73
+ };
74
+
75
+ const ParentNoise: React.FC<{children: React.ReactElement}> = ({children}) => {
76
+ const [, setNoise] = useState(0);
77
+
78
+ // Trigger parent rerenders without changing the loaded OpenAPI spec.
79
+ useEffect((): void => {
80
+ setNoise((value) => value + 1);
81
+ }, []);
82
+
83
+ return children;
84
+ };
85
+
86
+ let fieldProbeRenderCount = 0;
87
+
88
+ const FieldProbe: React.FC = React.memo(() => {
89
+ fieldProbeRenderCount += 1;
90
+ const {getModelField} = useOpenAPISpec();
91
+ const field = getModelField("Todo Items", "title");
92
+ return <View accessibilityLabel={field?.description ?? "missing"} testID="field-probe" />;
93
+ });
94
+
95
+ const ContextProbe: React.FC<{
96
+ onContext?: (context: ReturnType<typeof useOpenAPISpec>) => void;
97
+ }> = ({onContext}) => {
98
+ const context = useOpenAPISpec();
99
+ onContext?.(context);
100
+ return <Text>probe</Text>;
101
+ };
102
+
103
+ describe("OpenAPI context rerender regression coverage", () => {
104
+ const originalFetch = globalThis.fetch;
105
+
106
+ beforeEach(() => {
107
+ fieldProbeRenderCount = 0;
108
+ globalThis.fetch = mock(async (input: RequestInfo | URL) => {
109
+ const url = typeof input === "string" ? input : input.toString();
110
+ const spec = specByUrl[url];
111
+ if (!spec) {
112
+ throw new Error(`Unexpected OpenAPI spec URL: ${url}`);
113
+ }
114
+ return {
115
+ json: async () => spec,
116
+ };
117
+ }) as unknown as typeof globalThis.fetch;
118
+ });
119
+
120
+ afterEach(() => {
121
+ globalThis.fetch = originalFetch;
122
+ });
123
+
124
+ it("skips equivalent OpenAPI consumer renders and updates field lookups when the spec changes", async () => {
125
+ const result = render(
126
+ <ParentNoise>
127
+ <OpenAPIProvider specUrl="https://api.example.com/openapi-v0.json">
128
+ <FieldProbe />
129
+ </OpenAPIProvider>
130
+ </ParentNoise>
131
+ );
132
+
133
+ await waitFor(() => {
134
+ expect(result.getByLabelText("Title for the todo")).toBeTruthy();
135
+ });
136
+ assert.equal(fieldProbeRenderCount, 2);
137
+
138
+ await act(async () => {
139
+ result.rerender(
140
+ <ParentNoise>
141
+ <OpenAPIProvider specUrl="https://api.example.com/openapi-v0.json">
142
+ <FieldProbe />
143
+ </OpenAPIProvider>
144
+ </ParentNoise>
145
+ );
146
+ });
147
+ assert.equal(fieldProbeRenderCount, 2);
148
+
149
+ await act(async () => {
150
+ result.rerender(
151
+ <ParentNoise>
152
+ <OpenAPIProvider specUrl="https://api.example.com/openapi-v1.json">
153
+ <FieldProbe />
154
+ </OpenAPIProvider>
155
+ </ParentNoise>
156
+ );
157
+ });
158
+
159
+ await waitFor(() => {
160
+ expect(result.getByLabelText("Updated title description")).toBeTruthy();
161
+ });
162
+ assert.equal(fieldProbeRenderCount, 3);
163
+ assert.isNull(result.queryByLabelText("Title for the todo"));
164
+ });
165
+
166
+ it("keeps stable OpenAPI action references across equivalent provider renders", async () => {
167
+ let capturedContext: ReturnType<typeof useOpenAPISpec> | null = null;
168
+
169
+ const result = render(
170
+ <OpenAPIProvider specUrl="https://api.example.com/openapi-v0.json">
171
+ <ContextProbe
172
+ onContext={(context) => {
173
+ capturedContext = context;
174
+ }}
175
+ />
176
+ </OpenAPIProvider>
177
+ );
178
+
179
+ await waitFor(() => {
180
+ expect(capturedContext?.spec).toEqual(SPEC_V0);
181
+ });
182
+ const initialGetModelField = capturedContext?.getModelField;
183
+ const initialGetModelFields = capturedContext?.getModelFields;
184
+
185
+ await act(async () => {
186
+ result.rerender(
187
+ <OpenAPIProvider specUrl="https://api.example.com/openapi-v0.json">
188
+ <ContextProbe
189
+ onContext={(context) => {
190
+ capturedContext = context;
191
+ }}
192
+ />
193
+ </OpenAPIProvider>
194
+ );
195
+ });
196
+
197
+ expect(capturedContext?.getModelField).toBe(initialGetModelField);
198
+ expect(capturedContext?.getModelFields).toBe(initialGetModelFields);
199
+ });
200
+ });