@onekeyfe/react-native-native-list 6.7.0-3 → 6.7.0-30
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/README.md +4 -0
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +250 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +152 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +1 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -287
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
- package/docs/ROW_TEMPLATES.md +70 -11
- package/docs/SPEC.md +1170 -13
- package/docs/STYLE_SPEC.md +11 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +237 -51
- package/ios/NativeListActivityDetailsView.swift +30 -11
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +167 -30
- package/ios/NativeListDesignAssets.swift +13 -75
- package/ios/NativeListGeneratedIcons.swift +55 -0
- package/ios/NativeListIconBinding.swift +171 -0
- package/ios/NativeListIdentityRenderer.swift +256 -39
- package/ios/NativeListLeadingVisual.swift +127 -28
- package/ios/NativeListMarketRenderer.swift +120 -31
- package/ios/NativeListMediaPreviewSlot.swift +122 -61
- package/ios/NativeListMediaTileRenderer.swift +7 -3
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListMetricCardRenderer.swift +4 -2
- package/ios/NativeListModels.swift +42 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +2 -1
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +100 -4
- package/ios/RNCNativeListView.swift +1052 -58
- package/ios/tests/NativeListAccessoryStackTests.swift +101 -0
- package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2798 -3
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +26 -1
- package/ios/tests/NativeListSharedIconTests.swift +236 -0
- package/lib/module/NativeList.js +221 -36
- package/lib/module/NativeList.web.js +167 -46
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +3 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +1246 -48
- package/lib/module/web/NativeListGeneratedIcons.js +31 -0
- package/lib/module/web/NativeListWebEngine.js +513 -274
- package/lib/module/web/templates/ActivityRowRenderer.js +120 -87
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +40 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +158 -6
- package/lib/module/web/templates/MarketTableRowRenderer.js +37 -19
- package/lib/module/web/templates/MediaTileRowRenderer.js +4 -14
- package/lib/module/web/templates/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +3 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/lib/typescript/src/NativeList.d.ts +3 -3
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +20 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +126 -17
- package/lib/typescript/src/validation.d.ts +20 -0
- package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +32 -1
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/package.json +16 -10
- package/react-native-native-list.podspec +2 -6
- package/scripts/generate-icons.mjs +150 -0
- package/scripts/generate-icons.test.mjs +288 -0
- package/scripts/native-list-icons.json +260 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +416 -89
- package/src/NativeList.types.ts +24 -2
- package/src/NativeList.web.tsx +295 -89
- package/src/index.ts +2 -0
- package/src/models.ts +263 -144
- package/src/selection.ts +1 -0
- package/src/validation.ts +3013 -152
- package/src/web/NativeListGeneratedIcons.ts +28 -0
- package/src/web/NativeListWebEngine.ts +816 -343
- package/src/web/templates/ActivityRowRenderer.ts +178 -141
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +231 -6
- package/src/web/templates/MarketTableRowRenderer.ts +56 -33
- package/src/web/templates/MediaTileRowRenderer.ts +4 -17
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +11 -1
- package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
- package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
- package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +0 -1
package/lib/module/validation.js
CHANGED
|
@@ -12,15 +12,48 @@ const MAX_HEADER_LENGTH = 4096;
|
|
|
12
12
|
const MAX_SPACER_HEIGHT = 512;
|
|
13
13
|
const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
|
|
14
14
|
const MAX_MARKET_BADGES = 3;
|
|
15
|
+
const MARKET_METRIC_FIELDS = ['key', 'text', 'textSegments', 'secondaryText', 'secondaryTextSegments', 'weight', 'alignment', 'tone', 'secondaryTone'];
|
|
16
|
+
function isDevelopment() {
|
|
17
|
+
return typeof __DEV__ !== 'undefined' && __DEV__;
|
|
18
|
+
}
|
|
19
|
+
class NativeListInputError extends Error {
|
|
20
|
+
constructor(path, reason) {
|
|
21
|
+
super(`NativeList ${path}: ${reason}`);
|
|
22
|
+
this.path = path;
|
|
23
|
+
this.reason = reason;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
15
26
|
function fail(path, message) {
|
|
16
|
-
throw new
|
|
27
|
+
throw new NativeListInputError(path, message);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Component boundaries report locations, never caller-controlled payload values. */
|
|
31
|
+
export function containNativeListInput(operation) {
|
|
32
|
+
try {
|
|
33
|
+
return operation();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const path = error instanceof NativeListInputError ? error.path : 'input';
|
|
36
|
+
const reason = isDevelopment() && error instanceof NativeListInputError ? `: ${error.reason.split('"')[0].trim()}` : '';
|
|
37
|
+
console.warn(`NativeList rejected invalid input at ${path}${reason}`);
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
17
40
|
}
|
|
18
|
-
function
|
|
41
|
+
export function emptyNativeListSnapshot() {
|
|
42
|
+
return {
|
|
43
|
+
schemaVersion: 1,
|
|
44
|
+
generation: 0,
|
|
45
|
+
layout: {
|
|
46
|
+
kind: 'linear'
|
|
47
|
+
},
|
|
48
|
+
rows: []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function assertPlainSerializable(value, path, seen, requireFinite = true) {
|
|
19
52
|
if (value === null || value === undefined) return;
|
|
20
53
|
const valueType = typeof value;
|
|
21
54
|
if (valueType === 'string' || valueType === 'boolean') return;
|
|
22
55
|
if (valueType === 'number') {
|
|
23
|
-
if (!Number.isFinite(value)) fail(path, 'numbers must be finite');
|
|
56
|
+
if (requireFinite && !Number.isFinite(value)) fail(path, 'numbers must be finite');
|
|
24
57
|
return;
|
|
25
58
|
}
|
|
26
59
|
if (valueType !== 'object') fail(path, 'must contain only plain serializable data');
|
|
@@ -28,21 +61,23 @@ function assertPlainSerializable(value, path, seen) {
|
|
|
28
61
|
if (seen.has(objectValue)) fail(path, 'must not contain circular references');
|
|
29
62
|
seen.add(objectValue);
|
|
30
63
|
if (Array.isArray(value)) {
|
|
31
|
-
value.forEach((item, index) => assertPlainSerializable(item, `${path}[${index}]`, seen));
|
|
64
|
+
value.forEach((item, index) => assertPlainSerializable(item, `${path}[${index}]`, seen, requireFinite));
|
|
32
65
|
} else {
|
|
33
66
|
const prototype = Object.getPrototypeOf(value);
|
|
34
67
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
35
68
|
fail(path, 'must contain plain objects only');
|
|
36
69
|
}
|
|
37
|
-
Object.entries(value).forEach(([key, item]) =>
|
|
70
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
71
|
+
if (key === '__proto__' || key === 'constructor' && typeof item === 'object') fail(path, 'unsafe object key');
|
|
72
|
+
assertPlainSerializable(item, `${path}.${key}`, seen, requireFinite);
|
|
73
|
+
});
|
|
38
74
|
}
|
|
39
75
|
seen.delete(objectValue);
|
|
40
76
|
}
|
|
41
77
|
function assertKey(key, path) {
|
|
42
|
-
if (typeof key !== 'string' || key.length === 0 || key.length > MAX_KEY_LENGTH) {
|
|
43
|
-
fail(path, `must be a non-
|
|
78
|
+
if (typeof key !== 'string' || key.trim().length === 0 || key.length > MAX_KEY_LENGTH) {
|
|
79
|
+
fail(path, `must be a non-blank string no longer than ${MAX_KEY_LENGTH} characters`);
|
|
44
80
|
}
|
|
45
|
-
if (key.trim() !== key) fail(path, 'must not have leading or trailing whitespace');
|
|
46
81
|
}
|
|
47
82
|
function assertText(text, path) {
|
|
48
83
|
if (text === undefined) return;
|
|
@@ -136,10 +171,13 @@ const TEXT_STYLE_KEYS_BY_ROW_TYPE = {
|
|
|
136
171
|
metricCard: ['title', 'value', 'subtitle', 'trend'],
|
|
137
172
|
sectionHeader: ['title', 'subtitle', 'value'],
|
|
138
173
|
action: ['title', 'value'],
|
|
174
|
+
buttonGroup: [],
|
|
139
175
|
system: ['title', 'message', 'actionText']
|
|
140
176
|
};
|
|
141
177
|
const EXTRA_STYLE_KEYS_BY_ROW_TYPE = {
|
|
142
|
-
|
|
178
|
+
identity: ['leadingContentMaxWidthRatio'],
|
|
179
|
+
market: ['titleBadgeLayout', 'contentTrailingGap', 'subtitleTrailingPadding', 'changeWidth', 'changeHeight', 'changeCornerRadius'],
|
|
180
|
+
sectionHeader: ['valuePlacement', 'titleDecoration']
|
|
143
181
|
};
|
|
144
182
|
function assertTextStyle(style, path, additionalKeys = []) {
|
|
145
183
|
if (style === undefined) return;
|
|
@@ -252,6 +290,15 @@ function assertRowStyle(row, path) {
|
|
|
252
290
|
// Market keeps its own richer assertions, driven from assertMarketRow.
|
|
253
291
|
if (row.type === 'market') return;
|
|
254
292
|
assertBoxStyle(style, `${path}.style`);
|
|
293
|
+
if (row.type === 'identity') {
|
|
294
|
+
const ratio = style?.leadingContentMaxWidthRatio;
|
|
295
|
+
if (ratio !== undefined && (!Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
|
|
296
|
+
}
|
|
297
|
+
if (row.type === 'sectionHeader') {
|
|
298
|
+
const sectionStyle = style;
|
|
299
|
+
if (sectionStyle?.valuePlacement !== undefined && sectionStyle.valuePlacement !== 'afterTitle') fail(`${path}.style.valuePlacement`, 'must be afterTitle');
|
|
300
|
+
if (sectionStyle?.titleDecoration !== undefined && !['none', 'dashed'].includes(sectionStyle.titleDecoration)) fail(`${path}.style.titleDecoration`, 'must be none or dashed');
|
|
301
|
+
}
|
|
255
302
|
const slots = style;
|
|
256
303
|
textKeys.forEach(key => assertTextStyle(slots[key], `${path}.style.${key}`));
|
|
257
304
|
}
|
|
@@ -478,8 +525,56 @@ function assertWebMarketTable(table, path) {
|
|
|
478
525
|
}
|
|
479
526
|
});
|
|
480
527
|
}
|
|
528
|
+
function assertMarketMetrics(metrics, path) {
|
|
529
|
+
if (metrics === undefined) return;
|
|
530
|
+
if (!Array.isArray(metrics) || ![2, 3].includes(metrics.length)) fail(path, 'must contain 2 or 3 columns');
|
|
531
|
+
const keys = new Set();
|
|
532
|
+
metrics.forEach((column, index) => {
|
|
533
|
+
const columnPath = `${path}[${index}]`;
|
|
534
|
+
const value = protocolObject(column, columnPath);
|
|
535
|
+
protocolKey(value.key, `${columnPath}.key`);
|
|
536
|
+
if (keys.has(column.key)) fail(`${columnPath}.key`, 'must be unique');
|
|
537
|
+
keys.add(column.key);
|
|
538
|
+
if (typeof value.text !== 'string') fail(`${columnPath}.text`, 'must be a string');
|
|
539
|
+
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
540
|
+
const segments = column[field];
|
|
541
|
+
if (segments !== undefined && !Array.isArray(segments)) fail(`${columnPath}.${field}`, 'must be an array');
|
|
542
|
+
segments?.forEach((segment, segmentIndex) => {
|
|
543
|
+
const segmentPath = `${columnPath}.${field}[${segmentIndex}]`;
|
|
544
|
+
protocolObject(segment, segmentPath);
|
|
545
|
+
if (typeof segment.text !== 'string') fail(`${segmentPath}.text`, 'must be a string');
|
|
546
|
+
if (segment.style !== undefined && segment.style !== 'subscript') fail(`${segmentPath}.style`, 'must be subscript');
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (value.weight !== undefined && ![1, 2, 3].includes(value.weight)) fail(`${columnPath}.weight`, 'must be 1, 2, or 3');
|
|
550
|
+
if (value.alignment !== undefined && !['start', 'center', 'end'].includes(value.alignment)) fail(`${columnPath}.alignment`, 'must be start, center, or end');
|
|
551
|
+
if (value.secondaryText !== undefined && typeof value.secondaryText !== 'string') fail(`${columnPath}.secondaryText`, 'must be a string');
|
|
552
|
+
assertTextTone(value.tone, `${columnPath}.tone`);
|
|
553
|
+
assertTextTone(value.secondaryTone, `${columnPath}.secondaryTone`);
|
|
554
|
+
});
|
|
555
|
+
}
|
|
481
556
|
function assertMarketRow(row, path) {
|
|
482
557
|
assertWebMarketTable(row.webTable, `${path}.webTable`);
|
|
558
|
+
assertMarketMetrics(row.metrics, `${path}.metrics`);
|
|
559
|
+
if (row.metrics !== undefined) {
|
|
560
|
+
row.metrics.forEach((column, index) => {
|
|
561
|
+
const columnPath = `${path}.metrics[${index}]`;
|
|
562
|
+
const value = protocolObject(column, columnPath);
|
|
563
|
+
assertUnknownKeys(value, MARKET_METRIC_FIELDS, columnPath, 'Market metric key');
|
|
564
|
+
assertKey(column.key, `${columnPath}.key`);
|
|
565
|
+
assertText(column.text, `${columnPath}.text`);
|
|
566
|
+
assertText(column.secondaryText, `${columnPath}.secondaryText`);
|
|
567
|
+
assertTextTone(column.tone, `${columnPath}.tone`);
|
|
568
|
+
assertTextTone(column.secondaryTone, `${columnPath}.secondaryTone`);
|
|
569
|
+
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
570
|
+
column[field]?.forEach((segment, segmentIndex) => {
|
|
571
|
+
const segmentPath = `${columnPath}.${field}[${segmentIndex}]`;
|
|
572
|
+
assertText(segment.text, `${segmentPath}.text`);
|
|
573
|
+
if (segment.style !== undefined && segment.style !== 'subscript') fail(`${segmentPath}.style`, 'must be subscript');
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}
|
|
483
578
|
if (!['token', 'stock', 'perp'].includes(row.variant)) {
|
|
484
579
|
fail(`${path}.variant`, 'must be token, stock, or perp');
|
|
485
580
|
}
|
|
@@ -541,17 +636,106 @@ function assertVisualShape(shape, path) {
|
|
|
541
636
|
function assertTrailingAccessories(accessories, path) {
|
|
542
637
|
accessories?.forEach((accessory, index) => {
|
|
543
638
|
const accessoryPath = `${path}[${index}]`;
|
|
639
|
+
if (accessory.kind === 'button') {
|
|
640
|
+
assertUnknownKeys(accessory, ['kind', 'label', 'actionKey', 'disabled', 'testID', 'accessibilityLabel', 'textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor'], accessoryPath, 'button key');
|
|
641
|
+
if (typeof accessory.label !== 'string' || !accessory.label.trim()) fail(`${accessoryPath}.label`, 'must be non-blank');
|
|
642
|
+
assertKey(accessory.actionKey, `${accessoryPath}.actionKey`);
|
|
643
|
+
if (accessory.disabled !== undefined && typeof accessory.disabled !== 'boolean') fail(`${accessoryPath}.disabled`, 'must be boolean');
|
|
644
|
+
for (const field of ['textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor']) {
|
|
645
|
+
const value = accessory[field];
|
|
646
|
+
if (value !== undefined && (typeof value !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))) fail(`${accessoryPath}.${field}`, 'must be #RRGGBB or #RRGGBBAA');
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (accessory.kind === 'icon' && accessory.buttonStyle !== undefined && accessory.buttonStyle !== 'tertiary') fail(`${accessoryPath}.buttonStyle`, 'must be tertiary');
|
|
544
650
|
if (accessory.kind === 'progress' && (accessory.value < 0 || accessory.value > 1)) {
|
|
545
651
|
fail(`${accessoryPath}.value`, 'must be within 0...1');
|
|
546
652
|
}
|
|
547
653
|
if (accessory.kind === 'valuePair') {
|
|
654
|
+
if (accessory.primaryFontWeight !== undefined && accessory.primaryFontWeight !== 'medium') fail(`${accessoryPath}.primaryFontWeight`, 'must be medium when provided');
|
|
655
|
+
assertTextHelp(accessory.primaryHelp, `${accessoryPath}.primaryHelp`);
|
|
548
656
|
assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
|
|
549
657
|
assertTextTone(accessory.secondaryTone, `${accessoryPath}.secondaryTone`);
|
|
658
|
+
for (const field of ['primaryTextSegments', 'secondaryTextSegments']) {
|
|
659
|
+
const segments = accessory[field];
|
|
660
|
+
if (segments === undefined) continue;
|
|
661
|
+
const segmentPath = `${accessoryPath}.${field}`;
|
|
662
|
+
if (!Array.isArray(segments) || segments.length > 64) fail(segmentPath, 'must be an array of at most 64 segments');
|
|
663
|
+
let textLength = 0;
|
|
664
|
+
segments.forEach((segment, segmentIndex) => {
|
|
665
|
+
const path = `${segmentPath}[${segmentIndex}]`;
|
|
666
|
+
const entry = protocolObject(segment, path);
|
|
667
|
+
assertUnknownKeys(entry, ['text', 'style'], path, 'segment key');
|
|
668
|
+
if (typeof entry.text !== 'string' || entry.text.length > MAX_TEXT_LENGTH) fail(`${path}.text`, `must be a string no longer than ${MAX_TEXT_LENGTH} characters`);
|
|
669
|
+
if (entry.style !== undefined && entry.style !== 'subscript') fail(`${path}.style`, 'must be subscript when provided');
|
|
670
|
+
textLength += entry.text.length;
|
|
671
|
+
});
|
|
672
|
+
if (textLength > MAX_TEXT_LENGTH) fail(segmentPath, `total text must be at most ${MAX_TEXT_LENGTH} characters`);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function assertTextHelp(help, path) {
|
|
678
|
+
if (help === undefined) return;
|
|
679
|
+
const object = protocolObject(help, path);
|
|
680
|
+
assertUnknownKeys(object, ['actionKey', 'presentation', 'underline'], path, 'help key');
|
|
681
|
+
assertKey(help.actionKey, `${path}.actionKey`);
|
|
682
|
+
if (!['tooltip', 'popover'].includes(help.presentation)) fail(`${path}.presentation`, 'must be tooltip or popover');
|
|
683
|
+
if (help.underline !== undefined && help.underline !== 'dashed') fail(`${path}.underline`, 'must be dashed');
|
|
684
|
+
}
|
|
685
|
+
function assertButtonGroup(row, path) {
|
|
686
|
+
if (!Array.isArray(row.buttons) || row.buttons.length === 0) fail(`${path}.buttons`, 'must contain at least one button');
|
|
687
|
+
const keys = new Set();
|
|
688
|
+
row.buttons.forEach((button, index) => {
|
|
689
|
+
const itemPath = `${path}.buttons[${index}]`;
|
|
690
|
+
const object = protocolObject(button, itemPath);
|
|
691
|
+
assertUnknownKeys(object, ['key', 'label', 'actionKey', 'disabled', 'loading', 'testID', 'accessibilityLabel'], itemPath, 'button key');
|
|
692
|
+
assertKey(button.key, `${itemPath}.key`);
|
|
693
|
+
if (keys.has(button.key)) fail(`${itemPath}.key`, 'duplicate button key');
|
|
694
|
+
keys.add(button.key);
|
|
695
|
+
if (typeof button.label !== 'string' || !button.label.trim() || button.label.length > MAX_TEXT_LENGTH) fail(`${itemPath}.label`, 'must be non-blank bounded text');
|
|
696
|
+
assertKey(button.actionKey, `${itemPath}.actionKey`);
|
|
697
|
+
for (const field of ['disabled', 'loading']) {
|
|
698
|
+
if (button[field] !== undefined && typeof button[field] !== 'boolean') fail(`${itemPath}.${field}`, 'must be boolean');
|
|
699
|
+
}
|
|
700
|
+
for (const field of ['testID', 'accessibilityLabel']) {
|
|
701
|
+
if (button[field] !== undefined && typeof button[field] !== 'string') fail(`${itemPath}.${field}`, 'must be a string');
|
|
550
702
|
}
|
|
551
703
|
});
|
|
552
704
|
}
|
|
705
|
+
function assertIdentityExtras(row, path) {
|
|
706
|
+
for (const field of ['titleIcon', 'secondaryTitleIcon']) {
|
|
707
|
+
const titleIcon = row[field];
|
|
708
|
+
if (titleIcon === undefined) continue;
|
|
709
|
+
const iconPath = `${path}.${field}`;
|
|
710
|
+
const icon = protocolObject(titleIcon, iconPath);
|
|
711
|
+
assertUnknownKeys(icon, ['name', 'tintColor', 'accessibilityLabel', 'hoverActionKey'], iconPath, 'title icon key');
|
|
712
|
+
if (typeof titleIcon.name !== 'string' || !titleIcon.name.trim()) fail(`${iconPath}.name`, 'must be non-blank');
|
|
713
|
+
if (titleIcon.tintColor !== undefined && (typeof titleIcon.tintColor !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(titleIcon.tintColor))) fail(`${iconPath}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
|
|
714
|
+
if (titleIcon.accessibilityLabel !== undefined && typeof titleIcon.accessibilityLabel !== 'string') fail(`${iconPath}.accessibilityLabel`, 'must be a string');
|
|
715
|
+
if (titleIcon.hoverActionKey !== undefined) assertKey(titleIcon.hoverActionKey, `${iconPath}.hoverActionKey`);
|
|
716
|
+
}
|
|
717
|
+
if (row.titleImage !== undefined) {
|
|
718
|
+
const imagePath = `${path}.titleImage`;
|
|
719
|
+
const descriptor = protocolObject(row.titleImage, imagePath);
|
|
720
|
+
assertUnknownKeys(descriptor, ['image', 'accessibilityLabel', 'hoverActionKey'], imagePath, 'title image key');
|
|
721
|
+
protocolObject(row.titleImage.image, `${imagePath}.image`);
|
|
722
|
+
if (typeof row.titleImage.image.uri !== 'string') fail(`${imagePath}.image.uri`, 'must be a string');
|
|
723
|
+
assertImage(row.titleImage.image, `${imagePath}.image`);
|
|
724
|
+
const {
|
|
725
|
+
width,
|
|
726
|
+
height
|
|
727
|
+
} = row.titleImage.image;
|
|
728
|
+
if (width !== height || width < 1 || width > 40) fail(`${imagePath}.image`, 'must be square within 1...40');
|
|
729
|
+
if (row.titleImage.accessibilityLabel !== undefined && typeof row.titleImage.accessibilityLabel !== 'string') fail(`${imagePath}.accessibilityLabel`, 'must be a string');
|
|
730
|
+
if (row.titleImage.hoverActionKey !== undefined) assertKey(row.titleImage.hoverActionKey, `${imagePath}.hoverActionKey`);
|
|
731
|
+
}
|
|
732
|
+
const ratio = row.style?.leadingContentMaxWidthRatio;
|
|
733
|
+
if (ratio !== undefined && (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
|
|
734
|
+
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
735
|
+
}
|
|
553
736
|
function assertImage(image, path) {
|
|
554
737
|
if (!image) return;
|
|
738
|
+
if (!isAllowedImageUri(image.uri)) fail(`${path}.uri`, 'unsupported image URI');
|
|
555
739
|
if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
|
|
556
740
|
if (image.fallbackUris !== undefined) {
|
|
557
741
|
if (!Array.isArray(image.fallbackUris)) fail(`${path}.fallbackUris`, 'must be an array');
|
|
@@ -594,6 +778,9 @@ function assertLeadingVisual(visual, path) {
|
|
|
594
778
|
assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
|
|
595
779
|
// OneKey patch: validate optional selector overlays at the JSON boundary.
|
|
596
780
|
assertText(visual.fallbackIcon?.name, `${path}.fallbackIcon.name`);
|
|
781
|
+
if (visual.fallbackTextColor !== undefined && (typeof visual.fallbackTextColor !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackTextColor))) fail(`${path}.fallbackTextColor`, 'must be a hex color');
|
|
782
|
+
if (visual.fallbackIcon?.size !== undefined && (!Number.isFinite(visual.fallbackIcon.size) || visual.fallbackIcon.size <= 0 || visual.fallbackIcon.size > 40)) fail(`${path}.fallbackIcon.size`, 'must be within (0, 40]');
|
|
783
|
+
if (visual.fallbackIcon?.backgroundColor !== undefined && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackIcon.backgroundColor)) fail(`${path}.fallbackIcon.backgroundColor`, 'must be a hex color');
|
|
597
784
|
if ((visual.overlays?.length ?? 0) > 2) fail(`${path}.overlays`, 'supports at most two overlays');
|
|
598
785
|
visual.overlays?.forEach((overlay, index) => {
|
|
599
786
|
if (!['topLeft', 'bottomRight'].includes(overlay.position)) fail(`${path}.overlays[${index}].position`, 'must be topLeft or bottomRight');
|
|
@@ -610,7 +797,11 @@ function assertLeadingVisual(visual, path) {
|
|
|
610
797
|
}
|
|
611
798
|
if (overlay.padding !== undefined && overlay.padding * 2 >= Math.min(overlay.width ?? overlay.size ?? 20, overlay.height ?? overlay.size ?? 20)) fail(`${path}.overlays[${index}].padding`, 'must fit inside the overlay');
|
|
612
799
|
assertImage(overlay.image, `${path}.overlays[${index}].image`);
|
|
800
|
+
if (overlay.fallbackIcon !== undefined && !overlay.image) fail(`${path}.overlays[${index}].fallbackIcon`, 'requires image');
|
|
801
|
+
if (overlay.fallbackIcon !== undefined && (typeof overlay.fallbackIcon.name !== 'string' || !overlay.fallbackIcon.name.trim())) fail(`${path}.overlays[${index}].fallbackIcon.name`, 'must be non-blank');
|
|
802
|
+
if (overlay.fallbackIcon?.tintColor !== undefined && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(overlay.fallbackIcon.tintColor)) fail(`${path}.overlays[${index}].fallbackIcon.tintColor`, 'must be a hex color');
|
|
613
803
|
assertText(overlay.text, `${path}.overlays[${index}].text`);
|
|
804
|
+
if (overlay.fontWeight !== undefined && !['regular', 'medium', 'semibold', 'bold'].includes(overlay.fontWeight)) fail(`${path}.overlays[${index}].fontWeight`, 'must be regular, medium, semibold, or bold');
|
|
614
805
|
});
|
|
615
806
|
if (visual.kind === 'token') {
|
|
616
807
|
assertImage(visual.networkImage, `${path}.networkImage`);
|
|
@@ -624,6 +815,7 @@ function assertVisual(row, path) {
|
|
|
624
815
|
});
|
|
625
816
|
}
|
|
626
817
|
function assertActivity(row, path) {
|
|
818
|
+
if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean') fail(`${path}.hideLeading`, 'must be boolean');
|
|
627
819
|
assertText(row.title, `${path}.title`);
|
|
628
820
|
assertText(row.description, `${path}.description`);
|
|
629
821
|
if (row.presentation !== undefined && !['stacked', 'table'].includes(row.presentation)) fail(`${path}.presentation`, 'must be stacked or table');
|
|
@@ -702,6 +894,7 @@ function assertRowType(type, path) {
|
|
|
702
894
|
}
|
|
703
895
|
function assertRow(row, index, path = `rows[${index}]`) {
|
|
704
896
|
assertRowType(row.type, path);
|
|
897
|
+
assertUnknownKeys(row, ROW_FIELDS[row.type], path, 'row key');
|
|
705
898
|
assertKey(row.key, `${path}.key`);
|
|
706
899
|
// OneKey patch: explicit dimensions and opacity cannot corrupt list layout.
|
|
707
900
|
if (row.height !== undefined && (row.height < 0 || row.height > 4096)) fail(`${path}.height`, 'must be within 0...4096');
|
|
@@ -720,10 +913,26 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
720
913
|
assertWalletGroup(row, path);
|
|
721
914
|
break;
|
|
722
915
|
case 'identity':
|
|
916
|
+
if (row.contentHeight !== undefined && row.contentHeight !== 'auto') {
|
|
917
|
+
fail(`${path}.contentHeight`, 'must be auto');
|
|
918
|
+
}
|
|
919
|
+
if (row.subtitleLines !== undefined && ![0, 1, 2].includes(row.subtitleLines)) {
|
|
920
|
+
fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
|
|
921
|
+
}
|
|
922
|
+
if (row.longPressActionKey !== undefined) {
|
|
923
|
+
assertKey(row.longPressActionKey, `${path}.longPressActionKey`);
|
|
924
|
+
}
|
|
723
925
|
if (row.presentation !== undefined && row.presentation !== 'walletSidebar' && row.presentation !== 'accountSelector' && row.presentation !== 'networkSelector') {
|
|
724
926
|
fail(`${path}.presentation`, 'must be walletSidebar, accountSelector, or networkSelector when provided');
|
|
725
927
|
}
|
|
726
928
|
assertText(row.title, `${path}.title`);
|
|
929
|
+
if ((row.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
|
|
930
|
+
row.titleSuffixes?.forEach((suffix, index) => {
|
|
931
|
+
assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
|
|
932
|
+
if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
|
|
933
|
+
if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
|
|
934
|
+
});
|
|
935
|
+
assertIdentityExtras(row, path);
|
|
727
936
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
728
937
|
// OneKey patch: selector text segments truncate independently.
|
|
729
938
|
row.subtitleSegments?.forEach((segment, segmentIndex) => {
|
|
@@ -755,10 +964,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
755
964
|
assertActivity(row, path);
|
|
756
965
|
break;
|
|
757
966
|
case 'message':
|
|
967
|
+
if (row.presentation !== undefined && row.presentation !== 'inlineWarning') {
|
|
968
|
+
fail(`${path}.presentation`, 'must be inlineWarning');
|
|
969
|
+
}
|
|
758
970
|
assertText(row.title, `${path}.title`);
|
|
759
971
|
assertText(row.body, `${path}.body`);
|
|
760
|
-
if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
|
|
761
|
-
fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
|
|
972
|
+
if (![0, 1, 2, 3].includes(row.bodyLines ?? 3)) {
|
|
973
|
+
fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
|
|
762
974
|
}
|
|
763
975
|
assertImage(row.thumbnail, `${path}.thumbnail`);
|
|
764
976
|
break;
|
|
@@ -769,6 +981,13 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
769
981
|
row.columns.forEach((column, columnIndex) => {
|
|
770
982
|
assertKey(column.key, `${path}.columns[${columnIndex}].key`);
|
|
771
983
|
assertText(column.text, `${path}.columns[${columnIndex}].text`);
|
|
984
|
+
assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
|
|
985
|
+
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
986
|
+
column[field]?.forEach((segment, segmentIndex) => {
|
|
987
|
+
assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
|
|
988
|
+
if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
|
|
989
|
+
});
|
|
990
|
+
}
|
|
772
991
|
assertText(column.secondaryLeadingText, `${path}.columns[${columnIndex}].secondaryLeadingText`);
|
|
773
992
|
assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
|
|
774
993
|
assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
|
|
@@ -776,6 +995,10 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
776
995
|
if ((row.badges?.length ?? 0) > MAX_BADGES) {
|
|
777
996
|
fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
|
|
778
997
|
}
|
|
998
|
+
if ((row.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
|
|
999
|
+
fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
|
|
1000
|
+
}
|
|
1001
|
+
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
779
1002
|
break;
|
|
780
1003
|
case 'market':
|
|
781
1004
|
assertMarketRow(row, path);
|
|
@@ -826,6 +1049,11 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
826
1049
|
assertText(row.title, `${path}.title`);
|
|
827
1050
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
828
1051
|
assertText(row.value, `${path}.value`);
|
|
1052
|
+
if (row.leadingBadge) {
|
|
1053
|
+
assertKey(row.leadingBadge.key, `${path}.leadingBadge.key`);
|
|
1054
|
+
assertText(row.leadingBadge.text, `${path}.leadingBadge.text`);
|
|
1055
|
+
}
|
|
1056
|
+
assertTextHelp(row.valueHelp, `${path}.valueHelp`);
|
|
829
1057
|
if (row.valueActionKey !== undefined) {
|
|
830
1058
|
assertKey(row.valueActionKey, `${path}.valueActionKey`);
|
|
831
1059
|
}
|
|
@@ -846,6 +1074,9 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
846
1074
|
}
|
|
847
1075
|
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
848
1076
|
break;
|
|
1077
|
+
case 'buttonGroup':
|
|
1078
|
+
assertButtonGroup(row, path);
|
|
1079
|
+
break;
|
|
849
1080
|
case 'system':
|
|
850
1081
|
const presentation = 'presentation' in row ? row.presentation : undefined;
|
|
851
1082
|
if (presentation !== undefined && presentation !== 'market') {
|
|
@@ -906,10 +1137,23 @@ function assertMediaPreview(value, path) {
|
|
|
906
1137
|
fail(`${path}.probeOrder`, 'must contain one or two distinct image/video candidates');
|
|
907
1138
|
}
|
|
908
1139
|
}
|
|
909
|
-
|
|
1140
|
+
function assertSnapshotContract(snapshot) {
|
|
1141
|
+
if (snapshot.disclosure !== undefined) {
|
|
1142
|
+
if (typeof snapshot.disclosure.expanded !== 'boolean') fail('snapshot.disclosure.expanded', 'must be a boolean');
|
|
1143
|
+
const inset = snapshot.disclosure.expandedTrailingInset;
|
|
1144
|
+
if (inset !== undefined && (!Number.isFinite(inset) || inset < 0)) fail('snapshot.disclosure.expandedTrailingInset', 'must be finite and nonnegative');
|
|
1145
|
+
}
|
|
1146
|
+
if (snapshot.structuralTransition) {
|
|
1147
|
+
assertKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
|
|
1148
|
+
if (snapshot.structuralTransition.anchorKey !== undefined) assertKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
|
|
1149
|
+
const duration = snapshot.structuralTransition.durationMs;
|
|
1150
|
+
if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
|
|
1151
|
+
}
|
|
910
1152
|
if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
|
|
911
1153
|
assertPlainSerializable(snapshot, 'snapshot', new Set());
|
|
912
1154
|
assertText(snapshot.theme?.imageFallbackBackground, 'theme.imageFallbackBackground');
|
|
1155
|
+
if (snapshot.theme?.successBackground !== undefined && (typeof snapshot.theme.successBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))) fail('theme.successBackground', 'must be a hex color');
|
|
1156
|
+
if (snapshot.theme?.rowHoverBackground !== undefined && (typeof snapshot.theme.rowHoverBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))) fail('theme.rowHoverBackground', 'must be a hex color');
|
|
913
1157
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
914
1158
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
|
|
915
1159
|
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
@@ -978,7 +1222,621 @@ export function validateSnapshot(snapshot) {
|
|
|
978
1222
|
if (snapshot.selection?.mode === 'single' && selectedKeys.size > 1) {
|
|
979
1223
|
fail('snapshot.selection.selectedKeys', 'supports at most one key in single mode');
|
|
980
1224
|
}
|
|
981
|
-
return
|
|
1225
|
+
return snapshot;
|
|
1226
|
+
}
|
|
1227
|
+
const COMMON_ROW_FIELDS = ['height', 'heightRounding', 'testID', 'opacity', 'backgroundColor', 'backgroundFullWidth', 'pressDisabled', 'key', 'revision', 'sectionKey', 'groupId', 'groupPosition', 'size', 'density', 'disabled', 'selected', 'accessibilityLabel', 'separator', 'type', 'style'];
|
|
1228
|
+
const ROW_FIELDS = {
|
|
1229
|
+
identity: [...COMMON_ROW_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'presentation', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'titleLines', 'subtitleLines', 'badges', 'trailing', 'draggable'],
|
|
1230
|
+
walletGroup: [...COMMON_ROW_FIELDS, 'parent', 'children', 'draggable'],
|
|
1231
|
+
rail: [...COMMON_ROW_FIELDS, 'visual', 'title', 'status', 'badge', 'draggable'],
|
|
1232
|
+
activity: [...COMMON_ROW_FIELDS, 'leading', 'hideLeading', 'secondaryLeading', 'title', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'amounts', 'badges', 'presentation', 'fee', 'descriptionActionKey', 'footerActions'],
|
|
1233
|
+
message: [...COMMON_ROW_FIELDS, 'presentation', 'unread', 'leading', 'title', 'body', 'bodyLines', 'time', 'thumbnail'],
|
|
1234
|
+
dataRow: [...COMMON_ROW_FIELDS, 'leading', 'columns', 'trailing', 'checkbox', 'index', 'badge', 'badges', 'favorite', 'favoriteActive'],
|
|
1235
|
+
market: [...COMMON_ROW_FIELDS, 'variant', 'webTable', 'metrics', 'leadingAction', 'leading', 'title', 'subtitle', 'subtitlePrefix', 'subtitleSegments', 'price', 'priceSegments', 'change', 'badges', 'pressActionKey', 'pressInActionKey', 'longPressActionKey', 'diagnostics'],
|
|
1236
|
+
mediaTile: [...COMMON_ROW_FIELDS, 'variant', 'media', 'image', 'imageState', 'networkImage', 'title', 'subtitle', 'badge', 'closeActionKey'],
|
|
1237
|
+
metricCard: [...COMMON_ROW_FIELDS, 'variant', 'title', 'value', 'subtitle', 'trend', 'trendTone', 'visual', 'badge', 'metrics', 'progress'],
|
|
1238
|
+
sectionHeader: [...COMMON_ROW_FIELDS, 'sticky', 'valueActionTestID', 'valueSegments', 'titleActionKey', 'titleActionOnHover', 'presentation', 'indexTitle', 'variant', 'title', 'leadingBadge', 'titleLoading', 'subtitle', 'value', 'valueHelp', 'valueActionKey', 'titleIcon', 'valueIcon', 'checkbox'],
|
|
1239
|
+
action: [...COMMON_ROW_FIELDS, 'presentation', 'title', 'actionKey', 'tone', 'icon', 'checkbox', 'trailing'],
|
|
1240
|
+
buttonGroup: [...COMMON_ROW_FIELDS, 'buttons'],
|
|
1241
|
+
system: [...COMMON_ROW_FIELDS, 'variant', 'presentation', 'loadingStyle', 'message', 'actionKey', 'actionText', 'title', 'borderColor']
|
|
1242
|
+
};
|
|
1243
|
+
const COMMON_PATCH_FIELDS = ['height', 'heightRounding', 'opacity', 'pressDisabled', 'revision', 'disabled', 'selected', 'accessibilityLabel', 'separator', 'style'];
|
|
1244
|
+
const PATCH_FIELDS = {
|
|
1245
|
+
identity: [...COMMON_PATCH_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'subtitleLines', 'badges', 'trailing'],
|
|
1246
|
+
rail: [...COMMON_PATCH_FIELDS, 'title', 'visual', 'status', 'badge'],
|
|
1247
|
+
activity: [...COMMON_PATCH_FIELDS, 'presentation', 'leading', 'title', 'badges', 'status', 'hideLeading', 'secondaryLeading', 'description', 'primaryAmount', 'secondaryAmount', 'amounts', 'fee', 'descriptionActionKey', 'footerActions'],
|
|
1248
|
+
message: [...COMMON_PATCH_FIELDS, 'presentation', 'title', 'unread', 'body', 'bodyLines', 'time', 'thumbnail'],
|
|
1249
|
+
dataRow: [...COMMON_PATCH_FIELDS, 'leading', 'badges', 'trailing', 'badge', 'columns', 'checkbox', 'index', 'favorite', 'favoriteActive'],
|
|
1250
|
+
market: [...COMMON_PATCH_FIELDS, 'longPressActionKey', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'subtitle', 'badges', 'webTable', 'metrics', 'price', 'priceSegments', 'change', 'pressActionKey', 'pressInActionKey', 'diagnostics'],
|
|
1251
|
+
mediaTile: [...COMMON_PATCH_FIELDS, 'title', 'subtitle', 'badge', 'media', 'image', 'imageState', 'networkImage', 'closeActionKey'],
|
|
1252
|
+
metricCard: [...COMMON_PATCH_FIELDS, 'title', 'subtitle', 'visual', 'badge', 'variant', 'value', 'trend', 'trendTone', 'metrics', 'progress'],
|
|
1253
|
+
sectionHeader: [...COMMON_PATCH_FIELDS, 'titleActionKey', 'titleActionOnHover', 'title', 'titleIcon', 'subtitle', 'checkbox', 'variant', 'value', 'leadingBadge', 'titleLoading', 'valueHelp', 'valueActionKey', 'valueIcon'],
|
|
1254
|
+
action: [...COMMON_PATCH_FIELDS, 'title', 'trailing', 'checkbox', 'tone', 'icon'],
|
|
1255
|
+
buttonGroup: [...COMMON_PATCH_FIELDS, 'buttons'],
|
|
1256
|
+
system: ['revision', 'disabled', 'message']
|
|
1257
|
+
};
|
|
1258
|
+
function protocolObject(value, path) {
|
|
1259
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) fail(path, 'must be an object');
|
|
1260
|
+
return value;
|
|
1261
|
+
}
|
|
1262
|
+
function protocolKey(value, path) {
|
|
1263
|
+
if (typeof value !== 'string' || value.trim().length === 0) fail(path, 'must be a non-blank string');
|
|
1264
|
+
}
|
|
1265
|
+
const PROTOCOL_ARRAY_FIELDS = new Set(['columns', 'titleSuffixes', 'cells', 'points', 'images', 'overlays', 'badges', 'trailing', 'footerActions', 'buttons', 'amounts', 'metrics', 'children', 'subtitleSegments', 'titleMatch', 'selectedKeys', 'segments', 'hoverSecondary', 'hoverImages', 'secondaryBadges', 'fallbackUris', 'probeOrder', 'priceSegments', 'textSegments', 'secondaryTextSegments', 'primaryTextSegments']);
|
|
1266
|
+
const PROTOCOL_NUMBER_FIELDS = new Set(['leadingContentMaxWidthRatio', 'height', 'width', 'fontSize', 'lineHeight', 'opacity', 'offsetY', 'offsetX', 'cornerRadius', 'borderWidth', 'horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'start', 'end', 'padding', 'offset', 'overscan', 'minWidth', 'flex', 'paddingStart', 'paddingEnd', 'changeWidth', 'changeHeight', 'changeCornerRadius', 'contentTrailingGap', 'subtitleTrailingPadding', 'partGap', 'contentPadding', 'contentPaddingHorizontal', 'contentPaddingTop', 'contentPaddingBottom', 'itemSpacing', 'gridColumns']);
|
|
1267
|
+
|
|
1268
|
+
/** Validate only shapes that renderers dereference, not display budgets. */
|
|
1269
|
+
function assertProtocolFields(value, path, parentField = '') {
|
|
1270
|
+
if (value === undefined || value === null || typeof value !== 'object') return;
|
|
1271
|
+
if (Array.isArray(value)) {
|
|
1272
|
+
for (const [index, item] of value.entries()) {
|
|
1273
|
+
const itemPath = `${path}[${index}]`;
|
|
1274
|
+
if (['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)) {
|
|
1275
|
+
if (typeof item !== 'string') fail(itemPath, 'must be a string');
|
|
1276
|
+
} else if (parentField === 'points') {
|
|
1277
|
+
if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
|
|
1278
|
+
} else if (parentField === 'hoverImages' && item === null) continue;else protocolObject(item, itemPath);
|
|
1279
|
+
assertProtocolFields(item, itemPath, parentField);
|
|
1280
|
+
}
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
const object = value;
|
|
1284
|
+
if (parentField === 'fallbackIcon') {
|
|
1285
|
+
protocolKey(object.name, `${path}.name`);
|
|
1286
|
+
if (object.size !== undefined && (typeof object.size !== 'number' || !Number.isFinite(object.size) || object.size <= 0 || object.size > 40)) fail(`${path}.size`, 'must be within (0, 40]');
|
|
1287
|
+
for (const field of ['tintColor', 'backgroundColor']) {
|
|
1288
|
+
const color = object[field];
|
|
1289
|
+
if (color !== undefined && (typeof color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color))) fail(`${path}.${field}`, 'must be a hex color');
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
if (parentField === 'overlays' && object.fallbackIcon !== undefined && !object.image) fail(`${path}.fallbackIcon`, 'requires image');
|
|
1293
|
+
if (!path.includes('.style.') && ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(parentField) && typeof object.uri !== 'string') fail(`${path}.uri`, 'must be a string');
|
|
1294
|
+
Object.entries(value).forEach(([field, item]) => {
|
|
1295
|
+
if (item === undefined) return;
|
|
1296
|
+
if (field === 'headers') {
|
|
1297
|
+
const headers = protocolObject(item, `${path}.headers`);
|
|
1298
|
+
for (const [name, headerValue] of Object.entries(headers)) {
|
|
1299
|
+
if (!name.trim() || typeof headerValue !== 'string') fail(`${path}.headers`, 'must contain string headers');
|
|
1300
|
+
}
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
const fieldPath = `${path}.${field}`;
|
|
1304
|
+
if (!path.endsWith('.style') && PROTOCOL_ARRAY_FIELDS.has(field) && !Array.isArray(item)) fail(fieldPath, 'must be an array');
|
|
1305
|
+
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number') fail(fieldPath, 'must be a finite number');
|
|
1306
|
+
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item === 'number' && item < 0 && !['offsetX', 'offsetY'].includes(field)) fail(fieldPath, 'must be non-negative');
|
|
1307
|
+
if (parentField === 'overlays' && field === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) fail(fieldPath, 'must be regular, medium, semibold, or bold');
|
|
1308
|
+
if (field === 'buttonStyle' && item !== 'tertiary') fail(fieldPath, 'must be tertiary');
|
|
1309
|
+
if (field === 'hideLeading' && typeof item !== 'boolean') fail(fieldPath, 'must be boolean');
|
|
1310
|
+
if (field === 'key' || field === 'sectionKey' || field === 'groupId' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
|
|
1311
|
+
if ((field === 'uri' || field === 'fallbackUri') && typeof item !== 'string') fail(fieldPath, 'must be a string');
|
|
1312
|
+
if (field === 'style' && !(item === 'subscript' && /[Ss]egments\[/.test(path)) || field === 'container') protocolObject(item, fieldPath);
|
|
1313
|
+
if (path.endsWith('.style') && ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'change', 'columns', 'columnSecondary', 'value', 'valueSecondary', 'badge', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'trend', 'message', 'actionText'].includes(field)) protocolObject(item, fieldPath);
|
|
1314
|
+
assertProtocolFields(item, fieldPath, field);
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
function assertRowProtocol(row, path) {
|
|
1318
|
+
protocolObject(row, path);
|
|
1319
|
+
assertRowType(row.type, path);
|
|
1320
|
+
protocolKey(row.key, `${path}.key`);
|
|
1321
|
+
assertCoreRow(row, path);
|
|
1322
|
+
assertProtocolFields(row, path);
|
|
1323
|
+
for (const field of ['leading', 'visual', 'secondaryLeading']) {
|
|
1324
|
+
const visual = row[field];
|
|
1325
|
+
if (visual !== undefined || field === 'leading' && (row.type === 'identity' || row.type === 'market')) {
|
|
1326
|
+
const object = protocolObject(visual, `${path}.${field}`);
|
|
1327
|
+
if (object.kind === 'stackedImages' && !Array.isArray(object.images)) fail(`${path}.${field}.images`, 'must be an array');
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
for (const field of ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'indexTitle']) {
|
|
1331
|
+
const value = row[field];
|
|
1332
|
+
if (value !== undefined && typeof value !== 'string') fail(`${path}.${field}`, 'must be a string');
|
|
1333
|
+
}
|
|
1334
|
+
if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
|
|
1335
|
+
if (row.type === 'identity') {
|
|
1336
|
+
if (isDevelopment()) assertIdentityExtras(row, path);
|
|
1337
|
+
if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes)) fail(`${path}.titleSuffixes`, 'must be an array');
|
|
1338
|
+
row.titleSuffixes?.forEach((suffix, index) => {
|
|
1339
|
+
protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
|
|
1340
|
+
if (typeof suffix.text !== 'string' || !['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}]`, 'invalid title suffix');
|
|
1341
|
+
if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
|
|
1342
|
+
});
|
|
1343
|
+
let end = 0;
|
|
1344
|
+
row.titleMatch?.forEach(match => {
|
|
1345
|
+
if (!Number.isInteger(match.start) || !Number.isInteger(match.end) || match.start < end || match.end <= match.start || match.end > row.title.length) fail(`${path}.titleMatch`, 'invalid text range');
|
|
1346
|
+
end = match.end;
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
if (row.type === 'buttonGroup' && isDevelopment()) assertButtonGroup(row, path);
|
|
1350
|
+
if (row.type === 'sectionHeader' && isDevelopment()) assertTextHelp(row.valueHelp, `${path}.valueHelp`);
|
|
1351
|
+
if (row.type === 'mediaTile' && row.media) {
|
|
1352
|
+
protocolObject(row.media.source, `${path}.media.source`);
|
|
1353
|
+
if (!Array.isArray(row.media.probeOrder)) fail(`${path}.media.probeOrder`, 'must be an array');
|
|
1354
|
+
}
|
|
1355
|
+
if (row.type === 'walletGroup') {
|
|
1356
|
+
protocolObject(row.parent, `${path}.parent`);
|
|
1357
|
+
if (!Array.isArray(row.children)) fail(`${path}.children`, 'must be an array');
|
|
1358
|
+
const members = [row.parent, ...row.children];
|
|
1359
|
+
const keys = new Set();
|
|
1360
|
+
if (row.parent.key !== row.key) fail(`${path}.parent.key`, 'must match its group');
|
|
1361
|
+
members.forEach((member, index) => {
|
|
1362
|
+
assertRowProtocol(member, `${path}.members[${index}]`);
|
|
1363
|
+
if (member.type !== 'identity' || keys.has(member.key)) fail(path, 'invalid wallet member identity');
|
|
1364
|
+
keys.add(member.key);
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
if (row.type === 'dataRow') {
|
|
1368
|
+
if (!Array.isArray(row.columns)) fail(`${path}.columns`, 'must be an array');
|
|
1369
|
+
row.columns.forEach((column, index) => {
|
|
1370
|
+
const columnPath = `${path}.columns[${index}]`;
|
|
1371
|
+
protocolObject(column, columnPath);
|
|
1372
|
+
if (isDevelopment()) assertIdentityExtras(column, columnPath);
|
|
1373
|
+
});
|
|
1374
|
+
if (isDevelopment()) assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
1375
|
+
}
|
|
1376
|
+
if (row.type === 'market') {
|
|
1377
|
+
protocolObject(row.change, `${path}.change`);
|
|
1378
|
+
assertMarketMetrics(row.metrics, `${path}.metrics`);
|
|
1379
|
+
if (row.webTable) {
|
|
1380
|
+
const {
|
|
1381
|
+
columns,
|
|
1382
|
+
cells
|
|
1383
|
+
} = row.webTable;
|
|
1384
|
+
if (!Array.isArray(columns) || !Array.isArray(cells) || columns.length !== cells.length) fail(`${path}.webTable`, 'columns and cells must match');
|
|
1385
|
+
const keys = new Set();
|
|
1386
|
+
columns.forEach((column, index) => {
|
|
1387
|
+
protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
|
|
1388
|
+
if (keys.has(column.key) || cells[index]?.key !== column.key) fail(`${path}.webTable`, 'invalid column identity');
|
|
1389
|
+
keys.add(column.key);
|
|
1390
|
+
const cell = cells[index];
|
|
1391
|
+
if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind)) fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
|
|
1392
|
+
if (cell.kind === 'asset') protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
|
|
1393
|
+
if ((cell.kind === 'asset' || cell.kind === 'text') && cell.secondary !== undefined && !Array.isArray(cell.secondary)) fail(`${path}.webTable.cells[${index}].secondary`, 'must be an array');
|
|
1394
|
+
if (cell.kind === 'text' && !Array.isArray(cell.primary)) fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
|
|
1395
|
+
// The Web renderer spreads samples into Math.min/Math.max.
|
|
1396
|
+
if (cell.kind === 'sparkline' && (!Array.isArray(cell.points) || cell.points.length > 256)) fail(`${path}.webTable.cells[${index}].points`, 'must be an array of at most 256 samples');
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
function assertSnapshotProtocol(snapshot) {
|
|
1402
|
+
protocolObject(snapshot, 'snapshot');
|
|
1403
|
+
if (snapshot.disclosure !== undefined) {
|
|
1404
|
+
protocolObject(snapshot.disclosure, 'snapshot.disclosure');
|
|
1405
|
+
if (typeof snapshot.disclosure.expanded !== 'boolean') fail('snapshot.disclosure.expanded', 'must be a boolean');
|
|
1406
|
+
const inset = snapshot.disclosure.expandedTrailingInset;
|
|
1407
|
+
if (inset !== undefined && (!Number.isFinite(inset) || inset < 0)) fail('snapshot.disclosure.expandedTrailingInset', 'must be finite and nonnegative');
|
|
1408
|
+
}
|
|
1409
|
+
if (snapshot.structuralTransition) {
|
|
1410
|
+
protocolObject(snapshot.structuralTransition, 'snapshot.structuralTransition');
|
|
1411
|
+
protocolKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
|
|
1412
|
+
if (snapshot.structuralTransition.anchorKey !== undefined) protocolKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
|
|
1413
|
+
const duration = snapshot.structuralTransition.durationMs;
|
|
1414
|
+
if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
|
|
1415
|
+
}
|
|
1416
|
+
if (snapshot.theme?.successBackground !== undefined && (typeof snapshot.theme.successBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))) fail('theme.successBackground', 'must be a hex color');
|
|
1417
|
+
if (snapshot.theme?.rowHoverBackground !== undefined && (typeof snapshot.theme.rowHoverBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))) fail('theme.rowHoverBackground', 'must be a hex color');
|
|
1418
|
+
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
1419
|
+
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
1420
|
+
protocolObject(snapshot.layout, 'snapshot.layout');
|
|
1421
|
+
assertProtocolFields(snapshot.layout, 'snapshot.layout');
|
|
1422
|
+
if (snapshot.layout.orientation !== undefined && !['vertical', 'horizontal'].includes(snapshot.layout.orientation)) fail('snapshot.layout.orientation', 'is not supported');
|
|
1423
|
+
if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind)) fail('snapshot.layout.kind', 'is not supported');
|
|
1424
|
+
if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
|
|
1425
|
+
if (snapshot.layout.kind === 'grid' && (!Number.isInteger(snapshot.layout.gridColumns) || (snapshot.layout.gridColumns ?? 0) < 1 || (snapshot.layout.gridColumns ?? 0) > 7)) fail('snapshot.layout.gridColumns', 'must be an integer from 1 to 7');
|
|
1426
|
+
const keys = new Set();
|
|
1427
|
+
for (const [index, row] of snapshot.rows.entries()) {
|
|
1428
|
+
assertRowProtocol(row, `rows[${index}]`);
|
|
1429
|
+
if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
|
|
1430
|
+
keys.add(row.key);
|
|
1431
|
+
}
|
|
1432
|
+
if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
|
|
1433
|
+
if (snapshot.fixedFooter) assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
|
|
1434
|
+
if (snapshot.selection) {
|
|
1435
|
+
if (!Array.isArray(snapshot.selection.selectedKeys)) fail('snapshot.selection.selectedKeys', 'must be an array');
|
|
1436
|
+
snapshot.selection.selectedKeys.forEach(key => {
|
|
1437
|
+
if (!keys.has(key)) fail('snapshot.selection.selectedKeys', 'unknown row identity');
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
function isRecord(value) {
|
|
1442
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
1443
|
+
}
|
|
1444
|
+
function isAllowedImageUri(value) {
|
|
1445
|
+
// Keep native file, content, Photos and bundled-resource URIs alongside web images.
|
|
1446
|
+
// Android Release uses android.resource: instead of Metro's HTTP asset URLs.
|
|
1447
|
+
return typeof value === 'string' && value.trim().length > 0 && (!/^[a-z][a-z\d+.-]*:/i.test(value) || /^(https?|file|content|ph|assets-library|asset|res|android\.resource|blob|onekey-avatar):/i.test(value) || /^data:image\//i.test(value));
|
|
1448
|
+
}
|
|
1449
|
+
const IMAGE_FIELDS = ['uri', 'width', 'height', 'headers', 'contentFit', 'cachePolicy', 'autoplay', 'optimizeTos', 'overscan', 'loadingStrategy', 'fallbackUri', 'fallbackUris', 'retryTimes'];
|
|
1450
|
+
const ICON_FIELDS = ['name', 'tintColor', 'backgroundColor', 'size', 'accessibilityLabel', 'hoverActionKey'];
|
|
1451
|
+
const VISUAL_FIELDS = ['kind', 'name', 'image', 'images', 'networkImage', 'shape', 'tintColor', 'backgroundColor', 'fallbackIcon', 'fallbackText', 'fallbackTextColor', 'overlays', 'borderStyle', 'borderColor', 'cornerIcon'];
|
|
1452
|
+
const TEXT_STYLE_FIELDS = ['token', 'fontSize', 'fontWeight', 'color', 'lineHeight', 'lines', 'truncate', 'alignment', 'verticalAlignment', 'offsetY'];
|
|
1453
|
+
const ACCESSORY_FIELDS = {
|
|
1454
|
+
value: ['kind', 'text', 'secondary', 'textSegments'],
|
|
1455
|
+
valuePair: ['kind', 'primary', 'secondary', 'primaryFontWeight', 'primaryHelp', 'primaryTextSegments', 'secondaryTextSegments', 'primaryTone', 'secondaryTone'],
|
|
1456
|
+
button: ['kind', 'label', 'actionKey', 'disabled', 'testID', 'accessibilityLabel', 'textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor'],
|
|
1457
|
+
icon: ['kind', 'name', 'tintColor', 'buttonStyle', 'disabled', 'actionKey', 'testID', 'hoverActionKey', 'accessibilityLabel'],
|
|
1458
|
+
checkbox: ['kind', 'state', 'disabled', 'loading', 'target', 'actionKey'],
|
|
1459
|
+
radio: ['kind', 'checked', 'disabled', 'actionKey'],
|
|
1460
|
+
switch: ['kind', 'value', 'disabled', 'actionKey'],
|
|
1461
|
+
chevron: ['kind', 'actionKey'],
|
|
1462
|
+
menu: ['kind', 'actionKey'],
|
|
1463
|
+
drag: ['kind', 'actionKey'],
|
|
1464
|
+
spinner: ['kind'],
|
|
1465
|
+
progress: ['kind', 'value']
|
|
1466
|
+
};
|
|
1467
|
+
const REQUIRED_ROW_FIELDS = {
|
|
1468
|
+
identity: ['title', 'leading'],
|
|
1469
|
+
walletGroup: ['parent', 'children'],
|
|
1470
|
+
rail: ['title', 'visual'],
|
|
1471
|
+
activity: ['title', 'leading'],
|
|
1472
|
+
message: ['title', 'body', 'time'],
|
|
1473
|
+
dataRow: ['columns'],
|
|
1474
|
+
market: ['title', 'leading', 'variant', 'price', 'change'],
|
|
1475
|
+
mediaTile: ['title', 'variant'],
|
|
1476
|
+
metricCard: ['title', 'value'],
|
|
1477
|
+
sectionHeader: ['title', 'sectionKey'],
|
|
1478
|
+
action: ['title', 'actionKey'],
|
|
1479
|
+
buttonGroup: ['buttons'],
|
|
1480
|
+
system: ['variant']
|
|
1481
|
+
};
|
|
1482
|
+
function assertCoreRow(row, path) {
|
|
1483
|
+
const object = row;
|
|
1484
|
+
for (const key of REQUIRED_ROW_FIELDS[row.type]) {
|
|
1485
|
+
const value = object[key];
|
|
1486
|
+
if (value === undefined || value === null) fail(`${path}.${key}`, 'required field');
|
|
1487
|
+
if (['title', 'body', 'time', 'price', 'value', 'variant'].includes(key) && typeof value !== 'string') fail(`${path}.${key}`, 'must be a string');
|
|
1488
|
+
}
|
|
1489
|
+
if (row.type === 'market') {
|
|
1490
|
+
if (!row.price.trim()) fail(`${path}.price`, 'must be nonblank');
|
|
1491
|
+
if (typeof row.change?.text !== 'string') fail(`${path}.change.text`, 'must be a string');
|
|
1492
|
+
}
|
|
1493
|
+
if (row.type === 'activity') {
|
|
1494
|
+
row.amounts?.forEach((amount, index) => {
|
|
1495
|
+
protocolKey(amount.key, `${path}.amounts[${index}].key`);
|
|
1496
|
+
if (typeof amount.text !== 'string') fail(`${path}.amounts[${index}].text`, 'required financial text');
|
|
1497
|
+
});
|
|
1498
|
+
if (row.fee && typeof row.fee.primary !== 'string') fail(`${path}.fee.primary`, 'required financial text');
|
|
1499
|
+
row.footerActions?.forEach((action, index) => {
|
|
1500
|
+
protocolKey(action.key, `${path}.footerActions[${index}].key`);
|
|
1501
|
+
protocolKey(action.label, `${path}.footerActions[${index}].label`);
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
if (row.type === 'action') protocolKey(row.actionKey, `${path}.actionKey`);
|
|
1505
|
+
if (row.type === 'sectionHeader') protocolKey(row.sectionKey, `${path}.sectionKey`);
|
|
1506
|
+
if (row.type === 'system' && ['retry', 'warning', 'noMatch'].includes(row.variant)) {
|
|
1507
|
+
if (typeof object.message !== 'string') fail(`${path}.message`, 'must be a string');
|
|
1508
|
+
if (row.variant === 'retry') protocolKey(row.actionKey, `${path}.actionKey`);
|
|
1509
|
+
}
|
|
1510
|
+
if (row.type === 'dataRow') {
|
|
1511
|
+
if (!Array.isArray(row.columns) || row.columns.length === 0) fail(`${path}.columns`, 'required columns');
|
|
1512
|
+
row.columns.forEach((column, index) => {
|
|
1513
|
+
protocolObject(column, `${path}.columns[${index}]`);
|
|
1514
|
+
protocolKey(column.key, `${path}.columns[${index}].key`);
|
|
1515
|
+
if (typeof column.text !== 'string') fail(`${path}.columns[${index}].text`, 'must be a string');
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
if (row.type === 'buttonGroup') {
|
|
1519
|
+
if (!Array.isArray(row.buttons) || row.buttons.length === 0) fail(`${path}.buttons`, 'required buttons');
|
|
1520
|
+
const keys = new Set();
|
|
1521
|
+
row.buttons.forEach((button, index) => {
|
|
1522
|
+
const field = `${path}.buttons[${index}]`;
|
|
1523
|
+
protocolObject(button, field);
|
|
1524
|
+
protocolKey(button.key, `${field}.key`);
|
|
1525
|
+
protocolKey(button.actionKey, `${field}.actionKey`);
|
|
1526
|
+
protocolKey(button.label, `${field}.label`);
|
|
1527
|
+
if (keys.has(button.key)) fail(field, 'duplicate button identity');
|
|
1528
|
+
keys.add(button.key);
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
for (const field of ['trailing', 'leadingAction', 'titleIcon', 'valueIcon']) {
|
|
1532
|
+
const value = object[field];
|
|
1533
|
+
if (value === undefined) continue;
|
|
1534
|
+
// Identity title icons are decorative descriptors, not trailing controls.
|
|
1535
|
+
if (field === 'titleIcon' && row.type !== 'sectionHeader') continue;
|
|
1536
|
+
const accessories = field === 'trailing' ? value : [value];
|
|
1537
|
+
if (!Array.isArray(accessories)) fail(`${path}.${field}`, 'must be an array');
|
|
1538
|
+
accessories.forEach((accessory, index) => {
|
|
1539
|
+
const entry = protocolObject(accessory, `${path}.${field}[${index}]`);
|
|
1540
|
+
for (const key of entry.kind === 'value' ? ['text'] : entry.kind === 'valuePair' ? ['primary', 'secondary'] : []) {
|
|
1541
|
+
if (typeof entry[key] !== 'string') fail(`${path}.${field}[${index}].${key}`, 'required financial text');
|
|
1542
|
+
}
|
|
1543
|
+
if (['button', 'menu', 'switch'].includes(entry.kind) || 'actionKey' in entry) {
|
|
1544
|
+
protocolKey(entry.actionKey, `${path}.${field}[${index}].actionKey`);
|
|
1545
|
+
if (entry.kind === 'button') protocolKey(entry.label, `${path}.${field}[${index}].label`);
|
|
1546
|
+
}
|
|
1547
|
+
if (entry.kind === 'icon') protocolKey(entry.name, `${path}.${field}[${index}].name`);
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
function pickFields(object, fields) {
|
|
1552
|
+
return Object.fromEntries(Object.entries(object).filter(([key]) => fields.includes(key)));
|
|
1553
|
+
}
|
|
1554
|
+
function sanitizeImage(value) {
|
|
1555
|
+
if (!isRecord(value) || !isAllowedImageUri(value.uri) || typeof value.width !== 'number' || !Number.isFinite(value.width) || value.width <= 0 || typeof value.height !== 'number' || !Number.isFinite(value.height) || value.height <= 0) return undefined;
|
|
1556
|
+
const next = pickFields(value, IMAGE_FIELDS);
|
|
1557
|
+
next.width = Math.min(MAX_IMAGE_EDGE, value.width);
|
|
1558
|
+
next.height = Math.min(MAX_IMAGE_EDGE, value.height);
|
|
1559
|
+
if (next.headers !== undefined) {
|
|
1560
|
+
if (!isRecord(next.headers)) delete next.headers;else next.headers = Object.fromEntries(Object.entries(next.headers).filter(([key, item]) => key.trim() && key.length <= MAX_HEADER_LENGTH && typeof item === 'string' && item.length <= MAX_HEADER_LENGTH).slice(0, MAX_IMAGE_HEADERS));
|
|
1561
|
+
}
|
|
1562
|
+
if (next.fallbackUris !== undefined) {
|
|
1563
|
+
if (Array.isArray(next.fallbackUris)) next.fallbackUris = next.fallbackUris.filter(isAllowedImageUri);else delete next.fallbackUris;
|
|
1564
|
+
}
|
|
1565
|
+
if (next.fallbackUri !== undefined && !isAllowedImageUri(next.fallbackUri)) delete next.fallbackUri;
|
|
1566
|
+
if (next.overscan !== undefined && (typeof next.overscan !== 'number' || !Number.isFinite(next.overscan) || next.overscan < 1 || next.overscan > 4)) delete next.overscan;
|
|
1567
|
+
if (next.retryTimes !== undefined && (typeof next.retryTimes !== 'number' || !Number.isFinite(next.retryTimes) || next.retryTimes < 0)) delete next.retryTimes;
|
|
1568
|
+
const options = {
|
|
1569
|
+
contentFit: ['cover', 'contain', 'fill', 'center'],
|
|
1570
|
+
cachePolicy: ['memory-disk', 'memory', 'disk', 'none'],
|
|
1571
|
+
loadingStrategy: ['static', 'skeleton', 'none']
|
|
1572
|
+
};
|
|
1573
|
+
for (const [key, allowed] of Object.entries(options)) if (next[key] !== undefined && !allowed.includes(next[key])) delete next[key];
|
|
1574
|
+
for (const key of ['autoplay', 'optimizeTos']) if (next[key] !== undefined && typeof next[key] !== 'boolean') delete next[key];
|
|
1575
|
+
return next;
|
|
1576
|
+
}
|
|
1577
|
+
const NESTED_DECORATION_FIELDS = {
|
|
1578
|
+
webTable: ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'],
|
|
1579
|
+
columns: ['key', 'text', 'textSegments', 'titleIcon', 'secondaryTitleIcon', 'secondaryLeadingText', 'secondaryText', 'secondaryTextSegments', 'weight', 'alignment', 'tone', 'secondaryTone', 'width', 'minWidth', 'flex', 'paddingStart', 'paddingEnd'],
|
|
1580
|
+
cells: ['key', 'kind', 'active', 'disabled', 'testID', 'hoverActionKey', 'actionKey', 'accessibilityLabel', 'leading', 'title', 'secondary', 'lineGap', 'secondaryBadges', 'hoverImages', 'hoverSecondary', 'hoverActionLabel', 'badges', 'primary', 'partGap', 'points', 'width', 'height', 'strokeColor', 'fillColor'],
|
|
1581
|
+
badges: ['key', 'text', 'tone', 'iconName', 'icon', 'textColor', 'backgroundColor', 'actionKey', 'accessibilityLabel', 'style'],
|
|
1582
|
+
overlays: ['position', 'size', 'width', 'height', 'padding', 'offset', 'offsetX', 'offsetY', 'image', 'fallbackIcon', 'name', 'text', 'fontWeight', 'tintColor', 'backgroundColor'],
|
|
1583
|
+
primaryHelp: ['actionKey', 'presentation', 'underline'],
|
|
1584
|
+
valueHelp: ['actionKey', 'presentation', 'underline']
|
|
1585
|
+
};
|
|
1586
|
+
function sanitizeDecoration(value, field) {
|
|
1587
|
+
if (value === undefined || value === null) return undefined;
|
|
1588
|
+
if (!Array.isArray(value) && ['image', 'networkImage', 'thumbnail', 'source', 'images', 'hoverImages'].includes(field)) return sanitizeImage(value);
|
|
1589
|
+
if (['titleImage', 'titleIcon', 'secondaryTitleIcon', 'fallbackIcon', 'cornerIcon', 'media'].includes(field) && !isRecord(value)) return undefined;
|
|
1590
|
+
if (field === 'style' && typeof value !== 'string' && !isRecord(value)) return undefined;
|
|
1591
|
+
if (['badges', 'overlays'].includes(field) && !Array.isArray(value) && !isRecord(value)) return undefined;
|
|
1592
|
+
if (field === 'style' && typeof value === 'string') return value === 'subscript' ? value : undefined;
|
|
1593
|
+
if (Array.isArray(value)) {
|
|
1594
|
+
const items = value.map(item => sanitizeDecoration(item, field));
|
|
1595
|
+
return field === 'hoverImages' ? items.map(item => item ?? null) : items.filter(item => item !== undefined);
|
|
1596
|
+
}
|
|
1597
|
+
if (!isRecord(value)) return value;
|
|
1598
|
+
let object = value;
|
|
1599
|
+
if (field === 'titleImage') {
|
|
1600
|
+
const image = sanitizeImage(value.image);
|
|
1601
|
+
if (!image) return undefined;
|
|
1602
|
+
const edge = Math.min(40, Math.max(1, Math.round(Math.min(image.width, image.height))));
|
|
1603
|
+
object = {
|
|
1604
|
+
...pickFields(value, ['image', 'accessibilityLabel', 'hoverActionKey']),
|
|
1605
|
+
image: {
|
|
1606
|
+
...image,
|
|
1607
|
+
width: edge,
|
|
1608
|
+
height: edge
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
} else if (['titleIcon', 'secondaryTitleIcon', 'fallbackIcon', 'cornerIcon'].includes(field) && value.kind === undefined) {
|
|
1612
|
+
if (typeof value.name !== 'string' || !value.name.trim()) return undefined;
|
|
1613
|
+
object = pickFields(value, ICON_FIELDS);
|
|
1614
|
+
} else if (['leading', 'visual', 'secondaryLeading'].includes(field)) {
|
|
1615
|
+
object = pickFields(value, VISUAL_FIELDS);
|
|
1616
|
+
} else if (field === 'media') {
|
|
1617
|
+
object = pickFields(value, ['source', 'probeOrder']);
|
|
1618
|
+
}
|
|
1619
|
+
if (field === 'trailing' || ['leadingAction', 'titleIcon', 'valueIcon'].includes(field) && object.kind !== undefined) {
|
|
1620
|
+
const fields = ACCESSORY_FIELDS[object.kind];
|
|
1621
|
+
if (fields) object = pickFields(object, fields);
|
|
1622
|
+
} else if (field === 'buttons') object = pickFields(object, ['key', 'label', 'actionKey', 'disabled', 'loading', 'testID', 'accessibilityLabel']);else if (field === 'container') object = pickFields(object, ['height', 'backgroundColor', 'opacity', 'cornerRadius', 'borderWidth', 'borderColor', 'contentVerticalAlignment']);else if (field === 'imageStyle') object = pickFields(object, ['width', 'height', 'shape', 'cornerRadius', 'contentFit']);else if (field === 'style') object = pickFields(object, [...TEXT_STYLE_FIELDS, 'container', ...new Set(Object.values(ROW_BOX_STYLE_KEYS_BY_TYPE).flat()), ...new Set(Object.values(TEXT_STYLE_KEYS_BY_ROW_TYPE).flat()), ...new Set(Object.values(EXTRA_STYLE_KEYS_BY_ROW_TYPE).flat()), 'height']);else if (['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'change', 'value', 'valueSecondary', 'columnSecondary', 'primaryAmount', 'secondaryAmount', 'description', 'status', 'trend', 'message', 'actionText'].includes(field) && !('text' in object)) {
|
|
1623
|
+
object = pickFields(object, TEXT_STYLE_FIELDS);
|
|
1624
|
+
}
|
|
1625
|
+
if (NESTED_DECORATION_FIELDS[field]) object = pickFields(object, NESTED_DECORATION_FIELDS[field]);
|
|
1626
|
+
if (['textSegments', 'primaryTextSegments', 'secondaryTextSegments', 'priceSegments', 'segments'].includes(field)) object = pickFields(object, ['text', 'style']);
|
|
1627
|
+
if (field === 'subtitleSegments') object = pickFields(object, ['text', 'style', 'textSegments', 'tone', 'separatorBefore']);
|
|
1628
|
+
const styleObject = ['style', 'imageStyle', 'container'].includes(field) || TEXT_STYLE_FIELDS.some(key => key in object);
|
|
1629
|
+
const next = {};
|
|
1630
|
+
for (const [key, item] of Object.entries(object)) {
|
|
1631
|
+
if (item === undefined || item === null) continue;
|
|
1632
|
+
if ((/color$/i.test(key) || /background$/i.test(key)) && (typeof item !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(item))) continue;
|
|
1633
|
+
if (/TextSegments$/.test(key) || ['textSegments', 'priceSegments', 'subtitleSegments', 'segments'].includes(key)) {
|
|
1634
|
+
if (!Array.isArray(item) || item.some(segment => !isRecord(segment) || typeof segment.text !== 'string')) continue;
|
|
1635
|
+
}
|
|
1636
|
+
if (styleObject && PROTOCOL_NUMBER_FIELDS.has(key) && typeof item !== 'number') continue;
|
|
1637
|
+
if (key === 'token' && (typeof item !== 'string' || !Object.hasOwn(TYPOGRAPHY_TOKENS, item))) continue;
|
|
1638
|
+
if (key === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) continue;
|
|
1639
|
+
if (['disabled', 'loading', 'checked', 'selected', 'separator', 'hideLeading', 'pressDisabled', 'draggable', 'active', 'autoplay'].includes(key) && typeof item !== 'boolean') continue;
|
|
1640
|
+
if (key === 'primaryFontWeight' && item !== 'medium') continue;
|
|
1641
|
+
if (key === 'buttonStyle' && item !== 'tertiary') continue;
|
|
1642
|
+
if (key === 'hoverActionKey' && (typeof item !== 'string' || !item.trim())) continue;
|
|
1643
|
+
if (key === 'accessibilityLabel' && typeof item !== 'string') continue;
|
|
1644
|
+
if ((field === 'style' || PROTOCOL_NUMBER_FIELDS.has(key)) && typeof item !== 'object' && typeof item === 'number' && (!Number.isFinite(item) || item < 0 && !['offsetX', 'offsetY'].includes(key))) continue;
|
|
1645
|
+
if (field === 'style' && PROTOCOL_NUMBER_FIELDS.has(key) && typeof item !== 'number') continue;
|
|
1646
|
+
if (key === 'leadingContentMaxWidthRatio' && (typeof item !== 'number' || item <= 0 || item > 1)) continue;
|
|
1647
|
+
const normalized = sanitizeDecoration(item, field === 'style' && key === 'image' ? 'imageStyle' : key);
|
|
1648
|
+
if (normalized !== undefined) next[key] = normalized;
|
|
1649
|
+
}
|
|
1650
|
+
if (field === 'titleImage') {
|
|
1651
|
+
// The nested image was already normalized with title-specific geometry.
|
|
1652
|
+
if (!next.image) return undefined;
|
|
1653
|
+
}
|
|
1654
|
+
if (field === 'media' && (!next.source || !Array.isArray(next.probeOrder))) return undefined;
|
|
1655
|
+
if (['leading', 'visual', 'secondaryLeading'].includes(field)) {
|
|
1656
|
+
if (next.kind === 'image' && !next.image) return {
|
|
1657
|
+
kind: 'token',
|
|
1658
|
+
...pickFields(next, ['fallbackIcon', 'fallbackText', 'fallbackTextColor'])
|
|
1659
|
+
};
|
|
1660
|
+
if (next.kind === 'stackedImages' && (!Array.isArray(next.images) || next.images.length < 2)) return {
|
|
1661
|
+
kind: 'token'
|
|
1662
|
+
};
|
|
1663
|
+
if (next.kind === 'icon' && (typeof next.name !== 'string' || !next.name.trim())) return {
|
|
1664
|
+
kind: 'token'
|
|
1665
|
+
};
|
|
1666
|
+
if (!['token', 'account', 'wallet', 'network', 'image', 'icon', 'stackedImages'].includes(next.kind)) return {
|
|
1667
|
+
kind: 'token'
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
if (field === 'overlays' && (!['topLeft', 'bottomRight'].includes(next.position) || !next.image && !next.name && !next.text)) return undefined;
|
|
1671
|
+
if (field === 'trailing' && next.kind === 'icon' && !('actionKey' in value) && (typeof next.name !== 'string' || !next.name.trim())) return undefined;
|
|
1672
|
+
if (field === 'trailing' && !['value', 'valuePair', 'button', 'checkbox', 'radio', 'switch', 'chevron', 'menu', 'drag', 'icon', 'spinner', 'progress'].includes(next.kind) && !('actionKey' in value)) return undefined;
|
|
1673
|
+
if (field === 'badges' && (typeof next.key !== 'string' || !next.text && !next.iconName && !next.icon)) return undefined;
|
|
1674
|
+
if (next.kind === 'sparkline') {
|
|
1675
|
+
const points = Array.isArray(value.points) ? value.points.filter(point => typeof point === 'number' && Number.isFinite(point)).slice(0, 256) : [];
|
|
1676
|
+
// Preserve the table's column identity even when its optional drawing fails.
|
|
1677
|
+
return points.length < 2 ? {
|
|
1678
|
+
key: next.key,
|
|
1679
|
+
kind: 'text',
|
|
1680
|
+
primary: []
|
|
1681
|
+
} : {
|
|
1682
|
+
...next,
|
|
1683
|
+
points
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
return next;
|
|
1687
|
+
}
|
|
1688
|
+
function sanitizeMarketMetrics(value) {
|
|
1689
|
+
if (!Array.isArray(value)) return value;
|
|
1690
|
+
return value.map(metric => {
|
|
1691
|
+
const next = pickFields(metric, MARKET_METRIC_FIELDS);
|
|
1692
|
+
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
1693
|
+
if (next[field] !== undefined) next[field] = sanitizeDecoration(next[field], field);
|
|
1694
|
+
}
|
|
1695
|
+
return next;
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
function sanitizeRowForProduction(row) {
|
|
1699
|
+
const object = protocolObject(row, 'row');
|
|
1700
|
+
const fields = ROW_FIELDS[row.type];
|
|
1701
|
+
if (!fields) return row;
|
|
1702
|
+
const next = pickFields(object, fields);
|
|
1703
|
+
for (const [field, value] of Object.entries(next)) {
|
|
1704
|
+
if ((/color$/i.test(field) || /background$/i.test(field)) && (typeof value !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))) {
|
|
1705
|
+
delete next[field];
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
if (field === 'parent' && isRecord(value)) next[field] = sanitizeRowForProduction(value);else if (field === 'children' && Array.isArray(value)) next[field] = value.map(child => sanitizeRowForProduction(child));else {
|
|
1709
|
+
const normalized = row.type === 'market' && field === 'metrics' ? sanitizeMarketMetrics(value) : sanitizeDecoration(value, field);
|
|
1710
|
+
if (normalized === undefined) delete next[field];else next[field] = normalized;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
if (isRecord(next.style)) next.style = pickFields(next.style, ['container', ...ROW_BOX_STYLE_KEYS_BY_TYPE[row.type], ...(TEXT_STYLE_KEYS_BY_ROW_TYPE[row.type] ?? []), ...(EXTRA_STYLE_KEYS_BY_ROW_TYPE[row.type] ?? [])]);
|
|
1714
|
+
return sameJsonValue(row, next) ? row : next;
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
/** Empty images and optional nulls share one meaning before strict assertions. */
|
|
1718
|
+
function normalizeEmptyImages(value, field = '') {
|
|
1719
|
+
if (value === null || value === undefined || typeof value !== 'object') return value;
|
|
1720
|
+
if (Array.isArray(value)) {
|
|
1721
|
+
const next = value.map(item => normalizeEmptyImages(item, field));
|
|
1722
|
+
return next.every((item, index) => item === value[index]) ? value : next.filter(item => item !== undefined);
|
|
1723
|
+
}
|
|
1724
|
+
const object = value;
|
|
1725
|
+
if (typeof object.uri === 'string' && !object.uri.trim() && 'width' in object && 'height' in object) return undefined;
|
|
1726
|
+
let changed = false;
|
|
1727
|
+
const next = {};
|
|
1728
|
+
for (const [key, item] of Object.entries(object)) {
|
|
1729
|
+
const optional = object.type && !['key', 'type', ...(REQUIRED_ROW_FIELDS[object.type] ?? [])].includes(key);
|
|
1730
|
+
if (item === undefined || item === null && optional && !(object.type === 'market' && key === 'metrics') || ['priceSegments', 'subtitleSegments'].includes(key) && Array.isArray(item) && item.length === 0) {
|
|
1731
|
+
changed = true;
|
|
1732
|
+
continue;
|
|
1733
|
+
}
|
|
1734
|
+
const normalized = field === 'headers' ? item : normalizeEmptyImages(item, key);
|
|
1735
|
+
if (normalized !== undefined) next[key] = normalized;
|
|
1736
|
+
if (normalized !== item) changed = true;
|
|
1737
|
+
}
|
|
1738
|
+
if (field === 'media' && object.source !== undefined && next.source === undefined || field === 'titleImage' && object.image !== undefined && next.image === undefined) return undefined;
|
|
1739
|
+
if (['leading', 'visual', 'secondaryLeading'].includes(field) && next.kind === 'image' && !next.image) return {
|
|
1740
|
+
kind: 'token'
|
|
1741
|
+
};
|
|
1742
|
+
if (field === 'overlays' && object.image !== undefined && !next.image) return undefined;
|
|
1743
|
+
return changed ? next : value;
|
|
1744
|
+
}
|
|
1745
|
+
function normalizeSnapshotForProduction(snapshot) {
|
|
1746
|
+
if (!Array.isArray(snapshot.rows)) return snapshot;
|
|
1747
|
+
let rows = snapshot.rows.map(sanitizeRowForProduction);
|
|
1748
|
+
rows = rows.map((row, index) => {
|
|
1749
|
+
if (!row.groupId) return row;
|
|
1750
|
+
const previous = rows[index - 1]?.groupId === row.groupId;
|
|
1751
|
+
const following = rows[index + 1]?.groupId === row.groupId;
|
|
1752
|
+
return {
|
|
1753
|
+
...row,
|
|
1754
|
+
groupPosition: previous ? following ? 'middle' : 'last' : following ? 'first' : 'single'
|
|
1755
|
+
};
|
|
1756
|
+
});
|
|
1757
|
+
const next = {
|
|
1758
|
+
...snapshot,
|
|
1759
|
+
rows,
|
|
1760
|
+
...(snapshot.emptyState ? {
|
|
1761
|
+
emptyState: sanitizeRowForProduction(snapshot.emptyState)
|
|
1762
|
+
} : {}),
|
|
1763
|
+
...(snapshot.fixedFooter ? {
|
|
1764
|
+
fixedFooter: sanitizeRowForProduction(snapshot.fixedFooter)
|
|
1765
|
+
} : {})
|
|
1766
|
+
};
|
|
1767
|
+
if (snapshot.theme) next.theme = sanitizeDecoration(snapshot.theme, 'theme');
|
|
1768
|
+
if (snapshot.listStyle) next.listStyle = sanitizeDecoration(snapshot.listStyle, 'style');
|
|
1769
|
+
if (snapshot.selection && Array.isArray(snapshot.selection.selectedKeys)) {
|
|
1770
|
+
const selectable = new Set(rows.filter(row => !row.disabled && !['sectionHeader', 'action', 'system', 'buttonGroup', 'market', 'walletGroup'].includes(row.type)).map(row => row.key));
|
|
1771
|
+
const selectedKeys = [...new Set(snapshot.selection.selectedKeys.filter(key => selectable.has(key)))];
|
|
1772
|
+
next.selection = {
|
|
1773
|
+
...snapshot.selection,
|
|
1774
|
+
selectedKeys: snapshot.selection.mode === 'none' ? [] : snapshot.selection.mode === 'single' ? selectedKeys.slice(0, 1) : selectedKeys
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1777
|
+
return sameJsonValue(snapshot, next) ? snapshot : next;
|
|
1778
|
+
}
|
|
1779
|
+
export function validateSnapshot(snapshot) {
|
|
1780
|
+
assertPlainSerializable(snapshot, 'snapshot', new Set(), false);
|
|
1781
|
+
protocolObject(snapshot, 'snapshot');
|
|
1782
|
+
const normalized = normalizeEmptyImages(snapshot);
|
|
1783
|
+
if (Array.isArray(normalized.rows)) {
|
|
1784
|
+
normalized.rows.forEach((row, index) => {
|
|
1785
|
+
if (row.type === 'market') assertMarketMetrics(row.metrics, `snapshot.rows[${index}].metrics`);
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
const canonical = isDevelopment() ? normalized : normalizeSnapshotForProduction(normalized);
|
|
1789
|
+
assertPlainSerializable(canonical, 'snapshot', new Set());
|
|
1790
|
+
if (isDevelopment()) assertSnapshotContract(canonical);
|
|
1791
|
+
assertSnapshotProtocol(canonical);
|
|
1792
|
+
return normalizeSnapshotStyles(canonical);
|
|
1793
|
+
}
|
|
1794
|
+
const ownedNativeSnapshots = new WeakMap();
|
|
1795
|
+
function capturePlainData(value, seen = new Map()) {
|
|
1796
|
+
if (value === null || typeof value !== 'object') return value;
|
|
1797
|
+
const previous = seen.get(value);
|
|
1798
|
+
if (previous) return previous;
|
|
1799
|
+
const copy = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
|
|
1800
|
+
seen.set(value, copy);
|
|
1801
|
+
const captureKey = key => {
|
|
1802
|
+
Object.defineProperty(copy, key, {
|
|
1803
|
+
value: capturePlainData(value[key], seen),
|
|
1804
|
+
enumerable: true,
|
|
1805
|
+
writable: true,
|
|
1806
|
+
configurable: true
|
|
1807
|
+
});
|
|
1808
|
+
};
|
|
1809
|
+
if (Array.isArray(value)) {
|
|
1810
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1811
|
+
if (index in value) captureKey(String(index));
|
|
1812
|
+
}
|
|
1813
|
+
Object.keys(value).forEach(key => {
|
|
1814
|
+
const index = Number(key);
|
|
1815
|
+
if (Number.isInteger(index) && index >= 0 && index < value.length && String(index) === key) return;
|
|
1816
|
+
captureKey(key);
|
|
1817
|
+
});
|
|
1818
|
+
} else {
|
|
1819
|
+
Object.keys(value).forEach(captureKey);
|
|
1820
|
+
}
|
|
1821
|
+
return copy;
|
|
1822
|
+
}
|
|
1823
|
+
function deepFreeze(value, seen = new WeakSet()) {
|
|
1824
|
+
if (value === null || typeof value !== 'object' || seen.has(value)) return value;
|
|
1825
|
+
seen.add(value);
|
|
1826
|
+
Object.values(value).forEach(item => deepFreeze(item, seen));
|
|
1827
|
+
return Object.freeze(value);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
/** Capture caller data once before validation, including accessor values. */
|
|
1831
|
+
export function captureNativeListInput(value) {
|
|
1832
|
+
return capturePlainData(value);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
/** Private native-wrapper ownership; exported validators keep their public identity. */
|
|
1836
|
+
export function ownValidatedNativeSnapshot(snapshot) {
|
|
1837
|
+
const owned = deepFreeze(snapshot);
|
|
1838
|
+
ownedNativeSnapshots.set(owned, new Map(owned.rows.map((row, index) => [row.key, index])));
|
|
1839
|
+
return owned;
|
|
982
1840
|
}
|
|
983
1841
|
|
|
984
1842
|
/**
|
|
@@ -1000,8 +1858,12 @@ function normalizeSnapshotStyles(snapshot) {
|
|
|
1000
1858
|
return {
|
|
1001
1859
|
...snapshot,
|
|
1002
1860
|
rows,
|
|
1003
|
-
emptyState
|
|
1004
|
-
|
|
1861
|
+
...(emptyState !== undefined ? {
|
|
1862
|
+
emptyState
|
|
1863
|
+
} : {}),
|
|
1864
|
+
...(fixedFooter !== undefined ? {
|
|
1865
|
+
fixedFooter
|
|
1866
|
+
} : {})
|
|
1005
1867
|
};
|
|
1006
1868
|
}
|
|
1007
1869
|
function assertPatchChanges(patch, index) {
|
|
@@ -1024,7 +1886,23 @@ function assertPatchChanges(patch, index) {
|
|
|
1024
1886
|
}
|
|
1025
1887
|
switch (patch.type) {
|
|
1026
1888
|
case 'identity':
|
|
1889
|
+
if (patch.changes.contentHeight !== undefined && patch.changes.contentHeight !== 'auto') {
|
|
1890
|
+
fail(`${path}.contentHeight`, 'must be auto');
|
|
1891
|
+
}
|
|
1892
|
+
if (patch.changes.subtitleLines !== undefined && ![0, 1, 2].includes(patch.changes.subtitleLines)) {
|
|
1893
|
+
fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
|
|
1894
|
+
}
|
|
1895
|
+
if (patch.changes.longPressActionKey !== undefined) {
|
|
1896
|
+
assertKey(patch.changes.longPressActionKey, `${path}.longPressActionKey`);
|
|
1897
|
+
}
|
|
1027
1898
|
assertText(patch.changes.title, `${path}.title`);
|
|
1899
|
+
if ((patch.changes.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
|
|
1900
|
+
patch.changes.titleSuffixes?.forEach((suffix, index) => {
|
|
1901
|
+
assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
|
|
1902
|
+
if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
|
|
1903
|
+
if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
|
|
1904
|
+
});
|
|
1905
|
+
assertIdentityExtras(patch.changes, path);
|
|
1028
1906
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
1029
1907
|
assertText(patch.changes.tertiary, `${path}.tertiary`);
|
|
1030
1908
|
if (patch.changes.tertiaryTone !== undefined && !['secondary', 'info'].includes(patch.changes.tertiaryTone)) {
|
|
@@ -1058,11 +1936,14 @@ function assertPatchChanges(patch, index) {
|
|
|
1058
1936
|
}
|
|
1059
1937
|
break;
|
|
1060
1938
|
case 'message':
|
|
1939
|
+
if (patch.changes.presentation !== undefined && patch.changes.presentation !== 'inlineWarning') {
|
|
1940
|
+
fail(`${path}.presentation`, 'must be inlineWarning');
|
|
1941
|
+
}
|
|
1061
1942
|
assertText(patch.changes.title, `${path}.title`);
|
|
1062
1943
|
assertText(patch.changes.body, `${path}.body`);
|
|
1063
1944
|
assertText(patch.changes.time, `${path}.time`);
|
|
1064
|
-
if (patch.changes.bodyLines !== undefined && ![1, 2, 3].includes(patch.changes.bodyLines)) {
|
|
1065
|
-
fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
|
|
1945
|
+
if (patch.changes.bodyLines !== undefined && ![0, 1, 2, 3].includes(patch.changes.bodyLines)) {
|
|
1946
|
+
fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
|
|
1066
1947
|
}
|
|
1067
1948
|
assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
|
|
1068
1949
|
break;
|
|
@@ -1073,12 +1954,23 @@ function assertPatchChanges(patch, index) {
|
|
|
1073
1954
|
patch.changes.columns?.forEach((column, columnIndex) => {
|
|
1074
1955
|
assertKey(column.key, `${path}.columns[${columnIndex}].key`);
|
|
1075
1956
|
assertText(column.text, `${path}.columns[${columnIndex}].text`);
|
|
1957
|
+
assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
|
|
1958
|
+
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
1959
|
+
column[field]?.forEach((segment, segmentIndex) => {
|
|
1960
|
+
assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
|
|
1961
|
+
if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1076
1964
|
assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
|
|
1077
1965
|
assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
|
|
1078
1966
|
});
|
|
1079
1967
|
if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
|
|
1080
1968
|
fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
|
|
1081
1969
|
}
|
|
1970
|
+
if ((patch.changes.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
|
|
1971
|
+
fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
|
|
1972
|
+
}
|
|
1973
|
+
assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
|
|
1082
1974
|
break;
|
|
1083
1975
|
case 'market':
|
|
1084
1976
|
assertMarketRow({
|
|
@@ -1137,6 +2029,11 @@ function assertPatchChanges(patch, index) {
|
|
|
1137
2029
|
assertText(patch.changes.title, `${path}.title`);
|
|
1138
2030
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
1139
2031
|
assertText(patch.changes.value, `${path}.value`);
|
|
2032
|
+
if (patch.changes.leadingBadge) {
|
|
2033
|
+
assertKey(patch.changes.leadingBadge.key, `${path}.leadingBadge.key`);
|
|
2034
|
+
assertText(patch.changes.leadingBadge.text, `${path}.leadingBadge.text`);
|
|
2035
|
+
}
|
|
2036
|
+
assertTextHelp(patch.changes.valueHelp, `${path}.valueHelp`);
|
|
1140
2037
|
if (patch.changes.valueActionKey !== undefined) {
|
|
1141
2038
|
assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
|
|
1142
2039
|
}
|
|
@@ -1150,6 +2047,11 @@ function assertPatchChanges(patch, index) {
|
|
|
1150
2047
|
}
|
|
1151
2048
|
assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
|
|
1152
2049
|
break;
|
|
2050
|
+
case 'buttonGroup':
|
|
2051
|
+
if (patch.changes.buttons !== undefined) assertButtonGroup({
|
|
2052
|
+
buttons: patch.changes.buttons
|
|
2053
|
+
}, path);
|
|
2054
|
+
break;
|
|
1153
2055
|
case 'system':
|
|
1154
2056
|
assertText(patch.changes.message, `${path}.message`);
|
|
1155
2057
|
break;
|
|
@@ -1157,19 +2059,119 @@ function assertPatchChanges(patch, index) {
|
|
|
1157
2059
|
fail(`patches[${index}].type`, 'is not supported');
|
|
1158
2060
|
}
|
|
1159
2061
|
}
|
|
2062
|
+
function normalizePatch(patch, index) {
|
|
2063
|
+
const path = `patches[${index}]`;
|
|
2064
|
+
protocolObject(patch, path);
|
|
2065
|
+
protocolKey(patch.key, `${path}.key`);
|
|
2066
|
+
if (isDevelopment()) assertKey(patch.key, `${path}.key`);
|
|
2067
|
+
assertRowType(patch.type, path);
|
|
2068
|
+
const raw = protocolObject(patch.changes, `${path}.changes`);
|
|
2069
|
+
assertPlainSerializable(raw, `${path}.changes`, new Set(), false);
|
|
2070
|
+
const fields = PATCH_FIELDS[patch.type];
|
|
2071
|
+
const changes = {};
|
|
2072
|
+
for (const [field, value] of Object.entries(raw)) {
|
|
2073
|
+
if (value === undefined) continue;
|
|
2074
|
+
if (!fields?.includes(field)) {
|
|
2075
|
+
if (isDevelopment()) fail(`${path}.changes.${field}`, 'unsupported patch field');
|
|
2076
|
+
continue;
|
|
2077
|
+
}
|
|
2078
|
+
if (value === null) {
|
|
2079
|
+
if (patch.type === 'market' && field === 'metrics') fail(`${path}.changes.metrics`, 'use a full snapshot to remove metrics');
|
|
2080
|
+
if (REQUIRED_ROW_FIELDS[patch.type].includes(field) || patch.type === 'system' && field === 'message') {
|
|
2081
|
+
// The concrete system variant is checked after merging with its baseline.
|
|
2082
|
+
if (patch.type !== 'system') fail(`${path}.changes.${field}`, 'required field cannot be cleared');
|
|
2083
|
+
}
|
|
2084
|
+
changes[field] = null;
|
|
2085
|
+
continue;
|
|
2086
|
+
}
|
|
2087
|
+
if (patch.type === 'market' && field === 'metrics') assertMarketMetrics(value, `${path}.changes.metrics`);
|
|
2088
|
+
if (['priceSegments', 'subtitleSegments'].includes(field) && Array.isArray(value) && value.length === 0) {
|
|
2089
|
+
changes[field] = null;
|
|
2090
|
+
continue;
|
|
2091
|
+
}
|
|
2092
|
+
const normalized = normalizeEmptyImages(value, field);
|
|
2093
|
+
if (normalized === undefined) {
|
|
2094
|
+
if (!REQUIRED_ROW_FIELDS[patch.type].includes(field)) changes[field] = null;
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
const canonical = isDevelopment() ? normalized : patch.type === 'market' && field === 'metrics' ? sanitizeMarketMetrics(normalized) : sanitizeDecoration(normalized, field);
|
|
2098
|
+
if (canonical !== undefined) changes[field] = canonical;else if (field === 'titleImage') changes[field] = null;
|
|
2099
|
+
}
|
|
2100
|
+
if (patch.type === 'market' && Array.isArray(changes.priceSegments) && changes.priceSegments.length > 0 && (typeof changes.price !== 'string' || !changes.price.trim())) fail(`${path}.changes.price`, 'is required when priceSegments is updated');
|
|
2101
|
+
if (!isDevelopment()) {
|
|
2102
|
+
const sanitized = sanitizeRowForProduction({
|
|
2103
|
+
type: patch.type,
|
|
2104
|
+
...changes
|
|
2105
|
+
});
|
|
2106
|
+
for (const [field, value] of Object.entries(changes)) {
|
|
2107
|
+
if (value === null) continue;
|
|
2108
|
+
if (sanitized[field] === undefined) delete changes[field];else changes[field] = sanitized[field];
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
const values = Object.fromEntries(Object.entries(changes).filter(([, value]) => value !== null));
|
|
2112
|
+
if (patch.type === 'market' && 'metrics' in changes) assertMarketMetrics(changes.metrics, `${path}.changes.metrics`);
|
|
2113
|
+
assertPlainSerializable(values, `${path}.changes`, new Set());
|
|
2114
|
+
assertProtocolFields(values, `${path}.changes`);
|
|
2115
|
+
if (isDevelopment()) assertPatchChanges({
|
|
2116
|
+
...patch,
|
|
2117
|
+
changes: values
|
|
2118
|
+
}, index);
|
|
2119
|
+
const normalizedPatch = {
|
|
2120
|
+
type: patch.type,
|
|
2121
|
+
key: patch.key,
|
|
2122
|
+
changes
|
|
2123
|
+
};
|
|
2124
|
+
return Object.keys(changes).length > 0 ? normalizePatchStyles([normalizedPatch])[0] : undefined;
|
|
2125
|
+
}
|
|
2126
|
+
function reportRejectedPatch(index) {
|
|
2127
|
+
console.warn(`NativeList rejected invalid patch unit at patches[${index}]`);
|
|
2128
|
+
}
|
|
1160
2129
|
export function validatePatches(patches) {
|
|
1161
|
-
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
if (
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
2130
|
+
if (!Array.isArray(patches)) fail('patches', 'must be an array');
|
|
2131
|
+
const units = new Map();
|
|
2132
|
+
const rejectedKeys = new Set();
|
|
2133
|
+
const reject = (key, index, error) => {
|
|
2134
|
+
if (isDevelopment()) throw error;
|
|
2135
|
+
rejectedKeys.add(key);
|
|
2136
|
+
reportRejectedPatch(index);
|
|
2137
|
+
};
|
|
2138
|
+
patches.forEach((input, index) => {
|
|
2139
|
+
const key = isRecord(input) && typeof input.key === 'string' ? input.key : '';
|
|
2140
|
+
try {
|
|
2141
|
+
protocolObject(input, `patches[${index}]`);
|
|
2142
|
+
protocolKey(input.key, `patches[${index}].key`);
|
|
2143
|
+
assertRowType(input.type, `patches[${index}]`);
|
|
2144
|
+
const changes = capturePlainData(protocolObject(input.changes, `patches[${index}].changes`));
|
|
2145
|
+
assertPlainSerializable(changes, `patches[${index}].changes`, new Set(), false);
|
|
2146
|
+
const previous = units.get(key);
|
|
2147
|
+
if (previous && previous.patch.type !== input.type) fail(`patches[${index}].type`, 'conflicting row types');
|
|
2148
|
+
const defined = Object.fromEntries(Object.entries(changes).filter(([, value]) => value !== undefined));
|
|
2149
|
+
units.set(key, {
|
|
2150
|
+
index,
|
|
2151
|
+
patch: {
|
|
2152
|
+
key,
|
|
2153
|
+
type: input.type,
|
|
2154
|
+
changes: {
|
|
2155
|
+
...previous?.patch.changes,
|
|
2156
|
+
...defined
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
});
|
|
2160
|
+
} catch (error) {
|
|
2161
|
+
reject(key, index, error);
|
|
1169
2162
|
}
|
|
1170
|
-
assertPatchChanges(patch, index);
|
|
1171
2163
|
});
|
|
1172
|
-
|
|
2164
|
+
const accepted = [];
|
|
2165
|
+
for (const [key, unit] of units) {
|
|
2166
|
+
if (rejectedKeys.has(key)) continue;
|
|
2167
|
+
try {
|
|
2168
|
+
const patch = normalizePatch(unit.patch, unit.index);
|
|
2169
|
+
if (patch) accepted.push(patch);
|
|
2170
|
+
} catch (error) {
|
|
2171
|
+
reject(key, unit.index, error);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
return accepted;
|
|
1173
2175
|
}
|
|
1174
2176
|
|
|
1175
2177
|
/** Patches reach the native side without passing through a snapshot. */
|
|
@@ -1191,31 +2193,227 @@ function normalizePatchStyles(patches) {
|
|
|
1191
2193
|
});
|
|
1192
2194
|
return changed ? next : patches;
|
|
1193
2195
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
2196
|
+
const EMPTY_ROW_PATCHES = Object.freeze([]);
|
|
2197
|
+
function sameJsonValue(left, right) {
|
|
2198
|
+
if (left === right) return true;
|
|
2199
|
+
if (left === null || right === null) return false;
|
|
2200
|
+
if (typeof left !== 'object' || typeof right !== 'object') return false;
|
|
2201
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
2202
|
+
return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => sameJsonValue(value, right[index]));
|
|
2203
|
+
}
|
|
2204
|
+
const leftObject = left;
|
|
2205
|
+
const rightObject = right;
|
|
2206
|
+
const leftKeys = Object.keys(leftObject).filter(key => leftObject[key] !== undefined);
|
|
2207
|
+
const rightKeys = Object.keys(rightObject).filter(key => rightObject[key] !== undefined);
|
|
2208
|
+
return leftKeys.length === rightKeys.length && leftKeys.every(key => sameJsonValue(leftObject[key], rightObject[key]));
|
|
2209
|
+
}
|
|
2210
|
+
function sameOptionalPresence(left, right) {
|
|
2211
|
+
return left === undefined === (right === undefined);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/** Plan value-only patches; callers own valid immutable snapshots and commit state. */
|
|
2215
|
+
export function planNativeListPatches(previous, next) {
|
|
2216
|
+
if (previous === next) return EMPTY_ROW_PATCHES;
|
|
2217
|
+
const {
|
|
2218
|
+
rows: previousRows,
|
|
2219
|
+
...previousMetadata
|
|
2220
|
+
} = previous;
|
|
2221
|
+
const {
|
|
2222
|
+
rows: nextRows,
|
|
2223
|
+
...nextMetadata
|
|
2224
|
+
} = next;
|
|
2225
|
+
if (previousRows.length !== nextRows.length || !sameJsonValue(previousMetadata, nextMetadata)) return undefined;
|
|
2226
|
+
if (previousRows === nextRows) return EMPTY_ROW_PATCHES;
|
|
2227
|
+
const patches = [];
|
|
2228
|
+
for (let index = 0; index < nextRows.length; index += 1) {
|
|
2229
|
+
const oldRow = previousRows[index];
|
|
2230
|
+
const row = nextRows[index];
|
|
2231
|
+
if (oldRow.key !== row.key || oldRow.type !== row.type) return undefined;
|
|
2232
|
+
if (oldRow === row) continue;
|
|
2233
|
+
if (oldRow.type === 'identity' && row.type === 'identity') {
|
|
2234
|
+
const {
|
|
2235
|
+
subtitle: oldSubtitle,
|
|
2236
|
+
subtitleSegments: oldSubtitleSegments,
|
|
2237
|
+
trailing: oldTrailing,
|
|
2238
|
+
...oldMetadata
|
|
2239
|
+
} = oldRow;
|
|
2240
|
+
const {
|
|
2241
|
+
subtitle,
|
|
2242
|
+
subtitleSegments,
|
|
2243
|
+
trailing,
|
|
2244
|
+
...metadata
|
|
2245
|
+
} = row;
|
|
2246
|
+
if (!sameOptionalPresence(oldSubtitle, subtitle) || !sameOptionalPresence(oldSubtitleSegments, subtitleSegments) || !sameOptionalPresence(oldTrailing, trailing) || !sameJsonValue(oldMetadata, metadata)) return undefined;
|
|
2247
|
+
if (!sameJsonValue(oldSubtitle, subtitle) || !sameJsonValue(oldSubtitleSegments, subtitleSegments) || !sameJsonValue(oldTrailing, trailing)) {
|
|
2248
|
+
patches.push({
|
|
2249
|
+
type: 'identity',
|
|
2250
|
+
key: row.key,
|
|
2251
|
+
changes: {
|
|
2252
|
+
subtitle,
|
|
2253
|
+
subtitleSegments,
|
|
2254
|
+
trailing
|
|
2255
|
+
}
|
|
2256
|
+
});
|
|
2257
|
+
}
|
|
2258
|
+
} else if (oldRow.type === 'dataRow' && row.type === 'dataRow') {
|
|
2259
|
+
const {
|
|
2260
|
+
columns: oldColumns,
|
|
2261
|
+
trailing: oldTrailing,
|
|
2262
|
+
...oldMetadata
|
|
2263
|
+
} = oldRow;
|
|
2264
|
+
const {
|
|
2265
|
+
columns,
|
|
2266
|
+
trailing,
|
|
2267
|
+
...metadata
|
|
2268
|
+
} = row;
|
|
2269
|
+
if (!sameOptionalPresence(oldTrailing, trailing) || !sameJsonValue(oldMetadata, metadata) || !sameJsonValue(oldColumns[0], columns[0])) return undefined;
|
|
2270
|
+
if (!sameJsonValue(oldColumns.slice(1), columns.slice(1)) || !sameJsonValue(oldTrailing, trailing)) {
|
|
2271
|
+
patches.push({
|
|
2272
|
+
type: 'dataRow',
|
|
2273
|
+
key: row.key,
|
|
2274
|
+
changes: {
|
|
2275
|
+
columns,
|
|
2276
|
+
trailing
|
|
2277
|
+
}
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
} else if (!sameJsonValue(oldRow, row)) {
|
|
2281
|
+
return undefined;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return patches.length === 0 ? EMPTY_ROW_PATCHES : patches;
|
|
2285
|
+
}
|
|
2286
|
+
function mergeAndValidateSingleRow(previous, patch, index) {
|
|
2287
|
+
if (previous.key !== patch.key) fail(`patches[${index}].key`, 'does not match row identity');
|
|
2288
|
+
if (previous.type !== patch.type) fail(`patches[${index}].type`, 'does not match row type');
|
|
2289
|
+
const changes = {
|
|
2290
|
+
...patch.changes
|
|
2291
|
+
};
|
|
2292
|
+
if (previous.type === 'market') {
|
|
2293
|
+
if (typeof changes.price === 'string' && !('priceSegments' in changes) && previous.priceSegments !== undefined) changes.priceSegments = null;
|
|
2294
|
+
if ((previous.webTable !== undefined || 'webTable' in changes) && ['price', 'priceSegments', 'change'].some(field => field in changes) && changes.webTable === undefined) fail(`patches[${index}].changes.webTable`, 'table quote changes require visible table cells');
|
|
2295
|
+
}
|
|
2296
|
+
if (previous.type === 'identity' || previous.type === 'market') {
|
|
2297
|
+
if (typeof changes.subtitle === 'string' && !('subtitleSegments' in changes) && previous.subtitleSegments !== undefined) changes.subtitleSegments = null;
|
|
2298
|
+
if (Array.isArray(changes.subtitleSegments) && changes.subtitleSegments.length > 0 && !('subtitle' in changes) && previous.subtitle !== undefined) changes.subtitle = null;
|
|
2299
|
+
}
|
|
2300
|
+
const merged = {
|
|
2301
|
+
...previous
|
|
2302
|
+
};
|
|
2303
|
+
for (const [field, value] of Object.entries(changes)) {
|
|
2304
|
+
if (value === null) delete merged[field];else if (value !== undefined) merged[field] = value;
|
|
2305
|
+
}
|
|
2306
|
+
const next = normalizeRowStyles(merged);
|
|
2307
|
+
assertPlainSerializable(next, `rows[${index}]`, new Set());
|
|
2308
|
+
if (isDevelopment()) assertRow(next, index);
|
|
2309
|
+
assertRowProtocol(next, `rows[${index}]`);
|
|
2310
|
+
return {
|
|
2311
|
+
row: next,
|
|
2312
|
+
patch: {
|
|
2313
|
+
type: patch.type,
|
|
2314
|
+
key: patch.key,
|
|
2315
|
+
changes
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
/** One canonical batch owns both accepted rows and the native wire payload. */
|
|
2321
|
+
export function applyValidatedRowPatches(snapshot, patches) {
|
|
2322
|
+
if (!Array.isArray(patches)) fail('patches', 'must be an array');
|
|
2323
|
+
const owned = ownedNativeSnapshots.has(snapshot);
|
|
2324
|
+
const rowIndexes = ownedNativeSnapshots.get(snapshot) ?? validatedRowIndexes.get(snapshot) ?? new Map(snapshot.rows.map((row, index) => [row.key, index]));
|
|
2325
|
+
validatedRowIndexes.set(snapshot, rowIndexes);
|
|
2326
|
+
const units = new Map();
|
|
2327
|
+
const rejected = new Set();
|
|
2328
|
+
const rejectedGroups = new Set();
|
|
2329
|
+
const reject = (key, index, error) => {
|
|
2330
|
+
if (isDevelopment()) throw error;
|
|
2331
|
+
rejected.add(key);
|
|
2332
|
+
const rowIndex = rowIndexes.get(key);
|
|
2333
|
+
const group = rowIndex === undefined ? undefined : snapshot.rows[rowIndex].groupId;
|
|
2334
|
+
if (group) rejectedGroups.add(group);
|
|
2335
|
+
reportRejectedPatch(index);
|
|
2336
|
+
};
|
|
2337
|
+
patches.forEach((input, index) => {
|
|
2338
|
+
const key = isRecord(input) && typeof input.key === 'string' ? input.key : '';
|
|
2339
|
+
try {
|
|
2340
|
+
protocolObject(input, `patches[${index}]`);
|
|
2341
|
+
protocolKey(input.key, `patches[${index}].key`);
|
|
2342
|
+
const rowIndex = rowIndexes.get(input.key);
|
|
2343
|
+
if (rowIndex === undefined) fail(`patches[${index}].key`, 'unknown row identity');
|
|
2344
|
+
if (snapshot.rows[rowIndex].type !== input.type) fail(`patches[${index}].type`, 'does not match row type');
|
|
2345
|
+
const changes = protocolObject(input.changes, `patches[${index}].changes`);
|
|
2346
|
+
const captured = capturePlainData(changes);
|
|
2347
|
+
assertPlainSerializable(captured, `patches[${index}].changes`, new Set(), false);
|
|
2348
|
+
const previous = units.get(input.key);
|
|
2349
|
+
// Undefined is omitted at every merge, so it cannot overwrite an earlier change.
|
|
2350
|
+
const defined = Object.fromEntries(Object.entries(captured).filter(([, value]) => value !== undefined));
|
|
2351
|
+
units.set(input.key, {
|
|
2352
|
+
index,
|
|
2353
|
+
type: input.type,
|
|
2354
|
+
changes: {
|
|
2355
|
+
...previous?.changes,
|
|
2356
|
+
...defined
|
|
2357
|
+
}
|
|
2358
|
+
});
|
|
2359
|
+
} catch (error) {
|
|
2360
|
+
reject(key, index, error);
|
|
1206
2361
|
}
|
|
1207
|
-
if (row.type === 'market' && row.webTable && patch.type === 'market' && (patch.changes.price !== undefined || patch.changes.priceSegments !== undefined || patch.changes.change !== undefined) && patch.changes.webTable === undefined) fail('patches', 'table quote changes must include the visible table cells');
|
|
1208
|
-
return {
|
|
1209
|
-
...row,
|
|
1210
|
-
...patch.changes,
|
|
1211
|
-
key: row.key,
|
|
1212
|
-
type: row.type
|
|
1213
|
-
};
|
|
1214
2362
|
});
|
|
1215
|
-
|
|
2363
|
+
const pending = new Map();
|
|
2364
|
+
for (const [key, unit] of units) {
|
|
2365
|
+
if (rejected.has(key)) continue;
|
|
2366
|
+
try {
|
|
2367
|
+
const patch = normalizePatch({
|
|
2368
|
+
key,
|
|
2369
|
+
type: unit.type,
|
|
2370
|
+
changes: unit.changes
|
|
2371
|
+
}, unit.index);
|
|
2372
|
+
if (!patch) continue;
|
|
2373
|
+
const merged = mergeAndValidateSingleRow(snapshot.rows[rowIndexes.get(key)], patch, rowIndexes.get(key));
|
|
2374
|
+
if (merged.row.disabled && snapshot.selection?.selectedKeys.includes(key)) fail(`patches[${unit.index}]`, 'cannot disable a selected row');
|
|
2375
|
+
pending.set(key, merged);
|
|
2376
|
+
} catch (error) {
|
|
2377
|
+
reject(key, unit.index, error);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
const accepted = [];
|
|
2381
|
+
let rows;
|
|
2382
|
+
for (const [key, value] of pending) {
|
|
2383
|
+
const index = rowIndexes.get(key);
|
|
2384
|
+
const group = snapshot.rows[index].groupId;
|
|
2385
|
+
if (rejected.has(key) || group && rejectedGroups.has(group)) continue;
|
|
2386
|
+
if (!rows) rows = snapshot.rows.slice();
|
|
2387
|
+
rows[index] = owned ? deepFreeze(value.row) : value.row;
|
|
2388
|
+
accepted.push(owned ? deepFreeze(value.patch) : value.patch);
|
|
2389
|
+
}
|
|
2390
|
+
if (!rows) return {
|
|
2391
|
+
patches: EMPTY_ROW_PATCHES,
|
|
2392
|
+
snapshot,
|
|
2393
|
+
json: '[]'
|
|
2394
|
+
};
|
|
2395
|
+
const next = owned ? Object.freeze({
|
|
2396
|
+
...snapshot,
|
|
2397
|
+
rows: Object.freeze(rows)
|
|
2398
|
+
}) : {
|
|
1216
2399
|
...snapshot,
|
|
1217
2400
|
rows
|
|
1218
|
-
}
|
|
2401
|
+
};
|
|
2402
|
+
if (owned) ownedNativeSnapshots.set(next, rowIndexes);else validatedRowIndexes.set(next, rowIndexes);
|
|
2403
|
+
return {
|
|
2404
|
+
patches: accepted,
|
|
2405
|
+
snapshot: next,
|
|
2406
|
+
json: JSON.stringify(accepted)
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
const validatedRowIndexes = new WeakMap();
|
|
2410
|
+
export function applyOwnedNativePatches(snapshot, patches) {
|
|
2411
|
+
const owned = ownedNativeSnapshots.has(snapshot) ? snapshot : ownValidatedNativeSnapshot(validateSnapshot(capturePlainData(snapshot)));
|
|
2412
|
+
return applyValidatedRowPatches(owned, patches);
|
|
2413
|
+
}
|
|
2414
|
+
export function applyRowPatches(snapshot, patches) {
|
|
2415
|
+
const baseline = ownedNativeSnapshots.has(snapshot) ? snapshot : validateSnapshot(snapshot);
|
|
2416
|
+
return applyValidatedRowPatches(baseline, patches).snapshot;
|
|
1219
2417
|
}
|
|
1220
2418
|
export function serializeSnapshot(snapshot) {
|
|
1221
2419
|
return JSON.stringify(validateSnapshot(snapshot));
|