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

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 (144) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +29 -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 +193 -10
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +145 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -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 +1920 -109
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +29 -0
  20. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  24. package/docs/ROW_TEMPLATES.md +60 -9
  25. package/docs/SPEC.md +1004 -17
  26. package/docs/STYLE_SPEC.md +6 -0
  27. package/ios/HybridNativeList.swift +21 -2
  28. package/ios/NativeListAccessoryStack.swift +235 -39
  29. package/ios/NativeListActivityDetailsView.swift +18 -8
  30. package/ios/NativeListActivityRenderer.swift +8 -2
  31. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  32. package/ios/NativeListDataRowRenderer.swift +155 -27
  33. package/ios/NativeListDesignAssets.swift +9 -0
  34. package/ios/NativeListIdentityRenderer.swift +191 -30
  35. package/ios/NativeListLeadingVisual.swift +119 -22
  36. package/ios/NativeListMessageRenderer.swift +34 -1
  37. package/ios/NativeListModels.swift +42 -2
  38. package/ios/NativeListRendererRegistry.swift +1 -0
  39. package/ios/NativeListResolvedText.swift +2 -1
  40. package/ios/NativeListRowHost.swift +14 -0
  41. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  42. package/ios/RNCNativeListView.swift +1031 -55
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  45. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  59. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  60. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  61. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  62. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  63. package/ios/tests/NativeListLifecycleTests.swift +2720 -3
  64. package/lib/module/NativeList.js +200 -32
  65. package/lib/module/NativeList.web.js +262 -32
  66. package/lib/module/index.js +1 -1
  67. package/lib/module/models.js +1 -0
  68. package/lib/module/selection.js +1 -1
  69. package/lib/module/validation.js +776 -52
  70. package/lib/module/web/NativeListWebEngine.js +919 -79
  71. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  72. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  73. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  74. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  75. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  76. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  77. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  78. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  79. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  80. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  81. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  82. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  83. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  84. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  85. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  86. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  87. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  88. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  89. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  90. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  91. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  92. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  93. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  94. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  95. package/lib/typescript/src/NativeList.d.ts +3 -3
  96. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  97. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  98. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  99. package/lib/typescript/src/index.d.ts +2 -2
  100. package/lib/typescript/src/models.d.ts +176 -10
  101. package/lib/typescript/src/validation.d.ts +15 -0
  102. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  103. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  104. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  105. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  106. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  107. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  109. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  110. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  111. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  112. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  114. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  115. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  116. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  117. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  118. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  119. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  120. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  121. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  122. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  123. package/package.json +3 -3
  124. package/react-native-native-list.podspec +1 -0
  125. package/src/NativeList.nitro.ts +2 -0
  126. package/src/NativeList.tsx +391 -82
  127. package/src/NativeList.types.ts +34 -1
  128. package/src/NativeList.web.tsx +420 -65
  129. package/src/index.ts +2 -0
  130. package/src/models.ts +210 -3
  131. package/src/selection.ts +1 -0
  132. package/src/validation.ts +1635 -76
  133. package/src/web/NativeListWebEngine.ts +1476 -112
  134. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  135. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  136. package/src/web/templates/DataRowRenderer.ts +93 -20
  137. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  138. package/src/web/templates/MarketRowRenderer.ts +19 -3
  139. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  140. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  141. package/src/web/templates/MessageRowRenderer.ts +23 -7
  142. package/src/web/templates/RowContainerStyle.ts +2 -0
  143. package/src/web/templates/RowRendererRegistry.ts +21 -6
  144. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
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,7 +14,11 @@ import type {
13
14
  RowBoxStyle,
14
15
  RowModel,
15
16
  RowPatch,
17
+ RowTextHelp,
16
18
  WalletGroupRow,
19
+ WebMarketTableCell,
20
+ WebMarketTablePresentation,
21
+ WebMarketTableText,
17
22
  } from './models';
18
23
 
19
24
  const MAX_KEY_LENGTH = 256;
@@ -28,8 +33,42 @@ const MAX_SPACER_HEIGHT = 512;
28
33
  const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
29
34
  const MAX_MARKET_BADGES = 3;
30
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
+
31
46
  function fail(path: string, message: string): never {
32
- 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
+ };
33
72
  }
34
73
 
35
74
  function assertPlainSerializable(
@@ -69,16 +108,14 @@ function assertPlainSerializable(
69
108
  function assertKey(key: string, path: string): void {
70
109
  if (
71
110
  typeof key !== 'string' ||
72
- key.length === 0 ||
111
+ key.trim().length === 0 ||
73
112
  key.length > MAX_KEY_LENGTH
74
113
  ) {
75
114
  fail(
76
115
  path,
77
- `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`
78
117
  );
79
118
  }
80
- if (key.trim() !== key)
81
- fail(path, 'must not have leading or trailing whitespace');
82
119
  }
83
120
 
84
121
  function assertText(text: string | undefined, path: string): void {
@@ -185,12 +222,14 @@ const TEXT_STYLE_KEYS_BY_ROW_TYPE: Readonly<
185
222
  metricCard: ['title', 'value', 'subtitle', 'trend'],
186
223
  sectionHeader: ['title', 'subtitle', 'value'],
187
224
  action: ['title', 'value'],
225
+ buttonGroup: [],
188
226
  system: ['title', 'message', 'actionText'],
189
227
  };
190
228
 
191
229
  const EXTRA_STYLE_KEYS_BY_ROW_TYPE: Readonly<
192
230
  Partial<Record<RowModel['type'], readonly string[]>>
193
231
  > = {
232
+ identity: ['leadingContentMaxWidthRatio'],
194
233
  market: [
195
234
  'titleBadgeLayout',
196
235
  'contentTrailingGap',
@@ -199,6 +238,7 @@ const EXTRA_STYLE_KEYS_BY_ROW_TYPE: Readonly<
199
238
  'changeHeight',
200
239
  'changeCornerRadius',
201
240
  ],
241
+ sectionHeader: ['valuePlacement', 'titleDecoration'],
202
242
  };
203
243
 
204
244
  function assertTextStyle(
@@ -457,6 +497,33 @@ function assertRowStyle(row: RowModel, path: string): void {
457
497
  // Market keeps its own richer assertions, driven from assertMarketRow.
458
498
  if (row.type === 'market') return;
459
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
+ }
460
527
  const slots = style as Record<string, NativeListTextStyle | undefined>;
461
528
  textKeys.forEach((key) =>
462
529
  assertTextStyle(slots[key], `${path}.style.${key}`)
@@ -594,67 +661,12 @@ function normalizeRowStyles<T extends RowModel>(row: T): T {
594
661
  return next as T;
595
662
  }
596
663
 
597
- function assertMarketRow(row: MarketRow, path: string): void {
598
- if (!['token', 'stock', 'perp'].includes(row.variant)) {
599
- fail(`${path}.variant`, 'must be token, stock, or perp');
600
- }
601
- assertText(row.title, `${path}.title`);
602
- assertText(row.subtitle, `${path}.subtitle`);
603
- // OneKey patch: validate the independently laid out Market name.
604
- if (row.subtitlePrefix) {
605
- assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
606
- assertBoundedStyleNumber(
607
- row.subtitlePrefix.gap,
608
- `${path}.subtitlePrefix.gap`,
609
- 0,
610
- 64
611
- );
612
- assertBoundedStyleNumber(
613
- row.subtitlePrefix.maxWidth,
614
- `${path}.subtitlePrefix.maxWidth`,
615
- 1,
616
- 320
617
- );
618
- assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
619
- }
620
- assertText(row.price, `${path}.price`);
621
- assertText(row.change.text, `${path}.change.text`);
622
- assertTrailingAccessories(
623
- row.leadingAction ? [row.leadingAction] : undefined,
624
- `${path}.leadingAction`
625
- );
626
- if (row.leadingAction) {
627
- assertText(row.leadingAction.name, `${path}.leadingAction.name`);
628
- if (row.leadingAction.actionKey !== undefined) {
629
- assertKey(row.leadingAction.actionKey, `${path}.leadingAction.actionKey`);
630
- }
631
- }
632
- assertLeadingVisual(row.leading, `${path}.leading`);
633
- const assertSegments = (
634
- segments: MarketRow['priceSegments'],
635
- segmentPath: string
636
- ) => {
637
- segments?.forEach((segment, index) => {
638
- assertText(segment.text, `${segmentPath}[${index}].text`);
639
- if (segment.style !== undefined && segment.style !== 'subscript') {
640
- fail(
641
- `${segmentPath}[${index}].style`,
642
- 'must be subscript when provided'
643
- );
644
- }
645
- });
646
- };
647
- assertSegments(row.subtitleSegments, `${path}.subtitleSegments`);
648
- assertSegments(row.priceSegments, `${path}.priceSegments`);
649
- assertSegments(row.change.textSegments, `${path}.change.textSegments`);
650
- if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
651
- fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
652
- }
653
- if ((row.badges?.length ?? 0) > MAX_MARKET_BADGES) {
664
+ function assertMarketBadges(badges: MarketRow['badges'], path: string): void {
665
+ if ((badges?.length ?? 0) > MAX_MARKET_BADGES) {
654
666
  fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
655
667
  }
656
668
  const badgeKeys = new Set<string>();
657
- row.badges?.forEach((badge, index) => {
669
+ badges?.forEach((badge, index) => {
658
670
  const badgePath = `${path}.badges[${index}]`;
659
671
  assertKey(badge.key, `${badgePath}.key`);
660
672
  if (badgeKeys.has(badge.key)) {
@@ -709,6 +721,322 @@ function assertMarketRow(row: MarketRow, path: string): void {
709
721
  assertKey(badge.actionKey, `${badgePath}.actionKey`);
710
722
  }
711
723
  });
724
+ }
725
+
726
+ function assertWebMarketTable(
727
+ table: WebMarketTablePresentation | undefined,
728
+ path: string
729
+ ): void {
730
+ if (!table) return;
731
+ assertUnknownKeys(
732
+ table,
733
+ ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'],
734
+ path,
735
+ 'Web table key'
736
+ );
737
+ if (table.draggable !== undefined && typeof table.draggable !== 'boolean')
738
+ fail(`${path}.draggable`, 'must be boolean');
739
+ if (table.contextMenuActionKey !== undefined)
740
+ assertKey(table.contextMenuActionKey, `${path}.contextMenuActionKey`);
741
+ assertText(table.testID, `${path}.testID`);
742
+ if (
743
+ !Array.isArray(table.columns) ||
744
+ table.columns.length < 1 ||
745
+ table.columns.length > 12
746
+ )
747
+ fail(`${path}.columns`, 'must contain 1...12 columns');
748
+ if (
749
+ !Array.isArray(table.cells) ||
750
+ table.cells.length !== table.columns.length
751
+ )
752
+ fail(`${path}.cells`, 'must match the column count');
753
+ const keys = new Set<string>();
754
+ table.columns.forEach((column, index) => {
755
+ const field = `${path}.columns[${index}]`;
756
+ assertUnknownKeys(
757
+ column,
758
+ [
759
+ 'key',
760
+ 'width',
761
+ 'minWidth',
762
+ 'flex',
763
+ 'alignment',
764
+ 'paddingStart',
765
+ 'paddingEnd',
766
+ ],
767
+ field,
768
+ 'Web column key'
769
+ );
770
+ assertKey(column.key, `${field}.key`);
771
+ if (keys.has(column.key)) fail(field, 'column keys must be unique');
772
+ keys.add(column.key);
773
+ assertBoundedStyleNumber(column.width, `${field}.width`, 0, 4096);
774
+ assertBoundedStyleNumber(column.minWidth, `${field}.minWidth`, 0, 4096);
775
+ assertBoundedStyleNumber(column.flex, `${field}.flex`, 0, 16);
776
+ assertBoundedStyleNumber(
777
+ column.paddingStart,
778
+ `${field}.paddingStart`,
779
+ 0,
780
+ 64
781
+ );
782
+ assertBoundedStyleNumber(column.paddingEnd, `${field}.paddingEnd`, 0, 64);
783
+ if (
784
+ column.alignment !== undefined &&
785
+ !['start', 'center', 'end'].includes(column.alignment)
786
+ )
787
+ fail(`${field}.alignment`, 'must be start, center, or end');
788
+ });
789
+ const text = (value: WebMarketTableText, field: string) => {
790
+ assertUnknownKeys(
791
+ value,
792
+ ['text', 'segments', 'tone', 'style'],
793
+ field,
794
+ 'Web text key'
795
+ );
796
+ assertText(value.text, `${field}.text`);
797
+ assertTextTone(value.tone, `${field}.tone`);
798
+ assertTextStyle(value.style, `${field}.style`);
799
+ if (value.style)
800
+ assertUnknownKeys(
801
+ value.style,
802
+ ['fontSize', 'fontWeight', 'lineHeight', 'color'],
803
+ `${field}.style`,
804
+ 'Web table text style'
805
+ );
806
+ if ((value.segments?.length ?? 0) > 64)
807
+ fail(`${field}.segments`, 'supports at most 64 segments');
808
+ value.segments?.forEach((segment, index) => {
809
+ assertUnknownKeys(
810
+ segment,
811
+ ['text', 'style'],
812
+ `${field}.segments[${index}]`,
813
+ 'Web text segment'
814
+ );
815
+ assertText(segment.text, `${field}.segments[${index}].text`);
816
+ if (segment.style !== undefined && segment.style !== 'subscript')
817
+ fail(field, 'segment style must be subscript');
818
+ });
819
+ };
820
+ const line = (
821
+ parts: readonly WebMarketTableText[] | undefined,
822
+ field: string
823
+ ) => {
824
+ if (!parts) return;
825
+ if (!Array.isArray(parts) || parts.length > 8)
826
+ fail(field, 'supports at most 8 text parts');
827
+ parts.forEach((value, index) => text(value, `${field}[${index}]`));
828
+ };
829
+ table.cells.forEach((cell: WebMarketTableCell, index) => {
830
+ const field = `${path}.cells[${index}]`;
831
+ assertKey(cell.key, `${field}.key`);
832
+ if (cell.key !== table.columns[index].key)
833
+ fail(field, 'cell key/order must match its column');
834
+ switch (cell.kind) {
835
+ case 'favorite':
836
+ assertUnknownKeys(
837
+ cell,
838
+ [
839
+ 'key',
840
+ 'kind',
841
+ 'active',
842
+ 'disabled',
843
+ 'testID',
844
+ 'hoverActionKey',
845
+ 'actionKey',
846
+ 'accessibilityLabel',
847
+ ],
848
+ field,
849
+ 'Web favorite key'
850
+ );
851
+ if (typeof cell.active !== 'boolean')
852
+ fail(field, 'active must be boolean');
853
+ if (cell.disabled !== undefined && typeof cell.disabled !== 'boolean')
854
+ fail(field, 'disabled must be boolean');
855
+ if (cell.hoverActionKey !== undefined)
856
+ assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
857
+ assertText(cell.testID, `${field}.testID`);
858
+ assertKey(cell.actionKey, `${field}.actionKey`);
859
+ assertText(cell.accessibilityLabel, `${field}.accessibilityLabel`);
860
+ break;
861
+ case 'asset':
862
+ assertUnknownKeys(
863
+ cell,
864
+ [
865
+ 'key',
866
+ 'kind',
867
+ 'leading',
868
+ 'title',
869
+ 'secondary',
870
+ 'hoverSecondary',
871
+ 'hoverActionKey',
872
+ 'hoverActionLabel',
873
+ 'badges',
874
+ 'lineGap',
875
+ 'secondaryBadges',
876
+ 'hoverImages',
877
+ ],
878
+ field,
879
+ 'Web asset key'
880
+ );
881
+ assertBoundedStyleNumber(cell.lineGap, `${field}.lineGap`, 0, 8);
882
+ assertMarketBadges(cell.secondaryBadges, `${field}.secondary`);
883
+ cell.secondaryBadges?.forEach((badge, i) => {
884
+ assertUnknownKeys(
885
+ badge,
886
+ ['key', 'text', 'style'],
887
+ `${field}.secondaryBadges[${i}]`,
888
+ 'Web secondary badge key'
889
+ );
890
+ if (!badge.text) fail(field, 'secondary badges require text');
891
+ });
892
+ if (
893
+ cell.hoverImages !== undefined &&
894
+ (!Array.isArray(cell.hoverImages) || cell.hoverImages.length > 4)
895
+ )
896
+ fail(field, 'supports at most 4 hover images');
897
+ cell.hoverImages?.forEach((image, i) => {
898
+ if (image !== null) assertImage(image, `${field}.hoverImages[${i}]`);
899
+ });
900
+ assertLeadingVisual(cell.leading, `${field}.leading`);
901
+ text(cell.title, `${field}.title`);
902
+ line(cell.secondary, `${field}.secondary`);
903
+ line(cell.hoverSecondary, `${field}.hoverSecondary`);
904
+ assertText(cell.hoverActionLabel, `${field}.hoverActionLabel`);
905
+ if (cell.hoverActionKey !== undefined)
906
+ assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
907
+ assertMarketBadges(cell.badges, field);
908
+ cell.badges?.forEach((badge, i) =>
909
+ assertUnknownKeys(
910
+ badge,
911
+ [
912
+ 'key',
913
+ 'text',
914
+ 'iconName',
915
+ 'icon',
916
+ 'textColor',
917
+ 'backgroundColor',
918
+ 'actionKey',
919
+ 'accessibilityLabel',
920
+ 'style',
921
+ ],
922
+ `${field}.badges[${i}]`,
923
+ 'Web title badge key'
924
+ )
925
+ );
926
+ break;
927
+ case 'text':
928
+ assertUnknownKeys(
929
+ cell,
930
+ ['key', 'kind', 'primary', 'secondary', 'partGap'],
931
+ field,
932
+ 'Web text cell key'
933
+ );
934
+ assertBoundedStyleNumber(cell.partGap, `${field}.partGap`, 0, 8);
935
+ if (!Array.isArray(cell.primary) || !cell.primary.length)
936
+ fail(field, 'requires primary text');
937
+ line(cell.primary, `${field}.primary`);
938
+ line(cell.secondary, `${field}.secondary`);
939
+ break;
940
+ case 'sparkline':
941
+ assertUnknownKeys(
942
+ cell,
943
+ [
944
+ 'key',
945
+ 'kind',
946
+ 'points',
947
+ 'width',
948
+ 'height',
949
+ 'strokeColor',
950
+ 'fillColor',
951
+ ],
952
+ field,
953
+ 'Web sparkline key'
954
+ );
955
+ if (
956
+ !Array.isArray(cell.points) ||
957
+ cell.points.length > 256 ||
958
+ cell.points.some((value: number) => !Number.isFinite(value))
959
+ )
960
+ fail(field, 'supports at most 256 finite samples');
961
+ if (typeof cell.width !== 'number' || typeof cell.height !== 'number')
962
+ fail(field, 'sparkline dimensions are required');
963
+ assertBoundedStyleNumber(cell.width, `${field}.width`, 1, 512);
964
+ assertBoundedStyleNumber(cell.height, `${field}.height`, 1, 512);
965
+ for (const color of [cell.strokeColor, cell.fillColor])
966
+ if (
967
+ typeof color !== 'string' ||
968
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color)
969
+ )
970
+ fail(field, 'colors must be #RRGGBB or #RRGGBBAA');
971
+ break;
972
+ default:
973
+ fail(field, 'unsupported Web table cell kind');
974
+ }
975
+ });
976
+ }
977
+
978
+ function assertMarketRow(row: MarketRow, path: string): void {
979
+ assertWebMarketTable(row.webTable, `${path}.webTable`);
980
+ if (!['token', 'stock', 'perp'].includes(row.variant)) {
981
+ fail(`${path}.variant`, 'must be token, stock, or perp');
982
+ }
983
+ assertText(row.title, `${path}.title`);
984
+ assertText(row.subtitle, `${path}.subtitle`);
985
+ // OneKey patch: validate the independently laid out Market name.
986
+ if (row.subtitlePrefix) {
987
+ assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
988
+ assertText(
989
+ row.subtitlePrefix.hoverActionKey,
990
+ `${path}.subtitlePrefix.hoverActionKey`
991
+ );
992
+ assertBoundedStyleNumber(
993
+ row.subtitlePrefix.gap,
994
+ `${path}.subtitlePrefix.gap`,
995
+ 0,
996
+ 64
997
+ );
998
+ assertBoundedStyleNumber(
999
+ row.subtitlePrefix.maxWidth,
1000
+ `${path}.subtitlePrefix.maxWidth`,
1001
+ 1,
1002
+ 320
1003
+ );
1004
+ assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
1005
+ }
1006
+ assertText(row.price, `${path}.price`);
1007
+ assertText(row.change.text, `${path}.change.text`);
1008
+ assertTrailingAccessories(
1009
+ row.leadingAction ? [row.leadingAction] : undefined,
1010
+ `${path}.leadingAction`
1011
+ );
1012
+ if (row.leadingAction) {
1013
+ assertText(row.leadingAction.name, `${path}.leadingAction.name`);
1014
+ if (row.leadingAction.actionKey !== undefined) {
1015
+ assertKey(row.leadingAction.actionKey, `${path}.leadingAction.actionKey`);
1016
+ }
1017
+ }
1018
+ assertLeadingVisual(row.leading, `${path}.leading`);
1019
+ const assertSegments = (
1020
+ segments: MarketRow['priceSegments'],
1021
+ segmentPath: string
1022
+ ) => {
1023
+ segments?.forEach((segment, index) => {
1024
+ assertText(segment.text, `${segmentPath}[${index}].text`);
1025
+ if (segment.style !== undefined && segment.style !== 'subscript') {
1026
+ fail(
1027
+ `${segmentPath}[${index}].style`,
1028
+ 'must be subscript when provided'
1029
+ );
1030
+ }
1031
+ });
1032
+ };
1033
+ assertSegments(row.subtitleSegments, `${path}.subtitleSegments`);
1034
+ assertSegments(row.priceSegments, `${path}.priceSegments`);
1035
+ assertSegments(row.change.textSegments, `${path}.change.textSegments`);
1036
+ if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
1037
+ fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
1038
+ }
1039
+ assertMarketBadges(row.badges, path);
712
1040
  for (const [key, value] of [
713
1041
  ['pressActionKey', row.pressActionKey],
714
1042
  ['pressInActionKey', row.pressInActionKey],
@@ -753,6 +1081,55 @@ function assertTrailingAccessories(
753
1081
  ): void {
754
1082
  accessories?.forEach((accessory, index) => {
755
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');
756
1133
  if (
757
1134
  accessory.kind === 'progress' &&
758
1135
  (accessory.value < 0 || accessory.value > 1)
@@ -760,15 +1137,172 @@ function assertTrailingAccessories(
760
1137
  fail(`${accessoryPath}.value`, 'must be within 0...1');
761
1138
  }
762
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`);
763
1149
  assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
764
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
+ }
1183
+ }
1184
+ });
1185
+ }
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');
765
1244
  }
766
1245
  });
767
1246
  }
768
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
+
769
1294
  function assertImage(image: ImageSource | undefined, path: string): void {
770
1295
  if (!image) return;
771
1296
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
1297
+ if (image.fallbackUris !== undefined) {
1298
+ if (!Array.isArray(image.fallbackUris))
1299
+ fail(`${path}.fallbackUris`, 'must be an array');
1300
+ image.fallbackUris.forEach((uri, index) => {
1301
+ if (typeof uri !== 'string')
1302
+ fail(`${path}.fallbackUris[${index}]`, 'must be a string');
1303
+ assertText(uri, `${path}.fallbackUris[${index}]`);
1304
+ });
1305
+ }
772
1306
  if (
773
1307
  !Number.isFinite(image.width) ||
774
1308
  !Number.isFinite(image.height) ||
@@ -827,6 +1361,24 @@ function assertLeadingVisual(
827
1361
  assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
828
1362
  // OneKey patch: validate optional selector overlays at the JSON boundary.
829
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');
830
1382
  if ((visual.overlays?.length ?? 0) > 2)
831
1383
  fail(`${path}.overlays`, 'supports at most two overlays');
832
1384
  visual.overlays?.forEach((overlay, index) => {
@@ -886,7 +1438,34 @@ function assertLeadingVisual(
886
1438
  'must fit inside the overlay'
887
1439
  );
888
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
+ );
889
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
+ );
890
1469
  });
891
1470
  if (visual.kind === 'token') {
892
1471
  assertImage(visual.networkImage, `${path}.networkImage`);
@@ -918,6 +1497,8 @@ function assertVisual(row: RowModel, path: string): void {
918
1497
  }
919
1498
 
920
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');
921
1502
  assertText(row.title, `${path}.title`);
922
1503
  assertText(row.description, `${path}.description`);
923
1504
  if (
@@ -1082,6 +1663,18 @@ function assertRow(
1082
1663
  assertWalletGroup(row, path);
1083
1664
  break;
1084
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
+ }
1085
1678
  if (
1086
1679
  row.presentation !== undefined &&
1087
1680
  row.presentation !== 'walletSidebar' &&
@@ -1094,6 +1687,27 @@ function assertRow(
1094
1687
  );
1095
1688
  }
1096
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);
1097
1711
  assertText(row.subtitle, `${path}.subtitle`);
1098
1712
  // OneKey patch: selector text segments truncate independently.
1099
1713
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -1161,10 +1775,16 @@ function assertRow(
1161
1775
  assertActivity(row, path);
1162
1776
  break;
1163
1777
  case 'message':
1778
+ if (
1779
+ row.presentation !== undefined &&
1780
+ row.presentation !== 'inlineWarning'
1781
+ ) {
1782
+ fail(`${path}.presentation`, 'must be inlineWarning');
1783
+ }
1164
1784
  assertText(row.title, `${path}.title`);
1165
1785
  assertText(row.body, `${path}.body`);
1166
- if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
1167
- 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');
1168
1788
  }
1169
1789
  assertImage(row.thumbnail, `${path}.thumbnail`);
1170
1790
  break;
@@ -1175,6 +1795,23 @@ function assertRow(
1175
1795
  row.columns.forEach((column, columnIndex) => {
1176
1796
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
1177
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
+ }
1178
1815
  assertText(
1179
1816
  column.secondaryLeadingText,
1180
1817
  `${path}.columns[${columnIndex}].secondaryLeadingText`
@@ -1191,6 +1828,13 @@ function assertRow(
1191
1828
  if ((row.badges?.length ?? 0) > MAX_BADGES) {
1192
1829
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
1193
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`);
1194
1838
  break;
1195
1839
  case 'market':
1196
1840
  assertMarketRow(row, path);
@@ -1267,6 +1911,11 @@ function assertRow(
1267
1911
  assertText(row.title, `${path}.title`);
1268
1912
  assertText(row.subtitle, `${path}.subtitle`);
1269
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`);
1270
1919
  if (row.valueActionKey !== undefined) {
1271
1920
  assertKey(row.valueActionKey, `${path}.valueActionKey`);
1272
1921
  }
@@ -1299,6 +1948,9 @@ function assertRow(
1299
1948
  }
1300
1949
  assertTrailingAccessories(row.trailing, `${path}.trailing`);
1301
1950
  break;
1951
+ case 'buttonGroup':
1952
+ assertButtonGroup(row, path);
1953
+ break;
1302
1954
  case 'system':
1303
1955
  const presentation = 'presentation' in row ? row.presentation : undefined;
1304
1956
  if (presentation !== undefined && presentation !== 'market') {
@@ -1404,9 +2056,39 @@ function assertMediaPreview(value: unknown, path: string) {
1404
2056
  }
1405
2057
  }
1406
2058
 
1407
- export function validateSnapshot(
2059
+ function assertSnapshotContract(
1408
2060
  snapshot: NativeListSnapshot
1409
2061
  ): NativeListSnapshot {
2062
+ if (snapshot.disclosure !== undefined) {
2063
+ if (typeof snapshot.disclosure.expanded !== 'boolean')
2064
+ fail('snapshot.disclosure.expanded', 'must be a boolean');
2065
+ const inset = snapshot.disclosure.expandedTrailingInset;
2066
+ if (inset !== undefined && (!Number.isFinite(inset) || inset < 0))
2067
+ fail(
2068
+ 'snapshot.disclosure.expandedTrailingInset',
2069
+ 'must be finite and nonnegative'
2070
+ );
2071
+ }
2072
+ if (snapshot.structuralTransition) {
2073
+ assertKey(
2074
+ snapshot.structuralTransition.id,
2075
+ 'snapshot.structuralTransition.id'
2076
+ );
2077
+ if (snapshot.structuralTransition.anchorKey !== undefined)
2078
+ assertKey(
2079
+ snapshot.structuralTransition.anchorKey,
2080
+ 'snapshot.structuralTransition.anchorKey'
2081
+ );
2082
+ const duration = snapshot.structuralTransition.durationMs;
2083
+ if (
2084
+ duration !== undefined &&
2085
+ (!Number.isFinite(duration) || duration < 0 || duration > 2000)
2086
+ )
2087
+ fail(
2088
+ 'snapshot.structuralTransition.durationMs',
2089
+ 'must be finite within 0...2000'
2090
+ );
2091
+ }
1410
2092
  if (
1411
2093
  snapshot.capabilities?.refreshTriggerDistance !== undefined &&
1412
2094
  (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) ||
@@ -1418,6 +2100,22 @@ export function validateSnapshot(
1418
2100
  );
1419
2101
 
1420
2102
  assertPlainSerializable(snapshot, 'snapshot', new Set<object>());
2103
+ assertText(
2104
+ snapshot.theme?.imageFallbackBackground,
2105
+ 'theme.imageFallbackBackground'
2106
+ );
2107
+ if (
2108
+ snapshot.theme?.successBackground !== undefined &&
2109
+ (typeof snapshot.theme.successBackground !== 'string' ||
2110
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))
2111
+ )
2112
+ fail('theme.successBackground', 'must be a hex color');
2113
+ if (
2114
+ snapshot.theme?.rowHoverBackground !== undefined &&
2115
+ (typeof snapshot.theme.rowHoverBackground !== 'string' ||
2116
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))
2117
+ )
2118
+ fail('theme.rowHoverBackground', 'must be a hex color');
1421
2119
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
1422
2120
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
1423
2121
  fail('snapshot.generation', 'must be a non-negative safe integer');
@@ -1549,7 +2247,569 @@ export function validateSnapshot(
1549
2247
  'supports at most one key in single mode'
1550
2248
  );
1551
2249
  }
1552
- return normalizeSnapshotStyles(snapshot);
2250
+ return snapshot;
2251
+ }
2252
+
2253
+ function protocolObject(value: unknown, path: string): Record<string, unknown> {
2254
+ if (!value || typeof value !== 'object' || Array.isArray(value))
2255
+ fail(path, 'must be an object');
2256
+ return value as Record<string, unknown>;
2257
+ }
2258
+
2259
+ function protocolKey(value: unknown, path: string): void {
2260
+ if (typeof value !== 'string' || value.trim().length === 0)
2261
+ fail(path, 'must be a non-blank string');
2262
+ }
2263
+
2264
+ const PROTOCOL_ARRAY_FIELDS = new Set([
2265
+ 'columns',
2266
+ 'titleSuffixes',
2267
+ 'cells',
2268
+ 'points',
2269
+ 'images',
2270
+ 'overlays',
2271
+ 'badges',
2272
+ 'trailing',
2273
+ 'footerActions',
2274
+ 'buttons',
2275
+ 'amounts',
2276
+ 'metrics',
2277
+ 'children',
2278
+ 'subtitleSegments',
2279
+ 'titleMatch',
2280
+ 'selectedKeys',
2281
+ 'segments',
2282
+ 'hoverSecondary',
2283
+ 'hoverImages',
2284
+ 'secondaryBadges',
2285
+ 'fallbackUris',
2286
+ 'probeOrder',
2287
+ 'priceSegments',
2288
+ 'textSegments',
2289
+ 'secondaryTextSegments',
2290
+ 'primaryTextSegments',
2291
+ ]);
2292
+ const PROTOCOL_NUMBER_FIELDS = new Set([
2293
+ 'leadingContentMaxWidthRatio',
2294
+ 'height',
2295
+ 'width',
2296
+ 'fontSize',
2297
+ 'lineHeight',
2298
+ 'opacity',
2299
+ 'offsetY',
2300
+ 'offsetX',
2301
+ 'cornerRadius',
2302
+ 'borderWidth',
2303
+ 'horizontalPadding',
2304
+ 'verticalPadding',
2305
+ 'leadingGap',
2306
+ 'lineGap',
2307
+ 'titleBadgeGap',
2308
+ 'trailingGap',
2309
+ 'start',
2310
+ 'end',
2311
+ 'padding',
2312
+ 'offset',
2313
+ 'overscan',
2314
+ 'minWidth',
2315
+ 'flex',
2316
+ 'paddingStart',
2317
+ 'paddingEnd',
2318
+ 'changeWidth',
2319
+ 'changeHeight',
2320
+ 'changeCornerRadius',
2321
+ 'contentTrailingGap',
2322
+ 'subtitleTrailingPadding',
2323
+ 'partGap',
2324
+ 'contentPadding',
2325
+ 'contentPaddingHorizontal',
2326
+ 'contentPaddingTop',
2327
+ 'contentPaddingBottom',
2328
+ 'itemSpacing',
2329
+ 'gridColumns',
2330
+ ]);
2331
+
2332
+ /** Validate only shapes that renderers dereference, not display budgets. */
2333
+ function assertProtocolFields(
2334
+ value: unknown,
2335
+ path: string,
2336
+ parentField = ''
2337
+ ): void {
2338
+ if (value === undefined || value === null || typeof value !== 'object')
2339
+ return;
2340
+ if (Array.isArray(value)) {
2341
+ for (const [index, item] of value.entries()) {
2342
+ const itemPath = `${path}[${index}]`;
2343
+ if (
2344
+ ['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)
2345
+ ) {
2346
+ if (typeof item !== 'string') fail(itemPath, 'must be a string');
2347
+ } else if (parentField === 'points') {
2348
+ if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
2349
+ } else if (parentField === 'hoverImages' && item === null) continue;
2350
+ else protocolObject(item, itemPath);
2351
+ assertProtocolFields(item, itemPath, parentField);
2352
+ }
2353
+ return;
2354
+ }
2355
+ const object = value as Record<string, unknown>;
2356
+ if (parentField === 'fallbackIcon') {
2357
+ protocolKey(object.name, `${path}.name`);
2358
+ if (
2359
+ object.size !== undefined &&
2360
+ (typeof object.size !== 'number' ||
2361
+ !Number.isFinite(object.size) ||
2362
+ object.size <= 0 ||
2363
+ object.size > 40)
2364
+ )
2365
+ fail(`${path}.size`, 'must be within (0, 40]');
2366
+ for (const field of ['tintColor', 'backgroundColor'] as const) {
2367
+ const color = object[field];
2368
+ if (
2369
+ color !== undefined &&
2370
+ (typeof color !== 'string' ||
2371
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color))
2372
+ )
2373
+ fail(`${path}.${field}`, 'must be a hex color');
2374
+ }
2375
+ }
2376
+ if (
2377
+ parentField === 'overlays' &&
2378
+ object.fallbackIcon !== undefined &&
2379
+ !object.image
2380
+ )
2381
+ fail(`${path}.fallbackIcon`, 'requires image');
2382
+ if (
2383
+ !path.includes('.style.') &&
2384
+ ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(
2385
+ parentField
2386
+ ) &&
2387
+ typeof object.uri !== 'string'
2388
+ )
2389
+ fail(`${path}.uri`, 'must be a string');
2390
+ Object.entries(value).forEach(([field, item]) => {
2391
+ if (item === undefined) return;
2392
+ const fieldPath = `${path}.${field}`;
2393
+ if (
2394
+ !path.endsWith('.style') &&
2395
+ PROTOCOL_ARRAY_FIELDS.has(field) &&
2396
+ !Array.isArray(item)
2397
+ )
2398
+ fail(fieldPath, 'must be an array');
2399
+ if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number')
2400
+ fail(fieldPath, 'must be a finite number');
2401
+ if (
2402
+ PROTOCOL_NUMBER_FIELDS.has(field) &&
2403
+ typeof item === 'number' &&
2404
+ item < 0 &&
2405
+ !['offsetX', 'offsetY'].includes(field)
2406
+ )
2407
+ fail(fieldPath, 'must be non-negative');
2408
+ if (
2409
+ parentField === 'overlays' &&
2410
+ field === 'fontWeight' &&
2411
+ !['regular', 'medium', 'semibold', 'bold'].includes(item as string)
2412
+ )
2413
+ fail(fieldPath, 'must be regular, medium, semibold, or bold');
2414
+ if (field === 'buttonStyle' && item !== 'tertiary')
2415
+ fail(fieldPath, 'must be tertiary');
2416
+ if (field === 'hideLeading' && typeof item !== 'boolean')
2417
+ fail(fieldPath, 'must be boolean');
2418
+ if (
2419
+ field === 'key' ||
2420
+ field === 'sectionKey' ||
2421
+ field === 'actionKey' ||
2422
+ field.endsWith('ActionKey')
2423
+ )
2424
+ protocolKey(item, fieldPath);
2425
+ if (
2426
+ (field === 'uri' || field === 'fallbackUri') &&
2427
+ typeof item !== 'string'
2428
+ )
2429
+ fail(fieldPath, 'must be a string');
2430
+ if (
2431
+ (field === 'style' &&
2432
+ !(item === 'subscript' && /[Ss]egments\[/.test(path))) ||
2433
+ field === 'container'
2434
+ )
2435
+ protocolObject(item, fieldPath);
2436
+ if (
2437
+ path.endsWith('.style') &&
2438
+ [
2439
+ 'title',
2440
+ 'subtitle',
2441
+ 'tertiary',
2442
+ 'body',
2443
+ 'time',
2444
+ 'price',
2445
+ 'change',
2446
+ 'columns',
2447
+ 'columnSecondary',
2448
+ 'value',
2449
+ 'valueSecondary',
2450
+ 'badge',
2451
+ 'description',
2452
+ 'status',
2453
+ 'primaryAmount',
2454
+ 'secondaryAmount',
2455
+ 'trend',
2456
+ 'message',
2457
+ 'actionText',
2458
+ ].includes(field)
2459
+ )
2460
+ protocolObject(item, fieldPath);
2461
+ assertProtocolFields(item, fieldPath, field);
2462
+ });
2463
+ }
2464
+
2465
+ function assertRowProtocol(row: RowModel, path: string): void {
2466
+ protocolObject(row, path);
2467
+ assertRowType(row.type, path);
2468
+ protocolKey(row.key, `${path}.key`);
2469
+ assertProtocolFields(row, path);
2470
+ for (const field of ['leading', 'visual', 'secondaryLeading'] as const) {
2471
+ const visual = (row as unknown as Record<string, unknown>)[field];
2472
+ if (
2473
+ visual !== undefined ||
2474
+ (field === 'leading' &&
2475
+ (row.type === 'identity' || row.type === 'market'))
2476
+ ) {
2477
+ const object = protocolObject(visual, `${path}.${field}`);
2478
+ if (object.kind === 'stackedImages' && !Array.isArray(object.images))
2479
+ fail(`${path}.${field}.images`, 'must be an array');
2480
+ }
2481
+ }
2482
+ for (const field of [
2483
+ 'title',
2484
+ 'subtitle',
2485
+ 'tertiary',
2486
+ 'body',
2487
+ 'time',
2488
+ 'price',
2489
+ 'indexTitle',
2490
+ ] as const) {
2491
+ const value = (row as unknown as Record<string, unknown>)[field];
2492
+ if (value !== undefined && typeof value !== 'string')
2493
+ fail(`${path}.${field}`, 'must be a string');
2494
+ }
2495
+ if (row.height !== undefined && row.height < 0)
2496
+ fail(`${path}.height`, 'must be non-negative');
2497
+ if (row.type === 'identity') {
2498
+ assertIdentityExtras(row, path);
2499
+ if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes))
2500
+ fail(`${path}.titleSuffixes`, 'must be an array');
2501
+ row.titleSuffixes?.forEach((suffix, index) => {
2502
+ protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
2503
+ if (
2504
+ typeof suffix.text !== 'string' ||
2505
+ !['secondary', 'disabled'].includes(suffix.tone)
2506
+ )
2507
+ fail(`${path}.titleSuffixes[${index}]`, 'invalid title suffix');
2508
+ if (
2509
+ suffix.maxWidth !== undefined &&
2510
+ (!Number.isFinite(suffix.maxWidth) ||
2511
+ suffix.maxWidth < 0 ||
2512
+ suffix.maxWidth > 4096)
2513
+ )
2514
+ fail(
2515
+ `${path}.titleSuffixes[${index}].maxWidth`,
2516
+ 'must be finite within 0...4096'
2517
+ );
2518
+ });
2519
+ let end = 0;
2520
+ row.titleMatch?.forEach((match) => {
2521
+ if (
2522
+ !Number.isInteger(match.start) ||
2523
+ !Number.isInteger(match.end) ||
2524
+ match.start < end ||
2525
+ match.end <= match.start ||
2526
+ match.end > row.title.length
2527
+ )
2528
+ fail(`${path}.titleMatch`, 'invalid text range');
2529
+ end = match.end;
2530
+ });
2531
+ }
2532
+ if (row.type === 'buttonGroup') assertButtonGroup(row, path);
2533
+ if (row.type === 'sectionHeader')
2534
+ assertTextHelp(row.valueHelp, `${path}.valueHelp`);
2535
+ if (row.type === 'mediaTile' && row.media) {
2536
+ protocolObject(row.media.source, `${path}.media.source`);
2537
+ if (!Array.isArray(row.media.probeOrder))
2538
+ fail(`${path}.media.probeOrder`, 'must be an array');
2539
+ }
2540
+ if (row.type === 'walletGroup') {
2541
+ protocolObject(row.parent, `${path}.parent`);
2542
+ if (!Array.isArray(row.children))
2543
+ fail(`${path}.children`, 'must be an array');
2544
+ const members = [row.parent, ...row.children];
2545
+ const keys = new Set<string>();
2546
+ if (row.parent.key !== row.key)
2547
+ fail(`${path}.parent.key`, 'must match its group');
2548
+ members.forEach((member, index) => {
2549
+ assertRowProtocol(member, `${path}.members[${index}]`);
2550
+ if (member.type !== 'identity' || keys.has(member.key))
2551
+ fail(path, 'invalid wallet member identity');
2552
+ keys.add(member.key);
2553
+ });
2554
+ }
2555
+ if (row.type === 'dataRow') {
2556
+ if (!Array.isArray(row.columns))
2557
+ fail(`${path}.columns`, 'must be an array');
2558
+ row.columns.forEach((column, index) => {
2559
+ const columnPath = `${path}.columns[${index}]`;
2560
+ protocolObject(column, columnPath);
2561
+ assertIdentityExtras(column, columnPath);
2562
+ });
2563
+ assertTrailingAccessories(row.trailing, `${path}.trailing`);
2564
+ }
2565
+ if (row.type === 'market') {
2566
+ protocolObject(row.change, `${path}.change`);
2567
+ if (row.webTable) {
2568
+ const { columns, cells } = row.webTable;
2569
+ if (
2570
+ !Array.isArray(columns) ||
2571
+ !Array.isArray(cells) ||
2572
+ columns.length !== cells.length
2573
+ )
2574
+ fail(`${path}.webTable`, 'columns and cells must match');
2575
+ const keys = new Set<string>();
2576
+ columns.forEach((column, index) => {
2577
+ protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
2578
+ if (keys.has(column.key) || cells[index]?.key !== column.key)
2579
+ fail(`${path}.webTable`, 'invalid column identity');
2580
+ keys.add(column.key);
2581
+ const cell = cells[index];
2582
+ if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind))
2583
+ fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
2584
+ if (cell.kind === 'asset')
2585
+ protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
2586
+ if (
2587
+ (cell.kind === 'asset' || cell.kind === 'text') &&
2588
+ cell.secondary !== undefined &&
2589
+ !Array.isArray(cell.secondary)
2590
+ )
2591
+ fail(
2592
+ `${path}.webTable.cells[${index}].secondary`,
2593
+ 'must be an array'
2594
+ );
2595
+ if (cell.kind === 'text' && !Array.isArray(cell.primary))
2596
+ fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
2597
+ // The Web renderer spreads samples into Math.min/Math.max.
2598
+ if (
2599
+ cell.kind === 'sparkline' &&
2600
+ (!Array.isArray(cell.points) || cell.points.length > 256)
2601
+ )
2602
+ fail(
2603
+ `${path}.webTable.cells[${index}].points`,
2604
+ 'must be an array of at most 256 samples'
2605
+ );
2606
+ });
2607
+ }
2608
+ }
2609
+ }
2610
+
2611
+ function assertSnapshotProtocol(snapshot: NativeListSnapshot): void {
2612
+ protocolObject(snapshot, 'snapshot');
2613
+ if (snapshot.disclosure !== undefined) {
2614
+ protocolObject(snapshot.disclosure, 'snapshot.disclosure');
2615
+ if (typeof snapshot.disclosure.expanded !== 'boolean')
2616
+ fail('snapshot.disclosure.expanded', 'must be a boolean');
2617
+ const inset = snapshot.disclosure.expandedTrailingInset;
2618
+ if (inset !== undefined && (!Number.isFinite(inset) || inset < 0))
2619
+ fail(
2620
+ 'snapshot.disclosure.expandedTrailingInset',
2621
+ 'must be finite and nonnegative'
2622
+ );
2623
+ }
2624
+ if (snapshot.structuralTransition) {
2625
+ protocolObject(
2626
+ snapshot.structuralTransition,
2627
+ 'snapshot.structuralTransition'
2628
+ );
2629
+ protocolKey(
2630
+ snapshot.structuralTransition.id,
2631
+ 'snapshot.structuralTransition.id'
2632
+ );
2633
+ if (snapshot.structuralTransition.anchorKey !== undefined)
2634
+ protocolKey(
2635
+ snapshot.structuralTransition.anchorKey,
2636
+ 'snapshot.structuralTransition.anchorKey'
2637
+ );
2638
+ const duration = snapshot.structuralTransition.durationMs;
2639
+ if (
2640
+ duration !== undefined &&
2641
+ (!Number.isFinite(duration) || duration < 0 || duration > 2000)
2642
+ )
2643
+ fail(
2644
+ 'snapshot.structuralTransition.durationMs',
2645
+ 'must be finite within 0...2000'
2646
+ );
2647
+ }
2648
+ if (
2649
+ snapshot.theme?.successBackground !== undefined &&
2650
+ (typeof snapshot.theme.successBackground !== 'string' ||
2651
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))
2652
+ )
2653
+ fail('theme.successBackground', 'must be a hex color');
2654
+ if (
2655
+ snapshot.theme?.rowHoverBackground !== undefined &&
2656
+ (typeof snapshot.theme.rowHoverBackground !== 'string' ||
2657
+ !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))
2658
+ )
2659
+ fail('theme.rowHoverBackground', 'must be a hex color');
2660
+ if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
2661
+ if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0)
2662
+ fail('snapshot.generation', 'must be a non-negative safe integer');
2663
+ protocolObject(snapshot.layout, 'snapshot.layout');
2664
+ assertProtocolFields(snapshot.layout, 'snapshot.layout');
2665
+ if (
2666
+ snapshot.layout.orientation !== undefined &&
2667
+ !['vertical', 'horizontal'].includes(snapshot.layout.orientation)
2668
+ )
2669
+ fail('snapshot.layout.orientation', 'is not supported');
2670
+ if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind))
2671
+ fail('snapshot.layout.kind', 'is not supported');
2672
+ if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
2673
+ if (
2674
+ snapshot.layout.kind === 'grid' &&
2675
+ (!Number.isInteger(snapshot.layout.gridColumns) ||
2676
+ (snapshot.layout.gridColumns ?? 0) < 1 ||
2677
+ (snapshot.layout.gridColumns ?? 0) > 7)
2678
+ )
2679
+ fail('snapshot.layout.gridColumns', 'must be an integer from 1 to 7');
2680
+ const keys = new Set<string>();
2681
+ for (const [index, row] of snapshot.rows.entries()) {
2682
+ assertRowProtocol(row, `rows[${index}]`);
2683
+ if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
2684
+ keys.add(row.key);
2685
+ }
2686
+ if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
2687
+ if (snapshot.fixedFooter)
2688
+ assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
2689
+ if (snapshot.selection) {
2690
+ if (!Array.isArray(snapshot.selection.selectedKeys))
2691
+ fail('snapshot.selection.selectedKeys', 'must be an array');
2692
+ snapshot.selection.selectedKeys.forEach((key) => {
2693
+ if (!keys.has(key))
2694
+ fail('snapshot.selection.selectedKeys', 'unknown row identity');
2695
+ });
2696
+ }
2697
+ }
2698
+
2699
+ /** Empty optional image descriptors must take the same path as absent images. */
2700
+ function normalizeEmptyImages(value: unknown, field = ''): unknown {
2701
+ if (!value || typeof value !== 'object') return value;
2702
+ if (Array.isArray(value)) {
2703
+ const next = value.map((item) => normalizeEmptyImages(item));
2704
+ const filtered =
2705
+ field === 'images'
2706
+ ? next.filter((item) => item !== undefined)
2707
+ : next.map((item) => (item === undefined ? null : item));
2708
+ return filtered.length === value.length &&
2709
+ filtered.every((item, index) => item === value[index])
2710
+ ? value
2711
+ : filtered;
2712
+ }
2713
+ const object = value as Record<string, unknown>;
2714
+ if (
2715
+ typeof object.uri === 'string' &&
2716
+ !object.uri.trim() &&
2717
+ 'width' in object &&
2718
+ 'height' in object
2719
+ )
2720
+ return undefined;
2721
+ let changed = false;
2722
+ const next = { ...object };
2723
+ Object.entries(object).forEach(([key, item]) => {
2724
+ const normalized = normalizeEmptyImages(item, key);
2725
+ if (normalized !== item) {
2726
+ // Omitted JSON patch fields must also be absent from the JS merge.
2727
+ if (field === 'changes' && normalized === undefined) delete next[key];
2728
+ else next[key] = normalized;
2729
+ changed = true;
2730
+ }
2731
+ });
2732
+ if (field === 'media' && next.source === undefined) return undefined;
2733
+ return changed ? next : value;
2734
+ }
2735
+
2736
+ export function validateSnapshot(
2737
+ snapshot: NativeListSnapshot
2738
+ ): NativeListSnapshot {
2739
+ assertPlainSerializable(snapshot, 'snapshot', new Set<object>());
2740
+ if (isDevelopment()) assertSnapshotContract(snapshot);
2741
+ const normalized = isDevelopment()
2742
+ ? snapshot
2743
+ : (normalizeEmptyImages(snapshot) as NativeListSnapshot);
2744
+ assertSnapshotProtocol(normalized);
2745
+ return normalizeSnapshotStyles(normalized);
2746
+ }
2747
+
2748
+ const ownedNativeSnapshots = new WeakMap<
2749
+ NativeListSnapshot,
2750
+ ReadonlyMap<string, number>
2751
+ >();
2752
+
2753
+ function capturePlainData<T>(value: T, seen = new Map<object, object>()): T {
2754
+ if (value === null || typeof value !== 'object') return value;
2755
+ const previous = seen.get(value);
2756
+ if (previous) return previous as T;
2757
+ const copy: Record<string, unknown> | unknown[] = Array.isArray(value)
2758
+ ? new Array(value.length)
2759
+ : Object.create(Object.getPrototypeOf(value));
2760
+ seen.set(value, copy);
2761
+ const captureKey = (key: string) => {
2762
+ Object.defineProperty(copy, key, {
2763
+ value: capturePlainData((value as Record<string, unknown>)[key], seen),
2764
+ enumerable: true,
2765
+ writable: true,
2766
+ configurable: true,
2767
+ });
2768
+ };
2769
+ if (Array.isArray(value)) {
2770
+ for (let index = 0; index < value.length; index += 1) {
2771
+ if (index in value) captureKey(String(index));
2772
+ }
2773
+ Object.keys(value).forEach((key) => {
2774
+ const index = Number(key);
2775
+ if (
2776
+ Number.isInteger(index) &&
2777
+ index >= 0 &&
2778
+ index < value.length &&
2779
+ String(index) === key
2780
+ )
2781
+ return;
2782
+ captureKey(key);
2783
+ });
2784
+ } else {
2785
+ Object.keys(value).forEach(captureKey);
2786
+ }
2787
+ return copy as T;
2788
+ }
2789
+
2790
+ function deepFreeze<T>(value: T, seen = new WeakSet<object>()): T {
2791
+ if (value === null || typeof value !== 'object' || seen.has(value))
2792
+ return value;
2793
+ seen.add(value);
2794
+ Object.values(value).forEach((item) => deepFreeze(item, seen));
2795
+ return Object.freeze(value);
2796
+ }
2797
+
2798
+ /** Capture caller data once before validation, including accessor values. */
2799
+ export function captureNativeListInput<T>(value: T): T {
2800
+ return capturePlainData(value);
2801
+ }
2802
+
2803
+ /** Private native-wrapper ownership; exported validators keep their public identity. */
2804
+ export function ownValidatedNativeSnapshot(
2805
+ snapshot: NativeListSnapshot
2806
+ ): NativeListSnapshot {
2807
+ const owned = deepFreeze(snapshot);
2808
+ ownedNativeSnapshots.set(
2809
+ owned,
2810
+ new Map(owned.rows.map((row, index) => [row.key, index]))
2811
+ );
2812
+ return owned;
1553
2813
  }
1554
2814
 
1555
2815
  /**
@@ -1608,7 +2868,46 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1608
2868
 
1609
2869
  switch (patch.type) {
1610
2870
  case 'identity':
2871
+ if (
2872
+ patch.changes.contentHeight !== undefined &&
2873
+ patch.changes.contentHeight !== 'auto'
2874
+ ) {
2875
+ fail(`${path}.contentHeight`, 'must be auto');
2876
+ }
2877
+ if (
2878
+ patch.changes.subtitleLines !== undefined &&
2879
+ ![0, 1, 2].includes(patch.changes.subtitleLines)
2880
+ ) {
2881
+ fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
2882
+ }
2883
+ if (patch.changes.longPressActionKey !== undefined) {
2884
+ assertKey(
2885
+ patch.changes.longPressActionKey,
2886
+ `${path}.longPressActionKey`
2887
+ );
2888
+ }
1611
2889
  assertText(patch.changes.title, `${path}.title`);
2890
+ if ((patch.changes.titleSuffixes?.length ?? 0) > 3)
2891
+ fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
2892
+ patch.changes.titleSuffixes?.forEach((suffix, index) => {
2893
+ assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
2894
+ if (!['secondary', 'disabled'].includes(suffix.tone))
2895
+ fail(
2896
+ `${path}.titleSuffixes[${index}].tone`,
2897
+ 'must be secondary or disabled'
2898
+ );
2899
+ if (
2900
+ suffix.maxWidth !== undefined &&
2901
+ (!Number.isFinite(suffix.maxWidth) ||
2902
+ suffix.maxWidth < 0 ||
2903
+ suffix.maxWidth > 4096)
2904
+ )
2905
+ fail(
2906
+ `${path}.titleSuffixes[${index}].maxWidth`,
2907
+ 'must be finite within 0...4096'
2908
+ );
2909
+ });
2910
+ assertIdentityExtras(patch.changes, path);
1612
2911
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1613
2912
  assertText(patch.changes.tertiary, `${path}.tertiary`);
1614
2913
  if (
@@ -1657,14 +2956,20 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1657
2956
  }
1658
2957
  break;
1659
2958
  case 'message':
2959
+ if (
2960
+ patch.changes.presentation !== undefined &&
2961
+ patch.changes.presentation !== 'inlineWarning'
2962
+ ) {
2963
+ fail(`${path}.presentation`, 'must be inlineWarning');
2964
+ }
1660
2965
  assertText(patch.changes.title, `${path}.title`);
1661
2966
  assertText(patch.changes.body, `${path}.body`);
1662
2967
  assertText(patch.changes.time, `${path}.time`);
1663
2968
  if (
1664
2969
  patch.changes.bodyLines !== undefined &&
1665
- ![1, 2, 3].includes(patch.changes.bodyLines)
2970
+ ![0, 1, 2, 3].includes(patch.changes.bodyLines)
1666
2971
  ) {
1667
- fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
2972
+ fail(`${path}.bodyLines`, 'must be 0, 1, 2, or 3');
1668
2973
  }
1669
2974
  assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
1670
2975
  break;
@@ -1678,6 +2983,23 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1678
2983
  patch.changes.columns?.forEach((column, columnIndex) => {
1679
2984
  assertKey(column.key, `${path}.columns[${columnIndex}].key`);
1680
2985
  assertText(column.text, `${path}.columns[${columnIndex}].text`);
2986
+ assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
2987
+ for (const field of [
2988
+ 'textSegments',
2989
+ 'secondaryTextSegments',
2990
+ ] as const) {
2991
+ column[field]?.forEach((segment, segmentIndex) => {
2992
+ assertText(
2993
+ segment.text,
2994
+ `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`
2995
+ );
2996
+ if (segment.style !== undefined && segment.style !== 'subscript')
2997
+ fail(
2998
+ `${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`,
2999
+ 'must be subscript'
3000
+ );
3001
+ });
3002
+ }
1681
3003
  assertText(
1682
3004
  column.secondaryText,
1683
3005
  `${path}.columns[${columnIndex}].secondaryText`
@@ -1690,6 +3012,13 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1690
3012
  if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
1691
3013
  fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
1692
3014
  }
3015
+ if ((patch.changes.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
3016
+ fail(
3017
+ `${path}.trailing`,
3018
+ `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`
3019
+ );
3020
+ }
3021
+ assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
1693
3022
  break;
1694
3023
  case 'market':
1695
3024
  assertMarketRow(
@@ -1764,6 +3093,14 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1764
3093
  assertText(patch.changes.title, `${path}.title`);
1765
3094
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1766
3095
  assertText(patch.changes.value, `${path}.value`);
3096
+ if (patch.changes.leadingBadge) {
3097
+ assertKey(patch.changes.leadingBadge.key, `${path}.leadingBadge.key`);
3098
+ assertText(
3099
+ patch.changes.leadingBadge.text,
3100
+ `${path}.leadingBadge.text`
3101
+ );
3102
+ }
3103
+ assertTextHelp(patch.changes.valueHelp, `${path}.valueHelp`);
1767
3104
  if (patch.changes.valueActionKey !== undefined) {
1768
3105
  assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
1769
3106
  }
@@ -1786,6 +3123,10 @@ function assertPatchChanges(patch: RowPatch, index: number): void {
1786
3123
  }
1787
3124
  assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
1788
3125
  break;
3126
+ case 'buttonGroup':
3127
+ if (patch.changes.buttons !== undefined)
3128
+ assertButtonGroup({ buttons: patch.changes.buttons }, path);
3129
+ break;
1789
3130
  case 'system':
1790
3131
  assertText(patch.changes.message, `${path}.message`);
1791
3132
  break;
@@ -1798,18 +3139,32 @@ export function validatePatches(
1798
3139
  patches: readonly RowPatch[]
1799
3140
  ): readonly RowPatch[] {
1800
3141
  assertPlainSerializable(patches, 'patches', new Set<object>());
3142
+ if (!Array.isArray(patches)) fail('patches', 'must be an array');
1801
3143
  const keys = new Set<string>();
1802
- patches.forEach((patch, index) => {
1803
- assertKey(patch.key, `patches[${index}].key`);
3144
+ for (const [index, patch] of patches.entries()) {
3145
+ protocolObject(patch, `patches[${index}]`);
3146
+ protocolKey(patch.key, `patches[${index}].key`);
1804
3147
  if (keys.has(patch.key))
1805
3148
  fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
1806
3149
  keys.add(patch.key);
3150
+ protocolObject(patch.changes, `patches[${index}].changes`);
3151
+ assertRowType(patch.type, `patches[${index}]`);
3152
+ assertProtocolFields(patch.changes, `patches[${index}].changes`);
3153
+ if (patch.type === 'identity')
3154
+ assertIdentityExtras(patch.changes, `patches[${index}].changes`);
3155
+ if (!isDevelopment()) continue;
3156
+ assertKey(patch.key, `patches[${index}].key`);
1807
3157
  if (Object.keys(patch.changes).length === 0) {
1808
3158
  fail(`patches[${index}].changes`, 'must contain at least one field');
1809
3159
  }
1810
3160
  assertPatchChanges(patch, index);
1811
- });
1812
- return normalizePatchStyles(patches);
3161
+ }
3162
+ const normalized = isDevelopment()
3163
+ ? patches
3164
+ : (normalizeEmptyImages(patches) as readonly RowPatch[]);
3165
+ return normalizePatchStyles(
3166
+ normalized.filter((patch) => Object.keys(patch.changes).length > 0)
3167
+ );
1813
3168
  }
1814
3169
 
1815
3170
  /** Patches reach the native side without passing through a snapshot. */
@@ -1831,14 +3186,126 @@ function normalizePatchStyles(
1831
3186
  return changed ? next : patches;
1832
3187
  }
1833
3188
 
3189
+ const EMPTY_ROW_PATCHES: readonly RowPatch[] = Object.freeze([]);
3190
+
3191
+ function sameJsonValue(left: unknown, right: unknown): boolean {
3192
+ if (left === right) return true;
3193
+ if (left === null || right === null) return false;
3194
+ if (typeof left !== 'object' || typeof right !== 'object') return false;
3195
+ if (Array.isArray(left) || Array.isArray(right)) {
3196
+ return (
3197
+ Array.isArray(left) &&
3198
+ Array.isArray(right) &&
3199
+ left.length === right.length &&
3200
+ left.every((value, index) => sameJsonValue(value, right[index]))
3201
+ );
3202
+ }
3203
+ const leftObject = left as Record<string, unknown>;
3204
+ const rightObject = right as Record<string, unknown>;
3205
+ const leftKeys = Object.keys(leftObject).filter(
3206
+ (key) => leftObject[key] !== undefined
3207
+ );
3208
+ const rightKeys = Object.keys(rightObject).filter(
3209
+ (key) => rightObject[key] !== undefined
3210
+ );
3211
+ return (
3212
+ leftKeys.length === rightKeys.length &&
3213
+ leftKeys.every((key) => sameJsonValue(leftObject[key], rightObject[key]))
3214
+ );
3215
+ }
3216
+
3217
+ function sameOptionalPresence(left: unknown, right: unknown): boolean {
3218
+ return (left === undefined) === (right === undefined);
3219
+ }
3220
+
3221
+ /** Plan value-only patches; callers own valid immutable snapshots and commit state. */
3222
+ export function planNativeListPatches(
3223
+ previous: NativeListSnapshot,
3224
+ next: NativeListSnapshot
3225
+ ): readonly RowPatch[] | undefined {
3226
+ if (previous === next) return EMPTY_ROW_PATCHES;
3227
+ const { rows: previousRows, ...previousMetadata } = previous;
3228
+ const { rows: nextRows, ...nextMetadata } = next;
3229
+ if (
3230
+ previousRows.length !== nextRows.length ||
3231
+ !sameJsonValue(previousMetadata, nextMetadata)
3232
+ )
3233
+ return undefined;
3234
+ if (previousRows === nextRows) return EMPTY_ROW_PATCHES;
3235
+
3236
+ const patches: RowPatch[] = [];
3237
+ for (let index = 0; index < nextRows.length; index += 1) {
3238
+ const oldRow = previousRows[index];
3239
+ const row = nextRows[index];
3240
+ if (oldRow.key !== row.key || oldRow.type !== row.type) return undefined;
3241
+ if (oldRow === row) continue;
3242
+
3243
+ if (oldRow.type === 'identity' && row.type === 'identity') {
3244
+ const {
3245
+ subtitle: oldSubtitle,
3246
+ subtitleSegments: oldSubtitleSegments,
3247
+ trailing: oldTrailing,
3248
+ ...oldMetadata
3249
+ } = oldRow;
3250
+ const { subtitle, subtitleSegments, trailing, ...metadata } = row;
3251
+ if (
3252
+ !sameOptionalPresence(oldSubtitle, subtitle) ||
3253
+ !sameOptionalPresence(oldSubtitleSegments, subtitleSegments) ||
3254
+ !sameOptionalPresence(oldTrailing, trailing) ||
3255
+ !sameJsonValue(oldMetadata, metadata)
3256
+ )
3257
+ return undefined;
3258
+ if (
3259
+ !sameJsonValue(oldSubtitle, subtitle) ||
3260
+ !sameJsonValue(oldSubtitleSegments, subtitleSegments) ||
3261
+ !sameJsonValue(oldTrailing, trailing)
3262
+ ) {
3263
+ patches.push({
3264
+ type: 'identity',
3265
+ key: row.key,
3266
+ changes: { subtitle, subtitleSegments, trailing },
3267
+ });
3268
+ }
3269
+ } else if (oldRow.type === 'dataRow' && row.type === 'dataRow') {
3270
+ const {
3271
+ columns: oldColumns,
3272
+ trailing: oldTrailing,
3273
+ ...oldMetadata
3274
+ } = oldRow;
3275
+ const { columns, trailing, ...metadata } = row;
3276
+ if (
3277
+ !sameOptionalPresence(oldTrailing, trailing) ||
3278
+ !sameJsonValue(oldMetadata, metadata) ||
3279
+ !sameJsonValue(oldColumns[0], columns[0])
3280
+ )
3281
+ return undefined;
3282
+ if (
3283
+ !sameJsonValue(oldColumns.slice(1), columns.slice(1)) ||
3284
+ !sameJsonValue(oldTrailing, trailing)
3285
+ ) {
3286
+ patches.push({
3287
+ type: 'dataRow',
3288
+ key: row.key,
3289
+ changes: { columns, trailing },
3290
+ });
3291
+ }
3292
+ } else if (!sameJsonValue(oldRow, row)) {
3293
+ return undefined;
3294
+ }
3295
+ }
3296
+ return patches.length === 0 ? EMPTY_ROW_PATCHES : patches;
3297
+ }
3298
+
1834
3299
  export function applyRowPatches(
1835
3300
  snapshot: NativeListSnapshot,
1836
3301
  patches: readonly RowPatch[]
1837
3302
  ): NativeListSnapshot {
1838
- validatePatches(patches);
1839
- const patchByKey = new Map(patches.map((patch) => [patch.key, patch]));
3303
+ const normalizedPatches = validatePatches(patches);
3304
+ const patchByKey = new Map(
3305
+ normalizedPatches.map((patch) => [patch.key, patch])
3306
+ );
1840
3307
  const knownKeys = new Set(snapshot.rows.map((row) => row.key));
1841
- patches.forEach((patch) => {
3308
+ normalizedPatches.forEach((patch) => {
1842
3309
  if (!knownKeys.has(patch.key))
1843
3310
  fail('patches', `unknown row key "${patch.key}"`);
1844
3311
  });
@@ -1848,6 +3315,19 @@ export function applyRowPatches(
1848
3315
  if (patch.type !== row.type) {
1849
3316
  fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
1850
3317
  }
3318
+ if (
3319
+ row.type === 'market' &&
3320
+ row.webTable &&
3321
+ patch.type === 'market' &&
3322
+ (patch.changes.price !== undefined ||
3323
+ patch.changes.priceSegments !== undefined ||
3324
+ patch.changes.change !== undefined) &&
3325
+ patch.changes.webTable === undefined
3326
+ )
3327
+ fail(
3328
+ 'patches',
3329
+ 'table quote changes must include the visible table cells'
3330
+ );
1851
3331
  return {
1852
3332
  ...row,
1853
3333
  ...patch.changes,
@@ -1858,6 +3338,85 @@ export function applyRowPatches(
1858
3338
  return validateSnapshot({ ...snapshot, rows });
1859
3339
  }
1860
3340
 
3341
+ /** Native wrapper only: preserve full public validation for unsupported patches. */
3342
+ export function applyOwnedNativePatches(
3343
+ snapshot: NativeListSnapshot,
3344
+ patches: readonly RowPatch[]
3345
+ ): {
3346
+ patches: readonly RowPatch[];
3347
+ snapshot: NativeListSnapshot;
3348
+ json: string;
3349
+ } {
3350
+ const acceptedPatches = deepFreeze(
3351
+ validatePatches(capturePlainData(patches))
3352
+ );
3353
+ const rowIndexes = ownedNativeSnapshots.get(snapshot);
3354
+ const canPatchRows =
3355
+ rowIndexes !== undefined &&
3356
+ acceptedPatches.every((patch) => {
3357
+ const index = rowIndexes.get(patch.key);
3358
+ if (index === undefined || snapshot.rows[index].type !== patch.type)
3359
+ return false;
3360
+ const allowed =
3361
+ patch.type === 'identity'
3362
+ ? ['subtitle', 'subtitleSegments', 'trailing']
3363
+ : patch.type === 'dataRow'
3364
+ ? ['columns', 'trailing']
3365
+ : undefined;
3366
+ return (
3367
+ allowed !== undefined &&
3368
+ Object.entries(patch.changes).every(
3369
+ ([key, value]) =>
3370
+ allowed.includes(key) &&
3371
+ (value !== undefined ||
3372
+ (snapshot.rows[index] as unknown as Record<string, unknown>)[
3373
+ key
3374
+ ] === undefined)
3375
+ )
3376
+ );
3377
+ });
3378
+ if (!canPatchRows) {
3379
+ const baseline = rowIndexes ? snapshot : capturePlainData(snapshot);
3380
+ return {
3381
+ patches: acceptedPatches,
3382
+ snapshot: ownValidatedNativeSnapshot(
3383
+ applyRowPatches(baseline, acceptedPatches)
3384
+ ),
3385
+ json: JSON.stringify(acceptedPatches),
3386
+ };
3387
+ }
3388
+
3389
+ const nextRows = snapshot.rows.slice();
3390
+ for (const patch of acceptedPatches) {
3391
+ const index = rowIndexes.get(patch.key)!;
3392
+ const previous = nextRows[index];
3393
+ const merged = {
3394
+ ...previous,
3395
+ ...patch.changes,
3396
+ key: previous.key,
3397
+ type: previous.type,
3398
+ } as RowModel;
3399
+ const path = `rows[${index}]`;
3400
+ assertPlainSerializable(merged, path, new Set<object>());
3401
+ if (isDevelopment()) assertRow(merged, index);
3402
+ const normalized = isDevelopment()
3403
+ ? merged
3404
+ : (normalizeEmptyImages(merged) as RowModel);
3405
+ assertRowProtocol(normalized, path);
3406
+ nextRows[index] = deepFreeze(normalizeRowStyles(normalized));
3407
+ }
3408
+ const nextSnapshot = Object.freeze({
3409
+ ...snapshot,
3410
+ rows: Object.freeze(nextRows),
3411
+ });
3412
+ ownedNativeSnapshots.set(nextSnapshot, rowIndexes);
3413
+ return {
3414
+ patches: acceptedPatches,
3415
+ snapshot: nextSnapshot,
3416
+ json: JSON.stringify(acceptedPatches),
3417
+ };
3418
+ }
3419
+
1861
3420
  export function serializeSnapshot(snapshot: NativeListSnapshot): string {
1862
3421
  return JSON.stringify(validateSnapshot(snapshot));
1863
3422
  }