@terreno/ui 57.1.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.
- 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/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +101 -34
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +119 -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/DataTable.d.ts +2 -2
- package/dist/DataTable.js +203 -44
- 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/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/GPTChat.js +1 -1
- 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/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +45 -43
- 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/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/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/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +2 -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 +41 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +43 -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/package.json +41 -2
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +207 -0
- package/src/Button.tsx +146 -48
- package/src/Common.ts +124 -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.tsx +13 -5
- package/src/DataTable.tsx +418 -147
- 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/EmojiSelector.test.tsx +33 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/FilePickerButton.test.tsx +167 -0
- 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 +696 -0
- package/src/GPTChat.tsx +2 -2
- 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/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownView.test.tsx +55 -11
- package/src/MarkdownView.tsx +149 -150
- package/src/MediaQuery.ts +30 -34
- 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 +62 -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/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 +7 -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__/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__/TimezonePicker.test.tsx.snap +6 -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/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +27 -13
- 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 +106 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/loginTypes.ts +2 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
|
@@ -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,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,9 +3,9 @@ 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 "./AttachmentPreview";
|
|
6
|
+
export type * from "./AIRequestExplorer";
|
|
7
|
+
export type * from "./AiSuggestionBox";
|
|
8
|
+
export type * from "./AttachmentPreview";
|
|
9
9
|
export * from "./Avatar";
|
|
10
10
|
export * from "./Badge";
|
|
11
11
|
export {Banner, hideBanner} from "./Banner";
|
|
@@ -16,9 +16,9 @@ export * from "./Button";
|
|
|
16
16
|
export * from "./Card";
|
|
17
17
|
export * from "./CheckBox";
|
|
18
18
|
export * from "./Common";
|
|
19
|
-
export * from "./ConflictSheet";
|
|
20
|
-
export * from "./ConsentFormScreen";
|
|
21
|
-
export * from "./ConsentNavigator";
|
|
19
|
+
export type * from "./ConflictSheet";
|
|
20
|
+
export type * from "./ConsentFormScreen";
|
|
21
|
+
export type * from "./ConsentNavigator";
|
|
22
22
|
export * from "./Constants";
|
|
23
23
|
export * from "./CustomSelectField";
|
|
24
24
|
export * from "./conflictFieldDiff";
|
|
@@ -28,10 +28,8 @@ export * from "./DateTimeField";
|
|
|
28
28
|
export * from "./DateUtilities";
|
|
29
29
|
export * from "./DecimalRangeActionSheet";
|
|
30
30
|
export * from "./DismissButton";
|
|
31
|
-
export {DraggableList} from "./DraggableList";
|
|
32
31
|
export * from "./EditableCard";
|
|
33
32
|
export * from "./EmailField";
|
|
34
|
-
export {default as EmojiSelector} from "./EmojiSelector";
|
|
35
33
|
export * from "./ErrorBoundary";
|
|
36
34
|
export * from "./ErrorPage";
|
|
37
35
|
export * from "./Field";
|
|
@@ -42,8 +40,8 @@ export * from "./FilterBoolean";
|
|
|
42
40
|
export * from "./FilterChangesBadge";
|
|
43
41
|
export * from "./FilterSelectMenu";
|
|
44
42
|
export * from "./FlatList";
|
|
45
|
-
export * from "./GPTChat";
|
|
46
|
-
export * from "./GPTMemoryModal";
|
|
43
|
+
export type * from "./GPTChat";
|
|
44
|
+
export type * from "./GPTMemoryModal";
|
|
47
45
|
export * from "./Heading";
|
|
48
46
|
export * from "./HeightActionSheet";
|
|
49
47
|
export * from "./HeightField";
|
|
@@ -56,10 +54,25 @@ export * from "./InfoModalIcon";
|
|
|
56
54
|
export * from "./InfoTooltipButton";
|
|
57
55
|
export * from "./icons/BarsFilterIcon";
|
|
58
56
|
export * from "./Link";
|
|
57
|
+
export {
|
|
58
|
+
AIRequestExplorer,
|
|
59
|
+
AiSuggestionBox,
|
|
60
|
+
AttachmentPreview,
|
|
61
|
+
ConflictSheet,
|
|
62
|
+
ConsentFormScreen,
|
|
63
|
+
ConsentNavigator,
|
|
64
|
+
DraggableList,
|
|
65
|
+
EmojiSelector,
|
|
66
|
+
GPTChat,
|
|
67
|
+
GPTMemoryModal,
|
|
68
|
+
MarkdownEditor,
|
|
69
|
+
MarkdownEditorField,
|
|
70
|
+
UpgradeRequiredScreen,
|
|
71
|
+
} from "./lazyBoundaries/heavyOptionalExports";
|
|
59
72
|
export * from "./login/LoginScreen";
|
|
60
73
|
export type {LoginFieldConfig, LoginScreenProps} from "./login/loginTypes";
|
|
61
|
-
export * from "./MarkdownEditor";
|
|
62
|
-
export * from "./MarkdownEditorField";
|
|
74
|
+
export type * from "./MarkdownEditor";
|
|
75
|
+
export type * from "./MarkdownEditorField";
|
|
63
76
|
export * from "./MarkdownView";
|
|
64
77
|
export * from "./MediaQuery";
|
|
65
78
|
export * from "./MobileAddressAutoComplete";
|
|
@@ -74,6 +87,7 @@ export * from "./Page";
|
|
|
74
87
|
export * from "./Pagination";
|
|
75
88
|
export * from "./PasswordField";
|
|
76
89
|
export * from "./PhoneNumberField";
|
|
90
|
+
export * from "./Popover";
|
|
77
91
|
export * from "./PortalHost";
|
|
78
92
|
export * from "./pdfHtmlTemplate";
|
|
79
93
|
export * from "./Radio";
|
|
@@ -134,7 +148,7 @@ export * from "./table/TableTitle";
|
|
|
134
148
|
export * from "./table/tableContext";
|
|
135
149
|
export * from "./UnifiedAddressAutoComplete";
|
|
136
150
|
export * from "./Unifier";
|
|
137
|
-
export * from "./UpgradeRequiredScreen";
|
|
151
|
+
export type * from "./UpgradeRequiredScreen";
|
|
138
152
|
export * from "./UserInactivity";
|
|
139
153
|
export * from "./Utilities";
|
|
140
154
|
export * from "./useAppLaunchOrForeground";
|
|
@@ -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
|
+
});
|