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

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 (33) hide show
  1. package/docs/SPEC.md +365 -9
  2. package/lib/module/NativeList.js +2 -0
  3. package/lib/module/NativeList.web.js +135 -29
  4. package/lib/module/validation.js +143 -34
  5. package/lib/module/web/NativeListWebEngine.js +353 -62
  6. package/lib/module/web/templates/ActivityRowRenderer.js +432 -5
  7. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  8. package/lib/module/web/templates/MarketTableRowRenderer.js +576 -0
  9. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  10. package/lib/module/web/templates/RowRendererRegistry.js +5 -3
  11. package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
  12. package/lib/typescript/src/NativeList.types.d.ts +11 -1
  13. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  14. package/lib/typescript/src/models.d.ts +71 -1
  15. package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
  16. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  17. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  18. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  19. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
  20. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  21. package/package.json +3 -3
  22. package/src/NativeList.tsx +2 -0
  23. package/src/NativeList.types.ts +12 -1
  24. package/src/NativeList.web.tsx +183 -38
  25. package/src/models.ts +93 -0
  26. package/src/validation.ts +348 -58
  27. package/src/web/NativeListWebEngine.ts +600 -95
  28. package/src/web/templates/ActivityRowRenderer.ts +656 -7
  29. package/src/web/templates/MarketRowRenderer.ts +19 -3
  30. package/src/web/templates/MarketTableRowRenderer.ts +752 -0
  31. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  32. package/src/web/templates/RowRendererRegistry.ts +10 -5
  33. package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  import { useNativeListFontFamiliesJson } from "./fonts.js";
4
- import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
4
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
5
5
  import { View } from 'react-native';
6
6
  import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
7
- import { serializePatches, validateSnapshot } from "./validation.js";
7
+ import { applyRowPatches, validateSnapshot } from "./validation.js";
8
8
  import { NativeListWebEngine } from "./web/NativeListWebEngine.js";
9
9
  import { acquireNativeListAvatar, canonicalNativeListAvatarUri } from "./web/NativeListWebAvatarCache.js";
10
- import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  export function preloadNativeListAvatarImages(sources) {
12
12
  if (typeof document === 'undefined') return Promise.resolve(false);
13
13
  const uris = [...new Set(sources.map(source => canonicalNativeListAvatarUri(source.uri)).filter(uri => uri !== undefined))];
@@ -23,11 +23,13 @@ export function preloadNativeListAvatarImages(sources) {
23
23
  }
24
24
  export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
25
25
  snapshot,
26
- listHeader: _listHeader,
27
- listEmpty: _listEmpty,
28
- listFooter: _listFooter,
26
+ listHeader,
27
+ listEmpty,
28
+ listFooter,
29
29
  topOverlay: _topOverlay,
30
30
  topScrollEdgeEffect: _topScrollEdgeEffect,
31
+ webScrollHost,
32
+ webStickyInset = 0,
31
33
  scrollPositionThresholds: _scrollPositionThresholds,
32
34
  onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
33
35
  webVirtualizationEnabled = true,
@@ -51,20 +53,59 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
51
53
  const fontFamiliesJson = useNativeListFontFamiliesJson();
52
54
  const fontFamiliesJsonRef = useRef(fontFamiliesJson);
53
55
  fontFamiliesJsonRef.current = fontFamiliesJson;
56
+ const hasEmptySlot = listEmpty !== undefined;
57
+ const hasEmptySlotRef = useRef(hasEmptySlot);
58
+ hasEmptySlotRef.current = hasEmptySlot;
59
+ const [slotState, setSlotState] = useState(() => ({
60
+ hasRows: snapshot.rows.length > 0,
61
+ emptyBottomPadding: !snapshot.rows.length && hasEmptySlot ? snapshot.layout.contentPaddingBottom ?? snapshot.layout.contentPadding ?? 0 : 0,
62
+ padding: snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0
63
+ }));
64
+ const synchronizeSlots = next => {
65
+ const hasRows = next.rows.length > 0;
66
+ const padding = next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
67
+ const emptyBottomPadding = !hasRows && hasEmptySlotRef.current ? next.layout.contentPaddingBottom ?? next.layout.contentPadding ?? 0 : 0;
68
+ setSlotState(previous => previous.hasRows === hasRows && previous.padding === padding && previous.emptyBottomPadding === emptyBottomPadding ? previous : {
69
+ hasRows,
70
+ padding,
71
+ emptyBottomPadding
72
+ });
73
+ };
74
+ const normalizeWebSnapshot = (next, hasReactEmpty = hasEmptySlotRef.current, hasSlotLayout = useSlotLayoutRef.current) => {
75
+ if (hasSlotLayout && next.layout.orientation === 'horizontal') throw new Error('Web parent scrolling and container slots support vertical lists only');
76
+ const emptySlot = hasReactEmpty && next.rows.length === 0;
77
+ const validated = validateSnapshot(emptySlot ? {
78
+ ...next,
79
+ emptyState: undefined
80
+ } : next);
81
+ return emptySlot ? {
82
+ ...validated,
83
+ layout: {
84
+ ...validated.layout,
85
+ contentPaddingBottom: 0
86
+ }
87
+ } : validated;
88
+ };
54
89
  const [host, setHost] = useState(null);
90
+ const [contentBounds, setContentBounds] = useState(null);
91
+ const [ownedScrollHost, setOwnedScrollHost] = useState(null);
92
+ const useSlotLayoutRef = useRef(false);
93
+ useSlotLayoutRef.current ||= webScrollHost !== undefined || listHeader !== undefined || listEmpty !== undefined || listFooter !== undefined;
94
+ const useSlotLayout = useSlotLayoutRef.current;
95
+ const resolvedScrollHost = webScrollHost === undefined ? useSlotLayout ? ownedScrollHost : undefined : webScrollHost;
96
+ if (!Number.isFinite(webStickyInset) || webStickyInset < 0) throw new Error('webStickyInset must be finite and non-negative');
55
97
  const engineRef = useRef(undefined);
56
98
  const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
57
99
  webVirtualizationEnabledRef.current = webVirtualizationEnabled;
58
- const validatedSnapshot = useMemo(() => validateSnapshot(snapshot), [snapshot]);
100
+ const validatedSnapshot = useMemo(() => normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout), [snapshot, hasEmptySlot, useSlotLayout]);
59
101
  const snapshotRef = useRef(validatedSnapshot);
60
102
  const snapshotPropRef = useRef(validatedSnapshot);
61
103
  // An imperative snapshot survives host mounting until the snapshot prop changes.
62
104
  if (snapshotPropRef.current !== validatedSnapshot) {
63
105
  snapshotPropRef.current = validatedSnapshot;
64
106
  snapshotRef.current = validatedSnapshot;
107
+ synchronizeSlots(snapshot);
65
108
  }
66
- // OneKey patch: React refs can be ready before the DOM engine is mounted.
67
- const pendingPatchesRef = useRef(undefined);
68
109
  const appliedSnapshotRef = useRef(undefined);
69
110
  const callbacksRef = useRef({});
70
111
  callbacksRef.current = {
@@ -91,24 +132,39 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
91
132
  }, 'start')
92
133
  });
93
134
  const didApplyInitialScroll = useRef(false);
135
+ const scrollOptionsRef = useRef({
136
+ stickyInset: webStickyInset,
137
+ ownsRefresh: webScrollHost === undefined
138
+ });
139
+ scrollOptionsRef.current = {
140
+ stickyInset: webStickyInset,
141
+ ownsRefresh: webScrollHost === undefined
142
+ };
94
143
  useEffect(() => {
95
- if (!host) return;
96
- const engine = new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current);
144
+ if (!host || resolvedScrollHost === null || useSlotLayout && !contentBounds) return;
145
+ const engine = new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current, {
146
+ scrollHost: resolvedScrollHost,
147
+ contentBounds: contentBounds ?? undefined,
148
+ ...scrollOptionsRef.current
149
+ });
150
+ host.style.height = '';
97
151
  engineRef.current = engine;
98
152
  appliedSnapshotRef.current = snapshotRef.current;
99
- const pending = pendingPatchesRef.current;
100
- pendingPatchesRef.current = undefined;
101
- if (pending?.snapshot === snapshotRef.current) pending.batches.forEach(patches => engine.applyPatches(patches));
102
153
  const initial = initialScrollRef.current;
103
154
  if (initial && !didApplyInitialScroll.current) {
104
155
  didApplyInitialScroll.current = true;
105
156
  if (initial.index !== undefined) engine.scrollToIndex(initial.index, initial.scroll);else if (initial.key !== undefined) engine.scrollToKey(initial.key, initial.scroll);
106
157
  }
107
158
  return () => {
159
+ // Keep the paused tab in normal flow until its engine is restored.
160
+ host.style.height = `${engine.currentContentHeight()}px`;
108
161
  engine.destroy();
109
162
  if (engineRef.current === engine) engineRef.current = undefined;
110
163
  };
111
- }, [host, webSectionIndexContainerRef]);
164
+ }, [host, webSectionIndexContainerRef, resolvedScrollHost, contentBounds, useSlotLayout]);
165
+ useEffect(() => {
166
+ engineRef.current?.setStickyInset(webStickyInset);
167
+ }, [webStickyInset]);
112
168
  useEffect(() => {
113
169
  engineRef.current?.setFontFamiliesJson(fontFamiliesJson);
114
170
  }, [fontFamiliesJson]);
@@ -118,7 +174,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
118
174
  useEffect(() => {
119
175
  engineRef.current?.updateCallbacks(callbacksRef.current);
120
176
  });
121
- useEffect(() => {
177
+ useLayoutEffect(() => {
122
178
  const engine = engineRef.current;
123
179
  if (!engine || appliedSnapshotRef.current === validatedSnapshot) return;
124
180
  engine.applySnapshot(validatedSnapshot);
@@ -129,23 +185,19 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
129
185
  };
130
186
  useImperativeHandle(forwardedRef, () => ({
131
187
  applySnapshot(nextSnapshot) {
132
- const next = validateSnapshot(nextSnapshot);
133
- pendingPatchesRef.current = undefined;
188
+ const next = normalizeWebSnapshot(nextSnapshot);
189
+ engineRef.current?.applySnapshot(next);
134
190
  snapshotRef.current = next;
135
191
  appliedSnapshotRef.current = next;
136
- engineRef.current?.applySnapshot(next);
192
+ synchronizeSlots(nextSnapshot);
137
193
  },
138
194
  applyPatches(patches) {
139
195
  if (patches.length > 0) {
140
- serializePatches(patches);
141
- // engineRef.current?.applyPatches(patches);
142
- if (engineRef.current) engineRef.current.applyPatches(patches);else {
143
- if (pendingPatchesRef.current?.snapshot !== snapshotRef.current) pendingPatchesRef.current = {
144
- snapshot: snapshotRef.current,
145
- batches: []
146
- };
147
- pendingPatchesRef.current.batches.push(patches);
148
- }
196
+ const engine = engineRef.current;
197
+ if (engine) {
198
+ engine.applyPatches(patches);
199
+ snapshotRef.current = engine.currentSnapshot();
200
+ } else snapshotRef.current = applyRowPatches(snapshotRef.current, patches);
149
201
  }
150
202
  },
151
203
  reconcileSelection(selectedKeys) {
@@ -208,9 +260,63 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
208
260
  const setHostRef = useCallback(value => {
209
261
  setHost(value);
210
262
  }, []);
211
- return /*#__PURE__*/_jsx(View, {
263
+ const setBoundsRef = useCallback(value => {
264
+ setContentBounds(value);
265
+ }, []);
266
+ const setScrollHostRef = useCallback(value => {
267
+ setOwnedScrollHost(value);
268
+ }, []);
269
+ if (!useSlotLayout) return /*#__PURE__*/_jsx(View, {
212
270
  ...viewProps,
213
271
  ref: setHostRef
214
272
  });
273
+ const padding = slotState.padding;
274
+ const content = /*#__PURE__*/_jsxs(View, {
275
+ ref: setBoundsRef,
276
+ style: {
277
+ position: 'relative',
278
+ flexShrink: 0,
279
+ minWidth: 0
280
+ },
281
+ children: [listHeader !== undefined ? /*#__PURE__*/_jsx(View, {
282
+ style: {
283
+ paddingHorizontal: padding
284
+ },
285
+ children: listHeader
286
+ }) : null, /*#__PURE__*/_jsx(View, {
287
+ ref: setHostRef,
288
+ style: {
289
+ flexShrink: 0,
290
+ minWidth: 0
291
+ }
292
+ }), !slotState.hasRows && hasEmptySlot ? /*#__PURE__*/_jsx(View, {
293
+ style: {
294
+ paddingHorizontal: padding,
295
+ paddingBottom: slotState.emptyBottomPadding
296
+ },
297
+ children: listEmpty
298
+ }) : null, listFooter !== undefined ? /*#__PURE__*/_jsx(View, {
299
+ style: {
300
+ paddingHorizontal: padding
301
+ },
302
+ children: listFooter
303
+ }) : null]
304
+ });
305
+ return /*#__PURE__*/_jsx(View, {
306
+ ...viewProps,
307
+ style: [viewProps.style, {
308
+ position: 'relative',
309
+ minHeight: 0
310
+ }],
311
+ children: webScrollHost === undefined ? /*#__PURE__*/_jsx(View, {
312
+ ref: setScrollHostRef,
313
+ style: {
314
+ position: 'absolute',
315
+ inset: 0,
316
+ overflow: 'scroll'
317
+ },
318
+ children: content
319
+ }) : content
320
+ });
215
321
  });
216
322
  //# sourceMappingURL=NativeList.web.js.map
@@ -347,7 +347,139 @@ function normalizeRowStyles(row) {
347
347
  }
348
348
  return next;
349
349
  }
350
+ function assertMarketBadges(badges, path) {
351
+ if ((badges?.length ?? 0) > MAX_MARKET_BADGES) {
352
+ fail(`${path}.badges`, `supports at most ${MAX_MARKET_BADGES} badges`);
353
+ }
354
+ const badgeKeys = new Set();
355
+ badges?.forEach((badge, index) => {
356
+ const badgePath = `${path}.badges[${index}]`;
357
+ assertKey(badge.key, `${badgePath}.key`);
358
+ if (badgeKeys.has(badge.key)) {
359
+ fail(`${path}.badges`, `duplicate badge key "${badge.key}"`);
360
+ }
361
+ badgeKeys.add(badge.key);
362
+ assertText(badge.text, `${badgePath}.text`);
363
+ // OneKey patch: share typography bounds with Market text styles.
364
+ assertTextStyle(badge.style, `${badgePath}.style`, ['height', 'horizontalPadding']);
365
+ if (badge.style) assertUnknownKeys(badge.style, ['fontSize', 'fontWeight', 'lineHeight', 'height', 'horizontalPadding'], `${badgePath}.style`, 'Market badge style key');
366
+ assertBoundedStyleNumber(badge.style?.height, `${badgePath}.style.height`, 1, 64);
367
+ assertBoundedStyleNumber(badge.style?.horizontalPadding, `${badgePath}.style.horizontalPadding`, 0, 32);
368
+ if (badge.iconName !== undefined && badge.iconName !== 'verified') {
369
+ fail(`${badgePath}.iconName`, 'must be verified when provided');
370
+ }
371
+ if (badge.iconName !== undefined && badge.icon !== undefined) {
372
+ fail(`${badgePath}.icon`, 'cannot be combined with iconName');
373
+ }
374
+ assertImage(badge.icon, `${badgePath}.icon`);
375
+ if (badge.tone !== undefined && !['neutral', 'info', 'success', 'warning', 'danger'].includes(badge.tone)) {
376
+ fail(`${badgePath}.tone`, 'must be neutral, info, success, warning, or danger');
377
+ }
378
+ if (!badge.text && !badge.icon && !badge.iconName) {
379
+ fail(badgePath, 'requires text, icon, or iconName');
380
+ }
381
+ if (badge.actionKey !== undefined) {
382
+ assertKey(badge.actionKey, `${badgePath}.actionKey`);
383
+ }
384
+ });
385
+ }
386
+ function assertWebMarketTable(table, path) {
387
+ if (!table) return;
388
+ assertUnknownKeys(table, ['columns', 'cells', 'testID', 'draggable', 'contextMenuActionKey'], path, 'Web table key');
389
+ if (table.draggable !== undefined && typeof table.draggable !== 'boolean') fail(`${path}.draggable`, 'must be boolean');
390
+ if (table.contextMenuActionKey !== undefined) assertKey(table.contextMenuActionKey, `${path}.contextMenuActionKey`);
391
+ assertText(table.testID, `${path}.testID`);
392
+ if (!Array.isArray(table.columns) || table.columns.length < 1 || table.columns.length > 12) fail(`${path}.columns`, 'must contain 1...12 columns');
393
+ if (!Array.isArray(table.cells) || table.cells.length !== table.columns.length) fail(`${path}.cells`, 'must match the column count');
394
+ const keys = new Set();
395
+ table.columns.forEach((column, index) => {
396
+ const field = `${path}.columns[${index}]`;
397
+ assertUnknownKeys(column, ['key', 'width', 'minWidth', 'flex', 'alignment', 'paddingStart', 'paddingEnd'], field, 'Web column key');
398
+ assertKey(column.key, `${field}.key`);
399
+ if (keys.has(column.key)) fail(field, 'column keys must be unique');
400
+ keys.add(column.key);
401
+ assertBoundedStyleNumber(column.width, `${field}.width`, 0, 4096);
402
+ assertBoundedStyleNumber(column.minWidth, `${field}.minWidth`, 0, 4096);
403
+ assertBoundedStyleNumber(column.flex, `${field}.flex`, 0, 16);
404
+ assertBoundedStyleNumber(column.paddingStart, `${field}.paddingStart`, 0, 64);
405
+ assertBoundedStyleNumber(column.paddingEnd, `${field}.paddingEnd`, 0, 64);
406
+ if (column.alignment !== undefined && !['start', 'center', 'end'].includes(column.alignment)) fail(`${field}.alignment`, 'must be start, center, or end');
407
+ });
408
+ const text = (value, field) => {
409
+ assertUnknownKeys(value, ['text', 'segments', 'tone', 'style'], field, 'Web text key');
410
+ assertText(value.text, `${field}.text`);
411
+ assertTextTone(value.tone, `${field}.tone`);
412
+ assertTextStyle(value.style, `${field}.style`);
413
+ if (value.style) assertUnknownKeys(value.style, ['fontSize', 'fontWeight', 'lineHeight', 'color'], `${field}.style`, 'Web table text style');
414
+ if ((value.segments?.length ?? 0) > 64) fail(`${field}.segments`, 'supports at most 64 segments');
415
+ value.segments?.forEach((segment, index) => {
416
+ assertUnknownKeys(segment, ['text', 'style'], `${field}.segments[${index}]`, 'Web text segment');
417
+ assertText(segment.text, `${field}.segments[${index}].text`);
418
+ if (segment.style !== undefined && segment.style !== 'subscript') fail(field, 'segment style must be subscript');
419
+ });
420
+ };
421
+ const line = (parts, field) => {
422
+ if (!parts) return;
423
+ if (!Array.isArray(parts) || parts.length > 8) fail(field, 'supports at most 8 text parts');
424
+ parts.forEach((value, index) => text(value, `${field}[${index}]`));
425
+ };
426
+ table.cells.forEach((cell, index) => {
427
+ const field = `${path}.cells[${index}]`;
428
+ assertKey(cell.key, `${field}.key`);
429
+ if (cell.key !== table.columns[index].key) fail(field, 'cell key/order must match its column');
430
+ switch (cell.kind) {
431
+ case 'favorite':
432
+ assertUnknownKeys(cell, ['key', 'kind', 'active', 'disabled', 'testID', 'hoverActionKey', 'actionKey', 'accessibilityLabel'], field, 'Web favorite key');
433
+ if (typeof cell.active !== 'boolean') fail(field, 'active must be boolean');
434
+ if (cell.disabled !== undefined && typeof cell.disabled !== 'boolean') fail(field, 'disabled must be boolean');
435
+ if (cell.hoverActionKey !== undefined) assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
436
+ assertText(cell.testID, `${field}.testID`);
437
+ assertKey(cell.actionKey, `${field}.actionKey`);
438
+ assertText(cell.accessibilityLabel, `${field}.accessibilityLabel`);
439
+ break;
440
+ case 'asset':
441
+ assertUnknownKeys(cell, ['key', 'kind', 'leading', 'title', 'secondary', 'hoverSecondary', 'hoverActionKey', 'hoverActionLabel', 'badges', 'lineGap', 'secondaryBadges', 'hoverImages'], field, 'Web asset key');
442
+ assertBoundedStyleNumber(cell.lineGap, `${field}.lineGap`, 0, 8);
443
+ assertMarketBadges(cell.secondaryBadges, `${field}.secondary`);
444
+ cell.secondaryBadges?.forEach((badge, i) => {
445
+ assertUnknownKeys(badge, ['key', 'text', 'style'], `${field}.secondaryBadges[${i}]`, 'Web secondary badge key');
446
+ if (!badge.text) fail(field, 'secondary badges require text');
447
+ });
448
+ if (cell.hoverImages !== undefined && (!Array.isArray(cell.hoverImages) || cell.hoverImages.length > 4)) fail(field, 'supports at most 4 hover images');
449
+ cell.hoverImages?.forEach((image, i) => {
450
+ if (image !== null) assertImage(image, `${field}.hoverImages[${i}]`);
451
+ });
452
+ assertLeadingVisual(cell.leading, `${field}.leading`);
453
+ text(cell.title, `${field}.title`);
454
+ line(cell.secondary, `${field}.secondary`);
455
+ line(cell.hoverSecondary, `${field}.hoverSecondary`);
456
+ assertText(cell.hoverActionLabel, `${field}.hoverActionLabel`);
457
+ if (cell.hoverActionKey !== undefined) assertKey(cell.hoverActionKey, `${field}.hoverActionKey`);
458
+ assertMarketBadges(cell.badges, field);
459
+ cell.badges?.forEach((badge, i) => assertUnknownKeys(badge, ['key', 'text', 'iconName', 'icon', 'textColor', 'backgroundColor', 'actionKey', 'accessibilityLabel', 'style'], `${field}.badges[${i}]`, 'Web title badge key'));
460
+ break;
461
+ case 'text':
462
+ assertUnknownKeys(cell, ['key', 'kind', 'primary', 'secondary', 'partGap'], field, 'Web text cell key');
463
+ assertBoundedStyleNumber(cell.partGap, `${field}.partGap`, 0, 8);
464
+ if (!Array.isArray(cell.primary) || !cell.primary.length) fail(field, 'requires primary text');
465
+ line(cell.primary, `${field}.primary`);
466
+ line(cell.secondary, `${field}.secondary`);
467
+ break;
468
+ case 'sparkline':
469
+ assertUnknownKeys(cell, ['key', 'kind', 'points', 'width', 'height', 'strokeColor', 'fillColor'], field, 'Web sparkline key');
470
+ if (!Array.isArray(cell.points) || cell.points.length > 256 || cell.points.some(value => !Number.isFinite(value))) fail(field, 'supports at most 256 finite samples');
471
+ if (typeof cell.width !== 'number' || typeof cell.height !== 'number') fail(field, 'sparkline dimensions are required');
472
+ assertBoundedStyleNumber(cell.width, `${field}.width`, 1, 512);
473
+ assertBoundedStyleNumber(cell.height, `${field}.height`, 1, 512);
474
+ 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');
475
+ break;
476
+ default:
477
+ fail(field, 'unsupported Web table cell kind');
478
+ }
479
+ });
480
+ }
350
481
  function assertMarketRow(row, path) {
482
+ assertWebMarketTable(row.webTable, `${path}.webTable`);
351
483
  if (!['token', 'stock', 'perp'].includes(row.variant)) {
352
484
  fail(`${path}.variant`, 'must be token, stock, or perp');
353
485
  }
@@ -356,6 +488,7 @@ function assertMarketRow(row, path) {
356
488
  // OneKey patch: validate the independently laid out Market name.
357
489
  if (row.subtitlePrefix) {
358
490
  assertText(row.subtitlePrefix.text, `${path}.subtitlePrefix.text`);
491
+ assertText(row.subtitlePrefix.hoverActionKey, `${path}.subtitlePrefix.hoverActionKey`);
359
492
  assertBoundedStyleNumber(row.subtitlePrefix.gap, `${path}.subtitlePrefix.gap`, 0, 64);
360
493
  assertBoundedStyleNumber(row.subtitlePrefix.maxWidth, `${path}.subtitlePrefix.maxWidth`, 1, 320);
361
494
  assertTextStyle(row.subtitlePrefix.style, `${path}.subtitlePrefix.style`);
@@ -384,40 +517,7 @@ function assertMarketRow(row, path) {
384
517
  if (!['positive', 'negative', 'neutral'].includes(row.change.tone)) {
385
518
  fail(`${path}.change.tone`, 'must be positive, negative, or neutral');
386
519
  }
387
- if ((row.badges?.length ?? 0) > MAX_MARKET_BADGES) {
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
- });
520
+ assertMarketBadges(row.badges, path);
421
521
  for (const [key, value] of [['pressActionKey', row.pressActionKey], ['pressInActionKey', row.pressInActionKey], ['longPressActionKey', row.longPressActionKey], ['diagnostics.imageBindActionKey', row.diagnostics?.imageBindActionKey]]) {
422
522
  if (value !== undefined) assertKey(value, `${path}.${key}`);
423
523
  }
@@ -453,6 +553,13 @@ function assertTrailingAccessories(accessories, path) {
453
553
  function assertImage(image, path) {
454
554
  if (!image) return;
455
555
  if (!image.uri.trim()) fail(`${path}.uri`, 'must not be empty');
556
+ if (image.fallbackUris !== undefined) {
557
+ if (!Array.isArray(image.fallbackUris)) fail(`${path}.fallbackUris`, 'must be an array');
558
+ image.fallbackUris.forEach((uri, index) => {
559
+ if (typeof uri !== 'string') fail(`${path}.fallbackUris[${index}]`, 'must be a string');
560
+ assertText(uri, `${path}.fallbackUris[${index}]`);
561
+ });
562
+ }
456
563
  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
564
  fail(path, `width and height must be within 1...${MAX_IMAGE_EDGE}`);
458
565
  }
@@ -802,6 +909,7 @@ function assertMediaPreview(value, path) {
802
909
  export function validateSnapshot(snapshot) {
803
910
  if (snapshot.capabilities?.refreshTriggerDistance !== undefined && (!Number.isFinite(snapshot.capabilities.refreshTriggerDistance) || snapshot.capabilities.refreshTriggerDistance <= 0)) fail('capabilities.refreshTriggerDistance', 'must be a positive finite number');
804
911
  assertPlainSerializable(snapshot, 'snapshot', new Set());
912
+ assertText(snapshot.theme?.imageFallbackBackground, 'theme.imageFallbackBackground');
805
913
  if (snapshot.schemaVersion !== 1) fail('snapshot.schemaVersion', 'must be 1');
806
914
  if (!Number.isSafeInteger(snapshot.generation) || snapshot.generation < 0) {
807
915
  fail('snapshot.generation', 'must be a non-negative safe integer');
@@ -1096,6 +1204,7 @@ export function applyRowPatches(snapshot, patches) {
1096
1204
  if (patch.type !== row.type) {
1097
1205
  fail('patches', `row "${row.key}" is ${row.type}, not ${patch.type}`);
1098
1206
  }
1207
+ 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
1208
  return {
1100
1209
  ...row,
1101
1210
  ...patch.changes,