@onekeyfe/react-native-native-list 6.7.0-20 → 6.7.0-22

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 (151) hide show
  1. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +5 -0
  2. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +29 -4
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -10
  4. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  5. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +15 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListGeneratedIcons.kt +47 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +33 -2
  8. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +5 -0
  9. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  10. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +13 -10
  11. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +120 -338
  12. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +5 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +33 -8
  14. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +11 -5
  15. package/docs/ROW_TEMPLATES.md +10 -2
  16. package/docs/SPEC.md +432 -50
  17. package/ios/NativeListAccessoryStack.swift +6 -16
  18. package/ios/NativeListActivityDetailsView.swift +13 -4
  19. package/ios/NativeListDataRowRenderer.swift +15 -6
  20. package/ios/NativeListDesignAssets.swift +13 -84
  21. package/ios/NativeListGeneratedIcons.swift +55 -0
  22. package/ios/NativeListIconBinding.swift +171 -0
  23. package/ios/NativeListIdentityRenderer.swift +69 -13
  24. package/ios/NativeListLeadingVisual.swift +11 -9
  25. package/ios/NativeListMarketRenderer.swift +120 -31
  26. package/ios/NativeListMediaTileRenderer.swift +6 -2
  27. package/ios/NativeListMetricCardRenderer.swift +4 -2
  28. package/ios/NativeListSectionHeaderRenderer.swift +12 -4
  29. package/ios/RNCNativeListView.swift +21 -3
  30. package/ios/tests/NativeListAccessoryStackTests.swift +12 -0
  31. package/ios/tests/NativeListAccountSelectorLayoutTests.swift +96 -0
  32. package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
  33. package/ios/tests/NativeListLifecycleTests.swift +73 -4
  34. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  35. package/ios/tests/NativeListSharedIconTests.swift +236 -0
  36. package/lib/module/NativeList.js +25 -6
  37. package/lib/module/NativeList.web.js +9 -12
  38. package/lib/module/models.js +2 -0
  39. package/lib/module/validation.js +695 -114
  40. package/lib/module/web/NativeListGeneratedIcons.js +31 -0
  41. package/lib/module/web/NativeListWebEngine.js +24 -332
  42. package/lib/module/web/templates/ActivityRowRenderer.js +4 -24
  43. package/lib/module/web/templates/IdentityRowRenderer.js +66 -4
  44. package/lib/module/web/templates/MarketTableRowRenderer.js +36 -19
  45. package/lib/module/web/templates/MediaTileRowRenderer.js +2 -12
  46. package/lib/typescript/src/NativeList.types.d.ts +2 -2
  47. package/lib/typescript/src/models.d.ts +27 -14
  48. package/lib/typescript/src/validation.d.ts +7 -2
  49. package/lib/typescript/src/web/NativeListGeneratedIcons.d.ts +2 -0
  50. package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -1
  51. package/package.json +16 -10
  52. package/react-native-native-list.podspec +0 -5
  53. package/scripts/generate-icons.mjs +150 -0
  54. package/scripts/generate-icons.test.mjs +288 -0
  55. package/scripts/native-list-icons.json +260 -0
  56. package/src/NativeList.tsx +30 -10
  57. package/src/NativeList.types.ts +2 -2
  58. package/src/NativeList.web.tsx +10 -14
  59. package/src/models.ts +158 -153
  60. package/src/validation.ts +1757 -167
  61. package/src/web/NativeListGeneratedIcons.ts +28 -0
  62. package/src/web/NativeListWebEngine.ts +31 -415
  63. package/src/web/templates/ActivityRowRenderer.ts +15 -53
  64. package/src/web/templates/IdentityRowRenderer.ts +78 -4
  65. package/src/web/templates/MarketTableRowRenderer.ts +53 -33
  66. package/src/web/templates/MediaTileRowRenderer.ts +2 -15
  67. package/ios/Resources/NativeListIcons.xcassets/Contents.json +0 -1
  68. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/Contents.json +0 -1
  69. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_bottom.imageset/icon.svg +0 -1
  70. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/Contents.json +0 -1
  71. package/ios/Resources/NativeListIcons.xcassets/onekey_arrow_top.imageset/icon.svg +0 -1
  72. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/Contents.json +0 -1
  73. package/ios/Resources/NativeListIcons.xcassets/onekey_badge_verified_solid.imageset/icon.svg +0 -1
  74. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/Contents.json +0 -1
  75. package/ios/Resources/NativeListIcons.xcassets/onekey_chart_trending_up.imageset/icon.svg +0 -1
  76. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/Contents.json +0 -1
  77. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_checked.imageset/icon.svg +0 -1
  78. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/Contents.json +0 -1
  79. package/ios/Resources/NativeListIcons.xcassets/onekey_checkbox_indeterminate.imageset/icon.svg +0 -1
  80. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/Contents.json +0 -1
  81. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_bottom.imageset/icon.svg +0 -1
  82. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/Contents.json +0 -1
  83. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_grabber_ver.imageset/icon.svg +0 -1
  84. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/Contents.json +0 -1
  85. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_right_small.imageset/icon.svg +0 -1
  86. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/Contents.json +0 -1
  87. package/ios/Resources/NativeListIcons.xcassets/onekey_chevron_top.imageset/icon.svg +0 -1
  88. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +0 -15
  89. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
  90. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +0 -1
  91. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +0 -1
  92. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/Contents.json +0 -1
  93. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_hor.imageset/icon.svg +0 -1
  94. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +0 -1
  95. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +0 -1
  96. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/Contents.json +0 -1
  97. package/ios/Resources/NativeListIcons.xcassets/onekey_drag.imageset/icon.svg +0 -1
  98. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/Contents.json +0 -1
  99. package/ios/Resources/NativeListIcons.xcassets/onekey_error_solid.imageset/icon.svg +0 -1
  100. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +0 -15
  101. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
  102. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/Contents.json +0 -1
  103. package/ios/Resources/NativeListIcons.xcassets/onekey_image_square_waves.imageset/icon.svg +0 -1
  104. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/Contents.json +0 -1
  105. package/ios/Resources/NativeListIcons.xcassets/onekey_info_circle.imageset/icon.svg +0 -1
  106. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/Contents.json +0 -1
  107. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle.imageset/icon.svg +0 -1
  108. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/Contents.json +0 -1
  109. package/ios/Resources/NativeListIcons.xcassets/onekey_minus_circle_solid.imageset/icon.svg +0 -1
  110. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/Contents.json +0 -1
  111. package/ios/Resources/NativeListIcons.xcassets/onekey_pencil.imageset/icon.svg +0 -1
  112. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/Contents.json +0 -1
  113. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_circle.imageset/icon.svg +0 -1
  114. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +0 -1
  115. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +0 -1
  116. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/Contents.json +0 -1
  117. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_small.imageset/icon.svg +0 -1
  118. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/Contents.json +0 -1
  119. package/ios/Resources/NativeListIcons.xcassets/onekey_questionmark_solid.imageset/icon.svg +0 -1
  120. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +0 -15
  121. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
  122. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/Contents.json +0 -15
  123. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_account_error_custom.imageset/icon.svg +0 -14
  124. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/Contents.json +0 -15
  125. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_all_networks_solid.imageset/icon.svg +0 -12
  126. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/Contents.json +0 -15
  127. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_apple_brand.imageset/icon.svg +0 -6
  128. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/Contents.json +0 -15
  129. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_bot_illus.imageset/icon.svg +0 -15
  130. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/Contents.json +0 -15
  131. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_crossed_small_solid.imageset/icon.svg +0 -3
  132. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/Contents.json +0 -15
  133. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_globus_outline.imageset/icon.svg +0 -7
  134. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/Contents.json +0 -15
  135. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_google_illus.imageset/icon.svg +0 -18
  136. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/Contents.json +0 -15
  137. package/ios/Resources/NativeListIcons.xcassets/onekey_selector_lock_solid.imageset/icon.svg +0 -7
  138. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/Contents.json +0 -1
  139. package/ios/Resources/NativeListIcons.xcassets/onekey_shield_exclamation.imageset/icon.svg +0 -1
  140. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/Contents.json +0 -1
  141. package/ios/Resources/NativeListIcons.xcassets/onekey_speaker_promote.imageset/icon.svg +0 -1
  142. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/Contents.json +0 -1
  143. package/ios/Resources/NativeListIcons.xcassets/onekey_star.imageset/icon.svg +0 -1
  144. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/Contents.json +0 -1
  145. package/ios/Resources/NativeListIcons.xcassets/onekey_star_solid.imageset/icon.svg +0 -1
  146. package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/Contents.json +0 -1
  147. package/ios/Resources/NativeListIcons.xcassets/onekey_swap_hor.imageset/icon.svg +0 -1
  148. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +0 -1
  149. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +0 -1
  150. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +0 -1
  151. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +0 -1
@@ -12,6 +12,7 @@ const MAX_HEADER_LENGTH = 4096;
12
12
  const MAX_SPACER_HEIGHT = 512;
13
13
  const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
14
14
  const MAX_MARKET_BADGES = 3;
15
+ const MARKET_METRIC_FIELDS = ['key', 'text', 'textSegments', 'secondaryText', 'secondaryTextSegments', 'weight', 'alignment', 'tone', 'secondaryTone'];
15
16
  function isDevelopment() {
16
17
  return typeof __DEV__ !== 'undefined' && __DEV__;
17
18
  }
@@ -47,12 +48,12 @@ export function emptyNativeListSnapshot() {
47
48
  rows: []
48
49
  };
49
50
  }
50
- function assertPlainSerializable(value, path, seen) {
51
+ function assertPlainSerializable(value, path, seen, requireFinite = true) {
51
52
  if (value === null || value === undefined) return;
52
53
  const valueType = typeof value;
53
54
  if (valueType === 'string' || valueType === 'boolean') return;
54
55
  if (valueType === 'number') {
55
- if (!Number.isFinite(value)) fail(path, 'numbers must be finite');
56
+ if (requireFinite && !Number.isFinite(value)) fail(path, 'numbers must be finite');
56
57
  return;
57
58
  }
58
59
  if (valueType !== 'object') fail(path, 'must contain only plain serializable data');
@@ -60,13 +61,16 @@ function assertPlainSerializable(value, path, seen) {
60
61
  if (seen.has(objectValue)) fail(path, 'must not contain circular references');
61
62
  seen.add(objectValue);
62
63
  if (Array.isArray(value)) {
63
- value.forEach((item, index) => assertPlainSerializable(item, `${path}[${index}]`, seen));
64
+ value.forEach((item, index) => assertPlainSerializable(item, `${path}[${index}]`, seen, requireFinite));
64
65
  } else {
65
66
  const prototype = Object.getPrototypeOf(value);
66
67
  if (prototype !== Object.prototype && prototype !== null) {
67
68
  fail(path, 'must contain plain objects only');
68
69
  }
69
- Object.entries(value).forEach(([key, item]) => assertPlainSerializable(item, `${path}.${key}`, seen));
70
+ Object.entries(value).forEach(([key, item]) => {
71
+ if (key === '__proto__' || key === 'constructor' && typeof item === 'object') fail(path, 'unsafe object key');
72
+ assertPlainSerializable(item, `${path}.${key}`, seen, requireFinite);
73
+ });
70
74
  }
71
75
  seen.delete(objectValue);
72
76
  }
@@ -521,8 +525,56 @@ function assertWebMarketTable(table, path) {
521
525
  }
522
526
  });
523
527
  }
528
+ function assertMarketMetrics(metrics, path) {
529
+ if (metrics === undefined) return;
530
+ if (!Array.isArray(metrics) || ![2, 3].includes(metrics.length)) fail(path, 'must contain 2 or 3 columns');
531
+ const keys = new Set();
532
+ metrics.forEach((column, index) => {
533
+ const columnPath = `${path}[${index}]`;
534
+ const value = protocolObject(column, columnPath);
535
+ protocolKey(value.key, `${columnPath}.key`);
536
+ if (keys.has(column.key)) fail(`${columnPath}.key`, 'must be unique');
537
+ keys.add(column.key);
538
+ if (typeof value.text !== 'string') fail(`${columnPath}.text`, 'must be a string');
539
+ for (const field of ['textSegments', 'secondaryTextSegments']) {
540
+ const segments = column[field];
541
+ if (segments !== undefined && !Array.isArray(segments)) fail(`${columnPath}.${field}`, 'must be an array');
542
+ segments?.forEach((segment, segmentIndex) => {
543
+ const segmentPath = `${columnPath}.${field}[${segmentIndex}]`;
544
+ protocolObject(segment, segmentPath);
545
+ if (typeof segment.text !== 'string') fail(`${segmentPath}.text`, 'must be a string');
546
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(`${segmentPath}.style`, 'must be subscript');
547
+ });
548
+ }
549
+ if (value.weight !== undefined && ![1, 2, 3].includes(value.weight)) fail(`${columnPath}.weight`, 'must be 1, 2, or 3');
550
+ if (value.alignment !== undefined && !['start', 'center', 'end'].includes(value.alignment)) fail(`${columnPath}.alignment`, 'must be start, center, or end');
551
+ if (value.secondaryText !== undefined && typeof value.secondaryText !== 'string') fail(`${columnPath}.secondaryText`, 'must be a string');
552
+ assertTextTone(value.tone, `${columnPath}.tone`);
553
+ assertTextTone(value.secondaryTone, `${columnPath}.secondaryTone`);
554
+ });
555
+ }
524
556
  function assertMarketRow(row, path) {
525
557
  assertWebMarketTable(row.webTable, `${path}.webTable`);
558
+ assertMarketMetrics(row.metrics, `${path}.metrics`);
559
+ if (row.metrics !== undefined) {
560
+ row.metrics.forEach((column, index) => {
561
+ const columnPath = `${path}.metrics[${index}]`;
562
+ const value = protocolObject(column, columnPath);
563
+ assertUnknownKeys(value, MARKET_METRIC_FIELDS, columnPath, 'Market metric key');
564
+ assertKey(column.key, `${columnPath}.key`);
565
+ assertText(column.text, `${columnPath}.text`);
566
+ assertText(column.secondaryText, `${columnPath}.secondaryText`);
567
+ assertTextTone(column.tone, `${columnPath}.tone`);
568
+ assertTextTone(column.secondaryTone, `${columnPath}.secondaryTone`);
569
+ for (const field of ['textSegments', 'secondaryTextSegments']) {
570
+ column[field]?.forEach((segment, segmentIndex) => {
571
+ const segmentPath = `${columnPath}.${field}[${segmentIndex}]`;
572
+ assertText(segment.text, `${segmentPath}.text`);
573
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(`${segmentPath}.style`, 'must be subscript');
574
+ });
575
+ }
576
+ });
577
+ }
526
578
  if (!['token', 'stock', 'perp'].includes(row.variant)) {
527
579
  fail(`${path}.variant`, 'must be token, stock, or perp');
528
580
  }
@@ -662,12 +714,28 @@ function assertIdentityExtras(row, path) {
662
714
  if (titleIcon.accessibilityLabel !== undefined && typeof titleIcon.accessibilityLabel !== 'string') fail(`${iconPath}.accessibilityLabel`, 'must be a string');
663
715
  if (titleIcon.hoverActionKey !== undefined) assertKey(titleIcon.hoverActionKey, `${iconPath}.hoverActionKey`);
664
716
  }
717
+ if (row.titleImage !== undefined) {
718
+ const imagePath = `${path}.titleImage`;
719
+ const descriptor = protocolObject(row.titleImage, imagePath);
720
+ assertUnknownKeys(descriptor, ['image', 'accessibilityLabel', 'hoverActionKey'], imagePath, 'title image key');
721
+ protocolObject(row.titleImage.image, `${imagePath}.image`);
722
+ if (typeof row.titleImage.image.uri !== 'string') fail(`${imagePath}.image.uri`, 'must be a string');
723
+ assertImage(row.titleImage.image, `${imagePath}.image`);
724
+ const {
725
+ width,
726
+ height
727
+ } = row.titleImage.image;
728
+ if (width !== height || width < 1 || width > 40) fail(`${imagePath}.image`, 'must be square within 1...40');
729
+ if (row.titleImage.accessibilityLabel !== undefined && typeof row.titleImage.accessibilityLabel !== 'string') fail(`${imagePath}.accessibilityLabel`, 'must be a string');
730
+ if (row.titleImage.hoverActionKey !== undefined) assertKey(row.titleImage.hoverActionKey, `${imagePath}.hoverActionKey`);
731
+ }
665
732
  const ratio = row.style?.leadingContentMaxWidthRatio;
666
733
  if (ratio !== undefined && (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
667
734
  assertTrailingAccessories(row.trailing, `${path}.trailing`);
668
735
  }
669
736
  function assertImage(image, path) {
670
737
  if (!image) return;
738
+ if (!isAllowedImageUri(image.uri)) fail(`${path}.uri`, 'unsupported image URI');
671
739
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
672
740
  if (image.fallbackUris !== undefined) {
673
741
  if (!Array.isArray(image.fallbackUris)) fail(`${path}.fallbackUris`, 'must be an array');
@@ -826,6 +894,7 @@ function assertRowType(type, path) {
826
894
  }
827
895
  function assertRow(row, index, path = `rows[${index}]`) {
828
896
  assertRowType(row.type, path);
897
+ assertUnknownKeys(row, ROW_FIELDS[row.type], path, 'row key');
829
898
  assertKey(row.key, `${path}.key`);
830
899
  // OneKey patch: explicit dimensions and opacity cannot corrupt list layout.
831
900
  if (row.height !== undefined && (row.height < 0 || row.height > 4096)) fail(`${path}.height`, 'must be within 0...4096');
@@ -1155,6 +1224,37 @@ function assertSnapshotContract(snapshot) {
1155
1224
  }
1156
1225
  return snapshot;
1157
1226
  }
1227
+ const COMMON_ROW_FIELDS = ['height', 'heightRounding', 'testID', 'opacity', 'backgroundColor', 'backgroundFullWidth', 'pressDisabled', 'key', 'revision', 'sectionKey', 'groupId', 'groupPosition', 'size', 'density', 'disabled', 'selected', 'accessibilityLabel', 'separator', 'type', 'style'];
1228
+ const ROW_FIELDS = {
1229
+ identity: [...COMMON_ROW_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'presentation', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'titleLines', 'subtitleLines', 'badges', 'trailing', 'draggable'],
1230
+ walletGroup: [...COMMON_ROW_FIELDS, 'parent', 'children', 'draggable'],
1231
+ rail: [...COMMON_ROW_FIELDS, 'visual', 'title', 'status', 'badge', 'draggable'],
1232
+ activity: [...COMMON_ROW_FIELDS, 'leading', 'hideLeading', 'secondaryLeading', 'title', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'amounts', 'badges', 'presentation', 'fee', 'descriptionActionKey', 'footerActions'],
1233
+ message: [...COMMON_ROW_FIELDS, 'presentation', 'unread', 'leading', 'title', 'body', 'bodyLines', 'time', 'thumbnail'],
1234
+ dataRow: [...COMMON_ROW_FIELDS, 'leading', 'columns', 'trailing', 'checkbox', 'index', 'badge', 'badges', 'favorite', 'favoriteActive'],
1235
+ market: [...COMMON_ROW_FIELDS, 'variant', 'webTable', 'metrics', 'leadingAction', 'leading', 'title', 'subtitle', 'subtitlePrefix', 'subtitleSegments', 'price', 'priceSegments', 'change', 'badges', 'pressActionKey', 'pressInActionKey', 'longPressActionKey', 'diagnostics'],
1236
+ mediaTile: [...COMMON_ROW_FIELDS, 'variant', 'media', 'image', 'imageState', 'networkImage', 'title', 'subtitle', 'badge', 'closeActionKey'],
1237
+ metricCard: [...COMMON_ROW_FIELDS, 'variant', 'title', 'value', 'subtitle', 'trend', 'trendTone', 'visual', 'badge', 'metrics', 'progress'],
1238
+ sectionHeader: [...COMMON_ROW_FIELDS, 'sticky', 'valueActionTestID', 'valueSegments', 'titleActionKey', 'titleActionOnHover', 'presentation', 'indexTitle', 'variant', 'title', 'leadingBadge', 'titleLoading', 'subtitle', 'value', 'valueHelp', 'valueActionKey', 'titleIcon', 'valueIcon', 'checkbox'],
1239
+ action: [...COMMON_ROW_FIELDS, 'presentation', 'title', 'actionKey', 'tone', 'icon', 'checkbox', 'trailing'],
1240
+ buttonGroup: [...COMMON_ROW_FIELDS, 'buttons'],
1241
+ system: [...COMMON_ROW_FIELDS, 'variant', 'presentation', 'loadingStyle', 'message', 'actionKey', 'actionText', 'title', 'borderColor']
1242
+ };
1243
+ const COMMON_PATCH_FIELDS = ['height', 'heightRounding', 'opacity', 'pressDisabled', 'revision', 'disabled', 'selected', 'accessibilityLabel', 'separator', 'style'];
1244
+ const PATCH_FIELDS = {
1245
+ identity: [...COMMON_PATCH_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'subtitleLines', 'badges', 'trailing'],
1246
+ rail: [...COMMON_PATCH_FIELDS, 'title', 'visual', 'status', 'badge'],
1247
+ activity: [...COMMON_PATCH_FIELDS, 'presentation', 'leading', 'title', 'badges', 'status', 'hideLeading', 'secondaryLeading', 'description', 'primaryAmount', 'secondaryAmount', 'amounts', 'fee', 'descriptionActionKey', 'footerActions'],
1248
+ message: [...COMMON_PATCH_FIELDS, 'presentation', 'title', 'unread', 'body', 'bodyLines', 'time', 'thumbnail'],
1249
+ dataRow: [...COMMON_PATCH_FIELDS, 'leading', 'badges', 'trailing', 'badge', 'columns', 'checkbox', 'index', 'favorite', 'favoriteActive'],
1250
+ market: [...COMMON_PATCH_FIELDS, 'longPressActionKey', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'subtitle', 'badges', 'webTable', 'metrics', 'price', 'priceSegments', 'change', 'pressActionKey', 'pressInActionKey', 'diagnostics'],
1251
+ mediaTile: [...COMMON_PATCH_FIELDS, 'title', 'subtitle', 'badge', 'media', 'image', 'imageState', 'networkImage', 'closeActionKey'],
1252
+ metricCard: [...COMMON_PATCH_FIELDS, 'title', 'subtitle', 'visual', 'badge', 'variant', 'value', 'trend', 'trendTone', 'metrics', 'progress'],
1253
+ sectionHeader: [...COMMON_PATCH_FIELDS, 'titleActionKey', 'titleActionOnHover', 'title', 'titleIcon', 'subtitle', 'checkbox', 'variant', 'value', 'leadingBadge', 'titleLoading', 'valueHelp', 'valueActionKey', 'valueIcon'],
1254
+ action: [...COMMON_PATCH_FIELDS, 'title', 'trailing', 'checkbox', 'tone', 'icon'],
1255
+ buttonGroup: [...COMMON_PATCH_FIELDS, 'buttons'],
1256
+ system: ['revision', 'disabled', 'message']
1257
+ };
1158
1258
  function protocolObject(value, path) {
1159
1259
  if (!value || typeof value !== 'object' || Array.isArray(value)) fail(path, 'must be an object');
1160
1260
  return value;
@@ -1193,6 +1293,13 @@ function assertProtocolFields(value, path, parentField = '') {
1193
1293
  if (!path.includes('.style.') && ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(parentField) && typeof object.uri !== 'string') fail(`${path}.uri`, 'must be a string');
1194
1294
  Object.entries(value).forEach(([field, item]) => {
1195
1295
  if (item === undefined) return;
1296
+ if (field === 'headers') {
1297
+ const headers = protocolObject(item, `${path}.headers`);
1298
+ for (const [name, headerValue] of Object.entries(headers)) {
1299
+ if (!name.trim() || typeof headerValue !== 'string') fail(`${path}.headers`, 'must contain string headers');
1300
+ }
1301
+ return;
1302
+ }
1196
1303
  const fieldPath = `${path}.${field}`;
1197
1304
  if (!path.endsWith('.style') && PROTOCOL_ARRAY_FIELDS.has(field) && !Array.isArray(item)) fail(fieldPath, 'must be an array');
1198
1305
  if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number') fail(fieldPath, 'must be a finite number');
@@ -1200,7 +1307,7 @@ function assertProtocolFields(value, path, parentField = '') {
1200
1307
  if (parentField === 'overlays' && field === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) fail(fieldPath, 'must be regular, medium, semibold, or bold');
1201
1308
  if (field === 'buttonStyle' && item !== 'tertiary') fail(fieldPath, 'must be tertiary');
1202
1309
  if (field === 'hideLeading' && typeof item !== 'boolean') fail(fieldPath, 'must be boolean');
1203
- if (field === 'key' || field === 'sectionKey' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
1310
+ if (field === 'key' || field === 'sectionKey' || field === 'groupId' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
1204
1311
  if ((field === 'uri' || field === 'fallbackUri') && typeof item !== 'string') fail(fieldPath, 'must be a string');
1205
1312
  if (field === 'style' && !(item === 'subscript' && /[Ss]egments\[/.test(path)) || field === 'container') protocolObject(item, fieldPath);
1206
1313
  if (path.endsWith('.style') && ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'change', 'columns', 'columnSecondary', 'value', 'valueSecondary', 'badge', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'trend', 'message', 'actionText'].includes(field)) protocolObject(item, fieldPath);
@@ -1211,6 +1318,7 @@ function assertRowProtocol(row, path) {
1211
1318
  protocolObject(row, path);
1212
1319
  assertRowType(row.type, path);
1213
1320
  protocolKey(row.key, `${path}.key`);
1321
+ assertCoreRow(row, path);
1214
1322
  assertProtocolFields(row, path);
1215
1323
  for (const field of ['leading', 'visual', 'secondaryLeading']) {
1216
1324
  const visual = row[field];
@@ -1225,7 +1333,7 @@ function assertRowProtocol(row, path) {
1225
1333
  }
1226
1334
  if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
1227
1335
  if (row.type === 'identity') {
1228
- assertIdentityExtras(row, path);
1336
+ if (isDevelopment()) assertIdentityExtras(row, path);
1229
1337
  if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes)) fail(`${path}.titleSuffixes`, 'must be an array');
1230
1338
  row.titleSuffixes?.forEach((suffix, index) => {
1231
1339
  protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
@@ -1238,8 +1346,8 @@ function assertRowProtocol(row, path) {
1238
1346
  end = match.end;
1239
1347
  });
1240
1348
  }
1241
- if (row.type === 'buttonGroup') assertButtonGroup(row, path);
1242
- if (row.type === 'sectionHeader') assertTextHelp(row.valueHelp, `${path}.valueHelp`);
1349
+ if (row.type === 'buttonGroup' && isDevelopment()) assertButtonGroup(row, path);
1350
+ if (row.type === 'sectionHeader' && isDevelopment()) assertTextHelp(row.valueHelp, `${path}.valueHelp`);
1243
1351
  if (row.type === 'mediaTile' && row.media) {
1244
1352
  protocolObject(row.media.source, `${path}.media.source`);
1245
1353
  if (!Array.isArray(row.media.probeOrder)) fail(`${path}.media.probeOrder`, 'must be an array');
@@ -1261,12 +1369,13 @@ function assertRowProtocol(row, path) {
1261
1369
  row.columns.forEach((column, index) => {
1262
1370
  const columnPath = `${path}.columns[${index}]`;
1263
1371
  protocolObject(column, columnPath);
1264
- assertIdentityExtras(column, columnPath);
1372
+ if (isDevelopment()) assertIdentityExtras(column, columnPath);
1265
1373
  });
1266
- assertTrailingAccessories(row.trailing, `${path}.trailing`);
1374
+ if (isDevelopment()) assertTrailingAccessories(row.trailing, `${path}.trailing`);
1267
1375
  }
1268
1376
  if (row.type === 'market') {
1269
1377
  protocolObject(row.change, `${path}.change`);
1378
+ assertMarketMetrics(row.metrics, `${path}.metrics`);
1270
1379
  if (row.webTable) {
1271
1380
  const {
1272
1381
  columns,
@@ -1329,38 +1438,356 @@ function assertSnapshotProtocol(snapshot) {
1329
1438
  });
1330
1439
  }
1331
1440
  }
1441
+ function isRecord(value) {
1442
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
1443
+ }
1444
+ function isAllowedImageUri(value) {
1445
+ return typeof value === 'string' && value.trim().length > 0 && (!/^[a-z][a-z\d+.-]*:/i.test(value) || /^(https?|file|content|ph|assets-library|asset|res|blob|onekey-avatar):/i.test(value) || /^data:image\//i.test(value));
1446
+ }
1447
+ const IMAGE_FIELDS = ['uri', 'width', 'height', 'headers', 'contentFit', 'cachePolicy', 'autoplay', 'optimizeTos', 'overscan', 'loadingStrategy', 'fallbackUri', 'fallbackUris', 'retryTimes'];
1448
+ const ICON_FIELDS = ['name', 'tintColor', 'backgroundColor', 'size', 'accessibilityLabel', 'hoverActionKey'];
1449
+ const VISUAL_FIELDS = ['kind', 'name', 'image', 'images', 'networkImage', 'shape', 'tintColor', 'backgroundColor', 'fallbackIcon', 'fallbackText', 'fallbackTextColor', 'overlays', 'borderStyle', 'borderColor', 'cornerIcon'];
1450
+ const TEXT_STYLE_FIELDS = ['token', 'fontSize', 'fontWeight', 'color', 'lineHeight', 'lines', 'truncate', 'alignment', 'verticalAlignment', 'offsetY'];
1451
+ const ACCESSORY_FIELDS = {
1452
+ value: ['kind', 'text', 'secondary', 'textSegments'],
1453
+ valuePair: ['kind', 'primary', 'secondary', 'primaryFontWeight', 'primaryHelp', 'primaryTextSegments', 'secondaryTextSegments', 'primaryTone', 'secondaryTone'],
1454
+ button: ['kind', 'label', 'actionKey', 'disabled', 'testID', 'accessibilityLabel', 'textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor'],
1455
+ icon: ['kind', 'name', 'tintColor', 'buttonStyle', 'disabled', 'actionKey', 'testID', 'hoverActionKey', 'accessibilityLabel'],
1456
+ checkbox: ['kind', 'state', 'disabled', 'loading', 'target', 'actionKey'],
1457
+ radio: ['kind', 'checked', 'disabled', 'actionKey'],
1458
+ switch: ['kind', 'value', 'disabled', 'actionKey'],
1459
+ chevron: ['kind', 'actionKey'],
1460
+ menu: ['kind', 'actionKey'],
1461
+ drag: ['kind', 'actionKey'],
1462
+ spinner: ['kind'],
1463
+ progress: ['kind', 'value']
1464
+ };
1465
+ const REQUIRED_ROW_FIELDS = {
1466
+ identity: ['title', 'leading'],
1467
+ walletGroup: ['parent', 'children'],
1468
+ rail: ['title', 'visual'],
1469
+ activity: ['title', 'leading'],
1470
+ message: ['title', 'body', 'time'],
1471
+ dataRow: ['columns'],
1472
+ market: ['title', 'leading', 'variant', 'price', 'change'],
1473
+ mediaTile: ['title', 'variant'],
1474
+ metricCard: ['title', 'value'],
1475
+ sectionHeader: ['title', 'sectionKey'],
1476
+ action: ['title', 'actionKey'],
1477
+ buttonGroup: ['buttons'],
1478
+ system: ['variant']
1479
+ };
1480
+ function assertCoreRow(row, path) {
1481
+ const object = row;
1482
+ for (const key of REQUIRED_ROW_FIELDS[row.type]) {
1483
+ const value = object[key];
1484
+ if (value === undefined || value === null) fail(`${path}.${key}`, 'required field');
1485
+ if (['title', 'body', 'time', 'price', 'value', 'variant'].includes(key) && typeof value !== 'string') fail(`${path}.${key}`, 'must be a string');
1486
+ }
1487
+ if (row.type === 'market') {
1488
+ if (!row.price.trim()) fail(`${path}.price`, 'must be nonblank');
1489
+ if (typeof row.change?.text !== 'string') fail(`${path}.change.text`, 'must be a string');
1490
+ }
1491
+ if (row.type === 'activity') {
1492
+ row.amounts?.forEach((amount, index) => {
1493
+ protocolKey(amount.key, `${path}.amounts[${index}].key`);
1494
+ if (typeof amount.text !== 'string') fail(`${path}.amounts[${index}].text`, 'required financial text');
1495
+ });
1496
+ if (row.fee && typeof row.fee.primary !== 'string') fail(`${path}.fee.primary`, 'required financial text');
1497
+ row.footerActions?.forEach((action, index) => {
1498
+ protocolKey(action.key, `${path}.footerActions[${index}].key`);
1499
+ protocolKey(action.label, `${path}.footerActions[${index}].label`);
1500
+ });
1501
+ }
1502
+ if (row.type === 'action') protocolKey(row.actionKey, `${path}.actionKey`);
1503
+ if (row.type === 'sectionHeader') protocolKey(row.sectionKey, `${path}.sectionKey`);
1504
+ if (row.type === 'system' && ['retry', 'warning', 'noMatch'].includes(row.variant)) {
1505
+ if (typeof object.message !== 'string') fail(`${path}.message`, 'must be a string');
1506
+ if (row.variant === 'retry') protocolKey(row.actionKey, `${path}.actionKey`);
1507
+ }
1508
+ if (row.type === 'dataRow') {
1509
+ if (!Array.isArray(row.columns) || row.columns.length === 0) fail(`${path}.columns`, 'required columns');
1510
+ row.columns.forEach((column, index) => {
1511
+ protocolObject(column, `${path}.columns[${index}]`);
1512
+ protocolKey(column.key, `${path}.columns[${index}].key`);
1513
+ if (typeof column.text !== 'string') fail(`${path}.columns[${index}].text`, 'must be a string');
1514
+ });
1515
+ }
1516
+ if (row.type === 'buttonGroup') {
1517
+ if (!Array.isArray(row.buttons) || row.buttons.length === 0) fail(`${path}.buttons`, 'required buttons');
1518
+ const keys = new Set();
1519
+ row.buttons.forEach((button, index) => {
1520
+ const field = `${path}.buttons[${index}]`;
1521
+ protocolObject(button, field);
1522
+ protocolKey(button.key, `${field}.key`);
1523
+ protocolKey(button.actionKey, `${field}.actionKey`);
1524
+ protocolKey(button.label, `${field}.label`);
1525
+ if (keys.has(button.key)) fail(field, 'duplicate button identity');
1526
+ keys.add(button.key);
1527
+ });
1528
+ }
1529
+ for (const field of ['trailing', 'leadingAction', 'titleIcon', 'valueIcon']) {
1530
+ const value = object[field];
1531
+ if (value === undefined) continue;
1532
+ // Identity title icons are decorative descriptors, not trailing controls.
1533
+ if (field === 'titleIcon' && row.type !== 'sectionHeader') continue;
1534
+ const accessories = field === 'trailing' ? value : [value];
1535
+ if (!Array.isArray(accessories)) fail(`${path}.${field}`, 'must be an array');
1536
+ accessories.forEach((accessory, index) => {
1537
+ const entry = protocolObject(accessory, `${path}.${field}[${index}]`);
1538
+ for (const key of entry.kind === 'value' ? ['text'] : entry.kind === 'valuePair' ? ['primary', 'secondary'] : []) {
1539
+ if (typeof entry[key] !== 'string') fail(`${path}.${field}[${index}].${key}`, 'required financial text');
1540
+ }
1541
+ if (['button', 'menu', 'switch'].includes(entry.kind) || 'actionKey' in entry) {
1542
+ protocolKey(entry.actionKey, `${path}.${field}[${index}].actionKey`);
1543
+ if (entry.kind === 'button') protocolKey(entry.label, `${path}.${field}[${index}].label`);
1544
+ }
1545
+ if (entry.kind === 'icon') protocolKey(entry.name, `${path}.${field}[${index}].name`);
1546
+ });
1547
+ }
1548
+ }
1549
+ function pickFields(object, fields) {
1550
+ return Object.fromEntries(Object.entries(object).filter(([key]) => fields.includes(key)));
1551
+ }
1552
+ function sanitizeImage(value) {
1553
+ if (!isRecord(value) || !isAllowedImageUri(value.uri) || typeof value.width !== 'number' || !Number.isFinite(value.width) || value.width <= 0 || typeof value.height !== 'number' || !Number.isFinite(value.height) || value.height <= 0) return undefined;
1554
+ const next = pickFields(value, IMAGE_FIELDS);
1555
+ next.width = Math.min(MAX_IMAGE_EDGE, value.width);
1556
+ next.height = Math.min(MAX_IMAGE_EDGE, value.height);
1557
+ if (next.headers !== undefined) {
1558
+ if (!isRecord(next.headers)) delete next.headers;else next.headers = Object.fromEntries(Object.entries(next.headers).filter(([key, item]) => key.trim() && key.length <= MAX_HEADER_LENGTH && typeof item === 'string' && item.length <= MAX_HEADER_LENGTH).slice(0, MAX_IMAGE_HEADERS));
1559
+ }
1560
+ if (next.fallbackUris !== undefined) {
1561
+ if (Array.isArray(next.fallbackUris)) next.fallbackUris = next.fallbackUris.filter(isAllowedImageUri);else delete next.fallbackUris;
1562
+ }
1563
+ if (next.fallbackUri !== undefined && !isAllowedImageUri(next.fallbackUri)) delete next.fallbackUri;
1564
+ if (next.overscan !== undefined && (typeof next.overscan !== 'number' || !Number.isFinite(next.overscan) || next.overscan < 1 || next.overscan > 4)) delete next.overscan;
1565
+ if (next.retryTimes !== undefined && (typeof next.retryTimes !== 'number' || !Number.isFinite(next.retryTimes) || next.retryTimes < 0)) delete next.retryTimes;
1566
+ const options = {
1567
+ contentFit: ['cover', 'contain', 'fill', 'center'],
1568
+ cachePolicy: ['memory-disk', 'memory', 'disk', 'none'],
1569
+ loadingStrategy: ['static', 'skeleton', 'none']
1570
+ };
1571
+ for (const [key, allowed] of Object.entries(options)) if (next[key] !== undefined && !allowed.includes(next[key])) delete next[key];
1572
+ for (const key of ['autoplay', 'optimizeTos']) if (next[key] !== undefined && typeof next[key] !== 'boolean') delete next[key];
1573
+ return next;
1574
+ }
1575
+ const NESTED_DECORATION_FIELDS = {
1576
+ webTable: ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'],
1577
+ columns: ['key', 'text', 'textSegments', 'titleIcon', 'secondaryTitleIcon', 'secondaryLeadingText', 'secondaryText', 'secondaryTextSegments', 'weight', 'alignment', 'tone', 'secondaryTone', 'width', 'minWidth', 'flex', 'paddingStart', 'paddingEnd'],
1578
+ cells: ['key', 'kind', 'active', 'disabled', 'testID', 'hoverActionKey', 'actionKey', 'accessibilityLabel', 'leading', 'title', 'secondary', 'lineGap', 'secondaryBadges', 'hoverImages', 'hoverSecondary', 'hoverActionLabel', 'badges', 'primary', 'partGap', 'points', 'width', 'height', 'strokeColor', 'fillColor'],
1579
+ badges: ['key', 'text', 'tone', 'iconName', 'icon', 'textColor', 'backgroundColor', 'actionKey', 'accessibilityLabel', 'style'],
1580
+ overlays: ['position', 'size', 'width', 'height', 'padding', 'offset', 'offsetX', 'offsetY', 'image', 'fallbackIcon', 'name', 'text', 'fontWeight', 'tintColor', 'backgroundColor'],
1581
+ primaryHelp: ['actionKey', 'presentation', 'underline'],
1582
+ valueHelp: ['actionKey', 'presentation', 'underline']
1583
+ };
1584
+ function sanitizeDecoration(value, field) {
1585
+ if (value === undefined || value === null) return undefined;
1586
+ if (!Array.isArray(value) && ['image', 'networkImage', 'thumbnail', 'source', 'images', 'hoverImages'].includes(field)) return sanitizeImage(value);
1587
+ if (['titleImage', 'titleIcon', 'secondaryTitleIcon', 'fallbackIcon', 'cornerIcon', 'media'].includes(field) && !isRecord(value)) return undefined;
1588
+ if (field === 'style' && typeof value !== 'string' && !isRecord(value)) return undefined;
1589
+ if (['badges', 'overlays'].includes(field) && !Array.isArray(value) && !isRecord(value)) return undefined;
1590
+ if (field === 'style' && typeof value === 'string') return value === 'subscript' ? value : undefined;
1591
+ if (Array.isArray(value)) {
1592
+ const items = value.map(item => sanitizeDecoration(item, field));
1593
+ return field === 'hoverImages' ? items.map(item => item ?? null) : items.filter(item => item !== undefined);
1594
+ }
1595
+ if (!isRecord(value)) return value;
1596
+ let object = value;
1597
+ if (field === 'titleImage') {
1598
+ const image = sanitizeImage(value.image);
1599
+ if (!image) return undefined;
1600
+ const edge = Math.min(40, Math.max(1, Math.round(Math.min(image.width, image.height))));
1601
+ object = {
1602
+ ...pickFields(value, ['image', 'accessibilityLabel', 'hoverActionKey']),
1603
+ image: {
1604
+ ...image,
1605
+ width: edge,
1606
+ height: edge
1607
+ }
1608
+ };
1609
+ } else if (['titleIcon', 'secondaryTitleIcon', 'fallbackIcon', 'cornerIcon'].includes(field) && value.kind === undefined) {
1610
+ if (typeof value.name !== 'string' || !value.name.trim()) return undefined;
1611
+ object = pickFields(value, ICON_FIELDS);
1612
+ } else if (['leading', 'visual', 'secondaryLeading'].includes(field)) {
1613
+ object = pickFields(value, VISUAL_FIELDS);
1614
+ } else if (field === 'media') {
1615
+ object = pickFields(value, ['source', 'probeOrder']);
1616
+ }
1617
+ if (field === 'trailing' || ['leadingAction', 'titleIcon', 'valueIcon'].includes(field) && object.kind !== undefined) {
1618
+ const fields = ACCESSORY_FIELDS[object.kind];
1619
+ if (fields) object = pickFields(object, fields);
1620
+ } else if (field === 'buttons') object = pickFields(object, ['key', 'label', 'actionKey', 'disabled', 'loading', 'testID', 'accessibilityLabel']);else if (field === 'container') object = pickFields(object, ['height', 'backgroundColor', 'opacity', 'cornerRadius', 'borderWidth', 'borderColor', 'contentVerticalAlignment']);else if (field === 'imageStyle') object = pickFields(object, ['width', 'height', 'shape', 'cornerRadius', 'contentFit']);else if (field === 'style') object = pickFields(object, [...TEXT_STYLE_FIELDS, 'container', ...new Set(Object.values(ROW_BOX_STYLE_KEYS_BY_TYPE).flat()), ...new Set(Object.values(TEXT_STYLE_KEYS_BY_ROW_TYPE).flat()), ...new Set(Object.values(EXTRA_STYLE_KEYS_BY_ROW_TYPE).flat()), 'height']);else if (['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'change', 'value', 'valueSecondary', 'columnSecondary', 'primaryAmount', 'secondaryAmount', 'description', 'status', 'trend', 'message', 'actionText'].includes(field) && !('text' in object)) {
1621
+ object = pickFields(object, TEXT_STYLE_FIELDS);
1622
+ }
1623
+ if (NESTED_DECORATION_FIELDS[field]) object = pickFields(object, NESTED_DECORATION_FIELDS[field]);
1624
+ if (['textSegments', 'primaryTextSegments', 'secondaryTextSegments', 'priceSegments', 'segments'].includes(field)) object = pickFields(object, ['text', 'style']);
1625
+ if (field === 'subtitleSegments') object = pickFields(object, ['text', 'style', 'textSegments', 'tone', 'separatorBefore']);
1626
+ const styleObject = ['style', 'imageStyle', 'container'].includes(field) || TEXT_STYLE_FIELDS.some(key => key in object);
1627
+ const next = {};
1628
+ for (const [key, item] of Object.entries(object)) {
1629
+ if (item === undefined || item === null) continue;
1630
+ if ((/color$/i.test(key) || /background$/i.test(key)) && (typeof item !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(item))) continue;
1631
+ if (/TextSegments$/.test(key) || ['textSegments', 'priceSegments', 'subtitleSegments', 'segments'].includes(key)) {
1632
+ if (!Array.isArray(item) || item.some(segment => !isRecord(segment) || typeof segment.text !== 'string')) continue;
1633
+ }
1634
+ if (styleObject && PROTOCOL_NUMBER_FIELDS.has(key) && typeof item !== 'number') continue;
1635
+ if (key === 'token' && (typeof item !== 'string' || !Object.hasOwn(TYPOGRAPHY_TOKENS, item))) continue;
1636
+ if (key === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) continue;
1637
+ if (['disabled', 'loading', 'checked', 'selected', 'separator', 'hideLeading', 'pressDisabled', 'draggable', 'active', 'autoplay'].includes(key) && typeof item !== 'boolean') continue;
1638
+ if (key === 'primaryFontWeight' && item !== 'medium') continue;
1639
+ if (key === 'buttonStyle' && item !== 'tertiary') continue;
1640
+ if (key === 'hoverActionKey' && (typeof item !== 'string' || !item.trim())) continue;
1641
+ if (key === 'accessibilityLabel' && typeof item !== 'string') continue;
1642
+ if ((field === 'style' || PROTOCOL_NUMBER_FIELDS.has(key)) && typeof item !== 'object' && typeof item === 'number' && (!Number.isFinite(item) || item < 0 && !['offsetX', 'offsetY'].includes(key))) continue;
1643
+ if (field === 'style' && PROTOCOL_NUMBER_FIELDS.has(key) && typeof item !== 'number') continue;
1644
+ if (key === 'leadingContentMaxWidthRatio' && (typeof item !== 'number' || item <= 0 || item > 1)) continue;
1645
+ const normalized = sanitizeDecoration(item, field === 'style' && key === 'image' ? 'imageStyle' : key);
1646
+ if (normalized !== undefined) next[key] = normalized;
1647
+ }
1648
+ if (field === 'titleImage') {
1649
+ // The nested image was already normalized with title-specific geometry.
1650
+ if (!next.image) return undefined;
1651
+ }
1652
+ if (field === 'media' && (!next.source || !Array.isArray(next.probeOrder))) return undefined;
1653
+ if (['leading', 'visual', 'secondaryLeading'].includes(field)) {
1654
+ if (next.kind === 'image' && !next.image) return {
1655
+ kind: 'token',
1656
+ ...pickFields(next, ['fallbackIcon', 'fallbackText', 'fallbackTextColor'])
1657
+ };
1658
+ if (next.kind === 'stackedImages' && (!Array.isArray(next.images) || next.images.length < 2)) return {
1659
+ kind: 'token'
1660
+ };
1661
+ if (next.kind === 'icon' && (typeof next.name !== 'string' || !next.name.trim())) return {
1662
+ kind: 'token'
1663
+ };
1664
+ if (!['token', 'account', 'wallet', 'network', 'image', 'icon', 'stackedImages'].includes(next.kind)) return {
1665
+ kind: 'token'
1666
+ };
1667
+ }
1668
+ if (field === 'overlays' && (!['topLeft', 'bottomRight'].includes(next.position) || !next.image && !next.name && !next.text)) return undefined;
1669
+ if (field === 'trailing' && next.kind === 'icon' && !('actionKey' in value) && (typeof next.name !== 'string' || !next.name.trim())) return undefined;
1670
+ if (field === 'trailing' && !['value', 'valuePair', 'button', 'checkbox', 'radio', 'switch', 'chevron', 'menu', 'drag', 'icon', 'spinner', 'progress'].includes(next.kind) && !('actionKey' in value)) return undefined;
1671
+ if (field === 'badges' && (typeof next.key !== 'string' || !next.text && !next.iconName && !next.icon)) return undefined;
1672
+ if (next.kind === 'sparkline') {
1673
+ const points = Array.isArray(value.points) ? value.points.filter(point => typeof point === 'number' && Number.isFinite(point)).slice(0, 256) : [];
1674
+ // Preserve the table's column identity even when its optional drawing fails.
1675
+ return points.length < 2 ? {
1676
+ key: next.key,
1677
+ kind: 'text',
1678
+ primary: []
1679
+ } : {
1680
+ ...next,
1681
+ points
1682
+ };
1683
+ }
1684
+ return next;
1685
+ }
1686
+ function sanitizeMarketMetrics(value) {
1687
+ if (!Array.isArray(value)) return value;
1688
+ return value.map(metric => {
1689
+ const next = pickFields(metric, MARKET_METRIC_FIELDS);
1690
+ for (const field of ['textSegments', 'secondaryTextSegments']) {
1691
+ if (next[field] !== undefined) next[field] = sanitizeDecoration(next[field], field);
1692
+ }
1693
+ return next;
1694
+ });
1695
+ }
1696
+ function sanitizeRowForProduction(row) {
1697
+ const object = protocolObject(row, 'row');
1698
+ const fields = ROW_FIELDS[row.type];
1699
+ if (!fields) return row;
1700
+ const next = pickFields(object, fields);
1701
+ for (const [field, value] of Object.entries(next)) {
1702
+ if ((/color$/i.test(field) || /background$/i.test(field)) && (typeof value !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))) {
1703
+ delete next[field];
1704
+ continue;
1705
+ }
1706
+ if (field === 'parent' && isRecord(value)) next[field] = sanitizeRowForProduction(value);else if (field === 'children' && Array.isArray(value)) next[field] = value.map(child => sanitizeRowForProduction(child));else {
1707
+ const normalized = row.type === 'market' && field === 'metrics' ? sanitizeMarketMetrics(value) : sanitizeDecoration(value, field);
1708
+ if (normalized === undefined) delete next[field];else next[field] = normalized;
1709
+ }
1710
+ }
1711
+ if (isRecord(next.style)) next.style = pickFields(next.style, ['container', ...ROW_BOX_STYLE_KEYS_BY_TYPE[row.type], ...(TEXT_STYLE_KEYS_BY_ROW_TYPE[row.type] ?? []), ...(EXTRA_STYLE_KEYS_BY_ROW_TYPE[row.type] ?? [])]);
1712
+ return sameJsonValue(row, next) ? row : next;
1713
+ }
1332
1714
 
1333
- /** Empty optional image descriptors must take the same path as absent images. */
1715
+ /** Empty images and optional nulls share one meaning before strict assertions. */
1334
1716
  function normalizeEmptyImages(value, field = '') {
1335
- if (!value || typeof value !== 'object') return value;
1717
+ if (value === null || value === undefined || typeof value !== 'object') return value;
1336
1718
  if (Array.isArray(value)) {
1337
- const next = value.map(item => normalizeEmptyImages(item));
1338
- const filtered = field === 'images' ? next.filter(item => item !== undefined) : next.map(item => item === undefined ? null : item);
1339
- return filtered.length === value.length && filtered.every((item, index) => item === value[index]) ? value : filtered;
1719
+ const next = value.map(item => normalizeEmptyImages(item, field));
1720
+ return next.every((item, index) => item === value[index]) ? value : next.filter(item => item !== undefined);
1340
1721
  }
1341
1722
  const object = value;
1342
1723
  if (typeof object.uri === 'string' && !object.uri.trim() && 'width' in object && 'height' in object) return undefined;
1343
1724
  let changed = false;
1344
- const next = {
1345
- ...object
1346
- };
1347
- Object.entries(object).forEach(([key, item]) => {
1348
- const normalized = normalizeEmptyImages(item, key);
1349
- if (normalized !== item) {
1350
- // Omitted JSON patch fields must also be absent from the JS merge.
1351
- if (field === 'changes' && normalized === undefined) delete next[key];else next[key] = normalized;
1725
+ const next = {};
1726
+ for (const [key, item] of Object.entries(object)) {
1727
+ const optional = object.type && !['key', 'type', ...(REQUIRED_ROW_FIELDS[object.type] ?? [])].includes(key);
1728
+ if (item === undefined || item === null && optional && !(object.type === 'market' && key === 'metrics') || ['priceSegments', 'subtitleSegments'].includes(key) && Array.isArray(item) && item.length === 0) {
1352
1729
  changed = true;
1730
+ continue;
1353
1731
  }
1354
- });
1355
- if (field === 'media' && next.source === undefined) return undefined;
1732
+ const normalized = field === 'headers' ? item : normalizeEmptyImages(item, key);
1733
+ if (normalized !== undefined) next[key] = normalized;
1734
+ if (normalized !== item) changed = true;
1735
+ }
1736
+ if (field === 'media' && object.source !== undefined && next.source === undefined || field === 'titleImage' && object.image !== undefined && next.image === undefined) return undefined;
1737
+ if (['leading', 'visual', 'secondaryLeading'].includes(field) && next.kind === 'image' && !next.image) return {
1738
+ kind: 'token'
1739
+ };
1740
+ if (field === 'overlays' && object.image !== undefined && !next.image) return undefined;
1356
1741
  return changed ? next : value;
1357
1742
  }
1743
+ function normalizeSnapshotForProduction(snapshot) {
1744
+ if (!Array.isArray(snapshot.rows)) return snapshot;
1745
+ let rows = snapshot.rows.map(sanitizeRowForProduction);
1746
+ rows = rows.map((row, index) => {
1747
+ if (!row.groupId) return row;
1748
+ const previous = rows[index - 1]?.groupId === row.groupId;
1749
+ const following = rows[index + 1]?.groupId === row.groupId;
1750
+ return {
1751
+ ...row,
1752
+ groupPosition: previous ? following ? 'middle' : 'last' : following ? 'first' : 'single'
1753
+ };
1754
+ });
1755
+ const next = {
1756
+ ...snapshot,
1757
+ rows,
1758
+ ...(snapshot.emptyState ? {
1759
+ emptyState: sanitizeRowForProduction(snapshot.emptyState)
1760
+ } : {}),
1761
+ ...(snapshot.fixedFooter ? {
1762
+ fixedFooter: sanitizeRowForProduction(snapshot.fixedFooter)
1763
+ } : {})
1764
+ };
1765
+ if (snapshot.theme) next.theme = sanitizeDecoration(snapshot.theme, 'theme');
1766
+ if (snapshot.listStyle) next.listStyle = sanitizeDecoration(snapshot.listStyle, 'style');
1767
+ if (snapshot.selection && Array.isArray(snapshot.selection.selectedKeys)) {
1768
+ const selectable = new Set(rows.filter(row => !row.disabled && !['sectionHeader', 'action', 'system', 'buttonGroup', 'market', 'walletGroup'].includes(row.type)).map(row => row.key));
1769
+ const selectedKeys = [...new Set(snapshot.selection.selectedKeys.filter(key => selectable.has(key)))];
1770
+ next.selection = {
1771
+ ...snapshot.selection,
1772
+ selectedKeys: snapshot.selection.mode === 'none' ? [] : snapshot.selection.mode === 'single' ? selectedKeys.slice(0, 1) : selectedKeys
1773
+ };
1774
+ }
1775
+ return sameJsonValue(snapshot, next) ? snapshot : next;
1776
+ }
1358
1777
  export function validateSnapshot(snapshot) {
1359
- assertPlainSerializable(snapshot, 'snapshot', new Set());
1360
- if (isDevelopment()) assertSnapshotContract(snapshot);
1361
- const normalized = isDevelopment() ? snapshot : normalizeEmptyImages(snapshot);
1362
- assertSnapshotProtocol(normalized);
1363
- return normalizeSnapshotStyles(normalized);
1778
+ assertPlainSerializable(snapshot, 'snapshot', new Set(), false);
1779
+ protocolObject(snapshot, 'snapshot');
1780
+ const normalized = normalizeEmptyImages(snapshot);
1781
+ if (Array.isArray(normalized.rows)) {
1782
+ normalized.rows.forEach((row, index) => {
1783
+ if (row.type === 'market') assertMarketMetrics(row.metrics, `snapshot.rows[${index}].metrics`);
1784
+ });
1785
+ }
1786
+ const canonical = isDevelopment() ? normalized : normalizeSnapshotForProduction(normalized);
1787
+ assertPlainSerializable(canonical, 'snapshot', new Set());
1788
+ if (isDevelopment()) assertSnapshotContract(canonical);
1789
+ assertSnapshotProtocol(canonical);
1790
+ return normalizeSnapshotStyles(canonical);
1364
1791
  }
1365
1792
  const ownedNativeSnapshots = new WeakMap();
1366
1793
  function capturePlainData(value, seen = new Map()) {
@@ -1429,8 +1856,12 @@ function normalizeSnapshotStyles(snapshot) {
1429
1856
  return {
1430
1857
  ...snapshot,
1431
1858
  rows,
1432
- emptyState,
1433
- fixedFooter
1859
+ ...(emptyState !== undefined ? {
1860
+ emptyState
1861
+ } : {}),
1862
+ ...(fixedFooter !== undefined ? {
1863
+ fixedFooter
1864
+ } : {})
1434
1865
  };
1435
1866
  }
1436
1867
  function assertPatchChanges(patch, index) {
@@ -1626,28 +2057,119 @@ function assertPatchChanges(patch, index) {
1626
2057
  fail(`patches[${index}].type`, 'is not supported');
1627
2058
  }
1628
2059
  }
2060
+ function normalizePatch(patch, index) {
2061
+ const path = `patches[${index}]`;
2062
+ protocolObject(patch, path);
2063
+ protocolKey(patch.key, `${path}.key`);
2064
+ if (isDevelopment()) assertKey(patch.key, `${path}.key`);
2065
+ assertRowType(patch.type, path);
2066
+ const raw = protocolObject(patch.changes, `${path}.changes`);
2067
+ assertPlainSerializable(raw, `${path}.changes`, new Set(), false);
2068
+ const fields = PATCH_FIELDS[patch.type];
2069
+ const changes = {};
2070
+ for (const [field, value] of Object.entries(raw)) {
2071
+ if (value === undefined) continue;
2072
+ if (!fields?.includes(field)) {
2073
+ if (isDevelopment()) fail(`${path}.changes.${field}`, 'unsupported patch field');
2074
+ continue;
2075
+ }
2076
+ if (value === null) {
2077
+ if (patch.type === 'market' && field === 'metrics') fail(`${path}.changes.metrics`, 'use a full snapshot to remove metrics');
2078
+ if (REQUIRED_ROW_FIELDS[patch.type].includes(field) || patch.type === 'system' && field === 'message') {
2079
+ // The concrete system variant is checked after merging with its baseline.
2080
+ if (patch.type !== 'system') fail(`${path}.changes.${field}`, 'required field cannot be cleared');
2081
+ }
2082
+ changes[field] = null;
2083
+ continue;
2084
+ }
2085
+ if (patch.type === 'market' && field === 'metrics') assertMarketMetrics(value, `${path}.changes.metrics`);
2086
+ if (['priceSegments', 'subtitleSegments'].includes(field) && Array.isArray(value) && value.length === 0) {
2087
+ changes[field] = null;
2088
+ continue;
2089
+ }
2090
+ const normalized = normalizeEmptyImages(value, field);
2091
+ if (normalized === undefined) {
2092
+ if (!REQUIRED_ROW_FIELDS[patch.type].includes(field)) changes[field] = null;
2093
+ continue;
2094
+ }
2095
+ const canonical = isDevelopment() ? normalized : patch.type === 'market' && field === 'metrics' ? sanitizeMarketMetrics(normalized) : sanitizeDecoration(normalized, field);
2096
+ if (canonical !== undefined) changes[field] = canonical;else if (field === 'titleImage') changes[field] = null;
2097
+ }
2098
+ if (patch.type === 'market' && Array.isArray(changes.priceSegments) && changes.priceSegments.length > 0 && (typeof changes.price !== 'string' || !changes.price.trim())) fail(`${path}.changes.price`, 'is required when priceSegments is updated');
2099
+ if (!isDevelopment()) {
2100
+ const sanitized = sanitizeRowForProduction({
2101
+ type: patch.type,
2102
+ ...changes
2103
+ });
2104
+ for (const [field, value] of Object.entries(changes)) {
2105
+ if (value === null) continue;
2106
+ if (sanitized[field] === undefined) delete changes[field];else changes[field] = sanitized[field];
2107
+ }
2108
+ }
2109
+ const values = Object.fromEntries(Object.entries(changes).filter(([, value]) => value !== null));
2110
+ if (patch.type === 'market' && 'metrics' in changes) assertMarketMetrics(changes.metrics, `${path}.changes.metrics`);
2111
+ assertPlainSerializable(values, `${path}.changes`, new Set());
2112
+ assertProtocolFields(values, `${path}.changes`);
2113
+ if (isDevelopment()) assertPatchChanges({
2114
+ ...patch,
2115
+ changes: values
2116
+ }, index);
2117
+ const normalizedPatch = {
2118
+ type: patch.type,
2119
+ key: patch.key,
2120
+ changes
2121
+ };
2122
+ return Object.keys(changes).length > 0 ? normalizePatchStyles([normalizedPatch])[0] : undefined;
2123
+ }
2124
+ function reportRejectedPatch(index) {
2125
+ console.warn(`NativeList rejected invalid patch unit at patches[${index}]`);
2126
+ }
1629
2127
  export function validatePatches(patches) {
1630
- assertPlainSerializable(patches, 'patches', new Set());
1631
2128
  if (!Array.isArray(patches)) fail('patches', 'must be an array');
1632
- const keys = new Set();
1633
- for (const [index, patch] of patches.entries()) {
1634
- protocolObject(patch, `patches[${index}]`);
1635
- protocolKey(patch.key, `patches[${index}].key`);
1636
- if (keys.has(patch.key)) fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
1637
- keys.add(patch.key);
1638
- protocolObject(patch.changes, `patches[${index}].changes`);
1639
- assertRowType(patch.type, `patches[${index}]`);
1640
- assertProtocolFields(patch.changes, `patches[${index}].changes`);
1641
- if (patch.type === 'identity') assertIdentityExtras(patch.changes, `patches[${index}].changes`);
1642
- if (!isDevelopment()) continue;
1643
- assertKey(patch.key, `patches[${index}].key`);
1644
- if (Object.keys(patch.changes).length === 0) {
1645
- fail(`patches[${index}].changes`, 'must contain at least one field');
2129
+ const units = new Map();
2130
+ const rejectedKeys = new Set();
2131
+ const reject = (key, index, error) => {
2132
+ if (isDevelopment()) throw error;
2133
+ rejectedKeys.add(key);
2134
+ reportRejectedPatch(index);
2135
+ };
2136
+ patches.forEach((input, index) => {
2137
+ const key = isRecord(input) && typeof input.key === 'string' ? input.key : '';
2138
+ try {
2139
+ protocolObject(input, `patches[${index}]`);
2140
+ protocolKey(input.key, `patches[${index}].key`);
2141
+ assertRowType(input.type, `patches[${index}]`);
2142
+ const changes = capturePlainData(protocolObject(input.changes, `patches[${index}].changes`));
2143
+ assertPlainSerializable(changes, `patches[${index}].changes`, new Set(), false);
2144
+ const previous = units.get(key);
2145
+ if (previous && previous.patch.type !== input.type) fail(`patches[${index}].type`, 'conflicting row types');
2146
+ const defined = Object.fromEntries(Object.entries(changes).filter(([, value]) => value !== undefined));
2147
+ units.set(key, {
2148
+ index,
2149
+ patch: {
2150
+ key,
2151
+ type: input.type,
2152
+ changes: {
2153
+ ...previous?.patch.changes,
2154
+ ...defined
2155
+ }
2156
+ }
2157
+ });
2158
+ } catch (error) {
2159
+ reject(key, index, error);
2160
+ }
2161
+ });
2162
+ const accepted = [];
2163
+ for (const [key, unit] of units) {
2164
+ if (rejectedKeys.has(key)) continue;
2165
+ try {
2166
+ const patch = normalizePatch(unit.patch, unit.index);
2167
+ if (patch) accepted.push(patch);
2168
+ } catch (error) {
2169
+ reject(key, unit.index, error);
1646
2170
  }
1647
- assertPatchChanges(patch, index);
1648
2171
  }
1649
- const normalized = isDevelopment() ? patches : normalizeEmptyImages(patches);
1650
- return normalizePatchStyles(normalized.filter(patch => Object.keys(patch.changes).length > 0));
2172
+ return accepted;
1651
2173
  }
1652
2174
 
1653
2175
  /** Patches reach the native side without passing through a snapshot. */
@@ -1759,79 +2281,138 @@ export function planNativeListPatches(previous, next) {
1759
2281
  }
1760
2282
  return patches.length === 0 ? EMPTY_ROW_PATCHES : patches;
1761
2283
  }
1762
- export function applyRowPatches(snapshot, patches) {
1763
- const normalizedPatches = validatePatches(patches);
1764
- const patchByKey = new Map(normalizedPatches.map(patch => [patch.key, patch]));
1765
- const knownKeys = new Set(snapshot.rows.map(row => row.key));
1766
- normalizedPatches.forEach(patch => {
1767
- if (!knownKeys.has(patch.key)) fail('patches', `unknown row key "${patch.key}"`);
1768
- });
1769
- const rows = snapshot.rows.map(row => {
1770
- const patch = patchByKey.get(row.key);
1771
- if (!patch) return row;
1772
- if (patch.type !== row.type) {
1773
- fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
2284
+ function mergeAndValidateSingleRow(previous, patch, index) {
2285
+ if (previous.key !== patch.key) fail(`patches[${index}].key`, 'does not match row identity');
2286
+ if (previous.type !== patch.type) fail(`patches[${index}].type`, 'does not match row type');
2287
+ const changes = {
2288
+ ...patch.changes
2289
+ };
2290
+ if (previous.type === 'market') {
2291
+ if (typeof changes.price === 'string' && !('priceSegments' in changes) && previous.priceSegments !== undefined) changes.priceSegments = null;
2292
+ if ((previous.webTable !== undefined || 'webTable' in changes) && ['price', 'priceSegments', 'change'].some(field => field in changes) && changes.webTable === undefined) fail(`patches[${index}].changes.webTable`, 'table quote changes require visible table cells');
2293
+ }
2294
+ if (previous.type === 'identity' || previous.type === 'market') {
2295
+ if (typeof changes.subtitle === 'string' && !('subtitleSegments' in changes) && previous.subtitleSegments !== undefined) changes.subtitleSegments = null;
2296
+ if (Array.isArray(changes.subtitleSegments) && changes.subtitleSegments.length > 0 && !('subtitle' in changes) && previous.subtitle !== undefined) changes.subtitle = null;
2297
+ }
2298
+ const merged = {
2299
+ ...previous
2300
+ };
2301
+ for (const [field, value] of Object.entries(changes)) {
2302
+ if (value === null) delete merged[field];else if (value !== undefined) merged[field] = value;
2303
+ }
2304
+ const next = normalizeRowStyles(merged);
2305
+ assertPlainSerializable(next, `rows[${index}]`, new Set());
2306
+ if (isDevelopment()) assertRow(next, index);
2307
+ assertRowProtocol(next, `rows[${index}]`);
2308
+ return {
2309
+ row: next,
2310
+ patch: {
2311
+ type: patch.type,
2312
+ key: patch.key,
2313
+ changes
1774
2314
  }
1775
- if (row.type === 'market' && row.webTable && patch.type === 'market' && (patch.changes.price !== undefined || patch.changes.priceSegments !== undefined || patch.changes.change !== undefined) && patch.changes.webTable === undefined) fail('patches', 'table quote changes must include the visible table cells');
1776
- return {
1777
- ...row,
1778
- ...patch.changes,
1779
- key: row.key,
1780
- type: row.type
1781
- };
1782
- });
1783
- return validateSnapshot({
1784
- ...snapshot,
1785
- rows
1786
- });
2315
+ };
1787
2316
  }
1788
2317
 
1789
- /** Native wrapper only: preserve full public validation for unsupported patches. */
1790
- export function applyOwnedNativePatches(snapshot, patches) {
1791
- const acceptedPatches = deepFreeze(validatePatches(capturePlainData(patches)));
1792
- const rowIndexes = ownedNativeSnapshots.get(snapshot);
1793
- const canPatchRows = rowIndexes !== undefined && acceptedPatches.every(patch => {
1794
- const index = rowIndexes.get(patch.key);
1795
- if (index === undefined || snapshot.rows[index].type !== patch.type) return false;
1796
- const allowed = patch.type === 'identity' ? ['subtitle', 'subtitleSegments', 'trailing'] : patch.type === 'dataRow' ? ['columns', 'trailing'] : undefined;
1797
- return allowed !== undefined && Object.entries(patch.changes).every(([key, value]) => allowed.includes(key) && (value !== undefined || snapshot.rows[index][key] === undefined));
2318
+ /** One canonical batch owns both accepted rows and the native wire payload. */
2319
+ export function applyValidatedRowPatches(snapshot, patches) {
2320
+ if (!Array.isArray(patches)) fail('patches', 'must be an array');
2321
+ const owned = ownedNativeSnapshots.has(snapshot);
2322
+ const rowIndexes = ownedNativeSnapshots.get(snapshot) ?? validatedRowIndexes.get(snapshot) ?? new Map(snapshot.rows.map((row, index) => [row.key, index]));
2323
+ validatedRowIndexes.set(snapshot, rowIndexes);
2324
+ const units = new Map();
2325
+ const rejected = new Set();
2326
+ const rejectedGroups = new Set();
2327
+ const reject = (key, index, error) => {
2328
+ if (isDevelopment()) throw error;
2329
+ rejected.add(key);
2330
+ const rowIndex = rowIndexes.get(key);
2331
+ const group = rowIndex === undefined ? undefined : snapshot.rows[rowIndex].groupId;
2332
+ if (group) rejectedGroups.add(group);
2333
+ reportRejectedPatch(index);
2334
+ };
2335
+ patches.forEach((input, index) => {
2336
+ const key = isRecord(input) && typeof input.key === 'string' ? input.key : '';
2337
+ try {
2338
+ protocolObject(input, `patches[${index}]`);
2339
+ protocolKey(input.key, `patches[${index}].key`);
2340
+ const rowIndex = rowIndexes.get(input.key);
2341
+ if (rowIndex === undefined) fail(`patches[${index}].key`, 'unknown row identity');
2342
+ if (snapshot.rows[rowIndex].type !== input.type) fail(`patches[${index}].type`, 'does not match row type');
2343
+ const changes = protocolObject(input.changes, `patches[${index}].changes`);
2344
+ const captured = capturePlainData(changes);
2345
+ assertPlainSerializable(captured, `patches[${index}].changes`, new Set(), false);
2346
+ const previous = units.get(input.key);
2347
+ // Undefined is omitted at every merge, so it cannot overwrite an earlier change.
2348
+ const defined = Object.fromEntries(Object.entries(captured).filter(([, value]) => value !== undefined));
2349
+ units.set(input.key, {
2350
+ index,
2351
+ type: input.type,
2352
+ changes: {
2353
+ ...previous?.changes,
2354
+ ...defined
2355
+ }
2356
+ });
2357
+ } catch (error) {
2358
+ reject(key, index, error);
2359
+ }
1798
2360
  });
1799
- if (!canPatchRows) {
1800
- const baseline = rowIndexes ? snapshot : capturePlainData(snapshot);
1801
- return {
1802
- patches: acceptedPatches,
1803
- snapshot: ownValidatedNativeSnapshot(applyRowPatches(baseline, acceptedPatches)),
1804
- json: JSON.stringify(acceptedPatches)
1805
- };
2361
+ const pending = new Map();
2362
+ for (const [key, unit] of units) {
2363
+ if (rejected.has(key)) continue;
2364
+ try {
2365
+ const patch = normalizePatch({
2366
+ key,
2367
+ type: unit.type,
2368
+ changes: unit.changes
2369
+ }, unit.index);
2370
+ if (!patch) continue;
2371
+ const merged = mergeAndValidateSingleRow(snapshot.rows[rowIndexes.get(key)], patch, rowIndexes.get(key));
2372
+ if (merged.row.disabled && snapshot.selection?.selectedKeys.includes(key)) fail(`patches[${unit.index}]`, 'cannot disable a selected row');
2373
+ pending.set(key, merged);
2374
+ } catch (error) {
2375
+ reject(key, unit.index, error);
2376
+ }
1806
2377
  }
1807
- const nextRows = snapshot.rows.slice();
1808
- for (const patch of acceptedPatches) {
1809
- const index = rowIndexes.get(patch.key);
1810
- const previous = nextRows[index];
1811
- const merged = {
1812
- ...previous,
1813
- ...patch.changes,
1814
- key: previous.key,
1815
- type: previous.type
1816
- };
1817
- const path = `rows[${index}]`;
1818
- assertPlainSerializable(merged, path, new Set());
1819
- if (isDevelopment()) assertRow(merged, index);
1820
- const normalized = isDevelopment() ? merged : normalizeEmptyImages(merged);
1821
- assertRowProtocol(normalized, path);
1822
- nextRows[index] = deepFreeze(normalizeRowStyles(normalized));
1823
- }
1824
- const nextSnapshot = Object.freeze({
2378
+ const accepted = [];
2379
+ let rows;
2380
+ for (const [key, value] of pending) {
2381
+ const index = rowIndexes.get(key);
2382
+ const group = snapshot.rows[index].groupId;
2383
+ if (rejected.has(key) || group && rejectedGroups.has(group)) continue;
2384
+ if (!rows) rows = snapshot.rows.slice();
2385
+ rows[index] = owned ? deepFreeze(value.row) : value.row;
2386
+ accepted.push(owned ? deepFreeze(value.patch) : value.patch);
2387
+ }
2388
+ if (!rows) return {
2389
+ patches: EMPTY_ROW_PATCHES,
2390
+ snapshot,
2391
+ json: '[]'
2392
+ };
2393
+ const next = owned ? Object.freeze({
1825
2394
  ...snapshot,
1826
- rows: Object.freeze(nextRows)
1827
- });
1828
- ownedNativeSnapshots.set(nextSnapshot, rowIndexes);
2395
+ rows: Object.freeze(rows)
2396
+ }) : {
2397
+ ...snapshot,
2398
+ rows
2399
+ };
2400
+ if (owned) ownedNativeSnapshots.set(next, rowIndexes);else validatedRowIndexes.set(next, rowIndexes);
1829
2401
  return {
1830
- patches: acceptedPatches,
1831
- snapshot: nextSnapshot,
1832
- json: JSON.stringify(acceptedPatches)
2402
+ patches: accepted,
2403
+ snapshot: next,
2404
+ json: JSON.stringify(accepted)
1833
2405
  };
1834
2406
  }
2407
+ const validatedRowIndexes = new WeakMap();
2408
+ export function applyOwnedNativePatches(snapshot, patches) {
2409
+ const owned = ownedNativeSnapshots.has(snapshot) ? snapshot : ownValidatedNativeSnapshot(validateSnapshot(capturePlainData(snapshot)));
2410
+ return applyValidatedRowPatches(owned, patches);
2411
+ }
2412
+ export function applyRowPatches(snapshot, patches) {
2413
+ const baseline = ownedNativeSnapshots.has(snapshot) ? snapshot : validateSnapshot(snapshot);
2414
+ return applyValidatedRowPatches(baseline, patches).snapshot;
2415
+ }
1835
2416
  export function serializeSnapshot(snapshot) {
1836
2417
  return JSON.stringify(validateSnapshot(snapshot));
1837
2418
  }