@onekeyfe/react-native-native-list 6.7.0-alpha.359 → 6.7.0-alpha.363
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 +0 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +7 -240
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +4 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +3 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +0 -12
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +7 -87
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +1 -135
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +14 -43
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +0 -25
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +2 -17
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +0 -22
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +2 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +0 -69
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +1 -55
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +29 -587
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +0 -1
- package/docs/ROW_TEMPLATES.md +9 -60
- package/docs/SPEC.md +15 -317
- package/docs/STYLE_SPEC.md +0 -6
- package/ios/HybridNativeList.swift +0 -10
- package/ios/NativeListAccessoryStack.swift +37 -220
- package/ios/NativeListActivityDetailsView.swift +8 -18
- package/ios/NativeListActivityRenderer.swift +2 -8
- package/ios/NativeListDataRowRenderer.swift +16 -128
- package/ios/NativeListDesignAssets.swift +0 -3
- package/ios/NativeListIdentityRenderer.swift +5 -123
- package/ios/NativeListLeadingVisual.swift +14 -49
- package/ios/NativeListMessageRenderer.swift +1 -34
- package/ios/NativeListModels.swift +2 -16
- package/ios/NativeListRendererRegistry.swift +0 -1
- package/ios/NativeListResolvedText.swift +1 -2
- package/ios/NativeListRowHost.swift +0 -14
- package/ios/NativeListSectionHeaderRenderer.swift +0 -88
- package/ios/RNCNativeListView.swift +29 -335
- package/ios/tests/NativeListActivityPresentationTests.swift +0 -56
- package/ios/tests/NativeListLifecycleTests.swift +3 -1283
- package/lib/module/NativeList.js +21 -39
- package/lib/module/NativeList.web.js +4 -51
- package/lib/module/models.js +0 -1
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +8 -320
- package/lib/module/web/NativeListWebEngine.js +18 -373
- package/lib/module/web/templates/ActivityRowRenderer.js +7 -8
- package/lib/module/web/templates/DataRowRenderer.js +5 -40
- package/lib/module/web/templates/IdentityRowRenderer.js +4 -90
- package/lib/module/web/templates/MessageRowRenderer.js +2 -18
- package/lib/module/web/templates/RowContainerStyle.js +0 -1
- package/lib/module/web/templates/RowRendererRegistry.js +0 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +2 -36
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/lib/typescript/src/NativeList.nitro.d.ts +0 -1
- package/lib/typescript/src/NativeList.types.d.ts +0 -8
- package/lib/typescript/src/models.d.ts +9 -101
- package/lib/typescript/src/validation.d.ts +0 -10
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -26
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +3 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +0 -1
- package/src/NativeList.nitro.ts +0 -1
- package/src/NativeList.tsx +24 -72
- package/src/NativeList.types.ts +0 -9
- package/src/NativeList.web.tsx +8 -72
- package/src/models.ts +3 -113
- package/src/selection.ts +0 -1
- package/src/validation.ts +6 -721
- package/src/web/NativeListWebEngine.ts +19 -568
- package/src/web/templates/ActivityRowRenderer.ts +6 -14
- package/src/web/templates/DataRowRenderer.ts +20 -93
- package/src/web/templates/IdentityRowRenderer.ts +5 -150
- package/src/web/templates/MessageRowRenderer.ts +7 -23
- package/src/web/templates/RowContainerStyle.ts +0 -2
- package/src/web/templates/RowRendererRegistry.ts +1 -11
- package/src/web/templates/SectionHeaderRowRenderer.ts +4 -47
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +0 -102
- package/ios/NativeListButtonGroupRenderer.swift +0 -89
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +0 -47
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +0 -14
- package/src/web/templates/ButtonGroupRowRenderer.ts +0 -58
package/src/validation.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ROW_BOX_STYLE_KEYS_BY_TYPE } from './models';
|
|
2
2
|
import type {
|
|
3
3
|
ActivityRow,
|
|
4
|
-
ButtonGroupRow,
|
|
5
4
|
IdentityRow,
|
|
6
5
|
ImageSource,
|
|
7
6
|
LeadingVisual,
|
|
@@ -14,7 +13,6 @@ import type {
|
|
|
14
13
|
RowBoxStyle,
|
|
15
14
|
RowModel,
|
|
16
15
|
RowPatch,
|
|
17
|
-
RowTextHelp,
|
|
18
16
|
WalletGroupRow,
|
|
19
17
|
WebMarketTableCell,
|
|
20
18
|
WebMarketTablePresentation,
|
|
@@ -222,14 +220,12 @@ const TEXT_STYLE_KEYS_BY_ROW_TYPE: Readonly<
|
|
|
222
220
|
metricCard: ['title', 'value', 'subtitle', 'trend'],
|
|
223
221
|
sectionHeader: ['title', 'subtitle', 'value'],
|
|
224
222
|
action: ['title', 'value'],
|
|
225
|
-
buttonGroup: [],
|
|
226
223
|
system: ['title', 'message', 'actionText'],
|
|
227
224
|
};
|
|
228
225
|
|
|
229
226
|
const EXTRA_STYLE_KEYS_BY_ROW_TYPE: Readonly<
|
|
230
227
|
Partial<Record<RowModel['type'], readonly string[]>>
|
|
231
228
|
> = {
|
|
232
|
-
identity: ['leadingContentMaxWidthRatio'],
|
|
233
229
|
market: [
|
|
234
230
|
'titleBadgeLayout',
|
|
235
231
|
'contentTrailingGap',
|
|
@@ -238,7 +234,6 @@ const EXTRA_STYLE_KEYS_BY_ROW_TYPE: Readonly<
|
|
|
238
234
|
'changeHeight',
|
|
239
235
|
'changeCornerRadius',
|
|
240
236
|
],
|
|
241
|
-
sectionHeader: ['valuePlacement', 'titleDecoration'],
|
|
242
237
|
};
|
|
243
238
|
|
|
244
239
|
function assertTextStyle(
|
|
@@ -497,33 +492,6 @@ function assertRowStyle(row: RowModel, path: string): void {
|
|
|
497
492
|
// Market keeps its own richer assertions, driven from assertMarketRow.
|
|
498
493
|
if (row.type === 'market') return;
|
|
499
494
|
assertBoxStyle(style as RowBoxStyle, `${path}.style`);
|
|
500
|
-
if (row.type === 'identity') {
|
|
501
|
-
const ratio = (style as IdentityRow['style'])?.leadingContentMaxWidthRatio;
|
|
502
|
-
if (
|
|
503
|
-
ratio !== undefined &&
|
|
504
|
-
(!Number.isFinite(ratio) || ratio <= 0 || ratio > 1)
|
|
505
|
-
)
|
|
506
|
-
fail(
|
|
507
|
-
`${path}.style.leadingContentMaxWidthRatio`,
|
|
508
|
-
'must be within (0, 1]'
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
if (row.type === 'sectionHeader') {
|
|
512
|
-
const sectionStyle = style as Extract<
|
|
513
|
-
RowModel,
|
|
514
|
-
{ type: 'sectionHeader' }
|
|
515
|
-
>['style'];
|
|
516
|
-
if (
|
|
517
|
-
sectionStyle?.valuePlacement !== undefined &&
|
|
518
|
-
sectionStyle.valuePlacement !== 'afterTitle'
|
|
519
|
-
)
|
|
520
|
-
fail(`${path}.style.valuePlacement`, 'must be afterTitle');
|
|
521
|
-
if (
|
|
522
|
-
sectionStyle?.titleDecoration !== undefined &&
|
|
523
|
-
!['none', 'dashed'].includes(sectionStyle.titleDecoration)
|
|
524
|
-
)
|
|
525
|
-
fail(`${path}.style.titleDecoration`, 'must be none or dashed');
|
|
526
|
-
}
|
|
527
495
|
const slots = style as Record<string, NativeListTextStyle | undefined>;
|
|
528
496
|
textKeys.forEach((key) =>
|
|
529
497
|
assertTextStyle(slots[key], `${path}.style.${key}`)
|
|
@@ -1081,55 +1049,6 @@ function assertTrailingAccessories(
|
|
|
1081
1049
|
): void {
|
|
1082
1050
|
accessories?.forEach((accessory, index) => {
|
|
1083
1051
|
const accessoryPath = `${path}[${index}]`;
|
|
1084
|
-
if (accessory.kind === 'button') {
|
|
1085
|
-
assertUnknownKeys(
|
|
1086
|
-
accessory as Record<string, unknown>,
|
|
1087
|
-
[
|
|
1088
|
-
'kind',
|
|
1089
|
-
'label',
|
|
1090
|
-
'actionKey',
|
|
1091
|
-
'disabled',
|
|
1092
|
-
'testID',
|
|
1093
|
-
'accessibilityLabel',
|
|
1094
|
-
'textColor',
|
|
1095
|
-
'backgroundColor',
|
|
1096
|
-
'pressedBackgroundColor',
|
|
1097
|
-
'hoverBackgroundColor',
|
|
1098
|
-
'focusRingColor',
|
|
1099
|
-
],
|
|
1100
|
-
accessoryPath,
|
|
1101
|
-
'button key'
|
|
1102
|
-
);
|
|
1103
|
-
if (typeof accessory.label !== 'string' || !accessory.label.trim())
|
|
1104
|
-
fail(`${accessoryPath}.label`, 'must be non-blank');
|
|
1105
|
-
assertKey(accessory.actionKey, `${accessoryPath}.actionKey`);
|
|
1106
|
-
if (
|
|
1107
|
-
accessory.disabled !== undefined &&
|
|
1108
|
-
typeof accessory.disabled !== 'boolean'
|
|
1109
|
-
)
|
|
1110
|
-
fail(`${accessoryPath}.disabled`, 'must be boolean');
|
|
1111
|
-
for (const field of [
|
|
1112
|
-
'textColor',
|
|
1113
|
-
'backgroundColor',
|
|
1114
|
-
'pressedBackgroundColor',
|
|
1115
|
-
'hoverBackgroundColor',
|
|
1116
|
-
'focusRingColor',
|
|
1117
|
-
] as const) {
|
|
1118
|
-
const value = accessory[field];
|
|
1119
|
-
if (
|
|
1120
|
-
value !== undefined &&
|
|
1121
|
-
(typeof value !== 'string' ||
|
|
1122
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))
|
|
1123
|
-
)
|
|
1124
|
-
fail(`${accessoryPath}.${field}`, 'must be #RRGGBB or #RRGGBBAA');
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
if (
|
|
1128
|
-
accessory.kind === 'icon' &&
|
|
1129
|
-
accessory.buttonStyle !== undefined &&
|
|
1130
|
-
accessory.buttonStyle !== 'tertiary'
|
|
1131
|
-
)
|
|
1132
|
-
fail(`${accessoryPath}.buttonStyle`, 'must be tertiary');
|
|
1133
1052
|
if (
|
|
1134
1053
|
accessory.kind === 'progress' &&
|
|
1135
1054
|
(accessory.value < 0 || accessory.value > 1)
|
|
@@ -1137,160 +1056,12 @@ function assertTrailingAccessories(
|
|
|
1137
1056
|
fail(`${accessoryPath}.value`, 'must be within 0...1');
|
|
1138
1057
|
}
|
|
1139
1058
|
if (accessory.kind === 'valuePair') {
|
|
1140
|
-
if (
|
|
1141
|
-
accessory.primaryFontWeight !== undefined &&
|
|
1142
|
-
accessory.primaryFontWeight !== 'medium'
|
|
1143
|
-
)
|
|
1144
|
-
fail(
|
|
1145
|
-
`${accessoryPath}.primaryFontWeight`,
|
|
1146
|
-
'must be medium when provided'
|
|
1147
|
-
);
|
|
1148
|
-
assertTextHelp(accessory.primaryHelp, `${accessoryPath}.primaryHelp`);
|
|
1149
1059
|
assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
|
|
1150
1060
|
assertTextTone(accessory.secondaryTone, `${accessoryPath}.secondaryTone`);
|
|
1151
|
-
for (const field of [
|
|
1152
|
-
'primaryTextSegments',
|
|
1153
|
-
'secondaryTextSegments',
|
|
1154
|
-
] as const) {
|
|
1155
|
-
const segments = accessory[field];
|
|
1156
|
-
if (segments === undefined) continue;
|
|
1157
|
-
const segmentPath = `${accessoryPath}.${field}`;
|
|
1158
|
-
if (!Array.isArray(segments) || segments.length > 64)
|
|
1159
|
-
fail(segmentPath, 'must be an array of at most 64 segments');
|
|
1160
|
-
let textLength = 0;
|
|
1161
|
-
segments.forEach((segment, segmentIndex) => {
|
|
1162
|
-
const path = `${segmentPath}[${segmentIndex}]`;
|
|
1163
|
-
const entry = protocolObject(segment, path);
|
|
1164
|
-
assertUnknownKeys(entry, ['text', 'style'], path, 'segment key');
|
|
1165
|
-
if (
|
|
1166
|
-
typeof entry.text !== 'string' ||
|
|
1167
|
-
entry.text.length > MAX_TEXT_LENGTH
|
|
1168
|
-
)
|
|
1169
|
-
fail(
|
|
1170
|
-
`${path}.text`,
|
|
1171
|
-
`must be a string no longer than ${MAX_TEXT_LENGTH} characters`
|
|
1172
|
-
);
|
|
1173
|
-
if (entry.style !== undefined && entry.style !== 'subscript')
|
|
1174
|
-
fail(`${path}.style`, 'must be subscript when provided');
|
|
1175
|
-
textLength += entry.text.length;
|
|
1176
|
-
});
|
|
1177
|
-
if (textLength > MAX_TEXT_LENGTH)
|
|
1178
|
-
fail(
|
|
1179
|
-
segmentPath,
|
|
1180
|
-
`total text must be at most ${MAX_TEXT_LENGTH} characters`
|
|
1181
|
-
);
|
|
1182
|
-
}
|
|
1183
1061
|
}
|
|
1184
1062
|
});
|
|
1185
1063
|
}
|
|
1186
1064
|
|
|
1187
|
-
function assertTextHelp(help: RowTextHelp | undefined, path: string): void {
|
|
1188
|
-
if (help === undefined) return;
|
|
1189
|
-
const object = protocolObject(help, path);
|
|
1190
|
-
assertUnknownKeys(
|
|
1191
|
-
object,
|
|
1192
|
-
['actionKey', 'presentation', 'underline'],
|
|
1193
|
-
path,
|
|
1194
|
-
'help key'
|
|
1195
|
-
);
|
|
1196
|
-
assertKey(help.actionKey, `${path}.actionKey`);
|
|
1197
|
-
if (!['tooltip', 'popover'].includes(help.presentation))
|
|
1198
|
-
fail(`${path}.presentation`, 'must be tooltip or popover');
|
|
1199
|
-
if (help.underline !== undefined && help.underline !== 'dashed')
|
|
1200
|
-
fail(`${path}.underline`, 'must be dashed');
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
function assertButtonGroup(
|
|
1204
|
-
row: Pick<ButtonGroupRow, 'buttons'>,
|
|
1205
|
-
path: string
|
|
1206
|
-
): void {
|
|
1207
|
-
if (!Array.isArray(row.buttons) || row.buttons.length === 0)
|
|
1208
|
-
fail(`${path}.buttons`, 'must contain at least one button');
|
|
1209
|
-
const keys = new Set<string>();
|
|
1210
|
-
row.buttons.forEach((button, index) => {
|
|
1211
|
-
const itemPath = `${path}.buttons[${index}]`;
|
|
1212
|
-
const object = protocolObject(button, itemPath);
|
|
1213
|
-
assertUnknownKeys(
|
|
1214
|
-
object,
|
|
1215
|
-
[
|
|
1216
|
-
'key',
|
|
1217
|
-
'label',
|
|
1218
|
-
'actionKey',
|
|
1219
|
-
'disabled',
|
|
1220
|
-
'loading',
|
|
1221
|
-
'testID',
|
|
1222
|
-
'accessibilityLabel',
|
|
1223
|
-
],
|
|
1224
|
-
itemPath,
|
|
1225
|
-
'button key'
|
|
1226
|
-
);
|
|
1227
|
-
assertKey(button.key, `${itemPath}.key`);
|
|
1228
|
-
if (keys.has(button.key)) fail(`${itemPath}.key`, 'duplicate button key');
|
|
1229
|
-
keys.add(button.key);
|
|
1230
|
-
if (
|
|
1231
|
-
typeof button.label !== 'string' ||
|
|
1232
|
-
!button.label.trim() ||
|
|
1233
|
-
button.label.length > MAX_TEXT_LENGTH
|
|
1234
|
-
)
|
|
1235
|
-
fail(`${itemPath}.label`, 'must be non-blank bounded text');
|
|
1236
|
-
assertKey(button.actionKey, `${itemPath}.actionKey`);
|
|
1237
|
-
for (const field of ['disabled', 'loading'] as const) {
|
|
1238
|
-
if (button[field] !== undefined && typeof button[field] !== 'boolean')
|
|
1239
|
-
fail(`${itemPath}.${field}`, 'must be boolean');
|
|
1240
|
-
}
|
|
1241
|
-
for (const field of ['testID', 'accessibilityLabel'] as const) {
|
|
1242
|
-
if (button[field] !== undefined && typeof button[field] !== 'string')
|
|
1243
|
-
fail(`${itemPath}.${field}`, 'must be a string');
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
function assertIdentityExtras(
|
|
1249
|
-
row: Pick<
|
|
1250
|
-
IdentityRow,
|
|
1251
|
-
'titleIcon' | 'secondaryTitleIcon' | 'trailing' | 'style'
|
|
1252
|
-
>,
|
|
1253
|
-
path: string
|
|
1254
|
-
): void {
|
|
1255
|
-
for (const field of ['titleIcon', 'secondaryTitleIcon'] as const) {
|
|
1256
|
-
const titleIcon = row[field];
|
|
1257
|
-
if (titleIcon === undefined) continue;
|
|
1258
|
-
const iconPath = `${path}.${field}`;
|
|
1259
|
-
const icon = protocolObject(titleIcon, iconPath);
|
|
1260
|
-
assertUnknownKeys(
|
|
1261
|
-
icon,
|
|
1262
|
-
['name', 'tintColor', 'accessibilityLabel', 'hoverActionKey'],
|
|
1263
|
-
iconPath,
|
|
1264
|
-
'title icon key'
|
|
1265
|
-
);
|
|
1266
|
-
if (typeof titleIcon.name !== 'string' || !titleIcon.name.trim())
|
|
1267
|
-
fail(`${iconPath}.name`, 'must be non-blank');
|
|
1268
|
-
if (
|
|
1269
|
-
titleIcon.tintColor !== undefined &&
|
|
1270
|
-
(typeof titleIcon.tintColor !== 'string' ||
|
|
1271
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(titleIcon.tintColor))
|
|
1272
|
-
)
|
|
1273
|
-
fail(`${iconPath}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
|
|
1274
|
-
if (
|
|
1275
|
-
titleIcon.accessibilityLabel !== undefined &&
|
|
1276
|
-
typeof titleIcon.accessibilityLabel !== 'string'
|
|
1277
|
-
)
|
|
1278
|
-
fail(`${iconPath}.accessibilityLabel`, 'must be a string');
|
|
1279
|
-
if (titleIcon.hoverActionKey !== undefined)
|
|
1280
|
-
assertKey(titleIcon.hoverActionKey, `${iconPath}.hoverActionKey`);
|
|
1281
|
-
}
|
|
1282
|
-
const ratio = row.style?.leadingContentMaxWidthRatio;
|
|
1283
|
-
if (
|
|
1284
|
-
ratio !== undefined &&
|
|
1285
|
-
(typeof ratio !== 'number' ||
|
|
1286
|
-
!Number.isFinite(ratio) ||
|
|
1287
|
-
ratio <= 0 ||
|
|
1288
|
-
ratio > 1)
|
|
1289
|
-
)
|
|
1290
|
-
fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
|
|
1291
|
-
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
1065
|
function assertImage(image: ImageSource | undefined, path: string): void {
|
|
1295
1066
|
if (!image) return;
|
|
1296
1067
|
if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
|
|
@@ -1361,24 +1132,6 @@ function assertLeadingVisual(
|
|
|
1361
1132
|
assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
|
|
1362
1133
|
// OneKey patch: validate optional selector overlays at the JSON boundary.
|
|
1363
1134
|
assertText(visual.fallbackIcon?.name, `${path}.fallbackIcon.name`);
|
|
1364
|
-
if (
|
|
1365
|
-
visual.fallbackTextColor !== undefined &&
|
|
1366
|
-
(typeof visual.fallbackTextColor !== 'string' ||
|
|
1367
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackTextColor))
|
|
1368
|
-
)
|
|
1369
|
-
fail(`${path}.fallbackTextColor`, 'must be a hex color');
|
|
1370
|
-
if (
|
|
1371
|
-
visual.fallbackIcon?.size !== undefined &&
|
|
1372
|
-
(!Number.isFinite(visual.fallbackIcon.size) ||
|
|
1373
|
-
visual.fallbackIcon.size <= 0 ||
|
|
1374
|
-
visual.fallbackIcon.size > 40)
|
|
1375
|
-
)
|
|
1376
|
-
fail(`${path}.fallbackIcon.size`, 'must be within (0, 40]');
|
|
1377
|
-
if (
|
|
1378
|
-
visual.fallbackIcon?.backgroundColor !== undefined &&
|
|
1379
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackIcon.backgroundColor)
|
|
1380
|
-
)
|
|
1381
|
-
fail(`${path}.fallbackIcon.backgroundColor`, 'must be a hex color');
|
|
1382
1135
|
if ((visual.overlays?.length ?? 0) > 2)
|
|
1383
1136
|
fail(`${path}.overlays`, 'supports at most two overlays');
|
|
1384
1137
|
visual.overlays?.forEach((overlay, index) => {
|
|
@@ -1438,34 +1191,7 @@ function assertLeadingVisual(
|
|
|
1438
1191
|
'must fit inside the overlay'
|
|
1439
1192
|
);
|
|
1440
1193
|
assertImage(overlay.image, `${path}.overlays[${index}].image`);
|
|
1441
|
-
if (overlay.fallbackIcon !== undefined && !overlay.image)
|
|
1442
|
-
fail(`${path}.overlays[${index}].fallbackIcon`, 'requires image');
|
|
1443
|
-
if (
|
|
1444
|
-
overlay.fallbackIcon !== undefined &&
|
|
1445
|
-
(typeof overlay.fallbackIcon.name !== 'string' ||
|
|
1446
|
-
!overlay.fallbackIcon.name.trim())
|
|
1447
|
-
)
|
|
1448
|
-
fail(
|
|
1449
|
-
`${path}.overlays[${index}].fallbackIcon.name`,
|
|
1450
|
-
'must be non-blank'
|
|
1451
|
-
);
|
|
1452
|
-
if (
|
|
1453
|
-
overlay.fallbackIcon?.tintColor !== undefined &&
|
|
1454
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(overlay.fallbackIcon.tintColor)
|
|
1455
|
-
)
|
|
1456
|
-
fail(
|
|
1457
|
-
`${path}.overlays[${index}].fallbackIcon.tintColor`,
|
|
1458
|
-
'must be a hex color'
|
|
1459
|
-
);
|
|
1460
1194
|
assertText(overlay.text, `${path}.overlays[${index}].text`);
|
|
1461
|
-
if (
|
|
1462
|
-
overlay.fontWeight !== undefined &&
|
|
1463
|
-
!['regular', 'medium', 'semibold', 'bold'].includes(overlay.fontWeight)
|
|
1464
|
-
)
|
|
1465
|
-
fail(
|
|
1466
|
-
`${path}.overlays[${index}].fontWeight`,
|
|
1467
|
-
'must be regular, medium, semibold, or bold'
|
|
1468
|
-
);
|
|
1469
1195
|
});
|
|
1470
1196
|
if (visual.kind === 'token') {
|
|
1471
1197
|
assertImage(visual.networkImage, `${path}.networkImage`);
|
|
@@ -1497,8 +1223,6 @@ function assertVisual(row: RowModel, path: string): void {
|
|
|
1497
1223
|
}
|
|
1498
1224
|
|
|
1499
1225
|
function assertActivity(row: Partial<ActivityRow>, path: string): void {
|
|
1500
|
-
if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean')
|
|
1501
|
-
fail(`${path}.hideLeading`, 'must be boolean');
|
|
1502
1226
|
assertText(row.title, `${path}.title`);
|
|
1503
1227
|
assertText(row.description, `${path}.description`);
|
|
1504
1228
|
if (
|
|
@@ -1663,18 +1387,6 @@ function assertRow(
|
|
|
1663
1387
|
assertWalletGroup(row, path);
|
|
1664
1388
|
break;
|
|
1665
1389
|
case 'identity':
|
|
1666
|
-
if (row.contentHeight !== undefined && row.contentHeight !== 'auto') {
|
|
1667
|
-
fail(`${path}.contentHeight`, 'must be auto');
|
|
1668
|
-
}
|
|
1669
|
-
if (
|
|
1670
|
-
row.subtitleLines !== undefined &&
|
|
1671
|
-
![0, 1, 2].includes(row.subtitleLines)
|
|
1672
|
-
) {
|
|
1673
|
-
fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
|
|
1674
|
-
}
|
|
1675
|
-
if (row.longPressActionKey !== undefined) {
|
|
1676
|
-
assertKey(row.longPressActionKey, `${path}.longPressActionKey`);
|
|
1677
|
-
}
|
|
1678
1390
|
if (
|
|
1679
1391
|
row.presentation !== undefined &&
|
|
1680
1392
|
row.presentation !== 'walletSidebar' &&
|
|
@@ -1687,27 +1399,6 @@ function assertRow(
|
|
|
1687
1399
|
);
|
|
1688
1400
|
}
|
|
1689
1401
|
assertText(row.title, `${path}.title`);
|
|
1690
|
-
if ((row.titleSuffixes?.length ?? 0) > 3)
|
|
1691
|
-
fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
|
|
1692
|
-
row.titleSuffixes?.forEach((suffix, index) => {
|
|
1693
|
-
assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
|
|
1694
|
-
if (!['secondary', 'disabled'].includes(suffix.tone))
|
|
1695
|
-
fail(
|
|
1696
|
-
`${path}.titleSuffixes[${index}].tone`,
|
|
1697
|
-
'must be secondary or disabled'
|
|
1698
|
-
);
|
|
1699
|
-
if (
|
|
1700
|
-
suffix.maxWidth !== undefined &&
|
|
1701
|
-
(!Number.isFinite(suffix.maxWidth) ||
|
|
1702
|
-
suffix.maxWidth < 0 ||
|
|
1703
|
-
suffix.maxWidth > 4096)
|
|
1704
|
-
)
|
|
1705
|
-
fail(
|
|
1706
|
-
`${path}.titleSuffixes[${index}].maxWidth`,
|
|
1707
|
-
'must be finite within 0...4096'
|
|
1708
|
-
);
|
|
1709
|
-
});
|
|
1710
|
-
assertIdentityExtras(row, path);
|
|
1711
1402
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
1712
1403
|
// OneKey patch: selector text segments truncate independently.
|
|
1713
1404
|
row.subtitleSegments?.forEach((segment, segmentIndex) => {
|
|
@@ -1775,16 +1466,10 @@ function assertRow(
|
|
|
1775
1466
|
assertActivity(row, path);
|
|
1776
1467
|
break;
|
|
1777
1468
|
case 'message':
|
|
1778
|
-
if (
|
|
1779
|
-
row.presentation !== undefined &&
|
|
1780
|
-
row.presentation !== 'inlineWarning'
|
|
1781
|
-
) {
|
|
1782
|
-
fail(`${path}.presentation`, 'must be inlineWarning');
|
|
1783
|
-
}
|
|
1784
1469
|
assertText(row.title, `${path}.title`);
|
|
1785
1470
|
assertText(row.body, `${path}.body`);
|
|
1786
|
-
if (![
|
|
1787
|
-
fail(`${path}.bodyLines`, 'must be
|
|
1471
|
+
if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
|
|
1472
|
+
fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
|
|
1788
1473
|
}
|
|
1789
1474
|
assertImage(row.thumbnail, `${path}.thumbnail`);
|
|
1790
1475
|
break;
|
|
@@ -1795,23 +1480,6 @@ function assertRow(
|
|
|
1795
1480
|
row.columns.forEach((column, columnIndex) => {
|
|
1796
1481
|
assertKey(column.key, `${path}.columns[${columnIndex}].key`);
|
|
1797
1482
|
assertText(column.text, `${path}.columns[${columnIndex}].text`);
|
|
1798
|
-
assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
|
|
1799
|
-
for (const field of [
|
|
1800
|
-
'textSegments',
|
|
1801
|
-
'secondaryTextSegments',
|
|
1802
|
-
] as const) {
|
|
1803
|
-
column[field]?.forEach((segment, segmentIndex) => {
|
|
1804
|
-
assertText(
|
|
1805
|
-
segment.text,
|
|
1806
|
-
`${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`
|
|
1807
|
-
);
|
|
1808
|
-
if (segment.style !== undefined && segment.style !== 'subscript')
|
|
1809
|
-
fail(
|
|
1810
|
-
`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`,
|
|
1811
|
-
'must be subscript'
|
|
1812
|
-
);
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1815
1483
|
assertText(
|
|
1816
1484
|
column.secondaryLeadingText,
|
|
1817
1485
|
`${path}.columns[${columnIndex}].secondaryLeadingText`
|
|
@@ -1828,13 +1496,6 @@ function assertRow(
|
|
|
1828
1496
|
if ((row.badges?.length ?? 0) > MAX_BADGES) {
|
|
1829
1497
|
fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
|
|
1830
1498
|
}
|
|
1831
|
-
if ((row.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
|
|
1832
|
-
fail(
|
|
1833
|
-
`${path}.trailing`,
|
|
1834
|
-
`supports at most ${MAX_TRAILING_ACCESSORIES} accessories`
|
|
1835
|
-
);
|
|
1836
|
-
}
|
|
1837
|
-
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
1838
1499
|
break;
|
|
1839
1500
|
case 'market':
|
|
1840
1501
|
assertMarketRow(row, path);
|
|
@@ -1911,11 +1572,6 @@ function assertRow(
|
|
|
1911
1572
|
assertText(row.title, `${path}.title`);
|
|
1912
1573
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
1913
1574
|
assertText(row.value, `${path}.value`);
|
|
1914
|
-
if (row.leadingBadge) {
|
|
1915
|
-
assertKey(row.leadingBadge.key, `${path}.leadingBadge.key`);
|
|
1916
|
-
assertText(row.leadingBadge.text, `${path}.leadingBadge.text`);
|
|
1917
|
-
}
|
|
1918
|
-
assertTextHelp(row.valueHelp, `${path}.valueHelp`);
|
|
1919
1575
|
if (row.valueActionKey !== undefined) {
|
|
1920
1576
|
assertKey(row.valueActionKey, `${path}.valueActionKey`);
|
|
1921
1577
|
}
|
|
@@ -1948,9 +1604,6 @@ function assertRow(
|
|
|
1948
1604
|
}
|
|
1949
1605
|
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
1950
1606
|
break;
|
|
1951
|
-
case 'buttonGroup':
|
|
1952
|
-
assertButtonGroup(row, path);
|
|
1953
|
-
break;
|
|
1954
1607
|
case 'system':
|
|
1955
1608
|
const presentation = 'presentation' in row ? row.presentation : undefined;
|
|
1956
1609
|
if (presentation !== undefined && presentation !== 'market') {
|
|
@@ -2059,26 +1712,6 @@ function assertMediaPreview(value: unknown, path: string) {
|
|
|
2059
1712
|
function assertSnapshotContract(
|
|
2060
1713
|
snapshot: NativeListSnapshot
|
|
2061
1714
|
): NativeListSnapshot {
|
|
2062
|
-
if (snapshot.structuralTransition) {
|
|
2063
|
-
assertKey(
|
|
2064
|
-
snapshot.structuralTransition.id,
|
|
2065
|
-
'snapshot.structuralTransition.id'
|
|
2066
|
-
);
|
|
2067
|
-
if (snapshot.structuralTransition.anchorKey !== undefined)
|
|
2068
|
-
assertKey(
|
|
2069
|
-
snapshot.structuralTransition.anchorKey,
|
|
2070
|
-
'snapshot.structuralTransition.anchorKey'
|
|
2071
|
-
);
|
|
2072
|
-
const duration = snapshot.structuralTransition.durationMs;
|
|
2073
|
-
if (
|
|
2074
|
-
duration !== undefined &&
|
|
2075
|
-
(!Number.isFinite(duration) || duration < 0 || duration > 2000)
|
|
2076
|
-
)
|
|
2077
|
-
fail(
|
|
2078
|
-
'snapshot.structuralTransition.durationMs',
|
|
2079
|
-
'must be finite within 0...2000'
|
|
2080
|
-
);
|
|
2081
|
-
}
|
|
2082
1715
|
if (
|
|
2083
1716
|
snapshot.capabilities?.refreshTriggerDistance !== undefined &&
|
|
2084
1717
|
(!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) ||
|
|
@@ -2094,18 +1727,6 @@ function assertSnapshotContract(
|
|
|
2094
1727
|
snapshot.theme?.imageFallbackBackground,
|
|
2095
1728
|
'theme.imageFallbackBackground'
|
|
2096
1729
|
);
|
|
2097
|
-
if (
|
|
2098
|
-
snapshot.theme?.successBackground !== undefined &&
|
|
2099
|
-
(typeof snapshot.theme.successBackground !== 'string' ||
|
|
2100
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))
|
|
2101
|
-
)
|
|
2102
|
-
fail('theme.successBackground', 'must be a hex color');
|
|
2103
|
-
if (
|
|
2104
|
-
snapshot.theme?.rowHoverBackground !== undefined &&
|
|
2105
|
-
(typeof snapshot.theme.rowHoverBackground !== 'string' ||
|
|
2106
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))
|
|
2107
|
-
)
|
|
2108
|
-
fail('theme.rowHoverBackground', 'must be a hex color');
|
|
2109
1730
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
2110
1731
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
|
|
2111
1732
|
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
@@ -2253,7 +1874,6 @@ function protocolKey(value: unknown, path: string): void {
|
|
|
2253
1874
|
|
|
2254
1875
|
const PROTOCOL_ARRAY_FIELDS = new Set([
|
|
2255
1876
|
'columns',
|
|
2256
|
-
'titleSuffixes',
|
|
2257
1877
|
'cells',
|
|
2258
1878
|
'points',
|
|
2259
1879
|
'images',
|
|
@@ -2261,7 +1881,6 @@ const PROTOCOL_ARRAY_FIELDS = new Set([
|
|
|
2261
1881
|
'badges',
|
|
2262
1882
|
'trailing',
|
|
2263
1883
|
'footerActions',
|
|
2264
|
-
'buttons',
|
|
2265
1884
|
'amounts',
|
|
2266
1885
|
'metrics',
|
|
2267
1886
|
'children',
|
|
@@ -2280,7 +1899,6 @@ const PROTOCOL_ARRAY_FIELDS = new Set([
|
|
|
2280
1899
|
'primaryTextSegments',
|
|
2281
1900
|
]);
|
|
2282
1901
|
const PROTOCOL_NUMBER_FIELDS = new Set([
|
|
2283
|
-
'leadingContentMaxWidthRatio',
|
|
2284
1902
|
'height',
|
|
2285
1903
|
'width',
|
|
2286
1904
|
'fontSize',
|
|
@@ -2343,32 +1961,6 @@ function assertProtocolFields(
|
|
|
2343
1961
|
return;
|
|
2344
1962
|
}
|
|
2345
1963
|
const object = value as Record<string, unknown>;
|
|
2346
|
-
if (parentField === 'fallbackIcon') {
|
|
2347
|
-
protocolKey(object.name, `${path}.name`);
|
|
2348
|
-
if (
|
|
2349
|
-
object.size !== undefined &&
|
|
2350
|
-
(typeof object.size !== 'number' ||
|
|
2351
|
-
!Number.isFinite(object.size) ||
|
|
2352
|
-
object.size <= 0 ||
|
|
2353
|
-
object.size > 40)
|
|
2354
|
-
)
|
|
2355
|
-
fail(`${path}.size`, 'must be within (0, 40]');
|
|
2356
|
-
for (const field of ['tintColor', 'backgroundColor'] as const) {
|
|
2357
|
-
const color = object[field];
|
|
2358
|
-
if (
|
|
2359
|
-
color !== undefined &&
|
|
2360
|
-
(typeof color !== 'string' ||
|
|
2361
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color))
|
|
2362
|
-
)
|
|
2363
|
-
fail(`${path}.${field}`, 'must be a hex color');
|
|
2364
|
-
}
|
|
2365
|
-
}
|
|
2366
|
-
if (
|
|
2367
|
-
parentField === 'overlays' &&
|
|
2368
|
-
object.fallbackIcon !== undefined &&
|
|
2369
|
-
!object.image
|
|
2370
|
-
)
|
|
2371
|
-
fail(`${path}.fallbackIcon`, 'requires image');
|
|
2372
1964
|
if (
|
|
2373
1965
|
!path.includes('.style.') &&
|
|
2374
1966
|
['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(
|
|
@@ -2395,16 +1987,6 @@ function assertProtocolFields(
|
|
|
2395
1987
|
!['offsetX', 'offsetY'].includes(field)
|
|
2396
1988
|
)
|
|
2397
1989
|
fail(fieldPath, 'must be non-negative');
|
|
2398
|
-
if (
|
|
2399
|
-
parentField === 'overlays' &&
|
|
2400
|
-
field === 'fontWeight' &&
|
|
2401
|
-
!['regular', 'medium', 'semibold', 'bold'].includes(item as string)
|
|
2402
|
-
)
|
|
2403
|
-
fail(fieldPath, 'must be regular, medium, semibold, or bold');
|
|
2404
|
-
if (field === 'buttonStyle' && item !== 'tertiary')
|
|
2405
|
-
fail(fieldPath, 'must be tertiary');
|
|
2406
|
-
if (field === 'hideLeading' && typeof item !== 'boolean')
|
|
2407
|
-
fail(fieldPath, 'must be boolean');
|
|
2408
1990
|
if (
|
|
2409
1991
|
field === 'key' ||
|
|
2410
1992
|
field === 'sectionKey' ||
|
|
@@ -2485,27 +2067,6 @@ function assertRowProtocol(row: RowModel, path: string): void {
|
|
|
2485
2067
|
if (row.height !== undefined && row.height < 0)
|
|
2486
2068
|
fail(`${path}.height`, 'must be non-negative');
|
|
2487
2069
|
if (row.type === 'identity') {
|
|
2488
|
-
assertIdentityExtras(row, path);
|
|
2489
|
-
if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes))
|
|
2490
|
-
fail(`${path}.titleSuffixes`, 'must be an array');
|
|
2491
|
-
row.titleSuffixes?.forEach((suffix, index) => {
|
|
2492
|
-
protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
|
|
2493
|
-
if (
|
|
2494
|
-
typeof suffix.text !== 'string' ||
|
|
2495
|
-
!['secondary', 'disabled'].includes(suffix.tone)
|
|
2496
|
-
)
|
|
2497
|
-
fail(`${path}.titleSuffixes[${index}]`, 'invalid title suffix');
|
|
2498
|
-
if (
|
|
2499
|
-
suffix.maxWidth !== undefined &&
|
|
2500
|
-
(!Number.isFinite(suffix.maxWidth) ||
|
|
2501
|
-
suffix.maxWidth < 0 ||
|
|
2502
|
-
suffix.maxWidth > 4096)
|
|
2503
|
-
)
|
|
2504
|
-
fail(
|
|
2505
|
-
`${path}.titleSuffixes[${index}].maxWidth`,
|
|
2506
|
-
'must be finite within 0...4096'
|
|
2507
|
-
);
|
|
2508
|
-
});
|
|
2509
2070
|
let end = 0;
|
|
2510
2071
|
row.titleMatch?.forEach((match) => {
|
|
2511
2072
|
if (
|
|
@@ -2519,9 +2080,6 @@ function assertRowProtocol(row: RowModel, path: string): void {
|
|
|
2519
2080
|
end = match.end;
|
|
2520
2081
|
});
|
|
2521
2082
|
}
|
|
2522
|
-
if (row.type === 'buttonGroup') assertButtonGroup(row, path);
|
|
2523
|
-
if (row.type === 'sectionHeader')
|
|
2524
|
-
assertTextHelp(row.valueHelp, `${path}.valueHelp`);
|
|
2525
2083
|
if (row.type === 'mediaTile' && row.media) {
|
|
2526
2084
|
protocolObject(row.media.source, `${path}.media.source`);
|
|
2527
2085
|
if (!Array.isArray(row.media.probeOrder))
|
|
@@ -2542,16 +2100,8 @@ function assertRowProtocol(row: RowModel, path: string): void {
|
|
|
2542
2100
|
keys.add(member.key);
|
|
2543
2101
|
});
|
|
2544
2102
|
}
|
|
2545
|
-
if (row.type === 'dataRow')
|
|
2546
|
-
|
|
2547
|
-
fail(`${path}.columns`, 'must be an array');
|
|
2548
|
-
row.columns.forEach((column, index) => {
|
|
2549
|
-
const columnPath = `${path}.columns[${index}]`;
|
|
2550
|
-
protocolObject(column, columnPath);
|
|
2551
|
-
assertIdentityExtras(column, columnPath);
|
|
2552
|
-
});
|
|
2553
|
-
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
2554
|
-
}
|
|
2103
|
+
if (row.type === 'dataRow' && !Array.isArray(row.columns))
|
|
2104
|
+
fail(`${path}.columns`, 'must be an array');
|
|
2555
2105
|
if (row.type === 'market') {
|
|
2556
2106
|
protocolObject(row.change, `${path}.change`);
|
|
2557
2107
|
if (row.webTable) {
|
|
@@ -2600,42 +2150,6 @@ function assertRowProtocol(row: RowModel, path: string): void {
|
|
|
2600
2150
|
|
|
2601
2151
|
function assertSnapshotProtocol(snapshot: NativeListSnapshot): void {
|
|
2602
2152
|
protocolObject(snapshot, 'snapshot');
|
|
2603
|
-
if (snapshot.structuralTransition) {
|
|
2604
|
-
protocolObject(
|
|
2605
|
-
snapshot.structuralTransition,
|
|
2606
|
-
'snapshot.structuralTransition'
|
|
2607
|
-
);
|
|
2608
|
-
protocolKey(
|
|
2609
|
-
snapshot.structuralTransition.id,
|
|
2610
|
-
'snapshot.structuralTransition.id'
|
|
2611
|
-
);
|
|
2612
|
-
if (snapshot.structuralTransition.anchorKey !== undefined)
|
|
2613
|
-
protocolKey(
|
|
2614
|
-
snapshot.structuralTransition.anchorKey,
|
|
2615
|
-
'snapshot.structuralTransition.anchorKey'
|
|
2616
|
-
);
|
|
2617
|
-
const duration = snapshot.structuralTransition.durationMs;
|
|
2618
|
-
if (
|
|
2619
|
-
duration !== undefined &&
|
|
2620
|
-
(!Number.isFinite(duration) || duration < 0 || duration > 2000)
|
|
2621
|
-
)
|
|
2622
|
-
fail(
|
|
2623
|
-
'snapshot.structuralTransition.durationMs',
|
|
2624
|
-
'must be finite within 0...2000'
|
|
2625
|
-
);
|
|
2626
|
-
}
|
|
2627
|
-
if (
|
|
2628
|
-
snapshot.theme?.successBackground !== undefined &&
|
|
2629
|
-
(typeof snapshot.theme.successBackground !== 'string' ||
|
|
2630
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))
|
|
2631
|
-
)
|
|
2632
|
-
fail('theme.successBackground', 'must be a hex color');
|
|
2633
|
-
if (
|
|
2634
|
-
snapshot.theme?.rowHoverBackground !== undefined &&
|
|
2635
|
-
(typeof snapshot.theme.rowHoverBackground !== 'string' ||
|
|
2636
|
-
!/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))
|
|
2637
|
-
)
|
|
2638
|
-
fail('theme.rowHoverBackground', 'must be a hex color');
|
|
2639
2153
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
2640
2154
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0)
|
|
2641
2155
|
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
@@ -2724,73 +2238,6 @@ export function validateSnapshot(
|
|
|
2724
2238
|
return normalizeSnapshotStyles(normalized);
|
|
2725
2239
|
}
|
|
2726
2240
|
|
|
2727
|
-
const ownedNativeSnapshots = new WeakMap<
|
|
2728
|
-
NativeListSnapshot,
|
|
2729
|
-
ReadonlyMap<string, number>
|
|
2730
|
-
>();
|
|
2731
|
-
|
|
2732
|
-
function capturePlainData<T>(value: T, seen = new Map<object, object>()): T {
|
|
2733
|
-
if (value === null || typeof value !== 'object') return value;
|
|
2734
|
-
const previous = seen.get(value);
|
|
2735
|
-
if (previous) return previous as T;
|
|
2736
|
-
const copy: Record<string, unknown> | unknown[] = Array.isArray(value)
|
|
2737
|
-
? new Array(value.length)
|
|
2738
|
-
: Object.create(Object.getPrototypeOf(value));
|
|
2739
|
-
seen.set(value, copy);
|
|
2740
|
-
const captureKey = (key: string) => {
|
|
2741
|
-
Object.defineProperty(copy, key, {
|
|
2742
|
-
value: capturePlainData((value as Record<string, unknown>)[key], seen),
|
|
2743
|
-
enumerable: true,
|
|
2744
|
-
writable: true,
|
|
2745
|
-
configurable: true,
|
|
2746
|
-
});
|
|
2747
|
-
};
|
|
2748
|
-
if (Array.isArray(value)) {
|
|
2749
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
2750
|
-
if (index in value) captureKey(String(index));
|
|
2751
|
-
}
|
|
2752
|
-
Object.keys(value).forEach((key) => {
|
|
2753
|
-
const index = Number(key);
|
|
2754
|
-
if (
|
|
2755
|
-
Number.isInteger(index) &&
|
|
2756
|
-
index >= 0 &&
|
|
2757
|
-
index < value.length &&
|
|
2758
|
-
String(index) === key
|
|
2759
|
-
)
|
|
2760
|
-
return;
|
|
2761
|
-
captureKey(key);
|
|
2762
|
-
});
|
|
2763
|
-
} else {
|
|
2764
|
-
Object.keys(value).forEach(captureKey);
|
|
2765
|
-
}
|
|
2766
|
-
return copy as T;
|
|
2767
|
-
}
|
|
2768
|
-
|
|
2769
|
-
function deepFreeze<T>(value: T, seen = new WeakSet<object>()): T {
|
|
2770
|
-
if (value === null || typeof value !== 'object' || seen.has(value))
|
|
2771
|
-
return value;
|
|
2772
|
-
seen.add(value);
|
|
2773
|
-
Object.values(value).forEach((item) => deepFreeze(item, seen));
|
|
2774
|
-
return Object.freeze(value);
|
|
2775
|
-
}
|
|
2776
|
-
|
|
2777
|
-
/** Capture caller data once before validation, including accessor values. */
|
|
2778
|
-
export function captureNativeListInput<T>(value: T): T {
|
|
2779
|
-
return capturePlainData(value);
|
|
2780
|
-
}
|
|
2781
|
-
|
|
2782
|
-
/** Private native-wrapper ownership; exported validators keep their public identity. */
|
|
2783
|
-
export function ownValidatedNativeSnapshot(
|
|
2784
|
-
snapshot: NativeListSnapshot
|
|
2785
|
-
): NativeListSnapshot {
|
|
2786
|
-
const owned = deepFreeze(snapshot);
|
|
2787
|
-
ownedNativeSnapshots.set(
|
|
2788
|
-
owned,
|
|
2789
|
-
new Map(owned.rows.map((row, index) => [row.key, index]))
|
|
2790
|
-
);
|
|
2791
|
-
return owned;
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
2241
|
/**
|
|
2795
2242
|
* Resolves typography tokens to numbers. Returns the original snapshot when
|
|
2796
2243
|
* nothing needs resolving, so the common no-style path keeps object identity.
|
|
@@ -2847,46 +2294,7 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
|
|
|
2847
2294
|
|
|
2848
2295
|
switch (patch.type) {
|
|
2849
2296
|
case 'identity':
|
|
2850
|
-
if (
|
|
2851
|
-
patch.changes.contentHeight !== undefined &&
|
|
2852
|
-
patch.changes.contentHeight !== 'auto'
|
|
2853
|
-
) {
|
|
2854
|
-
fail(`${path}.contentHeight`, 'must be auto');
|
|
2855
|
-
}
|
|
2856
|
-
if (
|
|
2857
|
-
patch.changes.subtitleLines !== undefined &&
|
|
2858
|
-
![0, 1, 2].includes(patch.changes.subtitleLines)
|
|
2859
|
-
) {
|
|
2860
|
-
fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
|
|
2861
|
-
}
|
|
2862
|
-
if (patch.changes.longPressActionKey !== undefined) {
|
|
2863
|
-
assertKey(
|
|
2864
|
-
patch.changes.longPressActionKey,
|
|
2865
|
-
`${path}.longPressActionKey`
|
|
2866
|
-
);
|
|
2867
|
-
}
|
|
2868
2297
|
assertText(patch.changes.title, `${path}.title`);
|
|
2869
|
-
if ((patch.changes.titleSuffixes?.length ?? 0) > 3)
|
|
2870
|
-
fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
|
|
2871
|
-
patch.changes.titleSuffixes?.forEach((suffix, index) => {
|
|
2872
|
-
assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
|
|
2873
|
-
if (!['secondary', 'disabled'].includes(suffix.tone))
|
|
2874
|
-
fail(
|
|
2875
|
-
`${path}.titleSuffixes[${index}].tone`,
|
|
2876
|
-
'must be secondary or disabled'
|
|
2877
|
-
);
|
|
2878
|
-
if (
|
|
2879
|
-
suffix.maxWidth !== undefined &&
|
|
2880
|
-
(!Number.isFinite(suffix.maxWidth) ||
|
|
2881
|
-
suffix.maxWidth < 0 ||
|
|
2882
|
-
suffix.maxWidth > 4096)
|
|
2883
|
-
)
|
|
2884
|
-
fail(
|
|
2885
|
-
`${path}.titleSuffixes[${index}].maxWidth`,
|
|
2886
|
-
'must be finite within 0...4096'
|
|
2887
|
-
);
|
|
2888
|
-
});
|
|
2889
|
-
assertIdentityExtras(patch.changes, path);
|
|
2890
2298
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
2891
2299
|
assertText(patch.changes.tertiary, `${path}.tertiary`);
|
|
2892
2300
|
if (
|
|
@@ -2935,20 +2343,14 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
|
|
|
2935
2343
|
}
|
|
2936
2344
|
break;
|
|
2937
2345
|
case 'message':
|
|
2938
|
-
if (
|
|
2939
|
-
patch.changes.presentation !== undefined &&
|
|
2940
|
-
patch.changes.presentation !== 'inlineWarning'
|
|
2941
|
-
) {
|
|
2942
|
-
fail(`${path}.presentation`, 'must be inlineWarning');
|
|
2943
|
-
}
|
|
2944
2346
|
assertText(patch.changes.title, `${path}.title`);
|
|
2945
2347
|
assertText(patch.changes.body, `${path}.body`);
|
|
2946
2348
|
assertText(patch.changes.time, `${path}.time`);
|
|
2947
2349
|
if (
|
|
2948
2350
|
patch.changes.bodyLines !== undefined &&
|
|
2949
|
-
![
|
|
2351
|
+
![1, 2, 3].includes(patch.changes.bodyLines)
|
|
2950
2352
|
) {
|
|
2951
|
-
fail(`${path}.bodyLines`, 'must be
|
|
2353
|
+
fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
|
|
2952
2354
|
}
|
|
2953
2355
|
assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
|
|
2954
2356
|
break;
|
|
@@ -2962,23 +2364,6 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
|
|
|
2962
2364
|
patch.changes.columns?.forEach((column, columnIndex) => {
|
|
2963
2365
|
assertKey(column.key, `${path}.columns[${columnIndex}].key`);
|
|
2964
2366
|
assertText(column.text, `${path}.columns[${columnIndex}].text`);
|
|
2965
|
-
assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
|
|
2966
|
-
for (const field of [
|
|
2967
|
-
'textSegments',
|
|
2968
|
-
'secondaryTextSegments',
|
|
2969
|
-
] as const) {
|
|
2970
|
-
column[field]?.forEach((segment, segmentIndex) => {
|
|
2971
|
-
assertText(
|
|
2972
|
-
segment.text,
|
|
2973
|
-
`${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`
|
|
2974
|
-
);
|
|
2975
|
-
if (segment.style !== undefined && segment.style !== 'subscript')
|
|
2976
|
-
fail(
|
|
2977
|
-
`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`,
|
|
2978
|
-
'must be subscript'
|
|
2979
|
-
);
|
|
2980
|
-
});
|
|
2981
|
-
}
|
|
2982
2367
|
assertText(
|
|
2983
2368
|
column.secondaryText,
|
|
2984
2369
|
`${path}.columns[${columnIndex}].secondaryText`
|
|
@@ -2991,13 +2376,6 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
|
|
|
2991
2376
|
if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
|
|
2992
2377
|
fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
|
|
2993
2378
|
}
|
|
2994
|
-
if ((patch.changes.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
|
|
2995
|
-
fail(
|
|
2996
|
-
`${path}.trailing`,
|
|
2997
|
-
`supports at most ${MAX_TRAILING_ACCESSORIES} accessories`
|
|
2998
|
-
);
|
|
2999
|
-
}
|
|
3000
|
-
assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
|
|
3001
2379
|
break;
|
|
3002
2380
|
case 'market':
|
|
3003
2381
|
assertMarketRow(
|
|
@@ -3072,14 +2450,6 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
|
|
|
3072
2450
|
assertText(patch.changes.title, `${path}.title`);
|
|
3073
2451
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
3074
2452
|
assertText(patch.changes.value, `${path}.value`);
|
|
3075
|
-
if (patch.changes.leadingBadge) {
|
|
3076
|
-
assertKey(patch.changes.leadingBadge.key, `${path}.leadingBadge.key`);
|
|
3077
|
-
assertText(
|
|
3078
|
-
patch.changes.leadingBadge.text,
|
|
3079
|
-
`${path}.leadingBadge.text`
|
|
3080
|
-
);
|
|
3081
|
-
}
|
|
3082
|
-
assertTextHelp(patch.changes.valueHelp, `${path}.valueHelp`);
|
|
3083
2453
|
if (patch.changes.valueActionKey !== undefined) {
|
|
3084
2454
|
assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
|
|
3085
2455
|
}
|
|
@@ -3102,10 +2472,6 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
|
|
|
3102
2472
|
}
|
|
3103
2473
|
assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
|
|
3104
2474
|
break;
|
|
3105
|
-
case 'buttonGroup':
|
|
3106
|
-
if (patch.changes.buttons !== undefined)
|
|
3107
|
-
assertButtonGroup({ buttons: patch.changes.buttons }, path);
|
|
3108
|
-
break;
|
|
3109
2475
|
case 'system':
|
|
3110
2476
|
assertText(patch.changes.message, `${path}.message`);
|
|
3111
2477
|
break;
|
|
@@ -3129,8 +2495,6 @@ export function validatePatches(
|
|
|
3129
2495
|
protocolObject(patch.changes, `patches[${index}].changes`);
|
|
3130
2496
|
assertRowType(patch.type, `patches[${index}]`);
|
|
3131
2497
|
assertProtocolFields(patch.changes, `patches[${index}].changes`);
|
|
3132
|
-
if (patch.type === 'identity')
|
|
3133
|
-
assertIdentityExtras(patch.changes, `patches[${index}].changes`);
|
|
3134
2498
|
if (!isDevelopment()) continue;
|
|
3135
2499
|
assertKey(patch.key, `patches[${index}].key`);
|
|
3136
2500
|
if (Object.keys(patch.changes).length === 0) {
|
|
@@ -3207,85 +2571,6 @@ export function applyRowPatches(
|
|
|
3207
2571
|
return validateSnapshot({ ...snapshot, rows });
|
|
3208
2572
|
}
|
|
3209
2573
|
|
|
3210
|
-
/** Native wrapper only: preserve full public validation for unsupported patches. */
|
|
3211
|
-
export function applyOwnedNativePatches(
|
|
3212
|
-
snapshot: NativeListSnapshot,
|
|
3213
|
-
patches: readonly RowPatch[]
|
|
3214
|
-
): {
|
|
3215
|
-
patches: readonly RowPatch[];
|
|
3216
|
-
snapshot: NativeListSnapshot;
|
|
3217
|
-
json: string;
|
|
3218
|
-
} {
|
|
3219
|
-
const acceptedPatches = deepFreeze(
|
|
3220
|
-
validatePatches(capturePlainData(patches))
|
|
3221
|
-
);
|
|
3222
|
-
const rowIndexes = ownedNativeSnapshots.get(snapshot);
|
|
3223
|
-
const canPatchRows =
|
|
3224
|
-
rowIndexes !== undefined &&
|
|
3225
|
-
acceptedPatches.every((patch) => {
|
|
3226
|
-
const index = rowIndexes.get(patch.key);
|
|
3227
|
-
if (index === undefined || snapshot.rows[index].type !== patch.type)
|
|
3228
|
-
return false;
|
|
3229
|
-
const allowed =
|
|
3230
|
-
patch.type === 'identity'
|
|
3231
|
-
? ['subtitle', 'subtitleSegments', 'trailing']
|
|
3232
|
-
: patch.type === 'dataRow'
|
|
3233
|
-
? ['columns', 'trailing']
|
|
3234
|
-
: undefined;
|
|
3235
|
-
return (
|
|
3236
|
-
allowed !== undefined &&
|
|
3237
|
-
Object.entries(patch.changes).every(
|
|
3238
|
-
([key, value]) =>
|
|
3239
|
-
allowed.includes(key) &&
|
|
3240
|
-
(value !== undefined ||
|
|
3241
|
-
(snapshot.rows[index] as unknown as Record<string, unknown>)[
|
|
3242
|
-
key
|
|
3243
|
-
] === undefined)
|
|
3244
|
-
)
|
|
3245
|
-
);
|
|
3246
|
-
});
|
|
3247
|
-
if (!canPatchRows) {
|
|
3248
|
-
const baseline = rowIndexes ? snapshot : capturePlainData(snapshot);
|
|
3249
|
-
return {
|
|
3250
|
-
patches: acceptedPatches,
|
|
3251
|
-
snapshot: ownValidatedNativeSnapshot(
|
|
3252
|
-
applyRowPatches(baseline, acceptedPatches)
|
|
3253
|
-
),
|
|
3254
|
-
json: JSON.stringify(acceptedPatches),
|
|
3255
|
-
};
|
|
3256
|
-
}
|
|
3257
|
-
|
|
3258
|
-
const nextRows = snapshot.rows.slice();
|
|
3259
|
-
for (const patch of acceptedPatches) {
|
|
3260
|
-
const index = rowIndexes.get(patch.key)!;
|
|
3261
|
-
const previous = nextRows[index];
|
|
3262
|
-
const merged = {
|
|
3263
|
-
...previous,
|
|
3264
|
-
...patch.changes,
|
|
3265
|
-
key: previous.key,
|
|
3266
|
-
type: previous.type,
|
|
3267
|
-
} as RowModel;
|
|
3268
|
-
const path = `rows[${index}]`;
|
|
3269
|
-
assertPlainSerializable(merged, path, new Set<object>());
|
|
3270
|
-
if (isDevelopment()) assertRow(merged, index);
|
|
3271
|
-
const normalized = isDevelopment()
|
|
3272
|
-
? merged
|
|
3273
|
-
: (normalizeEmptyImages(merged) as RowModel);
|
|
3274
|
-
assertRowProtocol(normalized, path);
|
|
3275
|
-
nextRows[index] = deepFreeze(normalizeRowStyles(normalized));
|
|
3276
|
-
}
|
|
3277
|
-
const nextSnapshot = Object.freeze({
|
|
3278
|
-
...snapshot,
|
|
3279
|
-
rows: Object.freeze(nextRows),
|
|
3280
|
-
});
|
|
3281
|
-
ownedNativeSnapshots.set(nextSnapshot, rowIndexes);
|
|
3282
|
-
return {
|
|
3283
|
-
patches: acceptedPatches,
|
|
3284
|
-
snapshot: nextSnapshot,
|
|
3285
|
-
json: JSON.stringify(acceptedPatches),
|
|
3286
|
-
};
|
|
3287
|
-
}
|
|
3288
|
-
|
|
3289
2574
|
export function serializeSnapshot(snapshot: NativeListSnapshot): string {
|
|
3290
2575
|
return JSON.stringify(validateSnapshot(snapshot));
|
|
3291
2576
|
}
|