@onekeyfe/react-native-native-list 6.7.0-1 → 6.7.0-11
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/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +1 -1
- package/docs/SPEC.md +449 -14
- package/ios/HybridNativeList.swift +11 -3
- package/ios/RNCNativeListView.swift +10 -6
- package/ios/tests/NativeListLifecycleTests.swift +28 -0
- package/lib/module/NativeList.js +42 -21
- package/lib/module/NativeList.web.js +163 -32
- package/lib/module/ScrollEdgeEffect.js +8 -0
- package/lib/module/index.js +1 -0
- package/lib/module/validation.js +358 -47
- package/lib/module/web/NativeListWebEngine.js +373 -67
- package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/RowRendererRegistry.js +5 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/lib/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/lib/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/lib/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -1
- package/lib/typescript/src/NativeList.types.d.ts +14 -3
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/ScrollEdgeEffect.d.ts +5 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/models.d.ts +71 -1
- package/lib/typescript/src/validation.d.ts +3 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +4 -1
- package/src/NativeList.nitro.ts +3 -1
- package/src/NativeList.tsx +102 -60
- package/src/NativeList.types.ts +15 -3
- package/src/NativeList.web.tsx +264 -65
- package/src/ScrollEdgeEffect.ts +4 -0
- package/src/index.ts +2 -0
- package/src/models.ts +93 -0
- package/src/validation.ts +785 -72
- package/src/web/NativeListWebEngine.ts +625 -100
- package/src/web/templates/ActivityRowRenderer.ts +723 -7
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/RowRendererRegistry.ts +10 -5
- package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
package/src/validation.ts
CHANGED
|
@@ -14,6 +14,9 @@ import type {
|
|
|
14
14
|
RowModel,
|
|
15
15
|
RowPatch,
|
|
16
16
|
WalletGroupRow,
|
|
17
|
+
WebMarketTableCell,
|
|
18
|
+
WebMarketTablePresentation,
|
|
19
|
+
WebMarketTableText,
|
|
17
20
|
} from './models';
|
|
18
21
|
|
|
19
22
|
const MAX_KEY_LENGTH = 256;
|
|
@@ -28,8 +31,42 @@ const MAX_SPACER_HEIGHT = 512;
|
|
|
28
31
|
const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
|
|
29
32
|
const MAX_MARKET_BADGES = 3;
|
|
30
33
|
|
|
34
|
+
function isDevelopment(): boolean {
|
|
35
|
+
return typeof __DEV__ !== 'undefined' && __DEV__;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class NativeListInputError extends Error {
|
|
39
|
+
constructor(readonly path: string, readonly reason: string) {
|
|
40
|
+
super(`NativeList ${path}: ${reason}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
function fail(path: string, message: string): never {
|
|
32
|
-
throw new
|
|
45
|
+
throw new NativeListInputError(path, message);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Component boundaries report locations, never caller-controlled payload values. */
|
|
49
|
+
export function containNativeListInput<T>(operation: () => T): T | undefined {
|
|
50
|
+
try {
|
|
51
|
+
return operation();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const path = error instanceof NativeListInputError ? error.path : 'input';
|
|
54
|
+
const reason =
|
|
55
|
+
isDevelopment() && error instanceof NativeListInputError
|
|
56
|
+
? `: ${error.reason.split('"')[0].trim()}`
|
|
57
|
+
: '';
|
|
58
|
+
console.warn(`NativeList rejected invalid input at ${path}${reason}`);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function emptyNativeListSnapshot(): NativeListSnapshot {
|
|
64
|
+
return {
|
|
65
|
+
schemaVersion: 1,
|
|
66
|
+
generation: 0,
|
|
67
|
+
layout: { kind: 'linear' },
|
|
68
|
+
rows: [],
|
|
69
|
+
};
|
|
33
70
|
}
|
|
34
71
|
|
|
35
72
|
function assertPlainSerializable(
|
|
@@ -69,16 +106,14 @@ function assertPlainSerializable(
|
|
|
69
106
|
function assertKey(key: string, path: string): void {
|
|
70
107
|
if (
|
|
71
108
|
typeof key !== 'string' ||
|
|
72
|
-
key.length === 0 ||
|
|
109
|
+
key.trim().length === 0 ||
|
|
73
110
|
key.length > MAX_KEY_LENGTH
|
|
74
111
|
) {
|
|
75
112
|
fail(
|
|
76
113
|
path,
|
|
77
|
-
`must be a non-
|
|
114
|
+
`must be a non-blank string no longer than ${MAX_KEY_LENGTH} characters`
|
|
78
115
|
);
|
|
79
116
|
}
|
|
80
|
-
if (key.trim() !== key)
|
|
81
|
-
fail(path, 'must not have leading or trailing whitespace');
|
|
82
117
|
}
|
|
83
118
|
|
|
84
119
|
function assertText(text: string | undefined, path: string): void {
|
|
@@ -594,67 +629,12 @@ function normalizeRowStyles<T extends RowModel>(row: T): T {
|
|
|
594
629
|
return next as T;
|
|
595
630
|
}
|
|
596
631
|
|
|
597
|
-
function
|
|
598
|
-
if (
|
|
599
|
-
fail(`${path}.variant`, 'must be token, stock, or perp');
|
|
600
|
-
}
|
|
601
|
-
assertText(row.title, `${path}.title`);
|
|
602
|
-
assertText(row.subtitle, `${path}.subtitle`);
|
|
603
|
-
// OneKey patch: validate the independently laid out Market name.
|
|
604
|
-
if (row.subtitlePrefix) {
|
|
605
|
-
assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
|
|
606
|
-
assertBoundedStyleNumber(
|
|
607
|
-
row.subtitlePrefix.gap,
|
|
608
|
-
`${path}.subtitlePrefix.gap`,
|
|
609
|
-
0,
|
|
610
|
-
64
|
|
611
|
-
);
|
|
612
|
-
assertBoundedStyleNumber(
|
|
613
|
-
row.subtitlePrefix.maxWidth,
|
|
614
|
-
`${path}.subtitlePrefix.maxWidth`,
|
|
615
|
-
1,
|
|
616
|
-
320
|
|
617
|
-
);
|
|
618
|
-
assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
|
|
619
|
-
}
|
|
620
|
-
assertText(row.price, `${path}.price`);
|
|
621
|
-
assertText(row.change.text, `${path}.change.text`);
|
|
622
|
-
assertTrailingAccessories(
|
|
623
|
-
row.leadingAction ? [row.leadingAction] : undefined,
|
|
624
|
-
`${path}.leadingAction`
|
|
625
|
-
);
|
|
626
|
-
if (row.leadingAction) {
|
|
627
|
-
assertText(row.leadingAction.name, `${path}.leadingAction.name`);
|
|
628
|
-
if (row.leadingAction.actionKey !== undefined) {
|
|
629
|
-
assertKey(row.leadingAction.actionKey, `${path}.leadingAction.actionKey`);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
assertLeadingVisual(row.leading, `${path}.leading`);
|
|
633
|
-
const assertSegments = (
|
|
634
|
-
segments: MarketRow['priceSegments'],
|
|
635
|
-
segmentPath: string
|
|
636
|
-
) => {
|
|
637
|
-
segments?.forEach((segment, index) => {
|
|
638
|
-
assertText(segment.text, `${segmentPath}[${index}].text`);
|
|
639
|
-
if (segment.style !== undefined && segment.style !== 'subscript') {
|
|
640
|
-
fail(
|
|
641
|
-
`${segmentPath}[${index}].style`,
|
|
642
|
-
'must be subscript when provided'
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
};
|
|
647
|
-
assertSegments(row.subtitleSegments, `${path}.subtitleSegments`);
|
|
648
|
-
assertSegments(row.priceSegments, `${path}.priceSegments`);
|
|
649
|
-
assertSegments(row.change.textSegments, `${path}.change.textSegments`);
|
|
650
|
-
if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
|
|
651
|
-
fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
|
|
652
|
-
}
|
|
653
|
-
if ((row.badges?.length ?? 0) > MAX_MARKET_BADGES) {
|
|
632
|
+
function assertMarketBadges(badges: MarketRow['badges'], path: string): void {
|
|
633
|
+
if ((badges?.length ?? 0) > MAX_MARKET_BADGES) {
|
|
654
634
|
fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
|
|
655
635
|
}
|
|
656
636
|
const badgeKeys = new Set<string>();
|
|
657
|
-
|
|
637
|
+
badges?.forEach((badge, index) => {
|
|
658
638
|
const badgePath = `${path}.badges[${index}]`;
|
|
659
639
|
assertKey(badge.key, `${badgePath}.key`);
|
|
660
640
|
if (badgeKeys.has(badge.key)) {
|
|
@@ -709,6 +689,322 @@ function assertMarketRow(row: MarketRow, path: string): void {
|
|
|
709
689
|
assertKey(badge.actionKey, `${badgePath}.actionKey`);
|
|
710
690
|
}
|
|
711
691
|
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function assertWebMarketTable(
|
|
695
|
+
table: WebMarketTablePresentation | undefined,
|
|
696
|
+
path: string
|
|
697
|
+
): void {
|
|
698
|
+
if (!table) return;
|
|
699
|
+
assertUnknownKeys(
|
|
700
|
+
table,
|
|
701
|
+
['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'],
|
|
702
|
+
path,
|
|
703
|
+
'Web table key'
|
|
704
|
+
);
|
|
705
|
+
if (table.draggable !== undefined && typeof table.draggable !== 'boolean')
|
|
706
|
+
fail(`${path}.draggable`, 'must be boolean');
|
|
707
|
+
if (table.contextMenuActionKey !== undefined)
|
|
708
|
+
assertKey(table.contextMenuActionKey, `${path}.contextMenuActionKey`);
|
|
709
|
+
assertText(table.testID, `${path}.testID`);
|
|
710
|
+
if (
|
|
711
|
+
!Array.isArray(table.columns) ||
|
|
712
|
+
table.columns.length < 1 ||
|
|
713
|
+
table.columns.length > 12
|
|
714
|
+
)
|
|
715
|
+
fail(`${path}.columns`, 'must contain 1...12 columns');
|
|
716
|
+
if (
|
|
717
|
+
!Array.isArray(table.cells) ||
|
|
718
|
+
table.cells.length !== table.columns.length
|
|
719
|
+
)
|
|
720
|
+
fail(`${path}.cells`, 'must match the column count');
|
|
721
|
+
const keys = new Set<string>();
|
|
722
|
+
table.columns.forEach((column, index) => {
|
|
723
|
+
const field = `${path}.columns[${index}]`;
|
|
724
|
+
assertUnknownKeys(
|
|
725
|
+
column,
|
|
726
|
+
[
|
|
727
|
+
'key',
|
|
728
|
+
'width',
|
|
729
|
+
'minWidth',
|
|
730
|
+
'flex',
|
|
731
|
+
'alignment',
|
|
732
|
+
'paddingStart',
|
|
733
|
+
'paddingEnd',
|
|
734
|
+
],
|
|
735
|
+
field,
|
|
736
|
+
'Web column key'
|
|
737
|
+
);
|
|
738
|
+
assertKey(column.key, `${field}.key`);
|
|
739
|
+
if (keys.has(column.key)) fail(field, 'column keys must be unique');
|
|
740
|
+
keys.add(column.key);
|
|
741
|
+
assertBoundedStyleNumber(column.width, `${field}.width`, 0, 4096);
|
|
742
|
+
assertBoundedStyleNumber(column.minWidth, `${field}.minWidth`, 0, 4096);
|
|
743
|
+
assertBoundedStyleNumber(column.flex, `${field}.flex`, 0, 16);
|
|
744
|
+
assertBoundedStyleNumber(
|
|
745
|
+
column.paddingStart,
|
|
746
|
+
`${field}.paddingStart`,
|
|
747
|
+
0,
|
|
748
|
+
64
|
|
749
|
+
);
|
|
750
|
+
assertBoundedStyleNumber(column.paddingEnd, `${field}.paddingEnd`, 0, 64);
|
|
751
|
+
if (
|
|
752
|
+
column.alignment !== undefined &&
|
|
753
|
+
!['start', 'center', 'end'].includes(column.alignment)
|
|
754
|
+
)
|
|
755
|
+
fail(`${field}.alignment`, 'must be start, center, or end');
|
|
756
|
+
});
|
|
757
|
+
const text = (value: WebMarketTableText, field: string) => {
|
|
758
|
+
assertUnknownKeys(
|
|
759
|
+
value,
|
|
760
|
+
['text', 'segments', 'tone', 'style'],
|
|
761
|
+
field,
|
|
762
|
+
'Web text key'
|
|
763
|
+
);
|
|
764
|
+
assertText(value.text, `${field}.text`);
|
|
765
|
+
assertTextTone(value.tone, `${field}.tone`);
|
|
766
|
+
assertTextStyle(value.style, `${field}.style`);
|
|
767
|
+
if (value.style)
|
|
768
|
+
assertUnknownKeys(
|
|
769
|
+
value.style,
|
|
770
|
+
['fontSize', 'fontWeight', 'lineHeight', 'color'],
|
|
771
|
+
`${field}.style`,
|
|
772
|
+
'Web table text style'
|
|
773
|
+
);
|
|
774
|
+
if ((value.segments?.length ?? 0) > 64)
|
|
775
|
+
fail(`${field}.segments`, 'supports at most 64 segments');
|
|
776
|
+
value.segments?.forEach((segment, index) => {
|
|
777
|
+
assertUnknownKeys(
|
|
778
|
+
segment,
|
|
779
|
+
['text', 'style'],
|
|
780
|
+
`${field}.segments[${index}]`,
|
|
781
|
+
'Web text segment'
|
|
782
|
+
);
|
|
783
|
+
assertText(segment.text, `${field}.segments[${index}].text`);
|
|
784
|
+
if (segment.style !== undefined && segment.style !== 'subscript')
|
|
785
|
+
fail(field, 'segment style must be subscript');
|
|
786
|
+
});
|
|
787
|
+
};
|
|
788
|
+
const line = (
|
|
789
|
+
parts: readonly WebMarketTableText[] | undefined,
|
|
790
|
+
field: string
|
|
791
|
+
) => {
|
|
792
|
+
if (!parts) return;
|
|
793
|
+
if (!Array.isArray(parts) || parts.length > 8)
|
|
794
|
+
fail(field, 'supports at most 8 text parts');
|
|
795
|
+
parts.forEach((value, index) => text(value, `${field}[${index}]`));
|
|
796
|
+
};
|
|
797
|
+
table.cells.forEach((cell: WebMarketTableCell, index) => {
|
|
798
|
+
const field = `${path}.cells[${index}]`;
|
|
799
|
+
assertKey(cell.key, `${field}.key`);
|
|
800
|
+
if (cell.key !== table.columns[index].key)
|
|
801
|
+
fail(field, 'cell key/order must match its column');
|
|
802
|
+
switch (cell.kind) {
|
|
803
|
+
case 'favorite':
|
|
804
|
+
assertUnknownKeys(
|
|
805
|
+
cell,
|
|
806
|
+
[
|
|
807
|
+
'key',
|
|
808
|
+
'kind',
|
|
809
|
+
'active',
|
|
810
|
+
'disabled',
|
|
811
|
+
'testID',
|
|
812
|
+
'hoverActionKey',
|
|
813
|
+
'actionKey',
|
|
814
|
+
'accessibilityLabel',
|
|
815
|
+
],
|
|
816
|
+
field,
|
|
817
|
+
'Web favorite key'
|
|
818
|
+
);
|
|
819
|
+
if (typeof cell.active !== 'boolean')
|
|
820
|
+
fail(field, 'active must be boolean');
|
|
821
|
+
if (cell.disabled !== undefined && typeof cell.disabled !== 'boolean')
|
|
822
|
+
fail(field, 'disabled must be boolean');
|
|
823
|
+
if (cell.hoverActionKey !== undefined)
|
|
824
|
+
assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
|
|
825
|
+
assertText(cell.testID, `${field}.testID`);
|
|
826
|
+
assertKey(cell.actionKey, `${field}.actionKey`);
|
|
827
|
+
assertText(cell.accessibilityLabel, `${field}.accessibilityLabel`);
|
|
828
|
+
break;
|
|
829
|
+
case 'asset':
|
|
830
|
+
assertUnknownKeys(
|
|
831
|
+
cell,
|
|
832
|
+
[
|
|
833
|
+
'key',
|
|
834
|
+
'kind',
|
|
835
|
+
'leading',
|
|
836
|
+
'title',
|
|
837
|
+
'secondary',
|
|
838
|
+
'hoverSecondary',
|
|
839
|
+
'hoverActionKey',
|
|
840
|
+
'hoverActionLabel',
|
|
841
|
+
'badges',
|
|
842
|
+
'lineGap',
|
|
843
|
+
'secondaryBadges',
|
|
844
|
+
'hoverImages',
|
|
845
|
+
],
|
|
846
|
+
field,
|
|
847
|
+
'Web asset key'
|
|
848
|
+
);
|
|
849
|
+
assertBoundedStyleNumber(cell.lineGap, `${field}.lineGap`, 0, 8);
|
|
850
|
+
assertMarketBadges(cell.secondaryBadges, `${field}.secondary`);
|
|
851
|
+
cell.secondaryBadges?.forEach((badge, i) => {
|
|
852
|
+
assertUnknownKeys(
|
|
853
|
+
badge,
|
|
854
|
+
['key', 'text', 'style'],
|
|
855
|
+
`${field}.secondaryBadges[${i}]`,
|
|
856
|
+
'Web secondary badge key'
|
|
857
|
+
);
|
|
858
|
+
if (!badge.text) fail(field, 'secondary badges require text');
|
|
859
|
+
});
|
|
860
|
+
if (
|
|
861
|
+
cell.hoverImages !== undefined &&
|
|
862
|
+
(!Array.isArray(cell.hoverImages) || cell.hoverImages.length > 4)
|
|
863
|
+
)
|
|
864
|
+
fail(field, 'supports at most 4 hover images');
|
|
865
|
+
cell.hoverImages?.forEach((image, i) => {
|
|
866
|
+
if (image !== null) assertImage(image, `${field}.hoverImages[${i}]`);
|
|
867
|
+
});
|
|
868
|
+
assertLeadingVisual(cell.leading, `${field}.leading`);
|
|
869
|
+
text(cell.title, `${field}.title`);
|
|
870
|
+
line(cell.secondary, `${field}.secondary`);
|
|
871
|
+
line(cell.hoverSecondary, `${field}.hoverSecondary`);
|
|
872
|
+
assertText(cell.hoverActionLabel, `${field}.hoverActionLabel`);
|
|
873
|
+
if (cell.hoverActionKey !== undefined)
|
|
874
|
+
assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
|
|
875
|
+
assertMarketBadges(cell.badges, field);
|
|
876
|
+
cell.badges?.forEach((badge, i) =>
|
|
877
|
+
assertUnknownKeys(
|
|
878
|
+
badge,
|
|
879
|
+
[
|
|
880
|
+
'key',
|
|
881
|
+
'text',
|
|
882
|
+
'iconName',
|
|
883
|
+
'icon',
|
|
884
|
+
'textColor',
|
|
885
|
+
'backgroundColor',
|
|
886
|
+
'actionKey',
|
|
887
|
+
'accessibilityLabel',
|
|
888
|
+
'style',
|
|
889
|
+
],
|
|
890
|
+
`${field}.badges[${i}]`,
|
|
891
|
+
'Web title badge key'
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
break;
|
|
895
|
+
case 'text':
|
|
896
|
+
assertUnknownKeys(
|
|
897
|
+
cell,
|
|
898
|
+
['key', 'kind', 'primary', 'secondary', 'partGap'],
|
|
899
|
+
field,
|
|
900
|
+
'Web text cell key'
|
|
901
|
+
);
|
|
902
|
+
assertBoundedStyleNumber(cell.partGap, `${field}.partGap`, 0, 8);
|
|
903
|
+
if (!Array.isArray(cell.primary) || !cell.primary.length)
|
|
904
|
+
fail(field, 'requires primary text');
|
|
905
|
+
line(cell.primary, `${field}.primary`);
|
|
906
|
+
line(cell.secondary, `${field}.secondary`);
|
|
907
|
+
break;
|
|
908
|
+
case 'sparkline':
|
|
909
|
+
assertUnknownKeys(
|
|
910
|
+
cell,
|
|
911
|
+
[
|
|
912
|
+
'key',
|
|
913
|
+
'kind',
|
|
914
|
+
'points',
|
|
915
|
+
'width',
|
|
916
|
+
'height',
|
|
917
|
+
'strokeColor',
|
|
918
|
+
'fillColor',
|
|
919
|
+
],
|
|
920
|
+
field,
|
|
921
|
+
'Web sparkline key'
|
|
922
|
+
);
|
|
923
|
+
if (
|
|
924
|
+
!Array.isArray(cell.points) ||
|
|
925
|
+
cell.points.length > 256 ||
|
|
926
|
+
cell.points.some((value: number) => !Number.isFinite(value))
|
|
927
|
+
)
|
|
928
|
+
fail(field, 'supports at most 256 finite samples');
|
|
929
|
+
if (typeof cell.width !== 'number' || typeof cell.height !== 'number')
|
|
930
|
+
fail(field, 'sparkline dimensions are required');
|
|
931
|
+
assertBoundedStyleNumber(cell.width, `${field}.width`, 1, 512);
|
|
932
|
+
assertBoundedStyleNumber(cell.height, `${field}.height`, 1, 512);
|
|
933
|
+
for (const color of [cell.strokeColor, cell.fillColor])
|
|
934
|
+
if (
|
|
935
|
+
typeof color !== 'string' ||
|
|
936
|
+
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color)
|
|
937
|
+
)
|
|
938
|
+
fail(field, 'colors must be #RRGGBB or #RRGGBBAA');
|
|
939
|
+
break;
|
|
940
|
+
default:
|
|
941
|
+
fail(field, 'unsupported Web table cell kind');
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function assertMarketRow(row: MarketRow, path: string): void {
|
|
947
|
+
assertWebMarketTable(row.webTable, `${path}.webTable`);
|
|
948
|
+
if (!['token', 'stock', 'perp'].includes(row.variant)) {
|
|
949
|
+
fail(`${path}.variant`, 'must be token, stock, or perp');
|
|
950
|
+
}
|
|
951
|
+
assertText(row.title, `${path}.title`);
|
|
952
|
+
assertText(row.subtitle, `${path}.subtitle`);
|
|
953
|
+
// OneKey patch: validate the independently laid out Market name.
|
|
954
|
+
if (row.subtitlePrefix) {
|
|
955
|
+
assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
|
|
956
|
+
assertText(
|
|
957
|
+
row.subtitlePrefix.hoverActionKey,
|
|
958
|
+
`${path}.subtitlePrefix.hoverActionKey`
|
|
959
|
+
);
|
|
960
|
+
assertBoundedStyleNumber(
|
|
961
|
+
row.subtitlePrefix.gap,
|
|
962
|
+
`${path}.subtitlePrefix.gap`,
|
|
963
|
+
0,
|
|
964
|
+
64
|
|
965
|
+
);
|
|
966
|
+
assertBoundedStyleNumber(
|
|
967
|
+
row.subtitlePrefix.maxWidth,
|
|
968
|
+
`${path}.subtitlePrefix.maxWidth`,
|
|
969
|
+
1,
|
|
970
|
+
320
|
|
971
|
+
);
|
|
972
|
+
assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
|
|
973
|
+
}
|
|
974
|
+
assertText(row.price, `${path}.price`);
|
|
975
|
+
assertText(row.change.text, `${path}.change.text`);
|
|
976
|
+
assertTrailingAccessories(
|
|
977
|
+
row.leadingAction ? [row.leadingAction] : undefined,
|
|
978
|
+
`${path}.leadingAction`
|
|
979
|
+
);
|
|
980
|
+
if (row.leadingAction) {
|
|
981
|
+
assertText(row.leadingAction.name, `${path}.leadingAction.name`);
|
|
982
|
+
if (row.leadingAction.actionKey !== undefined) {
|
|
983
|
+
assertKey(row.leadingAction.actionKey, `${path}.leadingAction.actionKey`);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
assertLeadingVisual(row.leading, `${path}.leading`);
|
|
987
|
+
const assertSegments = (
|
|
988
|
+
segments: MarketRow['priceSegments'],
|
|
989
|
+
segmentPath: string
|
|
990
|
+
) => {
|
|
991
|
+
segments?.forEach((segment, index) => {
|
|
992
|
+
assertText(segment.text, `${segmentPath}[${index}].text`);
|
|
993
|
+
if (segment.style !== undefined && segment.style !== 'subscript') {
|
|
994
|
+
fail(
|
|
995
|
+
`${segmentPath}[${index}].style`,
|
|
996
|
+
'must be subscript when provided'
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
};
|
|
1001
|
+
assertSegments(row.subtitleSegments, `${path}.subtitleSegments`);
|
|
1002
|
+
assertSegments(row.priceSegments, `${path}.priceSegments`);
|
|
1003
|
+
assertSegments(row.change.textSegments, `${path}.change.textSegments`);
|
|
1004
|
+
if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
|
|
1005
|
+
fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
|
|
1006
|
+
}
|
|
1007
|
+
assertMarketBadges(row.badges, path);
|
|
712
1008
|
for (const [key, value] of [
|
|
713
1009
|
['pressActionKey', row.pressActionKey],
|
|
714
1010
|
['pressInActionKey', row.pressInActionKey],
|
|
@@ -769,6 +1065,15 @@ function assertTrailingAccessories(
|
|
|
769
1065
|
function assertImage(image: ImageSource | undefined, path: string): void {
|
|
770
1066
|
if (!image) return;
|
|
771
1067
|
if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
|
|
1068
|
+
if (image.fallbackUris !== undefined) {
|
|
1069
|
+
if (!Array.isArray(image.fallbackUris))
|
|
1070
|
+
fail(`${path}.fallbackUris`, 'must be an array');
|
|
1071
|
+
image.fallbackUris.forEach((uri, index) => {
|
|
1072
|
+
if (typeof uri !== 'string')
|
|
1073
|
+
fail(`${path}.fallbackUris[${index}]`, 'must be a string');
|
|
1074
|
+
assertText(uri, `${path}.fallbackUris[${index}]`);
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
772
1077
|
if (
|
|
773
1078
|
!Number.isFinite(image.width) ||
|
|
774
1079
|
!Number.isFinite(image.height) ||
|
|
@@ -1404,7 +1709,7 @@ function assertMediaPreview(value: unknown, path: string) {
|
|
|
1404
1709
|
}
|
|
1405
1710
|
}
|
|
1406
1711
|
|
|
1407
|
-
|
|
1712
|
+
function assertSnapshotContract(
|
|
1408
1713
|
snapshot: NativeListSnapshot
|
|
1409
1714
|
): NativeListSnapshot {
|
|
1410
1715
|
if (
|
|
@@ -1418,6 +1723,10 @@ export function validateSnapshot(
|
|
|
1418
1723
|
);
|
|
1419
1724
|
|
|
1420
1725
|
assertPlainSerializable(snapshot, 'snapshot', new Set<object>());
|
|
1726
|
+
assertText(
|
|
1727
|
+
snapshot.theme?.imageFallbackBackground,
|
|
1728
|
+
'theme.imageFallbackBackground'
|
|
1729
|
+
);
|
|
1421
1730
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
1422
1731
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
|
|
1423
1732
|
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
@@ -1549,7 +1858,384 @@ export function validateSnapshot(
|
|
|
1549
1858
|
'supports at most one key in single mode'
|
|
1550
1859
|
);
|
|
1551
1860
|
}
|
|
1552
|
-
return
|
|
1861
|
+
return snapshot;
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
function protocolObject(value: unknown, path: string): Record<string, unknown> {
|
|
1865
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
1866
|
+
fail(path, 'must be an object');
|
|
1867
|
+
return value as Record<string, unknown>;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
function protocolKey(value: unknown, path: string): void {
|
|
1871
|
+
if (typeof value !== 'string' || value.trim().length === 0)
|
|
1872
|
+
fail(path, 'must be a non-blank string');
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
const PROTOCOL_ARRAY_FIELDS = new Set([
|
|
1876
|
+
'columns',
|
|
1877
|
+
'cells',
|
|
1878
|
+
'points',
|
|
1879
|
+
'images',
|
|
1880
|
+
'overlays',
|
|
1881
|
+
'badges',
|
|
1882
|
+
'trailing',
|
|
1883
|
+
'footerActions',
|
|
1884
|
+
'amounts',
|
|
1885
|
+
'metrics',
|
|
1886
|
+
'children',
|
|
1887
|
+
'subtitleSegments',
|
|
1888
|
+
'titleMatch',
|
|
1889
|
+
'selectedKeys',
|
|
1890
|
+
'segments',
|
|
1891
|
+
'hoverSecondary',
|
|
1892
|
+
'hoverImages',
|
|
1893
|
+
'secondaryBadges',
|
|
1894
|
+
'fallbackUris',
|
|
1895
|
+
'probeOrder',
|
|
1896
|
+
'priceSegments',
|
|
1897
|
+
'textSegments',
|
|
1898
|
+
'secondaryTextSegments',
|
|
1899
|
+
'primaryTextSegments',
|
|
1900
|
+
]);
|
|
1901
|
+
const PROTOCOL_NUMBER_FIELDS = new Set([
|
|
1902
|
+
'height',
|
|
1903
|
+
'width',
|
|
1904
|
+
'fontSize',
|
|
1905
|
+
'lineHeight',
|
|
1906
|
+
'opacity',
|
|
1907
|
+
'offsetY',
|
|
1908
|
+
'offsetX',
|
|
1909
|
+
'cornerRadius',
|
|
1910
|
+
'borderWidth',
|
|
1911
|
+
'horizontalPadding',
|
|
1912
|
+
'verticalPadding',
|
|
1913
|
+
'leadingGap',
|
|
1914
|
+
'lineGap',
|
|
1915
|
+
'titleBadgeGap',
|
|
1916
|
+
'trailingGap',
|
|
1917
|
+
'start',
|
|
1918
|
+
'end',
|
|
1919
|
+
'padding',
|
|
1920
|
+
'offset',
|
|
1921
|
+
'overscan',
|
|
1922
|
+
'minWidth',
|
|
1923
|
+
'flex',
|
|
1924
|
+
'paddingStart',
|
|
1925
|
+
'paddingEnd',
|
|
1926
|
+
'changeWidth',
|
|
1927
|
+
'changeHeight',
|
|
1928
|
+
'changeCornerRadius',
|
|
1929
|
+
'contentTrailingGap',
|
|
1930
|
+
'subtitleTrailingPadding',
|
|
1931
|
+
'partGap',
|
|
1932
|
+
'contentPadding',
|
|
1933
|
+
'contentPaddingHorizontal',
|
|
1934
|
+
'contentPaddingTop',
|
|
1935
|
+
'contentPaddingBottom',
|
|
1936
|
+
'itemSpacing',
|
|
1937
|
+
'gridColumns',
|
|
1938
|
+
]);
|
|
1939
|
+
|
|
1940
|
+
/** Validate only shapes that renderers dereference, not display budgets. */
|
|
1941
|
+
function assertProtocolFields(
|
|
1942
|
+
value: unknown,
|
|
1943
|
+
path: string,
|
|
1944
|
+
parentField = ''
|
|
1945
|
+
): void {
|
|
1946
|
+
if (value === undefined || value === null || typeof value !== 'object')
|
|
1947
|
+
return;
|
|
1948
|
+
if (Array.isArray(value)) {
|
|
1949
|
+
for (const [index, item] of value.entries()) {
|
|
1950
|
+
const itemPath = `${path}[${index}]`;
|
|
1951
|
+
if (
|
|
1952
|
+
['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)
|
|
1953
|
+
) {
|
|
1954
|
+
if (typeof item !== 'string') fail(itemPath, 'must be a string');
|
|
1955
|
+
} else if (parentField === 'points') {
|
|
1956
|
+
if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
|
|
1957
|
+
} else if (parentField === 'hoverImages' && item === null) continue;
|
|
1958
|
+
else protocolObject(item, itemPath);
|
|
1959
|
+
assertProtocolFields(item, itemPath, parentField);
|
|
1960
|
+
}
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
const object = value as Record<string, unknown>;
|
|
1964
|
+
if (
|
|
1965
|
+
!path.includes('.style.') &&
|
|
1966
|
+
['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(
|
|
1967
|
+
parentField
|
|
1968
|
+
) &&
|
|
1969
|
+
typeof object.uri !== 'string'
|
|
1970
|
+
)
|
|
1971
|
+
fail(`${path}.uri`, 'must be a string');
|
|
1972
|
+
Object.entries(value).forEach(([field, item]) => {
|
|
1973
|
+
if (item === undefined) return;
|
|
1974
|
+
const fieldPath = `${path}.${field}`;
|
|
1975
|
+
if (
|
|
1976
|
+
!path.endsWith('.style') &&
|
|
1977
|
+
PROTOCOL_ARRAY_FIELDS.has(field) &&
|
|
1978
|
+
!Array.isArray(item)
|
|
1979
|
+
)
|
|
1980
|
+
fail(fieldPath, 'must be an array');
|
|
1981
|
+
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number')
|
|
1982
|
+
fail(fieldPath, 'must be a finite number');
|
|
1983
|
+
if (
|
|
1984
|
+
PROTOCOL_NUMBER_FIELDS.has(field) &&
|
|
1985
|
+
typeof item === 'number' &&
|
|
1986
|
+
item < 0 &&
|
|
1987
|
+
!['offsetX', 'offsetY'].includes(field)
|
|
1988
|
+
)
|
|
1989
|
+
fail(fieldPath, 'must be non-negative');
|
|
1990
|
+
if (
|
|
1991
|
+
field === 'key' ||
|
|
1992
|
+
field === 'sectionKey' ||
|
|
1993
|
+
field === 'actionKey' ||
|
|
1994
|
+
field.endsWith('ActionKey')
|
|
1995
|
+
)
|
|
1996
|
+
protocolKey(item, fieldPath);
|
|
1997
|
+
if (
|
|
1998
|
+
(field === 'uri' || field === 'fallbackUri') &&
|
|
1999
|
+
typeof item !== 'string'
|
|
2000
|
+
)
|
|
2001
|
+
fail(fieldPath, 'must be a string');
|
|
2002
|
+
if (
|
|
2003
|
+
(field === 'style' &&
|
|
2004
|
+
!(item === 'subscript' && /[Ss]egments\[/.test(path))) ||
|
|
2005
|
+
field === 'container'
|
|
2006
|
+
)
|
|
2007
|
+
protocolObject(item, fieldPath);
|
|
2008
|
+
if (
|
|
2009
|
+
path.endsWith('.style') &&
|
|
2010
|
+
[
|
|
2011
|
+
'title',
|
|
2012
|
+
'subtitle',
|
|
2013
|
+
'tertiary',
|
|
2014
|
+
'body',
|
|
2015
|
+
'time',
|
|
2016
|
+
'price',
|
|
2017
|
+
'change',
|
|
2018
|
+
'columns',
|
|
2019
|
+
'columnSecondary',
|
|
2020
|
+
'value',
|
|
2021
|
+
'valueSecondary',
|
|
2022
|
+
'badge',
|
|
2023
|
+
'description',
|
|
2024
|
+
'status',
|
|
2025
|
+
'primaryAmount',
|
|
2026
|
+
'secondaryAmount',
|
|
2027
|
+
'trend',
|
|
2028
|
+
'message',
|
|
2029
|
+
'actionText',
|
|
2030
|
+
].includes(field)
|
|
2031
|
+
)
|
|
2032
|
+
protocolObject(item, fieldPath);
|
|
2033
|
+
assertProtocolFields(item, fieldPath, field);
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
function assertRowProtocol(row: RowModel, path: string): void {
|
|
2038
|
+
protocolObject(row, path);
|
|
2039
|
+
assertRowType(row.type, path);
|
|
2040
|
+
protocolKey(row.key, `${path}.key`);
|
|
2041
|
+
assertProtocolFields(row, path);
|
|
2042
|
+
for (const field of ['leading', 'visual', 'secondaryLeading'] as const) {
|
|
2043
|
+
const visual = (row as unknown as Record<string, unknown>)[field];
|
|
2044
|
+
if (
|
|
2045
|
+
visual !== undefined ||
|
|
2046
|
+
(field === 'leading' &&
|
|
2047
|
+
(row.type === 'identity' || row.type === 'market'))
|
|
2048
|
+
) {
|
|
2049
|
+
const object = protocolObject(visual, `${path}.${field}`);
|
|
2050
|
+
if (object.kind === 'stackedImages' && !Array.isArray(object.images))
|
|
2051
|
+
fail(`${path}.${field}.images`, 'must be an array');
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
for (const field of [
|
|
2055
|
+
'title',
|
|
2056
|
+
'subtitle',
|
|
2057
|
+
'tertiary',
|
|
2058
|
+
'body',
|
|
2059
|
+
'time',
|
|
2060
|
+
'price',
|
|
2061
|
+
'indexTitle',
|
|
2062
|
+
] as const) {
|
|
2063
|
+
const value = (row as unknown as Record<string, unknown>)[field];
|
|
2064
|
+
if (value !== undefined && typeof value !== 'string')
|
|
2065
|
+
fail(`${path}.${field}`, 'must be a string');
|
|
2066
|
+
}
|
|
2067
|
+
if (row.height !== undefined && row.height < 0)
|
|
2068
|
+
fail(`${path}.height`, 'must be non-negative');
|
|
2069
|
+
if (row.type === 'identity') {
|
|
2070
|
+
let end = 0;
|
|
2071
|
+
row.titleMatch?.forEach((match) => {
|
|
2072
|
+
if (
|
|
2073
|
+
!Number.isInteger(match.start) ||
|
|
2074
|
+
!Number.isInteger(match.end) ||
|
|
2075
|
+
match.start < end ||
|
|
2076
|
+
match.end <= match.start ||
|
|
2077
|
+
match.end > row.title.length
|
|
2078
|
+
)
|
|
2079
|
+
fail(`${path}.titleMatch`, 'invalid text range');
|
|
2080
|
+
end = match.end;
|
|
2081
|
+
});
|
|
2082
|
+
}
|
|
2083
|
+
if (row.type === 'mediaTile' && row.media) {
|
|
2084
|
+
protocolObject(row.media.source, `${path}.media.source`);
|
|
2085
|
+
if (!Array.isArray(row.media.probeOrder))
|
|
2086
|
+
fail(`${path}.media.probeOrder`, 'must be an array');
|
|
2087
|
+
}
|
|
2088
|
+
if (row.type === 'walletGroup') {
|
|
2089
|
+
protocolObject(row.parent, `${path}.parent`);
|
|
2090
|
+
if (!Array.isArray(row.children))
|
|
2091
|
+
fail(`${path}.children`, 'must be an array');
|
|
2092
|
+
const members = [row.parent, ...row.children];
|
|
2093
|
+
const keys = new Set<string>();
|
|
2094
|
+
if (row.parent.key !== row.key)
|
|
2095
|
+
fail(`${path}.parent.key`, 'must match its group');
|
|
2096
|
+
members.forEach((member, index) => {
|
|
2097
|
+
assertRowProtocol(member, `${path}.members[${index}]`);
|
|
2098
|
+
if (member.type !== 'identity' || keys.has(member.key))
|
|
2099
|
+
fail(path, 'invalid wallet member identity');
|
|
2100
|
+
keys.add(member.key);
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
if (row.type === 'dataRow' && !Array.isArray(row.columns))
|
|
2104
|
+
fail(`${path}.columns`, 'must be an array');
|
|
2105
|
+
if (row.type === 'market') {
|
|
2106
|
+
protocolObject(row.change, `${path}.change`);
|
|
2107
|
+
if (row.webTable) {
|
|
2108
|
+
const { columns, cells } = row.webTable;
|
|
2109
|
+
if (
|
|
2110
|
+
!Array.isArray(columns) ||
|
|
2111
|
+
!Array.isArray(cells) ||
|
|
2112
|
+
columns.length !== cells.length
|
|
2113
|
+
)
|
|
2114
|
+
fail(`${path}.webTable`, 'columns and cells must match');
|
|
2115
|
+
const keys = new Set<string>();
|
|
2116
|
+
columns.forEach((column, index) => {
|
|
2117
|
+
protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
|
|
2118
|
+
if (keys.has(column.key) || cells[index]?.key !== column.key)
|
|
2119
|
+
fail(`${path}.webTable`, 'invalid column identity');
|
|
2120
|
+
keys.add(column.key);
|
|
2121
|
+
const cell = cells[index];
|
|
2122
|
+
if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind))
|
|
2123
|
+
fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
|
|
2124
|
+
if (cell.kind === 'asset')
|
|
2125
|
+
protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
|
|
2126
|
+
if (
|
|
2127
|
+
(cell.kind === 'asset' || cell.kind === 'text') &&
|
|
2128
|
+
cell.secondary !== undefined &&
|
|
2129
|
+
!Array.isArray(cell.secondary)
|
|
2130
|
+
)
|
|
2131
|
+
fail(
|
|
2132
|
+
`${path}.webTable.cells[${index}].secondary`,
|
|
2133
|
+
'must be an array'
|
|
2134
|
+
);
|
|
2135
|
+
if (cell.kind === 'text' && !Array.isArray(cell.primary))
|
|
2136
|
+
fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
|
|
2137
|
+
// The Web renderer spreads samples into Math.min/Math.max.
|
|
2138
|
+
if (
|
|
2139
|
+
cell.kind === 'sparkline' &&
|
|
2140
|
+
(!Array.isArray(cell.points) || cell.points.length > 256)
|
|
2141
|
+
)
|
|
2142
|
+
fail(
|
|
2143
|
+
`${path}.webTable.cells[${index}].points`,
|
|
2144
|
+
'must be an array of at most 256 samples'
|
|
2145
|
+
);
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
function assertSnapshotProtocol(snapshot: NativeListSnapshot): void {
|
|
2152
|
+
protocolObject(snapshot, 'snapshot');
|
|
2153
|
+
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
2154
|
+
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0)
|
|
2155
|
+
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
2156
|
+
protocolObject(snapshot.layout, 'snapshot.layout');
|
|
2157
|
+
assertProtocolFields(snapshot.layout, 'snapshot.layout');
|
|
2158
|
+
if (
|
|
2159
|
+
snapshot.layout.orientation !== undefined &&
|
|
2160
|
+
!['vertical', 'horizontal'].includes(snapshot.layout.orientation)
|
|
2161
|
+
)
|
|
2162
|
+
fail('snapshot.layout.orientation', 'is not supported');
|
|
2163
|
+
if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind))
|
|
2164
|
+
fail('snapshot.layout.kind', 'is not supported');
|
|
2165
|
+
if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
|
|
2166
|
+
if (
|
|
2167
|
+
snapshot.layout.kind === 'grid' &&
|
|
2168
|
+
(!Number.isInteger(snapshot.layout.gridColumns) ||
|
|
2169
|
+
(snapshot.layout.gridColumns ?? 0) < 1 ||
|
|
2170
|
+
(snapshot.layout.gridColumns ?? 0) > 7)
|
|
2171
|
+
)
|
|
2172
|
+
fail('snapshot.layout.gridColumns', 'must be an integer from 1 to 7');
|
|
2173
|
+
const keys = new Set<string>();
|
|
2174
|
+
for (const [index, row] of snapshot.rows.entries()) {
|
|
2175
|
+
assertRowProtocol(row, `rows[${index}]`);
|
|
2176
|
+
if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
|
|
2177
|
+
keys.add(row.key);
|
|
2178
|
+
}
|
|
2179
|
+
if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
|
|
2180
|
+
if (snapshot.fixedFooter)
|
|
2181
|
+
assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
|
|
2182
|
+
if (snapshot.selection) {
|
|
2183
|
+
if (!Array.isArray(snapshot.selection.selectedKeys))
|
|
2184
|
+
fail('snapshot.selection.selectedKeys', 'must be an array');
|
|
2185
|
+
snapshot.selection.selectedKeys.forEach((key) => {
|
|
2186
|
+
if (!keys.has(key))
|
|
2187
|
+
fail('snapshot.selection.selectedKeys', 'unknown row identity');
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
/** Empty optional image descriptors must take the same path as absent images. */
|
|
2193
|
+
function normalizeEmptyImages(value: unknown, field = ''): unknown {
|
|
2194
|
+
if (!value || typeof value !== 'object') return value;
|
|
2195
|
+
if (Array.isArray(value)) {
|
|
2196
|
+
const next = value.map((item) => normalizeEmptyImages(item));
|
|
2197
|
+
const filtered =
|
|
2198
|
+
field === 'images'
|
|
2199
|
+
? next.filter((item) => item !== undefined)
|
|
2200
|
+
: next.map((item) => (item === undefined ? null : item));
|
|
2201
|
+
return filtered.length === value.length &&
|
|
2202
|
+
filtered.every((item, index) => item === value[index])
|
|
2203
|
+
? value
|
|
2204
|
+
: filtered;
|
|
2205
|
+
}
|
|
2206
|
+
const object = value as Record<string, unknown>;
|
|
2207
|
+
if (
|
|
2208
|
+
typeof object.uri === 'string' &&
|
|
2209
|
+
!object.uri.trim() &&
|
|
2210
|
+
'width' in object &&
|
|
2211
|
+
'height' in object
|
|
2212
|
+
)
|
|
2213
|
+
return undefined;
|
|
2214
|
+
let changed = false;
|
|
2215
|
+
const next = { ...object };
|
|
2216
|
+
Object.entries(object).forEach(([key, item]) => {
|
|
2217
|
+
const normalized = normalizeEmptyImages(item, key);
|
|
2218
|
+
if (normalized !== item) {
|
|
2219
|
+
// Omitted JSON patch fields must also be absent from the JS merge.
|
|
2220
|
+
if (field === 'changes' && normalized === undefined) delete next[key];
|
|
2221
|
+
else next[key] = normalized;
|
|
2222
|
+
changed = true;
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
2225
|
+
if (field === 'media' && next.source === undefined) return undefined;
|
|
2226
|
+
return changed ? next : value;
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
export function validateSnapshot(
|
|
2230
|
+
snapshot: NativeListSnapshot
|
|
2231
|
+
): NativeListSnapshot {
|
|
2232
|
+
assertPlainSerializable(snapshot, 'snapshot', new Set<object>());
|
|
2233
|
+
if (isDevelopment()) assertSnapshotContract(snapshot);
|
|
2234
|
+
const normalized = isDevelopment()
|
|
2235
|
+
? snapshot
|
|
2236
|
+
: (normalizeEmptyImages(snapshot) as NativeListSnapshot);
|
|
2237
|
+
assertSnapshotProtocol(normalized);
|
|
2238
|
+
return normalizeSnapshotStyles(normalized);
|
|
1553
2239
|
}
|
|
1554
2240
|
|
|
1555
2241
|
/**
|
|
@@ -1798,18 +2484,30 @@ export function validatePatches(
|
|
|
1798
2484
|
patches: readonly RowPatch[]
|
|
1799
2485
|
): readonly RowPatch[] {
|
|
1800
2486
|
assertPlainSerializable(patches, 'patches', new Set<object>());
|
|
2487
|
+
if (!Array.isArray(patches)) fail('patches', 'must be an array');
|
|
1801
2488
|
const keys = new Set<string>();
|
|
1802
|
-
patches.
|
|
1803
|
-
|
|
2489
|
+
for (const [index, patch] of patches.entries()) {
|
|
2490
|
+
protocolObject(patch, `patches[${index}]`);
|
|
2491
|
+
protocolKey(patch.key, `patches[${index}].key`);
|
|
1804
2492
|
if (keys.has(patch.key))
|
|
1805
2493
|
fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
|
|
1806
2494
|
keys.add(patch.key);
|
|
2495
|
+
protocolObject(patch.changes, `patches[${index}].changes`);
|
|
2496
|
+
assertRowType(patch.type, `patches[${index}]`);
|
|
2497
|
+
assertProtocolFields(patch.changes, `patches[${index}].changes`);
|
|
2498
|
+
if (!isDevelopment()) continue;
|
|
2499
|
+
assertKey(patch.key, `patches[${index}].key`);
|
|
1807
2500
|
if (Object.keys(patch.changes).length === 0) {
|
|
1808
2501
|
fail(`patches[${index}].changes`, 'must contain at least one field');
|
|
1809
2502
|
}
|
|
1810
2503
|
assertPatchChanges(patch, index);
|
|
1811
|
-
}
|
|
1812
|
-
|
|
2504
|
+
}
|
|
2505
|
+
const normalized = isDevelopment()
|
|
2506
|
+
? patches
|
|
2507
|
+
: (normalizeEmptyImages(patches) as readonly RowPatch[]);
|
|
2508
|
+
return normalizePatchStyles(
|
|
2509
|
+
normalized.filter((patch) => Object.keys(patch.changes).length > 0)
|
|
2510
|
+
);
|
|
1813
2511
|
}
|
|
1814
2512
|
|
|
1815
2513
|
/** Patches reach the native side without passing through a snapshot. */
|
|
@@ -1835,10 +2533,12 @@ export function applyRowPatches(
|
|
|
1835
2533
|
snapshot: NativeListSnapshot,
|
|
1836
2534
|
patches: readonly RowPatch[]
|
|
1837
2535
|
): NativeListSnapshot {
|
|
1838
|
-
validatePatches(patches);
|
|
1839
|
-
const patchByKey = new Map(
|
|
2536
|
+
const normalizedPatches = validatePatches(patches);
|
|
2537
|
+
const patchByKey = new Map(
|
|
2538
|
+
normalizedPatches.map((patch) => [patch.key, patch])
|
|
2539
|
+
);
|
|
1840
2540
|
const knownKeys = new Set(snapshot.rows.map((row) => row.key));
|
|
1841
|
-
|
|
2541
|
+
normalizedPatches.forEach((patch) => {
|
|
1842
2542
|
if (!knownKeys.has(patch.key))
|
|
1843
2543
|
fail('patches', `unknown row key "${patch.key}"`);
|
|
1844
2544
|
});
|
|
@@ -1848,6 +2548,19 @@ export function applyRowPatches(
|
|
|
1848
2548
|
if (patch.type !== row.type) {
|
|
1849
2549
|
fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
|
|
1850
2550
|
}
|
|
2551
|
+
if (
|
|
2552
|
+
row.type === 'market' &&
|
|
2553
|
+
row.webTable &&
|
|
2554
|
+
patch.type === 'market' &&
|
|
2555
|
+
(patch.changes.price !== undefined ||
|
|
2556
|
+
patch.changes.priceSegments !== undefined ||
|
|
2557
|
+
patch.changes.change !== undefined) &&
|
|
2558
|
+
patch.changes.webTable === undefined
|
|
2559
|
+
)
|
|
2560
|
+
fail(
|
|
2561
|
+
'patches',
|
|
2562
|
+
'table quote changes must include the visible table cells'
|
|
2563
|
+
);
|
|
1851
2564
|
return {
|
|
1852
2565
|
...row,
|
|
1853
2566
|
...patch.changes,
|