@onekeyfe/react-native-native-list 6.7.0-alpha.354 → 6.7.0-alpha.362
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +0 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +7 -240
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +4 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +3 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +0 -12
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +7 -87
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +1 -135
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +14 -43
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +0 -25
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +2 -17
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +0 -22
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +2 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +0 -69
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +1 -55
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +21 -585
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +0 -1
- package/docs/ROW_TEMPLATES.md +9 -60
- package/docs/SPEC.md +5 -317
- package/docs/STYLE_SPEC.md +0 -6
- package/ios/HybridNativeList.swift +0 -10
- package/ios/NativeListAccessoryStack.swift +37 -220
- package/ios/NativeListActivityDetailsView.swift +8 -18
- package/ios/NativeListActivityRenderer.swift +2 -8
- package/ios/NativeListDataRowRenderer.swift +8 -105
- package/ios/NativeListDesignAssets.swift +0 -3
- package/ios/NativeListIdentityRenderer.swift +4 -119
- package/ios/NativeListLeadingVisual.swift +14 -49
- package/ios/NativeListMessageRenderer.swift +1 -34
- package/ios/NativeListModels.swift +2 -16
- package/ios/NativeListRendererRegistry.swift +0 -1
- package/ios/NativeListResolvedText.swift +1 -2
- package/ios/NativeListRowHost.swift +0 -14
- package/ios/NativeListSectionHeaderRenderer.swift +0 -88
- package/ios/RNCNativeListView.swift +29 -331
- package/ios/tests/NativeListActivityPresentationTests.swift +0 -56
- package/ios/tests/NativeListLifecycleTests.swift +3 -890
- package/lib/module/NativeList.js +21 -39
- package/lib/module/NativeList.web.js +4 -51
- package/lib/module/models.js +0 -1
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +8 -320
- package/lib/module/web/NativeListWebEngine.js +18 -373
- package/lib/module/web/templates/ActivityRowRenderer.js +7 -8
- package/lib/module/web/templates/DataRowRenderer.js +5 -40
- package/lib/module/web/templates/IdentityRowRenderer.js +4 -90
- package/lib/module/web/templates/MessageRowRenderer.js +2 -18
- package/lib/module/web/templates/RowContainerStyle.js +0 -1
- package/lib/module/web/templates/RowRendererRegistry.js +0 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +2 -36
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/lib/typescript/src/NativeList.nitro.d.ts +0 -1
- package/lib/typescript/src/NativeList.types.d.ts +0 -8
- package/lib/typescript/src/models.d.ts +9 -101
- package/lib/typescript/src/validation.d.ts +0 -10
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -26
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +3 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +0 -1
- package/src/NativeList.nitro.ts +0 -1
- package/src/NativeList.tsx +24 -72
- package/src/NativeList.types.ts +0 -9
- package/src/NativeList.web.tsx +8 -72
- package/src/models.ts +3 -113
- package/src/selection.ts +0 -1
- package/src/validation.ts +6 -721
- package/src/web/NativeListWebEngine.ts +19 -568
- package/src/web/templates/ActivityRowRenderer.ts +6 -14
- package/src/web/templates/DataRowRenderer.ts +20 -93
- package/src/web/templates/IdentityRowRenderer.ts +5 -150
- package/src/web/templates/MessageRowRenderer.ts +7 -23
- package/src/web/templates/RowContainerStyle.ts +0 -2
- package/src/web/templates/RowRendererRegistry.ts +1 -11
- package/src/web/templates/SectionHeaderRowRenderer.ts +4 -47
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +0 -102
- package/ios/NativeListButtonGroupRenderer.swift +0 -89
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +0 -47
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +0 -14
- package/src/web/templates/ButtonGroupRowRenderer.ts +0 -58
package/lib/module/validation.js
CHANGED
|
@@ -167,13 +167,10 @@ const TEXT_STYLE_KEYS_BY_ROW_TYPE = {
|
|
|
167
167
|
metricCard: ['title', 'value', 'subtitle', 'trend'],
|
|
168
168
|
sectionHeader: ['title', 'subtitle', 'value'],
|
|
169
169
|
action: ['title', 'value'],
|
|
170
|
-
buttonGroup: [],
|
|
171
170
|
system: ['title', 'message', 'actionText']
|
|
172
171
|
};
|
|
173
172
|
const EXTRA_STYLE_KEYS_BY_ROW_TYPE = {
|
|
174
|
-
|
|
175
|
-
market: ['titleBadgeLayout', 'contentTrailingGap', 'subtitleTrailingPadding', 'changeWidth', 'changeHeight', 'changeCornerRadius'],
|
|
176
|
-
sectionHeader: ['valuePlacement', 'titleDecoration']
|
|
173
|
+
market: ['titleBadgeLayout', 'contentTrailingGap', 'subtitleTrailingPadding', 'changeWidth', 'changeHeight', 'changeCornerRadius']
|
|
177
174
|
};
|
|
178
175
|
function assertTextStyle(style, path, additionalKeys = []) {
|
|
179
176
|
if (style === undefined) return;
|
|
@@ -286,15 +283,6 @@ function assertRowStyle(row, path) {
|
|
|
286
283
|
// Market keeps its own richer assertions, driven from assertMarketRow.
|
|
287
284
|
if (row.type === 'market') return;
|
|
288
285
|
assertBoxStyle(style, `${path}.style`);
|
|
289
|
-
if (row.type === 'identity') {
|
|
290
|
-
const ratio = style?.leadingContentMaxWidthRatio;
|
|
291
|
-
if (ratio !== undefined && (!Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
|
|
292
|
-
}
|
|
293
|
-
if (row.type === 'sectionHeader') {
|
|
294
|
-
const sectionStyle = style;
|
|
295
|
-
if (sectionStyle?.valuePlacement !== undefined && sectionStyle.valuePlacement !== 'afterTitle') fail(`${path}.style.valuePlacement`, 'must be afterTitle');
|
|
296
|
-
if (sectionStyle?.titleDecoration !== undefined && !['none', 'dashed'].includes(sectionStyle.titleDecoration)) fail(`${path}.style.titleDecoration`, 'must be none or dashed');
|
|
297
|
-
}
|
|
298
286
|
const slots = style;
|
|
299
287
|
textKeys.forEach(key => assertTextStyle(slots[key], `${path}.style.${key}`));
|
|
300
288
|
}
|
|
@@ -584,88 +572,15 @@ function assertVisualShape(shape, path) {
|
|
|
584
572
|
function assertTrailingAccessories(accessories, path) {
|
|
585
573
|
accessories?.forEach((accessory, index) => {
|
|
586
574
|
const accessoryPath = `${path}[${index}]`;
|
|
587
|
-
if (accessory.kind === 'button') {
|
|
588
|
-
assertUnknownKeys(accessory, ['kind', 'label', 'actionKey', 'disabled', 'testID', 'accessibilityLabel', 'textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor'], accessoryPath, 'button key');
|
|
589
|
-
if (typeof accessory.label !== 'string' || !accessory.label.trim()) fail(`${accessoryPath}.label`, 'must be non-blank');
|
|
590
|
-
assertKey(accessory.actionKey, `${accessoryPath}.actionKey`);
|
|
591
|
-
if (accessory.disabled !== undefined && typeof accessory.disabled !== 'boolean') fail(`${accessoryPath}.disabled`, 'must be boolean');
|
|
592
|
-
for (const field of ['textColor', 'backgroundColor', 'pressedBackgroundColor', 'hoverBackgroundColor', 'focusRingColor']) {
|
|
593
|
-
const value = accessory[field];
|
|
594
|
-
if (value !== undefined && (typeof value !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value))) fail(`${accessoryPath}.${field}`, 'must be #RRGGBB or #RRGGBBAA');
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
if (accessory.kind === 'icon' && accessory.buttonStyle !== undefined && accessory.buttonStyle !== 'tertiary') fail(`${accessoryPath}.buttonStyle`, 'must be tertiary');
|
|
598
575
|
if (accessory.kind === 'progress' && (accessory.value < 0 || accessory.value > 1)) {
|
|
599
576
|
fail(`${accessoryPath}.value`, 'must be within 0...1');
|
|
600
577
|
}
|
|
601
578
|
if (accessory.kind === 'valuePair') {
|
|
602
|
-
if (accessory.primaryFontWeight !== undefined && accessory.primaryFontWeight !== 'medium') fail(`${accessoryPath}.primaryFontWeight`, 'must be medium when provided');
|
|
603
|
-
assertTextHelp(accessory.primaryHelp, `${accessoryPath}.primaryHelp`);
|
|
604
579
|
assertTextTone(accessory.primaryTone, `${accessoryPath}.primaryTone`);
|
|
605
580
|
assertTextTone(accessory.secondaryTone, `${accessoryPath}.secondaryTone`);
|
|
606
|
-
for (const field of ['primaryTextSegments', 'secondaryTextSegments']) {
|
|
607
|
-
const segments = accessory[field];
|
|
608
|
-
if (segments === undefined) continue;
|
|
609
|
-
const segmentPath = `${accessoryPath}.${field}`;
|
|
610
|
-
if (!Array.isArray(segments) || segments.length > 64) fail(segmentPath, 'must be an array of at most 64 segments');
|
|
611
|
-
let textLength = 0;
|
|
612
|
-
segments.forEach((segment, segmentIndex) => {
|
|
613
|
-
const path = `${segmentPath}[${segmentIndex}]`;
|
|
614
|
-
const entry = protocolObject(segment, path);
|
|
615
|
-
assertUnknownKeys(entry, ['text', 'style'], path, 'segment key');
|
|
616
|
-
if (typeof entry.text !== 'string' || entry.text.length > MAX_TEXT_LENGTH) fail(`${path}.text`, `must be a string no longer than ${MAX_TEXT_LENGTH} characters`);
|
|
617
|
-
if (entry.style !== undefined && entry.style !== 'subscript') fail(`${path}.style`, 'must be subscript when provided');
|
|
618
|
-
textLength += entry.text.length;
|
|
619
|
-
});
|
|
620
|
-
if (textLength > MAX_TEXT_LENGTH) fail(segmentPath, `total text must be at most ${MAX_TEXT_LENGTH} characters`);
|
|
621
|
-
}
|
|
622
581
|
}
|
|
623
582
|
});
|
|
624
583
|
}
|
|
625
|
-
function assertTextHelp(help, path) {
|
|
626
|
-
if (help === undefined) return;
|
|
627
|
-
const object = protocolObject(help, path);
|
|
628
|
-
assertUnknownKeys(object, ['actionKey', 'presentation', 'underline'], path, 'help key');
|
|
629
|
-
assertKey(help.actionKey, `${path}.actionKey`);
|
|
630
|
-
if (!['tooltip', 'popover'].includes(help.presentation)) fail(`${path}.presentation`, 'must be tooltip or popover');
|
|
631
|
-
if (help.underline !== undefined && help.underline !== 'dashed') fail(`${path}.underline`, 'must be dashed');
|
|
632
|
-
}
|
|
633
|
-
function assertButtonGroup(row, path) {
|
|
634
|
-
if (!Array.isArray(row.buttons) || row.buttons.length === 0) fail(`${path}.buttons`, 'must contain at least one button');
|
|
635
|
-
const keys = new Set();
|
|
636
|
-
row.buttons.forEach((button, index) => {
|
|
637
|
-
const itemPath = `${path}.buttons[${index}]`;
|
|
638
|
-
const object = protocolObject(button, itemPath);
|
|
639
|
-
assertUnknownKeys(object, ['key', 'label', 'actionKey', 'disabled', 'loading', 'testID', 'accessibilityLabel'], itemPath, 'button key');
|
|
640
|
-
assertKey(button.key, `${itemPath}.key`);
|
|
641
|
-
if (keys.has(button.key)) fail(`${itemPath}.key`, 'duplicate button key');
|
|
642
|
-
keys.add(button.key);
|
|
643
|
-
if (typeof button.label !== 'string' || !button.label.trim() || button.label.length > MAX_TEXT_LENGTH) fail(`${itemPath}.label`, 'must be non-blank bounded text');
|
|
644
|
-
assertKey(button.actionKey, `${itemPath}.actionKey`);
|
|
645
|
-
for (const field of ['disabled', 'loading']) {
|
|
646
|
-
if (button[field] !== undefined && typeof button[field] !== 'boolean') fail(`${itemPath}.${field}`, 'must be boolean');
|
|
647
|
-
}
|
|
648
|
-
for (const field of ['testID', 'accessibilityLabel']) {
|
|
649
|
-
if (button[field] !== undefined && typeof button[field] !== 'string') fail(`${itemPath}.${field}`, 'must be a string');
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
function assertIdentityExtras(row, path) {
|
|
654
|
-
for (const field of ['titleIcon', 'secondaryTitleIcon']) {
|
|
655
|
-
const titleIcon = row[field];
|
|
656
|
-
if (titleIcon === undefined) continue;
|
|
657
|
-
const iconPath = `${path}.${field}`;
|
|
658
|
-
const icon = protocolObject(titleIcon, iconPath);
|
|
659
|
-
assertUnknownKeys(icon, ['name', 'tintColor', 'accessibilityLabel', 'hoverActionKey'], iconPath, 'title icon key');
|
|
660
|
-
if (typeof titleIcon.name !== 'string' || !titleIcon.name.trim()) fail(`${iconPath}.name`, 'must be non-blank');
|
|
661
|
-
if (titleIcon.tintColor !== undefined && (typeof titleIcon.tintColor !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(titleIcon.tintColor))) fail(`${iconPath}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
|
|
662
|
-
if (titleIcon.accessibilityLabel !== undefined && typeof titleIcon.accessibilityLabel !== 'string') fail(`${iconPath}.accessibilityLabel`, 'must be a string');
|
|
663
|
-
if (titleIcon.hoverActionKey !== undefined) assertKey(titleIcon.hoverActionKey, `${iconPath}.hoverActionKey`);
|
|
664
|
-
}
|
|
665
|
-
const ratio = row.style?.leadingContentMaxWidthRatio;
|
|
666
|
-
if (ratio !== undefined && (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) fail(`${path}.style.leadingContentMaxWidthRatio`, 'must be within (0, 1]');
|
|
667
|
-
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
668
|
-
}
|
|
669
584
|
function assertImage(image, path) {
|
|
670
585
|
if (!image) return;
|
|
671
586
|
if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
|
|
@@ -710,9 +625,6 @@ function assertLeadingVisual(visual, path) {
|
|
|
710
625
|
assertText(visual.cornerIcon?.name, `${path}.cornerIcon.name`);
|
|
711
626
|
// OneKey patch: validate optional selector overlays at the JSON boundary.
|
|
712
627
|
assertText(visual.fallbackIcon?.name, `${path}.fallbackIcon.name`);
|
|
713
|
-
if (visual.fallbackTextColor !== undefined && (typeof visual.fallbackTextColor !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackTextColor))) fail(`${path}.fallbackTextColor`, 'must be a hex color');
|
|
714
|
-
if (visual.fallbackIcon?.size !== undefined && (!Number.isFinite(visual.fallbackIcon.size) || visual.fallbackIcon.size <= 0 || visual.fallbackIcon.size > 40)) fail(`${path}.fallbackIcon.size`, 'must be within (0, 40]');
|
|
715
|
-
if (visual.fallbackIcon?.backgroundColor !== undefined && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackIcon.backgroundColor)) fail(`${path}.fallbackIcon.backgroundColor`, 'must be a hex color');
|
|
716
628
|
if ((visual.overlays?.length ?? 0) > 2) fail(`${path}.overlays`, 'supports at most two overlays');
|
|
717
629
|
visual.overlays?.forEach((overlay, index) => {
|
|
718
630
|
if (!['topLeft', 'bottomRight'].includes(overlay.position)) fail(`${path}.overlays[${index}].position`, 'must be topLeft or bottomRight');
|
|
@@ -729,11 +641,7 @@ function assertLeadingVisual(visual, path) {
|
|
|
729
641
|
}
|
|
730
642
|
if (overlay.padding !== undefined && overlay.padding * 2 >= Math.min(overlay.width ?? overlay.size ?? 20, overlay.height ?? overlay.size ?? 20)) fail(`${path}.overlays[${index}].padding`, 'must fit inside the overlay');
|
|
731
643
|
assertImage(overlay.image, `${path}.overlays[${index}].image`);
|
|
732
|
-
if (overlay.fallbackIcon !== undefined && !overlay.image) fail(`${path}.overlays[${index}].fallbackIcon`, 'requires image');
|
|
733
|
-
if (overlay.fallbackIcon !== undefined && (typeof overlay.fallbackIcon.name !== 'string' || !overlay.fallbackIcon.name.trim())) fail(`${path}.overlays[${index}].fallbackIcon.name`, 'must be non-blank');
|
|
734
|
-
if (overlay.fallbackIcon?.tintColor !== undefined && !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(overlay.fallbackIcon.tintColor)) fail(`${path}.overlays[${index}].fallbackIcon.tintColor`, 'must be a hex color');
|
|
735
644
|
assertText(overlay.text, `${path}.overlays[${index}].text`);
|
|
736
|
-
if (overlay.fontWeight !== undefined && !['regular', 'medium', 'semibold', 'bold'].includes(overlay.fontWeight)) fail(`${path}.overlays[${index}].fontWeight`, 'must be regular, medium, semibold, or bold');
|
|
737
645
|
});
|
|
738
646
|
if (visual.kind === 'token') {
|
|
739
647
|
assertImage(visual.networkImage, `${path}.networkImage`);
|
|
@@ -747,7 +655,6 @@ function assertVisual(row, path) {
|
|
|
747
655
|
});
|
|
748
656
|
}
|
|
749
657
|
function assertActivity(row, path) {
|
|
750
|
-
if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean') fail(`${path}.hideLeading`, 'must be boolean');
|
|
751
658
|
assertText(row.title, `${path}.title`);
|
|
752
659
|
assertText(row.description, `${path}.description`);
|
|
753
660
|
if (row.presentation !== undefined && !['stacked', 'table'].includes(row.presentation)) fail(`${path}.presentation`, 'must be stacked or table');
|
|
@@ -844,26 +751,10 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
844
751
|
assertWalletGroup(row, path);
|
|
845
752
|
break;
|
|
846
753
|
case 'identity':
|
|
847
|
-
if (row.contentHeight !== undefined && row.contentHeight !== 'auto') {
|
|
848
|
-
fail(`${path}.contentHeight`, 'must be auto');
|
|
849
|
-
}
|
|
850
|
-
if (row.subtitleLines !== undefined && ![0, 1, 2].includes(row.subtitleLines)) {
|
|
851
|
-
fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
|
|
852
|
-
}
|
|
853
|
-
if (row.longPressActionKey !== undefined) {
|
|
854
|
-
assertKey(row.longPressActionKey, `${path}.longPressActionKey`);
|
|
855
|
-
}
|
|
856
754
|
if (row.presentation !== undefined && row.presentation !== 'walletSidebar' && row.presentation !== 'accountSelector' && row.presentation !== 'networkSelector') {
|
|
857
755
|
fail(`${path}.presentation`, 'must be walletSidebar, accountSelector, or networkSelector when provided');
|
|
858
756
|
}
|
|
859
757
|
assertText(row.title, `${path}.title`);
|
|
860
|
-
if ((row.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
|
|
861
|
-
row.titleSuffixes?.forEach((suffix, index) => {
|
|
862
|
-
assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
|
|
863
|
-
if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
|
|
864
|
-
if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
|
|
865
|
-
});
|
|
866
|
-
assertIdentityExtras(row, path);
|
|
867
758
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
868
759
|
// OneKey patch: selector text segments truncate independently.
|
|
869
760
|
row.subtitleSegments?.forEach((segment, segmentIndex) => {
|
|
@@ -895,13 +786,10 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
895
786
|
assertActivity(row, path);
|
|
896
787
|
break;
|
|
897
788
|
case 'message':
|
|
898
|
-
if (row.presentation !== undefined && row.presentation !== 'inlineWarning') {
|
|
899
|
-
fail(`${path}.presentation`, 'must be inlineWarning');
|
|
900
|
-
}
|
|
901
789
|
assertText(row.title, `${path}.title`);
|
|
902
790
|
assertText(row.body, `${path}.body`);
|
|
903
|
-
if (![
|
|
904
|
-
fail(`${path}.bodyLines`, 'must be
|
|
791
|
+
if (![1, 2, 3].includes(row.bodyLines ?? 3)) {
|
|
792
|
+
fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
|
|
905
793
|
}
|
|
906
794
|
assertImage(row.thumbnail, `${path}.thumbnail`);
|
|
907
795
|
break;
|
|
@@ -912,13 +800,6 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
912
800
|
row.columns.forEach((column, columnIndex) => {
|
|
913
801
|
assertKey(column.key, `${path}.columns[${columnIndex}].key`);
|
|
914
802
|
assertText(column.text, `${path}.columns[${columnIndex}].text`);
|
|
915
|
-
assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
|
|
916
|
-
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
917
|
-
column[field]?.forEach((segment, segmentIndex) => {
|
|
918
|
-
assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
|
|
919
|
-
if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
803
|
assertText(column.secondaryLeadingText, `${path}.columns[${columnIndex}].secondaryLeadingText`);
|
|
923
804
|
assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
|
|
924
805
|
assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
|
|
@@ -926,10 +807,6 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
926
807
|
if ((row.badges?.length ?? 0) > MAX_BADGES) {
|
|
927
808
|
fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
|
|
928
809
|
}
|
|
929
|
-
if ((row.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
|
|
930
|
-
fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
|
|
931
|
-
}
|
|
932
|
-
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
933
810
|
break;
|
|
934
811
|
case 'market':
|
|
935
812
|
assertMarketRow(row, path);
|
|
@@ -980,11 +857,6 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
980
857
|
assertText(row.title, `${path}.title`);
|
|
981
858
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
982
859
|
assertText(row.value, `${path}.value`);
|
|
983
|
-
if (row.leadingBadge) {
|
|
984
|
-
assertKey(row.leadingBadge.key, `${path}.leadingBadge.key`);
|
|
985
|
-
assertText(row.leadingBadge.text, `${path}.leadingBadge.text`);
|
|
986
|
-
}
|
|
987
|
-
assertTextHelp(row.valueHelp, `${path}.valueHelp`);
|
|
988
860
|
if (row.valueActionKey !== undefined) {
|
|
989
861
|
assertKey(row.valueActionKey, `${path}.valueActionKey`);
|
|
990
862
|
}
|
|
@@ -1005,9 +877,6 @@ function assertRow(row, index, path = `rows[${index}]`) {
|
|
|
1005
877
|
}
|
|
1006
878
|
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
1007
879
|
break;
|
|
1008
|
-
case 'buttonGroup':
|
|
1009
|
-
assertButtonGroup(row, path);
|
|
1010
|
-
break;
|
|
1011
880
|
case 'system':
|
|
1012
881
|
const presentation = 'presentation' in row ? row.presentation : undefined;
|
|
1013
882
|
if (presentation !== undefined && presentation !== 'market') {
|
|
@@ -1069,17 +938,9 @@ function assertMediaPreview(value, path) {
|
|
|
1069
938
|
}
|
|
1070
939
|
}
|
|
1071
940
|
function assertSnapshotContract(snapshot) {
|
|
1072
|
-
if (snapshot.structuralTransition) {
|
|
1073
|
-
assertKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
|
|
1074
|
-
if (snapshot.structuralTransition.anchorKey !== undefined) assertKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
|
|
1075
|
-
const duration = snapshot.structuralTransition.durationMs;
|
|
1076
|
-
if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
|
|
1077
|
-
}
|
|
1078
941
|
if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
|
|
1079
942
|
assertPlainSerializable(snapshot, 'snapshot', new Set());
|
|
1080
943
|
assertText(snapshot.theme?.imageFallbackBackground, 'theme.imageFallbackBackground');
|
|
1081
|
-
if (snapshot.theme?.successBackground !== undefined && (typeof snapshot.theme.successBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))) fail('theme.successBackground', 'must be a hex color');
|
|
1082
|
-
if (snapshot.theme?.rowHoverBackground !== undefined && (typeof snapshot.theme.rowHoverBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))) fail('theme.rowHoverBackground', 'must be a hex color');
|
|
1083
944
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
1084
945
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
|
|
1085
946
|
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
@@ -1157,8 +1018,8 @@ function protocolObject(value, path) {
|
|
|
1157
1018
|
function protocolKey(value, path) {
|
|
1158
1019
|
if (typeof value !== 'string' || value.trim().length === 0) fail(path, 'must be a non-blank string');
|
|
1159
1020
|
}
|
|
1160
|
-
const PROTOCOL_ARRAY_FIELDS = new Set(['columns', '
|
|
1161
|
-
const PROTOCOL_NUMBER_FIELDS = new Set(['
|
|
1021
|
+
const PROTOCOL_ARRAY_FIELDS = new Set(['columns', 'cells', 'points', 'images', 'overlays', 'badges', 'trailing', 'footerActions', 'amounts', 'metrics', 'children', 'subtitleSegments', 'titleMatch', 'selectedKeys', 'segments', 'hoverSecondary', 'hoverImages', 'secondaryBadges', 'fallbackUris', 'probeOrder', 'priceSegments', 'textSegments', 'secondaryTextSegments', 'primaryTextSegments']);
|
|
1022
|
+
const PROTOCOL_NUMBER_FIELDS = new Set(['height', 'width', 'fontSize', 'lineHeight', 'opacity', 'offsetY', 'offsetX', 'cornerRadius', 'borderWidth', 'horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'start', 'end', 'padding', 'offset', 'overscan', 'minWidth', 'flex', 'paddingStart', 'paddingEnd', 'changeWidth', 'changeHeight', 'changeCornerRadius', 'contentTrailingGap', 'subtitleTrailingPadding', 'partGap', 'contentPadding', 'contentPaddingHorizontal', 'contentPaddingTop', 'contentPaddingBottom', 'itemSpacing', 'gridColumns']);
|
|
1162
1023
|
|
|
1163
1024
|
/** Validate only shapes that renderers dereference, not display budgets. */
|
|
1164
1025
|
function assertProtocolFields(value, path, parentField = '') {
|
|
@@ -1176,15 +1037,6 @@ function assertProtocolFields(value, path, parentField = '') {
|
|
|
1176
1037
|
return;
|
|
1177
1038
|
}
|
|
1178
1039
|
const object = value;
|
|
1179
|
-
if (parentField === 'fallbackIcon') {
|
|
1180
|
-
protocolKey(object.name, `${path}.name`);
|
|
1181
|
-
if (object.size !== undefined && (typeof object.size !== 'number' || !Number.isFinite(object.size) || object.size <= 0 || object.size > 40)) fail(`${path}.size`, 'must be within (0, 40]');
|
|
1182
|
-
for (const field of ['tintColor', 'backgroundColor']) {
|
|
1183
|
-
const color = object[field];
|
|
1184
|
-
if (color !== undefined && (typeof color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color))) fail(`${path}.${field}`, 'must be a hex color');
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
if (parentField === 'overlays' && object.fallbackIcon !== undefined && !object.image) fail(`${path}.fallbackIcon`, 'requires image');
|
|
1188
1040
|
if (!path.includes('.style.') && ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(parentField) && typeof object.uri !== 'string') fail(`${path}.uri`, 'must be a string');
|
|
1189
1041
|
Object.entries(value).forEach(([field, item]) => {
|
|
1190
1042
|
if (item === undefined) return;
|
|
@@ -1192,9 +1044,6 @@ function assertProtocolFields(value, path, parentField = '') {
|
|
|
1192
1044
|
if (!path.endsWith('.style') && PROTOCOL_ARRAY_FIELDS.has(field) && !Array.isArray(item)) fail(fieldPath, 'must be an array');
|
|
1193
1045
|
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number') fail(fieldPath, 'must be a finite number');
|
|
1194
1046
|
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item === 'number' && item < 0 && !['offsetX', 'offsetY'].includes(field)) fail(fieldPath, 'must be non-negative');
|
|
1195
|
-
if (parentField === 'overlays' && field === 'fontWeight' && !['regular', 'medium', 'semibold', 'bold'].includes(item)) fail(fieldPath, 'must be regular, medium, semibold, or bold');
|
|
1196
|
-
if (field === 'buttonStyle' && item !== 'tertiary') fail(fieldPath, 'must be tertiary');
|
|
1197
|
-
if (field === 'hideLeading' && typeof item !== 'boolean') fail(fieldPath, 'must be boolean');
|
|
1198
1047
|
if (field === 'key' || field === 'sectionKey' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
|
|
1199
1048
|
if ((field === 'uri' || field === 'fallbackUri') && typeof item !== 'string') fail(fieldPath, 'must be a string');
|
|
1200
1049
|
if (field === 'style' && !(item === 'subscript' && /[Ss]egments\[/.test(path)) || field === 'container') protocolObject(item, fieldPath);
|
|
@@ -1220,21 +1069,12 @@ function assertRowProtocol(row, path) {
|
|
|
1220
1069
|
}
|
|
1221
1070
|
if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
|
|
1222
1071
|
if (row.type === 'identity') {
|
|
1223
|
-
assertIdentityExtras(row, path);
|
|
1224
|
-
if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes)) fail(`${path}.titleSuffixes`, 'must be an array');
|
|
1225
|
-
row.titleSuffixes?.forEach((suffix, index) => {
|
|
1226
|
-
protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
|
|
1227
|
-
if (typeof suffix.text !== 'string' || !['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}]`, 'invalid title suffix');
|
|
1228
|
-
if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
|
|
1229
|
-
});
|
|
1230
1072
|
let end = 0;
|
|
1231
1073
|
row.titleMatch?.forEach(match => {
|
|
1232
1074
|
if (!Number.isInteger(match.start) || !Number.isInteger(match.end) || match.start < end || match.end <= match.start || match.end > row.title.length) fail(`${path}.titleMatch`, 'invalid text range');
|
|
1233
1075
|
end = match.end;
|
|
1234
1076
|
});
|
|
1235
1077
|
}
|
|
1236
|
-
if (row.type === 'buttonGroup') assertButtonGroup(row, path);
|
|
1237
|
-
if (row.type === 'sectionHeader') assertTextHelp(row.valueHelp, `${path}.valueHelp`);
|
|
1238
1078
|
if (row.type === 'mediaTile' && row.media) {
|
|
1239
1079
|
protocolObject(row.media.source, `${path}.media.source`);
|
|
1240
1080
|
if (!Array.isArray(row.media.probeOrder)) fail(`${path}.media.probeOrder`, 'must be an array');
|
|
@@ -1251,15 +1091,7 @@ function assertRowProtocol(row, path) {
|
|
|
1251
1091
|
keys.add(member.key);
|
|
1252
1092
|
});
|
|
1253
1093
|
}
|
|
1254
|
-
if (row.type === 'dataRow') {
|
|
1255
|
-
if (!Array.isArray(row.columns)) fail(`${path}.columns`, 'must be an array');
|
|
1256
|
-
row.columns.forEach((column, index) => {
|
|
1257
|
-
const columnPath = `${path}.columns[${index}]`;
|
|
1258
|
-
protocolObject(column, columnPath);
|
|
1259
|
-
assertIdentityExtras(column, columnPath);
|
|
1260
|
-
});
|
|
1261
|
-
assertTrailingAccessories(row.trailing, `${path}.trailing`);
|
|
1262
|
-
}
|
|
1094
|
+
if (row.type === 'dataRow' && !Array.isArray(row.columns)) fail(`${path}.columns`, 'must be an array');
|
|
1263
1095
|
if (row.type === 'market') {
|
|
1264
1096
|
protocolObject(row.change, `${path}.change`);
|
|
1265
1097
|
if (row.webTable) {
|
|
@@ -1286,15 +1118,6 @@ function assertRowProtocol(row, path) {
|
|
|
1286
1118
|
}
|
|
1287
1119
|
function assertSnapshotProtocol(snapshot) {
|
|
1288
1120
|
protocolObject(snapshot, 'snapshot');
|
|
1289
|
-
if (snapshot.structuralTransition) {
|
|
1290
|
-
protocolObject(snapshot.structuralTransition, 'snapshot.structuralTransition');
|
|
1291
|
-
protocolKey(snapshot.structuralTransition.id, 'snapshot.structuralTransition.id');
|
|
1292
|
-
if (snapshot.structuralTransition.anchorKey !== undefined) protocolKey(snapshot.structuralTransition.anchorKey, 'snapshot.structuralTransition.anchorKey');
|
|
1293
|
-
const duration = snapshot.structuralTransition.durationMs;
|
|
1294
|
-
if (duration !== undefined && (!Number.isFinite(duration) || duration < 0 || duration > 2000)) fail('snapshot.structuralTransition.durationMs', 'must be finite within 0...2000');
|
|
1295
|
-
}
|
|
1296
|
-
if (snapshot.theme?.successBackground !== undefined && (typeof snapshot.theme.successBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.successBackground))) fail('theme.successBackground', 'must be a hex color');
|
|
1297
|
-
if (snapshot.theme?.rowHoverBackground !== undefined && (typeof snapshot.theme.rowHoverBackground !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(snapshot.theme.rowHoverBackground))) fail('theme.rowHoverBackground', 'must be a hex color');
|
|
1298
1121
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
1299
1122
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
1300
1123
|
protocolObject(snapshot.layout, 'snapshot.layout');
|
|
@@ -1351,53 +1174,6 @@ export function validateSnapshot(snapshot) {
|
|
|
1351
1174
|
assertSnapshotProtocol(normalized);
|
|
1352
1175
|
return normalizeSnapshotStyles(normalized);
|
|
1353
1176
|
}
|
|
1354
|
-
const ownedNativeSnapshots = new WeakMap();
|
|
1355
|
-
function capturePlainData(value, seen = new Map()) {
|
|
1356
|
-
if (value === null || typeof value !== 'object') return value;
|
|
1357
|
-
const previous = seen.get(value);
|
|
1358
|
-
if (previous) return previous;
|
|
1359
|
-
const copy = Array.isArray(value) ? new Array(value.length) : Object.create(Object.getPrototypeOf(value));
|
|
1360
|
-
seen.set(value, copy);
|
|
1361
|
-
const captureKey = key => {
|
|
1362
|
-
Object.defineProperty(copy, key, {
|
|
1363
|
-
value: capturePlainData(value[key], seen),
|
|
1364
|
-
enumerable: true,
|
|
1365
|
-
writable: true,
|
|
1366
|
-
configurable: true
|
|
1367
|
-
});
|
|
1368
|
-
};
|
|
1369
|
-
if (Array.isArray(value)) {
|
|
1370
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
1371
|
-
if (index in value) captureKey(String(index));
|
|
1372
|
-
}
|
|
1373
|
-
Object.keys(value).forEach(key => {
|
|
1374
|
-
const index = Number(key);
|
|
1375
|
-
if (Number.isInteger(index) && index >= 0 && index < value.length && String(index) === key) return;
|
|
1376
|
-
captureKey(key);
|
|
1377
|
-
});
|
|
1378
|
-
} else {
|
|
1379
|
-
Object.keys(value).forEach(captureKey);
|
|
1380
|
-
}
|
|
1381
|
-
return copy;
|
|
1382
|
-
}
|
|
1383
|
-
function deepFreeze(value, seen = new WeakSet()) {
|
|
1384
|
-
if (value === null || typeof value !== 'object' || seen.has(value)) return value;
|
|
1385
|
-
seen.add(value);
|
|
1386
|
-
Object.values(value).forEach(item => deepFreeze(item, seen));
|
|
1387
|
-
return Object.freeze(value);
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
/** Capture caller data once before validation, including accessor values. */
|
|
1391
|
-
export function captureNativeListInput(value) {
|
|
1392
|
-
return capturePlainData(value);
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
/** Private native-wrapper ownership; exported validators keep their public identity. */
|
|
1396
|
-
export function ownValidatedNativeSnapshot(snapshot) {
|
|
1397
|
-
const owned = deepFreeze(snapshot);
|
|
1398
|
-
ownedNativeSnapshots.set(owned, new Map(owned.rows.map((row, index) => [row.key, index])));
|
|
1399
|
-
return owned;
|
|
1400
|
-
}
|
|
1401
1177
|
|
|
1402
1178
|
/**
|
|
1403
1179
|
* Resolves typography tokens to numbers. Returns the original snapshot when
|
|
@@ -1442,23 +1218,7 @@ function assertPatchChanges(patch, index) {
|
|
|
1442
1218
|
}
|
|
1443
1219
|
switch (patch.type) {
|
|
1444
1220
|
case 'identity':
|
|
1445
|
-
if (patch.changes.contentHeight !== undefined && patch.changes.contentHeight !== 'auto') {
|
|
1446
|
-
fail(`${path}.contentHeight`, 'must be auto');
|
|
1447
|
-
}
|
|
1448
|
-
if (patch.changes.subtitleLines !== undefined && ![0, 1, 2].includes(patch.changes.subtitleLines)) {
|
|
1449
|
-
fail(`${path}.subtitleLines`, 'must be 0, 1, or 2');
|
|
1450
|
-
}
|
|
1451
|
-
if (patch.changes.longPressActionKey !== undefined) {
|
|
1452
|
-
assertKey(patch.changes.longPressActionKey, `${path}.longPressActionKey`);
|
|
1453
|
-
}
|
|
1454
1221
|
assertText(patch.changes.title, `${path}.title`);
|
|
1455
|
-
if ((patch.changes.titleSuffixes?.length ?? 0) > 3) fail(`${path}.titleSuffixes`, 'supports at most 3 suffixes');
|
|
1456
|
-
patch.changes.titleSuffixes?.forEach((suffix, index) => {
|
|
1457
|
-
assertText(suffix.text, `${path}.titleSuffixes[${index}].text`);
|
|
1458
|
-
if (!['secondary', 'disabled'].includes(suffix.tone)) fail(`${path}.titleSuffixes[${index}].tone`, 'must be secondary or disabled');
|
|
1459
|
-
if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
|
|
1460
|
-
});
|
|
1461
|
-
assertIdentityExtras(patch.changes, path);
|
|
1462
1222
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
1463
1223
|
assertText(patch.changes.tertiary, `${path}.tertiary`);
|
|
1464
1224
|
if (patch.changes.tertiaryTone !== undefined && !['secondary', 'info'].includes(patch.changes.tertiaryTone)) {
|
|
@@ -1492,14 +1252,11 @@ function assertPatchChanges(patch, index) {
|
|
|
1492
1252
|
}
|
|
1493
1253
|
break;
|
|
1494
1254
|
case 'message':
|
|
1495
|
-
if (patch.changes.presentation !== undefined && patch.changes.presentation !== 'inlineWarning') {
|
|
1496
|
-
fail(`${path}.presentation`, 'must be inlineWarning');
|
|
1497
|
-
}
|
|
1498
1255
|
assertText(patch.changes.title, `${path}.title`);
|
|
1499
1256
|
assertText(patch.changes.body, `${path}.body`);
|
|
1500
1257
|
assertText(patch.changes.time, `${path}.time`);
|
|
1501
|
-
if (patch.changes.bodyLines !== undefined && ![
|
|
1502
|
-
fail(`${path}.bodyLines`, 'must be
|
|
1258
|
+
if (patch.changes.bodyLines !== undefined && ![1, 2, 3].includes(patch.changes.bodyLines)) {
|
|
1259
|
+
fail(`${path}.bodyLines`, 'must be 1, 2, or 3');
|
|
1503
1260
|
}
|
|
1504
1261
|
assertImage(patch.changes.thumbnail, `${path}.thumbnail`);
|
|
1505
1262
|
break;
|
|
@@ -1510,23 +1267,12 @@ function assertPatchChanges(patch, index) {
|
|
|
1510
1267
|
patch.changes.columns?.forEach((column, columnIndex) => {
|
|
1511
1268
|
assertKey(column.key, `${path}.columns[${columnIndex}].key`);
|
|
1512
1269
|
assertText(column.text, `${path}.columns[${columnIndex}].text`);
|
|
1513
|
-
assertIdentityExtras(column, `${path}.columns[${columnIndex}]`);
|
|
1514
|
-
for (const field of ['textSegments', 'secondaryTextSegments']) {
|
|
1515
|
-
column[field]?.forEach((segment, segmentIndex) => {
|
|
1516
|
-
assertText(segment.text, `${path}.columns[${columnIndex}].${field}[${segmentIndex}].text`);
|
|
1517
|
-
if (segment.style !== undefined && segment.style !== 'subscript') fail(`${path}.columns[${columnIndex}].${field}[${segmentIndex}].style`, 'must be subscript');
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
1270
|
assertText(column.secondaryText, `${path}.columns[${columnIndex}].secondaryText`);
|
|
1521
1271
|
assertTextTone(column.secondaryTone, `${path}.columns[${columnIndex}].secondaryTone`);
|
|
1522
1272
|
});
|
|
1523
1273
|
if ((patch.changes.badges?.length ?? 0) > MAX_BADGES) {
|
|
1524
1274
|
fail(`${path}.badges`, `supports at most ${MAX_BADGES} badges`);
|
|
1525
1275
|
}
|
|
1526
|
-
if ((patch.changes.trailing?.length ?? 0) > MAX_TRAILING_ACCESSORIES) {
|
|
1527
|
-
fail(`${path}.trailing`, `supports at most ${MAX_TRAILING_ACCESSORIES} accessories`);
|
|
1528
|
-
}
|
|
1529
|
-
assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
|
|
1530
1276
|
break;
|
|
1531
1277
|
case 'market':
|
|
1532
1278
|
assertMarketRow({
|
|
@@ -1585,11 +1331,6 @@ function assertPatchChanges(patch, index) {
|
|
|
1585
1331
|
assertText(patch.changes.title, `${path}.title`);
|
|
1586
1332
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
1587
1333
|
assertText(patch.changes.value, `${path}.value`);
|
|
1588
|
-
if (patch.changes.leadingBadge) {
|
|
1589
|
-
assertKey(patch.changes.leadingBadge.key, `${path}.leadingBadge.key`);
|
|
1590
|
-
assertText(patch.changes.leadingBadge.text, `${path}.leadingBadge.text`);
|
|
1591
|
-
}
|
|
1592
|
-
assertTextHelp(patch.changes.valueHelp, `${path}.valueHelp`);
|
|
1593
1334
|
if (patch.changes.valueActionKey !== undefined) {
|
|
1594
1335
|
assertKey(patch.changes.valueActionKey, `${path}.valueActionKey`);
|
|
1595
1336
|
}
|
|
@@ -1603,11 +1344,6 @@ function assertPatchChanges(patch, index) {
|
|
|
1603
1344
|
}
|
|
1604
1345
|
assertTrailingAccessories(patch.changes.trailing, `${path}.trailing`);
|
|
1605
1346
|
break;
|
|
1606
|
-
case 'buttonGroup':
|
|
1607
|
-
if (patch.changes.buttons !== undefined) assertButtonGroup({
|
|
1608
|
-
buttons: patch.changes.buttons
|
|
1609
|
-
}, path);
|
|
1610
|
-
break;
|
|
1611
1347
|
case 'system':
|
|
1612
1348
|
assertText(patch.changes.message, `${path}.message`);
|
|
1613
1349
|
break;
|
|
@@ -1627,7 +1363,6 @@ export function validatePatches(patches) {
|
|
|
1627
1363
|
protocolObject(patch.changes, `patches[${index}].changes`);
|
|
1628
1364
|
assertRowType(patch.type, `patches[${index}]`);
|
|
1629
1365
|
assertProtocolFields(patch.changes, `patches[${index}].changes`);
|
|
1630
|
-
if (patch.type === 'identity') assertIdentityExtras(patch.changes, `patches[${index}].changes`);
|
|
1631
1366
|
if (!isDevelopment()) continue;
|
|
1632
1367
|
assertKey(patch.key, `patches[${index}].key`);
|
|
1633
1368
|
if (Object.keys(patch.changes).length === 0) {
|
|
@@ -1684,53 +1419,6 @@ export function applyRowPatches(snapshot, patches) {
|
|
|
1684
1419
|
rows
|
|
1685
1420
|
});
|
|
1686
1421
|
}
|
|
1687
|
-
|
|
1688
|
-
/** Native wrapper only: preserve full public validation for unsupported patches. */
|
|
1689
|
-
export function applyOwnedNativePatches(snapshot, patches) {
|
|
1690
|
-
const acceptedPatches = deepFreeze(validatePatches(capturePlainData(patches)));
|
|
1691
|
-
const rowIndexes = ownedNativeSnapshots.get(snapshot);
|
|
1692
|
-
const canPatchRows = rowIndexes !== undefined && acceptedPatches.every(patch => {
|
|
1693
|
-
const index = rowIndexes.get(patch.key);
|
|
1694
|
-
if (index === undefined || snapshot.rows[index].type !== patch.type) return false;
|
|
1695
|
-
const allowed = patch.type === 'identity' ? ['subtitle', 'subtitleSegments', 'trailing'] : patch.type === 'dataRow' ? ['columns', 'trailing'] : undefined;
|
|
1696
|
-
return allowed !== undefined && Object.entries(patch.changes).every(([key, value]) => allowed.includes(key) && (value !== undefined || snapshot.rows[index][key] === undefined));
|
|
1697
|
-
});
|
|
1698
|
-
if (!canPatchRows) {
|
|
1699
|
-
const baseline = rowIndexes ? snapshot : capturePlainData(snapshot);
|
|
1700
|
-
return {
|
|
1701
|
-
patches: acceptedPatches,
|
|
1702
|
-
snapshot: ownValidatedNativeSnapshot(applyRowPatches(baseline, acceptedPatches)),
|
|
1703
|
-
json: JSON.stringify(acceptedPatches)
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
const nextRows = snapshot.rows.slice();
|
|
1707
|
-
for (const patch of acceptedPatches) {
|
|
1708
|
-
const index = rowIndexes.get(patch.key);
|
|
1709
|
-
const previous = nextRows[index];
|
|
1710
|
-
const merged = {
|
|
1711
|
-
...previous,
|
|
1712
|
-
...patch.changes,
|
|
1713
|
-
key: previous.key,
|
|
1714
|
-
type: previous.type
|
|
1715
|
-
};
|
|
1716
|
-
const path = `rows[${index}]`;
|
|
1717
|
-
assertPlainSerializable(merged, path, new Set());
|
|
1718
|
-
if (isDevelopment()) assertRow(merged, index);
|
|
1719
|
-
const normalized = isDevelopment() ? merged : normalizeEmptyImages(merged);
|
|
1720
|
-
assertRowProtocol(normalized, path);
|
|
1721
|
-
nextRows[index] = deepFreeze(normalizeRowStyles(normalized));
|
|
1722
|
-
}
|
|
1723
|
-
const nextSnapshot = Object.freeze({
|
|
1724
|
-
...snapshot,
|
|
1725
|
-
rows: Object.freeze(nextRows)
|
|
1726
|
-
});
|
|
1727
|
-
ownedNativeSnapshots.set(nextSnapshot, rowIndexes);
|
|
1728
|
-
return {
|
|
1729
|
-
patches: acceptedPatches,
|
|
1730
|
-
snapshot: nextSnapshot,
|
|
1731
|
-
json: JSON.stringify(acceptedPatches)
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
1422
|
export function serializeSnapshot(snapshot) {
|
|
1735
1423
|
return JSON.stringify(validateSnapshot(snapshot));
|
|
1736
1424
|
}
|