@onekeyfe/react-native-native-list 6.7.0-alpha.343 → 6.7.0-alpha.354

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.
Files changed (113) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +7 -0
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +87 -7
  8. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +135 -1
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +17 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  16. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  18. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +585 -21
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
  20. package/docs/ROW_TEMPLATES.md +60 -9
  21. package/docs/SPEC.md +361 -8
  22. package/docs/STYLE_SPEC.md +6 -0
  23. package/ios/HybridNativeList.swift +10 -0
  24. package/ios/NativeListAccessoryStack.swift +220 -37
  25. package/ios/NativeListActivityDetailsView.swift +18 -8
  26. package/ios/NativeListActivityRenderer.swift +8 -2
  27. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  28. package/ios/NativeListDataRowRenderer.swift +105 -8
  29. package/ios/NativeListDesignAssets.swift +3 -0
  30. package/ios/NativeListIdentityRenderer.swift +119 -4
  31. package/ios/NativeListLeadingVisual.swift +49 -14
  32. package/ios/NativeListMessageRenderer.swift +34 -1
  33. package/ios/NativeListModels.swift +16 -2
  34. package/ios/NativeListRendererRegistry.swift +1 -0
  35. package/ios/NativeListResolvedText.swift +2 -1
  36. package/ios/NativeListRowHost.swift +14 -0
  37. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  38. package/ios/RNCNativeListView.swift +331 -29
  39. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  40. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  41. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  42. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  45. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  46. package/ios/tests/NativeListLifecycleTests.swift +890 -3
  47. package/lib/module/NativeList.js +64 -27
  48. package/lib/module/NativeList.web.js +84 -17
  49. package/lib/module/models.js +1 -0
  50. package/lib/module/selection.js +1 -1
  51. package/lib/module/validation.js +532 -18
  52. package/lib/module/web/NativeListWebEngine.js +391 -24
  53. package/lib/module/web/templates/ActivityRowRenderer.js +8 -7
  54. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  55. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  56. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  57. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  58. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  59. package/lib/module/web/templates/RowRendererRegistry.js +3 -0
  60. package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
  61. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  62. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  63. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  64. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  65. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  66. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  67. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  68. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  69. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  70. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  71. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  72. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  73. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  74. package/lib/typescript/src/NativeList.d.ts +2 -2
  75. package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
  76. package/lib/typescript/src/NativeList.types.d.ts +8 -0
  77. package/lib/typescript/src/models.d.ts +101 -9
  78. package/lib/typescript/src/validation.d.ts +13 -0
  79. package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -0
  80. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  81. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  82. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
  83. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  84. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  85. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  87. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  88. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  89. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  90. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  91. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  92. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  93. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  94. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  95. package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  96. package/package.json +3 -3
  97. package/react-native-native-list.podspec +1 -0
  98. package/src/NativeList.nitro.ts +1 -0
  99. package/src/NativeList.tsx +155 -69
  100. package/src/NativeList.types.ts +9 -0
  101. package/src/NativeList.web.tsx +159 -49
  102. package/src/models.ts +113 -3
  103. package/src/selection.ts +1 -0
  104. package/src/validation.ts +1156 -18
  105. package/src/web/NativeListWebEngine.ts +594 -28
  106. package/src/web/templates/ActivityRowRenderer.ts +14 -6
  107. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  108. package/src/web/templates/DataRowRenderer.ts +93 -20
  109. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  110. package/src/web/templates/MessageRowRenderer.ts +23 -7
  111. package/src/web/templates/RowContainerStyle.ts +2 -0
  112. package/src/web/templates/RowRendererRegistry.ts +11 -1
  113. package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
package/src/validation.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ROW_BOX_STYLE_KEYS_BY_TYPE } from './models';
2
2
  import type {
3
3
  ActivityRow,
4
+ ButtonGroupRow,
4
5
  IdentityRow,
5
6
  ImageSource,
6
7
  LeadingVisual,
@@ -13,6 +14,7 @@ import type {
13
14
  RowBoxStyle,
14
15
  RowModel,
15
16
  RowPatch,
17
+ RowTextHelp,
16
18
  WalletGroupRow,
17
19
  WebMarketTableCell,
18
20
  WebMarketTablePresentation,
@@ -31,8 +33,42 @@ const MAX_SPACER_HEIGHT = 512;
31
33
  const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
32
34
  const MAX_MARKET_BADGES = 3;
33
35
 
36
+ function isDevelopment(): boolean {
37
+ return typeof __DEV__ !== 'undefined' && __DEV__;
38
+ }
39
+
40
+ class NativeListInputError extends Error {
41
+ constructor(readonly path: string, readonly reason: string) {
42
+ super(`NativeList ${path}: ${reason}`);
43
+ }
44
+ }
45
+
34
46
  function fail(path: string, message: string): never {
35
- throw new Error(`NativeList ${path}: ${message}`);
47
+ throw new NativeListInputError(path, message);
48
+ }
49
+
50
+ /** Component boundaries report locations, never caller-controlled payload values. */
51
+ export function containNativeListInput<T>(operation: () => T): T | undefined {
52
+ try {
53
+ return operation();
54
+ } catch (error) {
55
+ const path = error instanceof NativeListInputError ? error.path : 'input';
56
+ const reason =
57
+ isDevelopment() && error instanceof NativeListInputError
58
+ ? `: ${error.reason.split('"')[0].trim()}`
59
+ : '';
60
+ console.warn(`NativeList rejected invalid input at ${path}${reason}`);
61
+ return undefined;
62
+ }
63
+ }
64
+
65
+ export function emptyNativeListSnapshot(): NativeListSnapshot {
66
+ return {
67
+ schemaVersion: 1,
68
+ generation: 0,
69
+ layout: { kind: 'linear' },
70
+ rows: [],
71
+ };
36
72
  }
37
73
 
38
74
  function assertPlainSerializable(
@@ -72,16 +108,14 @@ function assertPlainSerializable(
72
108
  function assertKey(key: string, path: string): void {
73
109
  if (
74
110
  typeof key !== 'string' ||
75
- key.length === 0 ||
111
+ key.trim().length === 0 ||
76
112
  key.length > MAX_KEY_LENGTH
77
113
  ) {
78
114
  fail(
79
115
  path,
80
- `must be a non-empty string no longer than ${MAX_KEY_LENGTH} characters`
116
+ `must be a non-blank string no longer than ${MAX_KEY_LENGTH} characters`
81
117
  );
82
118
  }
83
- if (key.trim() !== key)
84
- fail(path, 'must not have leading or trailing whitespace');
85
119
  }
86
120
 
87
121
  function assertText(text: string | undefined, path: string): void {
@@ -188,12 +222,14 @@ const TEXT_STYLE_KEYS_BY_ROW_TYPE: Readonly<
188
222
  metricCard: ['title', 'value', 'subtitle', 'trend'],
189
223
  sectionHeader: ['title', 'subtitle', 'value'],
190
224
  action: ['title', 'value'],
225
+ buttonGroup: [],
191
226
  system: ['title', 'message', 'actionText'],
192
227
  };
193
228
 
194
229
  const EXTRA_STYLE_KEYS_BY_ROW_TYPE: Readonly<
195
230
  Partial<Record<RowModel['type'], readonly string[]>>
196
231
  > = {
232
+ identity: ['leadingContentMaxWidthRatio'],
197
233
  market: [
198
234
  'titleBadgeLayout',
199
235
  'contentTrailingGap',
@@ -202,6 +238,7 @@ const EXTRA_STYLE_KEYS_BY_ROW_TYPE: Readonly<
202
238
  'changeHeight',
203
239
  'changeCornerRadius',
204
240
  ],
241
+ sectionHeader: ['valuePlacement', 'titleDecoration'],
205
242
  };
206
243
 
207
244
  function assertTextStyle(
@@ -460,6 +497,33 @@ function assertRowStyle(row: RowModel, path: string): void {
460
497
  // Market keeps its own richer assertions, driven from assertMarketRow.
461
498
  if (row.type === 'market') return;
462
499
  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
+ }
463
527
  const slots = style as Record<string, NativeListTextStyle | undefined>;
464
528
  textKeys.forEach((key) =>
465
529
  assertTextStyle(slots[key], `${path}.style.${key}`)
@@ -1017,6 +1081,55 @@ function assertTrailingAccessories(
1017
1081
  ): void {
1018
1082
  accessories?.forEach((accessory, index) => {
1019
1083
  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');
1020
1133
  if (
1021
1134
  accessory.kind === 'progress' &&
1022
1135
  (accessory.value < 0 || accessory.value > 1)
@@ -1024,12 +1137,160 @@ function assertTrailingAccessories(
1024
1137
  fail(`${accessoryPath}.value`, 'must be within 0...1');
1025
1138
  }
1026
1139
  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`);
1027
1149
  assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
1028
1150
  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
+ }
1029
1183
  }
1030
1184
  });
1031
1185
  }
1032
1186
 
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
+
1033
1294
  function assertImage(image: ImageSource | undefined, path: string): void {
1034
1295
  if (!image) return;
1035
1296
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
@@ -1100,6 +1361,24 @@ function assertLeadingVisual(
1100
1361
  assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
1101
1362
  // OneKey patch: validate optional selector overlays at the JSON boundary.
1102
1363
  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');
1103
1382
  if ((visual.overlays?.length ?? 0) > 2)
1104
1383
  fail(`${path}.overlays`, 'supports at most two overlays');
1105
1384
  visual.overlays?.forEach((overlay, index) => {
@@ -1159,7 +1438,34 @@ function assertLeadingVisual(
1159
1438
  'must fit inside the overlay'
1160
1439
  );
1161
1440
  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
+ );
1162
1460
  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
+ );
1163
1469
  });
1164
1470
  if (visual.kind === 'token') {
1165
1471
  assertImage(visual.networkImage, `${path}.networkImage`);
@@ -1191,6 +1497,8 @@ function assertVisual(row: RowModel, path: string): void {
1191
1497
  }
1192
1498
 
1193
1499
  function assertActivity(row: Partial<ActivityRow>, path: string): void {
1500
+ if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean')
1501
+ fail(`${path}.hideLeading`, 'must be boolean');
1194
1502
  assertText(row.title, `${path}.title`);
1195
1503
  assertText(row.description, `${path}.description`);
1196
1504
  if (
@@ -1355,6 +1663,18 @@ function assertRow(
1355
1663
  assertWalletGroup(row, path);
1356
1664
  break;
1357
1665
  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
+ }
1358
1678
  if (
1359
1679
  row.presentation !== undefined &&
1360
1680
  row.presentation !== 'walletSidebar' &&
@@ -1367,6 +1687,27 @@ function assertRow(
1367
1687
  );
1368
1688
  }
1369
1689
  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);
1370
1711
  assertText(row.subtitle, `${path}.subtitle`);
1371
1712
  // OneKey patch: selector text segments truncate independently.
1372
1713
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -1434,10 +1775,16 @@ function assertRow(
1434
1775
  assertActivity(row, path);
1435
1776
  break;
1436
1777
  case 'message':
1778
+ if (
1779
+ row.presentation !== undefined &&
1780
+ row.presentation !== 'inlineWarning'
1781
+ ) {
1782
+ fail(`${path}.presentation`, 'must be inlineWarning');
1783
+ }
1437
1784
  assertText(row.title, `${path}.title`);
1438
1785
  assertText(row.body, `${path}.body`);
1439
- if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
1440
- fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
1786
+ if (![0, 1, 2, 3].includes(row.bodyLines ?? 3)) {
1787
+ fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
1441
1788
  }
1442
1789
  assertImage(row.thumbnail, `${path}.thumbnail`);
1443
1790
  break;
@@ -1448,6 +1795,23 @@ function assertRow(
1448
1795
  row.columns.forEach((column, columnIndex) => {
1449
1796
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
1450
1797
  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
+ }
1451
1815
  assertText(
1452
1816
  column.secondaryLeadingText,
1453
1817
  `${path}.columns[${columnIndex}].secondaryLeadingText`
@@ -1464,6 +1828,13 @@ function assertRow(
1464
1828
  if ((row.badges?.length ?? 0) > MAX_BADGES) {
1465
1829
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
1466
1830
  }
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`);
1467
1838
  break;
1468
1839
  case 'market':
1469
1840
  assertMarketRow(row, path);
@@ -1540,6 +1911,11 @@ function assertRow(
1540
1911
  assertText(row.title, `${path}.title`);
1541
1912
  assertText(row.subtitle, `${path}.subtitle`);
1542
1913
  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`);
1543
1919
  if (row.valueActionKey !== undefined) {
1544
1920
  assertKey(row.valueActionKey, `${path}.valueActionKey`);
1545
1921
  }
@@ -1572,6 +1948,9 @@ function assertRow(
1572
1948
  }
1573
1949
  assertTrailingAccessories(row.trailing, `${path}.trailing`);
1574
1950
  break;
1951
+ case 'buttonGroup':
1952
+ assertButtonGroup(row, path);
1953
+ break;
1575
1954
  case 'system':
1576
1955
  const presentation = 'presentation' in row ? row.presentation : undefined;
1577
1956
  if (presentation !== undefined && presentation !== 'market') {
@@ -1677,9 +2056,29 @@ function assertMediaPreview(value: unknown, path: string) {
1677
2056
  }
1678
2057
  }
1679
2058
 
1680
- export function validateSnapshot(
2059
+ function assertSnapshotContract(
1681
2060
  snapshot: NativeListSnapshot
1682
2061
  ): 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
+ }
1683
2082
  if (
1684
2083
  snapshot.capabilities?.refreshTriggerDistance !== undefined &&
1685
2084
  (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) ||
@@ -1695,6 +2094,18 @@ export function validateSnapshot(
1695
2094
  snapshot.theme?.imageFallbackBackground,
1696
2095
  'theme.imageFallbackBackground'
1697
2096
  );
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');
1698
2109
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
1699
2110
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
1700
2111
  fail('snapshot.generation', 'must be a non-negative safe integer');
@@ -1826,7 +2237,558 @@ export function validateSnapshot(
1826
2237
  'supports at most one key in single mode'
1827
2238
  );
1828
2239
  }
1829
- return normalizeSnapshotStyles(snapshot);
2240
+ return snapshot;
2241
+ }
2242
+
2243
+ function protocolObject(value: unknown, path: string): Record<string, unknown> {
2244
+ if (!value || typeof value !== 'object' || Array.isArray(value))
2245
+ fail(path, 'must be an object');
2246
+ return value as Record<string, unknown>;
2247
+ }
2248
+
2249
+ function protocolKey(value: unknown, path: string): void {
2250
+ if (typeof value !== 'string' || value.trim().length === 0)
2251
+ fail(path, 'must be a non-blank string');
2252
+ }
2253
+
2254
+ const PROTOCOL_ARRAY_FIELDS = new Set([
2255
+ 'columns',
2256
+ 'titleSuffixes',
2257
+ 'cells',
2258
+ 'points',
2259
+ 'images',
2260
+ 'overlays',
2261
+ 'badges',
2262
+ 'trailing',
2263
+ 'footerActions',
2264
+ 'buttons',
2265
+ 'amounts',
2266
+ 'metrics',
2267
+ 'children',
2268
+ 'subtitleSegments',
2269
+ 'titleMatch',
2270
+ 'selectedKeys',
2271
+ 'segments',
2272
+ 'hoverSecondary',
2273
+ 'hoverImages',
2274
+ 'secondaryBadges',
2275
+ 'fallbackUris',
2276
+ 'probeOrder',
2277
+ 'priceSegments',
2278
+ 'textSegments',
2279
+ 'secondaryTextSegments',
2280
+ 'primaryTextSegments',
2281
+ ]);
2282
+ const PROTOCOL_NUMBER_FIELDS = new Set([
2283
+ 'leadingContentMaxWidthRatio',
2284
+ 'height',
2285
+ 'width',
2286
+ 'fontSize',
2287
+ 'lineHeight',
2288
+ 'opacity',
2289
+ 'offsetY',
2290
+ 'offsetX',
2291
+ 'cornerRadius',
2292
+ 'borderWidth',
2293
+ 'horizontalPadding',
2294
+ 'verticalPadding',
2295
+ 'leadingGap',
2296
+ 'lineGap',
2297
+ 'titleBadgeGap',
2298
+ 'trailingGap',
2299
+ 'start',
2300
+ 'end',
2301
+ 'padding',
2302
+ 'offset',
2303
+ 'overscan',
2304
+ 'minWidth',
2305
+ 'flex',
2306
+ 'paddingStart',
2307
+ 'paddingEnd',
2308
+ 'changeWidth',
2309
+ 'changeHeight',
2310
+ 'changeCornerRadius',
2311
+ 'contentTrailingGap',
2312
+ 'subtitleTrailingPadding',
2313
+ 'partGap',
2314
+ 'contentPadding',
2315
+ 'contentPaddingHorizontal',
2316
+ 'contentPaddingTop',
2317
+ 'contentPaddingBottom',
2318
+ 'itemSpacing',
2319
+ 'gridColumns',
2320
+ ]);
2321
+
2322
+ /** Validate only shapes that renderers dereference, not display budgets. */
2323
+ function assertProtocolFields(
2324
+ value: unknown,
2325
+ path: string,
2326
+ parentField = ''
2327
+ ): void {
2328
+ if (value === undefined || value === null || typeof value !== 'object')
2329
+ return;
2330
+ if (Array.isArray(value)) {
2331
+ for (const [index, item] of value.entries()) {
2332
+ const itemPath = `${path}[${index}]`;
2333
+ if (
2334
+ ['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)
2335
+ ) {
2336
+ if (typeof item !== 'string') fail(itemPath, 'must be a string');
2337
+ } else if (parentField === 'points') {
2338
+ if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
2339
+ } else if (parentField === 'hoverImages' && item === null) continue;
2340
+ else protocolObject(item, itemPath);
2341
+ assertProtocolFields(item, itemPath, parentField);
2342
+ }
2343
+ return;
2344
+ }
2345
+ 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
+ if (
2373
+ !path.includes('.style.') &&
2374
+ ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(
2375
+ parentField
2376
+ ) &&
2377
+ typeof object.uri !== 'string'
2378
+ )
2379
+ fail(`${path}.uri`, 'must be a string');
2380
+ Object.entries(value).forEach(([field, item]) => {
2381
+ if (item === undefined) return;
2382
+ const fieldPath = `${path}.${field}`;
2383
+ if (
2384
+ !path.endsWith('.style') &&
2385
+ PROTOCOL_ARRAY_FIELDS.has(field) &&
2386
+ !Array.isArray(item)
2387
+ )
2388
+ fail(fieldPath, 'must be an array');
2389
+ if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number')
2390
+ fail(fieldPath, 'must be a finite number');
2391
+ if (
2392
+ PROTOCOL_NUMBER_FIELDS.has(field) &&
2393
+ typeof item === 'number' &&
2394
+ item < 0 &&
2395
+ !['offsetX', 'offsetY'].includes(field)
2396
+ )
2397
+ 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
+ if (
2409
+ field === 'key' ||
2410
+ field === 'sectionKey' ||
2411
+ field === 'actionKey' ||
2412
+ field.endsWith('ActionKey')
2413
+ )
2414
+ protocolKey(item, fieldPath);
2415
+ if (
2416
+ (field === 'uri' || field === 'fallbackUri') &&
2417
+ typeof item !== 'string'
2418
+ )
2419
+ fail(fieldPath, 'must be a string');
2420
+ if (
2421
+ (field === 'style' &&
2422
+ !(item === 'subscript' && /[Ss]egments\[/.test(path))) ||
2423
+ field === 'container'
2424
+ )
2425
+ protocolObject(item, fieldPath);
2426
+ if (
2427
+ path.endsWith('.style') &&
2428
+ [
2429
+ 'title',
2430
+ 'subtitle',
2431
+ 'tertiary',
2432
+ 'body',
2433
+ 'time',
2434
+ 'price',
2435
+ 'change',
2436
+ 'columns',
2437
+ 'columnSecondary',
2438
+ 'value',
2439
+ 'valueSecondary',
2440
+ 'badge',
2441
+ 'description',
2442
+ 'status',
2443
+ 'primaryAmount',
2444
+ 'secondaryAmount',
2445
+ 'trend',
2446
+ 'message',
2447
+ 'actionText',
2448
+ ].includes(field)
2449
+ )
2450
+ protocolObject(item, fieldPath);
2451
+ assertProtocolFields(item, fieldPath, field);
2452
+ });
2453
+ }
2454
+
2455
+ function assertRowProtocol(row: RowModel, path: string): void {
2456
+ protocolObject(row, path);
2457
+ assertRowType(row.type, path);
2458
+ protocolKey(row.key, `${path}.key`);
2459
+ assertProtocolFields(row, path);
2460
+ for (const field of ['leading', 'visual', 'secondaryLeading'] as const) {
2461
+ const visual = (row as unknown as Record<string, unknown>)[field];
2462
+ if (
2463
+ visual !== undefined ||
2464
+ (field === 'leading' &&
2465
+ (row.type === 'identity' || row.type === 'market'))
2466
+ ) {
2467
+ const object = protocolObject(visual, `${path}.${field}`);
2468
+ if (object.kind === 'stackedImages' && !Array.isArray(object.images))
2469
+ fail(`${path}.${field}.images`, 'must be an array');
2470
+ }
2471
+ }
2472
+ for (const field of [
2473
+ 'title',
2474
+ 'subtitle',
2475
+ 'tertiary',
2476
+ 'body',
2477
+ 'time',
2478
+ 'price',
2479
+ 'indexTitle',
2480
+ ] as const) {
2481
+ const value = (row as unknown as Record<string, unknown>)[field];
2482
+ if (value !== undefined && typeof value !== 'string')
2483
+ fail(`${path}.${field}`, 'must be a string');
2484
+ }
2485
+ if (row.height !== undefined && row.height < 0)
2486
+ fail(`${path}.height`, 'must be non-negative');
2487
+ 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
+ let end = 0;
2510
+ row.titleMatch?.forEach((match) => {
2511
+ if (
2512
+ !Number.isInteger(match.start) ||
2513
+ !Number.isInteger(match.end) ||
2514
+ match.start < end ||
2515
+ match.end <= match.start ||
2516
+ match.end > row.title.length
2517
+ )
2518
+ fail(`${path}.titleMatch`, 'invalid text range');
2519
+ end = match.end;
2520
+ });
2521
+ }
2522
+ if (row.type === 'buttonGroup') assertButtonGroup(row, path);
2523
+ if (row.type === 'sectionHeader')
2524
+ assertTextHelp(row.valueHelp, `${path}.valueHelp`);
2525
+ if (row.type === 'mediaTile' && row.media) {
2526
+ protocolObject(row.media.source, `${path}.media.source`);
2527
+ if (!Array.isArray(row.media.probeOrder))
2528
+ fail(`${path}.media.probeOrder`, 'must be an array');
2529
+ }
2530
+ if (row.type === 'walletGroup') {
2531
+ protocolObject(row.parent, `${path}.parent`);
2532
+ if (!Array.isArray(row.children))
2533
+ fail(`${path}.children`, 'must be an array');
2534
+ const members = [row.parent, ...row.children];
2535
+ const keys = new Set<string>();
2536
+ if (row.parent.key !== row.key)
2537
+ fail(`${path}.parent.key`, 'must match its group');
2538
+ members.forEach((member, index) => {
2539
+ assertRowProtocol(member, `${path}.members[${index}]`);
2540
+ if (member.type !== 'identity' || keys.has(member.key))
2541
+ fail(path, 'invalid wallet member identity');
2542
+ keys.add(member.key);
2543
+ });
2544
+ }
2545
+ if (row.type === 'dataRow') {
2546
+ if (!Array.isArray(row.columns))
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
+ }
2555
+ if (row.type === 'market') {
2556
+ protocolObject(row.change, `${path}.change`);
2557
+ if (row.webTable) {
2558
+ const { columns, cells } = row.webTable;
2559
+ if (
2560
+ !Array.isArray(columns) ||
2561
+ !Array.isArray(cells) ||
2562
+ columns.length !== cells.length
2563
+ )
2564
+ fail(`${path}.webTable`, 'columns and cells must match');
2565
+ const keys = new Set<string>();
2566
+ columns.forEach((column, index) => {
2567
+ protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
2568
+ if (keys.has(column.key) || cells[index]?.key !== column.key)
2569
+ fail(`${path}.webTable`, 'invalid column identity');
2570
+ keys.add(column.key);
2571
+ const cell = cells[index];
2572
+ if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind))
2573
+ fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
2574
+ if (cell.kind === 'asset')
2575
+ protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
2576
+ if (
2577
+ (cell.kind === 'asset' || cell.kind === 'text') &&
2578
+ cell.secondary !== undefined &&
2579
+ !Array.isArray(cell.secondary)
2580
+ )
2581
+ fail(
2582
+ `${path}.webTable.cells[${index}].secondary`,
2583
+ 'must be an array'
2584
+ );
2585
+ if (cell.kind === 'text' && !Array.isArray(cell.primary))
2586
+ fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
2587
+ // The Web renderer spreads samples into Math.min/Math.max.
2588
+ if (
2589
+ cell.kind === 'sparkline' &&
2590
+ (!Array.isArray(cell.points) || cell.points.length > 256)
2591
+ )
2592
+ fail(
2593
+ `${path}.webTable.cells[${index}].points`,
2594
+ 'must be an array of at most 256 samples'
2595
+ );
2596
+ });
2597
+ }
2598
+ }
2599
+ }
2600
+
2601
+ function assertSnapshotProtocol(snapshot: NativeListSnapshot): void {
2602
+ 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
+ if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
2640
+ if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0)
2641
+ fail('snapshot.generation', 'must be a non-negative safe integer');
2642
+ protocolObject(snapshot.layout, 'snapshot.layout');
2643
+ assertProtocolFields(snapshot.layout, 'snapshot.layout');
2644
+ if (
2645
+ snapshot.layout.orientation !== undefined &&
2646
+ !['vertical', 'horizontal'].includes(snapshot.layout.orientation)
2647
+ )
2648
+ fail('snapshot.layout.orientation', 'is not supported');
2649
+ if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind))
2650
+ fail('snapshot.layout.kind', 'is not supported');
2651
+ if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
2652
+ if (
2653
+ snapshot.layout.kind === 'grid' &&
2654
+ (!Number.isInteger(snapshot.layout.gridColumns) ||
2655
+ (snapshot.layout.gridColumns ?? 0) < 1 ||
2656
+ (snapshot.layout.gridColumns ?? 0) > 7)
2657
+ )
2658
+ fail('snapshot.layout.gridColumns', 'must be an integer from 1 to 7');
2659
+ const keys = new Set<string>();
2660
+ for (const [index, row] of snapshot.rows.entries()) {
2661
+ assertRowProtocol(row, `rows[${index}]`);
2662
+ if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
2663
+ keys.add(row.key);
2664
+ }
2665
+ if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
2666
+ if (snapshot.fixedFooter)
2667
+ assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
2668
+ if (snapshot.selection) {
2669
+ if (!Array.isArray(snapshot.selection.selectedKeys))
2670
+ fail('snapshot.selection.selectedKeys', 'must be an array');
2671
+ snapshot.selection.selectedKeys.forEach((key) => {
2672
+ if (!keys.has(key))
2673
+ fail('snapshot.selection.selectedKeys', 'unknown row identity');
2674
+ });
2675
+ }
2676
+ }
2677
+
2678
+ /** Empty optional image descriptors must take the same path as absent images. */
2679
+ function normalizeEmptyImages(value: unknown, field = ''): unknown {
2680
+ if (!value || typeof value !== 'object') return value;
2681
+ if (Array.isArray(value)) {
2682
+ const next = value.map((item) => normalizeEmptyImages(item));
2683
+ const filtered =
2684
+ field === 'images'
2685
+ ? next.filter((item) => item !== undefined)
2686
+ : next.map((item) => (item === undefined ? null : item));
2687
+ return filtered.length === value.length &&
2688
+ filtered.every((item, index) => item === value[index])
2689
+ ? value
2690
+ : filtered;
2691
+ }
2692
+ const object = value as Record<string, unknown>;
2693
+ if (
2694
+ typeof object.uri === 'string' &&
2695
+ !object.uri.trim() &&
2696
+ 'width' in object &&
2697
+ 'height' in object
2698
+ )
2699
+ return undefined;
2700
+ let changed = false;
2701
+ const next = { ...object };
2702
+ Object.entries(object).forEach(([key, item]) => {
2703
+ const normalized = normalizeEmptyImages(item, key);
2704
+ if (normalized !== item) {
2705
+ // Omitted JSON patch fields must also be absent from the JS merge.
2706
+ if (field === 'changes' && normalized === undefined) delete next[key];
2707
+ else next[key] = normalized;
2708
+ changed = true;
2709
+ }
2710
+ });
2711
+ if (field === 'media' && next.source === undefined) return undefined;
2712
+ return changed ? next : value;
2713
+ }
2714
+
2715
+ export function validateSnapshot(
2716
+ snapshot: NativeListSnapshot
2717
+ ): NativeListSnapshot {
2718
+ assertPlainSerializable(snapshot, 'snapshot', new Set<object>());
2719
+ if (isDevelopment()) assertSnapshotContract(snapshot);
2720
+ const normalized = isDevelopment()
2721
+ ? snapshot
2722
+ : (normalizeEmptyImages(snapshot) as NativeListSnapshot);
2723
+ assertSnapshotProtocol(normalized);
2724
+ return normalizeSnapshotStyles(normalized);
2725
+ }
2726
+
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;
1830
2792
  }
1831
2793
 
1832
2794
  /**
@@ -1885,7 +2847,46 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1885
2847
 
1886
2848
  switch (patch.type) {
1887
2849
  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
+ }
1888
2868
  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);
1889
2890
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1890
2891
  assertText(patch.changes.tertiary, `${path}.tertiary`);
1891
2892
  if (
@@ -1934,14 +2935,20 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1934
2935
  }
1935
2936
  break;
1936
2937
  case 'message':
2938
+ if (
2939
+ patch.changes.presentation !== undefined &&
2940
+ patch.changes.presentation !== 'inlineWarning'
2941
+ ) {
2942
+ fail(`${path}.presentation`, 'must be inlineWarning');
2943
+ }
1937
2944
  assertText(patch.changes.title, `${path}.title`);
1938
2945
  assertText(patch.changes.body, `${path}.body`);
1939
2946
  assertText(patch.changes.time, `${path}.time`);
1940
2947
  if (
1941
2948
  patch.changes.bodyLines !== undefined &&
1942
- ![1, 2, 3].includes(patch.changes.bodyLines)
2949
+ ![0, 1, 2, 3].includes(patch.changes.bodyLines)
1943
2950
  ) {
1944
- fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
2951
+ fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
1945
2952
  }
1946
2953
  assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
1947
2954
  break;
@@ -1955,6 +2962,23 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1955
2962
  patch.changes.columns?.forEach((column, columnIndex) => {
1956
2963
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
1957
2964
  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
+ }
1958
2982
  assertText(
1959
2983
  column.secondaryText,
1960
2984
  `${path}.columns[${columnIndex}].secondaryText`
@@ -1967,6 +2991,13 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1967
2991
  if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
1968
2992
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
1969
2993
  }
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`);
1970
3001
  break;
1971
3002
  case 'market':
1972
3003
  assertMarketRow(
@@ -2041,6 +3072,14 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
2041
3072
  assertText(patch.changes.title, `${path}.title`);
2042
3073
  assertText(patch.changes.subtitle, `${path}.subtitle`);
2043
3074
  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`);
2044
3083
  if (patch.changes.valueActionKey !== undefined) {
2045
3084
  assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
2046
3085
  }
@@ -2063,6 +3102,10 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
2063
3102
  }
2064
3103
  assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
2065
3104
  break;
3105
+ case 'buttonGroup':
3106
+ if (patch.changes.buttons !== undefined)
3107
+ assertButtonGroup({ buttons: patch.changes.buttons }, path);
3108
+ break;
2066
3109
  case 'system':
2067
3110
  assertText(patch.changes.message, `${path}.message`);
2068
3111
  break;
@@ -2075,18 +3118,32 @@ export function validatePatches(
2075
3118
  patches: readonly RowPatch[]
2076
3119
  ): readonly RowPatch[] {
2077
3120
  assertPlainSerializable(patches, 'patches', new Set<object>());
3121
+ if (!Array.isArray(patches)) fail('patches', 'must be an array');
2078
3122
  const keys = new Set<string>();
2079
- patches.forEach((patch, index) => {
2080
- assertKey(patch.key, `patches[${index}].key`);
3123
+ for (const [index, patch] of patches.entries()) {
3124
+ protocolObject(patch, `patches[${index}]`);
3125
+ protocolKey(patch.key, `patches[${index}].key`);
2081
3126
  if (keys.has(patch.key))
2082
3127
  fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
2083
3128
  keys.add(patch.key);
3129
+ protocolObject(patch.changes, `patches[${index}].changes`);
3130
+ assertRowType(patch.type, `patches[${index}]`);
3131
+ assertProtocolFields(patch.changes, `patches[${index}].changes`);
3132
+ if (patch.type === 'identity')
3133
+ assertIdentityExtras(patch.changes, `patches[${index}].changes`);
3134
+ if (!isDevelopment()) continue;
3135
+ assertKey(patch.key, `patches[${index}].key`);
2084
3136
  if (Object.keys(patch.changes).length === 0) {
2085
3137
  fail(`patches[${index}].changes`, 'must contain at least one field');
2086
3138
  }
2087
3139
  assertPatchChanges(patch, index);
2088
- });
2089
- return normalizePatchStyles(patches);
3140
+ }
3141
+ const normalized = isDevelopment()
3142
+ ? patches
3143
+ : (normalizeEmptyImages(patches) as readonly RowPatch[]);
3144
+ return normalizePatchStyles(
3145
+ normalized.filter((patch) => Object.keys(patch.changes).length > 0)
3146
+ );
2090
3147
  }
2091
3148
 
2092
3149
  /** Patches reach the native side without passing through a snapshot. */
@@ -2112,10 +3169,12 @@ export function applyRowPatches(
2112
3169
  snapshot: NativeListSnapshot,
2113
3170
  patches: readonly RowPatch[]
2114
3171
  ): NativeListSnapshot {
2115
- validatePatches(patches);
2116
- const patchByKey = new Map(patches.map((patch) => [patch.key, patch]));
3172
+ const normalizedPatches = validatePatches(patches);
3173
+ const patchByKey = new Map(
3174
+ normalizedPatches.map((patch) => [patch.key, patch])
3175
+ );
2117
3176
  const knownKeys = new Set(snapshot.rows.map((row) => row.key));
2118
- patches.forEach((patch) => {
3177
+ normalizedPatches.forEach((patch) => {
2119
3178
  if (!knownKeys.has(patch.key))
2120
3179
  fail('patches', `unknown row key "${patch.key}"`);
2121
3180
  });
@@ -2148,6 +3207,85 @@ export function applyRowPatches(
2148
3207
  return validateSnapshot({ ...snapshot, rows });
2149
3208
  }
2150
3209
 
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
+
2151
3289
  export function serializeSnapshot(snapshot: NativeListSnapshot): string {
2152
3290
  return JSON.stringify(validateSnapshot(snapshot));
2153
3291
  }