@terreno/ui 57.2.0 → 57.4.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.
- package/.ai/guidelines/core.md +1 -1
- package/README.md +17 -8
- package/dist/ActionSheet.d.ts +3 -3
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AnnouncementBanner.d.ts +12 -0
- package/dist/AnnouncementBanner.js +61 -0
- package/dist/AnnouncementBanner.js.map +1 -0
- package/dist/AnnouncementNavigator.d.ts +11 -0
- package/dist/AnnouncementNavigator.js +189 -0
- package/dist/AnnouncementNavigator.js.map +1 -0
- package/dist/AnnouncementScreen.d.ts +12 -0
- package/dist/AnnouncementScreen.js +28 -0
- package/dist/AnnouncementScreen.js.map +1 -0
- package/dist/AreaChart.d.ts +5 -0
- package/dist/AreaChart.js +69 -0
- package/dist/AreaChart.js.map +1 -0
- package/dist/BarChart.d.ts +5 -0
- package/dist/BarChart.js +89 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +116 -35
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +215 -9
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +46 -12
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DashboardGrid.d.ts +4 -0
- package/dist/DashboardGrid.js +38 -0
- package/dist/DashboardGrid.js.map +1 -0
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +278 -47
- package/dist/DataTable.js.map +1 -1
- package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
- package/dist/DataTableHeaderInfoMarkdown.js +7 -0
- package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
- package/dist/DonutChart.d.ts +5 -0
- package/dist/DonutChart.js +84 -0
- package/dist/DonutChart.js.map +1 -0
- package/dist/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/Filter.js +12 -2
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +28 -15
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +5 -2
- package/dist/Heading.js +6 -8
- package/dist/Heading.js.map +1 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Icon.d.ts +1 -2
- package/dist/Icon.js +4 -1
- package/dist/Icon.js.map +1 -1
- package/dist/LineChart.d.ts +5 -0
- package/dist/LineChart.js +68 -0
- package/dist/LineChart.js.map +1 -0
- package/dist/MarkdownEmbed.d.ts +6 -0
- package/dist/MarkdownEmbed.js +17 -0
- package/dist/MarkdownEmbed.js.map +1 -0
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +81 -44
- package/dist/MarkdownView.js.map +1 -1
- package/dist/MediaQuery.d.ts +5 -3
- package/dist/MediaQuery.js +9 -40
- package/dist/MediaQuery.js.map +1 -1
- package/dist/Modal.js +12 -10
- package/dist/Modal.js.map +1 -1
- package/dist/ModalSheet.d.ts +5 -1
- package/dist/ModalSheet.js +31 -13
- package/dist/ModalSheet.js.map +1 -1
- package/dist/MultiselectField.js +4 -9
- package/dist/MultiselectField.js.map +1 -1
- package/dist/NotificationBell.d.ts +16 -0
- package/dist/NotificationBell.js +15 -0
- package/dist/NotificationBell.js.map +1 -0
- package/dist/NotificationInbox.d.ts +21 -0
- package/dist/NotificationInbox.js +41 -0
- package/dist/NotificationInbox.js.map +1 -0
- package/dist/NotificationPreferences.d.ts +14 -0
- package/dist/NotificationPreferences.js +32 -0
- package/dist/NotificationPreferences.js.map +1 -0
- package/dist/OpenAPIContext.js +7 -6
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.js +7 -1
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.js +8 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Popover.d.ts +12 -0
- package/dist/Popover.js +37 -0
- package/dist/Popover.js.map +1 -0
- package/dist/PortalHost.js +10 -1
- package/dist/PortalHost.js.map +1 -1
- package/dist/ResponsiveBreakpoint.d.ts +65 -0
- package/dist/ResponsiveBreakpoint.js +111 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.js +7 -12
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +2 -2
- package/dist/SplitPage.native.js +1 -6
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +12 -10
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoFontProvider.d.ts +7 -0
- package/dist/TerrenoFontProvider.js +27 -0
- package/dist/TerrenoFontProvider.js.map +1 -0
- package/dist/TerrenoProvider.js +4 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Text.d.ts +5 -2
- package/dist/Text.js +6 -11
- package/dist/Text.js.map +1 -1
- package/dist/TextField.js +83 -6
- package/dist/TextField.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +9 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Theme.js +10 -8
- package/dist/Theme.js.map +1 -1
- package/dist/ToastNotifications.d.ts +4 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +4 -3
- package/dist/Tooltip.js +14 -3
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +26 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +6 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/announcementBuildVersion.d.ts +6 -0
- package/dist/announcementBuildVersion.js +21 -0
- package/dist/announcementBuildVersion.js.map +1 -0
- package/dist/announcementFrequency.d.ts +42 -0
- package/dist/announcementFrequency.js +163 -0
- package/dist/announcementFrequency.js.map +1 -0
- package/dist/announcementPlatform.d.ts +2 -0
- package/dist/announcementPlatform.js +11 -0
- package/dist/announcementPlatform.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +12 -0
- package/dist/charts/ChartFrame.js +13 -0
- package/dist/charts/ChartFrame.js.map +1 -0
- package/dist/charts/bars.d.ts +18 -0
- package/dist/charts/bars.js +29 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/layout.d.ts +47 -0
- package/dist/charts/layout.js +56 -0
- package/dist/charts/layout.js.map +1 -0
- package/dist/charts/paths.d.ts +31 -0
- package/dist/charts/paths.js +52 -0
- package/dist/charts/paths.js.map +1 -0
- package/dist/charts/scales.d.ts +6 -0
- package/dist/charts/scales.js +43 -0
- package/dist/charts/scales.js.map +1 -0
- package/dist/charts/theme.d.ts +9 -0
- package/dist/charts/theme.js +15 -0
- package/dist/charts/theme.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +17 -0
- package/dist/charts/types/chartTypes.js +2 -0
- package/dist/charts/types/chartTypes.js.map +1 -0
- package/dist/dashboardGridLayout.d.ts +22 -0
- package/dist/dashboardGridLayout.js +33 -0
- package/dist/dashboardGridLayout.js.map +1 -0
- package/dist/dataTableFilters.d.ts +33 -0
- package/dist/dataTableFilters.js +221 -0
- package/dist/dataTableFilters.js.map +1 -0
- package/dist/dataTableListQuery.d.ts +42 -0
- package/dist/dataTableListQuery.js +161 -0
- package/dist/dataTableListQuery.js.map +1 -0
- package/dist/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +30 -13
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +53 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +51 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +1 -0
- package/dist/login/LoginScreen.js +4 -2
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/loginTypes.d.ts +2 -0
- package/dist/markdownEmbeds.d.ts +6 -0
- package/dist/markdownEmbeds.js +59 -0
- package/dist/markdownEmbeds.js.map +1 -0
- package/dist/testing/resolveTestId.js +2 -1
- package/dist/testing/resolveTestId.js.map +1 -1
- package/dist/testing/types.d.ts +3 -0
- package/dist/textFieldOscillationGuard.d.ts +25 -0
- package/dist/textFieldOscillationGuard.js +41 -0
- package/dist/textFieldOscillationGuard.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
- package/dist/useAcknowledgeAnnouncement.js +94 -0
- package/dist/useAcknowledgeAnnouncement.js.map +1 -0
- package/dist/useAnnouncements.d.ts +73 -0
- package/dist/useAnnouncements.js +66 -0
- package/dist/useAnnouncements.js.map +1 -0
- package/package.json +46 -18
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AnnouncementBanner.test.tsx +267 -0
- package/src/AnnouncementBanner.tsx +128 -0
- package/src/AnnouncementNavigator.test.tsx +759 -0
- package/src/AnnouncementNavigator.tsx +287 -0
- package/src/AnnouncementScreen.test.tsx +97 -0
- package/src/AnnouncementScreen.tsx +70 -0
- package/src/AreaChart.test.tsx +68 -0
- package/src/AreaChart.tsx +194 -0
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/BarChart.test.tsx +96 -0
- package/src/BarChart.tsx +208 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +273 -0
- package/src/Button.tsx +163 -50
- package/src/Common.ts +219 -25
- package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
- package/src/ConsentFormScreen.test.tsx +145 -8
- package/src/ConsentFormScreen.tsx +74 -25
- package/src/ConsentNavigator.test.tsx +55 -0
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DashboardGrid.test.tsx +75 -0
- package/src/DashboardGrid.tsx +69 -0
- package/src/DataTable.test.tsx +296 -1
- package/src/DataTable.tsx +623 -160
- package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
- package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
- package/src/DataTableVirtualizationRegression.test.tsx +266 -0
- package/src/DateTimeField.test.tsx +54 -0
- package/src/DonutChart.test.tsx +121 -0
- package/src/DonutChart.tsx +160 -0
- package/src/EmojiSelector.test.tsx +84 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/Field.test.tsx +18 -0
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/Filter.test.tsx +25 -0
- package/src/Filter.tsx +38 -7
- package/src/FilterAccordion.test.tsx +37 -0
- package/src/FilterBoolean.test.tsx +96 -0
- package/src/FilterSelectMenu.test.tsx +23 -0
- package/src/GPTChat.test.tsx +803 -0
- package/src/GPTChat.tsx +177 -87
- package/src/GPTMemoryModal.test.tsx +67 -0
- package/src/Heading.tsx +8 -14
- package/src/HeightActionSheet.test.tsx +6 -9
- package/src/Hyperlink.tsx +5 -18
- package/src/Icon.tsx +6 -2
- package/src/LineChart.test.tsx +166 -0
- package/src/LineChart.tsx +190 -0
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownEmbed.test.tsx +34 -0
- package/src/MarkdownEmbed.tsx +43 -0
- package/src/MarkdownView.test.tsx +112 -11
- package/src/MarkdownView.tsx +197 -150
- package/src/MediaQuery.ts +30 -34
- package/src/Modal.test.tsx +107 -14
- package/src/Modal.tsx +20 -8
- package/src/ModalSheet.test.tsx +121 -9
- package/src/ModalSheet.tsx +46 -11
- package/src/MultiselectField.test.tsx +21 -0
- package/src/MultiselectField.tsx +11 -13
- package/src/NotificationBell.test.tsx +91 -0
- package/src/NotificationBell.tsx +77 -0
- package/src/NotificationInbox.test.tsx +130 -0
- package/src/NotificationInbox.tsx +144 -0
- package/src/NotificationPreferences.test.tsx +25 -0
- package/src/NotificationPreferences.tsx +75 -0
- package/src/OpenAPIContext.tsx +36 -29
- package/src/OpenAPIRenderRegression.test.tsx +200 -0
- package/src/P0RenderRegression.test.tsx +214 -0
- package/src/P1RenderRegression.test.tsx +141 -0
- package/src/P2ButtonRenderRegression.test.tsx +158 -0
- package/src/Page.test.tsx +13 -0
- package/src/Page.tsx +25 -5
- package/src/PickerSelect.test.tsx +38 -0
- package/src/PickerSelect.tsx +7 -0
- package/src/Popover.test.tsx +151 -0
- package/src/Popover.tsx +211 -0
- package/src/PortalHost.tsx +12 -6
- package/src/ResponsiveBreakpoint.test.tsx +184 -0
- package/src/ResponsiveBreakpoint.tsx +195 -0
- package/src/RootImportRegression.test.tsx +82 -0
- package/src/SplitPage.native.tsx +5 -9
- package/src/SplitPage.tsx +16 -19
- package/src/TapToEdit.test.tsx +45 -0
- package/src/TapToEdit.tsx +23 -18
- package/src/TerrenoFontProvider.test.tsx +38 -0
- package/src/TerrenoFontProvider.tsx +50 -0
- package/src/TerrenoProvider.tsx +6 -1
- package/src/Text.tsx +8 -21
- package/src/TextField.test.tsx +421 -0
- package/src/TextField.tsx +121 -4
- package/src/TextFieldNumberActionSheet.test.tsx +100 -0
- package/src/TextFieldNumberActionSheet.tsx +11 -2
- package/src/Theme.test.tsx +27 -0
- package/src/Theme.tsx +15 -10
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -4
- package/src/Tooltip.test.tsx +64 -0
- package/src/Tooltip.tsx +18 -4
- package/src/Unifier.ts +26 -3
- package/src/WebAddressAutocomplete.tsx +6 -2
- package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
- package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
- package/src/__snapshots__/Field.test.tsx.snap +29 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
- package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/Page.test.tsx.snap +13 -1
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
- package/src/__snapshots__/TextField.test.tsx.snap +5 -5
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/announcementBuildVersion.test.ts +43 -0
- package/src/announcementBuildVersion.ts +21 -0
- package/src/announcementFrequency.test.ts +245 -0
- package/src/announcementFrequency.ts +246 -0
- package/src/announcementPlatform.test.ts +27 -0
- package/src/announcementPlatform.ts +13 -0
- package/src/benchmarks/importGraph.test.ts +71 -0
- package/src/benchmarks/importGraph.ts +136 -0
- package/src/benchmarks/importTiming.test.ts +42 -0
- package/src/benchmarks/importTiming.ts +86 -0
- package/src/bunSetup.ts +174 -32
- package/src/charts/ChartFrame.tsx +67 -0
- package/src/charts/bars.test.ts +56 -0
- package/src/charts/bars.ts +53 -0
- package/src/charts/layout.test.ts +80 -0
- package/src/charts/layout.ts +99 -0
- package/src/charts/paths.test.ts +79 -0
- package/src/charts/paths.ts +100 -0
- package/src/charts/scales.test.ts +59 -0
- package/src/charts/scales.ts +60 -0
- package/src/charts/theme.test.ts +22 -0
- package/src/charts/theme.ts +24 -0
- package/src/charts/types/chartTypes.ts +19 -0
- package/src/dashboardGridLayout.test.ts +90 -0
- package/src/dashboardGridLayout.ts +60 -0
- package/src/dataTableFilters.test.tsx +552 -0
- package/src/dataTableFilters.tsx +441 -0
- package/src/dataTableListQuery.test.ts +220 -0
- package/src/dataTableListQuery.ts +201 -0
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +48 -14
- package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
- package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +134 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
- package/src/login/loginTypes.ts +2 -0
- package/src/markdownEmbeds.test.ts +53 -0
- package/src/markdownEmbeds.ts +62 -0
- package/src/pdfHtmlTemplate.test.ts +119 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
- package/src/testing/resolveTestId.test.ts +3 -0
- package/src/testing/resolveTestId.ts +1 -0
- package/src/testing/types.ts +3 -0
- package/src/textFieldOscillationGuard.test.ts +63 -0
- package/src/textFieldOscillationGuard.ts +89 -0
- package/src/types/react-native-markdown-display.d.ts +6 -0
- package/src/types/react-native-swiper-flatlist.d.ts +5 -5
- package/src/useAcknowledgeAnnouncement.test.ts +223 -0
- package/src/useAcknowledgeAnnouncement.ts +166 -0
- package/src/useAnnouncements.test.ts +226 -0
- package/src/useAnnouncements.ts +150 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {existsSync, readFileSync, statSync} from "node:fs";
|
|
2
|
+
import {dirname, join, resolve} from "node:path";
|
|
3
|
+
|
|
4
|
+
const SRC_ROOT = resolve(import.meta.dir, "..");
|
|
5
|
+
const DIST_ROOT = resolve(import.meta.dir, "../../dist");
|
|
6
|
+
|
|
7
|
+
const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
8
|
+
|
|
9
|
+
const resolveRelativeModule = (fromFile: string, specifier: string): string | null => {
|
|
10
|
+
if (!specifier.startsWith(".")) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const basePath = resolve(dirname(fromFile), specifier);
|
|
15
|
+
const candidates = [
|
|
16
|
+
basePath,
|
|
17
|
+
...SOURCE_EXTENSIONS.map((extension) => `${basePath}${extension}`),
|
|
18
|
+
...SOURCE_EXTENSIONS.map((extension) => join(basePath, `index${extension}`)),
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
for (const candidate of candidates) {
|
|
22
|
+
if (existsSync(candidate)) {
|
|
23
|
+
return candidate;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const collectSpecifiers = (source: string): string[] => {
|
|
31
|
+
const specifiers: string[] = [];
|
|
32
|
+
const patterns = [
|
|
33
|
+
/^\s*import\s+(?!type\b)[\s\S]*?\sfrom\s+["']([^"']+)["']/gm,
|
|
34
|
+
/^\s*export\s+\*\s+from\s+["']([^"']+)["']/gm,
|
|
35
|
+
/^\s*export\s+\{[^}]+\}\s+from\s+["']([^"']+)["']/gm,
|
|
36
|
+
/^\s*export\s+\{default\s+as\s+\w+\}\s+from\s+["']([^"']+)["']/gm,
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
for (const pattern of patterns) {
|
|
40
|
+
for (const match of source.matchAll(pattern)) {
|
|
41
|
+
const specifier = match[1];
|
|
42
|
+
if (specifier) {
|
|
43
|
+
specifiers.push(specifier);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return specifiers;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const walkModuleGraph = ({entryFile, visited}: {entryFile: string; visited: Set<string>}): void => {
|
|
52
|
+
if (visited.has(entryFile)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
visited.add(entryFile);
|
|
57
|
+
|
|
58
|
+
let source = "";
|
|
59
|
+
try {
|
|
60
|
+
source = readFileSync(entryFile, "utf8");
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const specifier of collectSpecifiers(source)) {
|
|
66
|
+
const resolved = resolveRelativeModule(entryFile, specifier);
|
|
67
|
+
if (resolved) {
|
|
68
|
+
walkModuleGraph({entryFile: resolved, visited});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export interface ImportGraphMeasurement {
|
|
74
|
+
entryFile: string;
|
|
75
|
+
moduleCount: number;
|
|
76
|
+
modulePaths: string[];
|
|
77
|
+
outputBytes: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const measureImportGraph = (entryFile: string): ImportGraphMeasurement => {
|
|
81
|
+
const visited = new Set<string>();
|
|
82
|
+
walkModuleGraph({entryFile, visited});
|
|
83
|
+
|
|
84
|
+
const modulePaths = [...visited].sort();
|
|
85
|
+
const outputBytes = modulePaths.reduce((total, modulePath) => {
|
|
86
|
+
try {
|
|
87
|
+
return total + statSync(modulePath).size;
|
|
88
|
+
} catch {
|
|
89
|
+
return total;
|
|
90
|
+
}
|
|
91
|
+
}, 0);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
entryFile,
|
|
95
|
+
moduleCount: modulePaths.length,
|
|
96
|
+
modulePaths,
|
|
97
|
+
outputBytes,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const resolvePackageEntry = (importPath: string): string => {
|
|
102
|
+
if (importPath === "@terreno/ui") {
|
|
103
|
+
return join(SRC_ROOT, "index.tsx");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (importPath.startsWith("@terreno/ui/")) {
|
|
107
|
+
const moduleName = importPath.slice("@terreno/ui/".length);
|
|
108
|
+
const srcCandidate = join(SRC_ROOT, `${moduleName}.tsx`);
|
|
109
|
+
if (existsSync(srcCandidate)) {
|
|
110
|
+
return srcCandidate;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const tsCandidate = join(SRC_ROOT, `${moduleName}.ts`);
|
|
114
|
+
if (existsSync(tsCandidate)) {
|
|
115
|
+
return tsCandidate;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const distCandidate = join(DIST_ROOT, `${moduleName}.js`);
|
|
119
|
+
if (existsSync(distCandidate)) {
|
|
120
|
+
return distCandidate;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw new Error(`Unsupported import path for graph measurement: ${importPath}`);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const diffImportGraphs = ({
|
|
128
|
+
baselinePaths,
|
|
129
|
+
comparisonPaths,
|
|
130
|
+
}: {
|
|
131
|
+
baselinePaths: string[];
|
|
132
|
+
comparisonPaths: string[];
|
|
133
|
+
}): string[] => {
|
|
134
|
+
const comparisonSet = new Set(comparisonPaths);
|
|
135
|
+
return baselinePaths.filter((modulePath) => !comparisonSet.has(modulePath));
|
|
136
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {existsSync, readdirSync} from "node:fs";
|
|
3
|
+
import {resolve} from "node:path";
|
|
4
|
+
|
|
5
|
+
import {compareBenchmarkSamples, measureFreshImportTiming} from "./importTiming";
|
|
6
|
+
|
|
7
|
+
const UI_PACKAGE_ROOT = resolve(import.meta.dir, "../..");
|
|
8
|
+
const leftoverProbePath = resolve(UI_PACKAGE_ROOT, "src/benchmarks/.fresh-import-probe.ts");
|
|
9
|
+
|
|
10
|
+
describe("importTiming", () => {
|
|
11
|
+
it("sorts benchmark samples for median timing", () => {
|
|
12
|
+
expect(compareBenchmarkSamples(2, 1)).toBe(1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("throws when the fresh import probe fails", () => {
|
|
16
|
+
expect(() =>
|
|
17
|
+
measureFreshImportTiming({
|
|
18
|
+
importPath: "../__definitely-missing-module__",
|
|
19
|
+
sampleCount: 1,
|
|
20
|
+
warmupCount: 0,
|
|
21
|
+
})
|
|
22
|
+
).toThrow(/Fresh import probe failed/);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("measures fresh-process import timing for a small subpath", () => {
|
|
26
|
+
const timing = measureFreshImportTiming({
|
|
27
|
+
importPath: "../Button",
|
|
28
|
+
sampleCount: 1,
|
|
29
|
+
warmupCount: 1,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(timing.importPath).toBe("../Button");
|
|
33
|
+
expect(timing.samplesMs).toHaveLength(1);
|
|
34
|
+
expect(timing.elapsedMs).toBeGreaterThan(0);
|
|
35
|
+
expect(existsSync(leftoverProbePath)).toBe(false);
|
|
36
|
+
expect(
|
|
37
|
+
readdirSync(resolve(UI_PACKAGE_ROOT, "src/benchmarks")).some((name) =>
|
|
38
|
+
name.includes("fresh-import-probe")
|
|
39
|
+
)
|
|
40
|
+
).toBe(false);
|
|
41
|
+
}, 120_000);
|
|
42
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {spawnSync} from "node:child_process";
|
|
2
|
+
import {existsSync, unlinkSync, writeFileSync} from "node:fs";
|
|
3
|
+
import {resolve} from "node:path";
|
|
4
|
+
|
|
5
|
+
export interface FreshImportTimingResult {
|
|
6
|
+
elapsedMs: number;
|
|
7
|
+
importPath: string;
|
|
8
|
+
samplesMs: number[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const UI_PACKAGE_ROOT = resolve(import.meta.dir, "../..");
|
|
12
|
+
const PROBE_FILE = resolve(UI_PACKAGE_ROOT, "src/benchmarks/.fresh-import-probe.ts");
|
|
13
|
+
|
|
14
|
+
export const compareBenchmarkSamples = (left: number, right: number): number => left - right;
|
|
15
|
+
|
|
16
|
+
const runFreshImportSample = (importPath: string): number => {
|
|
17
|
+
const probeSource = `
|
|
18
|
+
import {describe, expect, it} from "bun:test";
|
|
19
|
+
|
|
20
|
+
describe("fresh import timing", () => {
|
|
21
|
+
it("imports target module", async () => {
|
|
22
|
+
const start = performance.now();
|
|
23
|
+
const moduleNamespace = await import(${JSON.stringify(importPath)});
|
|
24
|
+
const elapsedMs = performance.now() - start;
|
|
25
|
+
const exportCount = Object.keys(moduleNamespace).length;
|
|
26
|
+
console.info("UI_IMPORT_TIMING_RESULT=" + JSON.stringify({elapsedMs, exportCount}));
|
|
27
|
+
expect(exportCount).toBeGreaterThan(0);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
`;
|
|
31
|
+
const childEnv = {...process.env, TZ: "America/New_York"};
|
|
32
|
+
delete childEnv.BUN_OPTIONS;
|
|
33
|
+
writeFileSync(PROBE_FILE, probeSource, "utf8");
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const result = spawnSync(
|
|
37
|
+
"bun",
|
|
38
|
+
["test", "--preload", "./src/bunSetup.ts", "./src/benchmarks/.fresh-import-probe.ts"],
|
|
39
|
+
{
|
|
40
|
+
cwd: UI_PACKAGE_ROOT,
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
env: childEnv,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
|
|
47
|
+
const match = output.match(/UI_IMPORT_TIMING_RESULT=({.+})/);
|
|
48
|
+
if (!match) {
|
|
49
|
+
throw new Error(`Fresh import probe failed for ${importPath}\n${output.slice(0, 2000)}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const parsed = JSON.parse(match[1]) as {elapsedMs: number};
|
|
53
|
+
return parsed.elapsedMs;
|
|
54
|
+
} finally {
|
|
55
|
+
if (existsSync(PROBE_FILE)) {
|
|
56
|
+
unlinkSync(PROBE_FILE);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const measureFreshImportTiming = ({
|
|
62
|
+
importPath,
|
|
63
|
+
sampleCount = 5,
|
|
64
|
+
warmupCount = 1,
|
|
65
|
+
}: {
|
|
66
|
+
importPath: string;
|
|
67
|
+
sampleCount?: number;
|
|
68
|
+
warmupCount?: number;
|
|
69
|
+
}): FreshImportTimingResult => {
|
|
70
|
+
for (let index = 0; index < warmupCount; index += 1) {
|
|
71
|
+
runFreshImportSample(importPath);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const samplesMs: number[] = [];
|
|
75
|
+
for (let index = 0; index < sampleCount; index += 1) {
|
|
76
|
+
samplesMs.push(runFreshImportSample(importPath));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const sortedSamples = [...samplesMs].sort(compareBenchmarkSamples);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
elapsedMs: sortedSamples[Math.floor(sortedSamples.length / 2)] ?? 0,
|
|
83
|
+
importPath,
|
|
84
|
+
samplesMs,
|
|
85
|
+
};
|
|
86
|
+
};
|
package/src/bunSetup.ts
CHANGED
|
@@ -45,6 +45,178 @@ const rnGlobals = globalThis as typeof globalThis & {
|
|
|
45
45
|
rnGlobals.__DEV__ = true;
|
|
46
46
|
rnGlobals.__BUNDLE_START_TIME__ = Date.now();
|
|
47
47
|
|
|
48
|
+
type MockFlatListRenderItemInfo = {
|
|
49
|
+
item: unknown;
|
|
50
|
+
index: number;
|
|
51
|
+
separators: {highlight: () => void; unhighlight: () => void};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type MockFlatListProps = MockComponentProps & {
|
|
55
|
+
data?: unknown[];
|
|
56
|
+
renderItem?: (info: MockFlatListRenderItemInfo) => React.ReactNode;
|
|
57
|
+
keyExtractor?: (item: unknown, index: number) => string;
|
|
58
|
+
getItemLayout?: (
|
|
59
|
+
data: unknown[] | null | undefined,
|
|
60
|
+
index: number
|
|
61
|
+
) => {length: number; offset: number; index: number};
|
|
62
|
+
initialNumToRender?: number;
|
|
63
|
+
maxToRenderPerBatch?: number;
|
|
64
|
+
windowSize?: number;
|
|
65
|
+
onScroll?: (event: {nativeEvent: {contentOffset: {x: number; y: number}}}) => void;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const DEFAULT_FLAT_LIST_VIEWPORT_HEIGHT = 400;
|
|
69
|
+
|
|
70
|
+
const getMockFlatListRenderedRange = ({
|
|
71
|
+
dataLength,
|
|
72
|
+
itemHeight,
|
|
73
|
+
initialNumToRender,
|
|
74
|
+
scrollOffsetY,
|
|
75
|
+
viewportHeight,
|
|
76
|
+
windowSize,
|
|
77
|
+
}: {
|
|
78
|
+
dataLength: number;
|
|
79
|
+
itemHeight: number;
|
|
80
|
+
initialNumToRender: number;
|
|
81
|
+
scrollOffsetY: number;
|
|
82
|
+
viewportHeight: number;
|
|
83
|
+
windowSize: number;
|
|
84
|
+
}): {end: number; start: number} => {
|
|
85
|
+
if (dataLength === 0) {
|
|
86
|
+
return {end: 0, start: 0};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const visibleRowCount = Math.max(1, Math.ceil(viewportHeight / itemHeight));
|
|
90
|
+
const overscanRows = Math.max(1, Math.floor(windowSize * visibleRowCount));
|
|
91
|
+
|
|
92
|
+
if (scrollOffsetY <= 0) {
|
|
93
|
+
return {
|
|
94
|
+
end: Math.min(dataLength, initialNumToRender),
|
|
95
|
+
start: 0,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const firstVisibleRow = Math.floor(scrollOffsetY / itemHeight);
|
|
100
|
+
const start = Math.max(0, firstVisibleRow - overscanRows);
|
|
101
|
+
const end = Math.min(dataLength, firstVisibleRow + visibleRowCount + overscanRows);
|
|
102
|
+
return {end: Math.max(end, start), start};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const createMockFlatListScrollRef = (
|
|
106
|
+
onScroll?: MockFlatListProps["onScroll"],
|
|
107
|
+
setScrollOffsetY?: (offsetY: number) => void,
|
|
108
|
+
getItemLayout?: MockFlatListProps["getItemLayout"],
|
|
109
|
+
data?: unknown[]
|
|
110
|
+
) => {
|
|
111
|
+
const scrollTo = ({x = 0, y = 0}: {animated?: boolean; x?: number; y?: number}) => {
|
|
112
|
+
setScrollOffsetY?.(y);
|
|
113
|
+
onScroll?.({
|
|
114
|
+
nativeEvent: {
|
|
115
|
+
contentOffset: {x, y},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const scrollToOffset = ({offset, animated: _animated}: {offset: number; animated?: boolean}) => {
|
|
120
|
+
scrollTo({y: offset});
|
|
121
|
+
};
|
|
122
|
+
const scrollToIndex = ({index, animated: _animated}: {index: number; animated?: boolean}) => {
|
|
123
|
+
const layout = getItemLayout?.(data, index);
|
|
124
|
+
const itemHeight = layout?.length ?? 54;
|
|
125
|
+
scrollToOffset({offset: layout?.offset ?? index * itemHeight});
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
scrollTo,
|
|
129
|
+
scrollToIndex,
|
|
130
|
+
scrollToOffset,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const createSimpleFlatList = () => {
|
|
135
|
+
return React.forwardRef(function SimpleFlatList(props: MockFlatListProps, ref) {
|
|
136
|
+
const {data, renderItem, keyExtractor, onScroll, ...restProps} = props;
|
|
137
|
+
const scrollRef = createMockFlatListScrollRef(onScroll);
|
|
138
|
+
React.useImperativeHandle(ref, () => ({
|
|
139
|
+
...scrollRef,
|
|
140
|
+
_listRef: {_scrollRef: scrollRef},
|
|
141
|
+
_scrollRef: scrollRef,
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
const separators = {highlight: () => {}, unhighlight: () => {}};
|
|
145
|
+
return React.createElement(
|
|
146
|
+
"FlatList",
|
|
147
|
+
restProps,
|
|
148
|
+
data?.map((item: unknown, index: number) => {
|
|
149
|
+
const element = renderItem?.({index, item, separators});
|
|
150
|
+
const key = keyExtractor?.(item, index) ?? String(index);
|
|
151
|
+
return React.createElement(React.Fragment, {key}, element);
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const createVirtualizedFlatList = (): React.ForwardRefExoticComponent<
|
|
158
|
+
MockFlatListProps & React.RefAttributes<unknown>
|
|
159
|
+
> =>
|
|
160
|
+
React.forwardRef(function VirtualizedFlatList(props, ref) {
|
|
161
|
+
const {
|
|
162
|
+
data,
|
|
163
|
+
renderItem,
|
|
164
|
+
keyExtractor,
|
|
165
|
+
getItemLayout,
|
|
166
|
+
initialNumToRender = 10,
|
|
167
|
+
windowSize = 21,
|
|
168
|
+
onScroll,
|
|
169
|
+
...restProps
|
|
170
|
+
} = props;
|
|
171
|
+
const [scrollOffsetY, setScrollOffsetY] = React.useState(0);
|
|
172
|
+
const dataLength = data?.length ?? 0;
|
|
173
|
+
const itemHeight = getItemLayout?.(data, 0)?.length ?? 54;
|
|
174
|
+
const shouldVirtualize = Boolean(getItemLayout && dataLength > 100);
|
|
175
|
+
const {end, start} = shouldVirtualize
|
|
176
|
+
? getMockFlatListRenderedRange({
|
|
177
|
+
dataLength,
|
|
178
|
+
initialNumToRender,
|
|
179
|
+
itemHeight,
|
|
180
|
+
scrollOffsetY,
|
|
181
|
+
viewportHeight: DEFAULT_FLAT_LIST_VIEWPORT_HEIGHT,
|
|
182
|
+
windowSize,
|
|
183
|
+
})
|
|
184
|
+
: {end: dataLength, start: 0};
|
|
185
|
+
|
|
186
|
+
const scrollRef = createMockFlatListScrollRef(onScroll, setScrollOffsetY, getItemLayout, data);
|
|
187
|
+
|
|
188
|
+
React.useImperativeHandle(ref, () => ({
|
|
189
|
+
...scrollRef,
|
|
190
|
+
_listRef: {_scrollRef: scrollRef},
|
|
191
|
+
_scrollRef: scrollRef,
|
|
192
|
+
}));
|
|
193
|
+
|
|
194
|
+
const separators = {highlight: () => {}, unhighlight: () => {}};
|
|
195
|
+
const children = data?.slice(start, end).map((item: unknown, relativeIndex: number) => {
|
|
196
|
+
const index = start + relativeIndex;
|
|
197
|
+
const element = renderItem?.({index, item, separators});
|
|
198
|
+
const key = keyExtractor?.(item, index) ?? String(index);
|
|
199
|
+
return React.createElement(React.Fragment, {key}, element);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return React.createElement("FlatList", restProps, children);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const VirtualizedFlatList = createVirtualizedFlatList();
|
|
206
|
+
const SimpleFlatList = createSimpleFlatList();
|
|
207
|
+
|
|
208
|
+
const shouldUseVirtualizedFlatList = (props: MockFlatListProps): boolean => {
|
|
209
|
+
const dataLength = props.data?.length ?? 0;
|
|
210
|
+
return Boolean(props.getItemLayout && dataLength > 100);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const FlatListRouter = React.forwardRef(function FlatListRouter(props, ref) {
|
|
214
|
+
if (shouldUseVirtualizedFlatList(props)) {
|
|
215
|
+
return React.createElement(VirtualizedFlatList, {...props, ref});
|
|
216
|
+
}
|
|
217
|
+
return React.createElement(SimpleFlatList, {...props, ref});
|
|
218
|
+
});
|
|
219
|
+
|
|
48
220
|
// Mock react-native to avoid Flow type errors
|
|
49
221
|
mock.module("react-native", () => {
|
|
50
222
|
const View = ({children, style, testID, ...props}: MockComponentProps) =>
|
|
@@ -63,23 +235,7 @@ mock.module("react-native", () => {
|
|
|
63
235
|
React.createElement("ImageBackground", props, children);
|
|
64
236
|
const ActivityIndicator = (props: MockComponentProps) =>
|
|
65
237
|
React.createElement("ActivityIndicator", props);
|
|
66
|
-
const FlatList =
|
|
67
|
-
data,
|
|
68
|
-
renderItem,
|
|
69
|
-
keyExtractor,
|
|
70
|
-
...props
|
|
71
|
-
}: MockComponentProps & {
|
|
72
|
-
data?: unknown[];
|
|
73
|
-
renderItem?: (info: {item: unknown; index: number; separators: unknown}) => React.ReactNode;
|
|
74
|
-
keyExtractor?: (item: unknown, index: number) => string;
|
|
75
|
-
}) =>
|
|
76
|
-
React.createElement(
|
|
77
|
-
"FlatList",
|
|
78
|
-
props,
|
|
79
|
-
data?.map((item: unknown, index: number) =>
|
|
80
|
-
renderItem?.({index, item, separators: {highlight: () => {}, unhighlight: () => {}}})
|
|
81
|
-
)
|
|
82
|
-
);
|
|
238
|
+
const FlatList = FlatListRouter;
|
|
83
239
|
const SectionList = (props: MockComponentProps) => React.createElement("SectionList", props);
|
|
84
240
|
const KeyboardAvoidingView = ({children, ...props}: MockComponentProps) =>
|
|
85
241
|
React.createElement("KeyboardAvoidingView", props, children);
|
|
@@ -1054,21 +1210,7 @@ mock.module("react-native/Libraries/Components/Switch/Switch", () => ({
|
|
|
1054
1210
|
}));
|
|
1055
1211
|
|
|
1056
1212
|
mock.module("react-native/Libraries/Lists/FlatList", () => ({
|
|
1057
|
-
default:
|
|
1058
|
-
data,
|
|
1059
|
-
renderItem,
|
|
1060
|
-
...props
|
|
1061
|
-
}: MockComponentProps & {
|
|
1062
|
-
data?: unknown[];
|
|
1063
|
-
renderItem?: (info: {item: unknown; index: number; separators: unknown}) => React.ReactNode;
|
|
1064
|
-
}) =>
|
|
1065
|
-
React.createElement(
|
|
1066
|
-
"FlatList",
|
|
1067
|
-
props,
|
|
1068
|
-
data?.map((item: unknown, index: number) =>
|
|
1069
|
-
renderItem?.({index, item, separators: {highlight: () => {}, unhighlight: () => {}}})
|
|
1070
|
-
)
|
|
1071
|
-
),
|
|
1213
|
+
default: FlatListRouter,
|
|
1072
1214
|
}));
|
|
1073
1215
|
|
|
1074
1216
|
mock.module("react-native/Libraries/Lists/SectionList", () => ({
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {FC, ReactNode} from "react";
|
|
2
|
+
|
|
3
|
+
import {Box} from "../Box";
|
|
4
|
+
import {Spinner} from "../Spinner";
|
|
5
|
+
import {Text} from "../Text";
|
|
6
|
+
import {resolveTestID, toTestProps} from "../testing/resolveTestId";
|
|
7
|
+
import {CHART_FOOTER_ROW_HEIGHT} from "./layout";
|
|
8
|
+
|
|
9
|
+
export interface ChartFrameProps {
|
|
10
|
+
accessibilityLabel?: string;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
emptyText: string;
|
|
13
|
+
isEmpty: boolean;
|
|
14
|
+
legendLabel?: string;
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
testID?: string;
|
|
17
|
+
tooltipText?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ChartFrame: FC<ChartFrameProps> = ({
|
|
21
|
+
accessibilityLabel,
|
|
22
|
+
children,
|
|
23
|
+
emptyText,
|
|
24
|
+
isEmpty,
|
|
25
|
+
legendLabel,
|
|
26
|
+
loading = false,
|
|
27
|
+
testID,
|
|
28
|
+
tooltipText,
|
|
29
|
+
}) => {
|
|
30
|
+
const showPlot = !loading && !isEmpty;
|
|
31
|
+
|
|
32
|
+
// alignSelf stretch keeps the frame full width even when a parent centers its children, so the
|
|
33
|
+
// measured plot width comes from the container instead of the chart's own content.
|
|
34
|
+
return (
|
|
35
|
+
<Box
|
|
36
|
+
accessibilityLabel={accessibilityLabel}
|
|
37
|
+
alignSelf="stretch"
|
|
38
|
+
minWidth={0}
|
|
39
|
+
width="100%"
|
|
40
|
+
{...toTestProps(testID)}
|
|
41
|
+
>
|
|
42
|
+
{loading ? (
|
|
43
|
+
<Box padding={4}>
|
|
44
|
+
<Spinner testID={resolveTestID(testID, "spinner")} />
|
|
45
|
+
</Box>
|
|
46
|
+
) : null}
|
|
47
|
+
{isEmpty && !loading ? <Text skipLinking>{emptyText}</Text> : null}
|
|
48
|
+
{showPlot ? children : null}
|
|
49
|
+
{showPlot ? (
|
|
50
|
+
<Box height={CHART_FOOTER_ROW_HEIGHT} minWidth={0} overflow="hidden">
|
|
51
|
+
{tooltipText ? (
|
|
52
|
+
<Text size="sm" skipLinking testID={resolveTestID(testID, "tooltip")} truncate>
|
|
53
|
+
{tooltipText}
|
|
54
|
+
</Text>
|
|
55
|
+
) : null}
|
|
56
|
+
</Box>
|
|
57
|
+
) : null}
|
|
58
|
+
{showPlot && legendLabel ? (
|
|
59
|
+
<Box height={CHART_FOOTER_ROW_HEIGHT} minWidth={0} overflow="hidden">
|
|
60
|
+
<Text size="sm" skipLinking testID={resolveTestID(testID, "legend")} truncate>
|
|
61
|
+
{legendLabel}
|
|
62
|
+
</Text>
|
|
63
|
+
</Box>
|
|
64
|
+
) : null}
|
|
65
|
+
</Box>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {getBarLayout, MARK_HIT_SIZE} from "./bars";
|
|
4
|
+
|
|
5
|
+
const yIdentity = (value: number): number => {
|
|
6
|
+
return 100 - value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
describe("getBarLayout", () => {
|
|
10
|
+
it("draws a positive bar from the value down to the zero baseline", () => {
|
|
11
|
+
const layout = getBarLayout({
|
|
12
|
+
barWidth: 20,
|
|
13
|
+
baselineY: 100,
|
|
14
|
+
value: 40,
|
|
15
|
+
xCenter: 50,
|
|
16
|
+
y: yIdentity,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(layout.x).toBe(40);
|
|
20
|
+
expect(layout.y).toBe(60);
|
|
21
|
+
expect(layout.width).toBe(20);
|
|
22
|
+
expect(layout.height).toBe(40);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("draws a negative bar from the zero baseline down to the value", () => {
|
|
26
|
+
const layout = getBarLayout({
|
|
27
|
+
barWidth: 20,
|
|
28
|
+
baselineY: 40,
|
|
29
|
+
value: -20,
|
|
30
|
+
xCenter: 50,
|
|
31
|
+
y: yIdentity,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(layout.x).toBe(40);
|
|
35
|
+
expect(layout.y).toBe(40);
|
|
36
|
+
expect(layout.width).toBe(20);
|
|
37
|
+
expect(layout.height).toBe(80);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("omits a zero-value bar and keeps a pressable hit target on the baseline", () => {
|
|
41
|
+
const layout = getBarLayout({
|
|
42
|
+
barWidth: 8,
|
|
43
|
+
baselineY: 100,
|
|
44
|
+
value: 0,
|
|
45
|
+
xCenter: 50,
|
|
46
|
+
y: yIdentity,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(layout.height).toBe(0);
|
|
50
|
+
expect(layout.y).toBe(100);
|
|
51
|
+
expect(layout.hitWidth).toBe(MARK_HIT_SIZE);
|
|
52
|
+
expect(layout.hitHeight).toBe(MARK_HIT_SIZE);
|
|
53
|
+
expect(layout.hitX).toBe(50 - MARK_HIT_SIZE / 2);
|
|
54
|
+
expect(layout.hitY).toBe(100 - MARK_HIT_SIZE / 2);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const MARK_HIT_SIZE = 24;
|
|
2
|
+
|
|
3
|
+
export interface BarLayout {
|
|
4
|
+
height: number;
|
|
5
|
+
hitHeight: number;
|
|
6
|
+
hitWidth: number;
|
|
7
|
+
hitX: number;
|
|
8
|
+
hitY: number;
|
|
9
|
+
width: number;
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const getBarLayout = ({
|
|
15
|
+
barWidth,
|
|
16
|
+
baselineY,
|
|
17
|
+
value,
|
|
18
|
+
xCenter,
|
|
19
|
+
y,
|
|
20
|
+
}: {
|
|
21
|
+
barWidth: number;
|
|
22
|
+
baselineY: number;
|
|
23
|
+
value: number;
|
|
24
|
+
xCenter: number;
|
|
25
|
+
y: (value: number) => number;
|
|
26
|
+
}): BarLayout => {
|
|
27
|
+
const valueY = y(value);
|
|
28
|
+
const x = xCenter - barWidth / 2;
|
|
29
|
+
let rectY = baselineY;
|
|
30
|
+
let rectHeight = 0;
|
|
31
|
+
if (value > 0) {
|
|
32
|
+
rectY = valueY;
|
|
33
|
+
rectHeight = Math.max(baselineY - valueY, 0);
|
|
34
|
+
} else if (value < 0) {
|
|
35
|
+
rectY = baselineY;
|
|
36
|
+
rectHeight = Math.max(valueY - baselineY, 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const hitWidth = Math.max(barWidth, MARK_HIT_SIZE);
|
|
40
|
+
const hitHeight = Math.max(rectHeight, MARK_HIT_SIZE);
|
|
41
|
+
const barMidY = rectHeight === 0 ? baselineY : rectY + rectHeight / 2;
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
height: rectHeight,
|
|
45
|
+
hitHeight,
|
|
46
|
+
hitWidth,
|
|
47
|
+
hitX: xCenter - hitWidth / 2,
|
|
48
|
+
hitY: barMidY - hitHeight / 2,
|
|
49
|
+
width: barWidth,
|
|
50
|
+
x,
|
|
51
|
+
y: rectY,
|
|
52
|
+
};
|
|
53
|
+
};
|