@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
@@ -0,0 +1,752 @@
1
+ import type {
2
+ MarketRow,
3
+ WebMarketTableCell,
4
+ WebMarketTableColumn,
5
+ WebMarketTableText,
6
+ } from '../../models';
7
+ import { createElement, markActionAnchorSource } from './RowElements';
8
+ import { applyTextWeight, applyValueSegments } from './RowText';
9
+ import type { RowPrimitives } from './RowVisual';
10
+
11
+ type CellViews = {
12
+ element: HTMLElement;
13
+ kind: WebMarketTableCell['kind'];
14
+ signature: string;
15
+ visual?: HTMLElement;
16
+ visualKey?: string;
17
+ title?: HTMLElement;
18
+ resting?: HTMLElement;
19
+ hover?: HTMLElement;
20
+ assetShape?: string;
21
+ hoverVisuals?: HTMLElement[];
22
+ badgeVisuals?: HTMLElement[];
23
+ };
24
+ type Views = { cells: Map<string, CellViews>; primitives: RowPrimitives };
25
+ const views = new WeakMap<HTMLElement, Views>();
26
+ const columnSignatures = new WeakMap<readonly WebMarketTableColumn[], string>();
27
+ let sparklineId = 0;
28
+ const svgNamespace = 'http://www.w3.org/2000/svg';
29
+ const outlineStar =
30
+ 'm15.455 7.243 7.729 1.123-5.592 5.45 1.32 7.698L12 17.879l-6.911 3.635 1.32-7.698-5.592-5.45 7.728-1.123L12 .24zM9.872 9.071l-4.759.69 3.444 3.358-.814 4.738L12 15.62l.465.245 3.791 1.993-.813-4.739 3.443-3.357-4.758-.69L12 4.758z';
31
+ const solidStar =
32
+ 'm15.405 7.313 7.84 1.034-5.735 5.443 1.44 7.774L12 17.793l-6.948 3.771 1.44-7.774L.756 8.347l7.839-1.034L12 .178z';
33
+ function columnsSignature(columns: readonly WebMarketTableColumn[]) {
34
+ let signature = columnSignatures.get(columns);
35
+ if (signature === undefined) {
36
+ signature = JSON.stringify(columns);
37
+ columnSignatures.set(columns, signature);
38
+ }
39
+ return signature;
40
+ }
41
+ function semanticCellShape(cell: WebMarketTableCell): unknown {
42
+ if (cell.kind === 'asset')
43
+ return {
44
+ key: cell.key,
45
+ kind: cell.kind,
46
+ leading: cell.leading,
47
+ badges: cell.badges,
48
+ hoverActionKey: cell.hoverActionKey,
49
+ lineGap: cell.lineGap,
50
+ secondaryBadges: cell.secondaryBadges,
51
+ hoverImages: cell.hoverImages,
52
+ primaryStyle: cell.title.style,
53
+ secondaryStyle: cell.secondary?.map((value) => value.style),
54
+ hover: cell.hoverSecondary,
55
+ };
56
+ if (cell.kind === 'favorite')
57
+ return {
58
+ key: cell.key,
59
+ kind: cell.kind,
60
+ actionKey: cell.actionKey,
61
+ hoverActionKey: cell.hoverActionKey,
62
+ };
63
+ if (cell.kind === 'sparkline')
64
+ return {
65
+ key: cell.key,
66
+ kind: cell.kind,
67
+ width: cell.width,
68
+ height: cell.height,
69
+ };
70
+ return {
71
+ key: cell.key,
72
+ kind: cell.kind,
73
+ partGap: cell.partGap,
74
+ primary: cell.primary.map((value) => value.style),
75
+ secondary: cell.secondary?.map((value) => value.style),
76
+ };
77
+ }
78
+ export function canPatchMarketTableValues(
79
+ previous: MarketRow,
80
+ next: MarketRow
81
+ ): boolean {
82
+ const a = previous.webTable,
83
+ b = next.webTable;
84
+ return (
85
+ !!a &&
86
+ !!b &&
87
+ a.testID === b.testID &&
88
+ a.draggable === b.draggable &&
89
+ a.contextMenuActionKey === b.contextMenuActionKey &&
90
+ previous.height === next.height &&
91
+ previous.style === next.style &&
92
+ columnsSignature(a.columns) === columnsSignature(b.columns) &&
93
+ a.cells.length === b.cells.length &&
94
+ a.cells.every(
95
+ (cell, index) =>
96
+ JSON.stringify(semanticCellShape(cell)) ===
97
+ JSON.stringify(semanticCellShape(b.cells[index]))
98
+ )
99
+ );
100
+ }
101
+ function tone(value: WebMarketTableText['tone'], secondary: boolean) {
102
+ return value === 'positive'
103
+ ? 'var(--nl-positive)'
104
+ : value === 'negative'
105
+ ? 'var(--nl-negative)'
106
+ : value === 'secondary' || (value === undefined && secondary)
107
+ ? 'var(--nl-secondary)'
108
+ : 'var(--nl-primary)';
109
+ }
110
+ function textPart(
111
+ document: Document,
112
+ part: WebMarketTableText,
113
+ secondary: boolean
114
+ ): HTMLElement {
115
+ const element = createElement(document, 'span', undefined, part.text);
116
+ const size = part.style?.fontSize ?? (secondary ? 12 : 16),
117
+ height = part.style?.lineHeight ?? (secondary ? 16 : 24);
118
+ const weight = { regular: 400, medium: 500, semibold: 600, bold: 700 }[
119
+ part.style?.fontWeight ?? (secondary ? 'regular' : 'medium')
120
+ ];
121
+ Object.assign(element.style, {
122
+ fontSize: `${size}px`,
123
+ lineHeight: `${height}px`,
124
+ fontWeight: String(weight),
125
+ color: part.style?.color ?? tone(part.tone, secondary),
126
+ minWidth: '0',
127
+ overflow: 'hidden',
128
+ textOverflow: 'ellipsis',
129
+ whiteSpace: 'nowrap',
130
+ });
131
+ applyTextWeight(element, weight);
132
+ if (part.segments?.length)
133
+ applyValueSegments(element, part.segments, size, height, weight);
134
+ return element;
135
+ }
136
+ function line(
137
+ document: Document,
138
+ parts: readonly WebMarketTableText[] | undefined,
139
+ secondary: boolean,
140
+ className?: string
141
+ ): HTMLElement {
142
+ const element = createElement(document, 'span', className);
143
+ Object.assign(element.style, {
144
+ display: 'flex',
145
+ gap: '2px',
146
+ alignItems: 'center',
147
+ minWidth: '0',
148
+ overflow: 'hidden',
149
+ height: secondary ? '16px' : '24px',
150
+ flexShrink: '0',
151
+ });
152
+ parts?.forEach((part) =>
153
+ element.appendChild(textPart(document, part, secondary))
154
+ );
155
+ return element;
156
+ }
157
+ function action(
158
+ element: HTMLElement,
159
+ key: string,
160
+ label: string,
161
+ slot: number
162
+ ) {
163
+ element.dataset.nativeListAction = key;
164
+ markActionAnchorSource(element, 'leadingAction', slot);
165
+ element.setAttribute('aria-label', label);
166
+ element.setAttribute('type', 'button');
167
+ Object.assign(element.style, {
168
+ border: '0',
169
+ padding: '4px',
170
+ background: 'transparent',
171
+ font: 'inherit',
172
+ display: 'inline-flex',
173
+ alignItems: 'center',
174
+ justifyContent: 'center',
175
+ cursor: 'pointer',
176
+ flexShrink: '0',
177
+ });
178
+ }
179
+ function icon(document: Document, d: string, size: number): SVGSVGElement {
180
+ const svg = document.createElementNS(svgNamespace, 'svg');
181
+ svg.setAttribute('viewBox', '0 0 24 24');
182
+ svg.setAttribute('width', String(size));
183
+ svg.setAttribute('height', String(size));
184
+ svg.setAttribute('aria-hidden', 'true');
185
+ svg.setAttribute('fill', 'currentColor');
186
+ const path = document.createElementNS(svgNamespace, 'path');
187
+ path.setAttribute('d', d);
188
+ path.setAttribute('fill-rule', 'evenodd');
189
+ svg.appendChild(path);
190
+ return svg;
191
+ }
192
+ function drawSparkline(
193
+ element: HTMLElement,
194
+ cell: Extract<WebMarketTableCell, { kind: 'sparkline' }>
195
+ ) {
196
+ element.replaceChildren();
197
+ if (cell.points.length < 2) return;
198
+ const svg = element.ownerDocument.createElementNS(svgNamespace, 'svg');
199
+ svg.setAttribute('width', String(cell.width));
200
+ svg.setAttribute('height', String(cell.height));
201
+ svg.setAttribute('viewBox', `0 0 ${cell.width} ${cell.height}`);
202
+ svg.setAttribute('aria-hidden', 'true');
203
+ const min = Math.min(...cell.points),
204
+ max = Math.max(...cell.points),
205
+ height = cell.height - 5,
206
+ step = cell.width / (cell.points.length - 1);
207
+ const y = (value: number) =>
208
+ max === min ? height / 2 : height - ((value - min) * height) / (max - min);
209
+ let d = '';
210
+ cell.points.forEach((point, index) => {
211
+ const x = index * step,
212
+ py = y(point);
213
+ if (index === 0) d = `M0 ${py}`;
214
+ else if (index >= 2 && index < cell.points.length - 1) {
215
+ const previousX = (index - 1) * step,
216
+ previousY = y(cell.points[index - 1]),
217
+ beforeX = (index - 2) * step,
218
+ beforeY = y(cell.points[index - 2]),
219
+ nextX = (index + 1) * step,
220
+ nextY = y(cell.points[index + 1]);
221
+ d += ` C${previousX + (x - beforeX) * 0.1} ${Math.max(
222
+ 0,
223
+ previousY + (py - beforeY) * 0.1
224
+ )} ${x - (nextX - previousX) * 0.1} ${Math.max(
225
+ 0,
226
+ py - (nextY - previousY) * 0.1
227
+ )} ${x} ${py}`;
228
+ } else d += ` L${x} ${py}`;
229
+ });
230
+ const id = `nl-sparkline-${++sparklineId}`,
231
+ clipId = id + '-clip';
232
+ const defs = element.ownerDocument.createElementNS(svgNamespace, 'defs'),
233
+ gradient = element.ownerDocument.createElementNS(
234
+ svgNamespace,
235
+ 'linearGradient'
236
+ );
237
+ gradient.id = id;
238
+ gradient.setAttribute('gradientUnits', 'userSpaceOnUse');
239
+ gradient.setAttribute('x1', '0');
240
+ gradient.setAttribute('y1', '0');
241
+ gradient.setAttribute('x2', '0');
242
+ gradient.setAttribute('y2', String(height));
243
+ const start = element.ownerDocument.createElementNS(svgNamespace, 'stop');
244
+ start.setAttribute('offset', '0');
245
+ start.setAttribute('stop-color', cell.fillColor);
246
+ const end = element.ownerDocument.createElementNS(svgNamespace, 'stop');
247
+ end.setAttribute('offset', '1');
248
+ end.setAttribute('stop-color', cell.fillColor);
249
+ end.setAttribute('stop-opacity', '0');
250
+ gradient.append(start, end);
251
+ defs.appendChild(gradient);
252
+ const clip = element.ownerDocument.createElementNS(svgNamespace, 'clipPath');
253
+ clip.id = clipId;
254
+ const rect = element.ownerDocument.createElementNS(svgNamespace, 'rect');
255
+ rect.setAttribute('width', String(cell.width));
256
+ rect.setAttribute('height', String(cell.height - 1));
257
+ clip.appendChild(rect);
258
+ defs.appendChild(clip);
259
+ svg.appendChild(defs);
260
+ const outline = `${d} L${cell.width + step * 2} ${y(
261
+ cell.points[cell.points.length - 1]
262
+ )} L${cell.width + step * 2} ${cell.height} L0 ${cell.height}`;
263
+ const group = element.ownerDocument.createElementNS(svgNamespace, 'g');
264
+ group.setAttribute('clip-path', `url(#${clipId})`);
265
+ const fill = element.ownerDocument.createElementNS(svgNamespace, 'path');
266
+ fill.setAttribute('d', outline + ' Z');
267
+ fill.setAttribute('fill', `url(#${id})`);
268
+ const stroke = element.ownerDocument.createElementNS(svgNamespace, 'path');
269
+ stroke.setAttribute('d', outline);
270
+ stroke.setAttribute('stroke', cell.strokeColor);
271
+ stroke.setAttribute('stroke-width', '1');
272
+ stroke.setAttribute('fill', 'none');
273
+ group.append(fill, stroke);
274
+ svg.appendChild(group);
275
+ element.appendChild(svg);
276
+ }
277
+ function updateCell(
278
+ view: CellViews,
279
+ cell: WebMarketTableCell,
280
+ primitives: RowPrimitives,
281
+ index: number
282
+ ) {
283
+ const signature = JSON.stringify(cell);
284
+ if (view.signature === signature) return;
285
+ const element = view.element,
286
+ document = element.ownerDocument;
287
+ if (cell.kind === 'asset') {
288
+ const visualKey = JSON.stringify(cell.leading);
289
+ if (view.visualKey !== visualKey) {
290
+ if (view.visual) {
291
+ primitives.dispose(view.visual);
292
+ view.visual.remove();
293
+ }
294
+ view.visual = primitives.visual(cell.leading);
295
+ view.visualKey = visualKey;
296
+ if (view.visual)
297
+ Object.assign(view.visual.style, {
298
+ width: '40px',
299
+ height: '40px',
300
+ flexBasis: '40px',
301
+ flexShrink: '0',
302
+ marginInlineEnd: '14px',
303
+ boxSizing: 'border-box',
304
+ border:
305
+ cell.leading &&
306
+ 'borderColor' in cell.leading &&
307
+ cell.leading.borderColor
308
+ ? `1px solid ${cell.leading.borderColor}`
309
+ : '0',
310
+ });
311
+ if (view.visual) {
312
+ if (
313
+ cell.leading &&
314
+ 'backgroundColor' in cell.leading &&
315
+ cell.leading.backgroundColor
316
+ )
317
+ view.visual.style.background = cell.leading.backgroundColor;
318
+ for (const child of [...view.visual.children]) {
319
+ if (child.classList.contains('ok-native-list-visual-main'))
320
+ Object.assign((child as HTMLElement).style, {
321
+ width: '100%',
322
+ height: '100%',
323
+ });
324
+ if (
325
+ child.classList.contains('ok-native-list-visual-overlay') &&
326
+ cell.leading &&
327
+ 'borderColor' in cell.leading &&
328
+ cell.leading.borderColor
329
+ ) {
330
+ const style = (child as HTMLElement).style;
331
+ for (const edge of ['left', 'right', 'top', 'bottom'] as const)
332
+ if (style[edge])
333
+ style[edge] = `${Number.parseFloat(style[edge]) - 1}px`;
334
+ }
335
+ }
336
+ }
337
+ }
338
+ const assetShape = JSON.stringify(semanticCellShape(cell));
339
+ if (view.title && view.assetShape === assetShape) {
340
+ const primary = textPart(document, cell.title, false);
341
+ view.title.firstElementChild?.replaceWith(primary);
342
+ view.resting?.replaceChildren(
343
+ ...(cell.secondary ?? []).map((part) => textPart(document, part, true))
344
+ );
345
+ if (view.hover) {
346
+ const button = view.hover.querySelector('button');
347
+ for (const child of [...view.hover.children])
348
+ if (child !== button) child.remove();
349
+ for (const part of cell.hoverSecondary ?? [])
350
+ view.hover.insertBefore(textPart(document, part, true), button);
351
+ }
352
+ view.signature = signature;
353
+ return;
354
+ }
355
+ view.hoverVisuals?.forEach((visual) => primitives.dispose(visual));
356
+ view.hoverVisuals = [];
357
+ view.badgeVisuals?.forEach((visual) => primitives.dispose(visual));
358
+ view.badgeVisuals = [];
359
+ view.assetShape = assetShape;
360
+ view.title = undefined;
361
+ view.resting = undefined;
362
+ view.hover = undefined;
363
+ for (const child of [...element.children])
364
+ if (child !== view.visual) child.remove();
365
+ if (view.visual) element.appendChild(view.visual);
366
+ const text = createElement(document, 'span');
367
+ Object.assign(text.style, {
368
+ display: 'flex',
369
+ flexDirection: 'column',
370
+ gap: `${cell.lineGap ?? 4}px`,
371
+ minWidth: '0',
372
+ flex: '1',
373
+ });
374
+ const title = line(document, [cell.title], false);
375
+ view.title = title;
376
+ title.style.gap = '4px';
377
+ cell.badges?.forEach((badge, slot) => {
378
+ const node = createElement(
379
+ document,
380
+ badge.actionKey ? 'button' : 'span',
381
+ 'ok-native-list-market-badge',
382
+ badge.text
383
+ );
384
+ if (badge.actionKey)
385
+ action(
386
+ node,
387
+ badge.actionKey,
388
+ badge.accessibilityLabel ?? badge.text ?? '',
389
+ slot
390
+ );
391
+ node.style.color = badge.textColor ?? '';
392
+ node.style.backgroundColor = badge.backgroundColor ?? '';
393
+ if (badge.style)
394
+ Object.assign(node.style, {
395
+ fontSize: `${badge.style.fontSize ?? 11}px`,
396
+ fontWeight: String(
397
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
398
+ badge.style.fontWeight ?? 'regular'
399
+ ]
400
+ ),
401
+ lineHeight: `${badge.style.lineHeight ?? 16}px`,
402
+ height: `${badge.style.height ?? 16}px`,
403
+ paddingInline: `${badge.style.horizontalPadding ?? 5}px`,
404
+ });
405
+ applyTextWeight(
406
+ node,
407
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
408
+ badge.style?.fontWeight ?? 'regular'
409
+ ]
410
+ );
411
+ if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
412
+ if (badge.icon) {
413
+ const visual = primitives.visual({
414
+ kind: 'image',
415
+ image: badge.icon,
416
+ shape: 'circle',
417
+ });
418
+ if (visual) {
419
+ Object.assign(node.style, {
420
+ height: `${badge.icon.height}px`,
421
+ padding: '0',
422
+ background: 'transparent',
423
+ });
424
+ Object.assign(visual.style, {
425
+ width: `${badge.icon.width}px`,
426
+ height: `${badge.icon.height}px`,
427
+ flexBasis: `${badge.icon.width}px`,
428
+ });
429
+ for (const child of [...visual.children])
430
+ Object.assign((child as HTMLElement).style, {
431
+ width: '100%',
432
+ height: '100%',
433
+ });
434
+ node.appendChild(visual);
435
+ view.badgeVisuals!.push(visual);
436
+ }
437
+ }
438
+ if (badge.iconName === 'verified') {
439
+ Object.assign(node.style, {
440
+ height: '16px',
441
+ padding: '0',
442
+ background: 'transparent',
443
+ borderRadius: '0',
444
+ });
445
+ applyTextWeight(
446
+ node,
447
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
448
+ badge.style?.fontWeight ?? 'regular'
449
+ ]
450
+ );
451
+ if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
452
+ node.textContent = '';
453
+ const svg = icon(
454
+ document,
455
+ 'M9.483 11.458v3.5h-1v-3.5z M10.467 2.698a2.03 2.03 0 0 1 3.065 0l1.358 1.564a.03.03 0 0 0 .028.01l2.046-.325a2.03 2.03 0 0 1 2.347 1.971l.037 2.07q0 .016.014.026l1.776 1.066a2.03 2.03 0 0 1 .532 3.019l-1.304 1.609a.03.03 0 0 0-.005.03l.675 1.956a2.03 2.03 0 0 1-1.533 2.656l-2.033.394a.03.03 0 0 0-.023.019l-.741 1.933a2.03 2.03 0 0 1-2.88 1.05l-1.811-1.006a.03.03 0 0 0-.03 0l-1.811 1.005a2.03 2.03 0 0 1-2.88-1.049l-.742-1.933a.03.03 0 0 0-.023-.019l-2.033-.394a2.03 2.03 0 0 1-1.532-2.656l.675-1.957a.03.03 0 0 0-.005-.029l-1.304-1.61a2.03 2.03 0 0 1 .532-3.018l1.776-1.066a.03.03 0 0 0 .014-.026l.035-2.07a2.03 2.03 0 0 1 2.349-1.97l2.045.324a.03.03 0 0 0 .028-.01zm1.516 3.76a.5.5 0 0 0-.447.276l-1.861 3.724H8.483a1 1 0 0 0-1 1v3.5a1 1 0 0 0 1 1h6.692a2 2 0 0 0 1.981-1.73l.341-2.5a2 2 0 0 0-1.982-2.27h-1.939l.197-1.269a1.5 1.5 0 0 0-1.481-1.731z',
456
+ 14
457
+ );
458
+ node.appendChild(svg);
459
+ }
460
+ title.appendChild(node);
461
+ });
462
+ text.appendChild(title);
463
+ if (cell.secondary?.length || cell.hoverSecondary?.length) {
464
+ const height =
465
+ cell.secondary?.[0]?.style?.lineHeight ??
466
+ cell.hoverSecondary?.[0]?.style?.lineHeight ??
467
+ 16;
468
+ const clip = createElement(
469
+ document,
470
+ 'span',
471
+ 'ok-native-list-table-secondary'
472
+ );
473
+ clip.style.height = `${height}px`;
474
+ const track = createElement(
475
+ document,
476
+ 'span',
477
+ 'ok-native-list-table-secondary-track'
478
+ );
479
+ track.style.setProperty('--nl-table-secondary-height', `${height}px`);
480
+ if (cell.secondary?.length) {
481
+ const resting = line(document, cell.secondary, true);
482
+ view.resting = resting;
483
+ resting.style.height = `${height}px`;
484
+ const restingFrame = createElement(document, 'span');
485
+ Object.assign(restingFrame.style, {
486
+ display: 'flex',
487
+ alignItems: 'center',
488
+ gap: '4px',
489
+ height: `${height}px`,
490
+ minWidth: '0',
491
+ });
492
+ cell.secondaryBadges?.forEach((badge) => {
493
+ const node = createElement(
494
+ document,
495
+ 'span',
496
+ 'ok-native-list-market-badge',
497
+ badge.text
498
+ );
499
+ Object.assign(node.style, {
500
+ fontSize: `${badge.style?.fontSize ?? 11}px`,
501
+ fontWeight: String(
502
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
503
+ badge.style?.fontWeight ?? 'regular'
504
+ ]
505
+ ),
506
+ lineHeight: `${badge.style?.lineHeight ?? 12}px`,
507
+ height: `${badge.style?.height ?? 16}px`,
508
+ paddingInline: `${badge.style?.horizontalPadding ?? 4}px`,
509
+ });
510
+ applyTextWeight(
511
+ node,
512
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
513
+ badge.style?.fontWeight ?? 'regular'
514
+ ]
515
+ );
516
+ restingFrame.appendChild(node);
517
+ });
518
+ restingFrame.appendChild(resting);
519
+ track.appendChild(restingFrame);
520
+ }
521
+ if (cell.hoverSecondary?.length) {
522
+ const hover = line(document, cell.hoverSecondary, true);
523
+ view.hover = hover;
524
+ hover.style.height = `${height}px`;
525
+ const hoverFrame = createElement(document, 'span');
526
+ Object.assign(hoverFrame.style, {
527
+ display: 'flex',
528
+ alignItems: 'center',
529
+ gap: cell.hoverActionKey ? '2px' : '4px',
530
+ height: `${height}px`,
531
+ minWidth: '0',
532
+ });
533
+ hoverFrame.appendChild(hover);
534
+ if (cell.hoverImages?.length) {
535
+ const group = createElement(document, 'span');
536
+ Object.assign(group.style, {
537
+ display: 'flex',
538
+ alignItems: 'center',
539
+ flexShrink: '0',
540
+ });
541
+ cell.hoverImages.forEach((image, i) => {
542
+ const visual = image
543
+ ? primitives.visual({ kind: 'image', image, shape: 'circle' })
544
+ : createElement(document, 'span', 'ok-native-list-visual');
545
+ if (visual) {
546
+ Object.assign(visual.style, {
547
+ width: '16px',
548
+ height: '16px',
549
+ flexBasis: '16px',
550
+ border: '1px solid var(--nl-row)',
551
+ boxSizing: 'border-box',
552
+ marginInlineEnd:
553
+ i === cell.hoverImages!.length - 1 ? '0' : '-4px',
554
+ zIndex: String(cell.hoverImages!.length - i),
555
+ overflow: 'hidden',
556
+ });
557
+ for (const child of [...visual.children])
558
+ Object.assign((child as HTMLElement).style, {
559
+ width: '100%',
560
+ height: '100%',
561
+ });
562
+ view.hoverVisuals!.push(visual);
563
+ group.appendChild(visual);
564
+ }
565
+ });
566
+ hoverFrame.appendChild(group);
567
+ }
568
+ if (cell.hoverActionKey) {
569
+ const button = createElement(document, 'button');
570
+ action(
571
+ button,
572
+ cell.hoverActionKey,
573
+ cell.hoverActionLabel ?? 'Copy address',
574
+ index
575
+ );
576
+ button.style.padding = '0';
577
+ button.style.color = 'var(--nl-icon-subdued)';
578
+ button.appendChild(
579
+ icon(
580
+ document,
581
+ 'M21 17h-4v4H3V7h4V3h14zM5 19h10V9H5zM9 7h8v8h2V5H9z',
582
+ 14
583
+ )
584
+ );
585
+ hoverFrame.appendChild(button);
586
+ }
587
+ track.appendChild(hoverFrame);
588
+ if (cell.secondary?.length) clip.dataset.hasHover = 'true';
589
+ }
590
+ clip.appendChild(track);
591
+ text.appendChild(clip);
592
+ }
593
+ element.appendChild(text);
594
+ } else if (cell.kind === 'favorite') {
595
+ const button =
596
+ element.querySelector('button') ?? createElement(document, 'button');
597
+ action(button, cell.actionKey, cell.accessibilityLabel, index);
598
+ button.setAttribute('aria-pressed', String(cell.active));
599
+ (button as HTMLButtonElement).disabled = !!cell.disabled;
600
+ button.removeAttribute('title');
601
+ if (cell.hoverActionKey)
602
+ button.dataset.nativeListHoverAction = cell.hoverActionKey;
603
+ else delete button.dataset.nativeListHoverAction;
604
+ if (cell.testID) button.dataset.testid = cell.testID;
605
+ else delete button.dataset.testid;
606
+ button.style.width = '24px';
607
+ button.style.height = '24px';
608
+ button.style.color = cell.active
609
+ ? 'var(--nl-accent)'
610
+ : 'var(--nl-icon-subdued)';
611
+ let svg = button.querySelector('svg');
612
+ if (!svg) {
613
+ svg = icon(document, cell.active ? solidStar : outlineStar, 16);
614
+ button.appendChild(svg);
615
+ }
616
+ svg
617
+ .querySelector('path')
618
+ ?.setAttribute('d', cell.active ? solidStar : outlineStar);
619
+ if (!button.parentElement) element.appendChild(button);
620
+ } else if (cell.kind === 'sparkline') drawSparkline(element, cell);
621
+ else {
622
+ element.replaceChildren();
623
+ const column = createElement(document, 'span');
624
+ Object.assign(column.style, {
625
+ display: 'flex',
626
+ flexDirection: 'column',
627
+ gap: '4px',
628
+ minWidth: '0',
629
+ width: '100%',
630
+ });
631
+ const primary = line(document, cell.primary, false);
632
+ primary.style.gap = `${cell.partGap ?? 2}px`;
633
+ column.appendChild(primary);
634
+ if (cell.secondary?.length)
635
+ column.appendChild(line(document, cell.secondary, true));
636
+ element.appendChild(column);
637
+ }
638
+ view.signature = signature;
639
+ }
640
+ function bind(body: HTMLElement, row: MarketRow, primitives: RowPrimitives) {
641
+ const state = views.get(body)!;
642
+ state.primitives = primitives;
643
+ const table = row.webTable!;
644
+ if (table.testID) body.dataset.testid = table.testID;
645
+ else delete body.dataset.testid;
646
+ const desired = new Set(table.columns.map((column) => column.key));
647
+ state.cells.forEach((view, key) => {
648
+ if (!desired.has(key)) {
649
+ view.hoverVisuals?.forEach((visual) => primitives.dispose(visual));
650
+ view.badgeVisuals?.forEach((visual) => primitives.dispose(visual));
651
+ if (view.visual) primitives.dispose(view.visual);
652
+ view.element.remove();
653
+ state.cells.delete(key);
654
+ }
655
+ });
656
+ table.columns.forEach((column, index) => {
657
+ const cell = table.cells[index];
658
+ let view = state.cells.get(column.key);
659
+ if (view?.kind !== cell.kind) {
660
+ view?.hoverVisuals?.forEach((visual) => primitives.dispose(visual));
661
+ view?.badgeVisuals?.forEach((visual) => primitives.dispose(visual));
662
+ if (view?.visual) primitives.dispose(view.visual);
663
+ view?.element.remove();
664
+ state.cells.delete(column.key);
665
+ view = undefined;
666
+ }
667
+ if (!view) {
668
+ view = {
669
+ element: createElement(
670
+ body.ownerDocument,
671
+ 'span',
672
+ 'ok-native-list-table-cell'
673
+ ),
674
+ kind: cell.kind,
675
+ signature: '',
676
+ };
677
+ view.element.dataset.columnKey = column.key;
678
+ state.cells.set(column.key, view);
679
+ }
680
+ const element = view.element;
681
+ Object.assign(element.style, {
682
+ display: 'flex',
683
+ boxSizing: 'border-box',
684
+ alignItems: 'center',
685
+ minWidth: `${column.minWidth ?? 0}px`,
686
+ width: column.width === undefined ? 'auto' : `${column.width}px`,
687
+ flex:
688
+ column.flex !== undefined
689
+ ? `${column.flex} 1 auto`
690
+ : column.width === undefined
691
+ ? '1 1 0px'
692
+ : `0 0 ${column.width}px`,
693
+ paddingInlineStart: `${column.paddingStart ?? 0}px`,
694
+ paddingInlineEnd: `${column.paddingEnd ?? 0}px`,
695
+ justifyContent:
696
+ column.alignment === 'end'
697
+ ? 'flex-end'
698
+ : column.alignment === 'center'
699
+ ? 'center'
700
+ : 'flex-start',
701
+ overflow: 'hidden',
702
+ height: '100%',
703
+ });
704
+ updateCell(view, cell, primitives, index);
705
+ body.appendChild(element);
706
+ });
707
+ }
708
+ function create(document: Document, row: MarketRow, primitives: RowPrimitives) {
709
+ const body = createElement(
710
+ document,
711
+ 'div',
712
+ 'ok-native-list-row ok-native-list-market-table'
713
+ );
714
+ body.dataset.nlRenderer = 'marketTable';
715
+ Object.assign(body.style, { gap: '0', padding: '0', borderRadius: '12px' });
716
+ views.set(body, { cells: new Map(), primitives });
717
+ bind(body, row, primitives);
718
+ return body;
719
+ }
720
+ export function updateMarketTableValues(element: HTMLElement, row: MarketRow) {
721
+ const body = element.querySelector<HTMLElement>(
722
+ '.ok-native-list-market-table'
723
+ );
724
+ const state = body ? views.get(body) : undefined;
725
+ if (!body || !state) return;
726
+ row.webTable!.cells.forEach((cell, index) => {
727
+ const view = state.cells.get(cell.key);
728
+ if (view) updateCell(view, cell, state.primitives, index);
729
+ });
730
+ element.setAttribute(
731
+ 'aria-label',
732
+ row.accessibilityLabel ?? [row.title, row.price, row.change.text].join(', ')
733
+ );
734
+ }
735
+ export const marketTableRowRenderer = {
736
+ key: 'marketTable',
737
+ appliesSizePreset: () => false,
738
+ create,
739
+ bind,
740
+ measure: () => 72,
741
+ measureRendered: () => undefined,
742
+ recycle: (body: HTMLElement) => {
743
+ const state = views.get(body);
744
+ state?.cells.forEach((view) => {
745
+ if (view.visual) state.primitives.dispose(view.visual);
746
+ view.hoverVisuals?.forEach((visual) => state.primitives.dispose(visual));
747
+ view.badgeVisuals?.forEach((visual) => state.primitives.dispose(visual));
748
+ });
749
+ state?.cells.clear();
750
+ body.replaceChildren();
751
+ },
752
+ };