@onekeyfe/react-native-native-list 6.7.0-1 → 6.7.0-11
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 +1 -1
- package/docs/SPEC.md +449 -14
- package/ios/HybridNativeList.swift +11 -3
- package/ios/RNCNativeListView.swift +10 -6
- package/ios/tests/NativeListLifecycleTests.swift +28 -0
- package/lib/module/NativeList.js +42 -21
- package/lib/module/NativeList.web.js +163 -32
- package/lib/module/ScrollEdgeEffect.js +8 -0
- package/lib/module/index.js +1 -0
- package/lib/module/validation.js +358 -47
- package/lib/module/web/NativeListWebEngine.js +373 -67
- package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/RowRendererRegistry.js +5 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/lib/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/lib/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/lib/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -1
- package/lib/typescript/src/NativeList.types.d.ts +14 -3
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/ScrollEdgeEffect.d.ts +5 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/models.d.ts +71 -1
- package/lib/typescript/src/validation.d.ts +3 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +4 -1
- package/src/NativeList.nitro.ts +3 -1
- package/src/NativeList.tsx +102 -60
- package/src/NativeList.types.ts +15 -3
- package/src/NativeList.web.tsx +264 -65
- package/src/ScrollEdgeEffect.ts +4 -0
- package/src/index.ts +2 -0
- package/src/models.ts +93 -0
- package/src/validation.ts +785 -72
- package/src/web/NativeListWebEngine.ts +625 -100
- package/src/web/templates/ActivityRowRenderer.ts +723 -7
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/RowRendererRegistry.ts +10 -5
- package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
package/lib/module/validation.js
CHANGED
|
@@ -12,8 +12,40 @@ const MAX_HEADER_LENGTH = 4096;
|
|
|
12
12
|
const MAX_SPACER_HEIGHT = 512;
|
|
13
13
|
const MAX_SECTION_INDEX_TITLE_LENGTH = 8;
|
|
14
14
|
const MAX_MARKET_BADGES = 3;
|
|
15
|
+
function isDevelopment() {
|
|
16
|
+
return typeof __DEV__ !== 'undefined' && __DEV__;
|
|
17
|
+
}
|
|
18
|
+
class NativeListInputError extends Error {
|
|
19
|
+
constructor(path, reason) {
|
|
20
|
+
super(`NativeList ${path}: ${reason}`);
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.reason = reason;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
15
25
|
function fail(path, message) {
|
|
16
|
-
throw new
|
|
26
|
+
throw new NativeListInputError(path, message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Component boundaries report locations, never caller-controlled payload values. */
|
|
30
|
+
export function containNativeListInput(operation) {
|
|
31
|
+
try {
|
|
32
|
+
return operation();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const path = error instanceof NativeListInputError ? error.path : 'input';
|
|
35
|
+
const reason = isDevelopment() && error instanceof NativeListInputError ? `: ${error.reason.split('"')[0].trim()}` : '';
|
|
36
|
+
console.warn(`NativeList rejected invalid input at ${path}${reason}`);
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function emptyNativeListSnapshot() {
|
|
41
|
+
return {
|
|
42
|
+
schemaVersion: 1,
|
|
43
|
+
generation: 0,
|
|
44
|
+
layout: {
|
|
45
|
+
kind: 'linear'
|
|
46
|
+
},
|
|
47
|
+
rows: []
|
|
48
|
+
};
|
|
17
49
|
}
|
|
18
50
|
function assertPlainSerializable(value, path, seen) {
|
|
19
51
|
if (value === null || value === undefined) return;
|
|
@@ -39,10 +71,9 @@ function assertPlainSerializable(value, path, seen) {
|
|
|
39
71
|
seen.delete(objectValue);
|
|
40
72
|
}
|
|
41
73
|
function assertKey(key, path) {
|
|
42
|
-
if (typeof key !== 'string' || key.length === 0 || key.length > MAX_KEY_LENGTH) {
|
|
43
|
-
fail(path, `must be a non-
|
|
74
|
+
if (typeof key !== 'string' || key.trim().length === 0 || key.length > MAX_KEY_LENGTH) {
|
|
75
|
+
fail(path, `must be a non-blank string no longer than ${MAX_KEY_LENGTH} characters`);
|
|
44
76
|
}
|
|
45
|
-
if (key.trim() !== key) fail(path, 'must not have leading or trailing whitespace');
|
|
46
77
|
}
|
|
47
78
|
function assertText(text, path) {
|
|
48
79
|
if (text === undefined) return;
|
|
@@ -347,7 +378,139 @@ function normalizeRowStyles(row) {
|
|
|
347
378
|
}
|
|
348
379
|
return next;
|
|
349
380
|
}
|
|
381
|
+
function assertMarketBadges(badges, path) {
|
|
382
|
+
if ((badges?.length ?? 0) > MAX_MARKET_BADGES) {
|
|
383
|
+
fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
|
|
384
|
+
}
|
|
385
|
+
const badgeKeys = new Set();
|
|
386
|
+
badges?.forEach((badge, index) => {
|
|
387
|
+
const badgePath = `${path}.badges[${index}]`;
|
|
388
|
+
assertKey(badge.key, `${badgePath}.key`);
|
|
389
|
+
if (badgeKeys.has(badge.key)) {
|
|
390
|
+
fail(`${path}.badges`, `duplicate badge key "${badge.key}"`);
|
|
391
|
+
}
|
|
392
|
+
badgeKeys.add(badge.key);
|
|
393
|
+
assertText(badge.text, `${badgePath}.text`);
|
|
394
|
+
// OneKey patch: share typography bounds with Market text styles.
|
|
395
|
+
assertTextStyle(badge.style, `${badgePath}.style`, ['height', 'horizontalPadding']);
|
|
396
|
+
if (badge.style) assertUnknownKeys(badge.style, ['fontSize', 'fontWeight', 'lineHeight', 'height', 'horizontalPadding'], `${badgePath}.style`, 'Market badge style key');
|
|
397
|
+
assertBoundedStyleNumber(badge.style?.height, `${badgePath}.style.height`, 1, 64);
|
|
398
|
+
assertBoundedStyleNumber(badge.style?.horizontalPadding, `${badgePath}.style.horizontalPadding`, 0, 32);
|
|
399
|
+
if (badge.iconName !== undefined && badge.iconName !== 'verified') {
|
|
400
|
+
fail(`${badgePath}.iconName`, 'must be verified when provided');
|
|
401
|
+
}
|
|
402
|
+
if (badge.iconName !== undefined && badge.icon !== undefined) {
|
|
403
|
+
fail(`${badgePath}.icon`, 'cannot be combined with iconName');
|
|
404
|
+
}
|
|
405
|
+
assertImage(badge.icon, `${badgePath}.icon`);
|
|
406
|
+
if (badge.tone !== undefined && !['neutral', 'info', 'success', 'warning', 'danger'].includes(badge.tone)) {
|
|
407
|
+
fail(`${badgePath}.tone`, 'must be neutral, info, success, warning, or danger');
|
|
408
|
+
}
|
|
409
|
+
if (!badge.text && !badge.icon && !badge.iconName) {
|
|
410
|
+
fail(badgePath, 'requires text, icon, or iconName');
|
|
411
|
+
}
|
|
412
|
+
if (badge.actionKey !== undefined) {
|
|
413
|
+
assertKey(badge.actionKey, `${badgePath}.actionKey`);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
function assertWebMarketTable(table, path) {
|
|
418
|
+
if (!table) return;
|
|
419
|
+
assertUnknownKeys(table, ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'], path, 'Web table key');
|
|
420
|
+
if (table.draggable !== undefined && typeof table.draggable !== 'boolean') fail(`${path}.draggable`, 'must be boolean');
|
|
421
|
+
if (table.contextMenuActionKey !== undefined) assertKey(table.contextMenuActionKey, `${path}.contextMenuActionKey`);
|
|
422
|
+
assertText(table.testID, `${path}.testID`);
|
|
423
|
+
if (!Array.isArray(table.columns) || table.columns.length < 1 || table.columns.length > 12) fail(`${path}.columns`, 'must contain 1...12 columns');
|
|
424
|
+
if (!Array.isArray(table.cells) || table.cells.length !== table.columns.length) fail(`${path}.cells`, 'must match the column count');
|
|
425
|
+
const keys = new Set();
|
|
426
|
+
table.columns.forEach((column, index) => {
|
|
427
|
+
const field = `${path}.columns[${index}]`;
|
|
428
|
+
assertUnknownKeys(column, ['key', 'width', 'minWidth', 'flex', 'alignment', 'paddingStart', 'paddingEnd'], field, 'Web column key');
|
|
429
|
+
assertKey(column.key, `${field}.key`);
|
|
430
|
+
if (keys.has(column.key)) fail(field, 'column keys must be unique');
|
|
431
|
+
keys.add(column.key);
|
|
432
|
+
assertBoundedStyleNumber(column.width, `${field}.width`, 0, 4096);
|
|
433
|
+
assertBoundedStyleNumber(column.minWidth, `${field}.minWidth`, 0, 4096);
|
|
434
|
+
assertBoundedStyleNumber(column.flex, `${field}.flex`, 0, 16);
|
|
435
|
+
assertBoundedStyleNumber(column.paddingStart, `${field}.paddingStart`, 0, 64);
|
|
436
|
+
assertBoundedStyleNumber(column.paddingEnd, `${field}.paddingEnd`, 0, 64);
|
|
437
|
+
if (column.alignment !== undefined && !['start', 'center', 'end'].includes(column.alignment)) fail(`${field}.alignment`, 'must be start, center, or end');
|
|
438
|
+
});
|
|
439
|
+
const text = (value, field) => {
|
|
440
|
+
assertUnknownKeys(value, ['text', 'segments', 'tone', 'style'], field, 'Web text key');
|
|
441
|
+
assertText(value.text, `${field}.text`);
|
|
442
|
+
assertTextTone(value.tone, `${field}.tone`);
|
|
443
|
+
assertTextStyle(value.style, `${field}.style`);
|
|
444
|
+
if (value.style) assertUnknownKeys(value.style, ['fontSize', 'fontWeight', 'lineHeight', 'color'], `${field}.style`, 'Web table text style');
|
|
445
|
+
if ((value.segments?.length ?? 0) > 64) fail(`${field}.segments`, 'supports at most 64 segments');
|
|
446
|
+
value.segments?.forEach((segment, index) => {
|
|
447
|
+
assertUnknownKeys(segment, ['text', 'style'], `${field}.segments[${index}]`, 'Web text segment');
|
|
448
|
+
assertText(segment.text, `${field}.segments[${index}].text`);
|
|
449
|
+
if (segment.style !== undefined && segment.style !== 'subscript') fail(field, 'segment style must be subscript');
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
const line = (parts, field) => {
|
|
453
|
+
if (!parts) return;
|
|
454
|
+
if (!Array.isArray(parts) || parts.length > 8) fail(field, 'supports at most 8 text parts');
|
|
455
|
+
parts.forEach((value, index) => text(value, `${field}[${index}]`));
|
|
456
|
+
};
|
|
457
|
+
table.cells.forEach((cell, index) => {
|
|
458
|
+
const field = `${path}.cells[${index}]`;
|
|
459
|
+
assertKey(cell.key, `${field}.key`);
|
|
460
|
+
if (cell.key !== table.columns[index].key) fail(field, 'cell key/order must match its column');
|
|
461
|
+
switch (cell.kind) {
|
|
462
|
+
case 'favorite':
|
|
463
|
+
assertUnknownKeys(cell, ['key', 'kind', 'active', 'disabled', 'testID', 'hoverActionKey', 'actionKey', 'accessibilityLabel'], field, 'Web favorite key');
|
|
464
|
+
if (typeof cell.active !== 'boolean') fail(field, 'active must be boolean');
|
|
465
|
+
if (cell.disabled !== undefined && typeof cell.disabled !== 'boolean') fail(field, 'disabled must be boolean');
|
|
466
|
+
if (cell.hoverActionKey !== undefined) assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
|
|
467
|
+
assertText(cell.testID, `${field}.testID`);
|
|
468
|
+
assertKey(cell.actionKey, `${field}.actionKey`);
|
|
469
|
+
assertText(cell.accessibilityLabel, `${field}.accessibilityLabel`);
|
|
470
|
+
break;
|
|
471
|
+
case 'asset':
|
|
472
|
+
assertUnknownKeys(cell, ['key', 'kind', 'leading', 'title', 'secondary', 'hoverSecondary', 'hoverActionKey', 'hoverActionLabel', 'badges', 'lineGap', 'secondaryBadges', 'hoverImages'], field, 'Web asset key');
|
|
473
|
+
assertBoundedStyleNumber(cell.lineGap, `${field}.lineGap`, 0, 8);
|
|
474
|
+
assertMarketBadges(cell.secondaryBadges, `${field}.secondary`);
|
|
475
|
+
cell.secondaryBadges?.forEach((badge, i) => {
|
|
476
|
+
assertUnknownKeys(badge, ['key', 'text', 'style'], `${field}.secondaryBadges[${i}]`, 'Web secondary badge key');
|
|
477
|
+
if (!badge.text) fail(field, 'secondary badges require text');
|
|
478
|
+
});
|
|
479
|
+
if (cell.hoverImages !== undefined && (!Array.isArray(cell.hoverImages) || cell.hoverImages.length > 4)) fail(field, 'supports at most 4 hover images');
|
|
480
|
+
cell.hoverImages?.forEach((image, i) => {
|
|
481
|
+
if (image !== null) assertImage(image, `${field}.hoverImages[${i}]`);
|
|
482
|
+
});
|
|
483
|
+
assertLeadingVisual(cell.leading, `${field}.leading`);
|
|
484
|
+
text(cell.title, `${field}.title`);
|
|
485
|
+
line(cell.secondary, `${field}.secondary`);
|
|
486
|
+
line(cell.hoverSecondary, `${field}.hoverSecondary`);
|
|
487
|
+
assertText(cell.hoverActionLabel, `${field}.hoverActionLabel`);
|
|
488
|
+
if (cell.hoverActionKey !== undefined) assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
|
|
489
|
+
assertMarketBadges(cell.badges, field);
|
|
490
|
+
cell.badges?.forEach((badge, i) => assertUnknownKeys(badge, ['key', 'text', 'iconName', 'icon', 'textColor', 'backgroundColor', 'actionKey', 'accessibilityLabel', 'style'], `${field}.badges[${i}]`, 'Web title badge key'));
|
|
491
|
+
break;
|
|
492
|
+
case 'text':
|
|
493
|
+
assertUnknownKeys(cell, ['key', 'kind', 'primary', 'secondary', 'partGap'], field, 'Web text cell key');
|
|
494
|
+
assertBoundedStyleNumber(cell.partGap, `${field}.partGap`, 0, 8);
|
|
495
|
+
if (!Array.isArray(cell.primary) || !cell.primary.length) fail(field, 'requires primary text');
|
|
496
|
+
line(cell.primary, `${field}.primary`);
|
|
497
|
+
line(cell.secondary, `${field}.secondary`);
|
|
498
|
+
break;
|
|
499
|
+
case 'sparkline':
|
|
500
|
+
assertUnknownKeys(cell, ['key', 'kind', 'points', 'width', 'height', 'strokeColor', 'fillColor'], field, 'Web sparkline key');
|
|
501
|
+
if (!Array.isArray(cell.points) || cell.points.length > 256 || cell.points.some(value => !Number.isFinite(value))) fail(field, 'supports at most 256 finite samples');
|
|
502
|
+
if (typeof cell.width !== 'number' || typeof cell.height !== 'number') fail(field, 'sparkline dimensions are required');
|
|
503
|
+
assertBoundedStyleNumber(cell.width, `${field}.width`, 1, 512);
|
|
504
|
+
assertBoundedStyleNumber(cell.height, `${field}.height`, 1, 512);
|
|
505
|
+
for (const color of [cell.strokeColor, cell.fillColor]) if (typeof color !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(color)) fail(field, 'colors must be #RRGGBB or #RRGGBBAA');
|
|
506
|
+
break;
|
|
507
|
+
default:
|
|
508
|
+
fail(field, 'unsupported Web table cell kind');
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
350
512
|
function assertMarketRow(row, path) {
|
|
513
|
+
assertWebMarketTable(row.webTable, `${path}.webTable`);
|
|
351
514
|
if (!['token', 'stock', 'perp'].includes(row.variant)) {
|
|
352
515
|
fail(`${path}.variant`, 'must be token, stock, or perp');
|
|
353
516
|
}
|
|
@@ -356,6 +519,7 @@ function assertMarketRow(row, path) {
|
|
|
356
519
|
// OneKey patch: validate the independently laid out Market name.
|
|
357
520
|
if (row.subtitlePrefix) {
|
|
358
521
|
assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
|
|
522
|
+
assertText(row.subtitlePrefix.hoverActionKey, `${path}.subtitlePrefix.hoverActionKey`);
|
|
359
523
|
assertBoundedStyleNumber(row.subtitlePrefix.gap, `${path}.subtitlePrefix.gap`, 0, 64);
|
|
360
524
|
assertBoundedStyleNumber(row.subtitlePrefix.maxWidth, `${path}.subtitlePrefix.maxWidth`, 1, 320);
|
|
361
525
|
assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
|
|
@@ -384,40 +548,7 @@ function assertMarketRow(row, path) {
|
|
|
384
548
|
if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
|
|
385
549
|
fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
|
|
386
550
|
}
|
|
387
|
-
|
|
388
|
-
fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
|
|
389
|
-
}
|
|
390
|
-
const badgeKeys = new Set();
|
|
391
|
-
row.badges?.forEach((badge, index) => {
|
|
392
|
-
const badgePath = `${path}.badges[${index}]`;
|
|
393
|
-
assertKey(badge.key, `${badgePath}.key`);
|
|
394
|
-
if (badgeKeys.has(badge.key)) {
|
|
395
|
-
fail(`${path}.badges`, `duplicate badge key "${badge.key}"`);
|
|
396
|
-
}
|
|
397
|
-
badgeKeys.add(badge.key);
|
|
398
|
-
assertText(badge.text, `${badgePath}.text`);
|
|
399
|
-
// OneKey patch: share typography bounds with Market text styles.
|
|
400
|
-
assertTextStyle(badge.style, `${badgePath}.style`, ['height', 'horizontalPadding']);
|
|
401
|
-
if (badge.style) assertUnknownKeys(badge.style, ['fontSize', 'fontWeight', 'lineHeight', 'height', 'horizontalPadding'], `${badgePath}.style`, 'Market badge style key');
|
|
402
|
-
assertBoundedStyleNumber(badge.style?.height, `${badgePath}.style.height`, 1, 64);
|
|
403
|
-
assertBoundedStyleNumber(badge.style?.horizontalPadding, `${badgePath}.style.horizontalPadding`, 0, 32);
|
|
404
|
-
if (badge.iconName !== undefined && badge.iconName !== 'verified') {
|
|
405
|
-
fail(`${badgePath}.iconName`, 'must be verified when provided');
|
|
406
|
-
}
|
|
407
|
-
if (badge.iconName !== undefined && badge.icon !== undefined) {
|
|
408
|
-
fail(`${badgePath}.icon`, 'cannot be combined with iconName');
|
|
409
|
-
}
|
|
410
|
-
assertImage(badge.icon, `${badgePath}.icon`);
|
|
411
|
-
if (badge.tone !== undefined && !['neutral', 'info', 'success', 'warning', 'danger'].includes(badge.tone)) {
|
|
412
|
-
fail(`${badgePath}.tone`, 'must be neutral, info, success, warning, or danger');
|
|
413
|
-
}
|
|
414
|
-
if (!badge.text && !badge.icon && !badge.iconName) {
|
|
415
|
-
fail(badgePath, 'requires text, icon, or iconName');
|
|
416
|
-
}
|
|
417
|
-
if (badge.actionKey !== undefined) {
|
|
418
|
-
assertKey(badge.actionKey, `${badgePath}.actionKey`);
|
|
419
|
-
}
|
|
420
|
-
});
|
|
551
|
+
assertMarketBadges(row.badges, path);
|
|
421
552
|
for (const [key, value] of [['pressActionKey', row.pressActionKey], ['pressInActionKey', row.pressInActionKey], ['longPressActionKey', row.longPressActionKey], ['diagnostics.imageBindActionKey', row.diagnostics?.imageBindActionKey]]) {
|
|
422
553
|
if (value !== undefined) assertKey(value, `${path}.${key}`);
|
|
423
554
|
}
|
|
@@ -453,6 +584,13 @@ function assertTrailingAccessories(accessories, path) {
|
|
|
453
584
|
function assertImage(image, path) {
|
|
454
585
|
if (!image) return;
|
|
455
586
|
if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
|
|
587
|
+
if (image.fallbackUris !== undefined) {
|
|
588
|
+
if (!Array.isArray(image.fallbackUris)) fail(`${path}.fallbackUris`, 'must be an array');
|
|
589
|
+
image.fallbackUris.forEach((uri, index) => {
|
|
590
|
+
if (typeof uri !== 'string') fail(`${path}.fallbackUris[${index}]`, 'must be a string');
|
|
591
|
+
assertText(uri, `${path}.fallbackUris[${index}]`);
|
|
592
|
+
});
|
|
593
|
+
}
|
|
456
594
|
if (!Number.isFinite(image.width) || !Number.isFinite(image.height) || image.width <= 0 || image.height <= 0 || image.width > MAX_IMAGE_EDGE || image.height > MAX_IMAGE_EDGE) {
|
|
457
595
|
fail(path, `width and height must be within 1...${MAX_IMAGE_EDGE}`);
|
|
458
596
|
}
|
|
@@ -799,9 +937,10 @@ function assertMediaPreview(value, path) {
|
|
|
799
937
|
fail(`${path}.probeOrder`, 'must contain one or two distinct image/video candidates');
|
|
800
938
|
}
|
|
801
939
|
}
|
|
802
|
-
|
|
940
|
+
function assertSnapshotContract(snapshot) {
|
|
803
941
|
if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
|
|
804
942
|
assertPlainSerializable(snapshot, 'snapshot', new Set());
|
|
943
|
+
assertText(snapshot.theme?.imageFallbackBackground, 'theme.imageFallbackBackground');
|
|
805
944
|
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
806
945
|
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
|
|
807
946
|
fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
@@ -870,7 +1009,170 @@ export function validateSnapshot(snapshot) {
|
|
|
870
1009
|
if (snapshot.selection?.mode === 'single' && selectedKeys.size > 1) {
|
|
871
1010
|
fail('snapshot.selection.selectedKeys', 'supports at most one key in single mode');
|
|
872
1011
|
}
|
|
873
|
-
return
|
|
1012
|
+
return snapshot;
|
|
1013
|
+
}
|
|
1014
|
+
function protocolObject(value, path) {
|
|
1015
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) fail(path, 'must be an object');
|
|
1016
|
+
return value;
|
|
1017
|
+
}
|
|
1018
|
+
function protocolKey(value, path) {
|
|
1019
|
+
if (typeof value !== 'string' || value.trim().length === 0) fail(path, 'must be a non-blank string');
|
|
1020
|
+
}
|
|
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']);
|
|
1023
|
+
|
|
1024
|
+
/** Validate only shapes that renderers dereference, not display budgets. */
|
|
1025
|
+
function assertProtocolFields(value, path, parentField = '') {
|
|
1026
|
+
if (value === undefined || value === null || typeof value !== 'object') return;
|
|
1027
|
+
if (Array.isArray(value)) {
|
|
1028
|
+
for (const [index, item] of value.entries()) {
|
|
1029
|
+
const itemPath = `${path}[${index}]`;
|
|
1030
|
+
if (['selectedKeys', 'fallbackUris', 'probeOrder'].includes(parentField)) {
|
|
1031
|
+
if (typeof item !== 'string') fail(itemPath, 'must be a string');
|
|
1032
|
+
} else if (parentField === 'points') {
|
|
1033
|
+
if (typeof item !== 'number') fail(itemPath, 'must be a finite number');
|
|
1034
|
+
} else if (parentField === 'hoverImages' && item === null) continue;else protocolObject(item, itemPath);
|
|
1035
|
+
assertProtocolFields(item, itemPath, parentField);
|
|
1036
|
+
}
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
const object = value;
|
|
1040
|
+
if (!path.includes('.style.') && ['image', 'networkImage', 'thumbnail', 'images', 'hoverImages'].includes(parentField) && typeof object.uri !== 'string') fail(`${path}.uri`, 'must be a string');
|
|
1041
|
+
Object.entries(value).forEach(([field, item]) => {
|
|
1042
|
+
if (item === undefined) return;
|
|
1043
|
+
const fieldPath = `${path}.${field}`;
|
|
1044
|
+
if (!path.endsWith('.style') && PROTOCOL_ARRAY_FIELDS.has(field) && !Array.isArray(item)) fail(fieldPath, 'must be an array');
|
|
1045
|
+
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item !== 'number') fail(fieldPath, 'must be a finite number');
|
|
1046
|
+
if (PROTOCOL_NUMBER_FIELDS.has(field) && typeof item === 'number' && item < 0 && !['offsetX', 'offsetY'].includes(field)) fail(fieldPath, 'must be non-negative');
|
|
1047
|
+
if (field === 'key' || field === 'sectionKey' || field === 'actionKey' || field.endsWith('ActionKey')) protocolKey(item, fieldPath);
|
|
1048
|
+
if ((field === 'uri' || field === 'fallbackUri') && typeof item !== 'string') fail(fieldPath, 'must be a string');
|
|
1049
|
+
if (field === 'style' && !(item === 'subscript' && /[Ss]egments\[/.test(path)) || field === 'container') protocolObject(item, fieldPath);
|
|
1050
|
+
if (path.endsWith('.style') && ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'change', 'columns', 'columnSecondary', 'value', 'valueSecondary', 'badge', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'trend', 'message', 'actionText'].includes(field)) protocolObject(item, fieldPath);
|
|
1051
|
+
assertProtocolFields(item, fieldPath, field);
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
function assertRowProtocol(row, path) {
|
|
1055
|
+
protocolObject(row, path);
|
|
1056
|
+
assertRowType(row.type, path);
|
|
1057
|
+
protocolKey(row.key, `${path}.key`);
|
|
1058
|
+
assertProtocolFields(row, path);
|
|
1059
|
+
for (const field of ['leading', 'visual', 'secondaryLeading']) {
|
|
1060
|
+
const visual = row[field];
|
|
1061
|
+
if (visual !== undefined || field === 'leading' && (row.type === 'identity' || row.type === 'market')) {
|
|
1062
|
+
const object = protocolObject(visual, `${path}.${field}`);
|
|
1063
|
+
if (object.kind === 'stackedImages' && !Array.isArray(object.images)) fail(`${path}.${field}.images`, 'must be an array');
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
for (const field of ['title', 'subtitle', 'tertiary', 'body', 'time', 'price', 'indexTitle']) {
|
|
1067
|
+
const value = row[field];
|
|
1068
|
+
if (value !== undefined && typeof value !== 'string') fail(`${path}.${field}`, 'must be a string');
|
|
1069
|
+
}
|
|
1070
|
+
if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
|
|
1071
|
+
if (row.type === 'identity') {
|
|
1072
|
+
let end = 0;
|
|
1073
|
+
row.titleMatch?.forEach(match => {
|
|
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');
|
|
1075
|
+
end = match.end;
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
if (row.type === 'mediaTile' && row.media) {
|
|
1079
|
+
protocolObject(row.media.source, `${path}.media.source`);
|
|
1080
|
+
if (!Array.isArray(row.media.probeOrder)) fail(`${path}.media.probeOrder`, 'must be an array');
|
|
1081
|
+
}
|
|
1082
|
+
if (row.type === 'walletGroup') {
|
|
1083
|
+
protocolObject(row.parent, `${path}.parent`);
|
|
1084
|
+
if (!Array.isArray(row.children)) fail(`${path}.children`, 'must be an array');
|
|
1085
|
+
const members = [row.parent, ...row.children];
|
|
1086
|
+
const keys = new Set();
|
|
1087
|
+
if (row.parent.key !== row.key) fail(`${path}.parent.key`, 'must match its group');
|
|
1088
|
+
members.forEach((member, index) => {
|
|
1089
|
+
assertRowProtocol(member, `${path}.members[${index}]`);
|
|
1090
|
+
if (member.type !== 'identity' || keys.has(member.key)) fail(path, 'invalid wallet member identity');
|
|
1091
|
+
keys.add(member.key);
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
if (row.type === 'dataRow' && !Array.isArray(row.columns)) fail(`${path}.columns`, 'must be an array');
|
|
1095
|
+
if (row.type === 'market') {
|
|
1096
|
+
protocolObject(row.change, `${path}.change`);
|
|
1097
|
+
if (row.webTable) {
|
|
1098
|
+
const {
|
|
1099
|
+
columns,
|
|
1100
|
+
cells
|
|
1101
|
+
} = row.webTable;
|
|
1102
|
+
if (!Array.isArray(columns) || !Array.isArray(cells) || columns.length !== cells.length) fail(`${path}.webTable`, 'columns and cells must match');
|
|
1103
|
+
const keys = new Set();
|
|
1104
|
+
columns.forEach((column, index) => {
|
|
1105
|
+
protocolKey(column.key, `${path}.webTable.columns[${index}].key`);
|
|
1106
|
+
if (keys.has(column.key) || cells[index]?.key !== column.key) fail(`${path}.webTable`, 'invalid column identity');
|
|
1107
|
+
keys.add(column.key);
|
|
1108
|
+
const cell = cells[index];
|
|
1109
|
+
if (!['favorite', 'asset', 'text', 'sparkline'].includes(cell.kind)) fail(`${path}.webTable.cells[${index}]`, 'unsupported cell kind');
|
|
1110
|
+
if (cell.kind === 'asset') protocolObject(cell.title, `${path}.webTable.cells[${index}].title`);
|
|
1111
|
+
if ((cell.kind === 'asset' || cell.kind === 'text') && cell.secondary !== undefined && !Array.isArray(cell.secondary)) fail(`${path}.webTable.cells[${index}].secondary`, 'must be an array');
|
|
1112
|
+
if (cell.kind === 'text' && !Array.isArray(cell.primary)) fail(`${path}.webTable.cells[${index}].primary`, 'must be an array');
|
|
1113
|
+
// The Web renderer spreads samples into Math.min/Math.max.
|
|
1114
|
+
if (cell.kind === 'sparkline' && (!Array.isArray(cell.points) || cell.points.length > 256)) fail(`${path}.webTable.cells[${index}].points`, 'must be an array of at most 256 samples');
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
function assertSnapshotProtocol(snapshot) {
|
|
1120
|
+
protocolObject(snapshot, 'snapshot');
|
|
1121
|
+
if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
|
|
1122
|
+
if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) fail('snapshot.generation', 'must be a non-negative safe integer');
|
|
1123
|
+
protocolObject(snapshot.layout, 'snapshot.layout');
|
|
1124
|
+
assertProtocolFields(snapshot.layout, 'snapshot.layout');
|
|
1125
|
+
if (snapshot.layout.orientation !== undefined && !['vertical', 'horizontal'].includes(snapshot.layout.orientation)) fail('snapshot.layout.orientation', 'is not supported');
|
|
1126
|
+
if (!['linear', 'sectioned', 'grid', 'table'].includes(snapshot.layout.kind)) fail('snapshot.layout.kind', 'is not supported');
|
|
1127
|
+
if (!Array.isArray(snapshot.rows)) fail('snapshot.rows', 'must be an array');
|
|
1128
|
+
if (snapshot.layout.kind === 'grid' && (!Number.isInteger(snapshot.layout.gridColumns) || (snapshot.layout.gridColumns ?? 0) < 1 || (snapshot.layout.gridColumns ?? 0) > 7)) fail('snapshot.layout.gridColumns', 'must be an integer from 1 to 7');
|
|
1129
|
+
const keys = new Set();
|
|
1130
|
+
for (const [index, row] of snapshot.rows.entries()) {
|
|
1131
|
+
assertRowProtocol(row, `rows[${index}]`);
|
|
1132
|
+
if (keys.has(row.key)) fail(`rows[${index}].key`, 'duplicate row identity');
|
|
1133
|
+
keys.add(row.key);
|
|
1134
|
+
}
|
|
1135
|
+
if (snapshot.emptyState) assertRowProtocol(snapshot.emptyState, 'emptyState');
|
|
1136
|
+
if (snapshot.fixedFooter) assertRowProtocol(snapshot.fixedFooter, 'fixedFooter');
|
|
1137
|
+
if (snapshot.selection) {
|
|
1138
|
+
if (!Array.isArray(snapshot.selection.selectedKeys)) fail('snapshot.selection.selectedKeys', 'must be an array');
|
|
1139
|
+
snapshot.selection.selectedKeys.forEach(key => {
|
|
1140
|
+
if (!keys.has(key)) fail('snapshot.selection.selectedKeys', 'unknown row identity');
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/** Empty optional image descriptors must take the same path as absent images. */
|
|
1146
|
+
function normalizeEmptyImages(value, field = '') {
|
|
1147
|
+
if (!value || typeof value !== 'object') return value;
|
|
1148
|
+
if (Array.isArray(value)) {
|
|
1149
|
+
const next = value.map(item => normalizeEmptyImages(item));
|
|
1150
|
+
const filtered = field === 'images' ? next.filter(item => item !== undefined) : next.map(item => item === undefined ? null : item);
|
|
1151
|
+
return filtered.length === value.length && filtered.every((item, index) => item === value[index]) ? value : filtered;
|
|
1152
|
+
}
|
|
1153
|
+
const object = value;
|
|
1154
|
+
if (typeof object.uri === 'string' && !object.uri.trim() && 'width' in object && 'height' in object) return undefined;
|
|
1155
|
+
let changed = false;
|
|
1156
|
+
const next = {
|
|
1157
|
+
...object
|
|
1158
|
+
};
|
|
1159
|
+
Object.entries(object).forEach(([key, item]) => {
|
|
1160
|
+
const normalized = normalizeEmptyImages(item, key);
|
|
1161
|
+
if (normalized !== item) {
|
|
1162
|
+
// Omitted JSON patch fields must also be absent from the JS merge.
|
|
1163
|
+
if (field === 'changes' && normalized === undefined) delete next[key];else next[key] = normalized;
|
|
1164
|
+
changed = true;
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
if (field === 'media' && next.source === undefined) return undefined;
|
|
1168
|
+
return changed ? next : value;
|
|
1169
|
+
}
|
|
1170
|
+
export function validateSnapshot(snapshot) {
|
|
1171
|
+
assertPlainSerializable(snapshot, 'snapshot', new Set());
|
|
1172
|
+
if (isDevelopment()) assertSnapshotContract(snapshot);
|
|
1173
|
+
const normalized = isDevelopment() ? snapshot : normalizeEmptyImages(snapshot);
|
|
1174
|
+
assertSnapshotProtocol(normalized);
|
|
1175
|
+
return normalizeSnapshotStyles(normalized);
|
|
874
1176
|
}
|
|
875
1177
|
|
|
876
1178
|
/**
|
|
@@ -1051,17 +1353,25 @@ function assertPatchChanges(patch, index) {
|
|
|
1051
1353
|
}
|
|
1052
1354
|
export function validatePatches(patches) {
|
|
1053
1355
|
assertPlainSerializable(patches, 'patches', new Set());
|
|
1356
|
+
if (!Array.isArray(patches)) fail('patches', 'must be an array');
|
|
1054
1357
|
const keys = new Set();
|
|
1055
|
-
patches.
|
|
1056
|
-
|
|
1358
|
+
for (const [index, patch] of patches.entries()) {
|
|
1359
|
+
protocolObject(patch, `patches[${index}]`);
|
|
1360
|
+
protocolKey(patch.key, `patches[${index}].key`);
|
|
1057
1361
|
if (keys.has(patch.key)) fail(`patches[${index}].key`, `duplicate key "${patch.key}"`);
|
|
1058
1362
|
keys.add(patch.key);
|
|
1363
|
+
protocolObject(patch.changes, `patches[${index}].changes`);
|
|
1364
|
+
assertRowType(patch.type, `patches[${index}]`);
|
|
1365
|
+
assertProtocolFields(patch.changes, `patches[${index}].changes`);
|
|
1366
|
+
if (!isDevelopment()) continue;
|
|
1367
|
+
assertKey(patch.key, `patches[${index}].key`);
|
|
1059
1368
|
if (Object.keys(patch.changes).length === 0) {
|
|
1060
1369
|
fail(`patches[${index}].changes`, 'must contain at least one field');
|
|
1061
1370
|
}
|
|
1062
1371
|
assertPatchChanges(patch, index);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1372
|
+
}
|
|
1373
|
+
const normalized = isDevelopment() ? patches : normalizeEmptyImages(patches);
|
|
1374
|
+
return normalizePatchStyles(normalized.filter(patch => Object.keys(patch.changes).length > 0));
|
|
1065
1375
|
}
|
|
1066
1376
|
|
|
1067
1377
|
/** Patches reach the native side without passing through a snapshot. */
|
|
@@ -1084,10 +1394,10 @@ function normalizePatchStyles(patches) {
|
|
|
1084
1394
|
return changed ? next : patches;
|
|
1085
1395
|
}
|
|
1086
1396
|
export function applyRowPatches(snapshot, patches) {
|
|
1087
|
-
validatePatches(patches);
|
|
1088
|
-
const patchByKey = new Map(
|
|
1397
|
+
const normalizedPatches = validatePatches(patches);
|
|
1398
|
+
const patchByKey = new Map(normalizedPatches.map(patch => [patch.key, patch]));
|
|
1089
1399
|
const knownKeys = new Set(snapshot.rows.map(row => row.key));
|
|
1090
|
-
|
|
1400
|
+
normalizedPatches.forEach(patch => {
|
|
1091
1401
|
if (!knownKeys.has(patch.key)) fail('patches', `unknown row key "${patch.key}"`);
|
|
1092
1402
|
});
|
|
1093
1403
|
const rows = snapshot.rows.map(row => {
|
|
@@ -1096,6 +1406,7 @@ export function applyRowPatches(snapshot, patches) {
|
|
|
1096
1406
|
if (patch.type !== row.type) {
|
|
1097
1407
|
fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
|
|
1098
1408
|
}
|
|
1409
|
+
if (row.type === 'market' && row.webTable && patch.type === 'market' && (patch.changes.price !== undefined || patch.changes.priceSegments !== undefined || patch.changes.change !== undefined) && patch.changes.webTable === undefined) fail('patches', 'table quote changes must include the visible table cells');
|
|
1099
1410
|
return {
|
|
1100
1411
|
...row,
|
|
1101
1412
|
...patch.changes,
|