@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,201 @@
|
|
|
1
|
+
import {DateTime} from "luxon";
|
|
2
|
+
|
|
3
|
+
import type {DataTableColumn, DataTableColumnFilter, DataTableQueryParams} from "./Common";
|
|
4
|
+
|
|
5
|
+
/** Debounce delay for DataTable toolbar search before emitting query params. */
|
|
6
|
+
export const DATA_TABLE_SEARCH_DEBOUNCE_MS = 250;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wire-format sentinel for optional choice filters meaning "field is null or unset".
|
|
10
|
+
* Must match `ADMIN_LIST_CHOICE_EMPTY_VALUE` in `@terreno/api`.
|
|
11
|
+
*/
|
|
12
|
+
export const DATA_TABLE_CHOICE_EMPTY_VALUE = "__empty__";
|
|
13
|
+
|
|
14
|
+
export const DATA_TABLE_CHOICE_EMPTY_LABEL = "Empty";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Date range bounds are collected as calendar days, so the range covers whole UTC days:
|
|
18
|
+
* the lower bound opens the chosen day and the upper bound closes it. Without this the
|
|
19
|
+
* upper bound would land on midnight and exclude everything recorded later that day.
|
|
20
|
+
*/
|
|
21
|
+
export const startOfUtcDay = (isoValue: string): string => {
|
|
22
|
+
const parsed = DateTime.fromISO(isoValue, {zone: "utc"});
|
|
23
|
+
if (!parsed.isValid) {
|
|
24
|
+
return isoValue;
|
|
25
|
+
}
|
|
26
|
+
return parsed.startOf("day").toISO({suppressMilliseconds: false}) ?? isoValue;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const endOfUtcDay = (isoValue: string): string => {
|
|
30
|
+
const parsed = DateTime.fromISO(isoValue, {zone: "utc"});
|
|
31
|
+
if (!parsed.isValid) {
|
|
32
|
+
return isoValue;
|
|
33
|
+
}
|
|
34
|
+
return parsed.endOf("day").toISO({suppressMilliseconds: false}) ?? isoValue;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Escape user input for case-insensitive MongoDB $regex literals. */
|
|
38
|
+
export const escapeRegexLiteral = (value: string): string => {
|
|
39
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface BuildDataTableListQueryInput {
|
|
43
|
+
columns: DataTableColumn[];
|
|
44
|
+
filters?: DataTableColumnFilter[];
|
|
45
|
+
filterValues?: Record<string, unknown>;
|
|
46
|
+
search?: string;
|
|
47
|
+
searchFields?: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const isNonEmptyString = (value: unknown): string | undefined => {
|
|
51
|
+
if (typeof value !== "string") {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const trimmed = value.trim();
|
|
55
|
+
return trimmed === "" ? undefined : trimmed;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const parseNumberRange = (value: unknown): {$gte?: number; $lte?: number} | undefined => {
|
|
59
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const record = value as {$gte?: unknown; $lte?: unknown; gte?: unknown; lte?: unknown};
|
|
63
|
+
const range: {$gte?: number; $lte?: number} = {};
|
|
64
|
+
const gte = record.$gte ?? record.gte;
|
|
65
|
+
const lte = record.$lte ?? record.lte;
|
|
66
|
+
if (typeof gte === "number" && !Number.isNaN(gte)) {
|
|
67
|
+
range.$gte = gte;
|
|
68
|
+
}
|
|
69
|
+
if (typeof lte === "number" && !Number.isNaN(lte)) {
|
|
70
|
+
range.$lte = lte;
|
|
71
|
+
}
|
|
72
|
+
return Object.keys(range).length > 0 ? range : undefined;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const parseChoiceValues = (value: unknown): string[] => {
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
return value.map((entry) => String(entry)).filter((entry) => entry !== "");
|
|
78
|
+
}
|
|
79
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
80
|
+
return [value.trim()];
|
|
81
|
+
}
|
|
82
|
+
return [];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const splitChoiceValues = (
|
|
86
|
+
values: string[],
|
|
87
|
+
allowEmpty: boolean
|
|
88
|
+
): {concrete: string[]; includeEmpty: boolean} => {
|
|
89
|
+
const includeEmpty = allowEmpty && values.includes(DATA_TABLE_CHOICE_EMPTY_VALUE);
|
|
90
|
+
const concrete = values.filter(
|
|
91
|
+
(entry) => entry !== DATA_TABLE_CHOICE_EMPTY_VALUE && entry !== ""
|
|
92
|
+
);
|
|
93
|
+
return {concrete, includeEmpty};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Builds a modelRouter-compatible choice filter value.
|
|
98
|
+
*
|
|
99
|
+
* Contract:
|
|
100
|
+
* - concrete only, one value → scalar equality
|
|
101
|
+
* - concrete only, many values → `{ $in: concrete[] }`
|
|
102
|
+
* - empty only → `{ $in: [DATA_TABLE_CHOICE_EMPTY_VALUE] }` (parsed server-side to null)
|
|
103
|
+
* - empty + concrete → `{ $in: [...concrete, DATA_TABLE_CHOICE_EMPTY_VALUE] }`
|
|
104
|
+
*/
|
|
105
|
+
export const buildChoiceFilterQueryValue = (
|
|
106
|
+
values: string[],
|
|
107
|
+
allowEmpty = false
|
|
108
|
+
): string | {$in: string[]} | undefined => {
|
|
109
|
+
const {concrete, includeEmpty} = splitChoiceValues(values, allowEmpty);
|
|
110
|
+
if (!includeEmpty && concrete.length === 0) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
if (includeEmpty && concrete.length === 0) {
|
|
114
|
+
return {$in: [DATA_TABLE_CHOICE_EMPTY_VALUE]};
|
|
115
|
+
}
|
|
116
|
+
if (!includeEmpty && concrete.length === 1) {
|
|
117
|
+
return concrete[0];
|
|
118
|
+
}
|
|
119
|
+
if (!includeEmpty) {
|
|
120
|
+
return {$in: concrete};
|
|
121
|
+
}
|
|
122
|
+
return {$in: [...concrete, DATA_TABLE_CHOICE_EMPTY_VALUE]};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Builds modelRouter-compatible list query params from DataTable search and filter state.
|
|
127
|
+
* Omits empty values. Does not include page, limit, or sort.
|
|
128
|
+
*/
|
|
129
|
+
export const buildDataTableListQuery = ({
|
|
130
|
+
columns,
|
|
131
|
+
filters = [],
|
|
132
|
+
filterValues = {},
|
|
133
|
+
search = "",
|
|
134
|
+
searchFields = [],
|
|
135
|
+
}: BuildDataTableListQueryInput): DataTableQueryParams => {
|
|
136
|
+
const params: DataTableQueryParams = {};
|
|
137
|
+
|
|
138
|
+
const declaredFilters = [
|
|
139
|
+
...columns
|
|
140
|
+
.map((column) => column.filter)
|
|
141
|
+
.filter((filter): filter is DataTableColumnFilter => Boolean(filter)),
|
|
142
|
+
...filters,
|
|
143
|
+
];
|
|
144
|
+
for (const filter of declaredFilters) {
|
|
145
|
+
const field = filter.field;
|
|
146
|
+
|
|
147
|
+
if (filter.kind === "text") {
|
|
148
|
+
const text = isNonEmptyString(filterValues[field]);
|
|
149
|
+
if (text) {
|
|
150
|
+
params[field] = {$options: "i", $regex: escapeRegexLiteral(text)};
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (filter.kind === "boolean") {
|
|
156
|
+
const value = filterValues[field];
|
|
157
|
+
if (value === true || value === false) {
|
|
158
|
+
params[field] = value;
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (filter.kind === "dateRange") {
|
|
164
|
+
const gte = isNonEmptyString(filterValues[`${field}_gte`]);
|
|
165
|
+
const lte = isNonEmptyString(filterValues[`${field}_lte`]);
|
|
166
|
+
if (gte) {
|
|
167
|
+
params[`${field}_gte`] = gte;
|
|
168
|
+
}
|
|
169
|
+
if (lte) {
|
|
170
|
+
params[`${field}_lte`] = lte;
|
|
171
|
+
}
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (filter.kind === "numberRange") {
|
|
176
|
+
const range = parseNumberRange(filterValues[field]);
|
|
177
|
+
if (range) {
|
|
178
|
+
params[field] = range;
|
|
179
|
+
}
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (filter.kind === "choice") {
|
|
184
|
+
const values = parseChoiceValues(filterValues[field]);
|
|
185
|
+
const queryValue = buildChoiceFilterQueryValue(values, filter.allowEmpty === true);
|
|
186
|
+
if (queryValue !== undefined) {
|
|
187
|
+
params[field] = queryValue;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const trimmedSearch = search.trim();
|
|
193
|
+
if (trimmedSearch && searchFields.length > 0) {
|
|
194
|
+
const escaped = escapeRegexLiteral(trimmedSearch);
|
|
195
|
+
params.$or = searchFields.map((field) => ({
|
|
196
|
+
[field]: {$options: "i", $regex: escaped},
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return params;
|
|
201
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {Categories} from "./emojiCategories";
|
|
4
|
+
|
|
5
|
+
describe("emojiCategories", () => {
|
|
6
|
+
it("exports the All category as a stable object", () => {
|
|
7
|
+
expect(Categories.all).toEqual({name: "All", symbol: null});
|
|
8
|
+
expect(Categories.people.symbol).toBe("🧑");
|
|
9
|
+
expect(Object.keys(Categories).sort()).toEqual([
|
|
10
|
+
"activities",
|
|
11
|
+
"all",
|
|
12
|
+
"emotion",
|
|
13
|
+
"flags",
|
|
14
|
+
"food",
|
|
15
|
+
"history",
|
|
16
|
+
"nature",
|
|
17
|
+
"objects",
|
|
18
|
+
"people",
|
|
19
|
+
"places",
|
|
20
|
+
"symbols",
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export const Categories = {
|
|
2
|
+
activities: {
|
|
3
|
+
name: "Activities",
|
|
4
|
+
symbol: "⚾️",
|
|
5
|
+
},
|
|
6
|
+
all: {
|
|
7
|
+
name: "All",
|
|
8
|
+
symbol: null,
|
|
9
|
+
},
|
|
10
|
+
emotion: {
|
|
11
|
+
name: "Smileys & Emotion",
|
|
12
|
+
symbol: "😀",
|
|
13
|
+
},
|
|
14
|
+
flags: {
|
|
15
|
+
name: "Flags",
|
|
16
|
+
symbol: "🏳️🌈",
|
|
17
|
+
},
|
|
18
|
+
food: {
|
|
19
|
+
name: "Food & Drink",
|
|
20
|
+
symbol: "🍔",
|
|
21
|
+
},
|
|
22
|
+
history: {
|
|
23
|
+
name: "Recently used",
|
|
24
|
+
symbol: "🕘",
|
|
25
|
+
},
|
|
26
|
+
nature: {
|
|
27
|
+
name: "Animals & Nature",
|
|
28
|
+
symbol: "🦄",
|
|
29
|
+
},
|
|
30
|
+
objects: {
|
|
31
|
+
name: "Objects",
|
|
32
|
+
symbol: "💡",
|
|
33
|
+
},
|
|
34
|
+
people: {
|
|
35
|
+
name: "People & Body",
|
|
36
|
+
symbol: "🧑",
|
|
37
|
+
},
|
|
38
|
+
places: {
|
|
39
|
+
name: "Travel & Places",
|
|
40
|
+
symbol: "✈️",
|
|
41
|
+
},
|
|
42
|
+
symbols: {
|
|
43
|
+
name: "Symbols",
|
|
44
|
+
symbol: "🔣",
|
|
45
|
+
},
|
|
46
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -3,12 +3,20 @@ export type {StyleProp, ViewStyle} from "react-native";
|
|
|
3
3
|
export * from "./Accordion";
|
|
4
4
|
export * from "./ActionSheet";
|
|
5
5
|
export * from "./AddressField";
|
|
6
|
-
export * from "./AIRequestExplorer";
|
|
7
|
-
export * from "./AiSuggestionBox";
|
|
8
|
-
export * from "./
|
|
6
|
+
export type * from "./AIRequestExplorer";
|
|
7
|
+
export type * from "./AiSuggestionBox";
|
|
8
|
+
export type * from "./AnnouncementBanner";
|
|
9
|
+
export * from "./AnnouncementBanner";
|
|
10
|
+
export type * from "./AnnouncementNavigator";
|
|
11
|
+
export * from "./AnnouncementNavigator";
|
|
12
|
+
export type * from "./AnnouncementScreen";
|
|
13
|
+
export * from "./AnnouncementScreen";
|
|
14
|
+
export type * from "./AreaChart";
|
|
15
|
+
export type * from "./AttachmentPreview";
|
|
9
16
|
export * from "./Avatar";
|
|
10
17
|
export * from "./Badge";
|
|
11
18
|
export {Banner, hideBanner} from "./Banner";
|
|
19
|
+
export type * from "./BarChart";
|
|
12
20
|
export * from "./Body";
|
|
13
21
|
export * from "./BooleanField";
|
|
14
22
|
export * from "./Box";
|
|
@@ -16,22 +24,23 @@ export * from "./Button";
|
|
|
16
24
|
export * from "./Card";
|
|
17
25
|
export * from "./CheckBox";
|
|
18
26
|
export * from "./Common";
|
|
19
|
-
export * from "./ConflictSheet";
|
|
20
|
-
export * from "./ConsentFormScreen";
|
|
21
|
-
export * from "./ConsentNavigator";
|
|
27
|
+
export type * from "./ConflictSheet";
|
|
28
|
+
export type * from "./ConsentFormScreen";
|
|
29
|
+
export type * from "./ConsentNavigator";
|
|
22
30
|
export * from "./Constants";
|
|
23
31
|
export * from "./CustomSelectField";
|
|
24
32
|
export * from "./conflictFieldDiff";
|
|
33
|
+
export * from "./DashboardGrid";
|
|
25
34
|
export * from "./DataTable";
|
|
26
35
|
export * from "./DateTimeActionSheet";
|
|
27
36
|
export * from "./DateTimeField";
|
|
28
37
|
export * from "./DateUtilities";
|
|
29
38
|
export * from "./DecimalRangeActionSheet";
|
|
30
39
|
export * from "./DismissButton";
|
|
31
|
-
export
|
|
40
|
+
export type * from "./DonutChart";
|
|
41
|
+
export * from "./dataTableListQuery";
|
|
32
42
|
export * from "./EditableCard";
|
|
33
43
|
export * from "./EmailField";
|
|
34
|
-
export {default as EmojiSelector} from "./EmojiSelector";
|
|
35
44
|
export * from "./ErrorBoundary";
|
|
36
45
|
export * from "./ErrorPage";
|
|
37
46
|
export * from "./Field";
|
|
@@ -42,8 +51,8 @@ export * from "./FilterBoolean";
|
|
|
42
51
|
export * from "./FilterChangesBadge";
|
|
43
52
|
export * from "./FilterSelectMenu";
|
|
44
53
|
export * from "./FlatList";
|
|
45
|
-
export * from "./GPTChat";
|
|
46
|
-
export * from "./GPTMemoryModal";
|
|
54
|
+
export type * from "./GPTChat";
|
|
55
|
+
export type * from "./GPTMemoryModal";
|
|
47
56
|
export * from "./Heading";
|
|
48
57
|
export * from "./HeightActionSheet";
|
|
49
58
|
export * from "./HeightField";
|
|
@@ -55,17 +64,40 @@ export * from "./ImageBackground";
|
|
|
55
64
|
export * from "./InfoModalIcon";
|
|
56
65
|
export * from "./InfoTooltipButton";
|
|
57
66
|
export * from "./icons/BarsFilterIcon";
|
|
67
|
+
export type * from "./LineChart";
|
|
58
68
|
export * from "./Link";
|
|
69
|
+
export {
|
|
70
|
+
AIRequestExplorer,
|
|
71
|
+
AiSuggestionBox,
|
|
72
|
+
AreaChart,
|
|
73
|
+
AttachmentPreview,
|
|
74
|
+
BarChart,
|
|
75
|
+
ConflictSheet,
|
|
76
|
+
ConsentFormScreen,
|
|
77
|
+
ConsentNavigator,
|
|
78
|
+
DonutChart,
|
|
79
|
+
DraggableList,
|
|
80
|
+
EmojiSelector,
|
|
81
|
+
GPTChat,
|
|
82
|
+
GPTMemoryModal,
|
|
83
|
+
LineChart,
|
|
84
|
+
MarkdownEditor,
|
|
85
|
+
MarkdownEditorField,
|
|
86
|
+
UpgradeRequiredScreen,
|
|
87
|
+
} from "./lazyBoundaries/heavyOptionalExports";
|
|
59
88
|
export * from "./login/LoginScreen";
|
|
60
89
|
export type {LoginFieldConfig, LoginScreenProps} from "./login/loginTypes";
|
|
61
|
-
export * from "./MarkdownEditor";
|
|
62
|
-
export * from "./MarkdownEditorField";
|
|
90
|
+
export type * from "./MarkdownEditor";
|
|
91
|
+
export type * from "./MarkdownEditorField";
|
|
63
92
|
export * from "./MarkdownView";
|
|
64
93
|
export * from "./MediaQuery";
|
|
65
94
|
export * from "./MobileAddressAutoComplete";
|
|
66
95
|
export * from "./Modal";
|
|
67
96
|
export * from "./ModalSheet";
|
|
68
97
|
export * from "./MultiselectField";
|
|
98
|
+
export * from "./NotificationBell";
|
|
99
|
+
export * from "./NotificationInbox";
|
|
100
|
+
export * from "./NotificationPreferences";
|
|
69
101
|
export * from "./NumberField";
|
|
70
102
|
export * from "./NumberPickerActionSheet";
|
|
71
103
|
export * from "./OfflineBanner";
|
|
@@ -74,6 +106,7 @@ export * from "./Page";
|
|
|
74
106
|
export * from "./Pagination";
|
|
75
107
|
export * from "./PasswordField";
|
|
76
108
|
export * from "./PhoneNumberField";
|
|
109
|
+
export * from "./Popover";
|
|
77
110
|
export * from "./PortalHost";
|
|
78
111
|
export * from "./pdfHtmlTemplate";
|
|
79
112
|
export * from "./Radio";
|
|
@@ -134,9 +167,11 @@ export * from "./table/TableTitle";
|
|
|
134
167
|
export * from "./table/tableContext";
|
|
135
168
|
export * from "./UnifiedAddressAutoComplete";
|
|
136
169
|
export * from "./Unifier";
|
|
137
|
-
export * from "./UpgradeRequiredScreen";
|
|
170
|
+
export type * from "./UpgradeRequiredScreen";
|
|
138
171
|
export * from "./UserInactivity";
|
|
139
172
|
export * from "./Utilities";
|
|
173
|
+
export * from "./useAcknowledgeAnnouncement";
|
|
174
|
+
export * from "./useAnnouncements";
|
|
140
175
|
export * from "./useAppLaunchOrForeground";
|
|
141
176
|
export * from "./useConsentForms";
|
|
142
177
|
export * from "./useStoredState";
|
|
@@ -145,7 +180,6 @@ export * from "./WebAddressAutocomplete";
|
|
|
145
180
|
|
|
146
181
|
// export * from "./Layout";
|
|
147
182
|
// export * from "./Drawer";
|
|
148
|
-
// export * from "./Chart";
|
|
149
183
|
|
|
150
184
|
// Lifted from react-native
|
|
151
185
|
type ImageRequireSource = number;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {describe, it, mock} from "bun:test";
|
|
2
|
+
import {render, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import type {ComponentType} from "react";
|
|
5
|
+
|
|
6
|
+
import {ErrorBoundary} from "../ErrorBoundary";
|
|
7
|
+
import {createLazyComponentExport, createLazyNamedExport} from "./createLazyComponentExport";
|
|
8
|
+
|
|
9
|
+
const TestLazyComponent = () => null;
|
|
10
|
+
|
|
11
|
+
const expectLazyRenderError = async ({
|
|
12
|
+
LazyExport,
|
|
13
|
+
message,
|
|
14
|
+
}: {
|
|
15
|
+
LazyExport: ComponentType<Record<string, unknown>>;
|
|
16
|
+
message: string;
|
|
17
|
+
}): Promise<void> => {
|
|
18
|
+
const onError = mock((_error: Error) => {});
|
|
19
|
+
const previousError = console.error;
|
|
20
|
+
const previousWarn = console.warn;
|
|
21
|
+
console.error = () => undefined;
|
|
22
|
+
console.warn = () => undefined;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const {unmount} = render(
|
|
26
|
+
<ErrorBoundary onError={onError}>
|
|
27
|
+
<LazyExport />
|
|
28
|
+
</ErrorBoundary>
|
|
29
|
+
);
|
|
30
|
+
await waitFor(() => {
|
|
31
|
+
assert.isNotEmpty(onError.mock.calls);
|
|
32
|
+
});
|
|
33
|
+
assert.strictEqual(onError.mock.calls[0]?.[0]?.message, message);
|
|
34
|
+
unmount();
|
|
35
|
+
} finally {
|
|
36
|
+
console.error = previousError;
|
|
37
|
+
console.warn = previousWarn;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe("createLazyComponentExport", () => {
|
|
42
|
+
it("defers module evaluation until render", async () => {
|
|
43
|
+
let loadCount = 0;
|
|
44
|
+
const LazyExport = createLazyComponentExport(async () => {
|
|
45
|
+
loadCount += 1;
|
|
46
|
+
return {default: TestLazyComponent};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
assert.strictEqual(loadCount, 0);
|
|
50
|
+
render(<LazyExport />);
|
|
51
|
+
await new Promise((resolve) => {
|
|
52
|
+
setTimeout(resolve, 0);
|
|
53
|
+
});
|
|
54
|
+
assert.strictEqual(loadCount, 1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("does not invoke factory when staticProperties are provided", () => {
|
|
58
|
+
let loadCount = 0;
|
|
59
|
+
const LazyExport = createLazyComponentExport(
|
|
60
|
+
async () => {
|
|
61
|
+
loadCount += 1;
|
|
62
|
+
return {default: TestLazyComponent};
|
|
63
|
+
},
|
|
64
|
+
{defaultProps: {placeholder: "Search..."}}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
assert.strictEqual(loadCount, 0);
|
|
68
|
+
assert.strictEqual(
|
|
69
|
+
(LazyExport as unknown as {defaultProps?: {placeholder?: string}}).defaultProps?.placeholder,
|
|
70
|
+
"Search..."
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("loads named exports through createLazyNamedExport", async () => {
|
|
75
|
+
let loadCount = 0;
|
|
76
|
+
const LazyExport = createLazyNamedExport(async () => {
|
|
77
|
+
loadCount += 1;
|
|
78
|
+
return {NamedWidget: TestLazyComponent};
|
|
79
|
+
}, "NamedWidget");
|
|
80
|
+
|
|
81
|
+
assert.strictEqual(loadCount, 0);
|
|
82
|
+
render(<LazyExport />);
|
|
83
|
+
await new Promise((resolve) => {
|
|
84
|
+
setTimeout(resolve, 0);
|
|
85
|
+
});
|
|
86
|
+
assert.strictEqual(loadCount, 1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("rejects factories without a default component", async () => {
|
|
90
|
+
const LazyExport = createLazyComponentExport(async () => ({notAComponent: true}));
|
|
91
|
+
await expectLazyRenderError({
|
|
92
|
+
LazyExport,
|
|
93
|
+
message: "Lazy component factory must resolve to { default: Component }",
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("rejects missing named exports", async () => {
|
|
98
|
+
const LazyExport = createLazyNamedExport(async () => ({Other: TestLazyComponent}), "Missing");
|
|
99
|
+
await expectLazyRenderError({
|
|
100
|
+
LazyExport,
|
|
101
|
+
message: 'Lazy export "Missing" was not found',
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, {type ComponentType, lazy, Suspense} from "react";
|
|
2
|
+
|
|
3
|
+
import {Spinner} from "../Spinner";
|
|
4
|
+
|
|
5
|
+
type LazyComponentProps = Record<string, unknown>;
|
|
6
|
+
type LazyComponent = ComponentType<LazyComponentProps>;
|
|
7
|
+
type LazyComponentModule = {default: LazyComponent};
|
|
8
|
+
|
|
9
|
+
const isLazyComponent = (value: unknown): value is LazyComponent => {
|
|
10
|
+
return typeof value === "function";
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const resolveLazyComponentModule = async (
|
|
14
|
+
factory: () => Promise<unknown>
|
|
15
|
+
): Promise<LazyComponentModule> => {
|
|
16
|
+
const moduleNamespace = await factory();
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
moduleNamespace &&
|
|
20
|
+
typeof moduleNamespace === "object" &&
|
|
21
|
+
"default" in moduleNamespace &&
|
|
22
|
+
isLazyComponent(moduleNamespace.default)
|
|
23
|
+
) {
|
|
24
|
+
return {default: moduleNamespace.default};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
throw new Error("Lazy component factory must resolve to { default: Component }");
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const createLazyComponentExport = (
|
|
31
|
+
factory: () => Promise<unknown>,
|
|
32
|
+
staticProperties?: Record<string, unknown>
|
|
33
|
+
): LazyComponent => {
|
|
34
|
+
const LazyComponent = lazy(() => resolveLazyComponentModule(factory));
|
|
35
|
+
|
|
36
|
+
const LazyExport: React.FC<LazyComponentProps> = (props) => (
|
|
37
|
+
<Suspense fallback={<Spinner />}>
|
|
38
|
+
<LazyComponent {...props} />
|
|
39
|
+
</Suspense>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (staticProperties) {
|
|
43
|
+
Object.assign(LazyExport, staticProperties);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return LazyExport;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const createLazyNamedExport = (
|
|
50
|
+
factory: () => Promise<unknown>,
|
|
51
|
+
exportName: string
|
|
52
|
+
): LazyComponent => {
|
|
53
|
+
return createLazyComponentExport(async () => {
|
|
54
|
+
const moduleNamespace = (await factory()) as Record<string, unknown>;
|
|
55
|
+
const component = moduleNamespace[exportName];
|
|
56
|
+
|
|
57
|
+
if (!isLazyComponent(component)) {
|
|
58
|
+
throw new Error(`Lazy export "${exportName}" was not found`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {default: component};
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {Categories} from "../emojiCategories";
|
|
4
|
+
import {
|
|
5
|
+
AIRequestExplorer,
|
|
6
|
+
DraggableList,
|
|
7
|
+
EmojiSelector,
|
|
8
|
+
heavyOptionalModuleFactories,
|
|
9
|
+
MarkdownEditor,
|
|
10
|
+
} from "./heavyOptionalExports";
|
|
11
|
+
|
|
12
|
+
describe("heavyOptionalExports", () => {
|
|
13
|
+
it("exposes lazy placeholders for heavy optional widgets", () => {
|
|
14
|
+
expect(AIRequestExplorer).toBeTruthy();
|
|
15
|
+
expect(DraggableList).toBeTruthy();
|
|
16
|
+
expect(EmojiSelector).toBeTruthy();
|
|
17
|
+
expect(MarkdownEditor).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("keeps EmojiSelector defaultProps.category referentially equal to Categories.all", () => {
|
|
21
|
+
expect(
|
|
22
|
+
(EmojiSelector as unknown as {defaultProps?: {category?: typeof Categories.all}}).defaultProps
|
|
23
|
+
?.category
|
|
24
|
+
).toBe(Categories.all);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("resolves each lazy module factory without rendering", async () => {
|
|
28
|
+
for (const factory of Object.values(heavyOptionalModuleFactories)) {
|
|
29
|
+
const moduleNamespace = await factory();
|
|
30
|
+
expect(moduleNamespace).toBeTruthy();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|